/* =============================================
   CivilTayari — Production Design System v5
   8px spatial grid · 6-step type scale
   WCAG AA contrast · Zero magic numbers
   ============================================= */

/* ── Design tokens ──────────────────────────── */
:root {
  /* Colour palette */
  --bg-base:       #07090f;
  --bg-surface:    #0c0f1c;
  --bg-card:       #101520;
  --bg-card-hover: #141a28;
  --bg-input:      #0c1120;
  --bg-highlight:  #161e30;
  --bg-overlay:    rgba(7,9,15,0.88);

  /* Borders */
  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.11);
  --border-accent: rgba(251,146,60,0.28);

  /* Brand */
  --accent:        #fb923c;
  --accent-bright: #fdba74;
  --accent-dim:    rgba(251,146,60,0.12);
  --accent-glow:   rgba(251,146,60,0.07);

  /* Semantic colours */
  --blue:          #38bdf8;
  --blue-dim:      rgba(56,189,248,0.10);
  --success:       #4ade80;
  --success-dim:   rgba(74,222,128,0.10);
  --danger:        #f87171;
  --danger-dim:    rgba(248,113,113,0.10);
  --warning:       #fbbf24;
  --warning-dim:   rgba(251,191,36,0.10);
  --purple:        #a78bfa;
  --purple-dim:    rgba(167,139,250,0.10);

  /* Text — all pass WCAG AA on --bg-base */
  --text-primary:   #eef2ff;  /* 14:1 on bg-base */
  --text-secondary: #94a3b8;  /* 5.5:1 */
  --text-muted:     #4e5f72;  /* 3:1 – use only for large text */
  --text-on-accent: #1a0a00;

  /* Typography — strict 6-step scale (1.25 ratio) */
  --font-display: 'Syne', system-ui, sans-serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  --text-xs:   0.75rem;    /* 12px — labels, badges, captions */
  --text-sm:   0.875rem;   /* 14px — secondary body, table cells */
  --text-base: 1rem;       /* 16px — primary body */
  --text-lg:   1.125rem;   /* 18px — lead text, question stem */
  --text-xl:   1.375rem;   /* 22px — page titles mobile */
  --text-2xl:  1.75rem;    /* 28px — section heroes */
  --text-3xl:  2.25rem;    /* 36px — score display */
  --text-4xl:  3rem;       /* 48px — landing headlines */

  --leading-tight:  1.25;
  --leading-snug:   1.4;
  --leading-normal: 1.6;
  --leading-relaxed:1.75;

  /* 8-px spatial grid */
  --sp-1:  8px;
  --sp-2:  16px;
  --sp-3:  24px;
  --sp-4:  32px;
  --sp-5:  40px;
  --sp-6:  48px;

  /* Radius tokens */
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  20px;
  --r-2xl: 28px;
  --r-pill:99px;

  /* Legacy aliases (keep for backward compat) */
  --radius:    var(--r-md);
  --radius-lg: var(--r-lg);
  --radius-xl: var(--r-xl);

  /* Touch targets */
  --touch:     52px;
  --touch-min: 44px;

  /* Layout */
  --header-h:      56px;
  --bottom-nav-h:  60px;
  --sidebar-w:     236px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.55);
  --shadow-accent: 0 0 20px rgba(251,146,60,0.18);
  --shadow-up: 0 -4px 20px rgba(0,0,0,0.5);
}

/* ── Reset ──────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html {
  font-size: var(--text-base);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
input, select, textarea {
  font-family: inherit;
  font-size: var(--text-base);
}
a { color: var(--accent); text-decoration: none; }
ul, ol { list-style: none; }
img { max-width: 100%; height: auto; display: block; }
.hidden { display: none !important; }

/* ── Page transitions ───────────────────────── */
#page-content { transition: opacity 0.18s ease, transform 0.18s ease; }
#page-content.page-exit  { opacity: 0; transform: translateY(6px); pointer-events: none; }
#page-content.page-enter { opacity: 0; transform: translateY(6px); animation: pageEnter 0.2s ease forwards; }
@keyframes pageEnter { to { opacity: 1; transform: none; } }
.page-skeleton { display: flex; flex-direction: column; gap: var(--sp-2); padding-top: var(--sp-1); }

/* ── Splash ─────────────────────────────────── */
#splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-4);
  animation: splashFade 0.35s ease 1.9s forwards;
}
@keyframes splashFade { to { opacity: 0; pointer-events: none; } }
.splash-logo { display: flex; align-items: center; gap: var(--sp-2); animation: fadeUp 0.45s ease; }
.splash-icon { width: 48px; height: 48px; color: var(--accent); filter: drop-shadow(0 0 10px rgba(251,146,60,0.45)); }
.splash-name { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 800; letter-spacing: -0.025em; }
.splash-bar  { width: 160px; height: 3px; background: var(--border-strong); border-radius: var(--r-pill); overflow: hidden; }
.splash-fill { height: 100%; width: 0; background: var(--accent); border-radius: var(--r-pill); animation: fillBar 1.6s ease forwards; }
@keyframes fillBar { to { width: 100%; } }
@keyframes fadeUp  { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ── Auth ───────────────────────────────────── */
#auth-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  padding: var(--sp-3) var(--sp-2) max(var(--sp-3), env(safe-area-inset-bottom));
}
.auth-bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.auth-grid-overlay {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(251,146,60,0.025) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(251,146,60,0.025) 1px, transparent 1px);
  background-size: 48px 48px;
}
.auth-orbs { position: absolute; inset: 0; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(72px); opacity: 0.14; animation: orbFloat 9s ease-in-out infinite; }
.orb-1 { width: 480px; height: 480px; background: radial-gradient(circle, #fb923c, transparent); top: -140px; right: -80px; }
.orb-2 { width: 360px; height: 360px; background: radial-gradient(circle, #38bdf8, transparent); bottom: -80px; left: -60px; animation-delay: 3s; }
.orb-3 { width: 280px; height: 280px; background: radial-gradient(circle, #a78bfa, transparent); top: 38%; left: 38%; animation-delay: 6s; }
@keyframes orbFloat { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(12px, -14px); } }

.auth-container {
  position: relative; z-index: 1; width: 100%; max-width: 400px;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
}
.auth-brand { display: flex; align-items: center; gap: var(--sp-2); animation: fadeUp 0.45s ease; }
.brand-icon { width: 40px; height: 40px; color: var(--accent); filter: drop-shadow(0 0 8px rgba(251,146,60,0.35)); }
.brand-name { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 800; letter-spacing: -0.025em; }
.brand-tagline { font-size: var(--text-xs); color: var(--text-secondary); margin-top: 2px; letter-spacing: 0.04em; }

.auth-card {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2xl);
  padding: var(--sp-3);
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.45s ease 0.08s both;
}
.auth-tabs {
  display: flex; gap: 4px;
  background: var(--bg-base);
  border-radius: var(--r-sm);
  padding: 4px;
  margin-bottom: var(--sp-2);
}
.auth-tab {
  flex: 1; padding: 10px 0; font-size: var(--text-base); font-weight: 500;
  border-radius: 6px /* intentional — inner tab */; color: var(--text-secondary);
  transition: background 0.2s, color 0.2s; min-height: var(--touch-min);
}
.auth-tab.active { background: var(--bg-highlight); color: var(--text-primary); }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-2); }
.auth-error-global {
  margin-top: var(--sp-2); padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-md); background: var(--danger-dim);
  border: 1px solid rgba(248,113,113,0.2); color: var(--danger);
  font-size: var(--text-sm); text-align: center; line-height: var(--leading-snug);
}
.auth-footer-note { font-size: var(--text-sm); color: var(--text-muted); text-align: center; animation: fadeUp 0.45s ease 0.16s both; }

/* ── Forms ──────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: var(--text-xs); font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.07em;
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-input);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 13px var(--sp-2);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  width: 100%;
  min-height: var(--touch);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-group input:disabled,
.form-group select:disabled { opacity: 0.45; cursor: not-allowed; }
.field-error { font-size: var(--text-xs); color: var(--danger); min-height: 16px; }
.optional { color: var(--text-muted); font-weight: 400; font-style: italic; }

/* ── Buttons ────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: var(--text-base);
  padding: 13px var(--sp-3);
  border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1);
  transition: background 0.15s, transform 0.1s, box-shadow 0.2s;
  border: none; min-height: var(--touch);
  touch-action: manipulation;
  letter-spacing: 0.01em;
  will-change: transform;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-bright);
  transform: translateY(-1px);
  box-shadow: var(--shadow-accent);
}
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary.btn-full { width: 100%; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-loader {
  width: 18px; height: 18px; flex-shrink: 0;
  border: 2px solid rgba(26,10,0,0.25);
  border-top-color: var(--text-on-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-secondary {
  background: var(--bg-highlight);
  color: var(--text-primary);
  font-weight: 500;
  font-size: var(--text-sm);
  padding: 11px var(--sp-2);
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1);
  transition: background 0.15s, border-color 0.15s;
  min-height: var(--touch); touch-action: manipulation;
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); border-color: var(--border-accent); }
.btn-secondary:active:not(:disabled) { transform: scale(0.98); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  padding: 9px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 6px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  min-height: var(--touch-min); touch-action: manipulation;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-highlight); }

.btn-forgot {
  font-size: var(--text-sm); color: var(--text-secondary); text-align: right;
  align-self: flex-end; padding: 4px; min-height: auto; transition: color 0.15s;
}
.btn-forgot:hover { color: var(--accent); }

.auth-divider {
  display: flex; align-items: center; gap: var(--sp-2);
  color: var(--text-muted); font-size: var(--text-sm);
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.btn-google {
  width: 100%; padding: 13px; border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-input); color: var(--text-primary);
  font-size: var(--text-base); font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: var(--sp-1);
  transition: background 0.15s, border-color 0.15s;
  min-height: var(--touch); touch-action: manipulation;
}
.btn-google:hover { background: var(--bg-highlight); border-color: var(--border-accent); }

/* ── Header ─────────────────────────────────── */
#app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: rgba(12,15,28,0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 max(var(--sp-2), env(safe-area-inset-left)) 0 max(var(--sp-2), env(safe-area-inset-right));
  contain: layout style;
}
.header-inner { width: 100%; display: flex; align-items: center; gap: var(--sp-1); }
.header-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; flex-shrink: 0;
  min-height: var(--touch-min); align-self: center;
}
.header-logo svg { width: 26px; height: 26px; color: var(--accent); }
.header-logo-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.header-nav { display: flex; align-items: center; gap: 2px; margin-left: var(--sp-2); }
.header-nav-item {
  display: flex; align-items: center; gap: 6px; padding: 7px 11px;
  border-radius: var(--r-md); font-size: var(--text-sm); font-weight: 500;
  color: var(--text-secondary); transition: color 0.15s, background 0.15s;
  min-height: var(--touch-min); touch-action: manipulation;
}
.header-nav-item:hover  { color: var(--text-primary); background: var(--bg-highlight); }
.header-nav-item.active { color: var(--accent); background: var(--accent-dim); }
.header-spacer { flex: 1; }

