/* ExamPulse — Shared Base Styles */
/* Readable variable names, BEM-lite naming */

/* ──────────────────────────────────────────────────────────────────
 * Design System v1.0 — Editorial Ink & Paper
 * Fonts: Fraunces (display) + Geist (body) + JetBrains Mono (data)
 * Dropped in April 2026. Tokens layered ADDITIVELY on top of the
 * legacy palette so existing components keep working while new
 * components (see student/styles.css bottom) get the new vocabulary.
 * ────────────────────────────────────────────────────────────────── */
/*
 * 2026-05-01 perf audit: the Google Fonts @import was render-blocking
 * for ~1.8s per Lighthouse mobile run. Browser couldn't begin laying
 * out the page until the imported fonts CSS resolved AND the WOFF2
 * files downloaded. Moved to <link rel="stylesheet"> in each HTML
 * head so the fonts CSS fetches in parallel with base.css instead of
 * sequentially after it. `&display=swap` (set on the link URL) keeps
 * the swap behaviour identical — fallback system fonts paint first,
 * Fraunces / Geist / JetBrains Mono swap in once loaded.
 */

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

:root {
  /* ── Legacy palette (dark default — preserved for user continuity) ── */
  --color-bg: #050810;
  --color-surface: #0d1117;
  --color-card: #161b22;
  --color-border: #21262d;
  --color-text: #e6edf3;
  /* Bumped from #a0a9b4 (3.8:1 on card #161b22) to #b8bec7 (5.1:1)
   * to clear WCAG AA for body text. Audit 2026-04-24. */
  --color-muted: #b8bec7;
  --color-accent: #60a5fa;               /* blue — the brand accent */
  --color-accent2: #818cf8;              /* accent variant */
  --color-success: #34d399;
  --color-danger: #f87171;
  --color-warning: #fbbf24;
  --color-purple: #a78bfa;
  --color-orange: #fb923c;

  /* ── Design-system palette (paper + ink + saffron family) ── */
  --paper:          #F5F1EA;
  --paper-alt:      #EDE7DC;
  --paper-deep:     #E3DBC9;
  --paper-line:     #C9C0AE;   /* was #D6CFBF — crisper dividers */
  --ink:            #1A1816;
  --ink-soft:       #2A2622;   /* was #3D3834 — deeper body text   */
  --ink-mute:       #574F49;   /* was #7A726A — passes WCAG AA normal (~6.8:1 on paper) */
  --ink-whisper:    #7A726A;   /* was #A8A197 — passes AA large, borderline normal (~4.1:1) */
  /*
   * Contrast audit (2026-04-20):
   *   On --paper (#F5F1EA):
   *     ink          15.1:1  ✓ AAA
   *     ink-soft     12.1:1  ✓ AAA (was 10.3)
   *     ink-mute      6.8:1  ✓ AA  (was 4.1, failing)
   *     ink-whisper   4.1:1  ✓ AA Large + borderline AA Normal (was 2.2, failing)
   *   The previous tokens were pulled from the preview HTML verbatim,
   *   but the preview's Fraunces serif tolerates lower contrast than
   *   our mixed-weight body Geist. Bumping depth keeps the editorial
   *   feel while making mono-micro labels actually readable.
   */
  --saffron:        #D65A2E;
  --saffron-soft:   #F3DFD3;
  --saffron-deep:   #A03B17;
  --sage:           #6B8E4E;
  --ember:          #E8984D;
  --brick:          #A83A2B;
  --indigo:         #2C3E6B;
  --plum:           #6B3A5E;

  /* ── Semantic tokens (new components use these) ── */
  --color-text-soft:    var(--color-muted);
  --color-whisper:      #666c75;
  --color-line:         var(--color-border);
  --color-surface-deep: #0b1016;
  --color-accent-soft:  rgba(96, 165, 250, 0.20);
  --color-accent-deep:  #2563eb;
  --color-info:         var(--indigo);

  /* "Foreground on coloured background" tokens — pick the legible
   * text colour for chips/buttons whose background is a brand colour
   * that flips lightness between themes. Default (dark theme) uses
   * the *light* variant of each colour, so dark text wins; paper
   * theme overrides these to white. Audit 2026-05-01.
   *   Dark theme  · accent #60a5fa + #000 = 6.4:1  ✓ AA   (was #fff = 3.0:1 ✗)
   *               · danger #f87171 + #000 = 6.4:1  ✓ AA   (was #fff = 3.0:1 ✗)
   *               · success #34d399+ #000 = 9.5:1  ✓ AAA
   *   Paper theme · accent #2563eb + #fff = 5.0:1  ✓ AA
   *               · danger --brick + #fff = 6.6:1  ✓ AA
   */
  --color-on-accent:  #0b0f17;
  --color-on-danger:  #0b0f17;
  --color-on-success: #0b0f17;
  --color-on-warning: #0b0f17;

  /* ── Typography (Design System v1.0) ── */
  --font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body:    'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  /* Legacy size scale (kept — existing rules reference these) */
  --font-size-xs: 0.625rem;
  --font-size-sm: 0.75rem;
  --font-size-md: 0.875rem;
  --font-size-lg: 1rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;

  /* New size scale — px-based, per design system */
  --text-xs:    11px;
  --text-sm:    12px;
  --text-base:  14px;
  --text-md:    16px;
  --text-lg:    20px;
  --text-xl:    28px;
  --text-2xl:   36px;
  --text-3xl:   48px;
  --text-4xl:   64px;

  --leading-xs:   1.4;
  --leading-sm:   1.5;
  --leading-base: 1.6;
  --leading-md:   1.55;
  --leading-lg:   1.4;
  --leading-xl:   1.2;
  --leading-2xl:  1.1;
  --leading-3xl:  1.05;
  --leading-4xl:  1.0;

  --tracking-tight:  -0.02em;
  --tracking-normal: 0;
  --tracking-wide:   0.1em;
  --tracking-wider:  0.15em;
  --tracking-widest: 0.2em;

  /* Legacy spacing (kept) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;

  /* New spacing rhythm (4px base, design system) */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;

  /* Legacy radius (kept) */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* New radius — tighter, editorial (design system §7.1) */
  --r-sm:   2px;
  --r-md:   3px;
  --r-lg:   4px;    /* default for cards */
  --r-xl:   6px;    /* modals, command palette */
  --r-pill: 999px;

  /* Elevation — tinted with ink, not black */
  --shadow-sm: 0 1px 2px rgba(26, 24, 22, 0.04);
  --shadow-md: 0 2px 8px rgba(26, 24, 22, 0.06), 0 1px 2px rgba(26, 24, 22, 0.04);
  --shadow-lg: 0 8px 24px rgba(26, 24, 22, 0.10), 0 2px 6px rgba(26, 24, 22, 0.05);
  --shadow-xl: 0 16px 48px rgba(26, 24, 22, 0.14), 0 4px 12px rgba(26, 24, 22, 0.06);

  /* Motion */
  --ease-quick:  cubic-bezier(0.2, 0.8, 0.3, 1);
  --ease-smooth: cubic-bezier(0.4, 0.0, 0.2, 1);
  --ease-poise:  cubic-bezier(0.65, 0.05, 0.36, 1);
  --dur-fast:    120ms;
  --dur-base:    200ms;
  --dur-slow:    400ms;
  --dur-reveal:  700ms;

  /* Layout */
  --container-max: 1440px;
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --gutter:        32px;
  --gutter-mobile: 16px;

  /* Focus — always visible */
  --focus-ring: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-accent);

  /* ── Z-Index Scale ── */
  --z-base: 1;
  --z-sticky: 10;
  --z-banner: 50;
  --z-palette: 55;
  --z-overlay: 70;
  --z-sidebar: 99;
  --z-toast: 200;
  --z-loading: 300;
  --z-skip: 999;
  --z-modal: 9999;
  --z-consent: 2147483000;
}

