/* ==========================================================================
   SAKSHAM — Design system v2
   A reading tool for neurodivergent learners.

   The look: friendly, confident, generous. Rounded shapes, chunky tappable
   buttons, clear colour-coded categories, one idea per card. Everything
   still bends to the reader's own font / size / contrast / motion settings —
   the theme tokens below are re-declared per `body[data-*]` so a single
   stylesheet serves cream, soft blue, dark and high-contrast modes.

   Sections
     1.  Tokens & themes
     2.  Reset & base type
     3.  Layout primitives
     4.  Buttons, chips, switches
     5.  Site chrome (nav, footer, skip link)
     6.  Setup screen
     7.  Home — hero
     8.  Home — library (stats, cards, carousel)
     9.  Panels (preferences, filters)
     10. Reader
     11. Complete screen
     12. Achievements
     13. Educators
     14. Prose pages
     15. Toast, popovers, utilities
     16. Responsive
   ========================================================================== */

/* ==========================================================================
   1. TOKENS & THEMES
   ========================================================================== */

:root {
  /* Brand */
  --c-accent:      #3D5CFF;
  --c-accent-soft: #E5EAFF;
  --c-warm:        #FF7C24;
  --c-warm-soft:   #FFE7DA;
  --c-sun:         #FFC531;

  /* Category identity.
     Each colour comes in three parts: the vivid `--cat-*` for shapes (card
     top rules, icon tiles), the `-soft` wash behind small labels, and the
     `-ink` variant for text. The ink variants are darkened until every
     label clears WCAG AA at 11–13px against its own soft wash — the vivid
     hue would only reach ~2.5:1 there. */
  --cat-stories:      #F0761E;
  --cat-stories-soft: #FFEDE0;
  --cat-stories-ink:  #9C4406;
  --cat-science:      #17916B;
  --cat-science-soft: #DDF4EC;
  --cat-science-ink:  #0E7150;
  --cat-sky:          #6E45B5;
  --cat-sky-soft:     #EDE6FA;
  --cat-sky-ink:      #5E38A4;

  /* Semantic */
  --ok:       #0E7150;
  --ok-soft:  #DDF4EC;
  --ok-ink:   #0E7150;
  --ok-badge-ink: #FFFFFF;

  /* Radii — big and soft */
  --r-xs: 8px;
  --r-sm: 12px;
  --r:    16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Elevation. Themes override these so dark mode doesn't get muddy. */
  --shadow-sm: 0 1px 2px rgba(23, 28, 38, 0.05), 0 2px 8px rgba(23, 28, 38, 0.05);
  --shadow:    0 2px 4px rgba(23, 28, 38, 0.05), 0 8px 24px rgba(23, 28, 38, 0.07);
  --shadow-lg: 0 4px 8px rgba(23, 28, 38, 0.05), 0 18px 44px rgba(23, 28, 38, 0.10);

  /* Type */
  --font-brand: 'Nunito', 'Poppins', system-ui, sans-serif;
  --font-body:  'Atkinson Hyperlegible', system-ui, sans-serif;

  --size-body: 1.0625rem;
  --line-height: 1.7;
  --letter-spacing: 0.005em;

  /* Motion + layout */
  --motion-scale: 1;
  --container: 74rem;
  --container-narrow: 46rem;
  --measure: 38rem;

  --nav-h: 4.25rem;
}

/* ---- Theme: warm cream (default) ---- */
body[data-contrast="cream"] {
  --bg: #FFFAF2;
  --bg-soft: #F7EFE1;
  --bg-card: #FFFFFF;
  --bg-sunk: #FBF5EA;
  --ink: #191E27;
  --ink-soft: #5A6472;
  --ink-faint: #8D97A6;
  --line: #EADFCB;
  --line-strong: #DBCCAF;
  --accent: #3D5CFF;
  --accent-soft: #E5EAFF;
  --accent-ink: #FFFFFF;
  --accent-strong: #2C42C4;   /* accent text on --accent-soft */
  --btn-shade: #2C42C4;
}

/* ---- Theme: soft blue ---- */
body[data-contrast="soft"] {
  --bg: #F2F5FC;
  --bg-soft: #E5EBF6;
  --bg-card: #FFFFFF;
  --bg-sunk: #EDF1FA;
  --ink: #171C26;
  --ink-soft: #4A5462;
  --ink-faint: #808B9B;
  --line: #D7E0EE;
  --line-strong: #BCC9DC;
  --accent: #3D5CFF;
  --accent-soft: #DFE5FA;
  --accent-ink: #FFFFFF;
  --accent-strong: #2C42C4;
  --btn-shade: #2C42C4;
}

/* ---- Theme: dark ---- */
body[data-contrast="dark"] {
  --bg: #12161D;
  --bg-soft: #1A2029;
  --bg-card: #1E2531;
  --bg-sunk: #171D25;
  --ink: #EDF0F5;
  --ink-soft: #B4BDCB;
  --ink-faint: #8590A1;
  --line: #2B3341;
  --line-strong: #3B4557;
  --accent: #8FA3FF;
  --accent-soft: #232E4B;
  --accent-ink: #101521;
  --btn-shade: #5F72C9;

  --cat-stories: #FFA25C;      --cat-stories-soft: #34261C;  --cat-stories-ink: #FFA25C;
  --cat-science: #58CFA6;      --cat-science-soft: #16302A;  --cat-science-ink: #58CFA6;
  --cat-sky:     #B79BEC;      --cat-sky-soft:     #26203A;  --cat-sky-ink:     #B79BEC;
  --ok: #58CFA6;               --ok-soft: #16302A;           --ok-ink: #58CFA6;
  --ok-badge-ink: #0C1F19;
  --accent-strong: #8FA3FF;
  --c-warm-soft: #35251A;
  --c-accent-soft: #232E4B;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:    0 2px 6px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 4px 10px rgba(0, 0, 0, 0.4), 0 20px 48px rgba(0, 0, 0, 0.32);
}

