/* polyglot — the one stylesheet (§9).
   Ink-dark paper, vermilion accent, typography first: the hanzi is the hero.
   Every colour, space and size is a variable in the :root blocks below.
   Tone colours --t1..--t5 are set at boot from config/app.config.js, so §0 stays the
   only place they are written. */

/* Noto Serif SC, subset by the pipeline to this pack's characters and self-hosted —
   no third-party request at runtime (§1.2). `swap` so text is never invisible while it
   loads; characters outside the subset fall back down the --font-han stack. */
@font-face {
  font-family: "Noto Serif SC";
  src: url("/assets/fonts/noto-serif-sc-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif SC";
  src: url("/assets/fonts/noto-serif-sc-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* paper — the default. Warm ground, ink text, seal red used sparingly. */
  --bg: #f2ede3;
  --surface: #faf7f0;
  --surface-2: #ece5d6;
  --border: #ddd4c3;
  --fg: #232120;
  --fg-dim: #6b655c;

  /* Seal red: stamps, primary CTAs, active states. Never body text, never decoration. */
  --accent: #b4372a;
  --accent-fill: #b4372a;
  --accent-fg: #ffffff;

  /* Paper is the reading lamp: no neon, no glow. The tokens exist so a shared rule
     never falls back to an undefined value; they are simply inert here. */
  --neon-cyan: #1a5fb4;
  --neon-yellow: #8a6d1f;
  --glow-sm: none;
  --glow-lg: none;

  --ok: #2f7d3f;
  /* Deliberately a shade off tone 1: the tones are config-owned, and a destructive
     action should not read as a tone mark. */
  --danger: #ad3429;
  --danger-fill: #ad3429;

  --shadow-1: 0 1px 2px rgb(35 33 32 / 0.08);
  --shadow-2: 0 10px 30px rgb(35 33 32 / 0.12);

  /* 田字格 practice-grid lines. */
  --grid: rgb(35 33 32 / 0.1);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.375rem;
  --text-xl: 2rem;
  --display: 2.75rem;
  --hanzi-size: clamp(64px, 22vw, 128px);
  --hanzi-back-size: clamp(40px, 13vw, 72px);

  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur: 160ms;

  /* Three roles: hanzi serif, latin display serif, UI sans. */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", Charter, Georgia, "Times New Roman", serif;
  --font-han: "Noto Serif SC", "Songti SC", SimSun, serif;

  --max-width: 720px;
  --sheet-width: 600px;
  --tabbar-h: 60px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  /* night market — the flagship theme. Deep blue-black street, signage pink, neon
     accents. Never pure black: a sign glows against a night sky, not a void. */
  --bg: #0c0f16;
  --surface: #151a24;
  --surface-2: #1d2330;
  --border: #2a3244;
  --fg: #e9ecf2;
  --fg-dim: #97a0b3;

  /*
   * Signage pink, split by role for the same reason v2 split vermilion: white on
   * #ff3d68 is 3.43:1, under the 4.5 a button label needs. The bright value stays
   * wherever the colour is *seen* — chrome, text on dark, and every glow — and only
   * filled buttons darken, which is imperceptible under a glow.
   */
  --accent: #ff3d68;
  --accent-fill: #d93458;
  --accent-fg: #ffffff;

  /* Secondary sign colours. Used for glow and accents, never for body text. */
  --neon-cyan: #33e6ff;
  --neon-yellow: #ffd23f;

  --ok: #3ddc84;
  --danger: #ff5252;
  --danger-fill: #cc4242;

  /* Neon tube glow. `currentColor` so a sign glows in whatever colour it is lit. */
  --glow-sm: 0 0 2px currentColor, 0 0 8px currentColor;
  --glow-lg: 0 0 2px currentColor, 0 0 10px currentColor, 0 0 28px currentColor;

  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.5);
  --shadow-2: 0 10px 30px rgb(0 0 0 / 0.55);
  --grid: rgb(233 236 242 / 0.1);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur: 0ms;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ── Shell ──────────────────────────────────────────────── */

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--fg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  text-decoration: none;
  letter-spacing: -0.01em;
}

/* The seal takes the accent from the theme; nothing else in the bar is red. */
.seal {
  color: var(--accent);
  flex: none;
}

.bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.top-nav {
  display: flex;
  gap: var(--space-4);
}

.nav-link {
  color: var(--fg-dim);
  text-decoration: none;
  font-size: var(--text-sm);
  padding: var(--space-1) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur) var(--ease);
}

