/* ============================================================
   QuizGame — design system
   Dark is the default theme; [data-theme="light"] overrides it.
   Theme choice is saved in localStorage by js/common.js.
   Type: "Space Grotesk" for display, "Inter" for body.
   ============================================================ */

:root,
[data-theme="dark"] {
  --bg: #0a0a0b;
  --bg-soft: #101013;
  --surface: #151518;
  --surface-2: #1d1d21;
  --surface-3: #242429;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f1e9;
  --muted: #a19c8e;
  --faint: #6d695e;
  --accent: #ff5a1f;
  --accent-hover: #ff6f3d;
  --accent-ink: #1d0e02;
  --accent-soft: rgba(255, 90, 31, 0.12);
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, 0.12);
  --danger: #f4536a;
  --danger-soft: rgba(244, 83, 106, 0.12);
  --warning: #f5a524;
  --warning-soft: rgba(245, 165, 36, 0.12);
  --gold: #e8b44a;
  --silver: #b9bec7;
  --bronze: #d08a4e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -12px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 3px rgba(255, 90, 31, 0.28);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f2ea;
  --bg-soft: #ede9dc;
  --surface: #fdfcf8;
  --surface-2: #f1ede0;
  --surface-3: #e8e2d1;
  --border: #e0dac7;
  --border-strong: #cfc7ae;
  --text: #1c1912;
  --muted: #6f695a;
  --faint: #a09a87;
  --accent: #d9480b;
  --accent-hover: #b93a07;
  --accent-ink: #fff8f0;
  --accent-soft: rgba(217, 72, 11, 0.1);
  --success: #12805c;
  --success-soft: rgba(18, 128, 92, 0.1);
  --danger: #d92d4e;
  --danger-soft: rgba(217, 45, 78, 0.08);
  --warning: #a86a04;
  --warning-soft: rgba(168, 106, 4, 0.1);
  --gold: #a8760a;
  --silver: #7c828c;
  --bronze: #a05f2c;
  --shadow: 0 1px 2px rgba(28, 25, 18, 0.06), 0 16px 40px -20px rgba(28, 25, 18, 0.25);
  --ring: 0 0 0 3px rgba(217, 72, 11, 0.22);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3, .display {
  font-family: "Space Grotesk", "Inter", system-ui, sans-serif;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 700;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.35rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- Layout utilities ---------- */
.container { max-width: 980px; margin: 0 auto; padding: 2.5rem 1.25rem 5rem; }
.center { text-align: center; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.error-text { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; }

/* Eyebrow label used above big headings */
.eyebrow {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.9rem;
}

/* ---------- Navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.logo { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark { display: inline-flex; color: var(--accent); }
.logo-mark svg { width: 28px; height: 28px; display: block; }
.logo-word {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
}
.nav-links a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.nav-links a.active { color: var(--text); background: var(--surface-2); }

.nav-right { display: flex; align-items: center; gap: 0.7rem; }
.nav-user { display: inline-flex; align-items: center; gap: 0.55rem; font-weight: 600; font-size: 0.95rem; color: var(--muted); }

.avatar {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 1.3rem;
  font-size: 0.98rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--border-strong); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn svg { width: 17px; height: 17px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 0.42rem 0.95rem; font-size: 0.88rem; border-radius: 8px; }
.btn-large { padding: 0.85rem 1.9rem; font-size: 1.05rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-warn { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.btn-warn:hover { background: var(--warning-soft); }
.btn-edit { background: var(--warning-soft); border-color: var(--border-strong); color: var(--warning); }
.btn-edit:hover { background: var(--warning-soft); border-color: var(--warning); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.9rem;
  margin: 1.5rem 0;
  box-shadow: var(--shadow);
}
.card > h2:first-child { margin-bottom: 1.1rem; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 1.1rem; font-weight: 600; font-size: 0.95rem; }
.field > span { display: block; margin-bottom: 0.4rem; }
label { display: block; margin-bottom: 1.1rem; font-weight: 600; font-size: 0.95rem; }
input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.72rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
  background: var(--surface);
}
label.inline { display: inline-flex; align-items: center; gap: 0.55rem; margin: 0; }
label.inline select { width: auto; margin-top: 0; }

.error-box {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 1.1rem;
  font-size: 0.95rem;
  font-weight: 500;
}

/* ---------- Landing ---------- */
.landing { max-width: 1120px; margin: 0 auto; padding: 0 1.25rem 5rem; }
.hero { text-align: center; padding: 5.5rem 1rem 4rem; max-width: 820px; margin: 0 auto; }
.hero h1 { font-size: clamp(2.6rem, 6vw, 4.3rem); margin-bottom: 1.25rem; }
.hero h1 .accent-word { color: var(--accent); }
.hero-sub { color: var(--muted); font-size: 1.12rem; max-width: 620px; margin: 0 auto 2.25rem; }
.hero-actions { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }

.hero-stats {
  display: flex; justify-content: center; gap: 2.5rem; flex-wrap: wrap;
  margin-top: 3.5rem; padding-top: 2.25rem;
  border-top: 1px solid var(--border);
}
.hero-stat { text-align: center; }
.hero-stat b { display: block; font-family: "Space Grotesk", sans-serif; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.hero-stat span { color: var(--muted); font-size: 0.88rem; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.1rem;
  margin-top: 1rem;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.6rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.feature-card:hover { transform: translateY(-3px); border-color: var(--border-strong); }
.icon-tile {
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 1rem;
}
.icon-tile svg { width: 22px; height: 22px; }
.feature-card h3 { font-size: 1.05rem; margin-bottom: 0.35rem; }
.feature-card p { color: var(--muted); font-size: 0.95rem; }

.footer { text-align: center; padding: 2.5rem 1rem; color: var(--faint); font-size: 0.88rem; border-top: 1px solid var(--border); margin-top: 4rem; }

/* ---------- Dashboard ---------- */
.page-head { margin-bottom: 0.5rem; }
.page-head h1 { font-size: 2.1rem; }
.page-head p { color: var(--muted); margin-top: 0.35rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.35rem 1.25rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--accent);
  opacity: 0;
}
.stat-card.highlight::before { opacity: 1; }
.stat-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-card.highlight .stat-value { color: var(--accent); }
.stat-label { color: var(--muted); font-size: 0.87rem; margin-top: 0.15rem; }

.quiz-setup {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
}
.hint { color: var(--faint); font-size: 0.88rem; margin-top: 0.9rem; }

.recent-list { display: flex; flex-direction: column; gap: 0.7rem; }
.recent-item {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1.1rem;
  font-weight: 500;
}
.recent-item .pct { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; padding: 0.4rem; }
.table { width: 100%; border-collapse: collapse; font-size: 0.96rem; }
.table th, .table td { padding: 0.85rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  color: var(--faint);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.rank-medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700; font-size: 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.rank-medal.r1 { background: rgba(232, 180, 74, 0.15); border-color: var(--gold); color: var(--gold); }
.rank-medal.r2 { background: rgba(185, 190, 199, 0.12); border-color: var(--silver); color: var(--silver); }
.rank-medal.r3 { background: rgba(208, 138, 78, 0.14); border-color: var(--bronze); color: var(--bronze); }

/* ---------- Result page ---------- */
.result-card { text-align: center; max-width: 860px; margin-left: auto; margin-right: auto; }
.result-ring {
  width: 92px; height: 92px; margin: 0.5rem auto 1rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
}
.result-ring svg { width: 44px; height: 44px; }
.big-score {
  font-family: "Space Grotesk", sans-serif;
  font-size: 4.5rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 0.75rem 0 0.25rem;
}
.big-score small { font-size: 1.4rem; color: var(--faint); font-weight: 500; }
.performance-msg { font-size: 1.2rem; color: var(--muted); font-weight: 500; }
.result-actions { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; margin-top: 2.25rem; }

/* ---------- History ---------- */
.history-list { display: flex; flex-direction: column; gap: 0.9rem; }
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1.25rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.35rem;
  transition: border-color 0.2s;
}
.history-item:hover { border-color: var(--border-strong); }
.history-item h3 { font-size: 1.05rem; }
.history-item .meta { color: var(--muted); font-size: 0.88rem; display: flex; gap: 0.9rem; flex-wrap: wrap; }
.history-score {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.7rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-align: right;
  line-height: 1.1;
}
.history-score small { display: block; font-family: "Inter", sans-serif; font-size: 0.78rem; color: var(--faint); font-weight: 500; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 0.4rem; margin: 1.75rem 0 0; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  border-radius: 10px 10px 0 0;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.95rem;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); }
.tab-panel { margin-top: 0; border-radius: 0 14px 14px 14px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.action-btns { display: flex; gap: 0.5rem; }

/* ---------- Entrance animations (subtle, staggered) ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.fade-in { animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
.slide-up { animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; animation-delay: var(--d, 0s); }

@media (prefers-reduced-motion: reduce) {
  .fade-in, .slide-up { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .hero { padding: 3.5rem 0.5rem 2.75rem; }
  .nav-links { display: none; }
  .nav-user span.uname { display: none; }
  .quiz-setup { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .container { padding: 1.5rem 0.9rem 3.5rem; }
  .card { padding: 1.35rem; }
  .big-score { font-size: 3.4rem; }
  .hero-stats { gap: 1.5rem; }
  .history-item { grid-template-columns: 1fr; }
  .history-score { text-align: left; }
}