/* ---- Theme: high contrast ---- */
body[data-contrast="high"] {
  --bg: #000000;
  --bg-soft: #000000;
  --bg-card: #000000;
  --bg-sunk: #0B0B0B;
  --ink: #FFFFFF;
  --ink-soft: #FFFFFF;
  --ink-faint: #FFD301;
  --line: #FFFFFF;
  --line-strong: #FFD301;
  --accent: #FFD301;
  --accent-soft: #2A2500;
  --accent-ink: #000000;
  --btn-shade: #A88A00;

  --cat-stories: #FFD301;      --cat-stories-soft: #2A2500;  --cat-stories-ink: #FFD301;
  --cat-science: #FFD301;      --cat-science-soft: #2A2500;  --cat-science-ink: #FFD301;
  --cat-sky:     #FFD301;      --cat-sky-soft:     #2A2500;  --cat-sky-ink:     #FFD301;
  --ok: #FFD301;               --ok-soft: #2A2500;           --ok-ink: #FFD301;
  --ok-badge-ink: #000000;
  --accent-strong: #FFD301;
  --c-warm-soft: #2A2500;
  --c-accent-soft: #2A2500;
  --c-sun: #FFD301;

  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: none;
}
/* High contrast wants hard edges, not soft depth. */
body[data-contrast="high"] .passage-card,
body[data-contrast="high"] .stat-card,
body[data-contrast="high"] .badge,
body[data-contrast="high"] .panel,
body[data-contrast="high"] .setup-card,
body[data-contrast="high"] .complete-card,
body[data-contrast="high"] .teacher-panel,
body[data-contrast="high"] .hero-progress,
body[data-contrast="high"] .prefs,
body[data-contrast="high"] .filter-panel { border-width: 2px; }

/* ---- Reader-chosen font ---- */
body[data-font="atkinson"] { --font-body: 'Atkinson Hyperlegible', system-ui, sans-serif; }
body[data-font="lexend"]   { --font-body: 'Lexend', system-ui, sans-serif; }
body[data-font="opendys"]  { --font-body: 'OpenDyslexic', 'Atkinson Hyperlegible', sans-serif; }
body[data-font="system"]   { --font-body: ui-sans-serif, system-ui, sans-serif; }

/* ---- Reader-chosen size ---- */
body[data-size="m"]  { --size-body: 1.0625rem; }
body[data-size="l"]  { --size-body: 1.1875rem; --measure: 36rem; }
body[data-size="xl"] { --size-body: 1.375rem;  --measure: 34rem; }

/* ---- Reader-chosen motion ---- */
body[data-motion="full"]    { --motion-scale: 1; }
body[data-motion="reduced"] { --motion-scale: 0.4; }
body[data-motion="none"]    { --motion-scale: 0; }
@media (prefers-reduced-motion: reduce) { :root { --motion-scale: 0; } }


/* ==========================================================================
   2. RESET & BASE TYPE
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Several components below set an explicit `display`, which would otherwise
   beat the UA stylesheet's rule for [hidden]. Keep [hidden] authoritative. */
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--size-body);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color calc(0.25s * var(--motion-scale)) ease,
              color calc(0.25s * var(--motion-scale)) ease;
}

h1, h2, h3, h4 {
  font-family: var(--font-brand);
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 0.5rem;
  font-weight: 800;
  text-wrap: balance;
}
h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 3rem); }
h2 { font-size: clamp(1.45rem, 1.2rem + 1vw, 1.9rem); }
h3 { font-size: 1.15rem; font-weight: 700; }
h4 { font-size: 0.95rem; font-weight: 700; letter-spacing: 0; }

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 3px; }

strong, b { font-weight: 700; }

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

.lede {
  font-size: 1.125em;
  color: var(--ink-soft);
  max-width: 42rem;
  margin: 0 0 1.25rem;
}
.text-soft { color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: 0.875rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}


/* ==========================================================================
   3. LAYOUT PRIMITIVES
   ========================================================================== */

main { flex: 1 0 auto; width: 100%; }
/* #main is focused programmatically after the skip link and on screen change.
   Screen readers still announce it; a page-wide outline would just be noise. */
main[tabindex="-1"]:focus { outline: none; }

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: clamp(1.15rem, 4vw, 2.5rem);
}