.nav-link:hover {
  color: var(--fg);
}

.nav-link.active {
  color: var(--fg);
  /* Ink, not seal red: the accent is reserved (§3.2.6). */
  border-bottom-color: var(--fg);
}

/* The gear: Settings and Credits live behind it, off the main nav. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.icon-btn:hover,
.icon-btn.active {
  color: var(--fg);
  background: var(--surface-2);
}

.icon-btn:active {
  transform: scale(0.97);
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-3) var(--space-5);
}

/* ── Bottom tab bar (mobile) ────────────────────────────── */

.tabbar {
  display: none;
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: var(--space-1) 0;
  color: var(--fg-dim);
  text-decoration: none;
  font-size: var(--text-xs);
  transition: color var(--dur) var(--ease);
}

.tab:active {
  transform: scale(0.97);
}

.tab.active {
  color: var(--accent);
}

@media (max-width: 640px) {
  .tabbar {
    display: flex;
  }
  .top-nav {
    display: none;
  }
  #app {
    padding-bottom: calc(var(--tabbar-h) + var(--space-5));
  }
  /* Review is full-screen study: the grade bar owns the thumb zone. */
  :root[data-route="review"] .tabbar {
    display: none;
  }
  :root[data-route="review"] #app {
    padding-bottom: var(--space-3);
  }
}

/* ── Type ───────────────────────────────────────────────── */

.title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-xl);
  margin: 0 0 var(--space-4);
  letter-spacing: -0.02em;
  font-weight: 700;
}

.panel-title,
.subtle-title {
  font-size: var(--text-sm);
  margin: 0 0 var(--space-2);
  color: var(--fg-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.muted {
  color: var(--fg-dim);
  font-size: var(--text-sm);
}

.empty {
  color: var(--fg-dim);
  text-align: center;
  padding: var(--space-5) var(--space-3);
}

.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;
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: var(--text-md);
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.btn:hover:not(:disabled) {
  border-color: var(--fg-dim);
  background: var(--surface-2);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Focus rings are ink, never seal red — an input is not a call to action (§3.3.5). */
.btn:focus-visible,
.tab:focus-visible,
.icon-btn:focus-visible,
.search:focus-visible,
.answer:focus-visible,
.nav-link:focus-visible,
.row-main:focus-visible,
.tianzige-audio:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.search:focus,
.answer:focus {
  border-color: var(--fg-dim);
  outline: 2px solid var(--fg);
  outline-offset: 1px;
}

/* Primary buttons read as pressed seals rather than flat rectangles. */
.btn-primary {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-fill) 92%, white) 0%,
    var(--accent-fill) 100%
  );
  color: var(--accent-fg);
  border: 1px solid color-mix(in srgb, var(--accent-fill) 80%, black);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.14), var(--shadow-1);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.14), var(--shadow-2);
  border-color: color-mix(in srgb, var(--accent-fill) 80%, black);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: inset 0 2px 6px rgb(0 0 0 / 0.25);
}

.btn-cta {
  width: 100%;
  min-height: 64px;
  font-size: var(--text-lg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}

.btn-wide {
  width: 100%;
}

.btn-quiet {
  background: transparent;
}

.btn-quiet.active {
  background: var(--surface-2);
  border-color: var(--fg);
}

.btn-danger {
  background: var(--danger-fill);
  border-color: var(--danger-fill);
  color: #fff;
  font-weight: 600;
}

.btn-small {
  min-height: 36px;
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
}

.btn kbd {
  font: inherit;
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

/* ── Home ───────────────────────────────────────────────── */

.home-cta {
  margin-bottom: var(--space-4);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  padding: var(--space-3) var(--space-2);
  text-align: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--display);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* Home ── the greeting and the completion stamp. */

.greeting {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  margin: 0 0 var(--space-3);
  letter-spacing: -0.01em;
}

.done-stamp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-align: center;
  padding: var(--space-5) var(--space-3);
}

.done-stamp .seal {
  color: var(--accent);
  margin-bottom: var(--space-2);
}

.done-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 400;
  margin: 0;
}

