/* LinguaFlow — mobile-first stylesheet. Original visual identity:
   deep teal + warm paper, saffron for rewards.

   Theming: every colour comes from the tokens below. <html data-theme="…">
   selects a preset (see public/js/core/theme.js); "system" (the default)
   follows the device's light/dark setting with the Classic palette.
   Semantic tokens (--good, --bad, --warn) mean correct / incorrect / caution
   in every theme and are kept distinct from each theme's brand colour.
   Contrast for every theme is checked by test/theme.test.js. */

/* Classic (light) — also the base for tokens that themes don't override. */
:root {
  /* Staging banner: the same in every theme (no theme overrides these). */
  --staging-bg: #8b0000;
  --staging-ink: #ffffff;
  /* Learning companion's face: the same in every theme (no overrides). */
  --comp-plate: #ffffff;
  --comp-ink: #1b2330;
  --comp-tongue: #ef7f71;
  --comp-cheek: #f29b93;
  --comp-rain: #6db4ec;
  --comp-cloud: #c9d3de;
  /* Chess board and pieces: the same in every theme, so pieces always read clearly. */
  --chess-light: #f0d9b5;
  --chess-dark: #b58863;
  --chess-piece-white: #ffffff;
  --chess-piece-black: #1b2330;
  --chess-select: #f6d743;
  --chess-last: #cdd26a;
  --chess-check: #e0584f;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1b2330;
  --ink-2: #4a5465;
  --muted: #5d6676;
  --line: #dcd7cc;
  --brand: #0b6b6a;
  --brand-ink: #ffffff;
  --brand-soft: #dff0ee;
  --brand-strong: #075251;
  --accent: #e3a21a;
  --accent-soft: #fbefd2;
  --accent-ink: #2a1c00;
  --good: #1d7a4c;
  --good-soft: #e1f3e8;
  --on-good: #ffffff;
  --bad: #b3322a;
  --bad-soft: #fbe5e2;
  --on-bad: #ffffff;
  --warn: #8a5a00;
  --warn-soft: #fdf1d8;
  --focus: #2f6fde;
  --hero-from: #0b6b6a;
  --hero-to: #075251;
  --hero-ink: #ffffff;
  --hero-btn-bg: #ffffff;
  --hero-btn-ink: #075251;
  --shadow: 0 1px 2px rgb(20 30 40 / 6%), 0 4px 14px rgb(20 30 40 / 6%);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}

/* Automatic: Classic dark when the device prefers dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  :root[data-theme="system"] {
    --bg: #0f1a1f;
    --surface: #17252b;
    --surface-2: #1f3038;
    --ink: #e9eef0;
    --ink-2: #c3ccd1;
    --muted: #9eabb2;
    --line: #2c3f47;
    --brand: #3fb5ac;
    --brand-ink: #062a29;
    --brand-soft: #173b3c;
    --brand-strong: #6fd0c8;
    --accent: #f0b743;
    --accent-soft: #3a2f16;
    --accent-ink: #2a1c00;
    --good: #5fcf92;
    --good-soft: #163327;
    --on-good: #0b1a12;
    --bad: #ff8a7f;
    --bad-soft: #3d1d1b;
    --on-bad: #2a0d0a;
    --warn: #f3c66b;
    --warn-soft: #3a2f16;
    --focus: #8ab4ff;
    --hero-from: #165c5a;
    --hero-to: #0f4544;
    --hero-ink: #f1fbfa;
    --hero-btn-bg: #ffffff;
    --hero-btn-ink: #075251;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1a1f;
  --surface: #17252b;
  --surface-2: #1f3038;
  --ink: #e9eef0;
  --ink-2: #c3ccd1;
  --muted: #9eabb2;
  --line: #2c3f47;
  --brand: #3fb5ac;
  --brand-ink: #062a29;
  --brand-soft: #173b3c;
  --brand-strong: #6fd0c8;
  --accent: #f0b743;
  --accent-soft: #3a2f16;
  --accent-ink: #2a1c00;
  --good: #5fcf92;
  --good-soft: #163327;
  --on-good: #0b1a12;
  --bad: #ff8a7f;
  --bad-soft: #3d1d1b;
  --on-bad: #2a0d0a;
  --warn: #f3c66b;
  --warn-soft: #3a2f16;
  --focus: #8ab4ff;
  --hero-from: #165c5a;
  --hero-to: #0f4544;
  --hero-ink: #f1fbfa;
  --hero-btn-bg: #ffffff;
  --hero-btn-ink: #075251;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

:root[data-theme="mint"] {
  --bg: #eef8f3;
  --surface: #ffffff;
  --surface-2: #dff1e8;
  --ink: #14261f;
  --ink-2: #3b574b;
  --muted: #4d695d;
  --line: #c9e2d6;
  --brand: #12806a;
  --brand-ink: #ffffff;
  --brand-soft: #d5f1e6;
  --brand-strong: #0b5c4c;
  --accent: #e59b2f;
  --accent-soft: #fdeccf;
  --accent-ink: #2a1a00;
  /* Leafier green than the mint brand so "correct" never reads as "selected". */
  --good: #2c731c;
  --good-soft: #e5f4dc;
  --bad: #b3322a;
  --bad-soft: #fbe5e2;
  --warn: #805200;
  --warn-soft: #fbf0d6;
  --hero-from: #12806a;
  --hero-to: #0b5c4c;
  --hero-btn-ink: #0b5c4c;
}

:root[data-theme="coral"] {
  --bg: #fff6f1;
  --surface: #ffffff;
  --surface-2: #fbe9e0;
  --ink: #2a1d1a;
  --ink-2: #5a4540;
  --muted: #6b5550;
  --line: #f0d8cd;
  --brand: #b9472c;
  --brand-ink: #ffffff;
  --brand-soft: #fde3d9;
  --brand-strong: #8f3220;
  --accent: #d98a1c;
  --accent-soft: #fcecd2;
  --accent-ink: #2a1a00;
  --good: #1d7a4c;
  --good-soft: #e1f3e8;
  /* Raspberry instead of red so "incorrect" never reads as the coral brand. */
  --bad: #a3164f;
  --bad-soft: #fbe3ec;
  --warn: #7a4f00;
  --warn-soft: #fcefd6;
  --hero-from: #c4512f;
  --hero-to: #93351f;
  --hero-btn-ink: #8f3220;
}

/* Playground: bright and friendly, for learners up to Class 8. Its animated
   sky is at the end of this file. */
