/* ============================================================================
   lull design system - "Nocturne"
   ----------------------------------------------------------------------------
   A premium, audio-first dark theme for the lull web app. Everything visual is
   driven by the design tokens in :root below (type scale, colour, spacing,
   radius, shadow, motion) so the look is consistent and the onboarding flow
   (welcome / language picker / paywall) can be built on the SAME primitives.

   Type pairing (self-hosted, see fonts/fonts.css):
     - Inter    : the UI grotesque - controls, labels, body, numbers in chrome.
     - Fraunces : the warm display serif - the target-language words, hero
                  numbers, screen titles. The Indonesian content reads as an
                  editorial object; the UI chrome stays quietly out of the way.

   The layout contract is LOAD-BEARING and unchanged: `.app` is pinned to the
   viewport (100dvh, overflow hidden) so the primary action + tab bar never fall
   below the fold; only the flexible middle region shrinks/scrolls. Do not
   regress this to min-height (see AGENTS.md / CLAUDE.md).
   ========================================================================== */

:root {
  /* ── Colour: raw nocturne palette ─────────────────────────────────────── */
  --bg-base: #06070f; /* the page behind the app column */
  --surface: #0c0e1b; /* app column base */
  --surface-1: #13162a; /* cards, panels */
  --surface-2: #191d36; /* raised controls, chips, list rows */
  --surface-3: #232845; /* hover / pressed */
  --glow-top: #1b2042; /* the radial aurora at the top of the column */

  --border: rgba(154, 164, 224, 0.1);
  --border-strong: rgba(154, 164, 224, 0.2);
  --border-faint: rgba(154, 164, 224, 0.055);

  --text: #edeffb;
  --text-dim: #a4abd4;
  --text-faint: #6e7398;

  /* Brand: a calm, luminous periwinkle. */
  --brand: #8ea2ff;
  --brand-bright: #aab8ff;
  --brand-deep: #5e6df0;
  --brand-ink: #0a0c1a; /* text/icon on a brand fill */
  --brand-soft: rgba(142, 162, 255, 0.14);
  --brand-glow: rgba(94, 109, 240, 0.45);

  /* Warm accent: amber. The "new word / pay attention" signal - the only warm
     note against the cool base, so it always reads as important. */
  --warm: #ffce86;
  --warm-bright: #ffd89c;
  --warm-ink: #2a2008;
  --warm-soft: rgba(255, 206, 134, 0.16);

  /* Positive (knew-it / known / mature) and danger (lapse) and info (young). */
  --positive: #74e0a8;
  --positive-ink: #04230f;
  --positive-soft: rgba(116, 224, 168, 0.15);
  --danger: #ff9090;
  --danger-soft: rgba(255, 144, 144, 0.14);
  --info: #7cc0ee;

  /* Semantic aliases (use these in components, not the raw palette). */
  --bg-card: var(--surface-1);
  --bg-control: var(--surface-2);
  --on-brand: var(--brand-ink);

  /* ── Type scale (modular ~1.22) ───────────────────────────────────────── */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;

  --text-2xs: 0.6875rem; /* 11 */
  --text-xs: 0.75rem; /* 12 */
  --text-sm: 0.8125rem; /* 13 */
  --text-base: 0.9375rem; /* 15 */
  --text-md: 1.0625rem; /* 17 */
  --text-lg: 1.25rem; /* 20 */
  --text-xl: 1.5rem; /* 24 */
  --text-2xl: 1.9375rem; /* 31 */
  --text-3xl: 2.75rem; /* 44 */
  --text-4xl: 3.5rem; /* 56 */

  --tracking-tight: -0.02em;
  --tracking-snug: -0.01em;
  --tracking-wide: 0.06em;
  --tracking-wider: 0.12em;

  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.55;

  /* ── Spacing scale (4px base) ─────────────────────────────────────────── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;

  /* ── Radius ───────────────────────────────────────────────────────────── */
  --radius-xs: 7px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* ── Elevation ────────────────────────────────────────────────────────── */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.22);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.55);
  --glow-brand: 0 8px 30px rgba(94, 109, 240, 0.45);
  /* a hairline "lit from above" highlight on raised surfaces */
  --edge-light: inset 0 1px 0 rgba(255, 255, 255, 0.05);

  /* ── Motion ───────────────────────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --dur-4: 520ms;

  /* ── Layout ───────────────────────────────────────────────────────────── */
  --maxw: 460px;
  --z-tabbar: 10;
  --z-status: 30;
  --z-peek: 40;
  --z-calib: 50;
  --z-onb: 50;
  --z-auth: 60;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg-base);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-feature-settings: "kern", "liga", "calt";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* The display serif, used for content-language words + hero figures + titles. */
.font-display {
  font-family: var(--font-display);
  font-optical-sizing: auto;
}

/* Shared focus ring for keyboard users (premium + accessible). */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* The app is a phone-shaped column: header on top, the active view in the
   middle, the mode tab bar pinned at the bottom. BOUNDED to the viewport
   (height, not min-height) with overflow contained, so a short phone viewport
   never pushes the primary action / tab bar below the fold into a full-page
   scroll - the flexible middle absorbs the squeeze instead. */