.header-streak {
  display: flex; align-items: center; gap: 5px;
  background: var(--warning-dim); border: 1px solid rgba(251,191,36,0.18);
  border-radius: var(--r-pill); padding: 5px 10px;
  font-size: var(--text-xs); font-weight: 700; color: var(--warning);
  white-space: nowrap;
}
.header-xp {
  display: flex; align-items: center; gap: 5px;
  background: var(--blue-dim); border: 1px solid rgba(56,189,248,0.18);
  border-radius: var(--r-pill); padding: 5px 10px;
  font-size: var(--text-xs); font-weight: 700; color: var(--blue);
  white-space: nowrap;
}
.header-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #c2410c);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-xs); color: var(--text-on-accent);
  cursor: pointer; transition: opacity 0.15s; touch-action: manipulation;
}
.header-avatar:hover { opacity: 0.88; }

.header-dropdown {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); padding: var(--sp-1);
  min-width: 208px; box-shadow: var(--shadow-lg);
  animation: dropIn 0.14s ease;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dropdown-item {
  display: flex; align-items: center; gap: var(--sp-1); padding: 11px 13px;
  border-radius: var(--r-sm); font-size: var(--text-sm); color: var(--text-secondary);
  transition: background 0.1s, color 0.1s; cursor: pointer; width: 100%;
  min-height: var(--touch);
}
.dropdown-item:hover { background: var(--bg-highlight); color: var(--text-primary); }
.dropdown-item.danger:hover { background: var(--danger-dim); color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

.header-mobile-menu {
  display: none; flex-direction: column; gap: 5px;
  width: 40px; height: 40px; cursor: pointer; padding: 10px;
  align-items: center; justify-content: center; border-radius: var(--r-sm);
}
.header-mobile-menu span { height: 2px; width: 20px; background: var(--text-primary); border-radius: var(--r-pill); transition: all 0.3s; }

/* ── Bottom Navigation ──────────────────────── */
#bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(12,15,28,0.97);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  contain: layout style;
}
.bottom-nav-inner {
  display: flex; align-items: stretch;
  height: 100%; width: 100%;
  max-width: 520px; margin: 0 auto;
}
.bottom-nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
  -webkit-tap-highlight-color: transparent;
  color: var(--text-muted); font-size: 0.6875rem; font-weight: 500;
  transition: color 0.15s; cursor: pointer;
  border-radius: 0; min-height: auto; padding: 0 4px;
  touch-action: manipulation; letter-spacing: 0.03em;
  position: relative;
}
.bottom-nav-btn svg { width: 22px; height: 22px; transition: transform 0.15s; }
.bottom-nav-btn.active { color: var(--accent); }
.bottom-nav-btn.active svg { transform: scale(1.1); }
.bottom-nav-btn.active::after {
  content: ''; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
.bottom-nav-btn:active svg { transform: scale(0.88); }

/* ── App layout ─────────────────────────────── */
.app-layout { display: flex; min-height: calc(100dvh - var(--header-h)); }

/* ── Sidebar ────────────────────────────────── */
#app-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-surface); border-right: 1px solid var(--border);
  height: calc(100dvh - var(--header-h));
  position: sticky; top: var(--header-h);
  overflow-y: auto; padding: var(--sp-1) var(--sp-1);
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  contain: layout style;
}
.sidebar-section-label {
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text-muted);
  padding: var(--sp-1) var(--sp-1) 4px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 9px; padding: 10px var(--sp-1);
  border-radius: var(--r-sm); font-size: var(--text-sm); font-weight: 500;
  color: var(--text-secondary); transition: background 0.1s, color 0.1s;
  cursor: pointer; width: 100%; text-align: left;
  min-height: var(--touch-min); touch-action: manipulation; position: relative;
}
.sidebar-item:hover  { background: var(--bg-highlight); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent-dim); color: var(--accent); }
.sidebar-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 56%; background: var(--accent); border-radius: 0 3px 3px 0;
}
.sidebar-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-badge {
  margin-left: auto; background: var(--accent); color: var(--text-on-accent);
  font-size: var(--text-xs); font-weight: 700; padding: 2px 6px; border-radius: var(--r-pill);
}
.sidebar-separator { height: 1px; background: var(--border); margin: var(--sp-1) 4px; }

/* ── Main content ───────────────────────────── */
#app-main {
  flex: 1; min-width: 0;
  padding: var(--sp-3) var(--sp-2);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
}
#page-content { max-width: 1080px; margin: 0 auto; }

/* ── Page header ────────────────────────────── */
.page-header { margin-bottom: var(--sp-3); scroll-margin-top: 64px; }
.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: var(--leading-tight);
  color: var(--text-primary);
}
.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: var(--leading-normal);
}

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-2);
  contain: layout style paint;
}
.card-sm { padding: var(--sp-1) 13px; }

.mb-8  { margin-bottom: var(--sp-1); }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: var(--sp-2); }
.mb-18 { margin-bottom: 18px; }
.mb-20 { margin-bottom: 20px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: var(--sp-2); }
.mt-20 { margin-top: 20px; }
.w-full { width: 100%; }