:root[data-theme="playground"] {
  --bg: #e6f6ff;
  --surface: #ffffff;
  --surface-2: #dcf0fb;
  --ink: #15304b;
  --ink-2: #2c4c6b;
  --muted: #42607c;
  --line: #bcdff2;
  --brand: #3a4fd8;
  --brand-ink: #ffffff;
  --brand-soft: #e3e7ff;
  --brand-strong: #2a39a6;
  --accent: #ffb703;
  --accent-soft: #fff1c7;
  --accent-ink: #2a1c00;
  --good: #17783f;
  --good-soft: #e0f5e6;
  --bad: #c4263b;
  --bad-soft: #fde4e7;
  --warn: #7a4f00;
  --warn-soft: #fff3d1;
  --hero-from: #4b5be6;
  --hero-to: #7b3fd6;
  --hero-btn-ink: #2a39a6;
  --radius: 20px;
  --radius-sm: 14px;
  --font: ui-rounded, "Nunito", "Baloo 2", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* Playground (Pink): the same animated sky, in pinks. Art at the end of this file. */
:root[data-theme="playground-pink"] {
  --bg: #fff0f7;
  --surface: #ffffff;
  --surface-2: #fde4f0;
  --ink: #3a1530;
  --ink-2: #5f2f50;
  --muted: #6d3f5d;
  --line: #f6cbe0;
  --brand: #c2257a;
  --brand-ink: #ffffff;
  --brand-soft: #fde0ef;
  --brand-strong: #91145a;
  --accent: #ffb703;
  --accent-soft: #fff1c7;
  --accent-ink: #2a1c00;
  --good: #17783f;
  --good-soft: #e0f5e6;
  --bad: #b3261e;
  --bad-soft: #fde6e3;
  --warn: #7a4f00;
  --warn-soft: #fff3d1;
  --hero-from: #c7287e;
  --hero-to: #8237bd;
  --hero-btn-ink: #91145a;
  --radius: 20px;
  --radius-sm: 14px;
  --font: ui-rounded, "Nunito", "Baloo 2", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* Midnight Aurora: deep navy, indigo and pink glow (AeroSapiens brand style).
   Its grid, glow and glass cards are at the end of this file. */
:root[data-theme="aurora"] {
  --bg: #0b1026;
  --surface: #1a2140;
  --surface-2: #232b50;
  --ink: #f2f4ff;
  --ink-2: #c9cfe8;
  --muted: #a7afd2;
  --line: #333c66;
  --brand: #a5b0ff;
  --brand-ink: #0b1026;
  --brand-soft: #2a3163;
  --brand-strong: #c3caff;
  --accent: #f0a6e8;
  --accent-soft: #3b2547;
  --accent-ink: #2a0d28;
  --good: #5fdd9d;
  --good-soft: #15352a;
  --on-good: #0b1a12;
  --bad: #ff8fa0;
  --bad-soft: #3f1d29;
  --on-bad: #2a0d0a;
  --warn: #f3c66b;
  --warn-soft: #3a2f16;
  --focus: #8ab4ff;
  --hero-from: #4a44c6;
  --hero-to: #93307f;
  --hero-ink: #ffffff;
  --hero-btn-bg: #ffffff;
  --hero-btn-ink: #3a2fa8;
  --grad-from: #5b5ef0;
  --grad-to: #d6337f;
  --shadow: 0 1px 2px rgb(0 0 0 / 35%), 0 8px 24px rgb(3 6 25 / 45%);
  color-scheme: dark;
}

:root[data-theme="lavender"] {
  --bg: #f6f4fb;
  --surface: #ffffff;
  --surface-2: #ece8f6;
  --ink: #1f1b2e;
  --ink-2: #4a4560;
  --muted: #5d5873;
  --line: #dcd6ec;
  --brand: #5a48b0;
  --brand-ink: #ffffff;
  --brand-soft: #e9e4fa;
  --brand-strong: #43358a;
  --accent: #d39424;
  --accent-soft: #fbefd6;
  --accent-ink: #2a1a00;
  --good: #1a6f45;
  --good-soft: #e1f3e8;
  --bad: #b3322a;
  --bad-soft: #fbe5e2;
  --warn: #7a4f00;
  --warn-soft: #fcefd6;
  --hero-from: #5a48b0;
  --hero-to: #3f3185;
  --hero-btn-ink: #43358a;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 0.6rem; }
a { color: var(--brand-strong); }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }

.muted { color: var(--muted); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.center { text-align: center; }
.lead { font-size: 1.1rem; color: var(--ink-2); }
.fine-print { font-size: 0.85rem; color: var(--muted); margin-top: 0.75rem; }
.eyebrow {
  text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem;
  font-weight: 700; color: var(--brand-strong); margin-bottom: 0.35rem;
}
.link { font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- Layout shell ---------- */

.shell { min-height: 100vh; min-height: 100dvh; }
.course-intro[hidden] { display: none; }
.view {
  outline: none;
  padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
body.in-session .view { padding-bottom: 0; }

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 16px;
}

.page-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.page-header h1 { margin: 0; }
.page-header__sub { color: var(--muted); margin: 0.2rem 0 0; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }

/* ---------- Navigation ---------- */

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav__brand { display: none; }
.nav__link {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.nav__link[aria-current="page"] { color: var(--brand-strong); }
.nav__link[aria-current="page"] .nav__icon { background: var(--brand-soft); }
.nav__icon { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; }
.nav__badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 0.7rem; line-height: 18px; text-align: center;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 2px solid transparent; border-radius: 12px;
  font-weight: 700; font-size: 1rem; text-decoration: none; cursor: pointer;
  transition: transform 80ms ease, background-color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: var(--brand-ink); }
.btn--primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn--secondary { background: var(--brand-soft); color: var(--brand-strong); }
.btn--ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn--danger { background: var(--bad-soft); color: var(--bad); }
.btn--block { width: 100%; }
.btn--lg { min-height: 54px; font-size: 1.05rem; padding: 0 24px; }
.btn--sm { min-height: 40px; padding: 0 14px; font-size: 0.9rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; border: 0; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Cards & stats ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card__title { font-size: 1.05rem; margin-bottom: 0.6rem; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 0.4rem; }
.card__head .card__title { margin: 0; }

.hero {
  background: linear-gradient(135deg, var(--hero-from) 0%, var(--hero-to) 100%);
  color: var(--hero-ink); border: 0;
}
.hero .eyebrow { color: inherit; opacity: 0.85; }
.hero__title { font-size: 1.45rem; margin-bottom: 0.3rem; }
.hero__goal { opacity: 0.95; }
.hero__meta { font-size: 0.85rem; opacity: 0.85; margin-bottom: 1rem; }
.hero .btn--primary { background: var(--hero-btn-bg); color: var(--hero-btn-ink); }
.hero .btn--primary:hover { background: var(--hero-btn-bg); filter: brightness(0.96); }

.home-top { display: flex; justify-content: space-between; align-items: center; }
.home-top__hello { font-size: 1.5rem; font-weight: 800; margin: 0; }
.home-top .muted { margin: 0; font-size: 0.9rem; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.stat__icon { color: var(--brand-strong); margin-bottom: 4px; }
.stat__icon--flame, .stat__icon--star { color: var(--accent); }
.stat__value { font-size: 1.4rem; font-weight: 800; line-height: 1.1; }
.stat__label { font-size: 0.8rem; color: var(--muted); }
.stat__hint { font-size: 0.75rem; color: var(--muted); }

.goal__row { display: flex; align-items: center; gap: 16px; }
.goal__xp { font-size: 1.1rem; margin-bottom: 0.2rem; }
.goal__xp strong { font-size: 1.5rem; }
.ring {
  --pct: 0;
  flex: none; width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--surface-2) 0);
}
.ring::before { content: ""; grid-area: 1 / 1; width: 58px; height: 58px; border-radius: 50%; background: var(--surface); }
.ring__value { grid-area: 1 / 1; position: relative; font-weight: 800; font-size: 0.95rem; }

.review-card__count strong { font-size: 1.5rem; }

.bars { position: relative; display: flex; gap: 6px; align-items: flex-end; height: 120px; padding-top: 6px; }
.bars__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.bars__track { flex: 1; width: 100%; max-width: 34px; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bars__fill { width: 100%; background: var(--brand); border-radius: 6px 6px 0 0; }
.bars__col.is-met .bars__fill { background: var(--accent); }
.bars__label { font-size: 0.72rem; color: var(--muted); }
.bars__col.is-today .bars__label { color: var(--ink); font-weight: 700; }

.wordlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.wordlist__item {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "t p" "s p";
  gap: 0 10px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.wordlist__item:last-child { border-bottom: 0; }
.wordlist__target { grid-area: t; font-weight: 700; }
.wordlist__source { grid-area: s; color: var(--muted); font-size: 0.9rem; }
.wordlist__item .pill { grid-area: p; align-self: center; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.pill--new { background: var(--surface-2); color: var(--muted); }
.pill--learning { background: var(--bad-soft); color: var(--bad); }
.pill--familiar { background: var(--accent-soft); color: var(--warn); }
.pill--mastered { background: var(--good-soft); color: var(--good); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 0.85rem;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.empty { text-align: center; padding: 12px 4px; }
.empty__title { font-weight: 700; margin-bottom: 0.25rem; }
.empty__text { color: var(--muted); }
.page.empty { padding-top: 15vh; align-items: center; }

.banner { padding: 10px 16px; text-align: center; font-size: 0.9rem; }
.banner--warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Boot / toast ---------- */

.boot { min-height: 70vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: min(92vw, 480px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 0.95rem;
}
.toast[data-kind="error"] { background: var(--bad); color: var(--on-bad); }

/* ---------- Onboarding ---------- */

.onboarding { max-width: 520px; margin: 0 auto; padding: 32px 16px 40px; min-height: 100dvh; display: flex; flex-direction: column; }
.onboarding__dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 28px; }
.onboarding__dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.onboarding__dots span.is-active { background: var(--brand); width: 22px; border-radius: 999px; }
.onboarding__step { display: flex; flex-direction: column; gap: 14px; }
.onboarding__step h1 { outline: none; }
.onboarding__logo { margin: 8px auto 8px 0; border-radius: 22px; }

.loop { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.loop__item { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.loop__item p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.loop__num { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-weight: 800; }

.choice-cards { display: flex; flex-direction: column; gap: 10px; }
.choice-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 14px 16px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface); border: 2px solid var(--line);
}
.choice-card span { color: var(--muted); font-size: 0.92rem; }
.choice-card[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); }
.choice-card--action:hover { border-color: var(--brand); }

/* ---------- Lessons path ---------- */

.unit { display: flex; flex-direction: column; gap: 10px; }
.unit__head h2 { margin: 0; }
.unit__head .muted { margin: 0.15rem 0 0; }
.unit__progress { font-size: 0.85rem; color: var(--muted); margin: 0.25rem 0 0; }
.lessons { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lesson-row {
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "n b" "n s";
  gap: 4px 12px; align-items: center;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.lesson-row:hover { border-color: var(--brand); }
.lesson-row.is-recommended { border: 2px solid var(--brand); box-shadow: var(--shadow); }
.lesson-row__num {
  grid-area: n; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800;
  background: var(--surface-2); color: var(--ink-2);
}
.lesson-row.is-done .lesson-row__num { background: var(--good-soft); color: var(--good); }
.lesson-row.is-recommended .lesson-row__num { background: var(--brand); color: var(--brand-ink); }
.lesson-row__body { grid-area: b; display: flex; flex-direction: column; min-width: 0; }
.lesson-row__title { font-weight: 700; }
.lesson-row__goal { color: var(--muted); font-size: 0.88rem; }
.status { grid-area: s; font-size: 0.78rem; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.status--done { color: var(--good); }
.status--next { color: var(--brand-strong); }
.status--placed { color: var(--warn); }

.lesson-stats { list-style: none; padding: 0; margin: 0; }
.lesson-stats li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.lesson-stats li:last-child { border-bottom: 0; }
.lesson-stats__val { white-space: nowrap; }

.mistakes { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 10px; }
.mistake { padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.mistake p { margin: 0 0 4px; }
.mistake__prompt { font-weight: 700; }
.mistake__label { color: var(--muted); font-weight: 600; }
.mistake__given { color: var(--bad); }
.mistake__correct { color: var(--good); font-weight: 600; }
.mistake__why { color: var(--ink-2); font-size: 0.92rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field--inline { flex-direction: row; align-items: center; gap: 10px; }
.field input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brand); }
.field select { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); max-width: 240px; }
.support { list-style: none; padding: 0; margin: 0 0 8px; }
.support li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.support__mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 0.8rem; background: currentColor; }
.support li.good .support__mark { background: var(--good-soft); }
.support li.warn .support__mark { background: var(--warn-soft); }
.choice-cards--row { display: grid; grid-template-columns: 1fr; }

.theme-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.theme-option {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  min-height: 60px; padding: 10px 14px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface); border: 2px solid var(--line);
}
.theme-option:hover { border-color: var(--brand); }
.theme-option[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.theme-option__swatches { display: flex; flex: none; }
.theme-option__swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line);
}
.theme-option__swatch + .theme-option__swatch { margin-left: -6px; }
.theme-option__text { display: flex; flex-direction: column; min-width: 0; }
.theme-option__text span { color: var(--muted); font-size: 0.88rem; }
.theme-option[aria-checked="true"]::after { content: "✓"; margin-left: auto; font-weight: 800; color: var(--brand-strong); }

/* ---------- Session (lesson player) ---------- */

.session { min-height: 100dvh; display: flex; flex-direction: column; }
.session__bar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "x p" "t t";
  align-items: center; gap: 2px 8px;
  padding: 8px 12px 6px; background: var(--bg);
}
.session__bar .icon-btn { grid-area: x; }
.session__title { grid-area: t; font-size: 0.78rem; color: var(--muted); padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { grid-area: p; height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress__fill { height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width 300ms ease; }
@media (prefers-reduced-motion: reduce) {
  .progress__fill, .btn { transition: none; }
}

.session__body { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }
.session__card { display: flex; flex-direction: column; gap: 14px; }
.ex { display: flex; flex-direction: column; gap: 14px; }
.ex-instruction { font-size: 1.3rem; font-weight: 800; outline: none; margin: 4px 0 0; }
.supp-banner { margin: 0; padding: 8px 12px; border-radius: 10px; border: 1px dashed var(--warn); background: var(--warn-soft); color: var(--warn); font-size: 0.88rem; }
.retry-banner { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--warn); font-weight: 600; font-size: 0.9rem; margin: 0; }
.retry-banner--quiet { background: transparent; padding: 0; }

.session__footer {
  position: sticky; bottom: 0; z-index: 10;
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}
.session__footer.is-idle { display: none; }
.session__footer-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.session__footer.is-correct { background: var(--good-soft); border-top-color: var(--good); }
.session__footer.is-wrong { background: var(--bad-soft); border-top-color: var(--bad); }
.session__footer.is-correct .btn--primary { background: var(--good); color: var(--on-good); }
.session__footer.is-wrong .btn--primary { background: var(--bad); color: var(--on-bad); }
.feedback:empty { display: none; }
.feedback__title { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; font-weight: 800; margin-bottom: 4px; }
.is-correct .feedback__title { color: var(--good); }
.is-wrong .feedback__title { color: var(--bad); }
.feedback__line { margin: 0 0 2px; }
.feedback__line--muted { color: var(--ink-2); font-size: 0.92rem; }
.feedback__why { display: flex; gap: 6px; align-items: flex-start; margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--surface); font-size: 0.95rem; }
.feedback__why .icon { flex: none; margin-top: 3px; }
.feedback__audio { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 0.9rem; color: var(--ink-2); }

/* Prompt and options */
.prompt-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.prompt-text { font-size: 1.35rem; font-weight: 700; margin: 0; }
.prompt-sub { color: var(--muted); margin: 6px 0 0; }
.speakable { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.target-text { margin: 0; }

.audio-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 0; background: var(--brand-soft); color: var(--brand-strong);
}
.audio-btn--slow { background: var(--surface-2); color: var(--ink-2); width: auto; padding: 0 12px 0 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 700; }
.audio-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.audio-btn.is-playing { box-shadow: 0 0 0 4px var(--brand-soft); }
.audio-btn--big { width: auto; height: 64px; padding: 0 22px; border-radius: 18px; font-weight: 700; }
.audio-btn--big:first-child { background: var(--brand); color: var(--brand-ink); }
.listen-controls { display: flex; gap: 10px; justify-content: center; padding: 12px 0; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  min-height: 54px; padding: 10px 14px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--line); font-size: 1.05rem;
  -webkit-tap-highlight-color: transparent;
}
.option:hover:not(:disabled) { border-color: var(--brand); }
.option[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); }
.option.is-correct { border-color: var(--good); background: var(--good-soft); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; opacity: 1; }
/* Shape cue as well as colour, so correct/incorrect never depends on hue alone. */
.option.is-correct::after, .option.is-wrong::after {
  margin-left: auto; padding-left: 8px; font-weight: 800; font-size: 1.15rem;
}
.option.is-correct::after { content: "✓"; color: var(--good); }
.option.is-wrong::after { content: "✗"; color: var(--bad); }
.option:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.6; }
.option__key {
  flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 700; color: var(--muted); border: 1px solid var(--line);
}

.blank { display: inline-block; min-width: 4.5em; border-bottom: 3px solid var(--brand); margin: 0 4px; text-align: center; color: var(--brand-strong); }
.blank.is-correct { border-color: var(--good); color: var(--good); }
.blank.is-wrong { border-color: var(--bad); color: var(--bad); }

/* Typed answers */
.typed { display: flex; flex-direction: column; gap: 8px; }
.answer-input {
  width: 100%; min-height: 88px; resize: vertical; padding: 12px 14px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.15rem; line-height: 1.4;
}
.answer-input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.charbar { display: flex; flex-wrap: wrap; gap: 6px; }
.charbar__key {
  min-width: 42px; height: 42px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: 1.1rem; font-weight: 600;
}
.charbar__key:hover { border-color: var(--brand); }

/* Word tiles */
.tile-builder { display: flex; flex-direction: column; gap: 16px; }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.tiles--answer {
  min-height: 64px; padding: 8px 4px; align-content: flex-start;
  border-bottom: 2px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0 55px, var(--line) 55px 56px);
}
.tiles--answer.is-correct { border-color: var(--good); }
.tiles--answer.is-wrong { border-color: var(--bad); }
.tiles--bank { justify-content: center; }
.tile {
  min-height: 46px; padding: 0 14px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--line); border-bottom-width: 4px;
  font-size: 1.05rem; font-weight: 600;
}
.tile:hover:not(:disabled) { border-color: var(--brand); }
.tile--ghost { visibility: visible; color: transparent; background: var(--surface-2); border-color: var(--surface-2); cursor: default; display: inline-flex; align-items: center; }