.app {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(125% 62% at 50% -8%, var(--glow-top) 0%, transparent 60%),
    radial-gradient(90% 55% at 50% 0%, #141833 0%, var(--surface) 58%);
}

/* A transient message overlay (loading / error). It does not block: pointer
   events pass through so the tab bar + recovery buttons beneath stay usable even
   while an error is shown (you can shuffle the pool / retry). */
.status {
  position: absolute;
  inset: 0;
  z-index: var(--z-status);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  padding: var(--space-8) var(--space-6);
  font-size: var(--text-md);
  letter-spacing: var(--tracking-snug);
  background: rgba(6, 7, 15, 0.84);
  backdrop-filter: blur(3px);
  pointer-events: none;
}
.status.error {
  color: var(--danger);
}
.status[hidden] {
  display: none;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: max(env(safe-area-inset-top), var(--space-4));
}
.stage[hidden] {
  display: none;
}

/* ── header: contextual label + progress ──────────────────────────────────── */
.scrhead {
  padding: var(--space-1) var(--space-5) 0;
  flex-shrink: 0;
}
.scrtop {
  font-size: var(--text-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  font-weight: 600;
  min-height: 1.3em;
}
.prog {
  height: 3px;
  background: var(--border);
  border-radius: var(--radius-pill);
  margin: var(--space-2) 0 0;
  overflow: hidden;
}
.prog.hidden {
  visibility: hidden;
}
.prog > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--brand-deep), var(--brand-bright));
  transition: width var(--dur-2) linear;
}

/* ── views ────────────────────────────────────────────────────────────────── */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--space-2) var(--space-5) var(--space-3);
}
.view[hidden] {
  display: none;
}
.view-list {
  overflow-y: auto;
}

/* The full-area tap target (Listen). Tap anywhere; nothing to aim at. */
.tapzone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  text-align: center;
  /* Contain the absolutely-positioned native-source video host (G6). */
  position: relative;
  /* The flexible region: it shrinks (and scrolls internally on a very short
     viewport) so the action buttons + footer + tab bar stay pinned and visible. */
  min-height: 0;
  overflow-y: auto;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tapzone:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 6px;
  border-radius: var(--radius-xl);
}
/* author display:flex otherwise beats the UA hidden rule (see AGENTS.md). */
.tapzone[hidden] {
  display: none;
}

/* ── native source-audio video host (PRD §11 G6) ──────────────────────────── */
/* Holds the YouTube embed for a custom-content part that plays its original
   source. pointer-events:none so the tap-to-mark surface underneath stays live
   (lull drives play/pause via the IFrame API, not the embed's own controls). */
.yt-host {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  pointer-events: none;
  z-index: 2;
}
.yt-host[hidden] {
  display: none;
}
.yt-host iframe,
.yt-host > * {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, 0 12px 40px rgba(0, 0, 0, 0.45));
}
/* While the source video shows, the orb + hint give way to it. */
.tapzone.playing-source .orb,
.tapzone.playing-source .hint {
  visibility: hidden;
}

/* ── the glowing "listening" orb ──────────────────────────────────────────── */
/* A luminous pearl: a layered radial body, an off-centre highlight (::before),
   and a soft blurred halo behind it (::after). It breathes slowly while playing,
   dims when paused, and gives a quick haptic "flash" pop on a tap. */
.orb {
  position: relative;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 34%, #ffffff 0%, transparent 26%),
    radial-gradient(
      circle at 50% 42%,
      var(--brand-bright) 0%,
      var(--brand) 48%,
      var(--brand-deep) 100%
    );
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 18px 60px rgba(94, 109, 240, 0.5);
  animation: breathe 4s var(--ease-soft) infinite;
}
.orb::before {
  /* a small specular highlight near the top, for dimensionality */
  content: "";
  position: absolute;
  top: 18%;
  left: 26%;
  width: 34%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.7), transparent 70%);
  filter: blur(3px);
}
.orb::after {
  /* a wide soft halo bloom behind the orb */
  content: "";
  position: absolute;
  inset: -34%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--brand-glow) 0%, transparent 62%);
  z-index: -1;
  animation: halo 4s var(--ease-soft) infinite;
}
.orb.paused {
  animation-play-state: paused;
  opacity: 0.5;
  filter: saturate(0.7);
}
.orb.paused::after {
  animation-play-state: paused;
  opacity: 0.45;
}
.orb.flash {
  animation: none;
  transform: scale(1.1);
  transition: transform var(--dur-1) var(--ease-spring);
}
@keyframes breathe {
  0%,
  100% {
    transform: scale(0.965);
  }
  50% {
    transform: scale(1.035);
  }
}
@keyframes halo {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.95);
  }
  50% {
    opacity: 0.85;
    transform: scale(1.08);
  }
}

/* The honest play-state caption under the orb (Listening / Paused / Ready /
   Preparing). A calm, tracked status line - the single source of truth for what
   is happening, so it can never contradict the transport control. */
.lstate {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-dim);
  min-height: 1.2em;
  margin-top: calc(-1 * var(--space-1));
}

/* The eyes-free mark gesture hint - subtle, secondary, shown only while a live
   story plays (set hidden by JS otherwise). */
.hint {
  color: var(--text-faint);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  max-width: 26ch;
}
.hint strong {
  color: var(--text-dim);
  font-weight: 600;
}

.chip {
  align-self: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--brand-bright);
  background: var(--brand-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft);
}
.chip[hidden] {
  display: none;
}
.chip:hover {
  border-color: var(--brand);
  background: rgba(142, 162, 255, 0.2);
}

/* ── genre / topic picker ─────────────────────────────────────────────────── */
/* A single, horizontally-scrolling row of chips. Fixed strip (flex-shrink:0) so
   it never pushes the primary action below the fold; only the tapzone shrinks. */
.genrebar {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1) var(--space-1) var(--space-2);
  flex-shrink: 0;
  scrollbar-width: none; /* eyes-free, no scrollbar chrome */
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.genrebar::-webkit-scrollbar {
  display: none;
}
/* author display:flex beats the UA hidden rule (the documented gotcha). */
.genrebar[hidden] {
  display: none;
}
.genre-chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft),
    color var(--dur-1) var(--ease-soft);
}
.genre-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.genre-chip.active {
  color: var(--brand-ink);
  background: linear-gradient(160deg, var(--brand-bright), var(--brand-deep));
  border-color: transparent;
}