/* A large, quiet hanzi instead of another box. */
.watermark {
  position: relative;
  text-align: center;
  padding: var(--space-5) 0;
}

.watermark::before {
  content: attr(data-han);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-han);
  font-size: clamp(160px, 46vw, 280px);
  line-height: 1;
  color: var(--fg);
  opacity: 0.05;
  pointer-events: none;
  user-select: none;
}

.watermark > * {
  position: relative;
}

/* ── Panels, fields ─────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.field {
  display: block;
  margin-bottom: var(--space-3);
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.slider {
  width: 100%;
  accent-color: var(--fg);
}

.slider-value {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.segmented,
.row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.search,
.answer {
  font: inherit;
  width: 100%;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  min-height: 48px;
  margin-bottom: var(--space-2);
}

/* ── Review: the sheet ──────────────────────────────────── */

.review {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Progress is the only thing outside the sheet. */
.session-progress {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: var(--sheet-width);
  width: 100%;
  margin: 0 auto;
}

.session-bar {
  flex: 1;
  height: 2px;
  background: var(--border);
  overflow: hidden;
}

.session-bar-fill {
  height: 100%;
  width: calc(var(--ratio, 0) * 100%);
  background: var(--fg);
  transition: width var(--dur) var(--ease);
}

.session-count {
  font-size: var(--text-xs);
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--sheet-width);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

/* Desktop: the sheet is centred in the space under the app bar, not floating in a void. */
@media (min-width: 641px) {
  .review {
    min-height: calc(100vh - 160px);
    justify-content: center;
  }
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: var(--space-4);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-3);
  cursor: pointer;
  min-height: 320px;
}

.card-front,
.card-back {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
}

.front-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
}

.card-back {
  text-align: center;
}

/* ── 田字格 ─────────────────────────────────────────────── */

.tianzige {
  position: relative;
  width: min(72vw, 260px);
  aspect-ratio: 1;
  border: 1px solid var(--grid);
  display: grid;
  place-items: center;
  flex: none;
}

.tianzige-content {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.grid-line {
  position: absolute;
  pointer-events: none;
}

.grid-v {
  left: 50%;
  top: 0;
  bottom: 0;
  border-left: 1px dashed var(--grid);
}

.grid-h {
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--grid);
}

/* Corner to corner: a full-width rule rotated about the centre. */
.grid-d1,
.grid-d2 {
  top: 50%;
  left: -20.71%;
  width: 141.42%;
  border-top: 1px dashed var(--grid);
  transform-origin: 50% 50%;
}

.grid-d1 {
  transform: rotate(45deg);
}

.grid-d2 {
  transform: rotate(-45deg);
}

.tianzige-audio {
  color: var(--fg-dim);
  cursor: pointer;
  border-radius: 2px;
}

.tianzige-write {
  width: min(60vw, 220px);
}