/* Learn card */
.learn-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.learn-card__target { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.learn-card__text { font-size: 1.5rem; font-weight: 800; margin: 0; flex: 1 1 200px; }
.learn-card__source { font-size: 1.1rem; color: var(--ink-2); margin: 0; }
.learn-card__note { padding: 12px; border-radius: 10px; background: var(--brand-soft); color: var(--ink); font-size: 0.95rem; }

/* Flashcard */
.flashcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 20px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; box-shadow: var(--shadow); }
.flashcard__front { display: flex; align-items: center; gap: 12px; }
.flashcard__word { font-size: 1.8rem; font-weight: 800; margin: 0; }
.flashcard__back { border-top: 1px dashed var(--line); padding-top: 14px; width: 100%; }
.flashcard__meaning { font-size: 1.2rem; font-weight: 700; }
.flashcard__note { color: var(--muted); margin: 0; }
.flashcard__rate { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Dialogue */
.dialogue__context { color: var(--muted); font-style: italic; margin: -4px 0 0; }
.dialogue { display: flex; flex-direction: column; gap: 10px; }
.bubble { align-self: flex-start; max-width: 88%; }
.bubble--you { align-self: flex-end; }
.bubble__speaker { font-size: 0.75rem; font-weight: 700; color: var(--muted); margin: 0 0 2px 4px; }
.bubble--you .bubble__speaker { text-align: right; margin-right: 4px; }
.bubble__body { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 16px 16px 16px 4px; background: var(--surface); border: 1px solid var(--line); }
.bubble--you .bubble__body { border-radius: 16px 16px 4px 16px; background: var(--brand-soft); border-color: transparent; }
.bubble__body .audio-btn { width: 34px; height: 34px; }
.bubble__target { font-weight: 700; margin: 0; }
.bubble__source { color: var(--muted); font-size: 0.88rem; margin: 0; }
.dialogue__choices { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.dialogue__hint { color: var(--bad); font-size: 0.95rem; margin: 0; }
.dialogue__hint:empty { display: none; }

/* Speaking */
.speak-actions { display: flex; justify-content: center; }
.mic-btn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 18px 26px; border-radius: 20px; cursor: pointer;
  border: 2px solid var(--brand); background: var(--surface); color: var(--brand-strong); font-weight: 700;
}
.mic-btn.is-listening { background: var(--brand); color: var(--brand-ink); }
.speak-status p { margin: 0 0 4px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 0.95rem; }

/* Summary */
.summary { max-width: 640px; margin: 0 auto; padding: 32px 16px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; text-align: center; }
.summary h1 { outline: none; margin: 0; }
.summary__badge { align-self: center; width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; background: var(--good-soft); color: var(--good); }
.summary__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary__stats .stat { align-items: center; }
.summary__mistakes { text-align: left; }
.summary__actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Course catalogue ---------- */

.catalogue { display: flex; flex-direction: column; gap: 20px; }
.pathway { display: flex; flex-direction: column; gap: 10px; }
.pathway__head h2 { margin: 0 0 2px; font-size: 1.1rem; }
.pathway__head p { margin: 0; }
.course-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.course-card-wrap { display: flex; flex-direction: column; gap: 6px; }
.course-card {
  display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left;
  min-height: 56px; padding: 12px 14px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface); border: 2px solid var(--line);
}
.course-card:hover:not(:disabled) { border-color: var(--brand); }
.course-card.is-current { border-color: var(--brand); background: var(--brand-soft); }
.course-card:disabled { cursor: default; background: var(--surface-2); }
.course-card--planned .course-card__title { color: var(--muted); }
.course-card__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.course-card__meta { font-size: 0.85rem; color: var(--muted); }
.badge { flex: none; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.badge--live { background: var(--good-soft); color: var(--good); }
.badge--pilot { background: var(--warn-soft); color: var(--warn); }
.course-card.is-current .badge { background: var(--brand); color: var(--brand-ink); }
.course-notices { display: flex; flex-direction: column; gap: 4px; }
.notice-line { margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 0.85rem; background: var(--surface-2); color: var(--ink-2); }
.notice-line--review { background: var(--warn-soft); color: var(--warn); }
.notice-line--source { background: transparent; padding: 0 2px; color: var(--muted); }
.status--sample { color: var(--warn); }
.status--locked { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.lesson-row.is-locked .lesson-row__title { color: var(--ink-2); }

/* Offer banner (text from the server) and locked-lesson page */
.offer { padding: 14px 16px; border-radius: 12px; background: var(--brand-soft); color: var(--ink); }
.offer__title { margin: 0 0 4px; font-size: 1.05rem; }
.offer__summary { margin: 0; }
.offer__details { margin: 8px 0 0; padding-left: 20px; font-size: 0.92rem; color: var(--ink-2); }
.offer__details li + li { margin-top: 2px; }
.ex-hint { margin: -6px 0 0; font-size: 0.9rem; }

/* ---------- Reading comprehension ---------- */

.passage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; line-height: 1.6; }
.passage__head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.passage__title { margin: 0; font-size: 1.15rem; }
.passage p { margin: 0 0 0.7rem; }
.passage .passage__credit { font-size: 0.78rem; color: var(--muted); margin: 0; }
.rq__heading { margin: 4px 0 0; font-size: 1.05rem; }
.rq { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: 14px; }
.rq__item { padding-left: 2px; }
.rq__q { margin: 0 0 6px; font-weight: 600; }
.rq__choices { display: flex; flex-wrap: wrap; gap: 8px; }
.rq__choice {
  min-height: 44px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface); font-weight: 600;
}
.rq__choice[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); }
.rq__input { width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font-size: 1rem; }
.rq__input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.rq__answer { margin: 6px 0 0; font-size: 0.92rem; color: var(--ink-2); }
.rq__item.is-correct .rq__answer { color: var(--good); }
.rq__item.is-wrong .rq__answer { color: var(--bad); }
.mark { display: inline-block; margin-left: 4px; font-weight: 800; }
.mark--ok { color: var(--good); }
.mark--bad { color: var(--bad); }