.summary {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--text-sm);
  max-width: 32ch;
}
.summary[hidden] {
  display: none;
}
.summary .marked {
  color: var(--warm);
  font-weight: 600;
}

/* ── listen footer: ONE primary transport, then secondary actions ─────────── */
/* The whole footer is pinned (flex-shrink:0) so the primary play control + the
   tab bar never fall below the fold; only the tapzone above absorbs a short
   viewport. */
.listen-footer {
  flex-shrink: 0;
  padding-top: var(--space-2);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* The single play/pause control, centred and prominent. A small transcript
   toggle sits to one side without competing; the play disc is the clear, lone
   primary action (it also cold-starts the live loop). */
.transport {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
}
.transport .ttoggle {
  justify-self: start;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  flex-shrink: 0; /* secondary actions stay visible; only the tapzone shrinks */
}
.actions:empty {
  display: none;
}

/* The round play/pause transport. A brand-gradient disc with a soft glow. */
.playbtn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--brand-bright), var(--brand-deep));
  color: var(--brand-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  border: none;
  cursor: pointer;
  box-shadow: var(--glow-brand), var(--edge-light);
  transition:
    transform var(--dur-1) var(--ease-spring),
    box-shadow var(--dur-2) var(--ease-soft),
    filter var(--dur-2) var(--ease-soft);
}
.playbtn:hover {
  filter: brightness(1.06);
  box-shadow: 0 10px 38px rgba(94, 109, 240, 0.6), var(--edge-light);
}
.playbtn:active {
  transform: scale(0.93);
}
/* The Listen-home primary: a larger disc so the single play action reads as THE
   focal control, with breathing room (no longer cramped in the lower third). */
.playbtn-primary {
  width: 76px;
  height: 76px;
  font-size: var(--text-xl);
}
.playbtn-primary > span {
  /* nudge the play triangle to optical centre */
  transform: translateX(1px);
}
.playbtn:disabled {
  cursor: default;
}
.playbtn:disabled:active {
  transform: none;
}
/* Non-blocking cold-start "preparing": the lone control pulses while a segment
   warms in the background (nothing is playable yet, so it disables to avoid a
   double-submit), mirroring the .btn.busy affordance. */
.playbtn.busy {
  animation: btn-pulse 1.5s var(--ease-soft) infinite;
}
.gest {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  text-align: center;
  letter-spacing: 0.01em;
  margin-top: var(--space-2);
}

/* Very short viewports (landscape / small split views): shrink the ambient orb
   and the transport so the orb never collides with the play control while the
   layout stays viewport-bounded (no page scroll; tab bar + play stay visible). */
@media (max-height: 560px) {
  .orb {
    width: 84px;
    height: 84px;
  }
  .playbtn-primary {
    width: 64px;
    height: 64px;
    font-size: var(--text-lg);
  }
  .tapzone {
    gap: var(--space-3);
  }
}

/* ── buttons ──────────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  padding: var(--space-3) var(--space-6);
  cursor: pointer;
  transition:
    transform var(--dur-1) var(--ease-spring),
    opacity var(--dur-1) var(--ease-soft),
    box-shadow var(--dur-2) var(--ease-soft),
    filter var(--dur-2) var(--ease-soft);
}
.btn:active {
  transform: scale(0.975);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn[hidden] {
  display: none;
}
/* Non-blocking "preparing" affordance: a soft pulse on the disabled button while
   a segment is generated in the background. It replaces the old full-screen
   "generating" overlay, so the rest of the app stays usable. */
.btn.busy {
  animation: btn-pulse 1.5s var(--ease-soft) infinite;
}
@keyframes btn-pulse {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 0.92;
  }
}
.btn-primary {
  background: linear-gradient(160deg, var(--brand-bright), var(--brand-deep));
  color: var(--brand-ink);
  box-shadow: var(--glow-brand), var(--edge-light);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 10px 38px rgba(94, 109, 240, 0.58), var(--edge-light);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
}

/* The prominent active-review entry on the Listen home. Amber = due/attention
   (matches the status-colour system + the recap CTA), so it reads as an
   actionable nudge distinct from the brand "Start listening". The live due count
   is the focal number. */
.btn-review {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--warm-soft);
  color: var(--warm-bright);
  border: 1px solid var(--warm-soft);
  box-shadow: var(--edge-light);
}
.btn-review:hover:not(:disabled) {
  color: var(--warm-bright);
  border-color: var(--warm);
  filter: brightness(1.05);
}
.btn-review .rcta-ic {
  display: inline-flex;
  width: 18px;
  height: 18px;
  color: var(--warm);
}
.btn-review .rcta-ic svg {
  width: 18px;
  height: 18px;
  display: block;
}
.btn-review .rcta-num {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--warm);
}

/* ── review flashcard (quiet, UI-driven; NO audio) ────────────────────────── */
/* The review view is a column: a big tappable card, the reveal button, then the
   four FSRS grade buttons (shown after the answer is revealed). */
#review-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
}
/* The id selector above beats `.view[hidden]{display:none}`, so restore the hide
   rule at id specificity (the documented hidden-rule gotcha, see AGENTS.md). */
