/* ==========================================================
   GED Hall Pass — design tokens + global layout
   Works on phone, tablet, and desktop. Light & dark.
   ---------------------------------------------------------- */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&display=swap");

/* ---------- design tokens ---------- */
:root {
  /* brand */
  --brand:       #6366f1;
  --brand-ink:   #4338ca;
  --brand-tint:  #eef2ff;

  /* neutral (light) */
  --bg:            #fafaf9;
  --bg-elev:       #ffffff;
  --ink:           #1c1917;
  --ink-muted:     #57534e;
  --ink-subtle:    #a8a29e;
  --line:          #e7e5e4;
  --line-strong:   #d6d3d1;

  /* semantic */
  --ok:       #059669;
  --ok-tint:  #d1fae5;
  --warn:     #b45309;
  --warn-tint:#fef3c7;
  --err:      #b91c1c;
  --err-tint: #fee2e2;

  /* subject accents */
  --rla:      #6366f1;
  --math:     #0ea5e9;
  --science:  #10b981;
  --social:   #f59e0b;

  /* radii + shadows */
  --r-sm: 8px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06), 0 2px 6px rgba(0,0,0,.04);
  --shadow:    0 2px 6px rgba(0,0,0,.06), 0 12px 30px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 14px rgba(0,0,0,.08), 0 28px 60px rgba(0,0,0,.10);

  /* motion */
  --ease-out: cubic-bezier(.2,.7,.2,1);
  --ease-spring: cubic-bezier(.2,.9,.3,1.2);
  --t-fast: 120ms;
  --t: 220ms;
  --t-slow: 420ms;

  /* type */
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Instrument Serif", "New York", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0b0a09;
    --bg-elev:       #141311;
    --ink:           #f5f5f4;
    --ink-muted:     #a8a29e;
    --ink-subtle:    #78716c;
    --line:          #292524;
    --line-strong:   #3a3432;
    --brand-tint:    rgba(99,102,241,.14);
    --ok-tint:       rgba(5,150,105,.18);
    --warn-tint:     rgba(180,83,9,.18);
    --err-tint:      rgba(185,28,28,.22);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
    --shadow:    0 2px 8px rgba(0,0,0,.4), 0 18px 40px rgba(0,0,0,.5);
    --shadow-lg: 0 4px 14px rgba(0,0,0,.5), 0 40px 80px rgba(0,0,0,.6);
  }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: radial-gradient(1200px 800px at 80% -10%, color-mix(in oklab, var(--brand) 12%, transparent), transparent 60%),
              radial-gradient(900px 700px at -10% 110%, color-mix(in oklab, var(--math) 10%, transparent), transparent 60%),
              var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout primitives ---------- */
.container   { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.container-narrow { max-width: 720px; margin: 0 auto; padding: 0 20px; }

.stack       { display: grid; gap: 18px; }
.stack-sm    { display: grid; gap: 10px; }
.stack-lg    { display: grid; gap: 32px; }
.row         { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.grid-2      { display: grid; grid-template-columns: 1fr; gap: 20px; }
.grid-3      { display: grid; grid-template-columns: 1fr; gap: 20px; }
.grid-4      { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(1.1) blur(14px);
  -webkit-backdrop-filter: saturate(1.1) blur(14px);
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  border-bottom: 1px solid var(--line);
}
.nav-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { display: inline-flex; align-items: baseline; gap: 8px; font-weight: 700; font-size: 1.08rem; letter-spacing: -.01em; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: conic-gradient(from 20deg, var(--rla), var(--math), var(--science), var(--social), var(--rla));
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand) 25%, transparent);
  display: inline-block; transform: translateY(2px);
}
.nav-links { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.nav-links a {
  padding: 8px 12px; border-radius: 999px; color: var(--ink-muted);
  transition: background var(--t) var(--ease-out), color var(--t) var(--ease-out);
}
.nav-links a:hover { color: var(--ink); background: var(--brand-tint); text-decoration: none; }
.nav-links a.is-active { color: var(--ink); background: var(--brand-tint); }

/* ---------- hero / display ---------- */
.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -.015em;
  line-height: 1.02;
  font-size: clamp(2.4rem, 6vw, 4.4rem);
}
.display em { font-style: italic; color: var(--brand-ink); }
.eyebrow { text-transform: uppercase; font-size: .78rem; letter-spacing: .12em; color: var(--ink-subtle); font-weight: 600; }