/* ---------- Match the following ---------- */

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match__col { display: flex; flex-direction: column; gap: 8px; }
.match__item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  min-height: 52px; padding: 8px 10px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface); font-size: 0.98rem;
}
.match__item:hover:not(:disabled) { border-color: var(--brand); }
.match__item.is-active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.match__item.is-paired { background: var(--brand-soft); }
.match__item.is-correct { border-color: var(--good); background: var(--good-soft); }
.match__item.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.match__item:disabled { cursor: default; }
.match__badge {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.78rem; font-weight: 800; border: 1px solid var(--line); color: var(--brand-strong);
}
.match__badge:empty { border-style: dashed; }
.match__text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Sequence ---------- */

.seq { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seq--answer { min-height: 60px; padding: 8px; border-radius: 12px; border: 2px dashed var(--line); }
.seq__empty { color: var(--muted); font-size: 0.9rem; padding: 8px; }
.seq__slot { display: flex; align-items: center; gap: 8px; }
.seq__slot .seq__card { flex: 1; }
.seq__slot.is-correct .seq__card { border-color: var(--good); background: var(--good-soft); }
.seq__slot.is-wrong .seq__card { border-color: var(--bad); background: var(--bad-soft); }
.seq__num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 0.8rem; }
.seq__card {
  width: 100%; text-align: left; min-height: 48px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); border-bottom-width: 4px; background: var(--surface); font-size: 0.98rem;
}
.seq__card:hover:not(:disabled) { border-color: var(--brand); }

/* ---------- Composition ---------- */