#review-view[hidden] {
  display: none;
}
.rcard {
  background: linear-gradient(170deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: var(--space-7) var(--space-5);
  width: 100%;
  max-width: 340px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-md), var(--edge-light);
  transition:
    transform var(--dur-2) var(--ease-spring),
    border-color var(--dur-2) var(--ease-soft);
  -webkit-tap-highlight-color: transparent;
}
.rcard:active {
  transform: scale(0.99);
}
.statuschip {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
}
.statuschip[hidden] {
  display: none;
}
.statuschip.s-new {
  background: var(--warm-soft);
  color: var(--warm);
}
.statuschip.s-learning {
  background: var(--brand-soft);
  color: var(--brand-bright);
}
.statuschip.s-known {
  background: var(--positive-soft);
  color: var(--positive);
}
.rword {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  line-height: var(--leading-tight);
  cursor: pointer;
}
.rhint {
  color: var(--text-faint);
  font-size: var(--text-sm);
  margin-top: var(--space-3);
}
.rback[hidden] {
  display: none;
}
.rmean {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  color: var(--warm);
  font-size: var(--text-lg);
  font-weight: 500;
  margin-top: var(--space-4);
}
.rexample {
  color: var(--text);
  font-size: var(--text-sm);
  font-style: italic;
  margin-top: var(--space-3);
  opacity: 0.82;
}
.rexample[hidden] {
  display: none;
}
.rsrs {
  color: var(--text-faint);
  font-size: var(--text-xs);
  margin-top: var(--space-3);
}
.revealrow {
  width: 100%;
  max-width: 340px;
  display: flex;
  justify-content: center;
}
.revealrow[hidden] {
  display: none;
}
.revealrow .btn {
  width: 100%;
}
/* The four FSRS grades, side by side. */
.grades {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  width: 100%;
  max-width: 340px;
}
.grades[hidden] {
  display: none;
}
.gbtn {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition:
    transform var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft),
    border-color var(--dur-1) var(--ease-soft);
  -webkit-tap-highlight-color: transparent;
}
.gbtn:active {
  transform: translateY(1px);
}
.g-again {
  border-color: rgba(255, 144, 144, 0.45);
  color: var(--danger);
}
.g-again:hover {
  background: var(--danger-soft);
}
.g-hard {
  border-color: rgba(255, 206, 134, 0.42);
  color: var(--warm);
}
.g-hard:hover {
  background: var(--warm-soft);
}
.g-good {
  border-color: rgba(142, 162, 255, 0.45);
  color: var(--brand-bright);
}
.g-good:hover {
  background: var(--brand-soft);
}
.g-easy {
  border-color: rgba(116, 224, 168, 0.45);
  color: var(--positive);
}
.g-easy:hover {
  background: var(--positive-soft);
}

/* ── lists (marked words, history) ────────────────────────────────────────── */
.listhead {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin: var(--space-1) 0 var(--space-3);
}
.list {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-1);
  border-bottom: 1px solid var(--border-faint);
}
.row:last-child {
  border-bottom: none;
}
.row .w {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: var(--text-md);
}
.row .m {
  color: var(--text-dim);
  font-size: var(--text-xs);
}
.row .st {
  margin-left: auto;
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--warm);
}
.list-empty {
  color: var(--text-faint);
  font-size: var(--text-sm);
  padding: var(--space-5) var(--space-1);
}

/* History list rows: a card with a play affordance. */
.seg {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--edge-light);
  transition:
    border-color var(--dur-1) var(--ease-soft),
    transform var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft);
}
.seg:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.seg:active {
  transform: scale(0.99);
}
.seg .pl {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: var(--text-xs);
}
.seg .t {
  font-size: var(--text-sm);
  font-weight: 500;
}
.seg .sub {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: 1px;
}
.seg .dur {
  margin-left: auto;
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  white-space: nowrap;
}

#marked-back {
  margin-top: var(--space-4);
  align-self: flex-start;
}

/* ── transcript (Show transcript toggle: Listen + Story) ──────────────────── */
.ttoggle {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color var(--dur-1) var(--ease-soft),
    color var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft);
}
.ttoggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.ttoggle[aria-pressed="true"] {
  color: var(--brand-bright);
  border-color: var(--brand);
  background: var(--brand-soft);
}
.ttoggle-spacer {
  justify-self: end;
}

/* The transcript renders the content language as an editorial serif column. */
.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-lg);
  font-weight: 400;
  line-height: 1.85;
  padding: var(--space-2) var(--space-1) var(--space-4);
}
.transcript[hidden] {
  display: none;
}
.tw {
  cursor: pointer;
  border-radius: 5px;
  /* Minimal horizontal padding: word separation now comes from the script's own
     spaces (interleaved into the transcript), so the old 3px side padding only
     pushed a visible gap BEFORE each punctuation mark. Keep a 1px hair for the
     highlight band; punctuation now hugs its word. */
  padding: 1px 1px;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-1) var(--ease-soft),
    color var(--dur-1) var(--ease-soft);
}
/* Inline status colour-coding (captain's request: SEE each word's status at a
   glance and spot mis-marked easy words). New = highlighted (a freshly introduced
   or reset word, the one to notice); Learning = lighter amber; Known + untracked =
   unstyled, so the words that need attention stand out. */
.tw-new {
  color: var(--warm);
  font-weight: 600;
  background: var(--warm-soft);
}
.tw-learning {
  color: var(--warm-bright);
  font-weight: 500;
}
.tw-unknown {
  color: var(--danger);
  font-weight: 500;
}
.tw-known,
.tw-plain {
  color: var(--text);
}
.tw:active,
.tw.sel {
  background: var(--brand-soft);
}
/* The word being spoken right now: the playback-synced highlight (in time with
   the audio). Two-class specificity so it reads over .tw.sel and the colour
   classes. */