/* ── Stats grid ─────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2); margin-bottom: var(--sp-3);
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-2);
  position: relative; overflow: hidden;
  transition: border-color 0.2s;
  contain: layout style paint;
}
.stat-card::after {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.orange::after { background: linear-gradient(90deg, var(--accent), transparent); }
.stat-card.blue::after   { background: linear-gradient(90deg, var(--blue), transparent); }
.stat-card.green::after  { background: linear-gradient(90deg, var(--success), transparent); }
.stat-card.purple::after { background: linear-gradient(90deg, var(--purple), transparent); }
.stat-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-base); margin-bottom: var(--sp-1);
}
.stat-card.orange .stat-icon { background: var(--accent-dim); }
.stat-card.blue   .stat-icon { background: var(--blue-dim); }
.stat-card.green  .stat-icon { background: var(--success-dim); }
.stat-card.purple .stat-icon { background: var(--purple-dim); }
.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-label { font-size: var(--text-xs); color: var(--text-secondary); margin-top: 4px; }

/* ── Dashboard grid ─────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 288px; gap: var(--sp-3); }
.section-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: var(--sp-2);
  display: flex; align-items: center; gap: var(--sp-1);
  color: var(--text-primary);
}

/* ── Daily quiz card ────────────────────────── */
.daily-quiz-card {
  background: linear-gradient(135deg, #140b00, #261500);
  border: 1px solid var(--border-accent);
  border-radius: var(--r-lg);
  padding: var(--sp-2);
  position: relative; overflow: hidden;
  margin-bottom: var(--sp-2);
}
.daily-quiz-card::before {
  content: ''; position: absolute;
  top: -48px; right: -48px; width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(251,146,60,0.12), transparent);
  border-radius: 50%; pointer-events: none;
}
.daily-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(251,146,60,0.12);
  border: 1px solid rgba(251,146,60,0.22);
  color: var(--accent-bright);
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase;
  padding: 3px 9px; border-radius: var(--r-pill);
  margin-bottom: var(--sp-1);
}
.daily-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: 5px;
  line-height: var(--leading-tight);
}
.daily-sub  { font-size: var(--text-sm); color: rgba(255,220,180,0.75); margin-bottom: var(--sp-2); }
.daily-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.daily-meta-item { font-size: var(--text-xs); color: var(--text-secondary); display: flex; align-items: center; gap: 5px; }

/* ── Subject cards ──────────────────────────── */
.subjects-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-1); }
.subject-card {
  background: var(--bg-highlight); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 13px;
  display: flex; align-items: center; gap: var(--sp-1);
  cursor: pointer; transform: translateY(0); transition: border-color 0.15s, background 0.15s;
  min-height: var(--touch); touch-action: manipulation;
}
.subject-card:hover  { border-color: var(--border-accent); background: var(--bg-card-hover); }
.subject-card:active { transform: scale(0.97); background: var(--bg-highlight); }
.subject-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.subject-icon  { font-size: var(--text-xl); flex-shrink: 0; }
.subject-name  { font-size: var(--text-sm); font-weight: 600; line-height: var(--leading-snug); }
.subject-count { font-size: var(--text-xs); color: var(--text-muted); margin-top: 1px; }

/* ── Progress bar ───────────────────────────── */
.progress-bar {
  height: 6px; background: var(--bg-highlight);
  border-radius: var(--r-pill); overflow: hidden;
  margin-top: var(--sp-1);
}
.progress-fill {
  height: 100%; border-radius: var(--r-pill);
  transition: width 0.55s ease;
}
.progress-fill.orange { background: var(--accent); }
.progress-fill.blue   { background: var(--blue); }
.progress-fill.green  { background: var(--success); }

/* ── Test UI ────────────────────────────────── */
.test-layout { display: grid; grid-template-columns: 1fr 256px; gap: var(--sp-3); align-items: start; }
.test-main   { min-width: 0; }

.test-header {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 13px var(--sp-2);
  margin-bottom: var(--sp-2); flex-wrap: wrap;
}
.test-title   { font-family: var(--font-display); font-size: var(--text-sm); font-weight: 700; }
.test-timer {
  font-family: var(--font-mono); font-size: var(--text-base); font-weight: 600;
  background: var(--bg-highlight); border: 1px solid var(--border-strong);
  color: var(--text-primary); padding: 7px 13px;
  border-radius: var(--r-sm); flex-shrink: 0; white-space: nowrap;
  transition: background 0.3s, color 0.3s;
}
.test-timer.warning {
  background: var(--danger-dim); border-color: rgba(248,113,113,0.28); color: var(--danger);
  animation: timerPulse 1s ease-in-out infinite;
}
.test-timer.critical {
  background: var(--danger); color: #fff; border-color: var(--danger);
  animation: timerPulse 0.4s ease-in-out infinite;
  font-weight: 900;
}
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.65; } }

.question-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.question-meta { display: flex; gap: 6px; margin-bottom: var(--sp-1); flex-wrap: wrap; }
.q-badge {
  font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px var(--sp-1); border-radius: var(--r-pill);
}
.q-badge.subject            { background: var(--blue-dim);    color: var(--blue);    border: 1px solid rgba(56,189,248,0.18); }
.q-badge.topic              { background: var(--accent-dim);  color: var(--accent);  border: 1px solid var(--border-accent); }
.q-badge.difficulty-easy   { background: var(--success-dim); color: var(--success); border: 1px solid rgba(74,222,128,0.18); }
.q-badge.difficulty-medium { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(251,191,36,0.18); }
.q-badge.difficulty-hard   { background: var(--danger-dim);  color: var(--danger);  border: 1px solid rgba(248,113,113,0.18); }
.question-number { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono); margin-bottom: var(--sp-1); }
.question-text   { font-size: var(--text-lg); line-height: var(--leading-relaxed); font-weight: 400; }

/* Options */
.options-list { display: flex; flex-direction: column; gap: var(--sp-1); margin-top: var(--sp-2); }
.option-item {
  padding: 14px var(--sp-2); border-radius: var(--r-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-input); cursor: pointer;
  display: flex; align-items: flex-start; gap: var(--sp-2);
  transition: border-color 0.12s, background 0.12s;
  font-size: var(--text-base); line-height: var(--leading-snug);
  user-select: none; min-height: var(--touch); touch-action: manipulation;
}
.option-item:hover:not(.correct):not(.wrong) { border-color: var(--accent); background: var(--accent-glow); }
.option-item:active:not(.correct):not(.wrong) { transform: scale(0.99); background: var(--accent-glow); }
.option-item.selected { border-color: var(--accent); background: var(--accent-dim); }
.option-item.correct  { border-color: var(--success); background: var(--success-dim); cursor: default; }
.option-item.wrong    { border-color: var(--danger);  background: var(--danger-dim);  cursor: default; }
.option-item.missed   { border-color: var(--warning); background: var(--warning-dim); cursor: default; }
.option-letter {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
  background: var(--bg-highlight); border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 700; font-family: var(--font-mono);
  transition: background 0.12s, border-color 0.12s; margin-top: 2px;
}
.option-item.selected .option-letter { background: var(--accent);  border-color: var(--accent);  color: var(--text-on-accent); }
.option-item.correct  .option-letter { background: var(--success); border-color: var(--success); color: #0a0f1e; }
.option-item.wrong    .option-letter { background: var(--danger);  border-color: var(--danger);  color: #fff; }

.explanation-box {
  background: var(--bg-highlight); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent); border-radius: var(--r-md);
  padding: var(--sp-2); margin-top: var(--sp-2);
  font-size: var(--text-sm); line-height: var(--leading-relaxed);
  color: var(--text-secondary); animation: fadeUp 0.22s ease;
}
.explanation-label {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--accent); margin-bottom: var(--sp-1);
}

/* Test nav */
.test-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-1); margin-top: var(--sp-2); flex-wrap: wrap;
}
.test-nav-actions { display: flex; align-items: center; gap: var(--sp-1); }
.btn-review {
  background: var(--warning-dim); border: 1px solid rgba(251,191,36,0.2); color: var(--warning);
  font-size: var(--text-sm); font-weight: 500; padding: 10px 14px; border-radius: var(--r-md);
  display: inline-flex; align-items: center; gap: 5px;
  transition: background 0.15s; min-height: var(--touch-min); touch-action: manipulation;
}
.btn-review:hover { background: rgba(251,191,36,0.16); }