.compose__task p { margin: 0 0 6px; }
.compose__fr { font-weight: 600; }
.compose__plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
.compose__plan summary { cursor: pointer; font-weight: 700; }
.compose__plan ol { margin: 8px 0 0; padding-left: 1.3rem; }
.compose__input { min-height: 200px; }
.compose__count { margin: -4px 0 0; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.compose__count[data-band="ok"] { color: var(--good); }
.compose__count[data-band="long"] { color: var(--warn); }
.compose__review { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.compose__review h3 { margin: 0; font-size: 1.05rem; outline: none; }
.compose__checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.compose__checklist li { display: flex; gap: 10px; align-items: flex-start; }
.compose__checklist input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.compose__model, .portfolio__text {
  margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2);
  font-family: var(--font); font-size: 0.98rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.portfolio { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.portfolio__meta { margin: 0 0 4px; font-size: 0.82rem; color: var(--muted); }

/* ---------- Content images ---------- */

.content-figure { margin: 4px 0 12px; }
.content-figure img { display: block; width: 100%; max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.content-figure figcaption { margin-top: 6px; font-size: 0.85rem; color: var(--ink-2); }
.content-figure__credit { color: var(--muted); }
.content-figure__desc { margin-top: 6px; font-size: 0.88rem; }
.content-figure__desc summary { cursor: pointer; color: var(--brand-strong); font-weight: 600; }
.content-figure__desc p { margin: 6px 0 0; color: var(--ink-2); }

/* ---------- Marks tables ---------- */

.marks-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.marks-table th, .marks-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.marks-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.marks-table tfoot td { font-weight: 700; border-bottom: 0; }
.marks-table tr.is-excluded td { color: var(--muted); background: var(--surface-2); }
.mock-rules { margin: 12px 0 0; padding-left: 1.2rem; font-size: 0.9rem; color: var(--ink-2); }
.mock-rules li { margin-bottom: 4px; }

/* ---------- Mock paper ---------- */

.mock { min-height: 100dvh; display: flex; flex-direction: column; }
.mock-bar {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  border-bottom: 1px solid var(--line); padding: 6px 12px 8px;
}
.mock-bar__top { display: flex; align-items: center; gap: 8px; }
.mock-bar__title { flex: 1; min-width: 0; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mock-clock {
  flex: none; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink);
}
.mock-clock.is-low { background: var(--bad-soft); color: var(--bad); }
.mock-nav { display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px 2px; scrollbar-width: thin; }
.mock-chip {
  flex: none; min-width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: 0.85rem;
}
.mock-chip.is-answered { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); }
.mock-body { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.mock-group { display: flex; flex-direction: column; gap: 10px; }
.mock-group__head h2 { margin: 0 0 2px; font-size: 1.1rem; }
.mock-group__head p { margin: 0; color: var(--ink-2); }
.mock-group__marks { font-size: 0.85rem; font-weight: 700; color: var(--brand-strong) !important; }
.mock-group__rule { font-size: 0.82rem; color: var(--muted) !important; }
.mock-group__warn { font-size: 0.88rem; font-weight: 700; color: var(--warn) !important; background: var(--warn-soft); padding: 6px 10px; border-radius: 8px; margin-top: 4px !important; }
.mock-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 8px; scroll-margin-top: 120px; }
.mock-item__q { margin: 0; font-weight: 600; }
.mock-item__n { color: var(--brand-strong); }
.mock-item__instr { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.mock-writing { display: flex; flex-direction: column; gap: 10px; }
.mock-foot {
  position: sticky; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
}
.mock-foot .charbar { max-width: 720px; margin: 0 auto; justify-content: center; }
.mock-foot .charbar__key { min-width: 36px; height: 36px; font-size: 1rem; }
.mock-foot__row { width: 100%; max-width: 720px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mock-counter { font-size: 0.85rem; color: var(--muted); }
.mock-between { text-align: center; }
.rubric { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rubric__row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rubric__row select { min-height: 40px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.mock-self-total { font-weight: 800; margin: 6px 0 0; }
.mock-review { border-top: 1px solid var(--line); padding: 8px 0; }
.mock-review summary { cursor: pointer; font-weight: 700; }
.mock-review__list { padding-left: 1.4rem; display: flex; flex-direction: column; gap: 10px; margin: 10px 0 0; }
.mock-review__item p { margin: 0 0 2px; }
.mock-review__q { font-weight: 600; }
.mock-review__state { font-weight: 700; }
.mock-review__item.is-correct .mock-review__state { color: var(--good); }
.mock-review__item.is-wrong .mock-review__state { color: var(--bad); }
.mock-review__item.is-unanswered .mock-review__state,
.mock-review__item.is-not-counted .mock-review__state { color: var(--warn); }
.mock-review__answer { color: var(--ink-2); }

/* ---------- Learning companion (Kuchu-Puchu) ----------
   Inline SVG (public/js/views/companion.js). The body follows the theme's
   brand colour; the face keeps fixed colours so it reads the same in every
   theme. Each mood plays one short animation (transform / opacity only, never
   looping) and then holds still. Fixed box sizes: no layout shift. */

.companion { display: inline-block; flex: none; width: 96px; height: 96px; line-height: 0; }
.companion--sm { width: 40px; height: 40px; }
/* In lessons: large enough to read the expression at a glance. */
.companion--lesson { width: 90px; height: 90px; }
.companion--lg { width: 104px; height: 104px; }
.companion__svg { width: 100%; height: 100%; overflow: visible; }
.comp-body { fill: var(--brand); }
.comp-plate { fill: var(--comp-plate); }
.comp-accent { fill: var(--accent); }
.comp-ink, .comp-mouth { fill: var(--comp-ink); }
.comp-shine { fill: var(--comp-plate); }
.comp-line { fill: none; stroke: var(--comp-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.comp-line--thin { stroke-width: 2.4; }
.comp-tongue { fill: var(--comp-tongue); }
.comp-cheek { fill: var(--comp-cheek); opacity: 0.55; }
.comp-star { fill: var(--accent); stroke: var(--comp-ink); stroke-width: 1.2; stroke-linejoin: round; }
.comp-spark { fill: var(--accent); }
.comp-shadow { fill: var(--ink); opacity: 0.12; }

.comp-figure { transform-origin: 60px 110px; }
.comp-hand { transform-origin: 100px 66px; opacity: 0; }
.comp-spark { transform-box: fill-box; transform-origin: center; }
.companion[data-mood="welcome"] .comp-hand,
.companion[data-mood="celebrating"] .comp-hand,
.companion[data-mood="excited"] .comp-hand,
.companion[data-mood="milestone"] .comp-hand { opacity: 1; }
.companion[data-mood="focused"] .comp-figure { transform: rotate(-3deg); }

.companion.is-playing[data-mood="welcome"] .comp-figure { animation: lf-bounce 700ms ease-out; }
.companion.is-playing[data-mood="welcome"] .comp-hand { animation: lf-wave 1100ms ease-in-out; }
.companion.is-playing[data-mood="focused"] .comp-figure { animation: lf-lean 450ms ease-out; }
.companion.is-playing[data-mood="happy"] .comp-figure { animation: lf-bounce 600ms ease-out; }
.companion.is-playing[data-mood="supportive"] .comp-figure { animation: lf-nod 900ms ease-in-out; }
.companion.is-playing[data-mood="encouraging"] .comp-figure { animation: lf-tilt 900ms ease-in-out; }
.companion.is-playing[data-mood="celebrating"] .comp-figure { animation: lf-jump 900ms ease-out; }
.companion.is-playing[data-mood="celebrating"] .comp-hand { animation: lf-wave 900ms ease-in-out; }
.companion.is-playing[data-mood="excited"] .comp-figure,
.companion.is-playing[data-mood="milestone"] .comp-figure { animation: lf-jump 900ms ease-out 2; }
.companion.is-playing[data-mood="excited"] .comp-hand,
.companion.is-playing[data-mood="milestone"] .comp-hand { animation: lf-wave 900ms ease-in-out 2; }
.companion.is-playing .comp-spark { animation: lf-pop 700ms ease-out backwards; }
.companion.is-playing .comp-spark--2 { animation-delay: 150ms; }
.companion.is-playing .comp-spark--3 { animation-delay: 300ms; }

@keyframes lf-bounce { 0%, 100% { transform: translateY(0); } 35% { transform: translateY(-6px); } 70% { transform: translateY(-1px); } }
@keyframes lf-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-14px) scale(1.02); }
  60% { transform: translateY(0) scale(1.04, 0.96); }
  80% { transform: translateY(-4px) scale(1); }
}
@keyframes lf-wave { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-22deg); } 50% { transform: rotate(8deg); } 75% { transform: rotate(-16deg); } }
@keyframes lf-lean { from { transform: rotate(0); } to { transform: rotate(-3deg); } }
@keyframes lf-nod { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(4deg); } 60% { transform: rotate(-1deg); } 80% { transform: rotate(2deg); } }
@keyframes lf-tilt { 0%, 100% { transform: rotate(0); } 35% { transform: rotate(-5deg) translateY(-2px); } 70% { transform: rotate(2deg); } }
@keyframes lf-pop { from { opacity: 0; transform: scale(0.3); } 60% { opacity: 1; transform: scale(1.2); } to { opacity: 1; transform: scale(1); } }

/* Reduced motion: the expressions stay, the movement goes. */
@media (prefers-reduced-motion: reduce) {
  .companion, .companion * { animation: none !important; transition: none !important; }
}

/* Companion with a line of text (Home, summaries). */
.buddy { display: flex; align-items: center; gap: 12px; }
.buddy__say {
  position: relative; margin: 0; padding: 10px 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; font-size: 0.95rem;
}
.buddy__say::before {
  content: ""; position: absolute; left: -7px; top: 50%; width: 12px; height: 12px;
  background: var(--surface); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.buddy--summary { flex-direction: column; gap: 14px; }
.buddy--summary .buddy__say::before { left: 50%; top: -7px; transform: translateX(-50%) rotate(135deg); }

/* In a lesson: a small companion at the end of the top bar, clear of the
   answers and the Check / Continue footer. */
.session__bar--buddy { grid-template-columns: auto 1fr auto; grid-template-areas: "x p c" "t t c"; }
.session__bar--buddy .companion { grid-area: c; }

.companion-setting { margin: 16px 0 6px; }
.companion-setting label { flex: 1; }

@media (max-width: 359px) {
  .companion--md { width: 78px; height: 78px; }
  .companion--lg { width: 88px; height: 88px; }
}

/* ---------- Install the app ---------- */

.install-tip {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px 12px;
  padding: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.install-tip__icon { border-radius: 10px; }
.install-tip__title { margin: 0; font-weight: 700; }
.install-tip__text .muted { margin: 0; font-size: 0.9rem; }
.install-tip__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.install-steps { margin: 0 0 10px; padding-left: 1.4em; }
.install-steps li { margin-bottom: 4px; }

/* ---------- Larger screens ---------- */

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats--wide { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .choice-cards--row { grid-template-columns: repeat(3, 1fr); }
  .theme-grid { grid-template-columns: 1fr 1fr; }
  .course-grid { grid-template-columns: 1fr 1fr; }
  .lesson-row { grid-template-columns: auto 1fr auto; grid-template-areas: "n b s"; }
  .summary__actions { flex-direction: row; justify-content: center; flex-wrap: wrap; }
  .options--grid { display: grid; grid-template-columns: 1fr 1fr; }
  .install-tip { grid-template-columns: auto 1fr auto; }
  .install-tip__actions { grid-column: auto; }
}

@media (min-width: 960px) {
  :root { --nav-w: 232px; }
  .nav {
    inset: 0 auto 0 0; width: var(--nav-w); height: auto;
    display: flex; flex-direction: column; gap: 4px; padding: 20px 12px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .nav__brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: var(--ink); text-decoration: none; font-weight: 800; font-size: 1.2rem; }
  .nav__brand img { border-radius: 9px; }
  .nav__link { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 8px 10px; border-radius: 12px; font-size: 0.98rem; }
  .nav__link[aria-current="page"] { background: var(--brand-soft); }
  .nav__link[aria-current="page"] .nav__icon { background: transparent; }
  .nav__icon { width: 28px; height: 28px; }
  .nav__badge { position: static; margin-left: auto; }
  .view { padding-bottom: 32px; margin-left: var(--nav-w); }
  body.in-session .view { margin-left: 0; }
  .page { padding: 32px 24px; }
  .toast { bottom: 24px; }
}

/* Staging banner (APP_ENV=staging only; injected by the server, src/app.js).
   Its tokens are set once in :root so it looks the same in every theme
   (contrast above 10:1). */
.staging-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  margin: 0;
  padding: 6px 16px;
  background: var(--staging-bg);
  color: var(--staging-ink);
  font: 700 14px/1.4 system-ui, sans-serif;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ---------- Kuchu-Puchu scenes ----------
   Decorative movement on top of a mood (data-anim, views/companion.js). One-shot
   in lessons (cheer, oops); looping only on the start-up pages. Reduced motion
   removes all of it (rule in the companion section plus the one below). */

.fx { opacity: 0; transform-box: fill-box; transform-origin: center; pointer-events: none; }
.fx-q { fill: var(--brand-strong); font: 800 18px/1 system-ui, sans-serif; }
.fx-note { fill: var(--accent); stroke: var(--comp-ink); stroke-width: 0.6; font: 800 18px/1 system-ui, sans-serif; }
.fx-heart { fill: var(--bad); }
.fx-burst-star { fill: var(--accent); stroke: var(--comp-ink); stroke-width: 0.8; }
.fx-flame { fill: var(--accent); stroke: var(--comp-ink); stroke-width: 0.8; }
.fx-bit--0 { fill: var(--accent); }
.fx-bit--1 { fill: var(--good); }
.fx-bit--2 { fill: var(--bad); }
.fx-bit--3 { fill: var(--brand); }
.fx-drop { fill: var(--comp-rain); stroke: var(--comp-ink); stroke-width: 0.8; }
.fx-cloud ellipse { fill: var(--comp-cloud); }
.fx-rain { fill: none; stroke: var(--comp-rain); stroke-width: 2.2; stroke-linecap: round; }

.companion.is-anim .comp-hand { opacity: 1; }
.companion.is-anim[data-anim="oops"] .comp-hand,
.companion.is-anim[data-anim="think"] .comp-hand { opacity: 0; }

/* hello: a big wave with floating hearts */
.companion.is-anim[data-anim="hello"] .comp-figure { animation: lf-sway 2.2s ease-in-out; }
.companion.is-anim[data-anim="hello"] .comp-hand { animation: lf-wave 1.1s ease-in-out; }
.companion.is-anim[data-anim="hello"] .fx-heart { animation: lf-float 2.2s ease-out; }
/* think: tilting the head with question marks */
.companion.is-anim[data-anim="think"] .comp-figure { animation: lf-ponder 2.6s ease-in-out; }
.companion.is-anim[data-anim="think"] .fx-q { animation: lf-float 2.6s ease-out; }
/* peek: leaning out to one side, then the other */
.companion.is-anim[data-anim="peek"] .comp-figure { animation: lf-peek 2.4s ease-in-out; }
.companion.is-anim[data-anim="peek"] .comp-hand { animation: lf-wave 2.4s ease-in-out; }
/* hop: quick hops with little flames */
.companion.is-anim[data-anim="hop"] .comp-figure { animation: lf-hop 0.7s ease-in-out; }
.companion.is-anim[data-anim="hop"] .fx-flame { animation: lf-flicker 0.7s ease-in-out; }
/* twirl: a full spin with stars */
.companion.is-anim[data-anim="twirl"] .comp-figure { animation: lf-twirl 2.6s cubic-bezier(.45,.05,.55,.95); }
.companion.is-anim[data-anim="twirl"] .fx-burst-star { animation: lf-twinkle 1.3s ease-in-out; }
/* dance: side-to-side with music notes */
.companion.is-anim[data-anim="dance"] .comp-figure { animation: lf-dance 0.9s ease-in-out; }
.companion.is-anim[data-anim="dance"] .comp-hand { animation: lf-wave 0.9s ease-in-out; }
.companion.is-anim[data-anim="dance"] .fx-note { animation: lf-float 1.8s ease-out; }
/* cheer (right answer): a jump and a burst of confetti */
.companion.is-anim[data-anim="cheer"] .comp-figure { animation: lf-cheer 900ms ease-out; }
.companion.is-anim[data-anim="cheer"] .comp-hand { animation: lf-wave 900ms ease-in-out; }
.companion.is-anim[data-anim="cheer"] .fx-bit { animation: lf-confetti 1100ms ease-out; }
.companion.is-anim[data-anim="cheer"] .fx-burst-star { animation: lf-twinkle 900ms ease-out; }
/* oops (wrong answer): a shake, a sweat drop and a small rain cloud; never harsh */
.companion.is-anim[data-anim="oops"] .comp-figure { animation: lf-shake 700ms ease-in-out; }
.companion.is-anim[data-anim="oops"] .fx-drop { animation: lf-drip 1300ms ease-in; }
.companion.is-anim[data-anim="oops"] .fx-cloud { animation: lf-cloud 1500ms ease-in-out; }

.companion.is-looping .comp-figure,
.companion.is-looping .comp-hand,
.companion.is-looping .fx { animation-iteration-count: infinite !important; }
.fx--2 { animation-delay: 200ms !important; }
.fx--3 { animation-delay: 400ms !important; }
.fx--4 { animation-delay: 150ms !important; }
.fx--5 { animation-delay: 300ms !important; }

@keyframes lf-sway { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg) translateY(-4px); } 75% { transform: rotate(4deg) translateY(-2px); } }
@keyframes lf-ponder { 0%, 100% { transform: rotate(0); } 30%, 55% { transform: rotate(-9deg); } 75% { transform: rotate(5deg); } }
@keyframes lf-peek { 0%, 100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-12px) rotate(-10deg); } 75% { transform: translateX(12px) rotate(10deg); } }
@keyframes lf-hop { 0%, 100% { transform: translateY(0) scale(1.05, 0.95); } 50% { transform: translateY(-16px) scale(0.97, 1.04); } }
@keyframes lf-twirl { 0%, 15% { transform: rotateY(0); } 65%, 100% { transform: rotateY(360deg); } }
@keyframes lf-dance { 0%, 100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-7px) rotate(-8deg) translateY(-5px); } 50% { transform: translateX(0) rotate(0); } 75% { transform: translateX(7px) rotate(8deg) translateY(-5px); } }
@keyframes lf-cheer { 0%, 100% { transform: translateY(0) scale(1); } 15% { transform: translateY(2px) scale(1.08, 0.92); } 45% { transform: translateY(-20px) scale(0.96, 1.06) rotate(-6deg); } 70% { transform: translateY(0) scale(1.05, 0.95) rotate(4deg); } 85% { transform: translateY(-5px) scale(1); } }
@keyframes lf-shake { 0%, 100% { transform: translateX(0) rotate(0); } 20% { transform: translateX(-6px) rotate(-5deg); } 40% { transform: translateX(6px) rotate(5deg); } 60% { transform: translateX(-4px) rotate(-3deg); } 80% { transform: translateX(3px) rotate(2deg); } }
@keyframes lf-float { 0% { opacity: 0; transform: translateY(8px) scale(0.6); } 25% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px) scale(1.1); } }
@keyframes lf-flicker { 0%, 100% { opacity: 0.9; transform: scale(0.85, 1.1); } 50% { opacity: 1; transform: scale(1.1, 0.85); } }
@keyframes lf-twinkle { 0%, 100% { opacity: 0; transform: scale(0.4) rotate(0); } 50% { opacity: 1; transform: scale(1.1) rotate(45deg); } }
@keyframes lf-confetti { 0% { opacity: 0; transform: translateY(14px) scale(0.3) rotate(0); } 20% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(24px) scale(1) rotate(160deg); } }
@keyframes lf-drip { 0% { opacity: 0; transform: translateY(-6px); } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(16px); } }
@keyframes lf-cloud { 0% { opacity: 0; transform: translateY(-8px); } 20%, 80% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-6px); } }