.tw.tw-active {
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
/* Proper paragraphs (captain): the transcript reads as spaced, indented blocks, not
   a run-on blob. The first line of each paragraph is indented; paragraphs are
   separated vertically. */
.tw-para {
  margin: 0 0 var(--space-3);
  text-indent: var(--space-5);
}
.tw-para:first-child {
  margin-top: 0;
}

/* The tap-to-inspect word peek (transcript): meaning + SRS state, in context.
   Pinned just under the header so it never covers the bottom controls (the play
   button, the transcript toggle, the tab bar) and stays reachable. */
.peek {
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  top: calc(env(safe-area-inset-top) + 56px);
  z-index: var(--z-peek);
  background: var(--surface-1);
  border: 1px solid var(--brand);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-lg);
  animation: peek-in var(--dur-2) var(--ease-out);
}
@keyframes peek-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.peek[hidden] {
  display: none;
}
.peek-x {
  position: absolute;
  top: var(--space-1);
  right: var(--space-2);
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
  padding: var(--space-1);
}
.peek-x:hover {
  color: var(--text);
}
.peek-word {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-xl);
  font-weight: 600;
}
.peek-gloss {
  color: var(--warm);
  font-size: var(--text-sm);
  margin-top: 3px;
}
.peek-gloss.muted {
  color: var(--text-faint);
}
.peek-srs {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: var(--space-3);
}

/* The New / Learning / Known segmented control inside the word popup. Each option
   is colour-coded to match the inline word colours; the current status is shown
   pressed. Tapping a segment recategorizes the word at once (captain override). */
.segctl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.segctl[hidden] {
  display: none;
}
.segbtn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-soft),
    color var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft);
  -webkit-tap-highlight-color: transparent;
}
.segbtn:hover {
  border-color: var(--border-strong);
}
.segbtn.sel.seg-new {
  border-color: var(--warm);
  color: var(--warm);
  background: var(--warm-soft);
}
.segbtn.sel.seg-learning {
  border-color: var(--brand-bright);
  color: var(--brand-bright);
  background: var(--brand-soft);
}
.segbtn.sel.seg-known {
  border-color: var(--positive);
  color: var(--positive);
  background: var(--positive-soft);
}
.peek-iknow {
  margin-top: var(--space-3);
  width: 100%;
  border: 1px solid rgba(116, 224, 168, 0.45);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--positive);
  background: var(--positive-soft);
  cursor: pointer;
  transition: filter var(--dur-1) var(--ease-soft);
}
.peek-iknow:hover {
  filter: brightness(1.1);
}
.peek-iknow[hidden] {
  display: none;
}

/* ── progress stats (Progress tab) ────────────────────────────────────────── */
.pstats {
  padding: var(--space-1) 0 var(--space-1);
}
.pstats[hidden] {
  display: none;
}
.hero {
  text-align: center;
  padding: var(--space-2) 0 var(--space-5);
}
.hero-num {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-4xl);
  font-weight: 500;
  letter-spacing: var(--tracking-tight);
  line-height: 1;
  color: var(--text);
}
.hero-label {
  font-size: var(--text-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  font-weight: 600;
  margin-top: var(--space-2);
}
.pcard {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--edge-light);
}
.pcard-title {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-weight: 600;
  margin-bottom: var(--space-3);
}
.mbar {
  display: flex;
  height: 18px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  gap: 2px;
}
.mbar > i {
  display: block;
  height: 100%;
}
.m-new {
  background: var(--warm);
}
.m-learning {
  background: var(--warm-bright);
  opacity: 0.7;
}
.m-young {
  background: var(--info);
}
.m-mature {
  background: var(--positive);
}
.mlegend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
}
.mleg {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-dim);
}
.mleg .dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}
.mleg b {
  color: var(--text);
  font-weight: 700;
}
.chart {
  width: 100%;
  height: 66px;
  display: block;
}
.chart-empty,
.ret-empty {
  font-size: var(--text-xs);
  color: var(--text-faint);
  padding: var(--space-2) 0;
}
.ret-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}
.ret-rate {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-2xl);
  font-weight: 500;
  color: var(--positive);
  line-height: 1;
}
.ret-sub {
  font-size: var(--text-xs);
  color: var(--text-faint);
}
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-3);
  text-align: center;
  box-shadow: var(--edge-light);
}
.tile-num {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--text);
}
.tile-label {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  margin-top: var(--space-1);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-weight: 600;
}
.tile-sub {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  margin-top: 3px;
  opacity: 0.9;
}
.histhead {
  margin-top: var(--space-4);
}

/* ── browsable vocabulary list (Progress tab; real word_state / FSRS state) ── */
.vocab-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}
.vocab-controls[hidden] {
  /* author display:flex beats the UA hidden rule (documented gotcha) */
  display: none;
}
.vocab-search {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-family: inherit;
}
.vocab-search::placeholder {
  color: var(--text-faint);
}
.vocab-search:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--glow-brand);
}
.vocab-sort {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px;
  flex: none;
}
.vocab-sortbtn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: var(--text-2xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.vocab-sortbtn.active {
  background: var(--brand-soft);
  color: var(--brand);
}
.vocab-list {
  gap: 0;
}
.vrow {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-1);
  border-bottom: 1px solid var(--border-faint);
  border-left: 2px solid transparent;
  padding-left: var(--space-3);
}
.vrow:last-child {
  border-bottom: none;
}
.vrow[data-bucket="new"] {
  border-left-color: var(--warm);
}
.vrow[data-bucket="learning"] {
  border-left-color: var(--warm-bright);
}
.vrow[data-bucket="young"] {
  border-left-color: var(--info);
}
.vrow[data-bucket="mature"] {
  border-left-color: var(--positive);
}
.vrow-main {
  flex: 1 1 auto;
  min-width: 0;
}
.vword {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: var(--text-md);
  color: var(--text);
  line-height: 1.2;
}
.vgloss {
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vrow-meta {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  text-align: right;
}
.vpill {
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-dim);
}
.vpill.v-new {
  background: var(--warm-soft);
  color: var(--warm);
}
.vpill.v-learning {
  background: var(--warm-soft);
  color: var(--warm-bright);
}
.vpill.v-young {
  background: var(--info-soft, rgba(122, 162, 247, 0.15));
  color: var(--info);
}
.vpill.v-mature {
  background: var(--positive-soft);
  color: var(--positive);
}
.vsub {
  font-size: var(--text-2xs);
  color: var(--text-faint);
}