/* Light theme — system preference. Mirrors `body.light` overrides
 * for the colour-on-coloured-bg tokens so buttons / chips / danger
 * states pass WCAG AA when the OS / Lighthouse defaults to light.
 * 2026-05-01 audit: Send OTP button was failing 3.4:1 contrast in
 * Lighthouse mobile because --color-on-accent stayed at the dark
 * default (#0b0f17) while --color-accent flipped to deep blue. */
@media (prefers-color-scheme: light) {
  body:not(.force-dark) {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-card: #f0f0f0;
    --color-border: #d1d5db;
    --color-text: #111827;
    --color-muted: #555;
    --color-accent: #2563eb;
    --color-accent2: #1d4ed8;
    --color-purple: #7c3aed;
    --color-orange: #ea580c;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #b45309;
    /* "Foreground on coloured bg" tokens — must flip to white when
     * the brand colours flip to their darker light-mode shades.
     * Verified contrast on light-mode --color-accent #2563eb:
     *   #FFFFFF  = 5.0 : 1   ✓ AA
     *   #0b0f17  = 3.4 : 1   ✗ (this was the bug)
     */
    --color-on-accent:  #FFFFFF;
    --color-on-danger:  #FFFFFF;
    --color-on-success: #FFFFFF;
    --color-on-warning: #1A1816;
  }
}
/* ─── Paper mode (light theme) — Editorial Ink & Paper v1.0 ────
 * Was a generic blue-on-white light theme; now the canonical paper
 * palette from the design system. Users who hit Toggle Theme land in
 * this mode — warm cream background, saffron single accent, ink text.
 */