/* Palette */
.palette-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-2);
  position: sticky; top: calc(var(--header-h) + var(--sp-2));
}
.palette-title  { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--sp-1); }
.palette-legend { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--sp-2); }
.legend-item    { display: flex; align-items: center; gap: var(--sp-1); font-size: var(--text-xs); color: var(--text-secondary); }
.legend-dot     { width: 10px; height: 10px; border-radius: 3px /* intentional — indicator bar */; flex-shrink: 0; }
.legend-dot.answered     { background: var(--success); }
.legend-dot.not-answered { background: var(--danger); }
.legend-dot.review       { background: var(--warning); }
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.palette-btn {
  aspect-ratio: 1; border-radius: var(--r-sm); font-size: var(--text-xs); font-weight: 600;
  font-family: var(--font-mono); background: var(--bg-highlight); border: 1px solid var(--border);
  color: var(--text-muted); transition: background 0.1s, color 0.1s;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  min-height: 40px; touch-action: manipulation;
}
.palette-btn.current      { border-color: var(--accent);  color: var(--accent);  background: var(--accent-glow); box-shadow: 0 0 0 2px var(--accent); font-weight: 800; }
.palette-btn.answered     { background: var(--success-dim); border-color: rgba(74,222,128,0.25); color: var(--success); }
.palette-btn.not-answered { background: var(--danger-dim);  border-color: rgba(248,113,113,0.25); color: var(--danger); }
.palette-btn.review       { background: var(--warning-dim); border-color: rgba(251,191,36,0.25);  color: var(--warning); }
.palette-submit-btn {
  width: 100%; margin-top: var(--sp-1);
  background: var(--success); color: #0a0f1e;
  font-weight: 700; padding: 11px; border-radius: var(--r-sm);
  font-size: var(--text-sm); transition: background 0.15s;
  min-height: var(--touch); touch-action: manipulation;
}
.palette-submit-btn:hover { background: #86efac; }

/* Palette toggle — hidden on desktop, shown by mobile CSS */
.palette-toggle         { display: none; }
.palette-inner          { padding: var(--sp-1) var(--sp-2) var(--sp-2); }
.palette-toggle-chevron { flex-shrink: 0; }

/* ── Results ────────────────────────────────── */
.results-screen { max-width: 600px; margin: 0 auto; text-align: center; }
.results-circle {
  width: 136px; height: 136px; border-radius: 50%;
  border: 8px solid var(--bg-highlight);
  margin: 0 auto var(--sp-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg-card);
}
.results-score       { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 800; letter-spacing: -0.02em; }
.results-score-label { font-size: var(--text-xs); color: var(--text-muted); }
.results-stats-row   { display: flex; gap: var(--sp-1); justify-content: center; flex-wrap: wrap; margin: var(--sp-2) 0; }
.result-stat {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 11px 14px; text-align: center; min-width: 72px;
}
.result-stat-val { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 700; }
.result-stat-lbl { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

/* ── Analytics ──────────────────────────────── */
.analytics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); margin-top: var(--sp-2); }
.topic-row {
  display: flex; align-items: center; gap: var(--sp-1);
  padding: 11px 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topic-row:last-child { border-bottom: none; }
.topic-name { flex: 1; min-width: 100px; font-size: var(--text-sm); }
.topic-acc  {
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  width: 40px; text-align: right; flex-shrink: 0;
}

/* ── Leaderboard ────────────────────────────── */
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th {
  text-align: left; font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted);
  padding: 0 var(--sp-1) var(--sp-1);
}
.lb-table td { padding: 11px var(--sp-1); font-size: var(--text-sm); border-bottom: 1px solid var(--border); }
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: var(--bg-highlight); }
.lb-rank { font-family: var(--font-mono); font-weight: 700; color: var(--text-muted); }
.lb-rank.gold   { color: var(--warning); }
.lb-rank.silver { color: var(--text-secondary); }
.lb-rank.bronze { color: var(--accent); }
.lb-avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #c2410c);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 700; color: var(--text-on-accent); flex-shrink: 0;
}
.lb-xp { font-family: var(--font-mono); font-weight: 600; color: var(--blue); }

/* ── Admin ──────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.admin-tab-bar {
  display: flex; gap: 4px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 4px;
  margin-bottom: var(--sp-2);
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.admin-tab-bar::-webkit-scrollbar { display: none; }
.admin-tab {
  padding: 9px var(--sp-2); font-size: var(--text-sm); font-weight: 500;
  border-radius: var(--r-sm); color: var(--text-secondary); white-space: nowrap;
  transition: background 0.15s, color 0.15s; min-height: var(--touch-min); touch-action: manipulation;
}
.admin-tab.active { background: var(--bg-card); color: var(--text-primary); }
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left; padding: 9px var(--sp-1); font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); background: var(--bg-surface); white-space: nowrap;
}
.data-table td { padding: 11px var(--sp-1); border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--bg-highlight); }
.badge { display: inline-flex; padding: 2px 7px; border-radius: var(--r-pill); font-size: 0.6875rem; font-weight: 700; }
.badge-green { background: var(--success-dim); color: var(--success); }
.badge-red   { background: var(--danger-dim);  color: var(--danger); }
.badge-amber { background: var(--accent-dim);  color: var(--accent); }
.badge-blue  { background: var(--blue-dim);    color: var(--blue); }

/* ── Onboarding ─────────────────────────────── */
#onboarding-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(7,9,15,0.94);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-2);
}
.onboarding-card {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--r-2xl); padding: var(--sp-3) var(--sp-3);
  width: 100%; max-width: 500px;
  animation: fadeUp 0.35s ease;
  max-height: 90dvh; overflow-y: auto;
}
.onboarding-step-indicator { display: flex; gap: 6px; margin-bottom: var(--sp-3); }
.step-dot { height: 3px; border-radius: var(--r-pill); background: var(--border-strong); flex: 1; transition: background 0.3s; }
.step-dot.done   { background: var(--accent); }
.step-dot.active { background: var(--accent); opacity: 0.5; }
.onboarding-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 800; margin-bottom: var(--sp-1); line-height: var(--leading-tight); }
.onboarding-sub   { color: var(--text-secondary); font-size: var(--text-sm); margin-bottom: var(--sp-2); line-height: var(--leading-normal); }
.option-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-1); }
.select-option {
  padding: 13px; border-radius: var(--r-md);
  border: 1.5px solid var(--border-strong); background: var(--bg-input);
  cursor: pointer; text-align: center;
  transition: border-color 0.15s, background 0.15s;
  font-size: var(--text-sm); font-weight: 500;
  min-height: var(--touch); touch-action: manipulation;
}
.select-option:hover    { border-color: var(--accent); background: var(--accent-glow); }
.select-option.selected { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.opt-icon { font-size: var(--text-xl); margin-bottom: 5px; }

/* ── Modals ─────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(7,9,15,0.82);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.18s ease;
}
@media (min-width: 600px) { .modal-overlay { align-items: center; padding: var(--sp-3); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--sp-3);
  width: 100%; box-shadow: var(--shadow-lg);
  animation: slideUp 0.24s ease;
  max-height: 90dvh; overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
}
@media (min-width: 600px) { .modal-box { border-radius: var(--r-xl); max-width: 460px; animation: fadeUp 0.22s ease; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: none; } }
.modal-title   { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--sp-1); }
.modal-sub     { color: var(--text-secondary); font-size: var(--text-sm); margin-bottom: var(--sp-2); line-height: var(--leading-normal); }
.modal-actions { display: flex; gap: var(--sp-1); margin-top: var(--sp-2); justify-content: flex-end; flex-wrap: wrap; }

/* ── Toasts ─────────────────────────────────── */
#toast-root {
  position: fixed; bottom: var(--sp-3); right: var(--sp-2);
  z-index: 1000; display: flex; flex-direction: column; gap: var(--sp-1);
  align-items: flex-end; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-1);
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: 12px var(--sp-2);
  box-shadow: var(--shadow-lg); min-width: 256px; max-width: 340px;
  animation: toastIn 0.22s ease; pointer-events: all; cursor: pointer;
  will-change: transform, opacity;
}
@keyframes toastIn  { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.toast.fadeout { animation: toastOut 0.22s ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(16px); } }
.toast-icon { font-size: var(--text-base); flex-shrink: 0; }
.toast-text { font-size: var(--text-sm); flex: 1; line-height: var(--leading-snug); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--blue); }
.toast.warning { border-left: 3px solid var(--warning); }