/* ---------- cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t) var(--ease-out), box-shadow var(--t) var(--ease-out), border-color var(--t) var(--ease-out);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-strong); }
.card-accent {
  position: relative; overflow: hidden;
}
.card-accent::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--accent, var(--brand));
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent;
  padding: 11px 18px; border-radius: 999px;
  font-weight: 600; cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t) var(--ease-out),
              box-shadow var(--t) var(--ease-out),
              border-color var(--t) var(--ease-out),
              color var(--t) var(--ease-out);
  text-decoration: none;
  background: var(--bg-elev);
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--brand); color: white; border-color: transparent; box-shadow: 0 6px 20px -4px color-mix(in oklab, var(--brand) 60%, transparent); }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--brand-tint); color: var(--ink); }
.btn-danger { background: var(--err); color: white; border-color: transparent; }
.btn-sm { padding: 7px 14px; font-size: .88rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- form ---------- */
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: .92rem; color: var(--ink-muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  outline: none;
  transition: border-color var(--t) var(--ease-out), box-shadow var(--t) var(--ease-out);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--brand) 20%, transparent);
}
.textarea { min-height: 120px; font-family: inherit; resize: vertical; }
.hint { color: var(--ink-muted); font-size: .86rem; }
.error-msg { color: var(--err); font-size: .9rem; min-height: 1.2em; }