/* ── close-the-loop recap banner (Listen + Progress) ───────────────────────── */
/* Amber = the "you marked these, lock them in" attention signal. A single tap on
   the whole banner routes into review; the corner x dismisses it for the session. */
.recap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  position: relative;
  background: linear-gradient(180deg, var(--warm-soft), rgba(255, 206, 134, 0.06));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--edge-light), var(--shadow-sm);
  cursor: pointer;
  transition:
    transform var(--dur-1) var(--ease-out),
    border-color var(--dur-2) var(--ease-soft);
  -webkit-tap-highlight-color: transparent;
}
.recap:hover {
  border-color: var(--warm-soft);
}
.recap:active {
  transform: scale(0.99);
}
.recap[hidden] {
  display: none;
}
.recap-num {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-3xl);
  font-weight: 500;
  line-height: 0.9;
  color: var(--warm);
  flex: none;
  min-width: 1.4em;
  text-align: center;
}
.recap-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.recap-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}
.recap-sub {
  font-size: var(--text-xs);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recap-cta {
  flex: none;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--warm-ink);
  background: var(--warm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.recap.done .recap-num {
  color: var(--positive);
}
.recap.done .recap-cta {
  color: var(--positive-ink);
  background: var(--positive);
}
.recap-x {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: var(--text-md);
  line-height: 1;
  color: var(--text-faint);
  padding: 2px 4px;
}
.recap-x:hover {
  color: var(--text-dim);
}

/* ── difficulty feedback prompt (end of story / on pause) ──────────────────── */
/* A quick, dismissible nudge - "too easy / just right / too hard" - that drives the
   active-feedback recalibration (we ASK what was new/hard, never guess). Sits at the
   top of the listen view; flex-shrink:0 so the viewport-bounded layout holds. */
.feedback {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: linear-gradient(170deg, var(--surface-1), var(--surface-2));
  box-shadow: var(--shadow-sm), var(--edge-light);
}
.feedback[hidden] {
  display: none;
}
.fb-q {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}
.fb-opts {
  display: flex;
  gap: var(--space-2);
}
.fb-opt {
  flex: 1;
  padding: var(--space-2) var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background-color var(--dur-1) var(--ease-soft),
    transform var(--dur-1) var(--ease-spring);
}
.fb-opt:active {
  transform: scale(0.97);
}
.fb-opt:hover {
  background: var(--brand-soft);
}
.fb-x {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: var(--text-md);
  line-height: 1;
  color: var(--text-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
}
.fb-x:hover {
  color: var(--text-dim);
}

/* ── "this week" effort row (Progress) ─────────────────────────────────────── */
.weekrow {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.weekstat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-2);
  text-align: center;
  box-shadow: var(--edge-light);
}
.weekstat .wn {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text);
  line-height: 1;
}
.weekstat .wl {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  margin-top: var(--space-1);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-weight: 600;
}

/* ── momentum: per-day effort bars (Progress) ──────────────────────────────── */
.mom {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 64px;
  margin-top: var(--space-1);
}
.mom-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 3px;
  height: 100%;
  min-width: 0;
}
.mom-bar {
  width: 100%;
  max-width: 16px;
  min-height: 3px;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  transition: height var(--dur-3) var(--ease-out);
}
.mom-day.on .mom-bar {
  background: linear-gradient(180deg, var(--brand-bright), var(--brand-deep));
}
.mom-day.today .mom-bar {
  background: linear-gradient(180deg, var(--warm-bright), var(--warm));
}
.mom-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--positive);
}
.mom-dot.empty {
  background: transparent;
}
.mom-foot {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-2xs);
  color: var(--text-faint);
  margin-top: var(--space-2);
}

/* ── story view (replay a past listen) ────────────────────────────────────── */
#story-back {
  align-self: flex-start;
  margin-bottom: var(--space-1);
  padding-left: 0;
}
.story-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  margin: var(--space-1) 0 3px;
}
.story-sub {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-4);
}
.story-player {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

/* ── the mode switcher (bottom tab bar) ───────────────────────────────────── */
.tabbar {
  display: flex;
  z-index: var(--z-tabbar);
  border-top: 1px solid var(--border);
  background: rgba(9, 11, 22, 0.78);
  backdrop-filter: blur(20px) saturate(1.3);
  padding: var(--space-2) var(--space-1) calc(env(safe-area-inset-bottom) + var(--space-3));
  flex-shrink: 0; /* the mode bar is always pinned at the bottom of the viewport */
}
.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  text-align: center;
  color: var(--text-faint);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  cursor: pointer;
  padding: var(--space-1) 0;
  transition: color var(--dur-1) var(--ease-soft);
}
.tab .ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}
.tab .ic svg {
  width: 22px;
  height: 22px;
  display: block;
}
.tab:hover {
  color: var(--text-dim);
}
.tab.active {
  color: var(--brand-bright);
}
.tab.active .ic {
  filter: drop-shadow(0 0 7px rgba(142, 162, 255, 0.6));
}
.badge {
  position: absolute;
  top: -3px;
  left: calc(50% + 8px);
  background: var(--warm);
  color: var(--warm-ink);
  font-size: 9px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0 5px;
  line-height: 15px;
}
.badge[hidden] {
  display: none;
}