/* A sad Kuchu-Puchu (wrong answer): shrinks down, beret slipping, tears falling. */
.comp-tear { fill: var(--comp-rain); stroke: var(--comp-ink); stroke-width: 0.6; transform-box: fill-box; transform-origin: top; }
.companion[data-mood="supportive"] .comp-figure { transform: translateY(5px) scale(1.04, 0.93); }
.companion[data-mood="supportive"] .comp-beret { transform: translate(-3px, 5px) rotate(-14deg); transform-box: fill-box; transform-origin: center; }
.companion.is-anim[data-anim="oops"] .comp-figure { animation: lf-sob 2600ms ease-in-out both; }
.companion.is-anim[data-anim="oops"] .comp-tear { animation: lf-tear 1100ms ease-in 3; }
.companion.is-anim[data-anim="oops"] .comp-tear--2 { animation-delay: 350ms; }
@keyframes lf-sob {
  0% { transform: none; }
  14% { transform: translateY(6px) scale(1.06, 0.9); }
  24%, 44%, 64%, 84% { transform: translateY(5px) scale(1.04, 0.93) translateX(-2px); }
  34%, 54%, 74% { transform: translateY(7px) scale(1.05, 0.91) translateX(2px); }
  100% { transform: translateY(5px) scale(1.04, 0.93); }
}
@keyframes lf-tear { 0% { opacity: 0; transform: translateY(-3px) scaleY(0.5); } 25% { opacity: 1; } 80% { opacity: 1; transform: translateY(9px) scaleY(1.1); } 100% { opacity: 0; transform: translateY(15px); } }

/* ---------- Streak cartoons ----------
   views/celebrate.js. Over the page without blocking it; only the close button
   takes touches. Props are decorative. Reduced motion shows the still picture. */