.screen { display: none; }
.screen.active { display: block; animation: fade calc(0.3s * var(--motion-scale)) ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.divider { height: 1px; background: var(--line); border: 0; margin: 2.5rem 0; }
.sep { color: var(--ink-faint); }


/* ==========================================================================
   4. BUTTONS, CHIPS, SWITCHES
   ========================================================================== */

/* Chunky "pressable" button — the solid bottom edge is the signature. */
.btn {
  --btn-lift: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.72rem 1.4rem;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 0.98rem;
  letter-spacing: 0.01em;
  line-height: 1.25;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: var(--r-pill);
  box-shadow: 0 var(--btn-lift) 0 var(--btn-shade);
  cursor: pointer;
  text-decoration: none;
  transition: transform calc(0.12s * var(--motion-scale)) ease,
              box-shadow calc(0.12s * var(--motion-scale)) ease,
              filter calc(0.15s * var(--motion-scale)) ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active {
  transform: translateY(var(--btn-lift));
  box-shadow: 0 0 0 var(--btn-shade);
}
.btn.lg { padding: 0.95rem 1.85rem; font-size: 1.05rem; --btn-lift: 4px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn.ghost {
  color: var(--ink);
  background: var(--bg-card);
  box-shadow: 0 var(--btn-lift) 0 var(--line);
  border: 2px solid var(--line);
  padding: calc(0.72rem - 2px) calc(1.4rem - 2px);
}
.btn.ghost:hover { background: var(--bg-soft); filter: none; border-color: var(--line-strong); }
.btn.ghost:active { box-shadow: 0 0 0 var(--line); }

/* Selectable pill (font / size / motion / language / need filters) */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-soft);
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-checked="true"], .chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Grade number buttons */
.grade-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.grade {
  width: 2.75rem; height: 2.75rem;
  display: grid; place-items: center;
  font-family: var(--font-brand);
  font-weight: 800;
  color: var(--ink-soft);
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.grade:hover { border-color: var(--line-strong); color: var(--ink); }
.grade[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}

/* Theme swatches */
.swatch-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.swatch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.9rem 0.45rem 0.5rem;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-soft);
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.swatch-btn:hover { border-color: var(--line-strong); }
.swatch-btn[aria-checked="true"] { border-color: var(--accent); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }
.sw {
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  flex: none;
}

/* Toggle switch */
.switch { display: inline-flex; align-items: center; cursor: pointer; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  display: block;
  width: 3.1rem; height: 1.75rem;
  background: var(--line-strong);
  border-radius: var(--r-pill);
  position: relative;
  transition: background calc(0.2s * var(--motion-scale)) ease;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 1.25rem; height: 1.25rem;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform calc(0.2s * var(--motion-scale)) ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(1.35rem); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Range slider */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; max-width: 22rem;
  height: 0.7rem;
  background: var(--bg-sunk);
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 1.45rem; height: 1.45rem;
  background: var(--accent);
  border: 3px solid var(--bg-card);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 1.2rem; height: 1.2rem;
  background: var(--accent);
  border: 3px solid var(--bg-card);
  border-radius: 50%;
  cursor: pointer;
}

/* Text inputs */
input[type="text"], textarea {
  width: 100%;
  padding: 0.85rem 1.05rem;
  background: var(--bg-card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color calc(0.15s * var(--motion-scale)) ease;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 6.5rem; line-height: 1.6; }
::placeholder { color: var(--ink-faint); opacity: 1; }

label { display: block; font-family: var(--font-brand); font-weight: 700; font-size: 0.95rem; margin-bottom: 0.4rem; }


/* ==========================================================================
   5. SITE CHROME
   ========================================================================== */

.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.7rem 1.15rem;
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 800;
  text-decoration: none;
  transition: top calc(0.15s * var(--motion-scale)) ease;
}
.skip:focus { top: 1rem; }

.site-nav {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: var(--container);
  margin-inline: auto;
  padding: 0 clamp(1.15rem, 4vw, 2.5rem);
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-family: var(--font-brand); font-weight: 800; font-size: 1.2rem;
  color: var(--ink); text-decoration: none;
  margin-right: auto;
}
.brand-mark {
  width: 2.3rem; height: 2.3rem;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 0.8rem;
  font-size: 1.15rem; font-weight: 700;
  box-shadow: 0 2px 0 var(--btn-shade);
  flex: none;
}
.nav-links { display: flex; align-items: center; gap: 0.25rem; }
.nav-links a {
  padding: 0.5rem 0.95rem;
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 700; font-size: 0.94rem;
  color: var(--ink-soft);
  text-decoration: none;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.nav-links a:hover { background: var(--bg-soft); color: var(--ink); }
.nav-links a.current { background: var(--accent-soft); color: var(--accent-strong); }
body[data-contrast="high"] .nav-links a.current { outline: 2px solid var(--accent); }

.nav-toggle {
  display: none;
  padding: 0.5rem 0.9rem;
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 700; font-size: 0.9rem;
  cursor: pointer;
}

.site-footer {
  flex: none;
  margin-top: 4rem;
  padding: 2rem 0;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.site-footer .container { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; justify-content: space-between; }
.footer-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; }
.footer-links a { color: var(--ink-soft); text-decoration: none; font-weight: 700; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }


/* ==========================================================================
   6. SETUP SCREEN
   ========================================================================== */

.setup {
  min-height: calc(100vh - var(--nav-h) - 8rem);
  display: grid;
  place-items: center;
  padding: clamp(2rem, 6vw, 4rem) clamp(1.15rem, 4vw, 2.5rem);
  background:
    radial-gradient(50rem 26rem at 15% -10%, var(--accent-soft), transparent 65%),
    radial-gradient(38rem 24rem at 90% 0%, var(--c-warm-soft), transparent 60%);
}
.setup-card {
  width: 100%;
  max-width: 34rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: clamp(1.75rem, 4vw, 2.75rem);
}
.setup-card h1 { font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.25rem); margin-bottom: 0.5rem; }
.meaning {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 0.2rem 0.7rem;
  border-radius: var(--r-pill);
  font-weight: 700;
  margin: 0 0 1rem;
}
.setup-card label { margin-top: 1.35rem; }
.avatar-picks {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}
@media (max-width: 34rem) { .avatar-picks { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.avatar-pick {
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  padding: 0.75rem 0.4rem;
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r);
  font-family: var(--font-brand); font-weight: 700; font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.avatar-pick:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.avatar-pick[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.setup-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.75rem; }
.dots { display: flex; gap: 0.4rem; justify-content: center; margin-top: 1.5rem; }
.dots > span {
  width: 0.5rem; height: 0.5rem;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transition: all calc(0.2s * var(--motion-scale)) ease;
}
.dots > span.on { width: 1.5rem; background: var(--accent); }

/* Avatar bubbles (shared with hero, educators roster) */
.avatar {
  display: grid; place-items: center;
  width: 2.4rem; height: 2.4rem;
  border-radius: 50%;
  font-size: 1.2rem;
  flex: none;
  line-height: 1;
}
.av-blue  { background: #DDE4FF; }
.av-green { background: #D8F2E7; }
.av-warm  { background: #FFE3CF; }
.av-sun   { background: #FFF0C2; }
.av-lav   { background: #ECE1FB; }
.av-rose  { background: #FCDEE7; }


/* ==========================================================================
   7. HOME — HERO
   ========================================================================== */

.hero-section {
  position: relative;
  padding: clamp(2.5rem, 5vw, 4.5rem) 0 clamp(2.5rem, 5vw, 4rem);
  background:
    radial-gradient(48rem 24rem at 8% 0%, var(--accent-soft), transparent 60%),
    radial-gradient(34rem 22rem at 95% 10%, var(--c-warm-soft), transparent 60%);
  border-bottom: 1px solid var(--line);
}
.hero-content {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
}
.hero-text { min-width: 0; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-family: var(--font-brand); font-weight: 800;
  font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 0.35rem 0.85rem;
  border-radius: var(--r-pill);
  margin: 0 0 1rem;
}
.hero-text h1 { margin-bottom: 0.75rem; }
.name-dot { color: var(--accent); }
.hero-sub { color: var(--ink-soft); font-size: 1.08em; max-width: 34rem; margin-bottom: 1.75rem; }

.hero-progress {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  max-width: 30rem;
  margin-bottom: 1.75rem;
}
.progress-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.7rem;
  font-family: var(--font-brand); font-weight: 700; font-size: 0.95rem;
}
.progress-row a { text-decoration: none; font-size: 0.88rem; }
.progress-row a:hover { text-decoration: underline; }
.progress-bar {
  display: block;
  height: 0.85rem;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress-fill, .progress-bar .fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--ok)));
  border-radius: var(--r-pill);
  transition: width calc(0.6s * var(--motion-scale)) cubic-bezier(0.22, 1, 0.36, 1);
}

.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; }
.edit-name-link {
  background: none; border: 0; padding: 0.4rem 0.2rem;
  color: var(--ink-soft); font-size: 0.88rem;
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.edit-name-link:hover { color: var(--accent); }

/* Hero orb — avatar in a set of soft rings with floating chips */
.hero-visual { display: grid; place-items: center; min-width: 0; }
.hero-orb {
  position: relative;
  width: min(20rem, 60vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.hero-orb .avatar {
  width: 46%; height: 46%;
  font-size: clamp(2.5rem, 7vw, 4rem);
  background: var(--bg-card);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 2;
}
.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px dashed var(--line-strong);
}
.orb-ring-1 {
  inset: 12%;
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
  border-style: solid;
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
  animation: pulse calc(6s / max(var(--motion-scale), 0.001)) ease-in-out infinite;
}
.orb-ring-2 { inset: 0; opacity: 0.75; animation: spin calc(50s / max(var(--motion-scale), 0.001)) linear infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@keyframes spin { to { transform: rotate(360deg); } }
body[data-motion="none"] .orb-ring-1,
body[data-motion="none"] .orb-ring-2,
body[data-motion="none"] .float-chip { animation: none !important; }

.float-chip {
  position: absolute;
  z-index: 3;
  display: grid; place-items: center;
  width: 3rem; height: 3rem;
  font-size: 1.4rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  animation: bob calc(5s / max(var(--motion-scale), 0.001)) ease-in-out infinite;
}
.chip-book { top: 6%;  left: 2%;  }
.chip-star { top: 20%; right: 0%; animation-delay: -1.6s; }
.chip-leaf { bottom: 8%; right: 12%; animation-delay: -3.2s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }


/* ==========================================================================
   8. HOME — LIBRARY
   ========================================================================== */

.library-section { padding: clamp(2.5rem, 5vw, 4rem) 0 1rem; }
.library-header {
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between;
  margin-bottom: 0.35rem;
}
.library-header h2 { margin: 0; }
.library-tools { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* --- Stat tiles --- */
.lib-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.9rem;
  margin: 1.75rem 0 2rem;
}
.stat-card {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.stat-ic {
  display: grid; place-items: center;
  width: 2.75rem; height: 2.75rem;
  border-radius: var(--r);
  font-size: 1.25rem;
  flex: none;
}
.stat-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.stat-num { font-family: var(--font-brand); font-weight: 800; font-size: 1.6rem; letter-spacing: -0.02em; }
.stat-label { font-size: 0.82rem; color: var(--ink-soft); font-weight: 600; }
.s-blue   .stat-ic { background: var(--c-accent-soft);  color: var(--accent-strong); }
.s-green  .stat-ic { background: var(--ok-soft);        color: var(--ok-ink); }
.s-purple .stat-ic { background: var(--cat-sky-soft);   color: var(--cat-sky-ink); }
.s-warm   .stat-ic { background: var(--c-warm-soft);    color: var(--cat-stories-ink); }

/* --- Card grid (becomes a snap carousel on narrow screens) --- */
.lib-carousel { position: relative; }
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: 1.1rem;
}
.carousel-nav, .carousel-dots { display: none; }

.passage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
  padding: 1.35rem 1.35rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  color: var(--ink);
  transition: transform calc(0.18s * var(--motion-scale)) ease,
              box-shadow calc(0.18s * var(--motion-scale)) ease,
              border-color calc(0.18s * var(--motion-scale)) ease;
}
.passage-card::before {
  content: '';
  position: absolute; inset: 0 0 auto 0;
  height: 5px;
  background: var(--cat, var(--accent));
}
.passage-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--cat, var(--accent));
}
/* A finished passage keeps its colour but settles back — still inviting to
   re-read, no longer competing for attention with the unread ones. */
.passage-card:has(.p-done-badge) { background: var(--bg-sunk); }
.passage-card:has(.p-done-badge) h3 { color: var(--ink-soft); }

.passage-card.p-stories { --cat: var(--cat-stories); --cat-soft: var(--cat-stories-soft); --cat-ink: var(--cat-stories-ink); }
.passage-card.p-science { --cat: var(--cat-science); --cat-soft: var(--cat-science-soft); --cat-ink: var(--cat-science-ink); }
.passage-card.p-sky     { --cat: var(--cat-sky);     --cat-soft: var(--cat-sky-soft);     --cat-ink: var(--cat-sky-ink); }

.p-top { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.15rem; }
.p-icon {
  display: grid; place-items: center;
  width: 2.4rem; height: 2.4rem;
  border-radius: var(--r-sm);
  background: var(--cat-soft, var(--accent-soft));
  font-size: 1.15rem;
  flex: none;
}
.p-cat-label {
  font-family: var(--font-brand); font-weight: 800;
  font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--cat-ink, var(--accent-strong));
}
.p-done-badge {
  margin-left: auto;
  display: grid; place-items: center;
  width: 1.7rem; height: 1.7rem;
  border-radius: 50%;
  background: var(--ok); color: var(--ok-badge-ink);
  font-size: 0.85rem; font-weight: 700;
  flex: none;
}

.passage-card h3 { margin: 0.1rem 0 0; font-size: 1.15rem; line-height: 1.25; }
.passage-card .preview {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.p-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.15rem; }
.p-tag {
  display: inline-block;
  padding: 0.22rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-brand);
  color: var(--ink-soft);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.t-dyslexia { color: var(--cat-stories-ink); background: var(--cat-stories-soft); border-color: transparent; }
.t-adhd     { color: var(--accent-strong); background: var(--c-accent-soft);  border-color: transparent; }
.t-autism   { color: var(--cat-sky-ink);  background: var(--cat-sky-soft);    border-color: transparent; }
.t-speech   { color: var(--ok-ink);       background: var(--ok-soft);         border-color: transparent; }
.t-visual   { color: var(--ink-soft);    background: var(--bg-sunk); }

.p-foot {
  display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem;
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.p-foot-item { display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.fi-ic { font-size: 0.9em; opacity: 0.85; }

.lib-empty {
  grid-column: 1 / -1;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border: 2px dashed var(--line-strong);
  border-radius: var(--r-lg);
}


/* ==========================================================================
   9. PANELS — preferences & filters
   ========================================================================== */

.prefs, .filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.9rem;
  overflow: hidden;
}
.prefs > summary, .filter-panel > summary {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.prefs > summary::-webkit-details-marker,
.filter-panel > summary::-webkit-details-marker { display: none; }
.prefs > summary:hover, .filter-panel > summary:hover { background: var(--bg-soft); }

.sum-icon {
  display: grid; place-items: center;
  width: 2.5rem; height: 2.5rem;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  font-size: 1.1rem;
  flex: none;
}
.filter-icon { background: var(--c-warm-soft); }
.sum-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }
.sum-title { font-family: var(--font-brand); font-weight: 800; font-size: 1rem; }
.sum-toggle {
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--bg-sunk);
  color: var(--ink-soft);
  flex: none;
}
.chev { display: block; transition: transform calc(0.2s * var(--motion-scale)) ease; line-height: 1; }
details[open] > summary .chev { transform: rotate(180deg); }

.prefs-body, .filter-body {
  padding: 1.4rem 1.25rem;
  border-top: 1px solid var(--line);
}
.prefs-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.5rem;
}
.pref-group, .filter-group { min-width: 0; }
.filter-group + .filter-group { margin-top: 1.4rem; }
.pref-label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.65rem;
  min-height: 1.9rem;
}
.pref-label h4, .filter-group h4 { margin: 0; }
.filter-group h4 { margin-bottom: 0.65rem; }
.pref-value {
  font-family: var(--font-brand); font-weight: 700; font-size: 0.85rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 0.15rem 0.6rem;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.pref-value:has(.switch) { background: none; padding: 0; }

.filter-result {
  margin-top: 1.4rem;
  padding: 0.85rem 1.1rem;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.filter-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.1rem; }


/* ==========================================================================
   10. READER
   ========================================================================== */

/* Everything in the reader shares one column width, so the title, the
   controls and the prose all start on the same line. */
#screen-reader .container { max-width: 52rem; }
.reader {
  max-width: var(--measure);
  margin-inline: auto;
  padding: 2rem 0 1rem;
}
.back {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 700; font-size: 0.9rem;
  color: var(--ink-soft);
  cursor: pointer;
  margin-bottom: 1.75rem;
}
.back:hover { border-color: var(--line-strong); color: var(--ink); }

.reader-eyebrow {
  font-family: var(--font-brand); font-weight: 800;
  font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.4rem;
}
#reader-title { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.6rem); margin-bottom: 0.6rem; }
.reader-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  color: var(--ink-soft); font-size: 0.92rem;
  margin-bottom: 1.25rem;
}

.para-progress {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 0.82rem; color: var(--ink-soft);
  margin-bottom: 1.5rem;
}
.para-progress .dots { display: flex; gap: 0.35rem; margin: 0; }
.para-progress .dot {
  width: 0.5rem; height: 0.5rem;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transition: all calc(0.3s * var(--motion-scale)) ease;
}
.para-progress .dot.read { width: 1.4rem; background: var(--accent); }

.reader-controls {
  position: sticky;
  top: calc(var(--nav-h) + 0.5rem);
  z-index: 50;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem 0.6rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow);
  margin-bottom: 2.5rem;
}
.reader-controls .grp { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.reader-controls .lbl { font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; }
.reader-controls .sep {
  width: 1px; height: 1.4rem;
  background: var(--line);
  flex: none;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 0;
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 800; font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all calc(0.15s * var(--motion-scale)) ease;
}
.icon-btn:hover { background: var(--accent); color: var(--accent-ink); }
.pace-slider { width: 6rem; height: 0.55rem; }
.pace-val { font-family: var(--font-brand); font-weight: 700; font-size: 0.82rem; color: var(--ink-soft); min-width: 2.3rem; }

/* --- The passage itself --- */
.passage-body {
  font-size: 1.12em;
  line-height: 1.85;
  text-align: left;      /* never justified — rivers of whitespace hurt dyslexic readers */
  hyphens: none;
}
.passage-body p { margin: 0 0 1.6em; }
.passage-body p:first-of-type::first-letter {
  float: left;
  font-family: var(--font-brand);
  font-size: 3.1em;
  line-height: 0.82;
  font-weight: 800;
  color: var(--accent);
  padding: 0.08em 0.12em 0 0;
}
body[data-font="opendys"] .passage-body p:first-of-type::first-letter { font-size: 2.6em; }

.word { display: inline; border-radius: 3px; }
.word.spoken {
  background: var(--c-sun);
  color: #171C26;
  box-shadow: 0 0 0 3px var(--c-sun);
}
body[data-contrast="high"] .word.spoken { background: var(--accent); color: #000; box-shadow: 0 0 0 3px var(--accent); }

.vocab {
  border-bottom: 2px dotted var(--accent);
  cursor: help;
  background: none;
  border-top: 0; border-left: 0; border-right: 0;
  padding: 0;
  font: inherit;
  color: inherit;
}
.vocab:hover { background: var(--accent-soft); }

.vocab-pop {
  position: absolute;
  z-index: 150;
  max-width: 17rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity calc(0.15s * var(--motion-scale)) ease, transform calc(0.15s * var(--motion-scale)) ease;
}
.vocab-pop.open { opacity: 1; transform: none; }
.vocab-pop .word {
  display: block;
  font-family: var(--font-brand); font-weight: 800;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

/* --- Reflection --- */
.reflect {
  margin: 3rem 0 0;
  padding: 1.5rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
}
.reflect h2 { font-size: 1.2rem; margin-bottom: 0.4rem; }
.prompt { font-style: italic; color: var(--ink-soft); margin-bottom: 1rem; }
.prev-reflection {
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 0.92rem;
  margin-bottom: 1rem;
}
.prev-reflection .lbl { display: block; font-weight: 700; color: var(--ink-soft); font-size: 0.8rem; margin-bottom: 0.2rem; }
.reflect-meta {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
  justify-content: space-between;
  font-size: 0.8rem; color: var(--ink-faint);
  margin: 0.4rem 0 1.1rem;
}
.reflect-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.skip-note { font-size: 0.85rem; color: var(--ink-soft); }


/* ==========================================================================
   11. COMPLETE SCREEN
   ========================================================================== */

.complete { display: grid; place-items: center; padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.complete-card {
  width: 100%;
  max-width: 36rem;
  margin-inline: auto;
  text-align: center;
  padding: clamp(1.75rem, 4vw, 2.75rem);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
}
.complete-icon {
  display: grid; place-items: center;
  width: 5rem; height: 5rem;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 2.25rem;
  animation: pop calc(0.5s * var(--motion-scale)) cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* The title carries a passage name, so it needs to stay calm at 3–7 words. */
.complete-card h1 { font-size: clamp(1.5rem, 1.15rem + 1.4vw, 2rem); }
.complete-sub { color: var(--ink-soft); }
.saved-line { font-size: 0.88rem; color: var(--ink-faint); }

.next-suggest { margin-top: 1.75rem; text-align: left; }
.next-suggest h2 { font-size: 1rem; color: var(--ink-soft); margin-bottom: 0.6rem; }
.next-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 1.15rem 1.25rem;
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  cursor: pointer;
  font: inherit; color: var(--ink);
  transition: all calc(0.18s * var(--motion-scale)) ease;
}
.next-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow); }
.next-card .meta {
  font-family: var(--font-brand); font-weight: 800;
  font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.35rem;
}
.next-card h3 { margin: 0 0 0.3rem; }
.next-card p { margin: 0; font-size: 0.9rem; color: var(--ink-soft); }
.all-done { margin-top: 1.5rem; padding: 1.25rem; background: var(--ok-soft); border-radius: var(--r-lg); }
.complete-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; justify-content: center; margin-top: 1.75rem; }


/* ==========================================================================
   12. ACHIEVEMENTS
   ========================================================================== */

.page-intro {
  padding: clamp(2.5rem, 5vw, 4rem) 0 clamp(2rem, 4vw, 3rem);
  background:
    radial-gradient(46rem 22rem at 10% 0%, var(--accent-soft), transparent 62%),
    radial-gradient(32rem 20rem at 92% 8%, var(--c-warm-soft), transparent 60%);
  border-bottom: 1px solid var(--line);
  margin-bottom: 2.5rem;
}
.page-intro h1 { margin-bottom: 0.75rem; }

/* Book-spine strip used as a decorative rule under page intros */
.hero-books, .intro-books {
  display: flex; align-items: flex-end; gap: 4px;
  margin-top: 1.75rem;
  height: 3.5rem;
}
.hero-books span, .intro-books span {
  display: block;
  width: 0.85rem;
  border-radius: 3px 3px 0 0;
  opacity: 0.9;
}
body[data-contrast="high"] .hero-books span,
body[data-contrast="high"] .intro-books span { background: var(--accent) !important; }

.panel {
  padding: 1.15rem 1.35rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.badge {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  transition: transform calc(0.18s * var(--motion-scale)) ease;
}
.badge h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.badge p { margin: 0; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.5; }
.badge-icon {
  display: grid; place-items: center;
  width: 3.25rem; height: 3.25rem;
  border-radius: 50%;
  font-size: 1.55rem;
  flex: none;
  background: var(--bg-sunk);
  border: 2px solid var(--line);
}
.badge.locked { opacity: 0.62; }
.badge.locked .badge-icon { filter: grayscale(1); }
.badge.unlocked {
  border-color: color-mix(in srgb, var(--c-sun) 65%, var(--line));
  background: linear-gradient(180deg, color-mix(in srgb, var(--c-sun) 12%, var(--bg-card)), var(--bg-card));
}
.badge.unlocked:hover { transform: translateY(-3px); }
.badge.unlocked .badge-icon {
  background: color-mix(in srgb, var(--c-sun) 28%, var(--bg-card));
  border-color: color-mix(in srgb, var(--c-sun) 60%, transparent);
}
.badge .when {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem; font-weight: 700;
  color: var(--ok-ink);
  background: var(--ok-soft);
  border-radius: var(--r-pill);
}


/* ==========================================================================
   13. EDUCATORS
   ========================================================================== */

.teacher-panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3vw, 1.9rem);
  margin-bottom: 3rem;
}
.teacher-panel .head {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
  align-items: baseline; justify-content: space-between;
  margin-bottom: 1rem;
}
.teacher-panel .head h2 { margin: 0; }
.class-meta { font-size: 0.88rem; color: var(--ink-soft); font-weight: 600; }
.demo-note {
  padding: 0.9rem 1.1rem;
  background: var(--c-warm-soft);
  border-radius: var(--r);
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 1.5rem;
}
body[data-contrast="high"] .demo-note { border: 2px solid var(--accent); }