/* ── first-run calibration overlay (self-rating seed -> banded probe) ───────── */
.calib {
  position: fixed;
  inset: 0;
  z-index: var(--z-calib);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom));
  background:
    radial-gradient(125% 62% at 50% -6%, var(--glow-top) 0%, transparent 58%),
    radial-gradient(90% 60% at 50% 0%, #141833 0%, var(--surface) 62%);
  overflow-y: auto;
}
.calib[hidden] {
  display: none;
}
.calib-panel {
  width: 100%;
  max-width: var(--maxw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.calib-panel[hidden] {
  display: none;
}
/* A small brand kicker above the first-run title (the first thing a new user
   sees). The only place the wordmark appears - the listen screen stays blank. */
.calib-kicker {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-lg);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--brand-bright);
  text-shadow: 0 0 24px rgba(142, 162, 255, 0.5);
}
.calib-title {
  margin: 0;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-2xl);
  font-weight: 500;
  letter-spacing: var(--tracking-snug);
  text-align: center;
  line-height: var(--leading-snug);
}
.calib-sub {
  margin: 0;
  color: var(--text-dim);
  text-align: center;
  font-size: var(--text-base);
  max-width: 34ch;
}

/* seed cards */
.calib-cards {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.calib-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--edge-light);
  transition:
    border-color var(--dur-2) var(--ease-soft),
    background-color var(--dur-2) var(--ease-soft),
    transform var(--dur-1) var(--ease-spring);
}
.calib-card:hover {
  border-color: var(--brand);
  background: var(--surface-2);
}
.calib-card:active {
  transform: scale(0.985);
}
.calib-card-h {
  font-size: var(--text-md);
  font-weight: 600;
}
.calib-card-d {
  font-size: var(--text-sm);
  color: var(--text-dim);
}

/* probe progress */
.calib-progress {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.calib-count {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-dim);
  min-width: 46px;
}
.calib-bar {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--border);
  overflow: hidden;
}
.calib-bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--brand-deep), var(--brand-bright));
  transition: width var(--dur-2) var(--ease-out);
}

/* probe word card */
.calib-wordcard {
  width: 100%;
  min-height: 188px;
  margin: var(--space-3) 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-strong);
  background: linear-gradient(170deg, var(--surface-1), var(--surface-2));
  box-shadow: var(--shadow-md), var(--edge-light);
  touch-action: pan-y;
  transition:
    transform var(--dur-1) var(--ease-out),
    opacity var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out);
}
.calib-wordcard.swipe-yes {
  transform: translateX(44px);
  opacity: 0;
  border-color: var(--positive);
}
.calib-wordcard.swipe-no {
  transform: translateX(-44px);
  opacity: 0;
  border-color: var(--danger);
}
.calib-word {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-3xl);
  font-weight: 500;
  letter-spacing: var(--tracking-snug);
  text-align: center;
  word-break: break-word;
  padding: 0 var(--space-3);
}
/* A full probe SENTENCE is smaller + tighter-leading than a single fallback word,
   so a couple of lines fit comfortably on the card. */
.calib-word.calib-sentence {
  font-size: var(--text-xl);
  line-height: 1.4;
}
/* Play the sentence's real Azure neural audio (pre-warmed) - the primary affordance
   on the comprehension card. */
.calib-play {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--brand-ink);
  background: var(--brand);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--glow-brand);
  transition: transform var(--dur-1) var(--ease-spring);
}
.calib-play:active {
  transform: scale(0.96);
}
.calib-swipehint {
  font-size: var(--text-xs);
  color: var(--text-faint);
}
/* The honest "we'll keep refining this" line under the calibration result. */
.calib-refine {
  font-size: var(--text-sm);
  color: var(--text-dim);
  margin-top: calc(-1 * var(--space-2));
}

/* probe answer buttons */
.calib-answers {
  width: 100%;
  display: flex;
  gap: var(--space-3);
}
.calib-ans {
  flex: 1;
  padding: var(--space-4) var(--space-2);
  font-size: var(--text-md);
  font-weight: 600;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  transition:
    background-color var(--dur-1) var(--ease-soft),
    transform var(--dur-1) var(--ease-spring);
}
.calib-ans:active {
  transform: scale(0.97);
}
.calib-no {
  background: var(--danger-soft);
  border-color: rgba(255, 144, 144, 0.5);
}
.calib-no:active {
  background: rgba(255, 144, 144, 0.24);
}
.calib-yes {
  background: var(--positive-soft);
  border-color: rgba(116, 224, 168, 0.5);
}
.calib-yes:active {
  background: rgba(116, 224, 168, 0.26);
}

/* result */
.calib-result-badge {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  color: var(--positive-ink);
  background: linear-gradient(160deg, var(--positive), #4fc78a);
  box-shadow: 0 10px 34px rgba(116, 224, 168, 0.4), var(--edge-light);
  margin-bottom: var(--space-1);
}
#calib-result .btn {
  margin-top: var(--space-3);
  width: 100%;
  max-width: 280px;
}

/* ── custom content (PRD §11): learn toward what you care about ──────────── */
/* The overlay reuses .calib / .calib-panel; these are the content-specific bits.
   Panels are top-aligned (they can be long lists), unlike the centred calibration
   panels, so the textarea + lists scroll naturally on a short phone. */