/* ── Referral ───────────────────────────────── */
.referral-box {
  background: linear-gradient(135deg, var(--bg-highlight), var(--bg-card));
  border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: var(--sp-2);
}
.referral-code-display {
  display: flex; align-items: center; gap: var(--sp-1);
  background: var(--bg-input); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: 13px var(--sp-2);
  font-family: var(--font-mono); font-size: var(--text-lg); font-weight: 600;
  color: var(--accent); margin: var(--sp-2) 0; flex-wrap: wrap;
}
.referral-code-display button {
  margin-left: auto; font-size: var(--text-sm); color: var(--text-secondary);
  background: var(--bg-highlight); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 7px 13px;
  transition: all 0.15s; min-height: var(--touch-min); touch-action: manipulation;
}
.referral-code-display button:hover { color: var(--accent); border-color: var(--border-accent); }
.referral-stats { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); flex-wrap: wrap; }
.ref-stat { flex: 1; min-width: 72px; text-align: center; }
.ref-stat-val { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 800; }
.ref-stat-lbl { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

/* ── Skeleton / Loading ─────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-highlight) 25%, var(--bg-card-hover) 50%, var(--bg-highlight) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-md);
  will-change: background-position;
}
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.75s linear infinite; flex-shrink: 0; will-change: transform;
}
.page-loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; gap: var(--sp-1); color: var(--text-muted); font-size: var(--text-sm);
}

/* ── Empty states ───────────────────────────── */
.empty-state { text-align: center; padding: var(--sp-6) var(--sp-3); color: var(--text-muted); }
.empty-state-icon  { font-size: var(--text-3xl); margin-bottom: var(--sp-2); opacity: 0.45; }
.empty-state-title { font-size: var(--text-base); font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.empty-state-text  { font-size: var(--text-sm); line-height: var(--leading-normal); }

/* ── Landing / SEO ──────────────────────────── */
.landing-hero { text-align: center; padding: var(--sp-6) var(--sp-3) var(--sp-5); }
.landing-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(var(--text-2xl), 5vw, 3rem);
  font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin-bottom: var(--sp-2);
}
.landing-hero p  {
  font-size: clamp(var(--text-sm), 2vw, var(--text-lg));
  color: var(--text-secondary); max-width: 580px; margin: 0 auto var(--sp-4);
  line-height: var(--leading-relaxed);
}
.landing-cta-group { display: flex; gap: var(--sp-1); justify-content: center; flex-wrap: wrap; }

/* ── Error boundary ─────────────────────────── */
.error-boundary {
  display: flex; align-items: center; justify-content: center;
  min-height: 50vh; padding: var(--sp-4);
}

/* ── Retention / Celebration ────────────────── */
@keyframes badgePop   { from { opacity: 0; transform: scale(0.5) rotate(-10deg); } to { opacity: 1; transform: scale(1) rotate(0deg); } }
@keyframes levelUpPop { from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.8); } to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes confettiFall { from { opacity: 1; transform: translateY(0) rotate(0deg); } to { opacity: 0; transform: translateY(72px) rotate(360deg); } }
@keyframes pulseGlow  { 0%, 100% { box-shadow: 0 0 0 0 rgba(251,146,60,0.35); } 50% { box-shadow: 0 0 0 7px rgba(251,146,60,0); } }
@keyframes fadeOut    { to { opacity: 0; transform: translateX(-50%) translateY(-10px); } }

/* ── Utilities ──────────────────────────────── */
.text-sm        { font-size: var(--text-sm); }
.text-xs        { font-size: var(--text-xs); }
.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent    { color: var(--accent); }
.text-success   { color: var(--success); }
.text-danger    { color: var(--danger); }
.text-center    { text-align: center; }
.font-mono      { font-family: var(--font-mono); }
.font-display   { font-family: var(--font-display); }
.truncate       { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */

/* ── Palette collapse token ─────────────────── */
:root {
  --palette-toggle-h: 48px; /* height of the collapsed palette handle bar */
}

/* Tablet ≤1100px */
@media (max-width: 1100px) {
  .stats-grid     { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .admin-grid     { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════
   Mobile ≤768px — primary mobile layout
   ══════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── App shell ── */
  #app-main {
    padding: var(--sp-2) var(--sp-2);
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--sp-2));
  }
  #bottom-nav  { display: block; }
  #app-sidebar { display: none; }
  .header-nav    { display: none; }
  .header-streak { display: none; }
  .header-xp     { display: none; }

  /* ── Toasts slide up from nav ── */
  #toast-root {
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--sp-1));
    right: 0; left: 0; align-items: stretch; padding: 0 var(--sp-2);
  }
  .toast { min-width: unset; max-width: unset; }
  @keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
  }

  /* ── Sidebar drawer ── */
  #app-sidebar.mobile-open {
    display: flex; position: fixed; left: 0; top: var(--header-h);
    height: calc(100dvh - var(--header-h)); z-index: 300;
    width: min(var(--sidebar-w), 78vw);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
  }
  @keyframes slideIn {
    from { transform: translateX(-100%); }
    to   { transform: none; }
  }
  #app-sidebar.mobile-open::after {
    content: ''; position: fixed;
    left: min(var(--sidebar-w), 78vw); top: 0; right: 0; bottom: 0;
    background: rgba(7,9,15,0.6); z-index: -1;
    animation: fadeIn 0.2s ease;
  }

  /* ── Page chrome ── */
  .page-header { margin-bottom: var(--sp-2); }
  .page-title  { font-size: var(--text-xl); }

  /* ── Stats chips — horizontal scroll ── */
  .stats-grid {
    grid-template-columns: repeat(4, minmax(108px, 1fr));
    overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: var(--sp-1); padding-bottom: 4px;
    margin-bottom: var(--sp-2);
    /* Snap to stat card boundaries */
    scroll-snap-type: x mandatory;
  }
  .stats-grid::-webkit-scrollbar { display: none; }
  .stat-card { min-width: 108px; scroll-snap-align: start; }

  .subjects-grid { gap: var(--sp-1); }

  /* ── Test layout ─────────────────────────── */
  .test-layout { grid-template-columns: 1fr; }

  /* Palette toggle bar visible on mobile */
  .palette-toggle {
    display: flex;
  }

  /* Collapsible question palette
     Default: collapsed (shows only toggle bar)
     .palette-card.expanded: full height */
  .palette-card {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    left: 0; right: 0; z-index: 150;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: none;
    box-shadow: var(--shadow-up);
    /* Collapsed: show only the toggle handle */
    max-height: var(--palette-toggle-h);
    overflow: hidden;
    transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    contain: layout style;
  }
  .palette-card.expanded {
    max-height: 46vh;
    overflow-y: auto;
  }
  .palette-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--palette-toggle-h);
    padding: 0 var(--sp-2);
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    flex-shrink: 0;
  }
  .palette-toggle-left {
    display: flex; align-items: center; gap: var(--sp-1);
    font-size: var(--text-xs); font-weight: 700;
    color: var(--text-secondary);
  }
  .palette-toggle-progress {
    display: flex; align-items: center; gap: 5px;
    font-size: var(--text-xs); font-weight: 600;
  }
  .palette-toggle-chevron {
    width: 16px; height: 16px;
    transition: transform 0.25s ease;
    color: var(--text-muted);
  }
  .palette-card.expanded .palette-toggle-chevron {
    transform: rotate(180deg);
  }
  .palette-inner {
    padding: 0 var(--sp-2) var(--sp-2);
  }
  .palette-legend { display: none; }
  .palette-grid   { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; }
  .palette-btn    { min-height: 36px; font-size: 0.6875rem; }
  .palette-title  { display: none; } /* replaced by toggle bar */

  /* Test nav sits directly above palette toggle */
  .test-nav {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--palette-toggle-h));
    left: 0; right: 0; z-index: 140;
    background: rgba(10,13,24,0.97);
    border-top: 1px solid var(--border);
    padding: 10px var(--sp-2);
    display: flex; align-items: center; gap: var(--sp-1);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }
  .test-nav > .btn-secondary {
    flex: 0 0 auto;
    min-height: var(--touch);
    padding: 10px 14px;
  }
  .test-nav-actions {
    flex: 1; display: flex; gap: var(--sp-1); justify-content: flex-end;
  }
  .test-nav-actions .btn-review  { flex: 1; justify-content: center; min-height: var(--touch); }
  .test-nav-actions .btn-primary { flex: 0 0 auto; min-width: 80px; min-height: var(--touch); }

  /* Content scroll area: above nav + palette toggle */
  .test-main {
    padding-bottom: calc(
      var(--bottom-nav-h) +
      env(safe-area-inset-bottom) +
      var(--palette-toggle-h) +
      52px  /* test-nav bar height */
    );
  }

  /* Question card */
  .question-card  { padding: var(--sp-2); margin-bottom: var(--sp-1); }
  .question-text  { font-size: var(--text-base); line-height: var(--leading-relaxed); }
  .question-meta  { flex-wrap: wrap; gap: 4px; }
  .q-badge        { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Options — larger tap targets */
  .option-item  { padding: 14px var(--sp-2); min-height: var(--touch); }
  .option-letter { width: 28px; height: 28px; flex-shrink: 0; }

  /* Test header — no progress bar margin collapse */
  .test-header {
    padding: 10px var(--sp-2);
    margin-bottom: var(--sp-1);
    flex-wrap: nowrap;
    gap: var(--sp-1);
    min-height: 52px;
  }
  .test-header > div:nth-child(2) {
    flex: 1; margin: 0 8px; min-width: 0;
  }
  .test-title { font-size: var(--text-xs); }

  /* ── Modals ── */
  .modal-overlay { align-items: flex-end; }
  .results-stats-row { gap: var(--sp-1); }
  .result-stat { min-width: 60px; padding: 10px var(--sp-1); }

  /* ── Admin ── */
  .admin-tab-bar {
    /* Show scrollability hint via fade */
    -webkit-mask-image: linear-gradient(to right, black 88%, transparent 100%);
    mask-image: linear-gradient(to right, black 88%, transparent 100%);
    /* Hint that more tabs exist via fade + padding */
    padding-right: var(--sp-3);
  }
}

