:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --sidebar: #121a24;
  --border: #2a3648;
  --text: #e7eef8;
  --muted: #8b9bb4;
  --accent: #3d9cf0;
  --accent-2: #2d7fc7;
  --danger: #e25555;
  --ok: #3cbf7f;
  --warn: #e0a84a;
  --sidebar-w: 220px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1b2a40, transparent),
              radial-gradient(900px 500px at 100% 0%, #182433, transparent),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.75rem; font-weight: 600; }
p { color: var(--muted); }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.auth-card h1 { font-size: 1.4rem; }
.brand-mark {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.app-sidebar .brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.app-nav { display: flex; flex-direction: column; padding: 0.75rem 0.5rem; gap: 0.25rem; flex: 1; }
.app-nav a {
  color: var(--muted);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
}
.app-nav a:hover { background: rgba(255,255,255,.04); color: var(--text); }
.app-nav a.active { background: rgba(61,156,240,.15); color: var(--text); }
.app-sidebar-foot {
  padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}
.app-sidebar-foot form { margin-top: 0.5rem; }
.app-main { flex: 1; padding: 1.5rem 1.75rem; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
input, select, textarea, button {
  font: inherit;
  color: var(--text);
}
input, select, textarea {
  width: 100%;
  background: #0d131c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--accent);
  border: none;
  color: #061018;
  font-weight: 600;
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-2); text-decoration: none; color: #061018; }
button.secondary, .btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.danger, .btn.danger { background: var(--danger); color: #fff; }
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.alert.error { background: rgba(226,85,85,.15); border: 1px solid rgba(226,85,85,.4); color: #ffb4b4; }
.alert.success { background: rgba(60,191,127,.12); border: 1px solid rgba(60,191,127,.35); color: #9be7c0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.online { background: rgba(60,191,127,.2); color: var(--ok); }
.badge.offline { background: rgba(139,155,180,.15); color: var(--muted); }
.badge.admin { background: rgba(61,156,240,.2); color: var(--accent); }
.mono { font-family: var(--mono); font-size: 0.85rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.preview {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #000;
}
.gallery-heading {
  margin: 1.25rem 0 0.75rem;
  font-size: 1rem;
}
.bg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.bg-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  background: rgba(0,0,0,.2);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.bg-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(61,156,240,.35);
}
.bg-thumb-btn {
  display: block;
  padding: 0;
  border: none;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  width: 100%;
}
.bg-thumb-btn img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.bg-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  min-height: 1.4rem;
}
.bg-card-name {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bg-delete {
  width: 100%;
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
}
.muted { color: var(--muted); }
.field { min-width: 160px; flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: auto; }
.remember-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.remember-row input { width: auto; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  place-items: center;
  z-index: 50;
  padding: 1rem;
}
.modal.open { display: grid; }
.modal-card {
  width: min(720px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.crop-wrap { max-height: 60vh; background: #000; }
.crop-wrap img { max-width: 100%; display: block; }
.display-list { display: grid; gap: 0.5rem; }
.display-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.display-item input { width: auto; }
.touch-debug-card { width: min(780px, 100%); }
.touch-debug-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: start;
}
#touchCanvas {
  display: block;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 100%;
}
.touch-debug-meta p { margin: 0 0 0.5rem; }
.touch-json {
  margin: 0;
  padding: 0.75rem;
  background: rgba(0,0,0,.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 240px;
  overflow: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (max-width: 720px) {
  .touch-debug-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .app-sidebar {
    width: 100%;
    height: auto;
    position: relative;
  }
  .app-nav { flex-direction: row; flex-wrap: wrap; }
}