.content-overlay .content-panel {
  justify-content: flex-start;
  margin: auto 0;
}
.content-x {
  position: absolute;
  top: calc(var(--space-4) + env(safe-area-inset-top));
  left: var(--space-5);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
}
#content-close {
  left: auto;
  right: var(--space-5);
}
.content-x:hover {
  color: var(--text);
}
.content-ref {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
}
.content-ref:focus {
  outline: none;
  border-color: var(--brand-bright);
}
.content-error {
  width: 100%;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
}
.content-error[hidden] {
  display: none;
}
.content-mine {
  width: 100%;
  margin-top: var(--space-3);
}
.content-mine[hidden] {
  display: none;
}
.content-item .t {
  font-weight: 500;
}
.content-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-xl);
  font-weight: 500;
  text-align: center;
  line-height: var(--leading-snug);
}
/* the coverage hero: a big "% you understand" figure */
.content-coverage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: var(--space-2);
}
.content-cov-num {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-4xl);
  font-weight: 600;
  color: var(--positive);
  line-height: 1;
}
.content-cov-label {
  color: var(--text-dim);
  font-size: var(--text-sm);
}
.content-newhead {
  align-self: flex-start;
  color: var(--text-dim);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}
.content-words {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  width: 100%;
  max-height: 32vh;
  overflow-y: auto;
}
/* a new-word chip = amber, matching the New maturity bucket everywhere else */
.content-chip {
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--warm-soft);
  color: var(--warm-bright);
  border: 1px solid rgba(255, 206, 134, 0.3);
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-sm);
}
.content-empty {
  color: var(--text-dim);
  font-size: var(--text-sm);
}
/* the lesson plan: ordered warm-ups + the content, each with a readiness chip */
.content-parts {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.content-part {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
}
.content-part-label {
  font-size: var(--text-base);
}
.content-part-status {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  color: var(--text-dim);
  background: var(--surface-2);
}
.content-part-status.s-ready {
  color: var(--positive);
  background: var(--positive-soft);
}
.content-part-status.s-failed {
  color: var(--danger);
  background: var(--danger-soft);
}
.content-panel .btn-primary {
  width: 100%;
  max-width: 320px;
  margin-top: var(--space-3);
}

/* ── onboarding (first run): welcome -> language -> background -> paywall ──── */
/* Reuses the .calib overlay + .calib-panel primitives; these are the onboarding-
   specific bits. Panels are centred like calibration, but can hold a list, so the
   overlay scrolls on a short viewport (inherited from .calib). */
.onb {
  z-index: var(--z-onb);
}
.onb-panel {
  position: relative;
}
.onb-panel .btn-primary {
  width: 100%;
  max-width: 320px;
  margin-top: var(--space-2);
}
.onb-panel .btn-ghost {
  width: 100%;
  max-width: 320px;
}
/* welcome feature points */
.onb-points {
  list-style: none;
  margin: var(--space-2) 0;
  padding: 0;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.onb-points li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-base);
  color: var(--text-dim);
}
.onb-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 12px var(--brand-glow);
}
/* background: a wrap of selectable language chips */
.onb-chips {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.onb-chip {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--text-base);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-soft),
    background-color var(--dur-1) var(--ease-soft),
    transform var(--dur-1) var(--ease-spring);
}
.onb-chip:active {
  transform: scale(0.97);
}
.onb-chip.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-bright);
}
/* the "you already know ~N words" transfer affordance (amber = head start) */
.onb-transfer {
  width: 100%;
  max-width: 360px;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--warm-bright);
  background: var(--warm-soft);
  border: 1px solid rgba(255, 206, 134, 0.3);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.onb-transfer[hidden] {
  display: none;
}
.onb-transfer strong {
  color: var(--warm);
  font-weight: 600;
}
/* paywall placeholder card */
.onb-pw-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: linear-gradient(170deg, var(--surface-1), var(--surface-2));
  box-shadow: var(--shadow-md), var(--edge-light);
  text-align: center;
}
.onb-pw-head {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--brand-bright);
}
.onb-pw-body {
  font-size: var(--text-sm);
  color: var(--text-dim);
}
.onb-pw-note {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--positive);
}

/* ── auth (signup / login), the front door ───────────────────────────────────
   Reuses the .calib overlay + .calib-panel primitives; sits above everything
   (onboarding/calibration) so an unauthenticated visitor always lands here. */
.auth {
  z-index: var(--z-auth);
}
.auth-panel {
  position: relative;
}
.auth-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: left;
}
.auth-flabel {
  font-size: var(--text-sm);
  color: var(--text-dim);
}
.auth-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-base);
  transition:
    border-color var(--dur-1) var(--ease-soft),
    box-shadow var(--dur-1) var(--ease-soft);
}
.auth-input::placeholder {
  color: var(--text-faint);
}
.auth-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.auth-form .btn-primary {
  width: 100%;
  margin-top: var(--space-1);
}
.auth-error {
  font-size: var(--text-sm);
  color: var(--danger);
  text-align: center;
}
.auth-error[hidden] {
  display: none;
}
.auth-note {
  font-size: var(--text-sm);
  color: var(--positive);
  text-align: center;
}
.auth-note[hidden] {
  display: none;
}
.auth-toggle {
  margin-top: var(--space-3);
  background: none;
  border: none;
  color: var(--brand-bright);
  font-family: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  padding: var(--space-2);
}
.auth-toggle:hover {
  text-decoration: underline;
}
.auth-toggle:disabled {
  opacity: 0.5;
  cursor: default;
}
.auth-forgot {
  margin-top: var(--space-1);
}
/* The author display:flex on .auth-field beats the UA [hidden] rule, so the
   per-mode field hiding (forgot = email-only, recovery = password-only) needs an
   explicit hide. The toggle/forgot/back buttons have no author display, but hide
   them explicitly too for clarity. */
.auth-field[hidden],
.auth-toggle[hidden] {
  display: none;
}

/* the account row at the bottom of Progress: email + sign out */
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.account-row[hidden] {
  display: none;
}
.account-email {
  font-size: var(--text-sm);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.account-row .btn-ghost {
  flex: 0 0 auto;
}

/* ── reduced motion: honour the OS preference (premium + accessible) ──────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .orb,
  .orb::after {
    animation: none;
  }
}