.roster { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.roster th {
  text-align: left;
  font-family: var(--font-brand); font-weight: 800;
  font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0 0.75rem 0.75rem;
  border-bottom: 2px solid var(--line);
}
.roster td { padding: 0.95rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.roster tbody tr:last-child td { border-bottom: 0; }
.roster tbody tr { transition: background calc(0.15s * var(--motion-scale)) ease; }
.roster tbody tr:hover { background: var(--bg-sunk); }
.student { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-brand); font-weight: 700; white-space: nowrap; }
.roster td:nth-child(2) .tag { margin: 0 0.3rem 0.3rem 0; }
.roster td:nth-child(3) { white-space: nowrap; font-family: var(--font-brand); font-weight: 700; }
.roster td:nth-child(3) .progress-bar { display: inline-block; width: 5.5rem; vertical-align: middle; margin-right: 0.5rem; height: 0.65rem; }
.roster td:nth-child(4) { color: var(--ink-soft); font-size: 0.88rem; min-width: 13rem; }

.tag {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  font-size: 0.78rem; font-weight: 700;
  font-family: var(--font-brand);
  color: var(--ink-soft);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.tag.accent { color: var(--accent-strong); background: var(--c-accent-soft); border-color: transparent; }
.tag.warm { color: var(--cat-stories-ink); background: var(--c-warm-soft); border-color: transparent; }


/* ==========================================================================
   14. PROSE PAGES
   ========================================================================== */

/* Left-aligned, not centred: the page intro above it starts at the container
   edge, and a centred column would leave a visible jog between the two. */
.prose { max-width: var(--container-narrow); }
.prose h2 { margin: 2.5rem 0 0.75rem; }
.prose > h2:first-child, .prose > *:first-child { margin-top: 0; }
.prose h3 { margin: 1.75rem 0 0.5rem; }
.prose p, .prose li { color: var(--ink-soft); }
.prose li { margin-bottom: 0.5rem; }
.prose ul, .prose ol { padding-left: 1.35rem; margin: 0 0 1.25rem; }
.prose blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--bg-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-sm);
  font-style: italic;
}
.prose table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: 0.92rem; }
.prose th, .prose td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--line); }
.prose th { font-family: var(--font-brand); font-weight: 800; }
.prose code {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1em 0.4em;
  font-size: 0.9em;
}