.write-target {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.write-row {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Card type ──────────────────────────────────────────── */

.hanzi {
  font-family: var(--font-han);
  font-size: var(--hanzi-size);
  line-height: 1;
  font-weight: 400;
}

.hanzi-back {
  font-size: var(--hanzi-back-size);
  margin-bottom: var(--space-2);
}

.pinyin {
  font-size: var(--text-lg);
  margin: var(--space-2) 0;
}

.pinyin-answer {
  font-size: var(--text-xl);
}

.pinyin.large {
  font-size: var(--text-xl);
}

.prompt {
  font-size: var(--text-lg);
  color: var(--fg-dim);
  margin: 0;
}

/* PROD: the English prompt is the hero. */
.prompt-defs {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: 1.3;
  gap: var(--space-2);
}

.prompt-sentence {
  font-size: var(--text-xl);
}

.rule {
  border: 0;
  border-top: 1px solid var(--border);
  width: 100%;
  margin: var(--space-3) 0;
}

.defs {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg-dim);
}

.trad {
  font-family: var(--font-han);
}

.hints {
  margin-top: var(--space-2);
}

.hint {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin: var(--space-1) 0;
}

.verdict {
  font-weight: 600;
  min-height: 1.5em;
}

.verdict.ok {
  color: var(--ok);
}

.verdict.bad {
  color: var(--danger);
}

.sentence {
  margin-bottom: var(--space-3);
}

.sentence-zh {
  font-family: var(--font-han);
  font-size: var(--text-lg);
  line-height: 1.9;
}

.sentence-pinyin {
  color: var(--fg-dim);
  margin: var(--space-1) 0;
}

.sentence-en {
  color: var(--fg-dim);
  font-size: var(--text-sm);
}

/* The target word is marked in grid ink, not accent — seal red is reserved. */
.target {
  border-bottom: 2px solid var(--grid);
  padding-bottom: 2px;
}

/* ── Grade bar: the sheet's footer ──────────────────────── */

.controls {
  border-top: 1px solid var(--border);
  padding: var(--space-3);
  background: var(--surface);
}

.ratings {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

.ratings .btn {
  flex-direction: column;
  gap: 2px;
  min-height: 56px;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-1);
  font-weight: 600;
}

.interval {
  font-size: var(--text-xs);
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.btn-again {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.btn-good,
.btn-easy {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
}

.suggested {
  box-shadow: inset 0 0 0 2px var(--fg);
}

.review.done {
  align-items: center;
  text-align: center;
  gap: var(--space-3);
}

/* Mobile: the sheet fills the content area; the grade bar sits in the thumb zone,
   above the tab bar. */
@media (max-width: 640px) {
  .sheet {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    margin-left: calc(var(--space-3) * -1);
    margin-right: calc(var(--space-3) * -1);
    width: auto;
  }

  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--tabbar-h);
    z-index: 15;
    padding-bottom: var(--space-2);
  }

  .stage {
    padding-bottom: 120px;
  }
}

/* ── Motion: the flip, and the stamp ────────────────────── */

/* The reveal is one orchestrated turn (§3.3.3): the front rotates away, content swaps
   at 90°, the back completes the turn, and the stage's height moves with it. */
.flip-stage {
  perspective: 1200px;
  transition: height calc(var(--dur) * 2) var(--ease);
}

.flip-stage > .card-front,
.flip-stage > .card-back {
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.flip-out {
  animation: flip-out var(--dur) var(--ease) forwards;
}

.flip-in {
  animation: flip-in var(--dur) var(--ease) both;
}

@keyframes flip-out {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(-90deg);
  }
}

@keyframes flip-in {
  from {
    transform: rotateY(90deg);
  }
  to {
    transform: rotateY(0deg);
  }
}

/* The grade bar arrives only once the card has finished turning. */
.controls {
  transition: opacity var(--dur) var(--ease);
}

.controls-hidden {
  opacity: 0;
  pointer-events: none;
}

/* Measured off-screen to animate the height; never seen. */
.measuring {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  inset-inline: 0;
}

@keyframes stamp-in {
  from {
    opacity: 0;
    transform: scale(1.04);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse-once {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.pulse {
  animation: pulse-once var(--dur) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  .stamp-in,
  .pulse,
  .flip-out,
  .flip-in {
    animation: none;
  }

  .flip-stage {
    transition: none;
  }
}

/* ── Banner ─────────────────────────────────────────────── */

.banner {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--fg-dim);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.banner-title {
  font-size: var(--text-md);
  margin: 0 0 var(--space-1);
}

.banner p {
  margin: 0;
  color: var(--fg-dim);
  font-size: var(--text-sm);
}

/* ── Lists: Browse results and My Words ─────────────────── */

.result,
.list-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}

.result-main,
.row-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.row-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.result-hanzi,
.row-hanzi {
  font-family: var(--font-han);
  font-size: var(--text-lg);
  margin-right: var(--space-2);
}

.result-defs,
.row-defs {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
}

.row-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
}

.added {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.added-link {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

/* The small seal-red stamp that marks something done. */
.stamp-check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--accent);
  font-size: var(--text-sm);
  white-space: nowrap;
  animation: stamp-in var(--dur) var(--ease) both;
}

@media (prefers-reduced-motion: reduce) {
  .stamp-check {
    animation: none;
  }
}

.result-count {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  padding: var(--space-2) 0;
}

.loading {
  text-align: center;
  padding: var(--space-4);
}

.chip {
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  white-space: nowrap;
}

.chip-next {
  border-color: var(--fg-dim);
  color: var(--fg);
}

.chip-mine {
  border-color: var(--border);
}

.chip-learning {
  color: var(--fg);
}

.center {
  text-align: center;
}

/* ── Word ───────────────────────────────────────────────── */

.word-header {
  text-align: center;
  margin-bottom: var(--space-4);
}

.progress-list,
.links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.mode-tag {
  display: inline-block;
  min-width: 4.5em;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}

.siblings {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.links a {
  color: var(--fg);
  text-decoration-color: var(--fg-dim);
}

/* ── Stats: level, heatmap, badges, XP (§10) ────────────── */

.level-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.level-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.level-number {
  font-family: var(--font-display);
  font-size: var(--display);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.level-label {
  margin: 0;
  font-weight: 600;
}

.level-text p {
  margin: 0;
}

/* Twelve weeks, a column per week, oldest first. */
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  overflow-x: auto;
}

.heat {
  aspect-ratio: 1;
  min-width: 8px;
  border-radius: 2px;
  background: var(--surface-2);
}

/* Ink density, not colour — the palette already carries meaning. */
.heat-1 {
  background: color-mix(in srgb, var(--fg) 20%, var(--surface-2));
}

.heat-2 {
  background: color-mix(in srgb, var(--fg) 40%, var(--surface-2));
}

.heat-3 {
  background: color-mix(in srgb, var(--fg) 65%, var(--surface-2));
}

.heat-4 {
  background: var(--fg);
}

.badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
}

.badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0.55;
}

.badge-earned {
  opacity: 1;
  border-color: var(--fg-dim);
}

.badge-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--accent-fg);
  font-size: var(--text-sm);
}