.celebrate { position: fixed; inset: 0; z-index: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 16px; pointer-events: none; background: rgb(11 16 38 / 80%); animation: cz-in 300ms ease-out both, cz-out 500ms ease-in 5500ms both; }
.celebrate__art { position: relative; width: min(82vw, 360px); aspect-ratio: 1; }
.celebrate__stage { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.celebrate__buddy { position: absolute; left: 50%; top: 50%; translate: -50% -50%; }
.celebrate__buddy .companion { width: 130px; height: 130px; }
.celebrate__count { margin: 0; color: var(--comp-plate); font-size: 2rem; font-weight: 800; text-align: center; }
.celebrate__say { margin: 0; color: var(--comp-plate); font-size: 1.1rem; font-weight: 600; text-align: center; }
.celebrate__close { position: absolute; top: 12px; right: 12px; pointer-events: auto; background: var(--surface); color: var(--ink); }
.celebrate--big .celebrate__count { font-size: 2.5rem; }
@keyframes cz-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes cz-out { to { opacity: 0; } }

.cz-balloon { animation: cz-rise 4.6s ease-in calc(var(--i) * 180ms) both; }
@keyframes cz-rise { from { transform: translateY(40px); } to { transform: translateY(-470px); } }
.celebrate--balloons .celebrate__buddy { animation: cz-float 4.8s ease-in-out both; }
@keyframes cz-float { 0% { transform: translateY(70px); } 60% { transform: translateY(-40px) rotate(-5deg); } 100% { transform: translateY(-20px) rotate(5deg); } }

.cz-twinkle { transform-box: fill-box; transform-origin: center; animation: cz-twinkle 1.1s ease-in-out calc(var(--i) * 170ms) infinite; }
@keyframes cz-twinkle { 0%, 100% { opacity: 0.2; transform: scale(0.5) rotate(0); } 50% { opacity: 1; transform: scale(1.2) rotate(40deg); } }

.cz-sun { transform-origin: 180px 90px; animation: cz-spin 7s linear infinite; }
@keyframes cz-spin { to { transform: rotate(360deg); } }
.celebrate--sunshine .celebrate__buddy { top: 66%; }

.cz-cake { animation: cz-pop 700ms cubic-bezier(.3,1.6,.6,1) both; transform-origin: 180px 320px; }
.cz-flame { transform-box: fill-box; transform-origin: bottom; animation: cz-flicker 420ms ease-in-out calc(var(--i) * 90ms) infinite alternate; }
@keyframes cz-pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes cz-flicker { from { transform: scale(0.8, 1.15); } to { transform: scale(1.15, 0.85); } }
.celebrate--cake .celebrate__buddy { top: 34%; }

.cz-rocket { animation: cz-launch 4.6s ease-in both; }
.cz-exhaust { transform-origin: 180px 330px; animation: cz-flicker 120ms linear infinite alternate; }
.celebrate--rocket .celebrate__buddy { top: 55%; animation: cz-launch 4.6s ease-in both; }
@keyframes cz-launch { 0%, 28% { transform: translateX(0); } 16% { transform: translateX(-3px); } 22% { transform: translateX(3px); } 100% { transform: translateY(-560px); } }

.cz-rays { transform-origin: 180px 75px; animation: cz-spin 5s linear infinite; }
.cz-ball { animation: cz-flash 500ms steps(2) infinite; }
@keyframes cz-flash { to { opacity: 0.7; } }
.cz-note { font: 800 34px/1 system-ui, sans-serif; animation: lf-float 1.8s ease-out calc(var(--i) * 220ms) infinite; transform-box: fill-box; }

.cz-speed { animation: cz-whoosh 620ms linear calc(var(--i) * 130ms) infinite; }
@keyframes cz-whoosh { from { transform: translateX(380px); } to { transform: translateX(-140px); } }
.cz-cloud--fast { animation: cz-whoosh 1.3s linear infinite; }
.cz-cape { transform-origin: 170px 190px; animation: cz-flap 360ms ease-in-out infinite alternate; }
@keyframes cz-flap { from { transform: rotate(-5deg) scaleY(0.92); } to { transform: rotate(6deg) scaleY(1.06); } }
.celebrate--hero .celebrate__buddy { animation: cz-fly 1.4s ease-in-out infinite alternate; }
@keyframes cz-fly { from { transform: translateY(14px) rotate(-12deg); } to { transform: translateY(-14px) rotate(-6deg); } }

.cz-burst { animation: cz-boom 1.5s ease-out calc(var(--i) * 280ms) infinite; }
@keyframes cz-boom { 0% { opacity: 0; transform: scale(0.1); } 25% { opacity: 1; } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.2); } }
.celebrate--eiffel .celebrate__buddy { top: 76%; }