/* ══════════════════════════════════════════════
   Small phone ≤480px
   ══════════════════════════════════════════════ */
@media (max-width: 480px) {
  :root { --header-h: 52px; }

  #app-main { padding: var(--sp-2) var(--sp-1); }
  .page-title { font-size: var(--text-xl); }

  /* Stats: 2-col grid instead of horizontal scroll */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    overflow-x: unset;
    scroll-snap-type: none;
  }
  .stat-card  { min-width: unset; }
  .stat-value { font-size: var(--text-xl); }

  .admin-grid     { grid-template-columns: repeat(2, 1fr); }
  .analytics-grid { grid-template-columns: 1fr; }

  .modal-box {
    padding: var(--sp-2);
    padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom));
  }

  /* Tighter option items */
  .option-letter { width: 26px; height: 26px; font-size: 0.6875rem; }
  .option-item   { gap: 10px; padding: 13px var(--sp-1); }

  .subjects-grid { grid-template-columns: 1fr; }

  /* Results */
  .results-circle { width: 108px; height: 108px; border-width: 6px; }
  .results-score  { font-size: var(--text-2xl); }

  /* Bottom nav: icon only */
  .bottom-nav-btn span { display: none; }
  .bottom-nav-btn { gap: 0; }

  /* Auth card: reduce horizontal padding */
  .auth-card { padding: var(--sp-2); }

  /* Onboarding: tighten padding */
  .onboarding-card { padding: var(--sp-2); }
}

/* ══════════════════════════════════════════════
   Very small ≤360px
   ══════════════════════════════════════════════ */
@media (max-width: 360px) {
  :root { --header-h: 48px; }
  #app-main { padding: var(--sp-1); }
  .stats-grid    { grid-template-columns: 1fr; }
  .admin-grid    { grid-template-columns: 1fr; }
  .option-grid   { grid-template-columns: 1fr; }
  .subjects-grid { grid-template-columns: 1fr; }
  .modal-box     { padding: var(--sp-1); }
  .question-card { padding: var(--sp-1); }
  .option-item   { padding: 12px var(--sp-1); gap: 8px; }
  .option-letter { width: 24px; height: 24px; }
}

/* ── Daily nav accent dot ───────────────────── */
.bottom-nav-btn[data-route="daily"]::before {
  content: '';
  position: absolute;
  top: 6px; right: 10px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
  animation: dailyPulse 2.5s ease-in-out infinite;
}
.bottom-nav-btn[data-route="daily"].active::before { display: none; }
@keyframes dailyPulse {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50%       { opacity: 0.4;  transform: scale(0.7); }
}

/* Very small ≤360px */
@media (max-width: 360px) {
  .stats-grid    { grid-template-columns: 1fr; }
  .admin-grid    { grid-template-columns: 1fr; }
  .option-grid   { grid-template-columns: 1fr; }
  .subjects-grid { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════
   MISSING UTILITY CLASSES
   ══════════════════════════════════════════════ */

/* Button loading state — inner text/spinner spans */
.btn-text   { display: inline-flex; align-items: center; gap: 6px; }

/* Margin utilities */
.mb-14 { margin-bottom: 14px; }

/* Onboarding option button */
.onb-option {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; padding: 13px var(--sp-2);
  background: var(--bg-input); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md); cursor: pointer; text-align: left;
  transition: border-color 0.12s, background 0.12s;
  min-height: var(--touch); touch-action: manipulation;
  color: var(--text-primary); font-family: var(--font-body);
}
.onb-option:hover { border-color: var(--border-accent); background: var(--bg-card-hover); }

/* Onboarding selection checkmark */
.onb-check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border-strong); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}

/* Admin panel checkboxes */
.ai-change-cb,
.btag-cb { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* Backup export column chip */
.col-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: var(--r-pill);
  background: var(--bg-highlight); border: 1px solid var(--border);
  font-size: var(--text-xs); font-weight: 500; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  touch-action: manipulation;
}
.col-chip:hover { border-color: var(--accent); }
.col-chip input { accent-color: var(--accent); margin: 0; }

/* Share badge button */
.share-badge-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--bg-highlight); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  touch-action: manipulation; min-height: var(--touch-min);
}
.share-badge-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Dashboard grid ─────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
@media (max-width: 768px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Card sm compact ────────────────────────────────── */
.card-sm { padding: var(--sp-1) 13px; }

/* ══════════════════════════════════════════════
   ACCESSIBILITY & INTERACTION POLISH
   ══════════════════════════════════════════════ */

/* ── Keyboard focus ring ────────────────────── */
/* Visible focus for keyboard/screen reader users, invisible for mouse */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* Interactive element focus */
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-ghost:focus-visible { box-shadow: 0 0 0 3px rgba(251,146,60,0.35); }

.option-item:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
.option-item[tabindex]:focus { outline: none; }
.option-item[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }

/* ── Reduced motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #page-content.page-exit,
  #page-content.page-enter { animation: none; opacity: 1; transform: none; }
  .skeleton { animation: none; background: var(--bg-highlight); }
  .splash-bar-fill { animation: none; }
}

/* ── Smooth scroll ──────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ── Selection color ────────────────────────── */
::selection        { background: rgba(251,146,60,0.25); color: var(--text-primary); }
::-moz-selection   { background: rgba(251,146,60,0.25); color: var(--text-primary); }

/* ── Scrollbar styling (desktop) ────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Tap highlight (mobile) ─────────────────── */
* { -webkit-tap-highlight-color: transparent; }
a, button, [role="button"], [onclick] { -webkit-tap-highlight-color: rgba(251,146,60,0.12); }

/* ── Input autofill styling ─────────────────── */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 100px var(--bg-input) inset;
  -webkit-text-fill-color: var(--text-primary);
  caret-color: var(--text-primary);
}