.badge-earned .badge-mark {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
}

.badge-label {
  margin: 0;
  font-size: var(--text-sm);
}

.badge-text p {
  margin: 0;
}

.xp-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.xp-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--fg-dim);
}

.xp-value {
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.xp-total {
  border-top: 1px solid var(--border);
  padding-top: var(--space-2);
  font-weight: 600;
  color: var(--fg);
}

/* ── Progress bars ──────────────────────────────────────── */

.bars {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.bar-label {
  font-size: var(--text-sm);
  color: var(--fg-dim);
  margin-bottom: var(--space-1);
}

.bar-track {
  background: var(--surface-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  background: var(--fg);
  height: 100%;
  width: calc(var(--ratio, 0) * 100%);
}

/* ── Empty states: compositions, not captions (§3.3.6) ──── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-3);
  min-height: 50vh;
}

.empty-motif {
  opacity: 0.12;
  pointer-events: none;
}

.empty-motif-grid .tianzige {
  width: 160px;
}

.empty-motif-seal {
  opacity: 1;
  color: var(--accent);
}

.empty-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0;
}

.empty-note {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin: 0;
}

.typed-answer {
  color: var(--fg-dim);
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
}

.measure-words {
  font-family: var(--font-han);
  font-size: var(--text-lg);
  margin: 0;
}

/* ── Icons ──────────────────────────────────────────────── */

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-size, 24px);
  height: var(--icon-size, 24px);
  flex: none;
}

.icon svg {
  display: block;
}

/* ── Tone colours (values injected from config at boot) ─── */

.t1 { color: var(--t1); }
.t2 { color: var(--t2); }
.t3 { color: var(--t3); }
.t4 { color: var(--t4); }
.t5 { color: var(--t5); }

/* ── Audio controls: normal + slow (§3.4.2, §3.4.4) ─────── */

.audio-control {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.btn-slow {
  padding-inline: var(--space-2);
  min-width: 44px;
}

.turtle {
  font-size: var(--text-md);
  line-height: 1;
}

/* Tapping the character speaks it (§3.4.3), so it has to look touchable. */
.speakable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: opacity var(--dur) var(--ease);
}

.speakable:hover {
  opacity: 0.75;
}

.speakable:active {
  transform: scale(0.98);
}

.speakable:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
}