.cz-confetti { transform-box: fill-box; transform-origin: center; animation: cz-fall 2.6s linear calc(var(--i) * 110ms) infinite; }
@keyframes cz-fall { from { transform: translateY(-20px) rotate(0); } to { transform: translateY(400px) rotate(540deg); } }
.cz-trophy { transform-origin: 180px 330px; animation: cz-pop 900ms cubic-bezier(.3,1.6,.6,1) 200ms both; }
.celebrate--trophy .celebrate__buddy { top: 30%; }
.cz-crown { animation: cz-drop 900ms cubic-bezier(.3,1.5,.6,1) 900ms both; }
@keyframes cz-drop { from { transform: translateY(-120px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.celebrate--trophy .cz-crown { translate: 0 -52px; }
.celebrate--grand .cz-crown { translate: 0 72px; }

.cz-rainbow path { stroke-dasharray: 100; animation: cz-draw 1.8s ease-out both; }
.cz-rainbow path:nth-child(2) { animation-delay: 120ms; }
.cz-rainbow path:nth-child(3) { animation-delay: 240ms; }
.cz-rainbow path:nth-child(4) { animation-delay: 360ms; }
.cz-rainbow path:nth-child(5) { animation-delay: 480ms; }
.cz-rainbow path:nth-child(6) { animation-delay: 600ms; }
@keyframes cz-draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
.celebrate--rainbow .celebrate__buddy { top: 64%; animation: cz-slide 4.6s ease-in-out both; }
@keyframes cz-slide { from { transform: translateX(-130px); } to { transform: translateX(130px); } }
.celebrate--grand .celebrate__buddy { top: 62%; }

@media (prefers-reduced-motion: reduce) {
  .celebrate, .celebrate * { animation: none !important; }
  .celebrate { animation: none !important; }
}

/* ---------- Start-up pages ---------- */

.onboarding__buddy { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: 104px; }
.onboarding__buddy--hero { justify-content: center; margin: 18px 0 26px; }
.onboarding__buddy--hero .companion { width: 180px; height: 180px; }
.onboarding__step--welcome { text-align: center; }
.onboarding__step--welcome .buddy__say--top { text-align: left; font-weight: 500; }
.buddy__say--top::before { left: 50%; top: -7px; transform: translateX(-50%) rotate(135deg); }
.onboarding__invited { margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.onboarding__actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.onboarding__actions .btn--block { flex: 1; width: auto; }
.onboarding__courses { margin-top: 12px; }
.onboarding__courses summary { cursor: pointer; color: var(--brand-strong); font-weight: 600; padding: 6px 0; }
.choice-card--icon { display: flex; flex-direction: row; align-items: center; gap: 12px; text-align: left; }
.choice-card__icon { font-size: 1.7rem; line-height: 1; flex: none; }
.choice-card__text { display: flex; flex-direction: column; min-width: 0; }
.choice-card__text span { color: var(--muted); font-size: 0.9rem; }

/* ---------- Footer ---------- */

.app-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 20px 16px calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); margin-top: 24px; }
body.in-session .app-footer, .app-footer--static { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.app-footer__inner { max-width: 760px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; justify-content: space-between; }
.app-footer__brand { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.app-footer__brand img { width: 156px; height: 28px; padding: 5px 8px; background: var(--comp-plate); border-radius: 8px; box-sizing: content-box; object-fit: contain; }
.app-footer__social { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; }
.app-footer__social a { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--brand-strong); background: var(--brand-soft); }
.app-footer__social a:hover { color: var(--brand-ink); background: var(--brand); }
.app-footer__links { display: flex; flex-wrap: wrap; gap: 4px 16px; flex-basis: 100%; }
.app-footer__links a { color: var(--ink-2); font-size: 0.9rem; padding: 6px 0; }
.app-footer__copy { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 0.82rem; }
@media (min-width: 960px) {
  body:not(.in-session) .app-footer:not(.app-footer--static) { margin-left: var(--nav-w); padding-bottom: 20px; }
  body.in-session .app-footer { margin-left: 0; }
}

/* ---------- Premium passes ---------- */

.premium { display: flex; flex-direction: column; gap: 16px; }
.premium__perks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.premium__perks li { display: flex; align-items: center; gap: 8px; }
.premium__perks .icon { color: var(--good); flex: none; }
.plans { display: grid; gap: 12px; grid-template-columns: 1fr; }
.plan { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 18px 16px; background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.plan .btn { margin-top: auto; }
.plan--highlight { border-color: var(--brand); }
.plan__tag { align-self: flex-start; padding: 2px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.78rem; font-weight: 800; }
.plan__name { margin: 4px 0 0; font-size: 1.05rem; }
.plan__price { margin: 0; font-size: 2rem; font-weight: 800; line-height: 1.2; color: var(--ink); }
.plan__gst { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.plan__total { margin: 0; font-weight: 700; color: var(--ink); }
.minors-warning { margin: 0; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--warn); background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 0.92rem; }
.invoice-list { display: grid; gap: 8px; }
.invoice { max-width: 720px; }
.invoice h2 { margin: 12px 0 0; font-size: 1rem; }
.invoice__number { margin: 0; font-weight: 700; font-size: 1.1rem; }
.invoice__party { margin: 0; }
.invoice__table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.invoice__table th, .invoice__table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; overflow-wrap: anywhere; }
.invoice__table .num { text-align: right; white-space: nowrap; }
.invoice__table--lines td:nth-child(2) { white-space: nowrap; }
.invoice__table tfoot th, .invoice__table tfoot td { font-weight: 800; border-bottom: 0; }
@media print {
  .invoice__actions { display: none; }
  .invoice-page { background: none; }
}
.restore-card summary { cursor: pointer; font-weight: 700; }
.restore { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.restore input, .copy-row input { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.premium-promo { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--accent-soft); color: var(--ink); border-radius: var(--radius); text-decoration: none; }
.premium-promo__icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.premium-promo__text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.premium-promo__text span { font-size: 0.88rem; color: var(--ink-2); }
.checkout { max-width: 520px; }
.checkout__back { align-self: flex-start; }
.checkout__price { font-size: 1.8rem; font-weight: 800; margin: 0; }
.checkout__price span { font-size: 1rem; font-weight: 500; color: var(--muted); }
.checkout__terms { margin: 0; padding-left: 1.2em; }
.checkout__error { margin: 0; color: var(--bad); font-weight: 600; }
.checkout__invoice-type { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.checkout__invoice-type legend { padding: 0; margin-bottom: 4px; font-weight: 600; }
.checkout__radio { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; }
.checkout__gst { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.checkout__gst input, .checkout__gst textarea { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; }
.checkout__gst .muted { margin: 0; }

/* ---------- Certificates ---------- */

.cert__head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cert__head .card__title, .cert__head p { margin: 0; }
.cert__badge { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.cert__badge--off { background: var(--surface-2); color: var(--muted); }
.cert__preview { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 12px; }
.cert .progress { margin-bottom: 6px; }
.cert__share { margin-top: 12px; }

/* ---------- Invite and share ---------- */

.copy-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.share-btn { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--ink); text-decoration: none; font-weight: 600; }
.share-btn:hover { border-color: var(--brand); }

/* ---------- Home additions ---------- */

.home-top__actions { display: flex; align-items: center; gap: 8px; }
.add-home { white-space: nowrap; }
.home-links { display: grid; gap: 8px; }
.home-link { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; font-weight: 600; }
.home-link .icon { color: var(--brand-strong); flex: none; }
@media (min-width: 640px) {
  .plans { grid-template-columns: repeat(3, 1fr); }
  .home-links { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 479px) {
  .home-top { flex-wrap: wrap; }
}
@media (max-width: 359px) {
  .home-top { flex-wrap: nowrap; }
  .add-home__label { display: none; }
}

/* ---------- Chess ---------- */

.chess__modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chess__mode { text-align: center; }
.chess__mode[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.chess__mode span { font-size: 0.82rem; }
.chess__buddy { min-height: 96px; }
.chess__board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; max-width: 520px; aspect-ratio: 1; margin: 0 auto; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); touch-action: manipulation; }
.chess__sq { position: relative; display: grid; place-items: center; padding: 0; margin: 0; border: 0; border-radius: 0; aspect-ratio: 1; min-width: 0; cursor: pointer; font-size: clamp(1.5rem, 9vw, 2.9rem); line-height: 1; }
.chess__sq.is-light { background: var(--chess-light); }
.chess__sq.is-dark { background: var(--chess-dark); }
.chess__sq.is-last { background: var(--chess-last); }
.chess__sq.is-selected { background: var(--chess-select); }
.chess__sq.is-check { background: var(--chess-check); }
.chess__sq.is-target::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgb(27 35 48 / 38%); }
.chess__sq.is-capture::after { width: 86%; height: 86%; background: none; border: 4px solid rgb(27 35 48 / 45%); }
.chess__sq:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 0; z-index: 1; }
.chess__piece { pointer-events: none; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Apple Symbols", sans-serif; }
.chess__piece--w { color: var(--chess-piece-white); text-shadow: 0 0 2px var(--chess-piece-black), 0 0 2px var(--chess-piece-black), 0 1px 1px var(--chess-piece-black); }
.chess__piece--b { color: var(--chess-piece-black); text-shadow: 0 0 1px var(--chess-piece-white); }
.chess__piece--inline { font-size: 1.5rem; line-height: 1; width: 1.8rem; text-align: center; }
.chess__actions { justify-content: center; }
.chess__promotion { padding: 12px; background: var(--surface); border: 2px solid var(--brand); border-radius: var(--radius); text-align: center; font-size: 1rem; }
.chess__promotion .chess__piece { font-size: 1.5rem; }
.chess__kuchu-only { display: grid; gap: 10px; }
.chess__words { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.chess__words li { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.link-button { min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--brand-strong); font-weight: 700; text-decoration: underline; cursor: pointer; }
.home-link__glyph { font-size: 1.3rem; line-height: 1; color: var(--brand-strong); }

/* ---------- Playground theme: an animated sky ----------
   Clouds drift and balloons rise behind the content. Decorative only; every
   card stays opaque so text contrast never depends on the art. Quieter during
   lessons, still with reduced motion. */

html:is([data-theme="playground"], [data-theme="playground-pink"]) { overflow-x: clip; }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) body::before,
:root:is([data-theme="playground"], [data-theme="playground-pink"]) body::after {
  content: ""; position: fixed; top: 0; left: 0; z-index: -1; pointer-events: none;
}
:root:is([data-theme="playground"], [data-theme="playground-pink"]) body::before {
  width: 200%; height: 340px;
  background: url("/img/bg-clouds.svg") repeat-x 0 0 / 50% 340px;
  animation: lf-drift 70s linear infinite;
}
:root:is([data-theme="playground"], [data-theme="playground-pink"]) body::after {
  width: 100%; height: calc(100% + 780px);
  background: url("/img/bg-balloons.svg") repeat 0 0 / 520px 780px;
  animation: lf-rise 60s linear infinite;
}
:root[data-theme="playground-pink"] body::after { background-image: url("/img/bg-balloons-pink.svg"); }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) body.in-session::after { opacity: 0.35; }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) .btn { border-radius: 999px; }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) .btn--primary { box-shadow: 0 4px 0 var(--brand-strong); }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) .btn--primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brand-strong); }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) .card { border-width: 2px; }
:root:is([data-theme="playground"], [data-theme="playground-pink"]) h1 { letter-spacing: 0; }
@keyframes lf-drift { to { transform: translateX(-50%); } }
@keyframes lf-rise { to { transform: translateY(-780px); } }

/* ---------- Midnight Aurora theme ----------
   Deep navy with a faint grid, a soft indigo and pink glow, glass cards and
   gradient headings and buttons. The glass sits on the dark background, so the
   contrast checked on the solid tokens still holds. */

:root[data-theme="aurora"] body::before,
:root[data-theme="aurora"] body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
:root[data-theme="aurora"] body::before {
  background-image:
    linear-gradient(rgb(165 176 255 / 5%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(165 176 255 / 5%) 1px, transparent 1px);
  background-size: 34px 34px;
}
:root[data-theme="aurora"] body::after {
  background:
    radial-gradient(45% 38% at 85% 2%, rgb(79 82 214 / 45%), transparent 70%),
    radial-gradient(40% 34% at 0% 100%, rgb(190 50 130 / 34%), transparent 70%);
  animation: lf-glow 14s ease-in-out infinite alternate;
}
:root[data-theme="aurora"] .card:not(.hero),
:root[data-theme="aurora"] .stat,
:root[data-theme="aurora"] .lesson-row,
:root[data-theme="aurora"] .choice-card,
:root[data-theme="aurora"] .theme-option,
:root[data-theme="aurora"] .option {
  background-color: rgb(26 33 64 / 78%);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
:root[data-theme="aurora"] .card,
:root[data-theme="aurora"] .lesson-row { border-radius: 18px; }
:root[data-theme="aurora"] .nav,
:root[data-theme="aurora"] .app-footer { background: rgb(11 16 38 / 88%); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
:root[data-theme="aurora"] .btn--primary {
  background: linear-gradient(95deg, var(--grad-from), var(--grad-to));
  border-color: transparent; color: var(--hero-ink);
}
:root[data-theme="aurora"] .hero .btn--primary { background: var(--hero-btn-bg); color: var(--hero-btn-ink); }
:root[data-theme="aurora"] .btn--primary:disabled { background: var(--surface-2); color: var(--muted); }
:root[data-theme="aurora"] .btn { border-radius: 999px; }
:root[data-theme="aurora"] .page-header h1,
:root[data-theme="aurora"] .onboarding h1,
:root[data-theme="aurora"] .summary h1,
:root[data-theme="aurora"] .home-top__hello {
  background: linear-gradient(95deg, var(--brand-strong), var(--accent));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
:root[data-theme="aurora"] .eyebrow { color: var(--brand-strong); }
@keyframes lf-glow { from { opacity: 0.75; transform: translateY(0); } to { opacity: 1; transform: translateY(-14px); } }

@media (prefers-reduced-motion: reduce) {
  :root:is([data-theme="playground"], [data-theme="playground-pink"]) body::before,
  :root:is([data-theme="playground"], [data-theme="playground-pink"]) body::after,
  :root[data-theme="aurora"] body::after { animation: none; }
  .fx { display: none; }
}