body.light,
body[data-theme="paper"] {
  --color-bg:           var(--paper);
  --color-surface:      var(--paper-alt);
  --color-surface-deep: var(--paper-deep);
  --color-card:         var(--paper-alt);
  --color-border:       var(--paper-line);
  --color-line:         var(--paper-line);
  --color-text:         var(--ink);
  --color-text-soft:    var(--ink-soft);
  --color-muted:        var(--ink-mute);
  --color-whisper:      var(--ink-whisper);
  --color-accent:       #2563eb;                 /* blue — paper-mode accent */
  --color-accent2:      #1d4ed8;
  --color-accent-soft:  rgba(37, 99, 235, 0.12);
  --color-accent-deep:  #1d4ed8;
  --color-success:      var(--sage);
  --color-danger:       var(--brick);
  --color-warning:      var(--ember);
  --color-purple:       var(--plum);
  --color-orange:       var(--ember);
  --focus-ring:         0 0 0 2px var(--paper), 0 0 0 4px #2563eb;
  /* Paper theme accent/danger are darker — switch to light text on top */
  --color-on-accent:    #FFFFFF;
  --color-on-danger:    #FFFFFF;
  --color-on-success:   #FFFFFF;
  --color-on-warning:   #1A1816;
}
body.light .btn--primary { color: var(--paper); }

/* `[data-theme="ink"]` — explicit opt-in for dark mode. Default root
 * already ships ink, so this alias is for components that reference
 * the design-system selector explicitly. */
[data-theme="ink"] {
  --color-bg:      var(--ink);
  --color-surface: #221F1C;
  --color-surface-deep: #2A2723;
  --color-text:    var(--paper);
  --color-text-soft: var(--paper-alt);
  --color-muted:   var(--ink-whisper);
  --color-whisper: var(--ink-mute);
  --color-line:    #3D3834;
  --color-accent:  #60a5fa;
  --color-accent-soft: rgba(96, 165, 250, 0.15);
  --color-accent-deep: #2563eb;
}

/* High contrast */
body.high-contrast {
  --color-bg: #000;
  --color-surface: #111;
  --color-card: #1a1a1a;
  --color-border: #444;
  --color-text: #fff;
  --color-muted: #ccc;
}

/* ── Editorial palette — dark-mode remap (2026-04-20) ──
 *
 * The Editorial Ink & Paper tokens (--paper*, --ink*) are defined in
 * :root as LIGHT-MODE values — cream backgrounds, near-black text.
 * When those tokens are consumed directly by panels on a DARK-themed
 * page (student.html / admin.html's default theme), the result is
 * dark-on-dark text or cream panels that fight the surrounding page.
 *
 * This block inverts them when the editorial shell is active AND the
 * page isn't explicitly in paper/light mode. Saffron / sage / ember /
 * brick / indigo / plum stay unchanged — they read well on both
 * backgrounds.
 *
 * Contrast (dark remap, on --paper-alt #1A1F26):
 *   --ink          (#F5F1EA) : 13.8:1  ✓ AAA
 *   --ink-soft     (#D9D1C2) :  9.8:1  ✓ AAA
 *   --ink-mute     (#B8B0A5) :  6.4:1  ✓ AA  (meta labels)
 *   --ink-whisper  (#8A8278) :  3.6:1  ✓ AA Large (tiny mono only)
 */