/* ── Improve text rendering ─────────────────── */
body {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Prevent CLS on image load ──────────────── */
img { display: block; }

/* ── Checkbox/radio base ────────────────────── */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Button active feedback (all buttons) ───── */
button:not(:disabled):active,
[role="button"]:not(:disabled):active {
  transform: scale(0.97);
}
.btn-primary:not(:disabled):active  { transform: scale(0.97); filter: brightness(0.92); }
.btn-secondary:not(:disabled):active { transform: scale(0.97); }

/* ── Card hover lift ─────────────────────────── */
.card-hover {
  transition: transform 0.15s, box-shadow 0.15s;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* ── Form validation states ──────────────────── */
.form-group input:invalid:not(:placeholder-shown),
.form-group select:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}
.form-group input:valid:not(:placeholder-shown) {
  border-color: rgba(74,222,128,0.4);
}

/* ── Truncation utility ──────────────────────── */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Font weight consistency ─────────────────── */
strong, b { font-weight: 700; }

.subject-card:hover { transform: translateY(-2px); }
.subject-card:active { transform: translateY(0) scale(0.97); }

/* ══════════════════════════════════════════════════════════════════════════════
   BULK QUESTION REVIEW SYSTEM
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Filter bar ──────────────────────────────────────────────────────────────── */
.qr-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-2);
}
.qr-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.qr-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.qr-select {
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.qr-select:focus { border-color: var(--accent); }

.qr-input {
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  outline: none;
  transition: border-color .15s;
  width: 100%;
  box-sizing: border-box;
}
.qr-input:focus  { border-color: var(--accent); }

.qr-textarea {
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  outline: none;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
  transition: border-color .15s;
  line-height: 1.5;
}
.qr-textarea:focus { border-color: var(--accent); }

/* ── Bulk action bar ─────────────────────────────────────────────────────────── */
.qr-bulk-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-2);
  position: sticky;
  top: 4px;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.qr-btn-danger {
  padding: 7px 16px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--r-md);
  color: #ef4444;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.qr-btn-danger:hover  { background: rgba(239,68,68,.2); }
.qr-btn-danger:active { transform: scale(.97); }
.qr-btn-danger:disabled { opacity: .45; cursor: not-allowed; }

/* ── Question card ───────────────────────────────────────────────────────────── */
.qr-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.qr-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.qr-card-sel {
  border-color: var(--border-accent) !important;
  background: var(--bg-highlight);
}
.qr-card-editing {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 1px var(--accent), 0 4px 20px rgba(251,146,60,.08);
}

/* Card sub-sections */
.qr-card-hd {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-highlight);
}
.qr-card-bd {
  padding: 12px 14px;
}
.qr-card-ft {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-highlight);
}

/* Checkbox */
.qr-cb-wrap {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.qr-cb-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* Status pill */
.qr-status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  border: 1px solid;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}

/* Badge row */
.qr-badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}
.qr-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.qr-badge-warn {
  background: rgba(251,146,60,.12);
  color: var(--accent);
  border: 1px solid rgba(251,146,60,.25);
}
.qr-badge-err {
  background: rgba(239,68,68,.1);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,.2);
}

/* Score bar */
.qr-score-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}
.qr-score-bar {
  width: 52px;
  height: 5px;
  background: var(--bg-base);
  border-radius: 99px;
  overflow: hidden;
}
.qr-score-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .3s;
}
.qr-score-hi  { background: #22c55e; }
.qr-score-mid { background: var(--accent); }
.qr-score-lo  { background: #ef4444; }
.qr-score-num {
  font-size: var(--text-xs);
  color: var(--text-muted);
  min-width: 28px;
}

/* Question text */
.qr-q-text {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  margin: 0 0 10px;
  word-break: break-word;
}

/* Options grid */
.qr-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
@media (max-width: 600px) {
  .qr-options-grid { grid-template-columns: 1fr; }
}

.qr-option {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.45;
}
.qr-option-correct {
  background: rgba(34,197,94,.08);
  border-color: rgba(34,197,94,.3);
  color: #86efac;
}
.qr-opt-letter {
  flex-shrink: 0;
  font-weight: 700;
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding-top: 1px;
}
.qr-correct-tick {
  flex-shrink: 0;
  margin-left: auto;
  color: #22c55e;
  font-weight: 700;
}

/* Reject note */
.qr-reject-note {
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(239,68,68,.07);
  border: 1px solid rgba(239,68,68,.18);
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  color: #f87171;
}

/* Explanation details */
.qr-expl {
  margin-top: 8px;
}
.qr-expl summary {
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.qr-expl p {
  margin: 6px 0 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.55;
}

/* Tags */
.qr-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.qr-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}
.qr-diff-easy   { color: #86efac; border-color: rgba(34,197,94,.25);  background: rgba(34,197,94,.07);  }
.qr-diff-medium { color: var(--accent-bright); border-color: var(--border-accent); background: var(--accent-dim); }
.qr-diff-hard   { color: #f87171; border-color: rgba(239,68,68,.25);  background: rgba(239,68,68,.07);  }

/* Per-card action buttons */
.qr-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.qr-act {
  padding: 5px 12px;
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  border: 1px solid;
  transition: background .12s, transform .1s;
  white-space: nowrap;
}
.qr-act:active { transform: scale(.96); }
.qr-act:disabled { opacity: .45; cursor: not-allowed; }

.qr-act-approve {
  background: rgba(34,197,94,.08);
  border-color: rgba(34,197,94,.25);
  color: #86efac;
}
.qr-act-approve:hover { background: rgba(34,197,94,.16); }

.qr-act-reject {
  background: rgba(239,68,68,.08);
  border-color: rgba(239,68,68,.22);
  color: #f87171;
}
.qr-act-reject:hover { background: rgba(239,68,68,.16); }

.qr-act-edit {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-secondary);
}
.qr-act-edit:hover { background: var(--bg-card-hover); border-color: var(--border-strong); }

/* ── Edit card ───────────────────────────────────────────────────────────────── */
.qr-edit-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(251,146,60,.06);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
}
.qr-edit-id {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.qr-edit-form {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qr-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.qr-edit-opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.qr-opt-inp {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  outline: none;
  transition: border-color .15s;
}
.qr-opt-inp:focus { border-color: var(--accent); }
.qr-radio-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.qr-radio-wrap input[type="radio"] { accent-color: var(--accent); cursor: pointer; }
.qr-edit-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.qr-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-highlight);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .qr-filter-bar { padding: 10px 12px; }
  .qr-filter-group { min-width: 0; width: 100%; }
  .qr-bulk-bar { flex-direction: column; align-items: stretch; }
  .qr-bulk-bar > div { justify-content: stretch; }
  .qr-bulk-bar button { flex: 1; }
  .qr-card-ft { flex-direction: column; align-items: flex-start; }
  .qr-edit-row2 { grid-template-columns: 1fr; }
  .qr-edit-opt-row { flex-wrap: wrap; }
  .qr-actions { width: 100%; justify-content: stretch; }
  .qr-act { flex: 1; text-align: center; }
}

/* ── Admin Review nav button (not a tab, navigates to /review route) ─────── */
.admin-tab-link {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.admin-tab-link:hover  { background: rgba(251,146,60,.2); }
.admin-tab-link:active { transform: scale(.97); }

/* ── Review stats bar ─────────────────────────────────────────────────────── */
.qr-stats-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-2);
}
.qr-stat-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  border: 1px solid;
}
.qr-stat-pending  { background: rgba(251,146,60,.1);   color: #fb923c; border-color: rgba(251,146,60,.3); }
.qr-stat-approved { background: rgba(34,197,94,.08);   color: #4ade80; border-color: rgba(34,197,94,.25); }
.qr-stat-rejected { background: rgba(239,68,68,.08);   color: #f87171; border-color: rgba(239,68,68,.22); }

.qr-stat-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.qr-stat-prog-bar {
  width: 80px;
  height: 6px;
  background: var(--bg-base);
  border-radius: 99px;
  overflow: hidden;
}
.qr-stat-prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #22c55e);
  border-radius: 99px;
  transition: width .5s ease;
}

/* ── Focused card (keyboard navigation) ──────────────────────────────────── */
.qr-card-focused {
  border-color: rgba(251,146,60,.5) !important;
  box-shadow: 0 0 0 2px rgba(251,146,60,.15), 0 4px 16px rgba(0,0,0,.2) !important;
}

/* ── Keyboard hint (shown on focused card) ───────────────────────────────── */
.qr-kb-hint {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 2px 8px;
  white-space: nowrap;
  font-family: var(--font-mono);
  letter-spacing: .02em;
}
.qr-kb-legend {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-highlight);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px 10px;
  font-family: var(--font-mono);
  letter-spacing: .02em;
}
@media (max-width: 640px) { .qr-kb-legend { display: none; } }

/* ── Migration warning banner ────────────────────────────────────────────── */
.qr-migrate-banner {
  padding: 12px 16px;
  background: rgba(251,146,60,.07);
  border: 1px solid var(--border-accent);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}
.qr-migrate-banner strong { color: var(--accent); }

/* ── Undo button inside toast ────────────────────────────────────────────── */
.qr-undo-btn {
  flex-shrink: 0;
  margin-left: 10px;
  padding: 3px 12px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--r-pill);
  color: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  min-height: auto;
}
.qr-undo-btn:hover { background: rgba(255,255,255,.25); }