/* About-page intro row (visual + text) */
.intro-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.55fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}
.intro-text { min-width: 0; }
.intro-visual { display: grid; place-items: center; min-width: 0; }
.intro-orb {
  position: relative;
  display: grid; place-items: center;
  width: min(13rem, 45vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}
.intro-emoji { font-size: clamp(2.5rem, 8vw, 4rem); }


/* ==========================================================================
   15. TOAST, INDICATORS, UTILITIES
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%; bottom: 1.5rem;
  transform: translate(-50%, 150%);
  z-index: 200;
  display: flex; align-items: center; gap: 0.9rem;
  max-width: min(26rem, calc(100vw - 2rem));
  padding: 0.9rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform calc(0.35s * var(--motion-scale)) cubic-bezier(0.34, 1.4, 0.64, 1),
              opacity calc(0.25s * var(--motion-scale)) ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast .icon {
  display: grid; place-items: center;
  width: 2.6rem; height: 2.6rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c-sun) 28%, var(--bg-card));
  font-size: 1.3rem;
  flex: none;
}
.toast .title { font-family: var(--font-brand); font-weight: 800; font-size: 0.95rem; }
.toast .meta { font-size: 0.85rem; color: var(--ink-soft); }

.voice-indicator {
  position: fixed;
  right: 1rem; bottom: 1rem;
  z-index: 90;
  padding: 0.5rem 0.95rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--r-pill);
  font-family: var(--font-brand); font-weight: 700; font-size: 0.82rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity calc(0.2s * var(--motion-scale)) ease;
}
.voice-indicator.on { opacity: 1; }


/* ==========================================================================
   16. RESPONSIVE
   ========================================================================== */

@media (max-width: 62rem) {
  .hero-content { grid-template-columns: 1fr; }
  .hero-visual { order: -1; justify-items: start; }
  .hero-orb { width: min(14rem, 45vw); }
  .float-chip { width: 2.4rem; height: 2.4rem; font-size: 1.1rem; }
  .intro-row { grid-template-columns: 1fr; }
  .intro-visual { justify-items: start; }
}

@media (max-width: 52rem) {
  :root { --nav-h: 3.75rem; }

  .nav-toggle { display: inline-block; }
  .nav-links {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.2rem;
    padding-bottom: 0.85rem;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 0.7rem 1rem; }

  /* Library becomes a snap carousel on small screens */
  .lib-grid {
    display: flex;
    gap: 0.9rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .lib-grid::-webkit-scrollbar { display: none; }
  .passage-card { flex: 0 0 min(20rem, 82vw); scroll-snap-align: start; }

  .carousel-dots { display: flex; gap: 0.4rem; justify-content: center; margin-top: 1rem; }
  .carousel-dot {
    width: 0.5rem; height: 0.5rem;
    padding: 0;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--line-strong);
    cursor: pointer;
    transition: all calc(0.2s * var(--motion-scale)) ease;
  }
  .carousel-dot.active { width: 1.5rem; background: var(--accent); }

  /* Once the toolbar wraps, the vertical rules land at row ends and read as noise. */
  .reader-controls { border-radius: var(--r-lg); }
  .reader-controls .sep { display: none; }
  .site-footer .container { flex-direction: column; align-items: flex-start; }

  /* Roster becomes stacked cards */
  .roster thead { display: none; }
  .roster, .roster tbody, .roster tr, .roster td { display: block; width: 100%; }
  .roster tr {
    background: var(--bg-sunk);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 0.85rem 1rem;
    margin-bottom: 0.85rem;
  }
  .roster td, .roster tbody tr:last-child td { border: 0; padding: 0.35rem 0; }
  .roster td::before {
    content: attr(data-lbl);
    display: block;
    font-family: var(--font-brand); font-weight: 800;
    font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 0.2rem;
  }
  .roster td:first-child::before { display: none; }
  .roster td:nth-child(4) { min-width: 0; }
}

@media (max-width: 30rem) {
  .btn, .btn.lg { width: 100%; }
  .hero-actions, .setup-actions, .complete-actions, .filter-actions, .reflect-actions { flex-direction: column; align-items: stretch; }
  .edit-name-link { text-align: center; }
  .badge-grid { grid-template-columns: 1fr; }
  .lib-stats { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .stat-card { padding: 0.8rem; gap: 0.6rem; }
  .stat-ic { width: 2.25rem; height: 2.25rem; font-size: 1.05rem; }
  .stat-num { font-size: 1.3rem; }
  .reflect-actions .skip-note { text-align: center; }
}

@media print {
  .site-nav, .site-footer, .reader-controls, .reflect, .toast, .voice-indicator, .back { display: none !important; }
  .passage-body { max-width: none; }
}