/* ── Study next, and word-page actions (§3.4.1, §3.4.6) ─── */

.word-actions {
  justify-content: center;
  margin-top: var(--space-3);
}

.result-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.practice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.locked-note {
  text-align: center;
  margin-top: var(--space-3);
}

/* ── Browse collections (§3.4.7) ────────────────────────── */

.collections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.collection {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 64px;
  padding: var(--space-3);
  text-align: left;
}

.collection-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.collection-meta {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

/* ── Voice picker (§3.4.4) ──────────────────────────────── */

.voices {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.voice-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
}

.voice-row:hover {
  background: var(--surface-2);
}

.voice-row.active {
  border-color: var(--fg-dim);
  background: var(--surface-2);
}

.voice-row input {
  accent-color: var(--fg);
  flex: none;
}

.voice-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.voice-name {
  font-size: var(--text-sm);
}

.voice-lang {
  font-size: var(--text-xs);
}

.voice-tip {
  margin-top: var(--space-2);
}

/* ── Onboarding and tone drills (Phase 7 §1) ────────────── */

.welcome,
.tones {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
}

.welcome-mark {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-3);
  color: var(--accent);
}

.welcome-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-xl);
  margin: 0 0 var(--space-3);
}

.welcome-lead {
  font-size: var(--text-lg);
  line-height: 1.5;
  margin: 0 0 var(--space-4);
}