.qr-toast-x {
  background: none;
  border: none;
  color: inherit;
  opacity: .5;
  font-size: 1rem;
  margin-left: 6px;
  padding: 0;
  min-height: auto;
  cursor: pointer;
}
.qr-toast-x:hover { opacity: 1; }

/* ── Review: filter bar sort dropdown adjustments ────────────────────────── */
@media (max-width: 760px) {
  #qr-sort { min-width: 0; width: 100%; }
}

/* ── View toggle (Card / Table) ──────────────────────────────────────────── */
.qr-view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 2px;
  flex-shrink: 0;
}
.qr-view-btn {
  padding: 4px 12px;
  border-radius: calc(var(--r-md) - 2px);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.qr-view-btn:hover   { color: var(--text-primary); }
.qr-view-active      { background: var(--bg-card); color: var(--text-primary) !important; }

/* ── Compact table view ──────────────────────────────────────────────────── */
.qr-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-3);
}
.qr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.qr-table thead {
  background: var(--bg-highlight);
  position: sticky;
  top: 0;
  z-index: 2;
}
.qr-table th {
  padding: 9px 12px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.qr-th-cb     { width: 36px; }
.qr-th-q      { min-width: 280px; }
.qr-th-ans    { min-width: 140px; }
.qr-th-sub    { min-width: 130px; }
.qr-th-status { width: 115px; }
.qr-th-score  { width: 100px; }
.qr-th-act    { width: 120px; }

.qr-tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.qr-tr:hover { background: var(--bg-card-hover); }
.qr-tr-sel   { background: var(--bg-highlight) !important; }
.qr-tr-focused { box-shadow: inset 2px 0 0 var(--accent); }
.qr-tr-editing { background: rgba(251,146,60,.04); }
.qr-tr-detail  { background: var(--bg-highlight); }
.qr-tr-detail td { padding: 0; }

.qr-table td {
  padding: 10px 12px;
  vertical-align: middle;
}

.qr-td-q-inner {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.qr-q-trunc {
  color: var(--text-primary);
  line-height: 1.45;
  word-break: break-word;
}
.qr-dup-icon {
  flex-shrink: 0;
  cursor: pointer;
  font-size: .9rem;
  padding: 1px 3px;
  border-radius: 4px;
  transition: background .12s;
}
.qr-dup-icon:hover { background: rgba(251,146,60,.2); }

.qr-ans-text {
  color: #86efac;
  font-size: var(--text-xs);
  font-weight: 600;
}
.qr-sub-trunc {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* Table action buttons */
.qr-tbl-actions {
  display: flex;
  gap: 4px;
}
.qr-tbl-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, transform .1s;
  flex-shrink: 0;
}
.qr-tbl-btn:hover    { background: var(--bg-card-hover); border-color: var(--border-strong); }
.qr-tbl-btn:active   { transform: scale(.93); }
.qr-tbl-btn:disabled { opacity: .4; cursor: not-allowed; }
.qr-tbl-approve:hover { background: rgba(34,197,94,.12);  border-color: rgba(34,197,94,.3); }
.qr-tbl-reject:hover  { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.3); }

/* Expanded detail panel inside table row */
.qr-detail-panel {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

/* ── Duplicate comparison modal ──────────────────────────────────────────── */
.qr-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.qr-compare-col {
  padding: 14px 16px;
}
.qr-compare-col:first-child { padding-right: 20px; }
.qr-compare-col:last-child  { padding-left: 20px; }
.qr-compare-divider {
  background: var(--border);
  width: 1px;
  align-self: stretch;
}
.qr-compare-label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 600px) {
  .qr-compare-grid {
    grid-template-columns: 1fr;
  }
  .qr-compare-divider { display: none; }
  .qr-compare-col { padding: 12px 0; border-bottom: 1px solid var(--border); }
}

/* ── Responsive table ────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .qr-th-ans, .qr-td-ans { display: none; }
  .qr-th-sub              { display: none; }
  .qr-sub-trunc           { display: none; }
}

/* ── Subject progress panel ──────────────────────────────────────────────── */
.qr-subj-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-2);
  overflow: hidden;
}
.qr-subj-header {
  display: grid;
  grid-template-columns: 1fr 2fr 70px 70px;
  gap: 8px;
  padding: 8px 14px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-highlight);
}
.qr-subj-row {
  display: grid;
  grid-template-columns: 1fr 2fr 70px 70px;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.qr-subj-row:last-of-type { border-bottom: none; }
.qr-subj-row:hover         { background: var(--bg-card-hover); }
.qr-subj-name {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qr-subj-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qr-subj-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-base);
  border-radius: 99px;
  overflow: hidden;
}
.qr-subj-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}
.qr-subj-num {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  min-width: 32px;
}
.qr-subj-pending { color: var(--accent) !important; }

/* ── Bulk field editor panel ─────────────────────────────────────────────── */
#qr-bulk-bar {
  flex-direction: column;
  align-items: stretch;
}
#qr-bulk-bar > div:first-child {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .qr-subj-header,
  .qr-subj-row { grid-template-columns: 1fr 1.5fr 50px; }
  .qr-subj-row > span:last-child,
  .qr-subj-header > span:last-child { display: none; }
}

/* ── Missing table/checkbox classes ─────────────────────────────────────── */

/* Checkbox inputs inside review cards and table rows */
.qr-check {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Table column cells not covered by earlier rules */
.qr-td-sub {
  max-width: 140px;
  overflow: hidden;
}
.qr-td-score {
  min-width: 90px;
}
.qr-td-act {
  white-space: nowrap;
}

/* Table expand/edit action buttons (supplement existing qr-tbl-btn rules) */
.qr-tbl-edit   { /* inherits from .qr-tbl-btn */ }
.qr-tbl-expand {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-secondary);
  font-size: .7rem;
}
.qr-tbl-expand:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

/* ── Flagged / report badges ─────────────────────────────────────────────── */
.qr-badge-report {
  background: rgba(239,68,68,.1);
  color: #f87171;
  border: 1px solid rgba(239,68,68,.25);
  cursor: default;
}
.qr-badge-flag {
  background: rgba(239,68,68,.12);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,.3);
  font-weight: 700;
}
.qr-flag-note {
  margin-top: 8px;
  padding: 7px 10px;
  background: rgba(239,68,68,.07);
  border: 1px solid rgba(239,68,68,.2);
  border-left: 3px solid #ef4444;
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  color: #fca5a5;
  line-height: 1.5;
}
.qr-stat-flagged {
  background: rgba(239,68,68,.1);
  color: #f87171;
  border-color: rgba(239,68,68,.3);
  transition: background .15s;
}
.qr-stat-flagged:hover {
  background: rgba(239,68,68,.2);
}

/* ── Report group cards in admin Reports tab ──────────────────────────────── */
.badge-red {
  background: rgba(239,68,68,.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,.3);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 700;
}

/* ── Multi-exam tag (highlighted differently from regular tags) ──────────── */
.qr-tag-exam {
  background: rgba(34,197,94,.07);
  border-color: rgba(34,197,94,.2);
  color: #86efac;
}