body[data-shell="editorial"]:not(.light):not([data-theme="paper"]) {
  --paper:          #0F1419;   /* deep ink-slate — page background */
  --paper-alt:      #1A1F26;   /* panel surface */
  --paper-deep:     #252B34;   /* inset / emphasis panel */
  --paper-line:     #3A4250;   /* crisp dividers on dark */
  --ink:            #F5F1EA;   /* primary text (cream on dark) */
  --ink-soft:       #D9D1C2;   /* secondary text */
  --ink-mute:       #B8B0A5;   /* labels / meta captions */
  --ink-whisper:    #8A8278;   /* tiny mono / non-critical */
}

/* Route semantic tokens to editorial palette when shell is active —
 * ensures buttons / dropdowns inside editorial panels pick up the
 * remapped palette rather than the default slate-dark theme. */
body[data-shell="editorial"] {
  background: var(--paper);
  color:      var(--ink);
}

/* Color-blind modes */
body.cb-deuteranopia { --color-success: #4484CE; --color-danger: #E69F00; --color-warning: #F0E442; --color-orange: #0072B2; }
body.cb-protanopia { --color-success: #56B4E9; --color-danger: #D55E00; --color-warning: #F0E442; --color-orange: #009E73; }
body.cb-tritanopia { --color-success: #CC79A7; --color-danger: #D55E00; --color-warning: #E69F00; --color-orange: #0072B2; }

/* Large text mode */
body.large-text .quiz-question-text,
body.large-text .quiz-option,
body.large-text p { font-size: 1.125rem !important; }
body.large-text .card-header { font-size: 1.25rem !important; }

/* Dyslexia font */
body.dyslexia-font, body.dyslexia-font * { font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important; }

html { overflow: auto; height: auto; }

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

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

/* Scrollbars */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--color-bg); }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

/* ── Screen Container ── */
.screen {
  display: none;
  min-height: 100vh;
  padding: var(--space-lg);
  max-width: 900px;
  margin: 0 auto;
}
.screen.active { display: block; }

/* ── Page Header ── */
.page-header {
  text-align: center;
  padding: var(--space-xl) 0;
  margin-bottom: var(--space-xl);
}
.page-header h1 {
  font-size: 1.375rem;
  background: linear-gradient(135deg, var(--color-accent), var(--color-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 800;
}
.page-header .subtitle {
  color: var(--color-muted);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

/* ── Cards ── */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}
.card-header {
  font-size: var(--font-size-lg);
  font-weight: 700;
  margin-bottom: var(--space-sm);
}
.card--highlighted {
  background: linear-gradient(135deg, rgba(96,165,250,.15), rgba(167,139,250,.15));
  border-color: var(--color-accent);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  min-height: 44px;
  border-radius: var(--radius-md);
  border: none;
  font-size: var(--font-size-md);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
  gap: 6px;
  font-family: inherit;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--full { width: 100%; }
.btn--small { padding: 8px 14px; font-size: var(--font-size-sm); min-height: 44px; }

/* 2026-05-01 audit (P1): replaced hardcoded `color: #000` on every
 * brand-coloured button with the theme-aware --color-on-* tokens.
 * Default (dark theme) keeps the dark text on light-blue accent
 * which passes AA. Paper theme switches to white on deep-blue accent
 * which also passes AA. Lighthouse was flagging Send OTP because the
 * `body.light` override at line ~263 sets paper as the colour but
 * the unique combo wasn't being detected as a known-good pair.
 * Using the explicit token resolves both branches deterministically. */
.btn--primary { background: var(--color-accent); color: var(--color-on-accent, #000); }
.btn--primary:hover { background: #93c5fd; color: var(--color-on-accent, #000); }
.btn--secondary { background: var(--color-card); color: var(--color-text); border: 1px solid var(--color-border); }
.btn--secondary:hover { border-color: var(--color-accent); }
.btn--danger { background: var(--color-danger); color: var(--color-on-danger, #000); }
.btn--success { background: var(--color-success); color: var(--color-on-success, #000); }
.btn--purple { background: var(--color-purple); color: #000; }

/* ── Form Elements ── */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8125rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--color-accent);
}
/* Keyboard focus ring — visible only for keyboard navigation (WCAG 2.4.7) */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}
.btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.textarea { resize: vertical; min-height: 60px; }

.form-label {
  font-size: 0.8125rem;
  color: var(--color-muted);
  display: block;
  margin-bottom: 6px;
}

/* ── Chips / Tags ── */
.chip-group { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: var(--space-sm) 0; }
.chip {
  padding: 10px 16px;
  min-height: 44px;
  border-radius: var(--radius-full);
  border: 1.5px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.chip:hover { border-color: var(--color-accent); background: rgba(96,165,250,.12); }
.chip.selected { background: var(--color-accent); color: #000; border-color: var(--color-accent); font-weight: 600; }

/* Light mode chips */
body.light .chip { border: 1.5px solid rgba(0,0,0,.2); background: rgba(0,0,0,.04); }
body.light .chip:hover { border-color: var(--color-accent); background: rgba(96,165,250,.08); }
body.light .chip.selected { background: var(--color-accent); color: #fff; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 700;
}
.badge--success { background: rgba(52,211,153,.15); color: var(--color-success); }
.badge--danger { background: rgba(248,113,113,.15); color: var(--color-danger); }
.badge--warning { background: rgba(251,191,36,.15); color: var(--color-warning); }
.badge--info { background: rgba(96,165,250,.15); color: var(--color-accent); }
.badge--purple { background: rgba(167,139,250,.15); color: var(--color-purple); }

/* ── Stat Grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin: var(--space-md) 0;
}
.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
}
.stat-value { font-size: 1.375rem; font-weight: 800; color: var(--color-accent); }
.stat-label { font-size: 0.6875rem; color: var(--color-muted); margin-top: var(--space-xs); }

/* ── Progress Bar ── */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-surface);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-success));
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── Tab Bar ── */
.tab-bar { display: flex; gap: var(--space-sm); margin-bottom: var(--space-lg); }
.tab-item {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 0.8125rem;
  min-height: 44px;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.tab-item.active { background: var(--color-accent); color: #000; border-color: var(--color-accent); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
  padding: var(--space-lg);
}
.modal-overlay.visible { display: flex; }
.modal-body {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 460px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-body h3 {
  font-size: var(--font-size-lg);
  margin-bottom: 10px;
  color: var(--color-accent);
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
}
.toast {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.visible { opacity: 1; }
.toast--info { background: var(--color-accent); color: #000; }
.toast--success { background: var(--color-success); color: #000; }
.toast--warning { background: var(--color-warning); color: #000; }
.toast--error { background: var(--color-danger); color: #fff; }

/* ── Loading Spinner ── */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility Classes ── */
.text-center { text-align: center; }
.text-muted { color: var(--color-muted); }
.text-small { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.gap-sm { gap: var(--space-sm); }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-sm); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.hidden { display: none !important; }

/* ── KaTeX Overrides ── */
.katex-display { margin: 8px 0 !important; }
.katex { font-size: 1.05em !important; }

/* ── Skip-to-content (screen-reader accessible, visually hidden) ── */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: 0;
  padding: 12px 16px;
  background: var(--color-accent);
  color: #000;
  z-index: var(--z-skip);
  font-weight: 700;
  text-decoration: none;
}
.skip-to-content:focus {
  top: 0;
}

/* ── Link-style button (for accessibility-preserving text buttons) ── */
.link-button {
  background: transparent;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

/* ── Print Styles ── */
@media print {
  body { background: white !important; color: black !important; }
  .screen { min-height: auto; }
  .screen:not(.active) { display: none !important; }
  .screen.active { display: block !important; }
  .btn, .toast-container, .tab-bar, .page-header, .modal-overlay { display: none !important; }
  .card { page-break-inside: avoid; border: 1px solid #ccc; box-shadow: none !important; }
  nav, .quiz-palette, .quiz-palette-toggle { display: none !important; }
  @page { margin: 0.5in; }
}

/* ── Mobile Responsive ── */
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 400px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tab-bar { flex-wrap: wrap; }
}

/* Mask the staff PIN visually without using type=password (prevents
   Safari/1Password autofill from leaking the PIN into the phone field). */
.pin-masked {
  -webkit-text-security: disc;
  text-security: disc;
  letter-spacing: 0.3em;
}

/* ── Reduced Motion (WCAG 2.3.3) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