.welcome-choices {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.welcome-skip {
  margin-top: var(--space-4);
  color: var(--fg-dim);
}

/* The archetype: mā má mǎ mà · ma. */
.tone-samples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.tone-sample {
  flex-direction: column;
  gap: var(--space-1);
  min-height: 96px;
  padding: var(--space-2);
}

.tone-sample-mark {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.tone-sample-pinyin {
  font-size: var(--text-lg);
}

.tone-sample-gloss {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

.tone-answers {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-1);
  margin: var(--space-3) 0;
}

.tone-answer {
  flex-direction: column;
  gap: 2px;
  min-height: 72px;
  padding: var(--space-2) var(--space-1);
}

.tone-answer-num {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.tone-answer-name {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

.pinyin-letters {
  font-family: var(--font-display);
  font-size: var(--display);
  margin: var(--space-3) 0;
}

.pinyin-example {
  font-family: var(--font-han);
  font-size: var(--text-lg);
  color: var(--fg-dim);
  margin-bottom: var(--space-3);
}

.home-secondary {
  margin-top: var(--space-3);
}

.tone-gym {
  width: 100%;
}

/* ── Teach screen (Phase 7 §3) ──────────────────────────── */

.teach {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  width: 100%;
}

.teach-pinyin {
  font-size: var(--text-xl);
  margin: 0;
}

.teach-defs {
  margin: 0;
  font-size: var(--text-lg);
}

.teach-sentence,
.teach-components {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}

.component-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.component-char {
  font-family: var(--font-han);
  font-size: var(--text-xl);
}

.component-equals {
  color: var(--fg-dim);
}

.component-parts {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.component-part {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.component-part-char {
  font-family: var(--font-han);
  font-size: var(--text-lg);
}

.component-part-meaning {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

.teach-done {
  margin-top: var(--space-3);
}

.teach-controls {
  min-height: 1px;
}

/* ══ Design v3 — night market ═══════════════════════════════════════════
   Stage surfaces get the theatre; tool surfaces stay fast and legible.
   Every glow below is gated on [data-effects="on"] and reduced motion. */

/* ── Neon signs (§2) ────────────────────────────────────── */

.neon-sign {
  display: grid;
  place-items: center;
  color: var(--neon-color, var(--accent));
}

.neon-defs {
  position: absolute;
  width: 0;
  height: 0;
}

.neon-stage {
  display: grid;
  place-items: center;
}

.neon-fallback {
  font-family: var(--font-han);
  font-size: clamp(64px, 18vw, 120px);
  line-height: 1;
  color: var(--neon-color, var(--accent));
}

/* The tube holds its glow once lit. */
:root[data-effects="on"] .neon-sign.lit .neon-fallback,
:root[data-effects="on"] .neon-sign.lit svg {
  filter: drop-shadow(0 0 6px var(--neon-color, var(--accent)))
    drop-shadow(0 0 18px var(--neon-color, var(--accent)));
}

.home-hero {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-3);
}

.hero-sign,
.done-sign {
  width: 140px;
  height: 140px;
}

.done-sign-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

/* ── Arcade layer (§3) — stage surfaces only ────────────── */

.odometer {
  display: inline-flex;
  gap: 1px;
  font-variant-numeric: tabular-nums;
}

.odometer-digit {
  display: inline-block;
}

:root[data-effects="on"] .odometer-digit.rolling {
  animation: odo-roll 300ms var(--ease) both;
  animation-delay: var(--roll-delay, 0ms);
}

@keyframes odo-roll {
  from {
    transform: translateY(-0.55em);
    opacity: 0.2;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.combo {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.combo-lit .combo-value {
  color: var(--accent);
}

:root[data-effects="on"] .combo-lit .combo-value {
  text-shadow: var(--glow-sm);
}

.combo-flame {
  font-size: 0.7em;
}

.medallions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
}

.medallion {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0.55;
  position: relative;
  overflow: hidden;
}

.medallion.earned {
  opacity: 1;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.medallion-face {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--accent);
}

.medallion.earned .medallion-face {
  border-color: var(--accent);
}

:root[data-effects="on"] .medallion.earned .medallion-face {
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 60%, transparent);
}

.medallion-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.medallion-label {
  font-size: var(--text-sm);
}

.medallion-progress {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

/* A single glint the first time an earned medallion is seen. */
:root[data-effects="on"] .medallion.glint::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 40%,
    rgb(255 255 255 / 0.22) 50%,
    transparent 60%
  );
  transform: translateX(-120%);
  animation: glint 900ms var(--ease) 200ms 1;
}

@keyframes glint {
  to {
    transform: translateX(120%);
  }
}

/* CRT scanlines — stage backgrounds only, never over reading. */
.stage-surface {
  position: relative;
}

:root[data-effects="on"] .stage-surface::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgb(255 255 255 / 0.03) 0 1px,
    transparent 1px 3px
  );
}

.stage-surface > * {
  position: relative;
  z-index: 1;
}

/* Paper is the reading lamp: no scanlines, whatever the effects setting. */
:root[data-theme="light"] .stage-surface::before {
  display: none;
}

/* ── Browse signboard (§5) ──────────────────────────────── */

.signboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.sign {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 68px;
  padding: var(--space-3);
  text-align: left;
  border-color: var(--border);
}

.sign-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--fg);
}

.sign-meta {
  font-size: var(--text-xs);
  color: var(--fg-dim);
}

.sign:hover:not(:disabled),
.sign:focus-visible {
  border-color: var(--accent);
}

:root[data-effects="on"] .sign:hover:not(:disabled) .sign-name,
:root[data-effects="on"] .sign:focus-visible .sign-name {
  color: var(--accent);
  text-shadow: var(--glow-sm);
}

/* ── Review: the four sanctioned accents (§4) ───────────── */

/* 1. The progress line. */
.session-bar-fill.neon-line {
  background: var(--accent);
}

:root[data-effects="on"] .session-bar-fill.neon-line {
  box-shadow: 0 0 6px var(--accent);
}

/* 2. The mode eyebrow's icon, faintly. */
:root[data-effects="on"] .eyebrow-glyph {
  filter: drop-shadow(0 0 4px currentColor);
  opacity: 0.9;
}

/* 3. One pulse on a correct judged answer. */
:root[data-effects="on"] .verdict.pulse-ok {
  animation: pulse-ok 420ms var(--ease) 1;
}

@keyframes pulse-ok {
  0% {
    text-shadow: none;
  }
  40% {
    text-shadow: 0 0 8px var(--ok);
  }
  100% {
    text-shadow: none;
  }
}

/* 4. Nothing else. The 田字格 stays ink — it is reading furniture, never a sign. */

/* Reduced motion and the reduce-effects switch stop everything above. */
@media (prefers-reduced-motion: reduce) {
  .odometer-digit.rolling,
  .medallion.glint::after,
  .verdict.pulse-ok {
    animation: none;
  }

  .stage-surface::before {
    display: none;
  }
}