/* ---------- chips / pills ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--brand-tint); color: var(--brand-ink);
  font-size: .78rem; font-weight: 600; letter-spacing: .02em;
  border: 1px solid color-mix(in oklab, var(--brand) 20%, transparent);
}
.chip.chip-ok   { background: var(--ok-tint);   color: var(--ok);   border-color: color-mix(in oklab, var(--ok) 20%, transparent); }
.chip.chip-warn { background: var(--warn-tint); color: var(--warn); border-color: color-mix(in oklab, var(--warn) 20%, transparent); }
.chip.chip-err  { background: var(--err-tint);  color: var(--err);  border-color: color-mix(in oklab, var(--err) 20%, transparent); }
.chip.chip-muted{ background: transparent; color: var(--ink-muted); border-color: var(--line); }

/* ---------- notification bell + dropdown ---------- */
.nav-bell { position: relative; }
.bell-dot {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--err); color: white; border-radius: 999px;
  font-size: .68rem; font-weight: 700; line-height: 16px;
  text-align: center;
}
.bell-panel {
  position: absolute; top: 56px; right: 12px; z-index: 1100;
  width: min(360px, calc(100vw - 24px));
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 18px 38px rgba(0,0,0,.18);
  max-height: 70vh; overflow-y: auto;
}
.bell-row {
  display: block; padding: 10px 14px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
.bell-row:last-child { border-bottom: 0; }
.bell-row:hover { background: var(--bg-elev); }
.bell-row.is-unread { background: var(--brand-tint); }

/* ---------- print stylesheet ---------- */
@media print {
  /* Hide chrome we don't want on paper. */
  .nav, footer, .listen-bar, [data-voice-passage], [data-voice-stem],
  [data-listen-passage], #voice-btn, #listen-btn, #another-btn,
  .skip-link, #cookie-banner, #verify-banner, .ach-grid, [data-back],
  .btn, .row .btn { display: none !important; }
  body { background: white; color: black; }
  .container, .container-narrow { max-width: 700px !important; margin: 0 auto !important; }
  .card { background: white !important; border: 1px solid #999 !important; padding: 12px !important; box-shadow: none !important; }
  .lesson-body, .prose, #lesson-body, .passage-body {
    font-size: 11pt; line-height: 1.55; color: black;
  }
  .lesson-body h1, .lesson-body h2, .lesson-body h3 {
    page-break-after: avoid;
  }
  .lesson-body img, .lesson-body table { page-break-inside: avoid; }
  /* Print-only credit footer we add via JS in lesson page. */
  .print-credit { display: block !important; }
  /* Eliminate animated backgrounds on landing pages we accidentally print. */
  .bg-drift { display: none !important; }
}
.print-credit { display: none; }

/* ---------- user-preference overrides ---------- */
/* Forced theme (overrides OS preference). */
:root[data-theme="dark"]  { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
/* Compact density: tighten generic section padding. */
:root[data-density="compact"] .section    { padding: 36px 0; }
:root[data-density="compact"] .section-sm { padding: 18px 0; }
:root[data-density="compact"] .card       { padding: 14px 16px; }
/* Font scale (1.0 default; settings allow 0.9..1.3). */
html { font-size: calc(100% * var(--font-scale, 1)); }
/* Force-reduce motion when user opted in via settings. */
:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
  scroll-behavior: auto !important;
}

/* ---------- accessibility utilities ---------- */
/* Visually hidden, but available to screen readers and keyboard focus.
   Standard sr-only recipe — clipped + 1px so AT can still find it. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  border: 0;
}
/* Skip-link — invisible until keyboard focus. WCAG 2.4.1. */
.skip-link {
  position: absolute; top: 0; left: 0;
  padding: 10px 14px;
  background: var(--brand); color: white; font-weight: 600;
  border-radius: 0 0 var(--r) 0;
  text-decoration: none;
  transform: translateY(-100%);
  transition: transform .2s ease;
  z-index: 10000;
}
.skip-link:focus { transform: translateY(0); }

/* Focus-visible polish — every interactive element gets a clear ring when
   reached via keyboard, but not when reached via mouse click. */
:focus-visible {
  outline: 3px solid color-mix(in oklab, var(--brand) 70%, transparent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, a:focus-visible, [role="button"]:focus-visible,
[role="radio"]:focus-visible, [role="checkbox"]:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 3px solid color-mix(in oklab, var(--brand) 70%, transparent);
  outline-offset: 2px;
}

/* Drag-drop keyboard-pickup state. */
.dd-item.kb-picked {
  outline: 3px dashed var(--brand);
  outline-offset: 2px;
  background: var(--brand-tint);
}

/* High-contrast preference — strengthens borders + outlines for users
   who request "more contrast" in OS settings. */
@media (prefers-contrast: more) {
  :focus-visible { outline-width: 4px; }
  .btn, .btn-day, .btn-day-ghost, .input { border-width: 2px; }
}

/* Reduced motion — disable scroll behavior and listen-mode pulses. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- achievements ---------- */
.ach-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.ach-tile {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg-elev);
  transition: border-color .15s ease, transform .12s ease;
}
.ach-tile.is-earned {
  border-color: color-mix(in oklab, var(--brand) 38%, transparent);
  background: color-mix(in oklab, var(--brand) 8%, var(--bg-elev));
}
.ach-tile.is-locked  { opacity: .55; }
.ach-icon { font-size: 1.6rem; line-height: 1; }
.ach-meta { line-height: 1.2; min-width: 0; }
.ach-meta strong { display: block; font-size: .92rem; }

/* ---------- modal dialog ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1500;
  background: rgba(15, 23, 42, .55);
  display: grid; place-items: center;
  padding: 16px;
}
.modal-card {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px 24px;
  width: min(480px, 100%);
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .3);
}

/* ---------- listen mode (sentence highlight + controller bar) ---------- */
.listen-sent {
  transition: background-color .25s ease, color .25s ease, box-shadow .25s ease;
  border-radius: 3px;
  padding: 0 1px;
}
.listen-sent.is-active {
  background: color-mix(in oklab, var(--brand) 22%, transparent);
  color: var(--brand-ink);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--brand) 30%, transparent);
}
.listen-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px;
  background: var(--brand-tint);
  border: 1px solid color-mix(in oklab, var(--brand) 32%, transparent);
  border-radius: var(--r);
  font-size: .92rem;
  color: var(--brand-ink);
  position: sticky; top: 8px; z-index: 5;
}
.listen-bar .row { display: flex; gap: 8px; }

/* ---------- section heading ---------- */
.section { padding: 64px 0; }
.section-sm { padding: 32px 0; }
.section-title { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -.01em; margin: 0 0 8px; }
.section-lead  { color: var(--ink-muted); max-width: 56ch; margin: 0 0 24px; }

/* ---------- animations ---------- */
@media (prefers-reduced-motion: no-preference) {
  .fade-up   { animation: fadeUp .7s var(--ease-out) both; }
  .fade-in   { animation: fadeIn .8s var(--ease-out) both; }
  .pop-in    { animation: popIn  .5s var(--ease-spring) both; }
  .stagger > * { animation: fadeUp .6s var(--ease-out) both; }
  .stagger > *:nth-child(1) { animation-delay: .05s; }
  .stagger > *:nth-child(2) { animation-delay: .12s; }
  .stagger > *:nth-child(3) { animation-delay: .19s; }
  .stagger > *:nth-child(4) { animation-delay: .26s; }
  .stagger > *:nth-child(5) { animation-delay: .33s; }
  .stagger > *:nth-child(6) { animation-delay: .40s; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn  { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: none; } }
@keyframes pulse  { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: .85; } }
@keyframes driftBG { 0% { transform: translate3d(0,0,0); } 50% { transform: translate3d(-2%, -1%, 0); } 100% { transform: translate3d(0,0,0); } }

/* Scroll-reveal — opt-in via [data-reveal]. A small IntersectionObserver
   in public/assets/reveal.js flips `is-revealed` when the element scrolls
   into view. */
[data-reveal] { opacity: 0; transform: translateY(16px); transition: opacity .7s var(--ease-out), transform .7s var(--ease-out); will-change: opacity, transform; }
[data-reveal].is-revealed { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  [data-reveal] { opacity: 1; transform: none; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- utilities ---------- */
.muted { color: var(--ink-muted); }
.subtle { color: var(--ink-subtle); }
.tiny { font-size: .82rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.break-word { word-break: break-word; overflow-wrap: anywhere; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* progress bar */
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand) 0%, var(--math) 100%); border-radius: 999px; transition: width var(--t-slow) var(--ease-out); }

/* Long-form markdown content (lessons, passages) */
.prose { max-width: 68ch; line-height: 1.72; }
.prose h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.8rem, 3vw, 2.4rem); line-height: 1.1; letter-spacing: -.01em; margin: 32px 0 12px; }
.prose h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.5rem; line-height: 1.2; margin: 28px 0 10px; }
.prose h3 { font-weight: 700; font-size: 1.12rem; margin: 20px 0 6px; color: var(--ink); }
.prose h4 { font-weight: 700; font-size: 1rem; margin: 16px 0 4px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .06em; font-size: .9rem; }
.prose p  { margin: 10px 0; }
.prose ul, .prose ol { margin: 10px 0; padding-left: 26px; }
.prose li { margin: 4px 0; }
.prose code { background: var(--brand-tint); border-radius: 4px; padding: 1px 6px; font-family: var(--font-mono); font-size: .92em; }
.prose blockquote {
  margin: 16px 0; padding: 4px 16px;
  border-left: 3px solid var(--brand);
  background: var(--brand-tint);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--ink-muted);
  font-style: italic;
}
.prose table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .94rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.prose th { background: var(--brand-tint); font-weight: 700; }
.prose .math-inline { font-family: var(--font-mono); font-size: .96em; }
.prose a { color: var(--brand-ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose > :first-child { margin-top: 0; }

.passage-body { line-height: 1.68; color: var(--ink); }
.passage-body p { margin: 10px 0; }
.passage-body h3, .passage-body h4 { font-family: var(--font-display); font-weight: 400; margin: 12px 0 6px; }

/* Sparkle for premium features */
.premium-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #78350f; border: 1px solid #fcd34d;
  letter-spacing: .04em;
}
