/* ===========================================================================
   Soltura — design system
   A clean, modern, friendly messaging UI in the Soltura brand palette (navy +
   lavender on warm cream; flat fills, no gradients — the same tokens as the
   public pages, e.g. /book's in src/server/book.ts). Everything is driven by
   CSS custom properties so the dark theme is a single block of overrides at
   the bottom.
   =========================================================================== */

:root {
  /* Surfaces & ink — warm cream ground + navy ink, from the Soltura brand
     palette. */
  --bg: #f6f1e6;
  --bg-grad-1: #fdfbf5;
  --bg-grad-2: #f6f1e6;
  --surface: #ffffff;
  --surface-2: #f7f3ea;
  --surface-3: #ede7d8;
  --ink: #222c74;
  --ink-soft: #46509a;
  --muted: #6d6890;
  --border: #e9e2d2;
  --border-strong: #d6ccb6;

  /* Brand — Soltura navy + lavender. Flat fills, no gradients.
     --accent-strong is the deep navy fill (CTAs, user bubbles, avatar);
     --accent is the violet interactive accent; --accent-ink is the text
     color on an --accent fill (white here, navy on the dark scheme's
     lavender accent). */
  --accent: #7b5fd8;
  --accent-2: #5f45c0;
  --accent-strong: #232e7b;
  --accent-soft: #efe9fc;
  --on-accent: #ffffff;
  --accent-ink: #ffffff;

  /* Bubbles */
  --bubble-bot: #f4efe3;
  --bubble-bot-ink: #222c74;
  --bubble-user: var(--accent-strong);
  --bubble-user-ink: #ffffff;

  /* Semantic */
  --good: #2f9e57;
  --good-soft: #e7f6ec;
  --bad: #df4f3a;
  --bad-soft: #fdebe8;
  --gold: #e0a93a;
  --gold-soft: #fff3d4;
  /* A tutor's work copy (work-copy.ts): its frame and tag, apart from every other colour. */
  --work-copy: #d9480f;
  --work-copy-ink: #ffffff;

  /* Shape & motion */
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(35, 46, 123, 0.06), 0 1px 3px rgba(35, 46, 123, 0.04);
  --shadow-md: 0 4px 12px rgba(35, 46, 123, 0.08), 0 2px 4px rgba(35, 46, 123, 0.05);
  --shadow-lg: 0 12px 32px rgba(35, 46, 123, 0.14), 0 4px 10px rgba(35, 46, 123, 0.07);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  font-size: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Brand-lavender text selection; works over both schemes' grounds. */
::selection { background: rgba(183, 165, 240, 0.5); }

/* Give the UA's default focus ring the brand accent (Chromium honors
   outline-color on its auto outline); bespoke :focus-visible rules below
   still win where they exist. */
:focus-visible { outline-color: var(--accent); }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 80% -10%, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Disable double-tap-to-zoom (iOS Safari ignores user-scalable=no for this).
     `manipulation` keeps panning/scrolling while dropping the zoom gesture. */
  touch-action: manipulation;
}

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

/* The `hidden` attribute must always win, even over the id/class `display`
   rules below (otherwise e.g. `#auth-screen { display: flex }` keeps the auth
   gate visible after login). See MDN's note on the hidden attribute. */
[hidden] {
  display: none !important;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.25rem;
  max-width: 1140px;
  margin: 0 auto;
  padding: 1.25rem;
  height: 100vh;
  height: 100dvh;
}

#chat-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

/* --- Brand header ---------------------------------------------------------- */

#chat-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface));
}
.billing-alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--gold);
  background: var(--gold-soft);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.35;
}
.billing-alert > span:first-child { flex: 1; }
.billing-alert button {
  flex: 0 0 auto;
  padding: 0.5rem 0.75rem;
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: var(--on-accent);
  white-space: nowrap;
}
.billing-alert-error { color: var(--bad); }
/* On Home the same alert is a card in the column, not a strip under a header. */
.home-inner .billing-alert {
  border: 1px solid var(--gold);
  border-radius: var(--radius);
}
.chat-header-meta { display: flex; flex-direction: column; line-height: 1.25; }
.chat-header-meta strong { font-size: 1.02rem; letter-spacing: -0.01em; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.76rem;
  color: var(--muted);
}
/* One line, always: "online" and "· your Spanish tutor" each hold together,
   and when the header is too narrow for both the role wraps onto a second
   row that the one-line height clips, leaving just "online". */
#status-text {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.3em;
  height: 1.25em;
  overflow: hidden;
}
#status-text > span { white-space: nowrap; }
.status-dot {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(47, 158, 87, 0.5);
  animation: pulse-dot 2.4s var(--ease) infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 87, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(47, 158, 87, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 87, 0); }
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
  user-select: none;
}
.avatar-lg { width: 3.1rem; height: 3.1rem; font-size: 1.3rem; }

/* ---------------------------------------------------------------------------
   Progress strip
   --------------------------------------------------------------------------- */

#progress-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.76rem;
  color: var(--ink-soft);
}
/* The one way out of any activity — the same pill on the chat header, the
   voice head, and the reading head: a quiet bordered pill reading "‹ Home"
   (or "‹ Library" inside a book). */
.back-btn {
  flex: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.back-btn:hover { color: var(--ink); border-color: var(--muted); }

/* The activity name on the header's right: which activity this chat is. */
.chat-activity {
  flex: none;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-2);
  white-space: nowrap;
}
.chat-activity .home-icon { width: 16px; height: 16px; }

/* TESTING ONLY: the "next day" fast-forward pill (hidden in production —
   main.ts reveals it on PR-preview and dev deployments). Dashed accent
   styling so it reads as a testing control, not product UI. */
#preview-next-day {
  flex: none;
  margin-left: auto;
  background: none;
  border: 1px dashed var(--accent);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--accent);
  cursor: pointer;
}
#preview-next-day:hover { color: var(--accent-2); border-color: var(--accent-2); }
#preview-next-day:disabled { opacity: 0.5; cursor: default; }
/* When the preview pill is visible it takes over the auto margin that pushes
   the activity name right, so the name falls back to normal spacing. */
#preview-next-day:not([hidden]) ~ .chat-activity { margin-left: 0.4rem; }

/* --- Auth screen --- */
#auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.auth-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.auth-card h1 { margin: 0; font-size: 1.25rem; }
.auth-card #auth-message { margin: 0; }
/* Clerk injects its own card chrome; let it set the width it was designed for. */
#clerk-signin { display: flex; justify-content: center; width: 100%; }

#progress-strip b { color: var(--ink); }

/* --- Daily goal banner ---
   The headline of the strip: hitting today's due goal is *the* thing the
   learner is trying to achieve, so it gets a full-width banner (title, count,
   streak, and a big progress bar) above the level banner. Clicking it opens
   the due-today popup. */
.daily-goal {
  flex: 1 1 100%;
  /* Shrinkable below its one-line text, or narrow screens clip its right edge. */
  min-width: 0;
  /* Anchor for the floating "+1" each review releases (.goal-plus). */
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease), border-color 0.12s var(--ease);
}
.daily-goal:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.daily-goal:active { transform: translateY(0); }
/* The row may wrap *between* its three pieces on narrow screens (the streak
   drops to its own line), but each piece stays on one line — never mid-phrase. */
.daily-goal-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.6rem;
  row-gap: 0.15rem;
}
.daily-goal-title {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink);
  white-space: nowrap;
}
.daily-goal-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.daily-goal-streak {
  margin-left: auto;
  white-space: nowrap;
}
.daily-goal-bar {
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}
.daily-goal-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-strong);
  transition: width 0.6s var(--ease);
}
.daily-goal--done {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.daily-goal--done .daily-goal-bar span {
  background: var(--gold);
}
/* Every review pumps the goal stat: the count pops, the fill flashes, and a
   "+1" floats up from the tip of the fill. */
.daily-goal-status.pct-tick { animation: streak-tick-pop 0.55s var(--ease); }
.daily-goal-bar.goal-bar-pulse span { animation: bar-glow 0.9s var(--ease); }
.goal-plus {
  position: absolute;
  bottom: 0.2rem;
  transform: translateX(-50%);
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-2);
  pointer-events: none;
  animation: goal-plus-float 1.1s var(--ease) forwards;
}
.daily-goal--done .goal-plus { color: #d99a1f; }
@keyframes goal-plus-float {
  0% { opacity: 0; transform: translate(-50%, 4px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -18px); }
}
@keyframes bar-glow {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.4); }
  100% { filter: brightness(1); }
}
/* ---------------------------------------------------------------------------
   Messages
   --------------------------------------------------------------------------- */

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.msg {
  max-width: 76%;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  animation: msg-in 0.26s var(--ease) both;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg .bubble {
  padding: 0.62rem 0.9rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  font-size: 1.06rem;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.bot .bubble {
  background: var(--bubble-bot);
  color: var(--bubble-bot-ink);
  border-bottom-left-radius: 6px;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-bottom-right-radius: 6px;
}

/* Every word of a bot message is a button (main.ts fillWords): a tap opens the
   word sheet. Reset so the message still reads as text — the hit area grows a
   little past the letters without moving them — and a word once tapped keeps a
   soft mark, so the learner sees what they asked about. */
.bw {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  padding: 0.04em 0.08em;
  margin: 0 -0.08em;
  border-radius: 5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.bw:active { background: var(--accent-soft); }
@media (hover: hover) {
  .bw:hover { background: var(--accent-soft); color: var(--accent-2); }
}
.bw:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.bw.is-tapped {
  color: var(--accent-2);
  background: var(--accent-soft);
  text-decoration: underline dotted;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

/* The learner's message as the bot would spell it — visible target-language
   "autocorrect" (accents, spelling, punctuation) under their bubble, with the
   words that changed highlighted. Unscoped: voice mode reuses the same line
   under the transcribed reply in its feedback panel (.voice-correction). */
.correction {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  padding: 0.1rem 0.35rem 0;
  max-width: 100%;
  word-wrap: break-word;
}
.correction-block { max-width: 100%; }
.correction-mark {
  color: var(--good);
  font-weight: 700;
  margin-right: 0.3rem;
}
/* Each highlighted fix is a button: tap it to ask why that word was corrected
   (the dotted underline is the affordance). The explanation lands in the
   .correction-explain card below the line. */
.correction-fix {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--good);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  border-radius: var(--radius-sm);
  transition: background 0.12s var(--ease);
}
.correction-fix:hover { background: var(--good-soft); }
/* A word the correction removed, left where it stood and struck through. */
.correction-removed {
  color: var(--bad);
  text-decoration: line-through;
  text-decoration-color: var(--bad);
}
.correction-fix.loading { animation: chip-pulse 1.2s ease-in-out infinite; cursor: default; }
/* How a native would put it is violet rather than the correction's green —
   another way of saying a correct sentence, not a fix. A message with both
   gets the Corrected | Native switch, which flips this one line between them;
   one with only the native version is labelled "Native:" instead. */
.natural-label {
  color: var(--accent-2);
  font-weight: 600;
}
/* The switch rides in the row with the play button and the time, at its head
   under the bubble's left edge, so the line above keeps the message's full
   width (voice mode's panel has no such row: there it sits under the line). */
.msg-foot.has-toggle { align-self: stretch; }
.msg-foot .correction-toggle { margin-right: auto; }
.correction-toggle {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}
.correction-toggle button {
  border: none;
  background: none;
  margin: 0;
  padding: 0.08rem 0.55rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.correction-toggle button + button { border-left: 1px solid var(--border); }
.correction-toggle button[aria-pressed="true"] { background: var(--good-soft); color: var(--good); }
.correction-toggle .correction-toggle-natural[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-2);
}
.correction-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (pointer: coarse) {
  .correction-toggle button { padding: 0.22rem 0.65rem; }
}
.correction.natural .correction-fix { color: var(--accent-2); }
.correction.natural .correction-fix:hover { background: var(--accent-soft); }
.natural-block .correction-explain { border-left-color: var(--accent); }
.correction-explain {
  margin-top: 0.45rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--good);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: left;
  animation: msg-in 0.2s var(--ease) both;
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.15rem;
}
.msg-time {
  font-size: 0.66rem;
  color: var(--muted);
  padding: 0 0.35rem;
  letter-spacing: 0.02em;
}

/* Per-message "play" (text-to-speech) button — mirrors .chip button. */
.play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  cursor: pointer;
  font-size: 0.62rem;
  line-height: 1;
  background: var(--surface-3);
  color: var(--ink-soft);
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.play:hover { background: var(--accent-soft); color: var(--accent-2); }
.play:active { transform: scale(0.9); }
.play.playing { background: var(--accent-soft); color: var(--accent-2); }
.play.loading { animation: chip-pulse 1.2s ease-in-out infinite; cursor: default; }
.play.error { background: var(--bad-soft); color: var(--bad); }

/* "?" affordance inset INSIDE the composer field, like a leading icon at the
   bottom-left. Starts as a round nudge button; the first tap expands it into a
   "send an automatic reply" pill (which overlays the empty field), the second
   tap sends. Absolutely positioned so the textarea text flows past it. */
.auto-reply {
  position: absolute;
  left: 0.4rem;
  bottom: 0.4rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.9rem;
  min-width: 1.9rem;
  /* Always leave a strip of the field to the right of the (expanded) pill so it
     can be tapped to dismiss / focus the input. */
  max-width: calc(100% - 3rem);
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--surface-3);
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.auto-reply:hover { background: var(--accent-soft); color: var(--accent-2); }
.auto-reply:active { transform: scale(0.95); }
/* Expanded, the pill grows to fit its call-to-action but stays left-anchored
   and content-sized — never spanning the whole field — so the rest of the
   field stays tappable: clicking it (to dismiss) or starting to type focuses
   the textarea, which collapses the pill. When the copy is too long for the
   width left (narrow screens), it wraps onto a second line and the pill grows
   upward like a popover rather than truncating. */
.auto-reply.expanded {
  height: auto;
  min-height: 1.9rem;
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  overflow: visible;
  border-radius: 0.95rem;
  padding: 0.34rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  background: var(--accent-soft);
  color: var(--accent-2);
}
.auto-reply:disabled { opacity: 0.5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.2rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 0.18rem 0.3rem 0.18rem 0.7rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.chip .word { font-weight: 600; }
.chip button {
  border: none;
  border-radius: 50%;
  width: 2.1rem;
  height: 2.1rem;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  background: var(--surface-3);
  color: var(--ink-soft);
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
}
/* Separate yes/no so a tap meant for "understood" doesn't land on "missed". */
.chip button + button { margin-left: 0.25rem; }
.chip button.grade-yes { color: var(--good); }
.chip button.grade-no { color: var(--bad); }
.chip button.grade-yes:hover { background: var(--good-soft); color: var(--good); }
.chip button.grade-no:hover { background: var(--bad-soft); color: var(--bad); }
.chip button:active { transform: scale(0.9); }
/* Buttons are removed once graded, so balance the padding to center the word. */
.chip.graded-got,
.chip.graded-missed { padding-right: 0.7rem; }
.chip.graded-got { border-color: var(--good); color: var(--good); background: var(--good-soft); }
.chip.graded-missed { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.chip.pending { animation: chip-pulse 1.2s ease-in-out infinite; }
.chip.pending .word { cursor: default; }
@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.explanation {
  margin-top: 0.45rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  line-height: 1.5;
  animation: msg-in 0.22s var(--ease) both;
}
.explanation .form-es { font-weight: 700; color: var(--accent-2); }
/* The words close in meaning (explanation.ts): a quiet list under the
   explanation, a known one marked with a small pill. */
.explanation-related {
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}
.explanation-related .related-title {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.explanation-related ul { margin: 0.15rem 0 0; padding: 0; list-style: none; }
.explanation-related li { margin-top: 0.15rem; }
.explanation-related .related-known {
  display: inline-block;
  padding: 0 0.4rem;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-2);
  vertical-align: 0.05em;
}
/* "Still confused?" under a ✗'s explanation (still-confused.ts): a quiet way
   on, on its own line at the box's end, that opens the message-help box. */
.explanation .still-confused {
  display: block;
  margin: 0.5rem 0 0 auto;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent-2);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
@media (hover: hover) {
  .explanation .still-confused:hover { border-color: var(--accent); }
}
.explanation .still-confused:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A ✗ in Talk (voice.ts chipAnswer): the chip's options under the guess's
   explanation, as a tapped word's sheet lists them; the one open is filled. */
.chip-options {
  margin-top: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.chip-options-label {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.chip-option {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent-2);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.chip-option.chosen { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }
.chip-option:disabled { opacity: 0.6; cursor: default; }
.chip-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The follow-up, inline in the explanation: the box to type it in, then the
   learner's question (their own words, like a sent message) and the answer
   under it, in the explanation's own type. */
/* The box to ask in is the chat's own composer, small: the same field and
   the same send button (#composer), so nothing about it is new to learn. */
.still-confused-ask {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  margin-top: 0.55rem;
}
.still-confused-q {
  width: fit-content;
  max-width: 85%;
  margin: 0.55rem 0 0 auto;
  padding: 0.35rem 0.65rem;
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
}
.still-confused-a {
  margin-top: 0.45rem;
  white-space: pre-wrap;
}

/* Typing indicator — animated dots in a bot bubble */
.typing {
  align-self: flex-start;
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
  padding: 0.2rem 0.1rem;
}
.typing-indicator {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  background: var(--bubble-bot);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow-sm);
  font-style: normal;
}
.typing-indicator .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.3s var(--ease) infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.36s; }
/* Right-aligned variant: shown while an automatic *learner* reply is being
   composed, so the dots sit on the learner's (right) side, in a user bubble. */
.typing.mine { align-self: flex-end; }
.typing.mine .typing-indicator {
  background: var(--bubble-user);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
}
.typing.mine .typing-indicator .dot { background: var(--bubble-user-ink); }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Ghost reply — the assistant's reply on its way: an outline of word-shaped
   pills in a bot bubble, written in word by word at the pace replies take
   (src/shared/ghost-reply.ts), with a pen at the edge. The words wrap to the
   bubble's width, so it fits any phone. */
.ghost-reply {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.35rem;
  row-gap: 0.55rem;
  width: min(16.5rem, 72vw);
  background: var(--bubble-bot);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
  animation: ghost-in 0.25s var(--ease);
}
.ghost-word {
  flex: none;
  height: 0.62rem;
  border-radius: var(--radius-pill);
  box-shadow: inset 0 0 0 1.5px var(--border-strong);
  transition: background-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.ghost-word.w {
  background: color-mix(in srgb, var(--muted) 55%, transparent);
  box-shadow: none;
}
.ghost-pen {
  flex: none;
  width: 3px;
  height: 1rem;
  margin-left: -0.15rem;
  border-radius: 2px;
  background: var(--accent);
  animation: ghost-pen 1s steps(1) infinite;
}
@keyframes ghost-in {
  from { opacity: 0; transform: translateY(4px); }
}
@keyframes ghost-pen {
  50% { opacity: 0.25; }
}
@media (prefers-reduced-motion: reduce) {
  .ghost-reply, .ghost-pen { animation: none; }
  .ghost-word { transition: none; }
}

/* ---------------------------------------------------------------------------
   App loading overlay — a clean spinner over the blurred app shell while the
   learner's state (stats, words, opening message) loads after onboarding.
   --------------------------------------------------------------------------- */
#app-loading {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(246, 241, 230, 0.55);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  animation: app-loading-in 0.2s var(--ease) both;
}
#app-loading[hidden] { display: none; }
.app-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.app-spinner {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: app-spin 0.8s linear infinite;
}
.app-loading-text {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
@keyframes app-spin {
  to { transform: rotate(360deg); }
}
@keyframes app-loading-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------------------
   Entry-mode picker — the full-screen texting / talking choice on app load.
   A fixed overlay that is a SIBLING of .layout (like #app-loading and the
   sign-up wall): it must never add transform / filter / z-index to the chat
   layout, whose stacking rules the onboarding tour depends on. Opaque token
   gradient (the same ground #voice-mode uses), so it needs no dark override
   and fully covers the not-yet-rendered shell behind it.
   --------------------------------------------------------------------------- */
#home {
  position: fixed;
  inset: 0;
  z-index: 2400; /* above chat + voice/reading (1500), below #app-loading (2500) */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  animation: app-loading-in 0.2s var(--ease) both;
}
#home[hidden] { display: none; }
.home-inner {
  max-width: 1140px;
  /* At least the screen's height, so "More" can sit at its foot. */
  min-height: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.home-bar { display: flex; align-items: center; gap: 0.8rem; }
.home-wordmark {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.home-wordmark span { color: var(--accent); font-weight: 600; font-size: 0.9rem; margin-left: 0.5rem; }
.home-menu { position: relative; margin-left: auto; }
.home-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem 0.3rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.home-menu-btn:hover { border-color: var(--accent); }
.home-avatar {
  width: 2rem;
  height: 2rem;
  font-size: 0.9rem;
  background: var(--surface-3);
  color: var(--ink);
  box-shadow: none;
}
.home-menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 1;
  min-width: 170px;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.home-menu-pop[hidden] { display: none; }
.home-menu-pop button {
  border: none;
  background: none;
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}
.home-menu-pop button:hover { background: var(--surface-2); }
/* The plate: the plan card over the tick-off bar. */
.home-plate { display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.76rem; color: var(--ink-soft); }
/* Room on the screen (main.ts fitHomePlate: the plate's height is set to it):
   today's card — or, on a done day, the bar on top — grows into it, and the
   cathedral's bar grows with it, its diorama drawn large over the title,
   the days and the sentence. */
.home-plate.is-roomy > :first-child { flex: 1 1 auto; min-height: 0; }
.home-plate.is-roomy > .day-card { display: flex; flex-direction: column; }
.home-plate.is-roomy .day-card-foot { flex: 1 1 auto; display: flex; min-height: 0; }
.home-plate.is-roomy .tickoff-bar {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: "thumb thumb thumb" "title count lock" "sub sub lock";
  align-content: stretch;
  padding: 1rem 1.1rem 1.05rem;
}
.home-plate.is-roomy .tickoff-bar-thumb { width: 100%; height: 100%; min-height: 0; margin-bottom: 0.7rem; }
.home-plate.is-roomy .tickoff-bar-thumb canvas { border-radius: 14px; box-shadow: inset 0 0 0 1px rgba(34, 44, 116, 0.06); }
/* Open, the large picture glows gold round its edge rather than jumping. */
.home-plate.is-roomy .tickoff-bar--open .tickoff-bar-thumb canvas { animation: tickoff-panel-glow 2.6s var(--ease) 0.6s infinite; }
@keyframes tickoff-panel-glow {
  0%, 60%, 100% { box-shadow: 0 0 0 0 rgba(224, 169, 58, 0); }
  72% { box-shadow: 0 0 0 3px rgba(224, 169, 58, 0.85), 0 0 18px rgba(224, 169, 58, 0.55); }
}
.home-plate.is-roomy .tickoff-bar-text b { font-size: 1.02rem; }
.home-plate.is-roomy .tickoff-bar-count { justify-self: end; align-self: end; margin-top: 0; }
.home-plate.is-roomy .tickoff-bar-check { width: 30px; height: 30px; }
/* A wide screen (main.ts homeWide): today's card down the left and the
   cathedral beside it, filling the right in every state. Home stays put, the
   plate exactly the screen's room tall (main.ts fitHomePlate): a day with more
   rows than fit scrolls its rows alone, under the card's date and title. */
@media (min-width: 1000px) {
  .home-plate.is-wide {
    display: grid;
    grid-template-columns: minmax(320px, 5fr) minmax(0, 7fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 1.25rem;
  }
  .home-plate.is-wide > .day-card { grid-column: 1; grid-row: 1; align-self: start; max-height: 100%; min-height: 0; }
  .home-plate.is-wide .day-rows {
    flex: 0 1 auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    /* Room inside the scroller for the next row's ring and shadow. */
    margin: 0 -0.6rem;
    padding: 0.3rem 0.6rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    /* Rows cut off at an edge fade out there (main.ts syncDayRowsScroll). */
    --fade-top: 0px;
    --fade-bottom: 0px;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
  }
  .home-plate.is-wide .day-card.has-above .day-rows { --fade-top: 1.75rem; }
  .home-plate.is-wide .day-card.has-below .day-rows { --fade-bottom: 3rem; }
  /* Under rows that do not all fit: how many are below, and a tap scrolls to them. */
  .day-rows-more {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0.15rem 0 0.45rem;
    padding: 0.35rem 0.85rem 0.35rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--accent);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
  }
  .day-rows-more[hidden] { display: none; }
  .day-rows-more:hover { border-color: var(--accent); }
  .day-rows-more svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
    animation: day-rows-nudge 1.8s var(--ease) infinite; }
  @keyframes day-rows-nudge { 0%, 55%, 100% { transform: none; } 75% { transform: translateY(3px); } }
  @media (prefers-reduced-motion: reduce) { .day-rows-more svg { animation: none; } }
  .home-plate.is-wide > .tickoff-bar { grid-column: 2; grid-row: 1; min-height: 0; }
}
/* Today's plan (main.ts planCardHtml), laid out as the card the tutor sends on
   WhatsApp (plan-card.ts): the date and the streak, the title over a rule, and
   a row per task — a tinted icon, a small capital label, the value — with each
   row's own progress at its right: a count and a bar under the row for texting
   and speaking, a tick for a lesson or a chapter. A row is a button that
   starts its activity, and says so quietly: a chevron at its far right and a
   press tint. Gold once everything is done; two columns of rows on a wide
   screen. */
.day-card {
  display: grid;
  padding: 0.85rem 0.95rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: 1rem;
}
.day-card-head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.6rem; }
.day-card-date { min-width: 0; font-size: 0.76rem; font-weight: 600; color: var(--muted); }
.day-card-streak { margin-left: auto; font-size: 0.78rem; color: var(--ink-soft); white-space: nowrap; }
.day-card-streak b { color: var(--ink); }
/* A row of its own under the date and the streak, for a student with rest
   days: those still free this week. */
.day-card-rest { flex-basis: 100%; text-align: right; font-size: 0.7rem; font-weight: 600; color: var(--muted); }
.day-card-title {
  margin: 0.1rem 0 0.25rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--ink);
}
.day-rows { list-style: none; margin: 0; padding: 0; display: grid; }
.day-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr) auto 0.5rem;
  grid-template-areas: "ico k end chev" "ico v end chev";
  align-items: center;
  column-gap: 0.75rem;
  width: calc(100% + 0.8rem);
  margin: 0 -0.4rem;
  padding: 0.42rem 0.4rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.day-row.has-bar { grid-template-areas: "ico k end chev" "ico v end chev" "ico bar bar chev"; }
.day-row::after {
  content: "";
  grid-area: chev;
  justify-self: end;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.12rem;
  border-top: 2px solid var(--border-strong);
  border-right: 2px solid var(--border-strong);
  transform: rotate(45deg);
}
@media (hover: hover) {
  .day-row:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
  .day-row:hover::after { border-color: var(--muted); }
}
.day-row:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }
/* The first row still to do is the one to tap now: raised like a button —
   tinted, edged in the accent, its chevron bold — with a slow ring pulsing
   out of it. Once everything is done no row is next (the cathedral's bar,
   on top, is). */
.day-row.is-next {
  margin-block: 0.25rem;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 65%, transparent), 0 3px 10px color-mix(in srgb, var(--accent) 20%, transparent);
  animation: day-next-pulse 2.4s var(--ease) infinite;
}
@media (hover: hover) { .day-row.is-next:hover { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); } }
.day-row.is-next:active { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
.day-row.is-next::after { width: 0.5rem; height: 0.5rem; border-width: 2.5px; border-color: var(--accent-strong); }
@keyframes day-next-pulse {
  0% {
    box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 65%, transparent), 0 3px 10px color-mix(in srgb, var(--accent) 20%, transparent),
      0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
  }
  70%,
  100% {
    box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 65%, transparent), 0 3px 10px color-mix(in srgb, var(--accent) 20%, transparent),
      0 0 0 8px color-mix(in srgb, var(--accent) 0%, transparent);
  }
}
@media (prefers-reduced-motion: reduce) { .day-row.is-next { animation: none; } }
.day-row-ico { grid-area: ico; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; font-size: 1.05rem; }
.day-row--text .day-row-ico { background: color-mix(in srgb, var(--accent-strong) 10%, var(--surface)); }
.day-row--talk .day-row-ico { background: var(--accent-soft); }
.day-row--lesson .day-row-ico { background: var(--good-soft); }
.day-row--reading .day-row-ico { background: var(--gold-soft); }
.day-row--listen .day-row-ico { background: color-mix(in srgb, #3a8fe0 14%, var(--surface)); }
.day-row--custom-free .day-row-ico { background: color-mix(in srgb, #d98b2b 14%, var(--surface)); }
.day-row--custom-voice-check .day-row-ico,
.day-row--custom-speaking-check .day-row-ico { background: var(--accent-soft); }
/* A catch-up of an earlier day's texting: texting's circle. */
.day-row--custom-catch-up .day-row-ico { background: color-mix(in srgb, var(--accent-strong) 10%, var(--surface)); }
/* Practice rows (shadowing, drills): their kind's icon may be a drawing. */
.day-row--shadow .day-row-ico { background: var(--accent-soft); }
.day-row--drill .day-row-ico { background: color-mix(in srgb, #e0763a 16%, var(--surface)); }
.day-row--dictate .day-row-ico { background: color-mix(in srgb, #2f8f6a 16%, var(--surface)); }
.day-row--grammar .day-row-ico { background: color-mix(in srgb, #3a6fd8 16%, var(--surface)); }
.day-row-ico img { display: block; width: 62%; height: 62%; }
.day-row-k {
  grid-area: k;
  align-self: end;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--muted);
}
.day-row-late { color: var(--bad); }
/* The mentor's focus for the row (DESIGN.md §8 "A row's focus"): a line
   under its name and over its bar, as wide as the row's text and count. */
.day-row.has-focus { grid-template-areas: "ico k end chev" "ico v end chev" "ico focus focus chev"; }
.day-row.has-bar.has-focus { grid-template-areas: "ico k end chev" "ico v end chev" "ico focus focus chev" "ico bar bar chev"; }
.day-row-focus { grid-area: focus; margin-top: 0.18rem; font-size: 0.8rem; font-weight: 600; line-height: 1.3; color: var(--accent-2); overflow-wrap: anywhere; }
.day-row-focus .row-focus-k { margin-right: 0.3rem; }
.day-row.is-done .day-row-focus { color: var(--muted); }
.day-row-v { grid-area: v; align-self: start; font-size: 0.97rem; font-weight: 650; line-height: 1.25; color: var(--ink); overflow-wrap: anywhere; }
.day-row-end { grid-area: end; justify-self: end; }
.day-row-n { font-size: 0.8rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-row-n b { font-size: 0.9rem; font-weight: 750; color: var(--ink); }
.day-row-bar { grid-area: bar; height: 0.3rem; margin-top: 0.38rem; overflow: hidden; border-radius: var(--radius-pill); background: var(--surface-3); }
.day-row-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent-strong); }
.day-check {
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
}
.day-row.is-done .day-check { border-color: var(--good); background: var(--good); }
.day-row.is-done .day-row-v { color: var(--ink-soft); }
.day-row.is-done .day-row-bar span { background: var(--good); }
.day-card.is-done { border-color: var(--gold); background: var(--gold-soft); }
.day-card.is-done .day-card-title { border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.day-card.is-done .day-row-ico { background: var(--surface); }
.day-card.is-done .day-row-v { color: var(--ink); }
.day-card.is-done .day-row-bar { background: color-mix(in srgb, var(--gold) 25%, transparent); }
.day-card.is-done .day-row-bar span { background: var(--gold); }
@media (min-width: 801px) {
  .day-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 2.25rem; }
}
/* "More": everything but today's plan, folded away until asked for — a fold
   line across the foot of the screen, its word and chevron in the middle,
   "Message Joe" floating just above it. Open, the cards follow it, with room
   under the last one for Joe. */
.home-more {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  scroll-margin-top: 1rem;
}
.home-more::before,
.home-more::after { content: ""; flex: 1; height: 1px; background: var(--border); }
/* Open, it follows today's plan, and the cards follow it. */
.home-more[aria-expanded="true"] { margin-top: 0; }
/* Room for "Message Joe" between today and the fold, however tall the screen. */
.home-plate { margin-bottom: 3.4rem; }
@media (hover: hover) {
  .home-more:hover { color: var(--ink); }
  .home-more:hover::before,
  .home-more:hover::after { background: var(--border-strong); }
}
.home-more-chev { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.2s var(--ease); }
.home-more[aria-expanded="true"] .home-more-chev { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .home-more-chev { transition: none; } }
/* What "More" unfolds: one card of rows in the plan card's own style
   (.day-row), with room under it for "Message Joe". */
.home-acts {
  margin-bottom: 4.5rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: 1rem;
}
.home-acts[hidden] { display: none; }
.home-acts li[hidden] { display: none; }
.day-row--lessons .day-row-ico { background: var(--good-soft); }
.day-row--ask .day-row-ico { background: var(--accent-soft); }
.day-row--library .day-row-ico { background: var(--gold-soft); }
.home-act-badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 650;
  white-space: nowrap;
}
.home-act-badge[hidden] { display: none; }
.home-icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
/* Message Joe: the human tutor on WhatsApp, floating at Home's bottom right
   (fixed inside #home, so it comes and goes with Home): his photo with
   WhatsApp's mark, and his name. */
.home-tutor {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  /* Above the fold line at the foot of the screen. */
  bottom: calc(max(0.6rem, env(safe-area-inset-bottom)) + 2.9rem);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 1.05rem 0.3rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
@media (hover: hover) { .home-tutor:hover { transform: translateY(-2px); } }
.home-tutor:active { transform: scale(0.97); }
.home-tutor-face { position: relative; flex: none; width: 2.5rem; height: 2.5rem; }
.home-tutor-face img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.home-tutor-wa {
  position: absolute;
  right: -0.2rem;
  bottom: -0.15rem;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0.17rem;
  border-radius: 50%;
  background: #25d366;
  color: #fff;
  box-shadow: 0 0 0 2px var(--surface);
}
@media (prefers-reduced-motion: reduce) { .home-tutor { transition: none; } }
@media (max-width: 800px) {
  .home-inner { padding: 1rem 0.9rem 0.6rem; gap: 0.8rem; }
  .home-plate { gap: 0.5rem; }
}

/* ---------------------------------------------------------------------------
   Composer
   --------------------------------------------------------------------------- */

#composer {
  display: flex;
  flex-wrap: wrap; /* lets the accent strip take a full-width row above the field */
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.8rem 0.9rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Tap-to-insert keys for target-language characters (á, ñ, ¿ …) the learner's
   keyboard may not offer. One scrollable row spanning the composer. */
#accent-strip {
  flex: 1 0 100%;
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  scrollbar-width: none;
}
#accent-strip::-webkit-scrollbar { display: none; }
#accent-strip[hidden] { display: none; }
.accent-key {
  flex: none;
  min-width: 2.1rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.1s var(--ease);
}
.accent-key:hover { border-color: var(--accent); background: var(--surface); }
.accent-key:active { transform: scale(0.92); }
/* Wraps the textarea so the auto-reply control can be inset inside the field. */
.composer-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}
#composer textarea,
.still-confused-ask textarea {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 1.05rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  font: inherit;
  font-size: 0.97rem;
  line-height: 1.4;
  background: var(--surface-2);
  color: var(--ink);
  resize: none;
  overflow-y: auto;
  max-height: 9.5rem;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
#composer textarea::placeholder,
.still-confused-ask textarea::placeholder { color: var(--muted); }
#composer textarea:focus,
.still-confused-ask textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 95, 216, 0.2);
}
/* Leave room on the left for the inset auto-reply control. The #composer id
   selector on the base rule outweighs a bare class, so scope this with the id. */
#composer .composer-field textarea { padding-left: 2.7rem; }

/* A link can be the primary action too (the subscribe wall's "Take the entry
   test"): the same pill, without the link underline. */
button.primary,
a.primary {
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), opacity 0.15s var(--ease), filter 0.15s var(--ease);
}
a.primary { display: inline-block; text-align: center; text-decoration: none; }
button.primary:hover,
a.primary:hover { filter: brightness(1.04); box-shadow: var(--shadow-md); }
button.primary:active,
a.primary:active { transform: scale(0.97); }
button.primary:disabled { opacity: 0.5; cursor: default; filter: none; box-shadow: none; }

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.85rem;
  height: 2.85rem;
  padding: 0;
  border-radius: 50%;
}
.send-btn svg { display: block; transform: translateX(-3px); }

/* ---------------------------------------------------------------------------
   Side pane — production items you're trying to use
   --------------------------------------------------------------------------- */

#side-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
#side-pane h2 {
  margin: 0 0 0.2rem;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.prod-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  margin-top: 0.65rem;
  font-size: 0.9rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.prod-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.prod-card .form-es { font-weight: 700; font-size: 0.98rem; }
/* Target-language sense cue after the form — "banco (para sentarse)" —
   quieter than the form itself, never a translation. */
.prod-card .prod-cue { font-size: 0.82rem; color: var(--muted); margin-left: 0.25rem; }
/* A recall card says which language to answer in ("In Spanish:") before the
   translation it shows; a grammar card names the item under its rule. */
.prod-stage { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-right: 0.15rem; }
.prod-name { font-size: 0.86rem; color: var(--ink-soft); margin: 0.2rem 0; }
/* A verb form's use card says what its forms mean after them: "diría, dirías… = would tell". */
.prod-means { font-weight: 400; font-size: 0.86rem; color: var(--ink-soft); white-space: nowrap; }

/* Title acts as the expand/collapse toggle but reads as plain inline text. */
.prod-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.prod-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Compact type hint shown only on the mobile pills. */
.prod-toggle::before {
  content: "";
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  align-self: center;
  background: var(--accent-2);
}
.prod-toggle[data-kind="phrase"]::before { background: var(--accent); }
.prod-toggle[data-kind="grammar"]::before { background: var(--good); }

/* Hidden in the mobile pill: a tap moves the body into the pop-out bubble. */
.prod-card .prod-body { display: none; }

/* Desktop sidebar has room — keep today's always-open behavior. */
@media (min-width: 801px) {
  .prod-card .prod-body { display: block; }
  .prod-toggle { cursor: default; flex-wrap: wrap; row-gap: 0.1rem; }
  .prod-toggle::before { display: none; }
  /* The cue is a whole scenario sentence: its own line under the term, not a
     column beside it that squeezes the term to one word per line. */
  .prod-card .prod-cue { flex-basis: 100%; margin-left: 0; line-height: 1.35; }
}
.prod-card .example { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.4; }
/* A verb form's sentence, the words its forms say in bold, as a recall word's. */
.prod-card .example b,
.prod-bubble .example b,
.voice-prod-card .example b { color: var(--ink); font-weight: 650; }
/* A recall word's sentence, in the hint's place: a sentence on its own line,
   its translation in bold. */
.prod-sentence { font-style: italic; }
.prod-sentence b { color: var(--ink); font-weight: 650; }
.prod-card .prod-cue.prod-sentence { flex-basis: 100%; margin-left: 0; }
/* A grammar card's "Try:" line: what kind of sentence to write to use it. */
.prod-card .how-to-use { font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.3rem; line-height: 1.4; }
.prod-card .how-to-use b { color: var(--accent-2); font-weight: 600; }
.prod-card .kind {
  display: inline-block;
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--accent-2);
  background: var(--accent-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.12rem 0.45rem;
  border-radius: var(--radius-pill);
  margin-bottom: 0.4rem;
}
.prod-card .reveal {
  display: block;
  margin-top: 0.55rem;
  font: inherit;
  font-size: 0.78rem;
  background: none;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.32rem 0.6rem;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.prod-card .reveal:hover { color: var(--accent-2); border-color: var(--accent); background: var(--accent-soft); }
.prod-card .revealed { margin-top: 0.5rem; font-style: italic; }
.prod-card .revealed:empty { display: none; }

/* "Show word" shows a recall card's word for a few seconds
   (prod-card.ts showWordBriefly): a bar under it runs down the time. */
.shown-timer {
  height: 3px;
  margin-top: 0.4rem;
  border-radius: var(--radius-pill);
  background: var(--border);
  overflow: hidden;
}
.shown-timer > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  animation-name: shown-timer;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes shown-timer {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}
@media (prefers-reduced-motion: reduce) { .shown-timer > span { animation: none; } }

/* A recall card's note (prod-card.ts noteHtml): what the word means beyond
   the card's translation, under the word "show the word" shows and on the
   tick of a correct use. Upright, so its target-language words, in italics,
   stand out from it. */
.card-note {
  margin: 0.35rem 0 0;
  font-style: normal;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.card-note i { font-style: italic; color: var(--ink); }
.suggestion .card-note {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

/* A word's small words (small-words.ts, DESIGN.md §1 "Small words"): the
   small word highlighted in the target language, underlined in the first
   language, what follows muted; then a strip of the right ones (✓) and the
   common traps (✗). The same on the cards and the panels. */
mark.sw {
  padding: 0 0.18em;
  border-radius: 0.28em;
  background: #ffd75e;
  color: #3a2a00;
  box-shadow: inset 0 -0.12em 0 #e7b52a;
  font-weight: 800;
}
mark.sw-en {
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: #e7b52a;
  text-decoration-thickness: 0.16em;
  text-underline-offset: 0.18em;
}
.sw-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem; margin: 0.35rem 0 0; padding: 0; list-style: none; font-style: normal; }
.sw-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25em;
  padding: 0.1em 0.6em;
  border: 1px solid;
  border-radius: 0.9em;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.45;
}
.sw-chip.is-ok { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.sw-chip.is-no { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.sw-chip small { font-size: 0.84em; font-weight: 500; opacity: 0.85; }
.sw-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.explanation .sw-strip { justify-content: flex-start; }

.suggestion {
  border: 1px solid var(--border);
  border-left: 3px solid var(--good);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  margin-top: 0.65rem;
  font-size: 0.86rem;
  line-height: 1.5;
  background: var(--good-soft);
  box-shadow: var(--shadow-sm);
  animation: msg-in 0.24s var(--ease) both;
}
#suggestions:not(:empty) { cursor: pointer; }
.suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.65rem;
  padding: 0.2rem 0.1rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  user-select: none;
}
.suggestions-header:focus-visible { outline: 2px solid var(--good); outline-offset: 2px; border-radius: var(--radius-sm); }
.suggestions-chevron {
  width: 0.5rem;
  height: 0.5rem;
  margin: 0 0.15rem 0.2rem 0;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s var(--ease);
}
#suggestions.collapsed .suggestions-chevron { transform: rotate(225deg); }
#suggestions.collapsed .suggestion { display: none; }
.suggestion.incorrect { border-left-color: var(--bad); background: var(--bad-soft); }
/* A near miss (near-miss.ts, DESIGN.md §5.2): not counted, but nothing was
   wrong — amber, not red. */
.suggestion.near { border-left-color: var(--gold); background: var(--gold-soft); }
.suggestion.near .near-title { font-weight: 700; }
.suggestion.near .near-why { margin-top: 0.2rem; }
.suggestion .confirm { display: flex; gap: 0.45rem; margin-top: 0.55rem; }
.suggestion button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.suggestion button:hover { background: var(--surface-2); border-color: var(--muted); }
.suggestion button:active { transform: scale(0.97); }

/* ---------------------------------------------------------------------------
   Placement modal
   --------------------------------------------------------------------------- */

dialog#placement-modal,
dialog#settings-modal,
dialog#due-modal,
dialog#install-modal,
dialog#word-sheet {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
dialog#placement-modal[open],
dialog#settings-modal[open],
dialog#due-modal[open],
dialog#install-modal[open],
dialog#word-sheet[open] { animation: modal-in 0.25s var(--ease) both; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
dialog::backdrop { background: rgba(17, 20, 56, 0.5); backdrop-filter: blur(3px); }
/* The placement quiz is a gate, not a dialog over the app: the chat shell is
   hidden beneath it (main.ts enterApp) and it cannot be dismissed, so it sits
   on its own opaque ground — the page background, not a blurred chat. Literal
   colours (the body gradient's --bg-grad-1/-2), since ::backdrop does not
   inherit custom properties in every browser. */
dialog#placement-modal::backdrop {
  background: radial-gradient(1200px 800px at 80% -10%, #fdfbf5, #f6f1e6);
  backdrop-filter: none;
}
.modal-head { display: flex; gap: 0.85rem; align-items: flex-start; }
.modal-head h2 { margin: 0 0 0.2rem; font-size: 1.2rem; letter-spacing: -0.01em; }
.modal-head #placement-intro { margin: 0; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.5; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.modal-foot #placement-round { margin: 0; }

#placement-screening { margin: 1.1rem 0 0.2rem; }
#placement-screening .placement-question { margin: 0 0 0.9rem; font-size: 1.05rem; font-weight: 600; }
.screening-options { display: flex; flex-direction: column; gap: 0.5rem; }
.screening-options button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease), transform 0.1s var(--ease);
}
.screening-options button:hover { border-color: var(--muted); }
.screening-options button:active { transform: scale(0.98); }

#placement-probes { display: flex; flex-direction: column; gap: 0.55rem; margin: 1.1rem 0; }
.probe {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.probe .word { font-size: 1.05rem; font-weight: 600; }
.probe .word .example { display: block; font-size: 0.8rem; font-weight: 400; color: var(--muted); margin-top: 0.15rem; }
/* Sense cue on a secondary-sense probe — inline after the word, quieter. */
.probe .word .probe-cue { font-size: 0.85rem; font-weight: 400; color: var(--muted); }
/* Four graded levels stacked as a confidence ladder (green → grey). The long
   labels don't fit inline next to the word, so each is a full-width row. */
.probe .options { display: flex; flex-direction: column; gap: 0.35rem; }
.probe button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.7rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease), transform 0.1s var(--ease);
}
.probe button:hover { border-color: var(--muted); }
.probe button:active { transform: scale(0.99); }
.probe button.selected-use { background: var(--good); color: #fff; border-color: var(--good); }
.probe button.selected-understand { background: #2f8f9e; color: #fff; border-color: #2f8f9e; }
.probe button.selected-recognise { background: #d98a2b; color: #fff; border-color: #d98a2b; }
.probe button.selected-none { background: var(--muted); color: #fff; border-color: var(--muted); }

/* One probe per screen: the item gets a little more room and a larger word. */
.probe.placement-single { padding: 1rem 0.9rem; gap: 0.7rem; }
.probe.placement-single .word { font-size: 1.3rem; }
/* One meaning of a word with several, asked as the word is used in a
   sentence: a quiet lead, then the sentence set off by a rule, the word's
   form in it marked. */
.probe .word .placement-usage-lead { display: block; margin-top: 0.35rem; font-size: 0.85rem; font-weight: 400; }
.probe .word .placement-usage {
  display: block;
  margin-top: 0.3rem;
  padding: 0.1rem 0 0.1rem 0.7rem;
  border-left: 3px solid var(--accent);
  font-size: 1.08rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.probe .word .placement-usage mark {
  background: transparent;
  color: inherit;
  font-weight: 700;
  box-shadow: inset 0 -0.38em 0 color-mix(in srgb, var(--accent) 22%, transparent);
}
/* The multiple-choice placement (DESIGN.md §7): a progress bar, what the
   question asks, the word or sentence large, then the options as full-width
   rows and "I don't know" set apart below them, quieter. One tap answers. */
.placement-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
}
.placement-progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s var(--ease);
}
.probe.placement-question-card { padding: 1rem 0.9rem; gap: 0.6rem; }
.placement-ask { margin: 0; font-size: 0.85rem; }
.placement-prompt { margin: 0 0 0.2rem; font-size: 1.35rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
/* Sentences read better a little smaller than a single word. */
.kind-form .placement-prompt,
.kind-meaning .placement-prompt { font-size: 1.12rem; }
.placement-gap {
  display: inline-block;
  min-width: 2.6em;
  border-bottom: 2px solid var(--accent);
  margin: 0 0.15em;
}
.placement-cue { font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.placement-options { display: flex; flex-direction: column; gap: 0.4rem; }
.probe .placement-option { padding: 0.6rem 0.8rem; line-height: 1.35; }
.probe .placement-dont-know {
  margin-top: 0.3rem;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  text-align: center;
}
.probe .placement-option:disabled,
.probe .placement-dont-know:disabled { opacity: 0.6; cursor: default; }
/* The diagnostic design: the typed gap and its Next button on one row, the
   verdict on a judged guess above the next question (no screen of its own),
   and the grammar check's reading on the recap. */
.placement-gap-row { display: flex; gap: 0.5rem; }
.placement-gap-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.1rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.placement-gap-input:focus { outline: none; border-color: var(--accent); }
.placement-gap-row button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font: inherit;
  cursor: pointer;
}
.placement-gap-row button:disabled { opacity: 0.6; cursor: default; }
/* The writing stage: the recall card's meaning large, its sentence (the
   meaning marked) and what separates the word under it. */
.placement-recall-prompt { margin: 0; font-size: 1.35rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.placement-recall-example { margin: 0; font-size: 1rem; line-height: 1.4; color: var(--ink-soft); }
.placement-recall-example strong { color: var(--ink); }
.placement-recall-hint { margin: 0; font-size: 0.92rem; }
.placement-recall-pointer { margin: 0; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.placement-verdict { margin: 0; font-size: 0.9rem; padding: 0.45rem 0.7rem; border-radius: var(--radius-sm); background: var(--surface-2); }
.placement-verdict.correct strong { color: var(--good); }
.placement-verdict.incorrect strong { color: var(--bad); }
/* The voice stages (voice-placement.ts), the test's last two: the sentence's
   play button and the speaking question's record button sit in the question
   card like its other controls. A sentence plays once: its button then reads
   "Played", greyed. No verdict is shown on any answer. */
.probe .placement-play,
.probe .placement-rec { align-self: flex-start; padding: 0.55rem 1rem; font-weight: 650; color: var(--accent); border-color: var(--accent); }
.probe .placement-play:disabled { opacity: 0.6; cursor: default; }
.probe .placement-play.is-played { color: var(--muted); border-color: var(--border); }
.probe .placement-rec.is-on { background: var(--bad); border-color: var(--bad); color: #fff; }
.probe .placement-rec:disabled { opacity: 0.6; cursor: default; }
.placement-rec-note { margin: 0; min-height: 1.2em; font-size: 0.85rem; }
/* The speaking question's aim (2026-11-23: a student read the question out,
   and spoke too little to be scored): under Record, a bar filling toward it
   while recording (green once reached) above the note's one line. */
.placement-aim-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.placement-aim-bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear; }
.placement-aim-bar.is-reached > span { background: var(--good); }
.placement-speak .placement-rec-note { color: var(--ink-soft); line-height: 1.4; }
.probe .placement-send-anyway { align-self: flex-start; }
.placement-speak .placement-rec-note:empty { display: none; }
/* What to try to do in the answer, under Record. */
.placement-tips { margin: 0.25rem 0 0; padding-left: 1.2rem; font-size: 0.92rem; line-height: 1.45; color: var(--ink-soft); }
.placement-tips li + li { margin-top: 0.15rem; }
/* The listening stage's real clips: a player above the question (play, where
   it is, a thin track; on the sheet also pause, back five seconds and a track
   to move along), each question in the clip's language only. */
.probe.placement-clip-player { padding: 0.7rem 0.9rem; gap: 0.5rem; }
.placement-clip-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.probe .placement-clip-back { padding: 0.55rem 0.8rem; font-variant-numeric: tabular-nums; }
.placement-clip-time { margin-left: auto; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.placement-clip-track { margin: 0; }
.placement-clip-track span { transition: width 0.25s linear; }
.placement-clip-seek { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }
.placement-clip-q { margin: 0; font-size: 1.1rem; font-weight: 600; line-height: 1.35; }
/* A clip's sheet: the time left and the player stay at the top of the test's
   window while its questions scroll under them, every question in view as
   the learner scrolls. The dialog's padding is the bar's own, so nothing
   shows above it. */
.placement-sheet-bar {
  position: sticky;
  top: -1.5rem;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: -0.4rem -1.5rem 0;
  padding: 0.6rem 1.5rem 0.55rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.placement-sheet-clock { margin: 0; font-size: 0.95rem; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.placement-sheet-clock.is-low { color: var(--bad); }
.placement-sheet { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.55rem; }
.placement-sheet-n { color: var(--muted); font-weight: 600; }
.placement-sheet-answer { width: 100%; min-height: 3.2rem; resize: vertical; font: inherit; line-height: 1.4; }
.placement-sheet-send { align-self: flex-end; }
/* Busy placeholder shown between rounds while answers are submitted/judged. */
.probe.placement-busy {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.6rem 0.7rem;
  color: var(--muted);
}
.probe.placement-busy::before {
  content: '';
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
/* Right/wrong feedback after a "recognise" guess is judged. */
.probe.placement-feedback {
  align-items: center;
  text-align: center;
  gap: 0.8rem;
  padding: 1.5rem 0.9rem;
}
.probe.placement-feedback .feedback-verdict { margin: 0; font-size: 1.25rem; font-weight: 700; }
.probe.placement-feedback.correct .feedback-verdict { color: var(--good); }
/* Semantic red, not the brand accent: with the accent now violet, a violet
   "not quite" would no longer read as a wrong answer. */
.probe.placement-feedback.incorrect .feedback-verdict { color: var(--bad); }
.probe.placement-feedback .feedback-meaning { margin: 0; font-size: 0.95rem; }

/* Floor-reached pause: "we've got a solid read — keep going or move on?" shown
   once a stage meets its answer floor, before the skip control is offered. */
.probe.placement-pause { align-items: center; text-align: center; gap: 1rem; padding: 1.4rem 0.9rem; }
.probe.placement-pause .placement-pause-prompt { margin: 0; font-size: 1.05rem; line-height: 1.45; }
.probe.placement-pause .placement-pause-actions { display: flex; gap: 0.6rem; width: 100%; }
.probe.placement-pause .placement-pause-actions button { flex: 1; padding: 0.7rem 0.6rem; }

#placement-submit.busy { cursor: default; opacity: 0.85; }
#placement-submit.busy::before {
  content: '';
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5em;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skip-the-rest control on later placement rounds: a quiet text button that
   sits between the round label and the primary Continue button. */
button.ghost {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.14s var(--ease), background 0.14s var(--ease);
}
button.ghost:hover { color: var(--ink); background: var(--surface-2); }
button.ghost:disabled { opacity: 0.5; cursor: default; }
#placement-skip { margin-left: auto; }
#placement-skip.busy { opacity: 0.7; cursor: default; }

/* The end of the test: thanks, and that the results went to the mentor. The
   shared modal head is hidden for this view, so the title is the top element.
   No level is shown here. */
#placement-results { margin: 0.6rem 0 0.2rem; text-align: center; }
.placement-thanks-title {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent);
}
.placement-thanks-body { margin: 0 0 1.2rem; font-size: 1rem; line-height: 1.5; color: var(--ink-soft); }
#placement-results .modal-foot { justify-content: center; gap: 0.6rem; }
.probe .guess-input {
  flex-basis: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  font: inherit;
}
.probe .guess-input:focus { outline: none; border-color: var(--accent); }

/* ---------------------------------------------------------------------------
   Settings modal / danger zone
   --------------------------------------------------------------------------- */

#settings-modal .modal-head h2 { margin: 0 0 0.2rem; font-size: 1.2rem; letter-spacing: -0.01em; }
#settings-modal #settings-account { margin: 0; }

.modal-close {
  margin-left: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease), transform 0.1s var(--ease);
}
.modal-close:hover { border-color: var(--muted); color: var(--ink); }
.modal-close:active { transform: scale(0.95); }

/* "Install app" on an iPhone or iPad (#install-modal, pwa.ts): three steps,
   each with a small picture of the bit of iOS to tap, the target ringed in
   lavender. The pictures keep iOS's own light greys and blue, in both themes,
   since they show the phone's screen rather than ours. */
dialog#install-modal { max-width: 440px; padding: 1.4rem 1.25rem 1.25rem; }
#install-modal .modal-head { align-items: center; }
.install-icon { width: 52px; height: 52px; flex: none; border-radius: 12px; border: 1px solid var(--border); }
#install-modal .modal-head h2 { margin: 0 0 0.15rem; font-size: 1.2rem; letter-spacing: -0.01em; }
.install-sub { margin: 0; font-size: 0.88rem; line-height: 1.4; color: var(--ink-soft); }
.install-steps { list-style: none; margin: 1.2rem 0 0; padding: 0; display: grid; gap: 1.05rem; }
.install-steps li { display: grid; grid-template-columns: 1.85rem minmax(0, 1fr); gap: 0.7rem; align-items: start; }
.install-n {
  width: 1.85rem; height: 1.85rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.9rem;
}
.install-steps p { margin: 0.2rem 0 0.5rem; font-size: 0.95rem; line-height: 1.42; }
.install-steps p b, .install-tip b { font-weight: 700; color: var(--ink); }
.install-pic {
  display: flex; align-items: center; gap: 0.55rem; height: 46px; padding: 0 0.45rem 0 0.8rem;
  border-radius: 14px; background: #f2f2f7; color: #1f1f1f;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif; font-size: 0.9rem;
}
.install-pic[hidden] { display: none; }
.install-pic svg { width: 20px; height: 20px; flex: none; }
.install-pic--bar { border-radius: 23px; background: #eef0f4; }
.install-url { flex: 1; min-width: 0; text-align: center; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.install-lead { display: inline-flex; color: #5f6368; }
.install-hit {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; color: #1f1f1f; font-weight: 700; letter-spacing: 0.05em;
  border: 2px solid var(--accent); box-shadow: 0 0 0 4px rgba(123, 95, 216, 0.22);
}
.install-pic--row {
  justify-content: space-between; padding: 0 0.9rem; background: #fff; font-size: 0.95rem;
  border: 2px solid var(--accent); box-shadow: 0 0 0 4px rgba(123, 95, 216, 0.22);
}
.install-pic--row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.install-pic--nav { justify-content: space-between; padding: 0 0.35rem 0 0.8rem; }
.install-ios { flex: none; color: #0a7aff; font-size: 0.85rem; }
.install-hit--text { width: auto; height: 34px; padding: 0 0.7rem; border-radius: 17px; color: #0a7aff; font-weight: 600; letter-spacing: 0; }
.install-pic--toolbar { justify-content: space-around; padding: 0 0.5rem; color: #0a7aff; }
.install-pic--toolbar .install-hit { color: #0a7aff; }
.install-tip {
  margin: 1.1rem 0 0; padding: 0.6rem 0.75rem; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--ink-soft); font-size: 0.86rem; line-height: 1.4;
}
.install-after { margin: 0.8rem 0 0; font-size: 0.86rem; line-height: 1.45; color: var(--ink-soft); }
.install-actions { display: flex; margin-top: 1.1rem; }
.install-actions button { flex: 1; }

.settings-section {
  margin-top: 1.1rem;
  padding: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.settings-section h3 { margin: 0 0 0.4rem; font-size: 1rem; letter-spacing: -0.01em; }
.settings-plan-link {
  display: inline;
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}
.settings-plan-link:hover { color: var(--ink); }
.settings-plan-link:disabled {
  color: var(--ink-soft);
  text-decoration: none;
  cursor: default;
}

/* ---------------------------------------------------------------------------
   Due-today popup
   --------------------------------------------------------------------------- */

#due-modal .modal-head h2 { margin: 0 0 0.2rem; font-size: 1.2rem; letter-spacing: -0.01em; }
#due-modal #due-summary { margin: 0; }
.due-explain {
  margin: 0.9rem 0 0.4rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  line-height: 1.5;
}
#due-list {
  margin-top: 0.6rem;
  max-height: min(55vh, 26rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.due-section {
  margin: 0.7rem 0 0.2rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.due-section:first-child { margin-top: 0; }
.due-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.due-row-main { min-width: 0; }
.due-text { font-weight: 600; }
/* Sense cue on a due row — quieter than the form, never a translation. */
.due-cue { font-weight: 400; font-size: 0.85em; color: var(--muted); }
.due-gloss {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.due-tags { display: flex; align-items: center; gap: 0.35rem; flex: none; }
.due-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  white-space: nowrap;
}
.due-tag--skill { background: var(--surface-3); }
.due-check { color: var(--good); font-weight: 700; }
.due-row--done {
  background: var(--surface);
  opacity: 0.72;
}
.due-row--done .due-text { text-decoration: line-through; text-decoration-color: var(--muted); }
.due-empty {
  margin: 0.6rem 0 0.2rem;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------------------------------------------------------------------------
   The word sheet (word-sheet.ts): a tap on a word of a chat message
   --------------------------------------------------------------------------- */

/* A fixed-height flex column: the header and the ask form stay put while one
   middle region (the message, the answers, the questions) scrolls, so new
   answers land somewhere predictable and the box never drifts out of reach. */
dialog#word-sheet {
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  flex-direction: column;
  overflow: hidden;
}
/* Scope the flex layout to [open] so we don't override the UA's
   `dialog:not([open]) { display: none }` and leave the sheet always visible. */
dialog#word-sheet[open] { display: flex; }
#word-sheet .modal-head { flex: 0 0 auto; }
.ws-kicker { margin: 0 0 0.15rem; font-size: 0.85rem; }
.ws-word {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
  color: var(--accent-2);
  overflow-wrap: anywhere;
}
.ws-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Room for the scrollbar so the text doesn't sit under it. */
  margin-right: -0.5rem;
  padding-right: 0.5rem;
}
/* The message the word is in, the word marked: a reminder, so kept quiet. */
.ws-context {
  margin: 0.8rem 0 0;
  padding: 0.55rem 0.8rem;
  background: var(--bubble-bot);
  color: var(--bubble-bot-ink);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  font-size: 0.95rem;
  line-height: 1.5;
}
.ws-context mark {
  background: var(--accent-soft);
  color: var(--accent-2);
  font-weight: 700;
  border-radius: 4px;
  padding: 0 0.12em;
}
.ws-answers {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.ws-answers:not(:empty) { margin-top: 0.9rem; }
.ws-pick {
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.ws-questions { display: flex; flex-direction: column; gap: 0.5rem; }
/* An offered question: a whole sentence to tap, like a suggested reply. */
.ws-question {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.1s var(--ease);
}
.ws-question:active { transform: scale(0.99); background: var(--accent-soft); }
@media (hover: hover) {
  .ws-question:hover { border-color: var(--accent); background: var(--accent-soft); }
}
.ws-loading { margin: 0.9rem 0 0.2rem; font-size: 0.9rem; }
/* Placeholders the size of a question while they are written. */
.ws-skeleton {
  display: block;
  height: 2.6rem;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  animation: chip-pulse 1.2s ease-in-out infinite;
}
.ws-skeleton:nth-child(3) { width: 86%; }
.ws-skeleton:nth-child(4) { width: 72%; }

/* ---------------------------------------------------------------------------
   "Ask Sofía" (ask-sofia.ts): a speech bubble with a question mark floating at
   the bottom right of the practice activities (cards, the Library, Listen,
   shadowing, dictation, drills), as Home's "Message Joe" floats on Home
   (fixed inside the activity's screen, so it comes and goes with it), and the
   sheet it opens over the activity — the word sheet's frame, with the chat's
   own bubbles and composer inside. ask-sofia.ts lifts it above the bars at
   the screen's foot it would cover (data-ask-foot); under the first-run
   tour's blur, a screen's popovers and its sheets.
   --------------------------------------------------------------------------- */
.ask-btn {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 5;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--accent-2);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.1s var(--ease);
}
.ask-btn svg { width: 1.5rem; height: 1.5rem; }
@media (hover: hover) {
  .ask-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
}
.ask-btn:active { transform: scale(0.94); }
.ask-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

dialog#ask-sheet {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  flex-direction: column;
  gap: 0.85rem;
  overflow: hidden;
}
/* Flex only while open, so the UA's dialog:not([open]) keeps hiding it. */
dialog#ask-sheet[open] { display: flex; animation: modal-in 0.25s var(--ease) both; }
#ask-sheet .modal-head { flex: 0 0 auto; align-items: center; }
.ask-sheet-head { min-width: 0; }
.ask-sheet-head h2 { margin: 0; }
.ask-sheet-sub { margin: 0; font-size: 0.85rem; }
.ask-thread {
  flex: 1 1 auto;
  min-height: 3rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-right: -0.5rem;
  padding-right: 0.5rem;
}
.ask-hint { margin: 0; font-size: 0.92rem; line-height: 1.5; }
.ask-hint[hidden] { display: none; }
/* The learner's question, as their message in the chat. */
.ask-q {
  align-self: flex-end;
  max-width: 85%;
  padding: 0.5rem 0.8rem;
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* The answer, as the tutor's message. */
.ask-a {
  align-self: flex-start;
  max-width: 92%;
  padding: 0.6rem 0.85rem;
  background: var(--bubble-bot);
  color: var(--ink);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ask-a.ask-typing { padding: 0; background: none; }
.ask-a.ask-error { background: var(--bad-soft); }
#ask-sheet .ask-form { flex: 0 0 auto; margin-top: 0; }
@media (max-width: 640px) {
  /* A sheet up from the bottom, as on a phone's own apps. */
  dialog#ask-sheet {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    max-height: 85dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  }
  /* A card stops above the button (on a wider screen it floats beside the card). */
  #cards-mode .cards-deck { margin-bottom: 3.25rem; }
}
/* What scrolls under the button ends clear of it, where the column it floats
   over spans the screen (on a wide screen it floats beside the column). */
@media (max-width: 800px) {
  [data-ask] :is(.reading-body, .listen-body, .practice-body)::after {
    content: '';
    display: block;
    flex: none;
    height: 3.25rem;
  }
}

/* A tapped word's options (word-sheet.ts): one per item the word carries,
   the guess first, then the sentence as a whole and "Something else" — rows
   to tap, like offered questions. None is open: the one tapped fills the
   sheet, with a way back to the list. */
.ws-options { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.9rem; }
.ws-options .ws-skeleton:nth-child(2) { width: 86%; }
.ws-options .ws-skeleton:nth-child(3) { width: 72%; }
.ws-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.1s var(--ease);
}
.ws-option:active { transform: scale(0.99); background: var(--accent-soft); }
@media (hover: hover) {
  .ws-option:hover { border-color: var(--accent); background: var(--accent-soft); }
}
.ws-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ws-option-title { flex: 1; min-width: 0; }
.ws-option-chev { flex: 0 0 auto; color: var(--muted); }
/* The option opened: its heading, what it shows, and the way back under it. */
.ws-detail { margin-top: 0.8rem; animation: msg-in 0.2s var(--ease) both; }
.ws-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0.9rem 0 0;
  padding: 0.3rem 0.75rem 0.3rem 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent-2);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
@media (hover: hover) {
  .ws-back:hover { border-color: var(--accent); }
}
.ws-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ws-detail-title { margin: 0 0 0.5rem; font-size: 1.05rem; color: var(--accent-2); }
.ws-detail-body .explanation { margin-top: 0; font-size: 0.92rem; }
.ws-detail .ws-loading { margin-top: 0.3rem; }
/* "Something else": the box to type in; the learner's questions and the
   answers come in under it. */
.ws-ask { font-size: 0.9rem; line-height: 1.5; }
.ws-ask > .still-confused-ask:first-child { margin-top: 0; }

/* Each word of the shared tap-a-word widget (voice mode's transcript, the
   Read view) is a reset button so it can be tapped without looking like one. */
.hw-word {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.02em 0.12em;
  margin: 0 -0.02em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.hw-word:hover { background: var(--accent-soft); color: var(--accent-2); }
.hw-word.looked-up {
  color: var(--accent-2);
  background: var(--accent-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.hw-word.loading { animation: chip-pulse 1.2s ease-in-out infinite; cursor: default; }
/* A word and the punctuation glued to it never break across lines. */
.hw-nobreak { white-space: nowrap; }

.msg-help-gloss {
  margin-top: 0.9rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.5;
  animation: msg-in 0.2s var(--ease) both;
}
.msg-help-gloss .hw-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
}
.msg-help-gloss .hw-term { font-weight: 700; color: var(--accent-2); font-size: 1rem; }
.msg-help-gloss .hw-base { font-size: 0.78rem; color: var(--muted); }
.msg-help-gloss .hw-translation { margin-top: 0.3rem; }
.msg-help-gloss .hw-note { margin-top: 0.35rem; color: var(--ink-soft); font-size: 0.84rem; }

.hw-qa { display: flex; flex-direction: column; gap: 0.3rem; }
.hw-q {
  align-self: flex-end;
  max-width: 85%;
  padding: 0.4rem 0.7rem;
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
  font-size: 0.9rem;
}
.hw-a {
  align-self: flex-start;
  max-width: 92%;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-help-ask {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  margin-top: 0.9rem;
  flex: 0 0 auto;
}
.msg-help-ask textarea {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  background: var(--surface-2);
  color: var(--ink);
  resize: none;
  overflow-y: auto;
  max-height: 8rem;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
.msg-help-ask textarea::placeholder { color: var(--muted); }
.msg-help-ask textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 95, 216, 0.2);
}

/* The blocking billing wall (main.ts showSubscribeWall): a full-screen,
   non-dismissible gate shown when the signed-in account lacks entitlement. */
#upgrade-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#upgrade-modal[hidden] { display: none; }
#upgrade-modal .overlay-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 760px;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s var(--ease) both;
}
#upgrade-modal .modal-head .muted {
  margin: 0;
  color: var(--ink-soft);
}
/* The backdrop is opaque — there is no usable app behind the wall to glimpse. */
#upgrade-modal.subscribe-wall {
  background: var(--bg);
}
.wall-plan-cards { display: flex; flex-direction: column; gap: 0.7rem; margin: 1rem 0; }
.wall-plan {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.1s ease;
}
.wall-plan:hover { transform: translateY(-1px); }
.wall-plan.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.wall-plan.is-selected::after {
  content: "✓";
  position: absolute;
  top: 0.8rem;
  right: 0.9rem;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.9rem;
  font-weight: 800;
}
.wall-plan-badge {
  position: absolute;
  top: -0.6rem;
  left: 0.9rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
}
.wall-plan-name { font-weight: 800; font-size: 0.95rem; }
.wall-plan-price { font-weight: 800; font-size: 1.4rem; letter-spacing: -0.02em; }
.wall-plan-note { color: var(--muted); font-size: 0.84rem; }
.wall-error { margin: 0 0 0.7rem; color: var(--bad); font-size: 0.9rem; font-weight: 600; }
#wall-subscribe,
#wall-recovery-portal { width: 100%; }
.wall-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
}
.wall-brand img { width: 28px; height: 28px; }
#wall-message-mentor {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 1rem 0 0;
}
/* The auth screen's link in the brand ink, not the browser's blue: "paid but
   didn't finish?" (main.ts), whose small form opens in place under it. */
.auth-lost-link-open {
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.auth-lost-link-open:hover { color: var(--ink); }
.auth-lost-link { width: 100%; text-align: center; }
.auth-lost-link[hidden], .auth-lost-link-form[hidden], .auth-lost-link-status[hidden] { display: none; }
.auth-lost-link-open { padding: 0.25rem 0.5rem; background: none; border: 0; font: inherit; font-size: 0.9rem; cursor: pointer; }
.auth-lost-link-form {
  margin-top: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}
.auth-lost-link-form .muted { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--ink-soft); }
.auth-lost-link-form .welcome-field { margin-bottom: 0.75rem; font-size: 0.9rem; }
.auth-lost-link-form button.primary { width: 100%; }
.auth-lost-link-status { margin: 0.75rem 0 0; font-size: 0.9rem; color: var(--ink-soft); }
.auth-lost-link-status.is-error { color: var(--bad); }
.wall-signout {
  display: block;
  margin: 1rem auto 0;
  padding: 0.3rem 0.6rem;
  background: none;
  border: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
}
.wall-signout:hover { color: var(--ink); }
.wall-signout[hidden] { display: none; }
.wall-delete { margin-top: 0.25rem; font-size: 0.82rem; }
/* Settings opened from the wall (main.ts openSettings accountOnly): only the
   account line and Delete account are meaningful without entitlement. */
#settings-modal.account-only .settings-section { display: none; }
/* The "checkout was cancelled" acknowledgement at the top of the wall. */
.wall-notice {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 600;
}
.wall-notice[hidden] { display: none; }

/* The Checkout confirmation state (#checkout-confirming): the same
   full-screen, non-dismissible gate as the wall — Stripe has taken the money
   and we are waiting for its webhook, so there is nothing else to do here. */
#checkout-confirming {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}
#checkout-confirming[hidden] { display: none; }
.checkout-confirming-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  max-width: 460px;
  width: calc(100% - 2rem);
  text-align: center;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s var(--ease) both;
}
.checkout-confirming-card .wall-brand { justify-content: center; }
.checkout-confirming-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}
.checkout-confirming-status h2 { margin: 0; font-size: 1.25rem; }
.checkout-confirming-status p { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }
#checkout-confirming-spinner[hidden] { display: none; }
#checkout-confirming-retry { width: 100%; margin-top: 1.25rem; }

/* The welcome-call gate (#welcome-call, main.ts showWelcomeCall): the same
   full-screen, non-dismissible surface as the wall. One card, two states —
   the contact form, then the waiting copy — swapped by main.ts. */
#welcome-call {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}
#welcome-call[hidden] { display: none; }
.welcome-call-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s var(--ease) both;
}
.welcome-call-card h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.welcome-call-card .muted { margin: 0 0 1rem; color: var(--ink-soft); font-size: 0.95rem; }
.welcome-contact[hidden], .welcome-waiting[hidden] { display: none; }
.welcome-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; font-weight: 600; }
.welcome-field input {
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  width: 100%;
}
.welcome-field input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(123, 95, 216, 0.2); }
.welcome-field input:disabled { opacity: 0.5; }
.welcome-hint, .welcome-call-card .welcome-hint { font-weight: 400; font-size: 0.85rem; margin: 0; }
.welcome-check { display: flex; align-items: flex-start; gap: 0.55rem; margin: 0 0 1rem; font-size: 0.92rem; cursor: pointer; }
.welcome-check input { margin-top: 0.2rem; accent-color: var(--accent); }
#welcome-email-note { margin: -0.4rem 0 1rem; }
#welcome-submit { width: 100%; margin-top: 0.25rem; }
#welcome-edit { display: block; margin: 0.5rem auto 0; }
/* The waiting state: the level test first — its button, and "start from
   zero" under it for a complete beginner — then, under a rule, when the app
   opens and how the tutor reaches them. Hidden while GET /api/state loads,
   so its title never flashes from one state to another. */
.welcome-waiting.is-loading { visibility: hidden; }
.welcome-placement-actions { display: flex; flex-direction: column; gap: 0.6rem; margin: 0 0 1rem; }
.welcome-placement-actions[hidden] { display: none; }
.welcome-placement-actions button.primary { width: 100%; }
.welcome-beginner {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.welcome-beginner:hover { background: var(--surface-2); }
.welcome-beginner:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(123, 95, 216, 0.2); }
.welcome-beginner:disabled, .welcome-placement-actions button.primary:disabled { opacity: 0.5; cursor: default; }
.welcome-beginner[hidden] { display: none; }
#welcome-placement-error { margin: -0.4rem 0 1rem; }
#welcome-placement-error[hidden] { display: none; }
.welcome-call-card .welcome-waiting-note {
  margin: 0 0 0.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
#checkout-confirming-retry[hidden] { display: none; }

/* First-run onboarding guide (src/client/onboarding.ts). A full-screen blur
   layer de-emphasises everything irrelevant to the current step; the relevant
   element(s) are "lifted" above it (.onboarding-lift) so they stay sharp, and
   on the first step the chips throb (.onboarding-throb) to draw the eye. The
   blur layer doesn't capture pointer events, so the lifted control stays
   clickable and the learner is never trapped; only the card takes clicks.

   These z-indexes are ordered: blur (2600) < lifted elements (2650) < card
   (2700). The lift trick relies on the chat layout not creating its own
   stacking context — see the note in onboarding.ts and CLAUDE.md rule 4 before
   restructuring the chat/side-pane or restyling these components. */
.onboarding-blur {
  position: fixed;
  inset: 0;
  z-index: 2600;
  pointer-events: none;
  background: rgba(17, 20, 56, 0.3);
  backdrop-filter: blur(5px) saturate(0.9);
  -webkit-backdrop-filter: blur(5px) saturate(0.9);
  animation: onboarding-fade 0.2s var(--ease) both;
}
@keyframes onboarding-fade { from { opacity: 0; } to { opacity: 1; } }
/* Raise the focused element(s) above the blur layer so they read crisply. */
.onboarding-lift {
  position: relative;
  z-index: 2650;
}
/* Blur a part back out even though it sits inside a lifted element (a lifted
   `.msg` forms a stacking context its children can't escape — see onboarding.ts).
   Matches the full-screen blur layer so it reads as "behind the focus". */
.onboarding-blur-out {
  filter: blur(5px) saturate(0.9);
  opacity: 0.85;
  pointer-events: none;
}
/* The focused element throbs (the chips on their step, the "?" button on its).
   The transform also gives it its own stacking context, but it already sits
   inside a lifted ancestor, so it stays above the blur. */
.onboarding-throb {
  animation: onboarding-throb 1.1s var(--ease) infinite;
  transform-origin: center;
}
@keyframes onboarding-throb {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes onboarding-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(123, 95, 216, 0); filter: brightness(1); }
  50% {
    box-shadow: 0 0 0 6px rgba(123, 95, 216, 0.42), var(--shadow-md);
    filter: brightness(1.18);
  }
}
/* On the chips step every still-unanswered chip glows as a whole pill (the word
   with its ✓ / ✗ together, so each reads as one thing to act on), the same
   brand-accent pulse the "?" gets on the help step. A chip stops glowing once
   it's graded. The row also throbs (.onboarding-throb on the .chips container). */
.onboarding-throb .chip:not(.graded-got):not(.graded-missed) {
  animation: onboarding-glow 1.1s var(--ease) infinite;
}
/* A standalone glow ring used to highlight a bar/element for a step (e.g. the
   "use them in your messages" production bar on the words step), reusing the
   same brand-accent pulse. */
.onboarding-glow-el { animation: onboarding-glow 1.1s var(--ease) infinite; }
/* On the tap step the message's words show they are buttons. */
.bubble.onboarding-glow-el .bw {
  text-decoration: underline dotted;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
.onboarding-card {
  position: fixed;
  z-index: 2700;
  width: min(20rem, calc(100vw - 2rem));
  /* Never taller than the viewport, so the card always leaves room beside its
     anchor (onboarding.ts places below it on short mobile screens). */
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1rem 1.1rem;
  color: var(--ink);
  animation: modal-in 0.2s var(--ease) both;
}
.onboarding-card h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.onboarding-card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.onboarding-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.onboarding-step {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.onboarding-skip {
  border: none;
  background: none;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.onboarding-skip:hover { color: var(--ink-soft); }
.onboarding-skip[hidden] { display: none; }
.onboarding-next {
  margin-left: auto;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.danger-zone {
  margin-top: 1.1rem;
  padding: 1rem;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: var(--bad-soft);
}
.danger-zone h3 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--bad); letter-spacing: -0.01em; }
.danger-zone .muted { color: var(--ink-soft); }
.danger-zone input[type="email"] {
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}
.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.settings-actions button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  font: inherit;
  cursor: pointer;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}
.settings-actions button:hover { border-color: var(--muted); }
.settings-actions button:active { transform: scale(0.98); }
button.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
button.danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); filter: brightness(0.95); }
button.danger:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
   Celebrations: due-complete, level-up, and voice mode's speaking goal
   (src/client/celebrate.ts). The card and confetti sit above #voice-mode
   (1500) so the speaking-goal card shows over the voice overlay.
   --------------------------------------------------------------------------- */

.celebrate-confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2000;
}
.celebrate-confetti span {
  position: absolute;
  top: -12vh;
  border-radius: 2px;
  opacity: 0;
  animation-name: confetti-fall;
  animation-timing-function: cubic-bezier(0.3, 0.6, 0.5, 1);
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translate3d(0, -12vh, 0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translate3d(var(--drift, 0), 112vh, 0) rotate(var(--rot, 540deg)); opacity: 0; }
}

.celebrate-card {
  position: fixed;
  left: 50%;
  top: 24%;
  z-index: 2001;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* Fill most of the screen: 80% of the viewport, capped so a desktop card
     doesn't sprawl. */
  width: 80vw;
  max-width: 640px;
  padding: 20px 30px 18px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  cursor: pointer;
  animation: celebrate-pop-in 0.45s var(--ease) both;
}
.celebrate-card.leaving { animation: celebrate-pop-out 0.4s var(--ease) both; }
.celebrate-card .celebrate-emoji {
  font-size: 2.6rem;
  line-height: 1;
  animation: celebrate-emoji-bounce 0.9s var(--ease) 0.1s both;
}
.celebrate-title {
  font-size: 1.2rem;
  font-weight: 700;
}
.celebrate-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
/* A pill is its icon beside its text: when the text wraps (a phone), the
   icon stays on the left spanning every line rather than riding the first. */
.celebrate-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
}
/* Sized by celebrate.ts to the rows of text beside it (font-size, inline). */
.celebrate-stat-icon {
  flex: none;
  line-height: 1;
}
.celebrate-stat--streak {
  position: relative;
  background: var(--gold-soft);
  border-color: var(--gold);
}
.celebrate-stat--level {
  background: var(--accent-soft);
  border-color: var(--accent);
}
/* Completing the day opens Home's tick-off: the pill pops in as the streak ticks. */
.celebrate-stat--unlock {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  animation: celebrate-unlock-in 0.55s var(--ease) 1.1s backwards;
}
@keyframes celebrate-unlock-in {
  0% { opacity: 0; transform: scale(0.4); }
  60% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}
/* The streak acts out its extension: it enters at yesterday's count (or not at
   all on day one), then ticks up to include today with a pop and a "+1". When
   the day's other goal is still open it is a muted hint instead. */
.celebrate-stat--streak.streak-empty { display: none; }
.celebrate-stat--streak.celebrate-stat--pending {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--muted);
  font-weight: 500;
}
.celebrate-stat--streak.streak-tick,
.daily-goal-streak.streak-tick { animation: streak-tick-pop 0.55s var(--ease); }
@keyframes streak-tick-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.28); }
  100% { transform: scale(1); }
}
.streak-plus {
  position: absolute;
  top: -0.6rem;
  right: -0.45rem;
  font-size: 0.82rem;
  font-weight: 800;
  color: #d99a1f;
  pointer-events: none;
  animation: streak-plus-float 1.1s var(--ease) forwards;
}
@keyframes streak-plus-float {
  0% { opacity: 0; transform: translateY(6px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-16px); }
}
@keyframes celebrate-emoji-bounce {
  0% { transform: scale(0.3) rotate(-14deg); }
  45% { transform: scale(1.25) rotate(7deg); }
  70% { transform: scale(0.95) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .celebrate-card,
  .celebrate-card.leaving,
  .celebrate-card .celebrate-emoji,
  .celebrate-stat--streak.streak-tick,
  .celebrate-stat--unlock,
  .daily-goal-streak.streak-tick,
  .daily-goal-status.pct-tick,
  .daily-goal-bar.goal-bar-pulse span,
  .goal-plus,
  .streak-plus { animation: none; }
  .daily-goal-bar span { transition: none; }
}
@keyframes celebrate-pop-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.7); }
  60% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.06); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes celebrate-pop-out {
  0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.9); }
}

.daily-goal.celebrate-pop,
.voice-goal.celebrate-pop { animation: chip-celebrate 0.7s var(--ease); }
@keyframes chip-celebrate {
  0% { transform: scale(1); }
  30% { transform: scale(1.18); }
  55% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------------------------
   Ticking off the day (src/client/tick-off.ts): Home's bar under the plate —
   locked until every daily goal is hit, then open, then done — and the
   dialog with the cathedral the tutor's goal in days builds, drawn by the 3D
   scene (src/scene/) on a canvas, or flat on another until it loads. The
   tags over the canvas are placed by transforms set from code.
   --------------------------------------------------------------------------- */

/* Laid out on a grid so the sentence has the width: the cathedral, then the
   title with the days on its line, the sentence under both, and the lock. */
.tickoff-bar {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "thumb title count lock" "thumb sub sub lock";
  align-items: center;
  column-gap: 0.8rem;
  row-gap: 0.15rem;
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
.tickoff-bar:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.tickoff-bar[aria-busy="true"] { cursor: progress; }
.tickoff-bar:active { transform: translateY(0); }
.tickoff-bar-text { display: contents; }
.tickoff-bar-text b { grid-area: title; align-self: end; min-width: 0; font-size: 0.9rem; color: var(--ink); }
.tickoff-bar-text span { grid-area: sub; align-self: start; font-size: 0.8rem; line-height: 1.35; }
.tickoff-bar-count {
  grid-area: count;
  align-self: end;
  justify-self: end;
  padding: 0.12rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* The learner's own cathedral as a diorama (home-cathedral.ts, diorama.ts):
   the model on its lawn, on a panel of sky — the stones laid so far in
   sandstone, today's in gold, the rest a pale wireframe. Large enough, a
   swipe across it spins it (is-spinnable); vertical moves stay the page's. */
.tickoff-bar-thumb { grid-area: thumb; position: relative; width: 66px; height: 46px; }
.tickoff-bar-thumb canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(180deg, #efe9f7 0%, #fbf1e4 60%, #f6ead6 100%);
}
.tickoff-bar-thumb canvas.is-spinnable { touch-action: pan-y; cursor: grab; }
.tickoff-bar-thumb canvas.is-spinning { cursor: grabbing; }
.tickoff-bar:has(canvas.is-spinning) { transform: none; }
.tickoff-bar-lock { grid-area: lock; display: grid; place-items: center; }
/* Locked, the bar is the plan card's footer (main.ts renderHomePlate): the
   line under the rows, as the WhatsApp card has one, on the card's own
   ground, a hairline above it. */
.day-card-foot { margin: 0.45rem -0.95rem -0.45rem; border-top: 1px solid var(--border); }
.tickoff-bar--in-card {
  padding: 0.8rem 0.95rem 0.85rem;
  border: 0;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
  background: var(--surface-2);
  box-shadow: none;
}
.tickoff-bar--in-card:hover { transform: none; box-shadow: none; background: color-mix(in srgb, var(--ink) 4%, var(--surface-2)); }
.tickoff-bar--in-card .tickoff-bar-count { border-color: var(--border-strong); color: var(--ink-soft); }
/* A narrow phone: the days go under the sentence, so the title keeps its line. */
@media (max-width: 380px) {
  .tickoff-bar { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "thumb title lock" "thumb sub lock" "thumb count lock"; }
  .tickoff-bar-count { justify-self: start; align-self: start; margin-top: 0.2rem; }
}
.tickoff-bar-lock svg,
.tickoff-bar-check svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tickoff-lock-shackle { transform-origin: 16px 11px; }
/* Open: the bar fills, the lock's shackle swings up, a sheen passes now and
   then, and the little cathedral glows gold round today's stones. */
.tickoff-bar--open {
  border: 1px solid var(--accent-strong);
  background: var(--accent-strong);
  color: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-md);
}
.tickoff-bar--open .tickoff-bar-text b { color: #fff; font-size: 0.95rem; }
.tickoff-bar--open .tickoff-bar-lock { color: var(--gold); }
.tickoff-bar--open .tickoff-lock-shackle { transform: translateY(-2px) rotate(34deg); }
.tickoff-bar--open:hover { box-shadow: var(--shadow-lg); }
.tickoff-bar--open::before {
  content: '';
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: 0;
  width: 30%;
  background: rgba(255, 255, 255, 0.13);
  transform: translateX(-150%) skewX(-20deg);
  animation: tickoff-sheen 3.6s var(--ease) 1s infinite;
  pointer-events: none;
}
@keyframes tickoff-sheen {
  0% { transform: translateX(-150%) skewX(-20deg); }
  35%, 100% { transform: translateX(450%) skewX(-20deg); }
}
.tickoff-bar--open .tickoff-bar-thumb canvas { animation: tickoff-glow 2.6s var(--ease) 0.6s infinite; }
@keyframes tickoff-glow {
  0%, 60%, 100% { transform: none; filter: none; }
  72% { transform: translateY(-2px) scale(1.08); filter: drop-shadow(0 0 6px rgba(224, 169, 58, 0.9)); }
}
/* The unlock, played once a day: the shackle springs open and the bar pops
   with a gold ring. */
.tickoff-bar.is-unlocking { animation: tickoff-unlock 0.9s var(--ease) both; }
.tickoff-bar.is-unlocking .tickoff-lock-shackle { animation: tickoff-shackle 0.9s var(--ease) both; }
@keyframes tickoff-unlock {
  0% { transform: scale(0.97); box-shadow: 0 0 0 0 rgba(224, 169, 58, 0.75), var(--shadow-md); }
  45% { transform: scale(1.025); }
  100% { transform: scale(1); box-shadow: 0 0 0 16px rgba(224, 169, 58, 0), var(--shadow-md); }
}
@keyframes tickoff-shackle {
  0%, 25% { transform: none; }
  45% { transform: translateY(-4px); }
  75% { transform: translateY(-2px) rotate(46deg); }
  100% { transform: translateY(-2px) rotate(34deg); }
}
.tickoff-bar--done {
  border: 1px solid var(--good);
  background: var(--good-soft);
  color: var(--ink-soft);
}
.tickoff-bar--done .tickoff-bar-count { color: var(--good); }
/* Today laid: a tick on the corner of the little cathedral. */
.tickoff-bar-check {
  position: absolute;
  right: -5px;
  bottom: -3px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  box-shadow: 0 0 0 2px var(--good-soft);
}
.tickoff-bar-check svg { width: 13px; height: 13px; stroke-width: 3; }
/* Back from ticking the day off: the bar arrives with a green ring. */
.tickoff-bar--done.is-fresh { animation: tickoff-fresh 0.9s var(--ease) both; }
.tickoff-bar--done.is-fresh .tickoff-bar-check { animation: celebrate-emoji-bounce 0.8s var(--ease) 0.1s both; }
@keyframes tickoff-fresh {
  0% { transform: scale(0.97); box-shadow: 0 0 0 0 rgba(47, 158, 87, 0.6); }
  45% { transform: scale(1.02); }
  100% { transform: scale(1); box-shadow: 0 0 0 16px rgba(47, 158, 87, 0); }
}

/* --- The dialog ------------------------------------------------------------ */

dialog.tickoff {
  width: min(920px, calc(100vw - 20px));
  max-width: none;
  max-height: calc(100dvh - 16px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--gold);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog.tickoff::backdrop {
  background: rgba(15, 18, 54, 0.6);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.tickoff-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1rem 1.1rem 1.1rem;
  animation: tickoff-in 0.4s var(--ease) both;
}
@keyframes tickoff-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.tickoff-head { display: flex; align-items: flex-start; gap: 0.8rem; }
.tickoff-heading { flex: 1; min-width: 0; }
.tickoff-tools { flex: none; display: flex; gap: 0.3rem; }
.tickoff-tool {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.tickoff-tool:hover { color: var(--ink); border-color: var(--accent); }
.tickoff-tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tickoff-sound .tickoff-sound-mute,
.tickoff-sound.is-muted .tickoff-sound-wave { display: none; }
.tickoff-sound.is-muted .tickoff-sound-mute { display: inline; }
.tickoff-title { margin: 0.1rem 0 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.tickoff-title.is-done { animation: celebrate-emoji-bounce 0.8s var(--ease) both; }
.tickoff-sub { margin: 0.2rem 0 0; max-width: 40rem; color: var(--muted); font-size: 0.9rem; line-height: 1.4; white-space: pre-line; }

/* The stage: the scene's canvas, the flat one under it until the scene has
   loaded, and the tags over both. */
.tickoff-stage {
  position: relative;
  isolation: isolate;
  height: clamp(300px, 66vh, 680px);
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(#4a7cc4, #ffd2a0 72%, #a9998a 72%);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.tickoff-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tickoff-canvas { opacity: 0; pointer-events: none; transition: opacity 0.6s var(--ease); }
.tickoff-flat { transition: opacity 0.6s var(--ease); }
.tickoff-stage.is-3d .tickoff-canvas { opacity: 1; pointer-events: auto; }
.tickoff-stage.is-3d .tickoff-flat { opacity: 0; pointer-events: none; }
.tickoff-stage.is-3d .tickoff-canvas:active { cursor: grabbing; }
.tickoff-stage.is-complete { box-shadow: inset 0 0 0 2px rgba(224, 169, 58, 0.7), 0 0 28px rgba(224, 169, 58, 0.35); }
/* The days, done and to come, over the sky. */
.tickoff-counts {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}
.tickoff-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.9);
  color: #232e7b;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 24, 70, 0.18);
}
.tickoff-chip b { font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tickoff-chip--done b { color: #2f9e57; }
.tickoff-chip.is-bumped b { display: inline-block; animation: celebrate-emoji-bounce 0.7s var(--ease) both; }
/* "Today", over today's stones until they are taken. */
.tickoff-today-tag,
.tickoff-day-tag {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
.tickoff-today-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e0a93a;
  color: #232e7b;
  box-shadow: 0 2px 8px rgba(20, 24, 70, 0.3);
}
.tickoff-today-tag::after {
  content: '';
  position: absolute;
  left: calc(50% + var(--point, 0px));
  bottom: -5px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-bottom: 0;
  border-top-color: #e0a93a;
}
.tickoff-today-tag[hidden],
.tickoff-day-tag[hidden] { display: none; }
.tickoff-today-tag.is-locked { background: #f1ead9; color: #6d6890; }
.tickoff-today-tag.is-locked::after { border-top-color: #f1ead9; }
.tickoff-today-lock svg { display: block; width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
/* A moment's caption: what the day's stones made room for, as it goes in. */
.tickoff-moment {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 3;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  background: rgba(35, 46, 123, 0.88);
  color: #fff6df;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(224, 169, 58, 0.7), 0 4px 18px rgba(20, 24, 70, 0.35);
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
}
.tickoff-moment.is-on { animation: tickoff-moment 3.4s var(--ease) both; }
/* How to look round the 3D cathedral: until it is first moved, or a while. */
.tickoff-look {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 2;
  max-width: calc(100% - 24px);
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: rgba(20, 24, 70, 0.62);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translate(-50%, 6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.tickoff-look.is-on { opacity: 1; transform: translate(-50%, 0); }
@keyframes tickoff-moment {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  12%, 82% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -4px); }
}
.tickoff-today-tag.is-shaking { animation: tickoff-shake 0.42s var(--ease); }
@keyframes tickoff-shake {
  0%, 100% { margin-left: 0; }
  20% { margin-left: -6px; }
  45% { margin-left: 5px; }
  70% { margin-left: -3px; }
}
/* A laid stone's day, under the pointer. */
.tickoff-day-tag { background: rgba(20, 24, 60, 0.86); color: #fff; font-weight: 700; }

.tickoff-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; flex-wrap: wrap; }
.tickoff-hint { flex: 1 1 16rem; margin: 0; color: var(--muted); font-size: 0.86rem; }
.tickoff-hint.is-locked::before { content: '🔒 '; }
.tickoff-hint.is-flash { animation: tickoff-flash 0.7s var(--ease); }
@keyframes tickoff-flash {
  0%, 100% { color: var(--muted); }
  30% { color: var(--ink); }
}
button.tickoff-lay {
  flex: none;
  min-width: 12rem;
  border-color: #e0a93a;
  background: #e0a93a;
  color: #232e7b;
  font-weight: 800;
  box-shadow: 0 0 0 0 rgba(224, 169, 58, 0.6);
  animation: tickoff-lay-pulse 2.4s var(--ease) 1.2s infinite;
}
/* Not while locked: the gold would say it can be pressed. */
button.tickoff-lay:hover:not(:disabled, [aria-disabled="true"]) { background: #edb94b; }
button.tickoff-lay[aria-disabled="true"] { border-color: var(--border-strong); background: var(--surface-3); color: var(--muted); animation: none; cursor: not-allowed; }
button.tickoff-lay:disabled { animation: none; opacity: 0.6; }
@keyframes tickoff-lay-pulse {
  0%, 70%, 100% { box-shadow: 0 0 0 0 rgba(224, 169, 58, 0); }
  30% { box-shadow: 0 0 0 8px rgba(224, 169, 58, 0.28); }
}
.tickoff-end { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem 0.8rem; flex-wrap: wrap; }
.tickoff-streak {
  margin: 0 auto 0 0;
  padding: 4px 14px;
  border: 1px solid var(--gold);
  border-radius: var(--radius-pill);
  background: var(--gold-soft);
  font-size: 0.92rem;
  font-weight: 700;
  animation: streak-tick-pop 0.55s var(--ease);
}
.tickoff-error { margin: 0; color: var(--bad); font-size: 0.85rem; }
.tickoff-retry { padding: 0; border: none; background: none; color: var(--accent-2); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.tickoff-done { min-width: 9rem; }

@media (max-width: 560px) {
  dialog.tickoff { width: calc(100vw - 8px); max-height: calc(100dvh - 8px); border-radius: var(--radius); }
  .tickoff-panel { gap: 0.55rem; padding: 0.75rem 0.6rem 0.8rem; }
  .tickoff-title { font-size: 1.12rem; }
  .tickoff-sub { font-size: 0.8rem; }
  .tickoff-stage { height: clamp(300px, 58dvh, 620px); margin: 0 -0.15rem; }
  .tickoff-chip { font-size: 0.7rem; padding: 3px 9px; }
  .tickoff-chip b { font-size: 0.9rem; }
  .tickoff-lay { width: 100%; }
  .tickoff-done { width: 100%; }
  .tickoff-streak { margin: 0 auto; }
  .tickoff-bar { gap: 0.6rem; padding: 0.55rem 0.7rem; }
}
@media (max-height: 600px) {
  .tickoff-sub { display: none; }
  .tickoff-stage { height: max(220px, calc(100dvh - 190px)); }
}
@media (prefers-reduced-motion: reduce) {
  .tickoff-panel,
  .tickoff-title.is-done,
  .tickoff-streak,
  .tickoff-hint.is-flash,
  .tickoff-lay,
  .tickoff-chip.is-bumped b,
  .tickoff-today-tag.is-shaking,
  .tickoff-bar--open::before,
  .tickoff-bar--open .tickoff-bar-thumb canvas,
  .home-plate.is-roomy .tickoff-bar--open .tickoff-bar-thumb canvas,
  .tickoff-bar.is-unlocking,
  .tickoff-bar.is-unlocking .tickoff-lock-shackle,
  .tickoff-bar--done.is-fresh,
  .tickoff-bar--done.is-fresh .tickoff-bar-check { animation: none; }
  .tickoff-canvas,
  .tickoff-flat { transition: none; }
  /* The caption still comes and goes, without moving. */
  .tickoff-moment { transform: translate(-50%, 0); }
  .tickoff-moment.is-on { animation: tickoff-moment-fade 3.4s linear both; }
}
@keyframes tickoff-moment-fade {
  0%, 100% { opacity: 0; }
  8%, 86% { opacity: 1; }
}

/* ---------------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------------- */

.muted { color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

/* Nice slim scrollbars */
#messages, #side-pane { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
#messages::-webkit-scrollbar, #side-pane::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb, #side-pane::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ---------------------------------------------------------------------------
   Voice mode — the all speaking & listening view (src/client/voice.ts)

   A fixed full-screen overlay above the app (NOT inside .layout, so it can't
   disturb the onboarding tour's stacking assumptions). Deliberately sparse:
   the `data-phase` attribute on #voice-mode gates what is visible, so the
   "only the chips" / "only the reply items" contract shows through in the CSS
   too — voice.ts toggles [hidden], these rules just style what remains.
   --------------------------------------------------------------------------- */

#voice-mode {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 1rem env(safe-area-inset-bottom);
}
#voice-mode[hidden] { display: none; }

/* The wide layout's grouping wrappers — the call, its scrolling body, and the
   rail (see the desktop block below). Out of the box tree everywhere else, so
   on a phone the regions stack as one column, in the order the phone block
   gives them. */
.voice-call,
.voice-call-body,
.voice-turn { display: contents; }

/* Three columns with equal-weight sides, so the identity in the middle sits on
   the header's true centre line. (An auto margin can't do this: with only the
   exit button beside it, the leftover space it centres within is the space to
   the *right* of that button, which pushed the tutor's name well off-axis.) */
.voice-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.2rem;
}
.voice-head-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}
.voice-head-text { display: flex; flex-direction: column; }
/* "your Spanish tutor" under the name — the wide layout has the room. */
.voice-role { display: none; }
#voice-exit {
  justify-self: start;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
#voice-exit:hover { color: var(--ink); border-color: var(--muted); }

/* Who speaks (speaker-voice.ts): a pill beside the tutor's name opening the
   region's voices under the head. */
.voice-head { position: relative; }
.voice-head-meta { position: relative; }
.speaker-voice-btn {
  position: absolute;
  left: calc(100% + 0.6rem);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.speaker-voice-btn[hidden] { display: none; }
.speaker-voice-btn:hover,
.speaker-voice-btn[aria-expanded="true"] { color: var(--ink); border-color: var(--accent); }
.speaker-voice-icon { flex: none; }
.speaker-voice-caret { font-size: 0.7em; }
.speaker-voice-pop {
  position: absolute;
  top: calc(100% + 0.2rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(70vh, 32rem);
  overflow-y: auto;
  padding: 0.85rem 0.6rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.speaker-voice-pop[hidden] { display: none; }
.speaker-voice-title { margin: 0 0.4rem; font-weight: 700; color: var(--ink); }
.speaker-voice-hint { margin: 0.2rem 0.4rem 0.6rem; font-size: 0.8rem; color: var(--muted); }
.speaker-voice-list { display: flex; flex-direction: column; gap: 0.15rem; }
.speaker-voice-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}
.speaker-voice-row:hover { background: var(--surface-2); }
.speaker-voice-row[aria-pressed="true"] { background: var(--accent-soft); }
.speaker-voice-row-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.speaker-voice-row-place { font-size: 0.78rem; color: var(--muted); }
.speaker-voice-row-mark { flex: none; width: 1rem; text-align: center; color: var(--accent-2); }
.speaker-voice-row.is-playing .speaker-voice-row-mark { animation: speaker-voice-playing 1.2s var(--ease) infinite; }
@keyframes speaker-voice-playing {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.speaker-voice-error { margin: 0.5rem 0.4rem 0; font-size: 0.8rem; color: var(--bad); }
.speaker-voice-error[hidden] { display: none; }
#voice-replay[hidden] { display: none; }

/* The day's speech-time goal (minutes of talking done / target) — voice mode's
   whole daily-progress display, sitting in the header grid's right column
   opposite the exit button — and under it, smaller, the time Talk takes in
   all at the learner's factor (DESIGN.md §8, "Talk's real time"). Turns
   accent-colored once the goal is reached. */
.voice-goal {
  justify-self: end;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.voice-goal[hidden] { display: none; }
.voice-goal-text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.voice-goal-real { font-size: 0.85em; color: var(--muted); }
.voice-goal.voice-goal-done {
  /* accent-2 for the text: the violet accent alone dips under AA on the warm
     light ground at this size (the border stays accent). */
  color: var(--accent-2);
  border-color: var(--accent);
}

/* Top-anchored, never centered: vertical centering would re-seat every region
   whenever any content changed. Regions stack from the top in a fixed order
   and hold their positions for the whole conversation. */
#voice-stage {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem 0;
}
.voice-stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  width: 100%;
  max-width: 30rem;
  text-align: center;
}

/* The tutor's presence — the wide layout only (a phone hides it and lets the
   header's dot do its job): a voice glyph of five bars on a navy disc, set in
   two flat halo rings. While the tutor speaks the bars move and the rings
   ripple out; while the tutor is getting a reply ready (loading, and the
   learner's reply being sent) the bars wave in turn; on the learner's turn the
   whole orb recedes — the words to use, and the mic, are the focus. */
.voice-orb {
  --orb: clamp(6.5rem, 19vh, 10.5rem);
  position: relative;
  flex: none;
  width: var(--orb);
  height: var(--orb);
  display: grid;
  place-items: center;
  transition:
    width 0.45s var(--ease),
    height 0.45s var(--ease),
    opacity 0.35s var(--ease),
    transform 0.35s var(--ease);
}
.voice-orb::before,
.voice-orb::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent-soft);
}
.voice-orb::after {
  inset: 13%;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.voice-orb-core {
  position: relative;
  z-index: 1;
  width: 58%;
  height: 58%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-strong);
  box-shadow: var(--shadow-lg);
}
.voice-orb-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8%;
  width: 50%;
  height: 44%;
}
/* At rest the bars draw a still waveform, tallest in the middle. */
.voice-orb-bars i {
  flex: 1;
  height: 40%;
  border-radius: 999px;
  background: var(--on-accent);
  transition: height 0.3s var(--ease);
}
.voice-orb-bars i:nth-child(1),
.voice-orb-bars i:nth-child(5) { height: 30%; }
.voice-orb-bars i:nth-child(3) { height: 85%; }
.voice-orb-bars i:nth-child(2),
.voice-orb-bars i:nth-child(4) { height: 58%; }

#voice-mode[data-phase="speaking"] .voice-orb-bars i {
  animation: voice-bar 0.8s var(--ease) infinite alternate;
}
#voice-mode[data-phase="speaking"] .voice-orb-bars i:nth-child(1) { animation-duration: 0.74s; animation-delay: -0.3s; }
#voice-mode[data-phase="speaking"] .voice-orb-bars i:nth-child(2) { animation-duration: 0.92s; animation-delay: -0.55s; }
#voice-mode[data-phase="speaking"] .voice-orb-bars i:nth-child(3) { animation-duration: 0.66s; }
#voice-mode[data-phase="speaking"] .voice-orb-bars i:nth-child(4) { animation-duration: 0.86s; animation-delay: -0.2s; }
#voice-mode[data-phase="speaking"] .voice-orb-bars i:nth-child(5) { animation-duration: 0.78s; animation-delay: -0.62s; }
@keyframes voice-bar {
  from { height: 22%; }
  to { height: 100%; }
}
/* Speaking, the two rings leave the disc's edge in turn and spread out like
   sound, in a stronger tint than the resting halo so they read on white. */
#voice-mode[data-phase="speaking"] .voice-orb::before,
#voice-mode[data-phase="speaking"] .voice-orb::after {
  inset: 0;
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  animation: voice-ripple 2.4s cubic-bezier(0.2, 0.6, 0.35, 1) infinite;
}
#voice-mode[data-phase="speaking"] .voice-orb::after { animation-delay: -1.2s; }
@keyframes voice-ripple {
  from { transform: scale(0.58); opacity: 1; }
  to { transform: scale(1.35); opacity: 0; }
}

#voice-mode[data-phase="loading"] .voice-orb-bars i,
#voice-mode[data-phase="sending"] .voice-orb-bars i {
  height: 22%;
  animation: voice-bar-wait 1.2s var(--ease) infinite;
}
#voice-mode[data-phase="loading"] .voice-orb-bars i:nth-child(2),
#voice-mode[data-phase="sending"] .voice-orb-bars i:nth-child(2) { animation-delay: 0.12s; }
#voice-mode[data-phase="loading"] .voice-orb-bars i:nth-child(3),
#voice-mode[data-phase="sending"] .voice-orb-bars i:nth-child(3) { animation-delay: 0.24s; }
#voice-mode[data-phase="loading"] .voice-orb-bars i:nth-child(4),
#voice-mode[data-phase="sending"] .voice-orb-bars i:nth-child(4) { animation-delay: 0.36s; }
#voice-mode[data-phase="loading"] .voice-orb-bars i:nth-child(5),
#voice-mode[data-phase="sending"] .voice-orb-bars i:nth-child(5) { animation-delay: 0.48s; }
@keyframes voice-bar-wait {
  0%, 100% { height: 22%; }
  40% { height: 60%; }
}

#voice-mode[data-phase="reply"] .voice-orb,
#voice-mode[data-phase="recording"] .voice-orb,
#voice-mode[data-phase="feedback"] .voice-orb { opacity: 0.4; transform: scale(0.8); }
@media (prefers-reduced-motion: reduce) {
  .voice-orb::before,
  .voice-orb::after,
  .voice-orb-bars i { animation: none !important; }
}

#voice-status {
  margin: 0;
  /* Two lines reserved: prompts wrap on narrow screens, and a 1↔2-line status
     change must not shift the regions below. */
  min-height: 2.9em;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Folding. On a phone one region is open at a time: the phase's live panel
   (voice.ts applyPanelFolds folds the rest to their title bars), plus anything
   the learner reopened by hand. The wide layout has the room to keep every
   region open (the inactive ones dimmed), so only the revealed transcript
   folds there — on its own toggle, everywhere (it is deliberately NOT in the
   phase-folding panels set). Tapping a folded title opens it again. */
.voice-transcript-panel { animation: msg-in 0.22s var(--ease) both; }
.voice-panel-toggle:not(:disabled) { cursor: pointer; }
/* Chevron marking a title as foldable, pointing down when the panel is open.
   A title that can't fold (the wide layout's, which voice.ts disables) has
   none. */
.voice-panel-toggle::after {
  content: '';
  float: right;
  width: 0.42rem;
  height: 0.42rem;
  margin: 0.15rem 0.1rem 0 0;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s var(--ease);
}
.voice-panel-collapsed .voice-panel-toggle::after {
  margin-top: 0.05rem;
  transform: rotate(-45deg);
}
.voice-panel-toggle:disabled::after { display: none; }
.voice-panel-collapsed > .voice-panel-body { display: none; }
.voice-panel-collapsed {
  /* A title bar and nothing else — and not dimmed: a folded strip is already
     plainly out of the way, so dimming it would only make its title hard to
     read (and it stays tappable to reopen). */
  min-height: 0;
  padding: 0.5rem 0.9rem;
  opacity: 1;
  pointer-events: auto;
}
.voice-panel-collapsed .voice-panel-title { margin: 0; }

/* The feedback gate's dismiss button: the reply's feedback is on screen alone
   (data-phase="feedback"), the tutor's audio held — this starts it. It lives
   in .voice-foot, standing in for the mic (hidden in this phase) with the
   same fill and weight: the phase's one action, at the bottom. */
.voice-feedback-continue {
  display: block;
  margin: 0;
  padding: 0.9rem 1.8rem;
  border: none;
  border-radius: 999px;
  background: var(--accent-strong);
  color: var(--on-accent);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.1s var(--ease);
  pointer-events: auto; /* the floating foot itself lets taps through */
}
.voice-feedback-continue:active { transform: scale(0.96); }
/* Trailing room under the stage while the button floats over it, as the mic
   phases get for the mic — sized to the shorter button. */
#voice-mode[data-phase="feedback"] .voice-stage-inner { padding-bottom: 5.5rem; }
.voice-feedback-continue[hidden] { display: none; }
.voice-feedback-continue:disabled { opacity: 0.5; cursor: default; }
/* The one review area: "Missed something important?" + replay, joined by the
   "show text" escape hatch once the learner has listened again (voice.ts). It
   sits right under the understanding pills, between regions, so while its
   controls don't apply (the tutor speaking, the feedback gate) it folds away
   rather than leave a hole in the stack — appearing then moves only the
   regions below it, which are folded in those phases. The exception is
   recording: the reply items it sits above are the live region then, so it
   stays, dimmed and inert like an inactive region, and the words being read
   don't jump at the mic tap. */
.voice-review {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  min-height: 4.4rem;
  transition: opacity 0.25s var(--ease);
}
.voice-review[hidden] { display: none; }
.voice-review-pending { display: none; }
.voice-review-inactive { opacity: 0.45; pointer-events: none; }
.voice-review-prompt { margin: 0; font-size: 0.8rem; color: var(--muted); }
.voice-review-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.voice-show-text,
#voice-review #voice-replay {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.voice-show-text:hover,
#voice-review #voice-replay:hover { color: var(--ink); border-color: var(--muted); }
.voice-show-text[hidden] { display: none; }

/* The three fixed voice regions: the understanding pills for the bot's message
   (#voice-understanding), the feedback on the learner's own reply
   (#voice-feedback), and the items to use in the reply (#voice-prod-panel).
   All three stay on screen in fixed positions for the whole turn — content
   lands *inside* a region; regions themselves never come and go. Phases dim
   the inactive ones instead of removing them. */
.voice-panel {
  width: 100%;
  min-height: 3.4rem;
  padding: 0.7rem 0.9rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: opacity 0.25s var(--ease);
}
.voice-panel[hidden] { display: none; }
.voice-panel-inactive { opacity: 0.45; pointer-events: none; }
/* The title stays reachable even in a dimmed panel: on a phone it is the
   control that expands a collapsed region back open (.voice-panel-collapsed). */
.voice-panel-inactive > .voice-panel-title { pointer-events: auto; }
.voice-panel-title {
  margin: 0 0 0.55rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
/* Styled as the plain heading text it replaced; the fold block above makes it
   a working control (cursor + chevron) wherever it can fold. */
.voice-panel-toggle {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  /* Form controls don't inherit these two from the heading on their own. */
  text-transform: inherit;
  text-align: left;
}
/* One-line control legend under a panel title (what ✓ and ✗ do). */
.voice-panel-hint {
  margin: -0.35rem 0 0.55rem;
  font-size: 0.74rem;
  color: var(--muted);
}

/* The learner's transcribed reply + its corrected form, at the top of the
   feedback panel: a compact right-aligned reply bubble (the chat's own user
   vocabulary) with the shared .correction line beneath. */
.voice-correction {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  width: 100%;
  margin-bottom: 0.6rem;
}
.voice-correction[hidden] { display: none; }
.voice-said {
  max-width: 88%;
  padding: 0.4rem 0.7rem;
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: left;
}
.voice-correction .correction { text-align: right; }
.voice-correction .correction-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 100%;
}
.voice-correction .correction-explain { align-self: stretch; }
.voice-correction .correction-toggle { margin-top: 0.3rem; }

/* Inside the revealed transcript: the one-line tap hint and the word-by-word
   message (the words themselves are global .hw-word buttons; the gloss card
   reuses .msg-help-gloss). */
.voice-transcript-hint {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  color: var(--muted);
}
.voice-transcript-words {
  margin: 0;
  line-height: 1.7;
}

/* The reply's verification cards and the pills' explanations reuse the chat's
   own .suggestion / .explanation / .typing styling; just lay them out
   full-width. */
#voice-cards,
#voice-explanations { width: 100%; display: flex; flex-direction: column; gap: 0.5rem; text-align: left; }
#voice-cards .suggestion,
#voice-explanations .explanation { margin-top: 0; }
#voice-explanations:not(:empty) { margin-top: 0.6rem; }

#voice-chips { justify-content: flex-start; }
/* A graded pill keeps both its buttons (voice.ts buildChip), so it keeps its
   size and nothing around it moves: the answer given stays filled in, the
   other fades. (The text chat's pills drop theirs.) */
#voice-chips .chip.graded-got,
#voice-chips .chip.graded-missed { padding-right: 0.3rem; }
#voice-chips .chip button:disabled { cursor: default; }
#voice-chips .chip button:disabled:not(.chosen),
#voice-chips .chip button:disabled:not(.chosen):hover { background: var(--surface-3); opacity: 0.3; }
#voice-chips .chip button.grade-yes.chosen { background: var(--good); color: #fff; }
#voice-chips .chip button.grade-no.chosen { background: var(--bad); color: #fff; }

/* Synced pill reveal: during the speaking phase the understanding pills pop in
   one by one as the voice reaches each word, fully interactive — the same ✓/✗
   grading as the review phase, just arriving word by word. A not-yet-spoken
   pill already OCCUPIES its space (visibility, not display) so the panel takes
   its final size the moment the turn renders and reveals never shift layout;
   removing .chip-hidden fades the pill in place. */
.chip-hidden { visibility: hidden; }
@keyframes chip-pop {
  from { opacity: 0; transform: scale(0.82); }
  to { opacity: 1; transform: scale(1); }
}
#voice-chips.speaking .chip:not(.chip-hidden) { animation: chip-pop 0.22s ease-out; }
@media (prefers-reduced-motion: reduce) {
  #voice-chips.speaking .chip:not(.chip-hidden) { animation: none; }
}

/* The reply items inside their panel: the words to work into the spoken reply.
   Rendered (dimmed) from the start of the turn — see #voice-prod-panel.
   One compact tile each, on every screen: the item and its kind on the first
   line with the reveal button at its end, the cue (a hint, or a recall card's
   sentence) on the line under them across the tile's width, then a grammar
   card's name, example and "Try:" line. The text has the first column and the
   button the second, so a long head wraps beside the button rather than
   pushing it onto a line of its own, and "In Spanish:", the word and its
   sentence read as one line of text, never as three narrow columns. */
#voice-production {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.voice-prod-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 0.6rem;
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  text-align: left;
}
.voice-prod-card > * { grid-column: 1 / -1; min-width: 0; }
.voice-prod-card > .voice-prod-head { grid-column: 1; grid-row: 1; line-height: 1.3; }
.voice-prod-card > .reveal { grid-column: 2; grid-row: 1; }
.voice-prod-card > .revealed:empty { display: none; }
.voice-prod-head .prod-stage { font-size: 0.74rem; margin-right: 0.1rem; }
.voice-prod-head .form-es { font-weight: 700; font-size: 0.98rem; }
/* An expression's or grammar item's kind: a small line above it. */
.voice-prod-kind {
  display: block;
  margin-bottom: 0.05rem;
  font-size: 0.56rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}
.voice-prod-cue { margin-top: 0.1rem; font-size: 0.8rem; line-height: 1.35; color: var(--muted); }
.voice-prod-cue.prod-sentence { color: var(--ink-soft); }
.voice-prod-card .prod-name { margin: 0.1rem 0 0; font-size: 0.8rem; }
.voice-prod-card .example,
.voice-prod-card .how-to-use { margin-top: 0.1rem; font-size: 0.8rem; line-height: 1.35; color: var(--ink-soft); }
.voice-prod-card .how-to-use b { color: var(--accent-2); font-weight: 600; }
.voice-prod-card .revealed { margin-top: 0.3rem; }
.voice-prod-card .revealed .explanation { margin-top: 0; font-size: 0.82rem; padding: 0.5rem 0.7rem; }
/* Small enough that a short word keeps its button on its line on a 320px phone. */
.voice-prod-card .reveal {
  padding: 0.22rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent-2);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.voice-prod-card .reveal:hover { border-color: var(--accent); background: var(--accent-soft); }

/* The mic floats over the stage instead of owning an opaque band below it:
   the foot is lifted out of the column and made see-through, and only the
   things on it that carry meaning (the button, its label, the live wave)
   paint or take taps — everything else in its box shows, and scrolls,
   straight through. The stage's content gets the mic's height as trailing
   room in the mic phases, so the last region can always be scrolled clear. */
.voice-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0 calc(1.2rem + env(safe-area-inset-bottom));
  pointer-events: none;
}
#voice-mode[data-phase="reply"] .voice-stage-inner,
#voice-mode[data-phase="recording"] .voice-stage-inner,
#voice-mode[data-phase="sending"] .voice-stage-inner { padding-bottom: 8.5rem; }
/* The recording waveform (mic-wave.ts draws into it): visible only while
   recording, but present — space reserved — in every phase the mic shows, so
   its appearance never shifts the button mid-tap. Its `color` is what the
   bars are drawn in (read via getComputedStyle); matching the recording red
   ties it to the live mic. */
.voice-wave {
  display: none;
  width: min(15rem, 70vw);
  height: 2.2rem;
  visibility: hidden;
  color: var(--bad);
  /* It sits on whatever is underneath, so it carries its own backing. */
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#voice-mode[data-phase="reply"] .voice-wave,
#voice-mode[data-phase="recording"] .voice-wave,
#voice-mode[data-phase="sending"] .voice-wave { display: block; }
#voice-mode[data-phase="recording"] .voice-wave { visibility: visible; }

/* The mic: the single reply affordance. Big, obvious, and it turns red while
   recording so the tap-to-stop state is unmistakable. */
#voice-mic {
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 50%;
  border: none;
  background: var(--accent-strong);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.1s var(--ease), background 0.2s var(--ease);
  pointer-events: auto;
}
#voice-mic[hidden] { display: none; }
#voice-mic:active { transform: scale(0.94); }
#voice-mic:disabled { opacity: 0.5; cursor: default; }
#voice-mic.recording {
  background: var(--bad);
  animation: voice-mic-pulse 1.2s var(--ease) infinite;
}
@keyframes voice-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 45%, transparent); }
  50% { box-shadow: 0 0 0 1rem transparent; }
}
/* A pill of its own, legible over whatever the foot floats above. */
#voice-hint {
  margin: 0;
  padding: 0.2rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
}
#voice-hint[hidden] { display: none; }

/* The dead-end state: the session's socket dropped and every reconnection
   attempt failed. It covers voice mode entirely — nothing underneath is worth
   tapping — and carries exactly one action, back to the text chat. Sits above
   everything inside #voice-mode (which is itself z-index 1500). */
.voice-lost {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
}
.voice-lost[hidden] { display: none; }
.voice-lost-card {
  width: min(26rem, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.6rem 1.4rem;
  text-align: center;
}
.voice-lost-icon { font-size: 2.2rem; line-height: 1; margin-bottom: 0.6rem; }
.voice-lost-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  line-height: 1.3;
  color: var(--ink);
}
.voice-lost-card p {
  margin: 0 0 1.2rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}
#voice-lost-exit {
  width: 100%;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent-strong);
  color: var(--on-accent);
  font: inherit;
  font-weight: 700;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  transition: transform 0.1s var(--ease), background 0.2s var(--ease);
}
#voice-lost-exit:hover { background: var(--accent-2); }
#voice-lost-exit:active { transform: scale(0.98); }

/* The key badge beside the mic's label and on the feedback gate's button
   (voice.ts keyCap): Space moves the turn on. Only where there is a mouse,
   and so almost always a keyboard. */
.voice-key { display: none; }
@media (hover: hover) and (pointer: fine) {
  .voice-key {
    display: inline-block;
    min-width: 1.7rem;
    margin-left: 0.55rem;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink-soft);
    font: 600 0.72rem/1.45 var(--font);
    text-align: center;
    vertical-align: 0.05em;
  }
  .voice-feedback-continue .voice-key {
    border-color: color-mix(in srgb, var(--on-accent) 40%, transparent);
    background: color-mix(in srgb, var(--on-accent) 14%, transparent);
    color: var(--on-accent);
  }
}

/* ---------------------------------------------------------------------------
   Voice mode, wide layout — a call beside the turn.

   The phone's single column is a 30rem strip on a desktop: most of the screen
   bare, the regions folded to empty title bars, and the mic floating over the
   reply items it asks the learner to read. Here the stage is a grid in the
   chat's own proportions (a main pane and a side column):

   - The call (left): a card with the tutor's orb and the status at the top,
     the "Listen again / Show text" row under them, then a scrolling body:
     the understanding pills (they pop in under the voice that says them)
     with the explanation of any marked ✗, the message text once revealed,
     and the feedback on the learner's reply. The mic (or the gate's "Hear
     the reply") docks at its foot. The card is the grid's ::before, spanning
     the call and the foot.
   - The rail (right): the words to use, alone — open for the whole turn,
     ringed in the accent on the learner's turn and dimmed before it — so
     nothing that grows elsewhere (an explanation, the message text) can
     push them out of view when it is time to say them.

   Nothing moves once it is placed: the top of the call (orb, status, review
   row) keeps one height whatever the phase, the call body only ever grows
   downward, a graded pill keeps its size, and each column scrolls on its
   own.
   --------------------------------------------------------------------------- */

@media (min-width: 801px) {
  #voice-mode {
    --voice-max: 72rem;
    --voice-rail: clamp(21.5rem, 30vw, 24rem);
    /* Lucide icons (ISC), drawn through masks in the text color. */
    --icon-listen: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3'/></svg>");
    --icon-say: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/><path d='M13 8H7'/><path d='M17 12H7'/></svg>");
    --icon-check: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><path d='m9 12 2 2 4-4'/></svg>");
    --icon-text: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect width='18' height='14' x='3' y='5' rx='2' ry='2'/><path d='M7 15h4M15 15h2M7 11h2M13 11h4'/></svg>");
    --icon-replay: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/><path d='M3 3v5h5'/></svg>");
    /* On a tall screen the head and the stage (capped below) sit together in
       the middle, rather than the call stretching into a tower. */
    justify-content: center;
    padding: env(safe-area-inset-top) 1.5rem env(safe-area-inset-bottom);
  }

  /* The head spans the stage's width, so Home and the goal line up with the
     call's and the rail's outer edges. */
  .voice-head {
    width: 100%;
    max-width: var(--voice-max);
    margin: 0 auto;
    padding: 1rem 0;
  }
  .voice-head-meta { gap: 0.65rem; }
  .voice-head-text { line-height: 1.25; }
  .voice-head-meta strong { font-size: 1.02rem; letter-spacing: -0.01em; }
  .voice-role { display: block; font-size: 0.76rem; color: var(--muted); }
  .voice-role:empty { display: none; }
  #voice-exit { padding: 0.4rem 0.9rem; font-size: 0.85rem; background: var(--surface); }
  #voice-mode .voice-context { width: 100%; max-width: var(--voice-max); margin: -0.35rem auto 0.9rem; }
  #voice-mode .voice-batch { width: 100%; max-width: var(--voice-max); margin: -0.35rem auto 0.9rem; }

  /* The goal as a ring filling toward the day's minutes (voice.ts sets
     --goal-progress, 0–1), the minutes beside it. */
  .voice-goal {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem 0.35rem 0.45rem;
    background: var(--surface);
    font-size: 0.85rem;
    color: var(--ink-soft);
  }
  .voice-goal::before {
    content: '';
    flex: none;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: conic-gradient(var(--accent) calc(var(--goal-progress, 0) * 1turn), var(--surface-3) 0);
    -webkit-mask: radial-gradient(farthest-side, transparent 56%, #000 60%);
    mask: radial-gradient(farthest-side, transparent 56%, #000 60%);
  }
  .voice-goal.voice-goal-done::before { background: var(--accent); }

  #voice-stage {
    flex: 0 1 52rem;
    overflow: hidden;
    align-items: stretch;
    padding: 0 0 1.5rem;
  }
  .voice-stage-inner,
  #voice-mode[data-phase] .voice-stage-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--voice-rail);
    grid-template-rows: minmax(0, 1fr) auto;
    column-gap: 1.5rem;
    row-gap: 0;
    align-items: stretch;
    max-width: var(--voice-max);
    height: 100%;
    padding: 0;
    text-align: left;
  }
  /* The call's card, behind the call and its foot. */
  .voice-stage-inner::before {
    content: '';
    grid-column: 1;
    grid-row: 1 / span 2;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: var(--shadow-lg);
  }

  /* ---- The call ---------------------------------------------------------- */
  /* With nothing under it the tutor has the call to itself: the full-size orb,
     sitting well down the card. Once the body shows anything (the pills, the
     message text, the feedback) voice.ts marks the call compact and the orb
     shrinks to a small presence at the top, the status with it — gliding, so
     the body's content slides up into the room rather than jumping. */
  .voice-call {
    --call-top: clamp(1.25rem, 15vh, 8.5rem);
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 0;
    padding: var(--call-top) 2rem 0;
    text-align: center;
    transition: padding-top 0.45s var(--ease);
  }
  .voice-call-compact { --call-top: 1rem; }
  .voice-call-compact .voice-orb { --orb: 3.5rem; }
  #voice-status {
    margin: clamp(0.6rem, 1.8vh, 1.1rem) 0 0;
    max-width: 32rem;
    /* Two lines held, so a status that wraps moves nothing below it. */
    min-height: 2.6em;
    font-size: 1.3rem;
    transition: font-size 0.45s var(--ease), margin-top 0.45s var(--ease);
    font-weight: 650;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-wrap: balance;
  }
  /* One row under the status. It keeps its height while it has nothing to
     offer (hidden or pending), so the call body under it never moves. */
  #voice-review {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem 0.7rem;
    min-height: 2.5rem;
    margin-top: 0.2rem;
  }
  #voice-review[hidden],
  #voice-review.voice-review-pending { display: flex !important; visibility: hidden; }
  .voice-review-prompt { font-size: 0.86rem; }
  .voice-show-text,
  #voice-review #voice-replay {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.95rem 0.42rem 0.8rem;
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--accent-2);
    font-size: 0.86rem;
    font-weight: 600;
  }
  .voice-show-text:hover,
  #voice-review #voice-replay:hover { color: var(--accent-2); border-color: var(--accent); background: var(--accent-soft); }
  .voice-show-text::before,
  #voice-review #voice-replay::before {
    content: '';
    width: 1rem;
    height: 1rem;
    background: currentColor;
    -webkit-mask: var(--icon-replay) center / contain no-repeat;
    mask: var(--icon-replay) center / contain no-repeat;
  }
  .voice-show-text::before {
    -webkit-mask-image: var(--icon-text);
    mask-image: var(--icon-text);
  }

  /* The body: what was said — the pills and their explanations, the message
     text, the feedback on the learner's reply — scrolling on its own under
     the fixed top. Top-anchored, so what lands in it only ever grows
     downward and nothing already there moves. */
  .voice-call-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    padding: 0.9rem 0.25rem 1rem;
  }
  /* Compact, the status holds one line (at this size every prompt fits one
     on a desktop), and the review row slims down. */
  .voice-call-compact #voice-status { margin-top: 0.4rem; min-height: 1.3em; font-size: 1.1rem; }
  .voice-call-compact #voice-review { min-height: 2.1rem; margin-top: 0.35rem; }
  /* At the feedback gate the row has nothing to offer until the next message
     is heard, and the body's content is swapped then anyway: its room goes
     to the feedback. */
  #voice-mode[data-phase="feedback"] .voice-call-compact #voice-review { display: none !important; }
  .voice-call-compact .voice-show-text,
  .voice-call-compact #voice-review #voice-replay { padding: 0.28rem 0.8rem 0.28rem 0.65rem; font-size: 0.82rem; }
  .voice-call-compact .voice-call-body { padding-top: 0.6rem; }
  .voice-call-body > .voice-panel {
    flex: none;
    max-width: 38rem;
    padding: 0.95rem 1.2rem 1.1rem;
    border-radius: var(--radius-lg);
  }
  /* Between the reply being sent and the next message being spoken the
     pills panel holds nothing to answer (the next message's pills wait,
     hidden, for their words): out of the way of the feedback, then back. */
  #voice-mode[data-phase="sending"] #voice-understanding,
  #voice-mode[data-phase="feedback"] #voice-understanding { display: none; }
  /* A message with no pills leaves nothing to answer: no empty card either,
     so the tutor keeps the room. */
  #voice-understanding:not(:has(.chip)) { display: none; }
  .voice-transcript-panel {
    padding: 0.95rem 1.2rem 1.1rem;
    background: var(--surface-2);
    border-color: transparent;
    box-shadow: none;
  }
  .voice-transcript-words { font-size: 1.05rem; line-height: 1.65; }
  /* The feedback shows only while it has something in it: outside the gate
     it is empty, and an empty panel in the call would be a hole. */
  #voice-feedback:not(:has(#voice-correction:not([hidden]), #voice-cards > *)) { display: none; }
  .voice-said { font-size: 0.98rem; padding: 0.5rem 0.85rem; }

  /* ---- The foot: the mic, or the gate's continue button ------------------ */
  /* One row, so the call body above keeps the height: the live waveform to
     the mic's left (its newest bar beside the mic), the label to its right,
     the mic on the call's centre line whatever their widths. */
  .voice-foot {
    grid-column: 1;
    grid-row: 2;
    position: relative;
    inset: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    /* Wide enough for the recording halo at its fullest. */
    column-gap: 2rem;
    padding: 0.6rem 1.5rem clamp(1.1rem, 3vh, 1.75rem);
    pointer-events: auto;
  }
  .voice-foot > * { grid-row: 1; }
  #voice-mic,
  .voice-feedback-continue { grid-column: 2; }
  #voice-hint { grid-column: 3; justify-self: start; text-align: left; }
  .voice-wave {
    grid-column: 1;
    justify-self: end;
    width: min(12rem, 100%);
    height: 2.4rem;
    border-radius: 0;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  #voice-mic {
    position: relative;
    width: 5rem;
    height: 5rem;
    box-shadow: 0 0 0 7px var(--accent-soft), var(--shadow-lg);
    transition: transform 0.12s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
  }
  #voice-mic svg { width: 32px; height: 32px; }
  #voice-mic:hover:not(:disabled) { box-shadow: 0 0 0 11px var(--accent-soft), var(--shadow-lg); }
  /* Recording: the halo follows the learner's voice (voice.ts sets
     --mic-level from the same samples as the waveform) instead of pulsing on
     a timer — it swells when they are heard and stays still when they aren't. */
  #voice-mic.recording,
  #voice-mic.recording:hover:not(:disabled) {
    animation: none;
    box-shadow:
      0 0 0 calc(7px + var(--mic-level, 0) * 13px) color-mix(in srgb, var(--bad) 22%, transparent),
      var(--shadow-lg);
    transition: box-shadow 60ms linear, background 0.2s var(--ease);
  }
  /* Sending: a ring turns round the (disabled) mic until the tutor answers. */
  #voice-mode[data-phase="sending"] #voice-mic::after {
    content: '';
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    animation: voice-spin 0.9s linear infinite;
  }
  @keyframes voice-spin { to { transform: rotate(1turn); } }
  #voice-hint {
    /* Positioned so the label paints over the mic's halo at its widest. */
    position: relative;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    font-size: 0.9rem;
    color: var(--muted);
  }
  .voice-feedback-continue {
    padding: 0.95rem 1.6rem 0.95rem 1.9rem;
    font-size: 1.02rem;
    box-shadow: 0 0 0 7px var(--accent-soft), var(--shadow-lg);
  }
  .voice-feedback-continue:disabled { box-shadow: none; }

  /* ---- Overflow you can see (voice.ts markOverflow) ---------------------- */
  /* The call body and the word list scroll on their own, so their scrollbar
     is drawn, always, in the accent (a Mac otherwise hides it until you
     scroll). Its gutter is kept even when nothing overflows, so content never
     shifts when it comes. Only an edge with more beyond it fades. */
  .voice-call-body,
  .voice-turn .voice-panel-body {
    --fade-top: 0rem;
    --fade-bottom: 0rem;
    scrollbar-gutter: stable;
    /* The fades, and a solid strip down the right that keeps the scrollbar
       itself out of them. */
    -webkit-mask:
      linear-gradient(transparent, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent),
      linear-gradient(#000, #000) right / 12px 100% no-repeat;
    mask:
      linear-gradient(transparent, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent),
      linear-gradient(#000, #000) right / 12px 100% no-repeat;
  }
  .voice-call-body { scrollbar-gutter: stable both-edges; }
  .voice-call-body[data-more-above],
  .voice-turn .voice-panel-body[data-more-above] { --fade-top: 1.5rem; }
  .voice-call-body[data-more-below],
  .voice-turn .voice-panel-body[data-more-below] { --fade-bottom: 1.5rem; }
  .voice-call-body::-webkit-scrollbar,
  .voice-turn .voice-panel-body::-webkit-scrollbar { width: 10px; }
  .voice-call-body::-webkit-scrollbar-track,
  .voice-turn .voice-panel-body::-webkit-scrollbar-track {
    margin: 0.4rem 0;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--border) 55%, transparent);
    background-clip: padding-box;
    border: 3px solid transparent;
  }
  .voice-call-body::-webkit-scrollbar-thumb,
  .voice-turn .voice-panel-body::-webkit-scrollbar-thumb {
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--accent) 60%, transparent);
    background-clip: padding-box;
    border: 2px solid transparent;
  }
  .voice-call-body::-webkit-scrollbar-thumb:hover,
  .voice-turn .voice-panel-body::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }
  @supports not selector(::-webkit-scrollbar) {
    .voice-call-body,
    .voice-turn .voice-panel-body {
      scrollbar-width: thin;
      scrollbar-color: color-mix(in srgb, var(--accent) 60%, transparent) transparent;
    }
  }

  /* ---- The rail ---------------------------------------------------------- */
  .voice-turn {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  /* The words' card runs the rail's full height, level with the call. Its
     title stays put and the list scrolls inside the card when eight long
     items outgrow it, fading at the edges rather than being cut. */
  .voice-turn .voice-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 1.05rem 0.6rem 0.4rem;
    border-radius: 28px;
    box-shadow: var(--shadow-md);
  }
  .voice-turn .voice-panel-title { padding: 0 0.55rem; }
  .voice-turn .voice-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0.35rem 0.55rem 0.9rem;
  }
  .voice-panel-inactive { opacity: 0.6; }
  /* The live region: the one the phase asks the learner to act on. */
  .voice-turn .voice-panel:not(.voice-panel-inactive),
  #voice-understanding:not(.voice-panel-inactive),
  #voice-feedback:not(.voice-panel-inactive) {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-md);
  }

  /* Panel titles: a heading with an icon rather than the phone's small caps. */
  .voice-panel-title {
    margin: 0 0 0.5rem;
    font-size: 0.98rem;
    font-weight: 650;
    letter-spacing: -0.005em;
    text-transform: none;
    color: var(--ink);
  }
  .voice-panel-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }
  .voice-panel-toggle::before {
    content: '';
    flex: none;
    width: 1.15rem;
    height: 1.15rem;
    background: var(--accent-2);
    -webkit-mask: var(--icon, none) center / contain no-repeat;
    mask: var(--icon, none) center / contain no-repeat;
  }
  .voice-panel-toggle::after { margin: 0 0.15rem 0 auto; }
  #voice-understanding { --icon: var(--icon-listen); }
  #voice-prod-panel { --icon: var(--icon-say); }
  #voice-feedback { --icon: var(--icon-check); }
  #voice-transcript { --icon: var(--icon-text); }
  .voice-panel-collapsed { padding: 0.8rem 1.2rem; }
  /* Legends line up under the title's words, past its icon. */
  .voice-panel-hint,
  .voice-transcript-hint { margin: -0.2rem 0 0.8rem; padding-left: 1.75rem; font-size: 0.8rem; }

  /* The pills, a size up: the call has the width. */
  #voice-chips { gap: 0.5rem; }
  #voice-chips .chip,
  #voice-chips .chip.graded-got,
  #voice-chips .chip.graded-missed { font-size: 0.92rem; padding: 0.2rem 0.28rem 0.2rem 0.8rem; gap: 0.35rem; }
  #voice-chips .chip button { width: 2.05rem; height: 2.05rem; }
  #voice-chips .chip button + button { margin-left: 0.15rem; }

  /* The words to use: the tiles above (one layout everywhere), a size up. */
  #voice-production { gap: 0.45rem; }
  .voice-prod-card { padding: 0.6rem 0.6rem 0.6rem 0.8rem; }
  .voice-prod-head .form-es { font-size: 1.02rem; }

  /* A chapter talk has no pills and no words to use: the call alone, centred. */
  #voice-mode[data-driver="chapter"] { --voice-max: 52rem; }
  #voice-mode[data-driver="chapter"] .voice-stage-inner { grid-template-columns: minmax(0, 1fr); }
  #voice-mode[data-driver="chapter"] .voice-turn,
  #voice-mode[data-driver="chapter"] #voice-understanding { display: none; }
}

/* A short desktop window: a smaller orb, status and mic buy the call body the
   room for the message text and the feedback. */
@media (min-width: 801px) and (max-height: 760px) {
  .voice-orb { --orb: clamp(5rem, 15vh, 8rem); }
  .voice-head { padding: 0.6rem 0; }
  .voice-call { --call-top: clamp(1rem, 10vh, 4rem); }
  .voice-call-compact { --call-top: 0.8rem; }
  .voice-call-compact .voice-orb { --orb: 3rem; }
  .voice-call-compact #voice-status { font-size: 1rem; }
  #voice-status { font-size: 1.12rem; }
  #voice-mic { width: 4.4rem; height: 4.4rem; }
  .voice-wave { height: 2rem; }
  .voice-call-body { padding-top: 0.6rem; }
}

@keyframes prod-bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
}
@media (prefers-reduced-motion: reduce) {
  .prod-bubble.entering { animation: none; }
}

/* ---------------------------------------------------------------------------
   Mobile — single column; production items become a floating horizontal reel
   relocated above the composer by main.ts.
   --------------------------------------------------------------------------- */

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
    max-width: none;
    height: 100vh;
    height: 100dvh;
  }
  #chat-pane {
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  .billing-alert {
    align-items: stretch;
    flex-direction: column;
    gap: 0.5rem;
  }
  .billing-alert button { width: 100%; }
  .msg { max-width: 85%; }

  /* The chat header's back pill shrinks to a bare chevron so the tutor's
     name and status keep one line each. The label stays in the DOM (hidden
     by font-size: 0), so it is still the button's accessible name. */
  #chat-back {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    font-size: 0;
  }
  #chat-back::before {
    content: '‹';
    font-size: 1.35rem;
    line-height: 1;
    margin-top: -0.12rem; /* optical centre: the glyph sits high in its box */
  }

  /* In the chat the goal banner sits straight on the progress strip instead
     of being a card inside it (a box within a box on a phone). A met goal
     tints the whole strip gold instead of the card. */
  #progress-strip .daily-goal {
    padding: 0;
    border: none;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }
  #progress-strip .daily-goal:hover { transform: none; box-shadow: none; }
  #progress-strip:has(.daily-goal--done) { background: var(--gold-soft); }

  /* Stripped of desktop chrome — a flex wrapper with suggestions pulled above
     the heading too (they already precede the reel in the DOM) and the reel
     itself sitting just above the composer. Positioned (no z-index, so no
     stacking context for the onboarding lift to fight) to anchor the bubble. */
  #side-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    overflow: visible;
    box-shadow: none;
  }
  #side-pane > h2 {
    display: block;
    margin: 0;
    padding: 0.45rem 0.85rem 0.15rem;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(10px);
    color: var(--ink-soft);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  #side-pane > p.muted { display: none; }
  #suggestions { order: -1; }
  /* The pane doesn't scroll on phones (the reel is a fixed-height strip), so
     a tray with many notes would grow past the viewport, squeeze the chat to
     nothing and push the composer off screen with no way to reach the rest.
     Cap it and scroll it on its own; the header stays put so the tray can
     still be folded away from wherever the learner has scrolled to. */
  #suggestions:not(:empty) {
    padding: 0 0.75rem 0;
    max-height: 45vh;
    max-height: 45dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  #suggestions .suggestions-header {
    position: sticky;
    top: 0;
    /* Above the notes, whose finished entry animation (msg-in keeps its end
       transform) makes each a stacking context that would paint over it.
       A leaf of the tray, so no ancestor of the onboarding lift is touched. */
    z-index: 1;
    margin-top: 0;
    padding: 0.5rem 0.1rem 0.2rem;
    background: var(--surface);
  }

  /* Horizontal, swipeable, floating reel of one-line pills: the term and a
     glimpse of its cue. The whole cue and the reveal live in the bubble a tap
     on the pill opens. */
  #production-list {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    /* Snap a pill clear of the edge, so the active pill's ring isn't clipped. */
    scroll-padding-inline: 0.85rem;
    padding: 0.3rem 0.85rem 0.6rem;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(10px);
    box-shadow: 0 -8px 24px rgba(35, 46, 123, 0.14);
    scrollbar-width: none;
  }
  #production-list::-webkit-scrollbar { display: none; }
  #production-list .prod-card {
    flex: 0 0 auto;
    max-width: 75vw;
    padding: 0.4rem 0.6rem;
    margin-top: 0;
    font-size: 0.78rem;
    scroll-snap-align: start;
    white-space: nowrap;
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease), box-shadow 0.15s var(--ease);
  }
  #production-list .prod-card:hover { transform: none; }
  /* The popped-out pill: tinted and ringed while its bubble is open. */
  #production-list .prod-card.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
  }
  /* The rare extra-long phrase is capped above and ellipsised here so it
     can't spill over the next pill; the bubble shows it whole. */
  #production-list .prod-card .form-es,
  #production-list .prod-card .prod-cue {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #production-list .prod-card .form-es { flex: 0 1 auto; font-size: 0.86rem; }
  /* The cue says which sense is wanted, so the pill keeps a glimpse of it —
     enough to show there is one and prompt a tap for the rest in the bubble.
     It is a whole scenario sentence, so it gives way before the term does (a
     far higher shrink weight) and is capped well short of its full length. */
  #production-list .prod-card .prod-cue {
    flex: 0 100 auto;
    max-width: 7.5rem;
    margin-left: 0;
  }
  #production-list .prod-toggle::before { width: 0.45rem; height: 0.45rem; }
  #production-list > .muted { margin: 0; align-self: center; }

  /* The pop-out bubble over the conversation, just above the bar (main.ts
     sets `bottom` from the heading and --arrow-x from the tapped pill). */
  .prod-bubble:not([hidden]) {
    display: block;
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    z-index: 6;
    padding: 0.75rem 2.75rem 0.85rem 0.95rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    touch-action: pan-y;
    transition: transform 0.18s var(--ease), opacity 0.18s var(--ease);
  }
  .prod-bubble.dragging { transition: none; }
  .prod-bubble.entering {
    animation: prod-bubble-in 0.18s var(--ease);
    transform-origin: var(--arrow-x, 50%) 100%;
  }
  .prod-bubble::after {
    content: "";
    position: absolute;
    bottom: -7px;
    left: var(--arrow-x, 50%);
    width: 12px;
    height: 12px;
    margin-left: -6px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transform: rotate(45deg);
  }
  .prod-bubble-close {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
  }
  .prod-bubble-close:hover,
  .prod-bubble-close:focus-visible { background: var(--accent-soft); color: var(--accent-2); }
  .prod-bubble-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
  }
  .prod-bubble-head::before {
    content: "";
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent-2);
  }
  .prod-bubble[data-kind="phrase"] .prod-bubble-head::before { background: var(--accent); }
  .prod-bubble[data-kind="grammar"] .prod-bubble-head::before { background: var(--good); }
  .prod-bubble-head .form-es { font-weight: 700; font-size: 1.02rem; }
  /* Cue, example and explanation line up under the term, past the dot. */
  .prod-bubble-cue,
  .prod-bubble .example,
  .prod-bubble .how-to-use,
  .prod-bubble .revealed,
  .prod-bubble .reveal { margin-left: 0.95rem; }
  .prod-bubble-cue {
    margin-top: 0.2rem;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.35;
  }
  .prod-bubble .kind { display: none; }
  .prod-bubble .example {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.86rem;
    font-style: italic;
    line-height: 1.35;
  }
  .prod-bubble .how-to-use {
    margin-top: 0.3rem;
    color: var(--ink-soft);
    font-size: 0.86rem;
    line-height: 1.35;
  }
  .prod-bubble .how-to-use b { color: var(--accent-2); font-weight: 600; }
  .prod-bubble .revealed { margin-top: 0.55rem; font-size: 0.86rem; }
  .prod-bubble .revealed:empty { display: none; }
  .prod-bubble .reveal {
    display: block;
    margin-top: 0.6rem;
    padding: 0.32rem 0.75rem;
    font: inherit;
    font-size: 0.78rem;
    background: none;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-pill);
    color: var(--accent-2);
    cursor: pointer;
  }
  .prod-bubble .reveal:hover { border-color: var(--accent); background: var(--accent-soft); }

  /* -------------------------------------------------------------------------
     Voice mode on a phone.

     A phone gets roughly a third of the desktop's vertical room, and the desktop
     layout spends its top ~250px on chrome (a tutor avatar, a separate orb below
     it, and a two-line status) before the first piece of content. That pushed the
     active region — and the mic — clean off the bottom of the screen: on the
     reply phase the learner was told "use the words below" while the words were
     entirely below the fold. Two moves buy the space back.

     1. One speaking indicator, on the centre line. Two accent circles stacked
        down the middle said the same thing twice, so the standalone orb goes
        and the header carries the state instead — but as a presence dot rather
        than an avatar: a full-size disc beside the name straddles the header's
        centre line, so the eye reads the orange blob as off-centre no matter
        how exactly the pair is centred. The dot does the orb's whole job
        (pulsing while the tutor speaks, receding on the learner's turn) beside
        a name that now sits on the axis. Worth ~7rem of dead height.
     2. (Historical) inactive regions folding to their title bar started here as
        a phone-only move; it is now the universal one-region-open policy — see
        the fold block above this query. Only the header/status sizing below
        remains phone-specific.
     ------------------------------------------------------------------------- */
  .voice-orb { display: none; }
  /* The markup groups the regions for the wide layout (the call, the rail);
     with those wrappers out of the box tree, this puts them back in the
     phone's order: the review row sits under the pills it is about. */
  #voice-status { order: 1; }
  #voice-transcript { order: 2; }
  #voice-understanding { order: 3; }
  #voice-review { order: 4; }
  #voice-feedback { order: 5; }
  #voice-prod-panel { order: 6; }
  .voice-head { padding: 0.45rem 0.2rem; }
  .voice-head-meta { gap: 0.45rem; }
  /* The goal chip earns its header slot on a phone by staying tiny. */
  .voice-goal { padding: 0.25rem 0.55rem; font-size: 0.72rem; }
  .speaker-voice-btn { padding: 0.2rem 0.45rem; }
  /* On a phone the tutor's name and the voice's would crowd the head: the
     pill keeps its icon, and the list says whose voice it is. */
  .speaker-voice-name { display: none; }
  .voice-head-meta .avatar {
    width: 0.5rem;
    height: 0.5rem;
    /* The initial is decoration at this size — the name it stands for is right
       beside it. */
    font-size: 0;
    box-shadow: none;
    transition: opacity 0.25s var(--ease);
  }
  #voice-mode[data-phase="speaking"] .voice-head-meta .avatar,
  #voice-mode[data-phase="loading"] .voice-head-meta .avatar {
    animation: voice-dot-pulse 1.5s var(--ease) infinite;
  }
  /* The orb's ring scaled to a dot — 1.1rem of halo would swamp it. */
  @keyframes voice-dot-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-soft); }
    50% { transform: scale(1.15); box-shadow: 0 0 0 0.42rem transparent; }
  }
  /* The learner's turn: the tutor recedes, as the orb did. */
  #voice-mode[data-phase="reply"] .voice-head-meta .avatar,
  #voice-mode[data-phase="recording"] .voice-head-meta .avatar,
  #voice-mode[data-phase="sending"] .voice-head-meta .avatar,
  #voice-mode[data-phase="feedback"] .voice-head-meta .avatar { opacity: 0.3; }

  /* Tighter all round: the stage is the scarce resource now. */
  #voice-stage { padding: 0.5rem 0; }
  .voice-stage-inner { gap: 0.7rem; }
  /* The status is the instruction on a phone — there is no transcript beside it
     to carry the turn — so it takes the weight the orb used to have. */
  #voice-status {
    /* Every status is written to fit one line (see the note on min-height), and
       1rem is the size that holds them at 390px — but the widest of them, in
       French, needs the full 328px a 360px phone has and would wrap on a 320px
       one. So the size is fluid below that and only reaches its 1rem cap once
       the screen is wide enough to take it: 4.6vw is the slope at which the
       widest string tracks the available width, less a margin for the device
       fonts that are wider than the one measured here. */
    font-size: clamp(0.82rem, 4.6vw - 1.5px, 1rem);
    font-weight: 600;
    line-height: 1.35;
    color: var(--ink);
    /* One line, and exactly one: the desktop reserves a second so a 1↔2-line
       status can't shove the regions below it, but on a phone that reserve was
       pure hole — so the prompts were cut to fit one line in all three UI
       languages instead, which buys back the line AND keeps the regions still.
       Anything that does overflow it (a raw error message, which is unbounded)
       grows the block rather than being clipped. */
    min-height: 1.35em;
  }

  /* (Panel folding is global now — see the fold block above the phone query.)
     The reply items keep the compact tiles of the base rules. */

  /* The review slot costs 4.4rem whenever it shows; a phone can spare less. */
  .voice-review { min-height: 3.2rem; }
  .voice-foot { padding-bottom: calc(0.9rem + env(safe-area-inset-bottom)); }
  #voice-mic { width: 4rem; height: 4rem; }
  #voice-mode[data-phase="reply"] .voice-stage-inner,
  #voice-mode[data-phase="recording"] .voice-stage-inner,
  #voice-mode[data-phase="sending"] .voice-stage-inner { padding-bottom: 7.5rem; }
  #voice-mode[data-phase="feedback"] .voice-stage-inner { padding-bottom: 5rem; }
}

/* ---------------------------------------------------------------------------
   Dark theme
   --------------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  .tickoff-bar-thumb canvas { background: linear-gradient(180deg, #252a5c 0%, #2c2f5e 60%, #343259 100%); }
  .home-plate.is-roomy .tickoff-bar-thumb canvas { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06); }
}
@media (prefers-color-scheme: dark) {
  :root {
    /* Deep-navy ground (not gray) — the public pages' dark palette, extended with
       an extra surface step for the app's denser chrome. */
    --bg: #0f1236;
    --bg-grad-1: #171c4a;
    --bg-grad-2: #0e1133;
    --surface: #222962;
    --surface-2: #2a326e;
    --surface-3: #353f83;
    --ink: #f4efe3;
    --ink-soft: #cdd0ea;
    --muted: #9aa0cd;
    --border: #3a4390;
    --border-strong: #4d57a6;

    /* Lavender becomes the legible accent on navy; deep violet keeps the
       filled controls (CTAs, user bubbles) with white text on top, and
       lavender fills carry navy text (--accent-ink). */
    --accent: #b7a5f0;
    --accent-2: #cfc4f6;
    --accent-strong: #7b5fd8;
    --work-copy: #ff8c42;
    --work-copy-ink: #1b1f4d;
    --accent-soft: #342b6d;
    --accent-ink: #232e7b;
    --bubble-bot: #2e3675;
    --bubble-bot-ink: #f4efe3;

    --good-soft: #16301f;
    --bad-soft: #3a1c19;
    --gold-soft: #322a12;

    --shadow-sm: 0 1px 2px rgba(4, 6, 24, 0.35), 0 1px 3px rgba(4, 6, 24, 0.25);
    --shadow-md: 0 4px 12px rgba(4, 6, 24, 0.4), 0 2px 4px rgba(4, 6, 24, 0.3);
    --shadow-lg: 0 12px 32px rgba(4, 6, 24, 0.5), 0 4px 10px rgba(4, 6, 24, 0.35);

    color-scheme: dark;
  }
  #app-loading { background: rgba(15, 17, 46, 0.6); }
  dialog#placement-modal::backdrop {
    background: radial-gradient(1200px 800px at 80% -10%, #171c4a, #0e1133);
  }
  /* White on the dark scheme's lighter muted fails contrast; keep the "don't
     know" probe state legible with near-black-navy text instead. */
  .probe button.selected-none { color: #10143c; }
  .tickoff-stage { background: linear-gradient(#060b1e, #22305a 72%, #1e2233 72%); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------------------
   Reading mode — a chapter at one of six CEFR sub-levels (src/client/reading.ts)

   A fixed full-screen overlay above the app, a SIBLING of .layout like voice
   mode (the onboarding tour's stacking rules). The words are the same global
   .hw-word buttons as the message-help pop-up; the gloss card reuses
   .msg-help-gloss, docked to the bottom edge so it never covers the tapped
   word; the "Explain" pill floats beside a multi-word selection.
   --------------------------------------------------------------------------- */

#reading-mode {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#reading-mode[hidden] { display: none; }

.reading-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
#reading-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
#reading-back:hover { color: var(--ink); border-color: var(--muted); }
.reading-head-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.reading-head-meta strong {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reading-head-meta .muted { font-size: 0.78rem; }
.reading-level-badge {
  justify-self: end;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.reading-level-badge[hidden] { display: none; }
.reading-levels {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.reading-level-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.reading-level-btn:hover:not(:disabled) { color: var(--ink); }
.reading-level-btn[aria-pressed="true"] { background: var(--accent-strong); color: var(--on-accent); }
.reading-level-btn:disabled { opacity: 0.35; cursor: default; }

/* The library: "currently reading" then every other book, one card each with
   its level pills and a start/continue button. */
.reading-library {
  max-width: 42rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.reading-library[hidden] { display: none; }
.reading-library-hint { margin: 0 0 0.4rem; font-size: 0.9rem; }
.reading-book {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-md);
}
.reading-book-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.reading-book-author { margin: 0.15rem 0 0.2rem; font-size: 0.85rem; }
.reading-book-length { margin: 0 0 0.8rem; font-size: 0.8rem; }
.reading-book-progress {
  margin: 0 0 0.8rem;
  font-size: 0.85rem;
  color: var(--accent-2);
  font-weight: 600;
}
.reading-section-title {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.reading-book-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
}
.reading-book-level {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
}
.reading-open-btn {
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s var(--ease), transform 0.12s var(--ease);
}
.reading-open-btn:hover { filter: brightness(1.04); }
.reading-open-btn:active { transform: scale(0.97); }
/* Chapter headings inside the flowing book text. */
.reading-chapter-heading {
  margin: 2rem 0 1rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}
.reading-chapter-heading:first-child { margin-top: 0.4rem; padding-top: 0; border-top: none; }

.reading-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.2rem 1rem;
  -webkit-overflow-scrolling: touch;
}
.reading-article {
  max-width: 42rem;
  margin: 0 auto;
  /* Room under the last paragraph so the docked gloss never hides it. */
  padding-bottom: 45vh;
}
.reading-article[hidden] { display: none; }
.reading-chapter-label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.reading-title {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.45rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.reading-meta { margin: 0; font-size: 0.82rem; }
.reading-hint { margin: 0.6rem 0 1.2rem; font-size: 0.82rem; }
.reading-chapters-text .reading-para {
  margin: 0 0 1.15rem;
  font-size: 1.12rem;
  line-height: 1.8;
  color: var(--ink);
  /* Word buttons flow inline; keep the selection colour readable over them. */
}
/* Tighter than the pop-up's word buttons so a comma sits flush against its
   word; the hover/looked-up background still covers the word itself. */
.reading-chapters-text .reading-para .hw-word { padding: 0.04em 0.08em; margin: 0 -0.08em; }
.reading-status {
  max-width: 42rem;
  margin: 1rem auto;
  text-align: center;
}
.reading-status[hidden] { display: none; }

.reading-explain {
  position: fixed;
  z-index: 1600;
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  animation: msg-in 0.15s var(--ease) both;
}
.reading-explain[hidden] { display: none; }

.reading-gloss {
  position: fixed;
  z-index: 1600;
  left: 1rem;
  right: 1rem;
  bottom: calc(env(safe-area-inset-bottom) + 1rem);
  max-width: 42rem;
  margin: 0 auto;
  max-height: 40vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  /* .msg-help-gloss's entrance animation fills its final transform; a fixed
     card centred by auto margins needs neither. */
  animation: none;
  transform: none;
}
.reading-gloss[hidden] { display: none; }

@media (max-width: 640px) {
  .reading-head {
    grid-template-columns: auto 1fr;
    gap: 0.5rem 0.75rem;
    padding: 0.6rem 0.75rem;
  }
  .reading-book-actions { flex-direction: column; align-items: stretch; }
  .reading-open-btn { width: 100%; }
  .reading-body { padding: 1rem 0.9rem; }
  .reading-chapters-text .reading-para { font-size: 1.08rem; line-height: 1.75; }
}

/* ---------------------------------------------------------------------------
   The Listen view (src/client/listening.ts): the library of clips, and a clip
   — the player on top, one question at a time, then the score and the
   transcript. A full-screen overlay like the Read view, its head shared.
   --------------------------------------------------------------------------- */
#listen-mode {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#listen-mode[hidden] { display: none; }
.listen-back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.listen-back-btn:hover { color: var(--ink); border-color: var(--muted); }
.listen-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.2rem 1rem 3rem;
  -webkit-overflow-scrolling: touch;
}
.listen-library, .listen-clip { max-width: 42rem; margin: 0 auto; }
.listen-library[hidden], .listen-clip[hidden] { display: none; }
.listen-intro { margin: 0 0 0.8rem; font-size: 0.92rem; }
.listen-levels {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.listen-level-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}
.listen-level-btn[aria-pressed="true"] { background: var(--accent-strong); color: var(--on-accent); }
.listen-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.listen-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.8rem;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.12s var(--ease), transform 0.12s var(--ease);
}
.listen-card:hover { border-color: var(--accent); }
.listen-card:active { transform: scale(0.99); }
.listen-card-title { grid-column: 1; font-weight: 700; font-size: 1.02rem; line-height: 1.3; }
.listen-card-prog { grid-column: 1; font-size: 0.82rem; color: var(--muted); }
.listen-card-meta { grid-column: 1; font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.listen-card-level { font-weight: 700; color: var(--accent-2); }
.listen-card-state {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}
.listen-card-state.is-done { color: var(--good); }

/* The player stays on top while the questions scroll under it. */
.listen-player {
  position: sticky;
  top: -1.2rem;
  z-index: 2;
  margin: -1.2rem -1rem 1rem;
  padding: 0.8rem 1rem 0.7rem;
  background: var(--accent-strong);
  color: var(--on-accent);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.listen-player-top { display: flex; align-items: center; gap: 0.6rem; }
.listen-play {
  flex: none;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  background: #fff;
  cursor: pointer;
  position: relative;
}
.listen-play::before {
  content: '';
  position: absolute;
  left: 52%;
  top: 50%;
  transform: translate(-40%, -50%);
  border-left: 0.85rem solid var(--accent-strong);
  border-top: 0.55rem solid transparent;
  border-bottom: 0.55rem solid transparent;
}
.listen-play.is-playing::before {
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0.75rem;
  height: 0.95rem;
  border: none;
  border-left: 0.26rem solid var(--accent-strong);
  border-right: 0.26rem solid var(--accent-strong);
  box-sizing: border-box;
}
.listen-back5 {
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.3rem 0.55rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.listen-seek { flex: 1 1 auto; min-width: 0; accent-color: #fff; }
.listen-time { flex: none; font-size: 0.8rem; font-variant-numeric: tabular-nums; opacity: 0.9; }
.listen-player-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.55rem; font-size: 0.78rem; }
.listen-speed-label { opacity: 0.8; margin-right: 0.15rem; }
.listen-speed {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.listen-speed[aria-pressed="true"] { background: #fff; color: var(--accent-strong); border-color: #fff; }
.listen-note { margin-left: auto; opacity: 0.85; }

.listen-how { margin: 0 0 0.8rem; font-size: 0.9rem; }
.listen-native-toggle {
  display: inline-block;
  margin: 0 0 0.8rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.listen-native-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-2); }
.listen-q, .listen-done {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--shadow-md);
}
.listen-q-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; }
.listen-q-count { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.listen-type {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-2);
}
.listen-dots { display: inline-flex; gap: 0.3rem; margin-left: auto; }
.listen-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--surface-3); }
.listen-dot.is-now { background: var(--accent); }
.listen-dot.is-right { background: var(--good); }
.listen-dot.is-wrong { background: var(--bad); }
.listen-q-text { margin: 0.7rem 0 0.9rem; font-size: 1.12rem; font-weight: 600; line-height: 1.45; }
.listen-q-text.is-statement { padding-left: 0.75rem; border-left: 3px solid var(--accent); }
.listen-es, .listen-native { display: block; }
.listen-native { margin-top: 0.2rem; font-size: 0.86em; font-weight: 400; color: var(--muted); }
.listen-said-hint { margin: -0.4rem 0 0.8rem; font-size: 0.82rem; }
.listen-options, .listen-said { display: grid; gap: 0.5rem; }
.listen-said { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.listen-option {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.98rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.12s var(--ease), background 0.12s var(--ease);
}
.listen-option:hover:not(:disabled) { border-color: var(--accent); }
.listen-option:disabled { cursor: default; }
.listen-said-btn { justify-content: center; text-align: center; font-weight: 600; }
.listen-letter {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.listen-option.is-right { border-color: var(--good); background: var(--good-soft); }
.listen-option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.listen-option.is-faded { opacity: 0.55; }
.listen-typed { display: flex; gap: 0.5rem; }
.listen-typed-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  padding: 0.65rem 0.8rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.listen-typed-input:focus { outline: none; border-color: var(--accent); }
.listen-check, .listen-next, .listen-primary {
  flex: none;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font: inherit;
  font-weight: 600;
  background: var(--accent-strong);
  color: var(--on-accent);
  cursor: pointer;
}
.listen-check:disabled { opacity: 0.5; cursor: default; }
/* Scrolled to just under the player, which stays on top. */
.listen-feedback, .listen-q, .listen-done { scroll-margin-top: 8.5rem; }
.listen-feedback {
  margin-top: 1rem;
  padding: 0.85rem 0.95rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.listen-feedback.is-right { border-color: var(--good); }
.listen-feedback.is-wrong { border-color: var(--bad); }
.listen-verdict { margin: 0 0 0.3rem; font-weight: 700; }
.listen-feedback.is-right .listen-verdict { color: var(--good); }
.listen-feedback.is-wrong .listen-verdict { color: var(--bad); }
.listen-key { margin: 0 0 0.4rem; }
.listen-why { margin: 0 0 0.7rem; font-size: 0.92rem; line-height: 1.5; }
.listen-evidence-k { margin: 0 0 0.35rem; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.listen-evidence, .listen-transcript { display: grid; gap: 0.35rem; }
.listen-line {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 10px);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
}
.listen-line:hover { border-color: var(--accent); }
.listen-line.is-on { border-color: var(--accent); background: var(--accent-soft); }
.listen-line-play { flex: none; color: var(--accent); font-size: 0.72rem; margin-top: 0.3rem; }
.listen-spans { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.listen-span {
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent-2);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.listen-span.is-on { background: var(--accent-soft); }
.listen-later { margin: 0.7rem 0 0; font-size: 0.8rem; }
.listen-review-why { grid-column: 2; font-size: 0.86rem; color: var(--muted); }
.listen-next { margin-top: 0.9rem; }
.listen-done-score { margin: 0 0 0.8rem; font-size: 1.25rem; font-weight: 700; }
.listen-review { margin: 0 0 1.2rem; padding: 0; list-style: none; display: grid; gap: 0.55rem; }
.listen-review li { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.55rem; font-size: 0.92rem; line-height: 1.45; }
.listen-review-mark { grid-row: span 2; font-weight: 700; }
.listen-review li.is-right .listen-review-mark { color: var(--good); }
.listen-review li.is-wrong .listen-review-mark { color: var(--bad); }
.listen-review-a { font-size: 0.86rem; color: var(--ink-soft); }
.listen-transcript-k { margin: 0 0 0.2rem; font-size: 1rem; }
.listen-transcript-hint { margin: 0 0 0.6rem; font-size: 0.82rem; }
.listen-credit { margin: 1rem 0 0; font-size: 0.78rem; line-height: 1.5; }
.listen-credit a { color: inherit; }
/* A finished clip's ways on, alone in the last row: the main one filled, Home
   beside it outlined. On a phone they share the width, a footer. */
.listen-done-actions { display: flex; gap: 0.6rem; margin-top: 1rem; }
@media (max-width: 640px) {
  .listen-done-actions > button { flex: 1 1 0; }
}
/* Answering again: a quiet link after the score. */
.listen-link {
  border: none;
  background: none;
  padding: 0;
  margin-left: 0.3rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  white-space: nowrap;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}
.listen-link:hover { color: var(--ink); }
.listen-secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
@media (max-width: 640px) {
  /* The clip's level stays on the title's row. */
  .reading-head.listen-head { grid-template-columns: auto 1fr auto; }
  .listen-head .reading-head-meta .muted { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  .listen-body { padding: 1rem 0.9rem 3rem; }
  .listen-player { top: -1rem; margin: -1rem -0.9rem 1rem; }
  .listen-said { grid-template-columns: 1fr; }
  .listen-q, .listen-done { padding: 0.9rem 0.9rem 1rem; }
}

/* ---------------------------------------------------------------------------
   Learner-led conversations — Ask, and the talk about a chapter
   (src/client/main.ts). The same chat pane as Practise in a single column:
   no progress strip, no side pane, no chips. The schedule drives only
   Practise.
   --------------------------------------------------------------------------- */

/* One column, narrower than the two-column practise layout. */
.layout.single { grid-template-columns: minmax(0, 1fr); max-width: 820px; }
.layout.single #side-pane { display: none; }
.layout.single #progress-strip { display: none; }
/* Sending an automatic reply makes no sense when the learner leads. */
.layout.single .auto-reply { display: none; }
.layout.single #composer .composer-field textarea { padding-left: 1.05rem; }

/* Ask: the first-language aside under a reply about the language itself. */
.msg-aside {
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border-strong);
  font-size: 0.86rem;
  color: var(--ink-soft);
}

/* The card at the top of a chapter talk: what the thread is about. */
.chapter-card {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.chapter-card-spine { flex: none; width: 30px; height: 40px; border-radius: 4px; background: var(--accent-strong); }
.chapter-card-title { font-weight: 700; }
.chapter-card-sub { font-size: 0.8rem; color: var(--muted); }

/* Inside a book, after each chapter: the one link into conversation. */
.reading-talk {
  margin: 1.5rem 0 0.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.reading-talk-title { margin: 0; font-size: 0.95rem; font-weight: 700; }
.reading-talk-desc { margin: 0; font-size: 0.82rem; color: var(--muted); }
.reading-talk-row { display: flex; gap: 0.45rem; margin-top: 0.2rem; }
.reading-talk-row button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.reading-talk-row .reading-talk-text { border: none; background: var(--accent-strong); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.reading-talk-row .reading-talk-voice { border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-soft); }
.reading-talk-row .reading-talk-voice:hover { border-color: var(--accent); color: var(--ink); }
.reading-talk-row .home-icon { width: 16px; height: 16px; }

/* A row's focus (row-focus.ts, DESIGN.md §8 "A row's focus"): the mentor's
   one thing to mind, in a band under the head of the screen a row of the
   day opens — its label, then the mentor's words, a line or two on a phone. */
.row-focus {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.35;
}
.row-focus[hidden] { display: none; }
.row-focus-k { flex: none; font-size: 0.66rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-2); }
.row-focus-v { min-width: 0; max-width: 40rem; font-weight: 600; overflow-wrap: anywhere; }
/* Talk and the task sheet have no head band to hang it from: a rounded box. */
#voice-focus,
#task-sheet-focus {
  align-self: center;
  max-width: min(100%, 42rem);
  margin: 0 0 0.6rem;
  border: 0;
  border-radius: var(--radius-sm);
}
#task-sheet-focus { justify-content: flex-start; margin: 0 0 0.9rem; }

/* Voice mode in a chapter talk: the caption under the head; no production panel. */
.voice-context {
  margin: 0 0 0.4rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-2);
}
.voice-context[hidden] { display: none; }
#voice-mode[data-driver="chapter"] #voice-prod-panel { display: none; }

/* A part of the day's Talk done (voice.ts showBatchDone): a line in the
   window under the head saying the next part comes later in the plan, with
   Home and "keep talking". It moves the call down; it never covers it. */
.voice-batch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.9rem;
  margin: 0 0 0.6rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--good);
  border-radius: var(--radius);
  background: var(--good-soft);
  color: var(--ink);
  font-size: 0.88rem;
  animation: voice-batch-in 0.25s var(--ease);
}
.voice-batch[hidden] { display: none; }
.voice-batch-text { flex: 1 1 18rem; margin: 0; line-height: 1.4; }
.voice-batch-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.voice-batch-actions button {
  padding: 0.4rem 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.voice-batch-actions #voice-batch-home { border-color: var(--accent-strong); background: var(--accent-strong); color: var(--on-accent); }
@keyframes voice-batch-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .voice-batch { animation: none; } }

/* ---------------------------------------------------------------------------
   Lessons — the week the tutor scheduled, and one lesson full-screen
   (src/client/lessons.ts, DESIGN.md §9). A fixed full-screen overlay like
   reading and voice mode — a SIBLING of .layout, never inside it (the
   onboarding tour's stacking rules). The head reuses the reading head; the
   messages reuse the chat's .msg / .bubble; target-language sentences are
   tap-to-hear chips.
   --------------------------------------------------------------------------- */

#lesson-mode {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 0 0;
}
#lesson-mode[hidden] { display: none; }
#lesson-mode .reading-head { grid-template-columns: auto 1fr; }
#lesson-mode .ghost-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
#lesson-mode .ghost-btn:hover { border-color: var(--accent); color: var(--ink); }

/* The step bar: the lesson's steps as a row of pills, done ones ticked. */
.lesson-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  scrollbar-width: none;
}
.lesson-steps::-webkit-scrollbar { display: none; }
.lesson-steps[hidden] { display: none; }
.lesson-steps-track {
  display: flex;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.lesson-step {
  flex: none;
  padding: 0.22rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.lesson-step.done { color: var(--accent-2); border-color: var(--accent-soft); background: var(--accent-soft); }
.lesson-step.done::before { content: '✓ '; }
.lesson-step.current { color: var(--on-accent); background: var(--accent-strong); border-color: var(--accent-strong); font-variant-numeric: tabular-nums; }

.lesson-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.2rem 1rem 1.6rem;
  -webkit-overflow-scrolling: touch;
}

/* The week: to do, coming up, done — one card per lesson. */
.lesson-week {
  max-width: 42rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.lesson-week[hidden] { display: none; }
.lesson-empty { text-align: center; margin: 2rem 0; }
.lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-md);
}
/* A later day's lesson, beyond today's plan: flat, its border dashed. */
.lesson-card[data-status="ahead"] { box-shadow: none; background: var(--surface-2); border-style: dashed; }
.lesson-section-note { margin: -0.3rem 0 0; font-size: 0.88rem; line-height: 1.45; }
.lesson-card-title { margin: 0; font-size: 1.15rem; line-height: 1.3; letter-spacing: -0.01em; }
.lesson-card-note { margin: 0.25rem 0 0.8rem; font-size: 0.9rem; line-height: 1.45; }
.lesson-card-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.lesson-card-state { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.lesson-card[data-status="started"] .lesson-card-state { color: var(--accent-2); }
.lesson-tag {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
}
.lesson-tag.overdue { color: var(--bad); background: var(--bad-soft); }
.lesson-tag.repeat { color: var(--accent-2); background: var(--surface-2); }
.lesson-card-btn {
  margin-left: auto;
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.5rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s var(--ease), transform 0.12s var(--ease);
}
.lesson-card-btn:hover { filter: brightness(1.04); }
.lesson-card-btn:active { transform: scale(0.97); }
#lesson-mode .lesson-card-btn.ghost-btn { background: var(--surface); color: var(--ink-soft); }
.lesson-card-btn:disabled { opacity: 0.5; cursor: default; filter: none; transform: none; }

/* One lesson: the teacher's messages and the learner's answers. */
.lesson-thread {
  max-width: 44rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.lesson-thread[hidden] { display: none; }
.lesson-thread .msg.bot { max-width: 88%; }
.lesson-thread .msg .bubble strong { font-weight: 700; }
/* A teacher's message as Markdown (lessons.ts renderText): the basics, spaced
   for reading on a phone. */
/* Lines a little tighter than other bubbles', paragraphs further apart, so a
   long message reads as paragraphs. */
.lesson-thread .msg .bubble { line-height: 1.4; }
.lesson-thread .bubble.md > :first-child { margin-top: 0; }
.lesson-thread .bubble.md > :last-child { margin-bottom: 0; }
.lesson-thread .bubble.md p { margin: 0.85em 0; }
.lesson-thread .bubble.md h4 { margin: 0.8em 0 0.3em; font-size: 1em; font-weight: 700; }
.lesson-thread .bubble.md ul,
.lesson-thread .bubble.md ol { margin: 0.85em 0; padding-left: 1.3em; }
.lesson-thread .bubble.md li { margin: 0.35em 0; padding-left: 0.1em; }
.lesson-thread .bubble.md li > p { margin: 0.2em 0; }
.lesson-thread .bubble.md li::marker { color: var(--muted); }
.lesson-thread .bubble.md em { font-style: italic; }
.lesson-thread .bubble.md code { font-size: 0.9em; background: var(--surface); border-radius: 4px; padding: 0.05em 0.3em; }
.lesson-thread .bubble.md pre { margin: 0.6em 0; padding: 0.5em 0.7em; overflow-x: auto; background: var(--surface); border-radius: var(--radius-sm); }
.lesson-thread .bubble.md pre code { background: none; padding: 0; white-space: pre; }
.lesson-thread .bubble.md blockquote { margin: 0.6em 0; padding-left: 0.8em; border-left: 3px solid var(--border); color: var(--ink-soft); }
.lesson-thread .bubble.md hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.lesson-thread .bubble.md .md-table { margin: 0.6em 0; overflow-x: auto; }
.lesson-thread .bubble.md table { border-collapse: collapse; font-size: 0.92em; }
.lesson-thread .bubble.md th,
.lesson-thread .bubble.md td { padding: 0.3em 0.6em; text-align: left; border-bottom: 1px solid var(--border); }
.lesson-credit { margin: 0.4rem 0 0; text-align: center; font-size: 0.75rem; line-height: 1.4; overflow-wrap: anywhere; }
.lesson-credit + .lesson-credit { margin-top: 0; }
.lesson-credit a { color: inherit; }
/* A first open, waiting on the model: its stages, a bar and the time left. */
.lesson-opening {
  margin: 1.5rem auto 0;
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.2rem 1.2rem;
  box-shadow: var(--shadow-md);
  animation: app-loading-in 0.25s ease-out;
}
.lesson-opening-title { margin: 0 0 0.8rem; font-size: 1.1rem; line-height: 1.3; letter-spacing: -0.01em; }
.lesson-opening-bar { height: 0.5rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.lesson-opening-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s linear;
}
.lesson-opening-left { margin: 0.45rem 0 0.9rem; font-size: 0.85rem; }
.lesson-opening-stages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.lesson-opening-stages li { display: flex; align-items: center; gap: 0.6rem; font-size: 0.95rem; line-height: 1.35; }
.lesson-opening-stages li[data-state="todo"] { color: var(--muted); }
.lesson-opening-stages li[data-state="now"] { font-weight: 600; }
.lesson-opening-mark {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  box-sizing: border-box;
}
.lesson-opening-stages li[data-state="now"] .lesson-opening-mark {
  border-color: var(--accent);
  border-right-color: transparent;
  animation: app-spin 0.9s linear infinite;
}
.lesson-opening-stages li[data-state="done"] .lesson-opening-mark {
  border-color: var(--good);
  background: var(--good);
  position: relative;
}
.lesson-opening-stages li[data-state="done"] .lesson-opening-mark::after {
  content: '';
  position: absolute;
  left: 0.27rem;
  top: 0.1rem;
  width: 0.25rem;
  height: 0.5rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .lesson-opening { animation: none; }
  .lesson-opening-bar > span { transition: none; }
  .lesson-opening-stages li[data-state="now"] .lesson-opening-mark { animation: none; border-right-color: var(--accent); }
}
/* A target-language sentence: a chip that plays it (TTS). */
/* It runs in the line like words: inline, so it is no taller than the text
   around it and a long sentence wraps across lines, each line its own small
   box (box-decoration-break) rather than one tall pill. */
.lesson-target {
  display: inline;
  padding: 0.02em 0.28em;
  border: 1px solid var(--accent);
  border-radius: 0.4em;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.lesson-target[role="button"] { cursor: pointer; transition: background 0.15s var(--ease); }
.lesson-target[role="button"]:hover { background: var(--accent-soft); }
.lesson-target[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lesson-target.playing { background: var(--accent-soft); }
.lesson-target.loading { opacity: 0.6; }
.lesson-target.heard { font-style: italic; color: var(--accent-2); }
.lesson-target-icon { font-size: 0.72em; margin-right: 0.25em; vertical-align: 0.08em; }
.lesson-hint-tag {
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
}
.lesson-thread .bubble.spoken::before { content: '🎙 '; }
/* How an answer was marked, under the learner's bubble. */
.lesson-outcome {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-pill);
}
.lesson-outcome[data-outcome="correct"],
.lesson-outcome[data-outcome="accepted"] { color: var(--good); background: var(--good-soft); }
.lesson-outcome[data-outcome="incorrect"] { color: var(--bad); background: var(--bad-soft); }
.lesson-typing { align-self: flex-start; }

/* The end of a lesson: what it graded. */
.lesson-summary {
  margin-top: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  animation: msg-in 0.26s var(--ease) both;
}
.lesson-summary h2 { margin: 0; font-size: 1.2rem; }
.lesson-score { margin: 0; font-size: 1rem; font-weight: 700; color: var(--accent-2); }
.lesson-results { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
.lesson-results li { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.92rem; }
.lesson-result-mark { font-weight: 800; }
.lesson-results li[data-grade="got-it"] .lesson-result-mark { color: var(--good); }
.lesson-results li[data-grade="missed-it"] .lesson-result-mark { color: var(--bad); }
.lesson-result-text { font-weight: 600; }
.lesson-result-skill { font-size: 0.8rem; }
.lesson-summary .lesson-card-btn { margin-left: 0; align-self: flex-start; }

/* The answer box: "I'm stuck" and the keyboard/mic switch, then one of the two. */
.lesson-foot {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
}
.lesson-foot[hidden] { display: none; }
.lesson-foot-row,
.lesson-write,
.lesson-speak { max-width: 44rem; margin: 0 auto; }
.lesson-foot-row { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.lesson-stuck,
.lesson-switch {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--ink-soft);
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.lesson-stuck:hover,
.lesson-switch:hover { border-color: var(--accent); color: var(--ink); }
.lesson-stuck[hidden],
.lesson-switch[hidden] { display: none; }
.lesson-stuck:disabled,
.lesson-switch:disabled { opacity: 0.5; cursor: default; }
.lesson-write { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.55rem; }
.lesson-write[hidden] { display: none; }
.lesson-accents { flex: 1 0 100%; display: flex; gap: 0.3rem; overflow-x: auto; scrollbar-width: none; }
.lesson-accents[hidden] { display: none; }
#lesson-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: 1.4rem;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--surface);
  max-height: 140px;
}
#lesson-input:focus { outline: none; border-color: var(--accent); }
.lesson-speak { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.lesson-speak[hidden] { display: none; }
.lesson-mic {
  width: 4rem;
  height: 4rem;
  border: none;
  border-radius: 50%;
  background: var(--accent-strong);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.12s var(--ease), background 0.15s var(--ease);
}
.lesson-mic:active { transform: scale(0.95); }
.lesson-mic:disabled { opacity: 0.5; cursor: default; }
.lesson-mic.recording { background: var(--bad); animation: lesson-mic-pulse 1.2s var(--ease) infinite; }
@keyframes lesson-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(223, 79, 58, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(223, 79, 58, 0); }
}
.lesson-mic-hint { margin: 0; font-size: 0.82rem; }

dialog.lesson-leave {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  max-width: 400px;
  width: calc(100% - 2rem);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
dialog.lesson-leave[open] { animation: modal-in 0.25s var(--ease) both; }
dialog.lesson-leave h2 { margin: 0 0 0.4rem; font-size: 1.15rem; }
dialog.lesson-leave p { margin: 0 0 1rem; line-height: 1.45; }
.lesson-leave-actions { display: flex; flex-direction: column; gap: 0.5rem; }

/* A custom task's sheet (task-sheet.ts): the task in the mentor's words. */
dialog.task-sheet {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.3rem 1.4rem 1.4rem;
  max-width: 420px;
  width: calc(100% - 2rem);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
dialog.task-sheet[open] { animation: modal-in 0.25s var(--ease) both; }
.task-sheet-kind { margin: 0 0 0.45rem; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
dialog.task-sheet h2 { margin: 0 0 0.6rem; font-size: 1.2rem; line-height: 1.3; overflow-wrap: anywhere; }
.task-sheet-note { margin: 0 0 0.9rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; color: var(--ink-soft); }
.task-sheet-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.2rem;
  color: var(--accent-strong);
  font-weight: 650;
  text-decoration: none;
}
.task-sheet-link::after { content: '↗'; font-size: 0.9em; }
.task-sheet-link:hover { text-decoration: underline; }
.task-sheet-host { margin: 0 0 0.9rem; font-size: 0.82rem; overflow-wrap: anywhere; }
.task-sheet-status { margin: 0 0 0.9rem; font-weight: 700; color: var(--good); }
.task-sheet-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.3rem; }
.task-sheet-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: var(--radius-pill);
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
@media (hover: hover) { .task-sheet-btn:hover { background: var(--surface-2); } }
.task-sheet-btn:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 640px) {
  .lesson-steps { padding: 0.5rem 0.75rem; justify-content: flex-start; }
  .lesson-body { padding: 1rem 0.8rem 1.4rem; }
  .lesson-thread .msg.bot { max-width: 94%; }
  .lesson-card-btn { flex: 1 0 100%; margin-left: 0; }
}

/* A day that keeps to the tutor's order (ProgressDto.planEnforced): a row not
   open yet is faded, with a lock where its chevron was; a tap on it nudges
   the row that comes first. */
.day-row.is-locked { opacity: 0.5; cursor: not-allowed; }
.day-row.is-locked::after {
  content: "🔒";
  width: auto;
  height: auto;
  margin-right: 0;
  border: 0;
  transform: none;
  font-size: 0.8rem;
  opacity: 0.9;
}
@media (hover: hover) { .day-row.is-locked:hover { background: none; } }
.day-row.is-nudged { animation: day-row-nudge 420ms ease-in-out; }
@keyframes day-row-nudge { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { .day-row.is-nudged { animation: none; } }

/* ---------------------------------------------------------------------------
   Cards (quick-review.ts, DESIGN.md §5 "Quick reviews"): the texting reviews
   done on cards, full screen, before the chat. A card turns over in 3D: the
   first language on its front, the item on its back. The chat's button to the
   cards that come back sits in the side pane above the words to use.
   --------------------------------------------------------------------------- */

.quick-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-2);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease);
}
.quick-open[hidden] { display: none; }
.quick-open::before { content: '🃏'; margin-right: 0.1rem; }
.quick-open::after { content: '›'; margin-left: auto; font-size: 1.15rem; line-height: 1; }
.quick-open:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.quick-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Nothing to do yet: the cards answered a moment ago come back in a few minutes. */
.quick-open.is-waiting {
  border-color: var(--border);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 500;
}
@media (max-width: 800px) {
  /* A slim row in the bar above the reel of words to use. */
  .quick-open {
    margin: 0;
    padding: 0.4rem 0.85rem;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    font-size: 0.84rem;
  }
  .quick-open:hover { transform: none; box-shadow: none; }
}

#cards-mode {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 0 0;
}
#cards-mode[hidden] { display: none; }
#cards-mode .reading-head { grid-template-columns: auto 1fr auto; }
.cards-count {
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cards-count:empty { display: none; }
.cards-body {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
}
.cards-progress { flex: none; }
.cards-track { display: block; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
#cards-fill { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--good); transition: width 0.4s var(--ease); }
.cards-line { flex: none; min-height: 1.35rem; margin: 0.45rem 0 0.3rem; text-align: center; font-size: 0.86rem; font-weight: 600; line-height: 1.4; color: var(--muted); }
.cards-line .cards-good { color: var(--good); }
.cards-line .cards-bad { color: var(--bad); }
.cards-line .cards-fixed { font-weight: 500; color: var(--ink-soft); }
.cards-line .cards-fixed [lang] { color: var(--good); font-weight: 700; }

.cards-deck {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
  perspective: 1400px;
}
.cards-card,
.cards-ghost {
  grid-area: 1 / 1;
  width: min(100cqw, calc((100cqh - 30px) * 0.75));
  aspect-ratio: 3 / 4;
  margin-bottom: 22px;
}
.cards-ghost {
  transform-origin: 50% 100%;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  transform: translateY(11px) scale(0.95);
  opacity: 0.85;
  box-shadow: var(--shadow-sm);
}
.cards-ghost.is-second { transform: translateY(22px) scale(0.9); opacity: 0.55; }
.cards-card { position: relative; cursor: pointer; animation: cards-in 0.35s var(--ease) both; }
@keyframes cards-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
.cards-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.2, 1); }
.cards-card.is-turned { cursor: default; }
.cards-card.is-turned .cards-inner { transform: rotateY(180deg); }
.cards-side {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.2rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 16px 36px rgba(35, 46, 123, 0.14), 0 3px 8px rgba(35, 46, 123, 0.07);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  text-align: center;
  overflow: hidden;
}
.cards-back {
  transform: rotateY(180deg);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: linear-gradient(165deg, var(--surface) 35%, var(--accent-soft));
}
.cards-tag {
  align-self: flex-start;
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.cards-tag--back { background: var(--accent); color: var(--on-accent); }
.cards-new {
  position: absolute;
  top: 1.1rem;
  right: 1.2rem;
  padding: 0.3rem 0.7rem;
  border-radius: 99px;
  background: var(--gold-soft);
  color: #8a6414;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.cards-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0.7rem; width: 100%; }
.cards-word { color: var(--ink); font-size: 2.1rem; font-weight: 800; line-height: 1.12; letter-spacing: -0.02em; text-wrap: balance; overflow-wrap: anywhere; }
.cards-from { color: var(--muted); font-size: 0.88rem; font-weight: 600; }
.cards-cue { color: var(--ink-soft); font-size: 1rem; line-height: 1.45; text-wrap: balance; }
.cards-cue b { color: var(--ink); }
/* A marked-word card asks from its sentence: it is the card's whole face. */
.cards-cue--marked { color: var(--ink); font-size: 1.3rem; font-weight: 600; line-height: 1.4; }
.cards-cue--marked b { color: var(--accent-2); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.cards-pointer { padding: 0.2rem 0.65rem; border-radius: 99px; background: var(--gold-soft); color: #8a6414; font-size: 0.8rem; font-weight: 700; }
.cards-rule { max-width: 24rem; color: var(--ink); font-size: 1.25rem; font-weight: 700; line-height: 1.35; text-wrap: balance; }
.cards-gender { margin-top: -0.4rem; color: var(--muted); font-size: 0.85rem; font-style: italic; }
.cards-hint { display: flex; align-items: center; justify-content: center; gap: 0.45rem; color: var(--muted); font-size: 0.85rem; font-weight: 650; }
.cards-hint svg,
.cards-play svg,
.cards-turn svg,
.cards-mark svg,
.cards-next svg,
.cards-stamp svg,
.cards-end-badge svg { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cards-play {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 99px;
  background: var(--surface);
  color: var(--accent-2);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.cards-play.is-loading { opacity: 0.6; }
.cards-back .card-note {
  flex: none;
  width: 100%;
  margin: 0;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: left;
}
.cards-stamp {
  position: absolute;
  top: 0.95rem;
  right: 0.95rem;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  box-shadow: 0 6px 14px rgba(46, 140, 90, 0.35);
}
.cards-stamp[hidden] { display: none; }

.cards-foot { flex: none; margin-top: 0.9rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.cards-foot > :only-child,
.cards-foot > .cards-type,
.cards-foot > .cards-give-up,
.cards-foot > .cards-next,
.cards-foot > .cards-turn { grid-column: 1 / -1; }
.cards-turn,
.cards-next,
.cards-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.2rem;
  padding: 0 1rem;
  border-radius: 99px;
  font: inherit;
  font-size: 1rem;
  font-weight: 750;
  cursor: pointer;
}
.cards-turn,
.cards-next { border: 0; background: var(--accent-strong); color: #fff; box-shadow: 0 8px 20px rgba(35, 46, 123, 0.22); }
.cards-mark { border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--ink-soft); }
.cards-mark.cards-no { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.cards-mark.cards-yes { color: var(--good); border-color: var(--good); }
.cards-foot button:disabled { opacity: 0.55; cursor: default; }
.cards-foot kbd {
  display: none;
  min-width: 1.3rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font: 700 0.68rem/1.3 var(--font);
}
@media (hover: hover) and (min-width: 900px) { .cards-foot kbd { display: inline-block; } }
.cards-type { display: grid; gap: 0.5rem; }
.cards-accents { display: flex; gap: 0.3rem; overflow-x: auto; scrollbar-width: none; }
.cards-type-row { display: flex; gap: 0.5rem; }
.cards-type input {
  flex: 1 1 auto;
  min-width: 0;
  height: 3.2rem;
  padding: 0 1rem;
  border: 1.5px solid var(--accent);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.cards-type input:focus { outline: none; }
.cards-check { flex: none; height: 3.2rem; padding: 0 1.3rem; border: 0; border-radius: 14px; background: var(--accent-strong); color: #fff; font: inherit; font-weight: 750; cursor: pointer; }
.cards-give-up { justify-self: center; border: none; background: none; color: var(--ink-soft); font: inherit; font-size: 0.9rem; text-decoration: underline; cursor: pointer; }

.cards-end { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.8rem; text-align: center; }
.cards-end-badge {
  display: grid;
  place-items: center;
  width: 5.2rem;
  height: 5.2rem;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  box-shadow: 0 0 0 10px var(--good-soft), 0 14px 30px rgba(46, 140, 90, 0.3);
}
.cards-end-badge svg { width: 2.4rem; height: 2.4rem; stroke-width: 3; }
.cards-end h2 { margin: 0.6rem 0 0; color: var(--ink); font-size: 1.5rem; font-weight: 800; letter-spacing: -0.015em; }
.cards-end-later { max-width: 22rem; margin: 0; color: var(--ink-soft); line-height: 1.45; }
.cards-loading { align-self: center; }
/* What each part of a card is for (Joe, 2026-11-22): the box at the card's
   foot (2026-11-23; it was at the top) says what to do and how much; every
   other part has a small label. */
.cards-task {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.3;
  text-align: left;
}
.cards-task svg,
.cards-verdict-head svg { flex: none; width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cards-label { color: var(--muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: -0.4rem; text-wrap: balance; }
.cards-example { color: var(--muted); font-size: 0.95rem; font-style: italic; line-height: 1.45; text-wrap: balance; }
.cards-example b { color: var(--ink-soft); font-style: normal; }
.cards-word-small { color: var(--ink); font-size: 1.15rem; font-weight: 750; }
/* A card's small words (small-words.ts): the strip sits tight under the word. */
.cards-main .sw-strip { margin-top: -0.2rem; max-width: 26rem; }
.cards-from mark.sw { box-shadow: none; }
.cards-forms { max-width: 24rem; color: var(--ink-soft); font-size: 0.95rem; line-height: 1.45; text-wrap: balance; }
.cards-noteline { max-width: 22rem; color: var(--muted); font-size: 0.85rem; font-weight: 600; line-height: 1.4; text-wrap: balance; }
/* Big is what you write (Joe, 2026-11-27): an underlined-words card leads
   with those words, the sentence small under them to show how they fit, and
   its box at the foot names them in a chip. */
.cards-word--marked { text-decoration: underline; text-decoration-color: var(--accent-2); text-decoration-thickness: 3px; text-underline-offset: 7px; }
.cards-cue--context { margin-top: 0.4rem; color: var(--ink-soft); font-weight: 500; }
.cards-cue--context b { color: var(--ink); font-weight: 750; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.cards-task-words { padding: 0.02em 0.4em; border-radius: 6px; background: var(--surface); color: var(--ink); font-weight: 850; }
.cards-task-words.is-marked { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
/* With the result box under it, the card takes the deck's whole width: a
   narrow card would break its word over lines. */
.cards-deck.has-verdict .cards-card,
.cards-deck.has-verdict .cards-ghost { width: 100cqw; height: calc(100cqh - 30px); aspect-ratio: auto; }
.cards-seen {
  position: absolute;
  top: 1.1rem;
  right: 1.2rem;
  padding: 0.3rem 0.7rem;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
}

/* The result of a typed card, large under it (Joe, 2026-11-22: the reason
   was small grey text at the top, easy to miss). */
.cards-verdict {
  flex: none;
  max-height: 45%;
  overflow-y: auto;
  margin-top: 0.7rem;
  padding: 0.75rem 0.95rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  line-height: 1.45;
  animation: cards-in 0.25s var(--ease) both;
}
.cards-verdict[hidden] { display: none; }
.cards-verdict-head { display: flex; align-items: center; gap: 0.45rem; font-size: 1.05rem; font-weight: 800; }
.cards-verdict p { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.93rem; }
.cards-verdict p b { color: var(--ink); }
.cards-verdict i { color: var(--ink); }
.cards-verdict.is-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 55%, transparent); }
.cards-verdict.is-good .cards-verdict-head { color: var(--good); }
.cards-verdict.is-bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.cards-verdict.is-bad .cards-verdict-head { color: var(--bad); }
.cards-verdict.is-other { background: var(--gold-soft); border-color: var(--gold); }
.cards-verdict.is-other .cards-verdict-head { color: color-mix(in srgb, var(--gold) 55%, var(--ink)); }
.cards-verdict-after { font-weight: 600; }
.cards-two { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; margin-top: 0.35rem; font-size: 0.93rem; }
.cards-two span:nth-child(odd) { color: var(--muted); font-weight: 700; }
.cards-two .is-ok { color: var(--good); font-weight: 750; }
.cards-two .is-no { color: var(--ink); font-weight: 750; }
.cards-said { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--border-strong); color: var(--ink); font-size: 1rem; }
.cards-said-label { display: block; margin-bottom: 0.15rem; color: var(--muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.cards-said .correction-fix { cursor: default; }
.cards-settle svg { opacity: 0.75; }


@media (min-width: 900px) {
  .cards-body { max-width: 620px; padding-top: 1.4rem; }
  .cards-word { font-size: 2.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .cards-inner { transition: none; }
  .cards-card { animation: none; }
}

/* ===========================================================================
   Practice screens (shadowing, drills): one frame, src/client/practice-frame.ts
   A `.practice-mode` overlay (a sibling of `.layout`, like lesson mode):
     .reading-head        ‹ Home | the kind's name over "3 of 10 min today" | .practice-count
     .practice-bar        the sitting's items: progressBar()
     .practice-body > .practice-col   a centred column: .practice-from, .practice-card …
     .practice-foot > .practice-foot-in   a small button left, the one main
                          action in the middle (.practice-main, or the mic),
                          a small one right; .is-wide gives the middle the row.
   =========================================================================== */
.practice-mode {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-grad-1), var(--bg-grad-2));
  padding: env(safe-area-inset-top) 0 0;
}
.practice-mode[hidden] { display: none; }
.practice-mode .reading-head { grid-template-columns: auto 1fr auto; }
.practice-count {
  justify-self: end;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Up to 20 items, a pill each; more, one continuous track (progressBar). */
.practice-bar {
  display: flex;
  gap: 0.3rem;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.practice-bar i { flex: 0 1 1.6rem; height: 0.32rem; border-radius: var(--radius-pill); background: var(--surface-3); }
.practice-bar i.is-done { background: var(--good); }
.practice-bar i.is-part { background: var(--gold); }
.practice-bar i.is-miss { background: var(--bad); }
.practice-bar i.is-now { background: var(--accent-strong); }
.practice-bar-track {
  display: flex;
  width: min(100%, 34rem);
  height: 0.32rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}
.practice-bar-track span { height: 100%; }
.practice-bar-track .is-done { background: var(--good); }
.practice-bar-track .is-part { background: var(--gold); }
.practice-bar-track .is-miss { background: var(--bad); }
.practice-bar-track .is-now { min-width: 0.4rem; background: var(--accent-strong); }
.practice-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1.1rem 1rem 1.4rem;
}
.practice-col {
  width: 100%;
  max-width: 34rem;
  margin: 0.6rem auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  text-align: center;
}
.practice-from {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.practice-from b {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink-soft);
}
.practice-card {
  width: 100%;
  padding: 1.05rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.practice-foot {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem max(0.9rem, env(safe-area-inset-right)) calc(0.8rem + env(safe-area-inset-bottom)) max(0.9rem, env(safe-area-inset-left));
}
.practice-foot-in {
  max-width: 34rem;
  min-height: 6.1rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
}
.practice-foot-in > :first-child { justify-self: start; }
.practice-foot-in > :last-child { justify-self: end; }
.practice-foot-in.is-wide { grid-template-columns: 1fr; }
.practice-foot-in.is-wide > * { justify-self: stretch; }
.practice-side {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.practice-side.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.practice-main {
  padding: 0.85rem 1.6rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent-strong);
  color: var(--on-accent);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}
.practice-main:disabled, .practice-side:disabled { opacity: 0.5; cursor: default; }
@media (min-width: 801px) {
  .practice-col { max-width: 38rem; margin-top: 2.5rem; }
  .practice-card { padding: 1.4rem 1.6rem; }
}

/* ---------------------------------------------------------------------------
   Dictation (#dictate-mode, client/dictation.ts; DESIGN.md §8 "Dictation")
   On the practice frame (above). What is dictation's own: the clip's context
   (a card over a new clip's first chunk, a line after), the chunk's player
   with "what comes before", the box, and the words marked and lit.
   --------------------------------------------------------------------------- */
#dictate-mode .practice-col { align-items: stretch; }
#dictate-mode .practice-from { text-align: center; }
.dict-context { display: flex; flex-direction: column; gap: 0.35rem; text-align: left; background: var(--accent-soft); border-color: transparent; box-shadow: none; }
.dict-context h2 { margin: 0; font-size: 1.12rem; line-height: 1.3; color: var(--ink); text-wrap: balance; }
.dict-context p { margin: 0; color: var(--ink-soft); }
#dictate-mode .dict-context .practice-from { text-align: left; }
.dict-programme { font-size: 0.8rem; }
.dict-card { display: flex; flex-direction: column; gap: 0.75rem; text-align: left; }
.dict-player { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 0.75rem; border-radius: var(--radius-lg); background: var(--accent-strong); color: var(--on-accent); }
.dict-play { flex: none; width: 3.1rem; height: 3.1rem; border: none; border-radius: 50%; background: var(--surface); color: var(--accent-strong); display: grid; place-items: center; cursor: pointer; }
.dict-player-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.dict-player-mid b { font-size: 0.95rem; }
.dict-track { display: block; height: 0.25rem; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--on-accent) 25%, transparent); overflow: hidden; }
.dict-track i { display: block; height: 100%; width: 0; background: var(--on-accent); }
.dict-plays { font-size: 0.78rem; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dict-names { margin: 0; font-size: 0.88rem; color: var(--ink-soft); }
.dict-names b { font-weight: 650; color: var(--ink); background: var(--surface-3); border-radius: 0.35rem; padding: 0.05rem 0.35rem; }
.dict-before { align-self: flex-start; padding: 0.4rem 0.8rem; border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--ink-soft); font: inherit; font-size: 0.85rem; font-weight: 650; cursor: pointer; }
.dict-write { display: flex; flex-direction: column; gap: 0.45rem; text-align: left; }
.dict-hint { font-size: 0.85rem; color: var(--muted); }
#dictate-input { width: 100%; min-height: 5.5rem; resize: vertical; padding: 0.7rem 0.85rem; border: 1.5px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.05rem; line-height: 1.45; }
#dictate-input:focus { outline: none; border-color: var(--accent); }
.dict-accents { flex: none; }
.dict-keys { margin: 0; font-size: 0.78rem; }
.dict-status { margin: 0; font-size: 0.88rem; color: var(--bad); text-align: center; }
.dict-score { margin: 0; color: var(--ink-soft); }
.dict-score b { margin-right: 0.25rem; font-size: 1.5rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.dict-marked { margin: 0; font-size: 1.12rem; line-height: 2.5; }
.dict-w { display: inline-flex; flex-direction: column; align-items: center; vertical-align: top; padding: 0 0.2rem; border-radius: 0.35rem; line-height: 1.4; }
.dict-w small { font-size: 0.72rem; line-height: 1.1; white-space: nowrap; }
.dict-w.is-right { color: var(--good); }
.dict-w.is-accent, .dict-w.is-spelling, .dict-w.is-near { color: var(--gold); background: var(--gold-soft); }
.dict-w.is-wrong { color: var(--bad); background: var(--bad-soft); }
.dict-w.is-missed { color: var(--bad); text-decoration: underline dashed; text-underline-offset: 0.3rem; }
.dict-w.is-opt, .dict-w.is-given { color: var(--muted); }
.dict-w.is-given { text-decoration: underline dotted; text-underline-offset: 0.3rem; }
.dict-w.is-extra { color: var(--bad); text-decoration: line-through; font-size: 0.85em; }
.dict-w.is-lit { background: var(--gold-soft); color: var(--ink); box-shadow: 0 0 0 2px var(--gold); }
.dict-legend { margin: 0; display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; font-size: 0.78rem; color: var(--ink-soft); }
.dict-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.dict-legend i { width: 0.6rem; height: 0.6rem; border-radius: 0.15rem; background: var(--muted); }
.dict-legend .is-right i { background: var(--good); }
.dict-legend .is-accent i, .dict-legend .is-spelling i, .dict-legend .is-near i { background: var(--gold); }
.dict-legend .is-wrong i, .dict-legend .is-missed i, .dict-legend .is-extra i { background: var(--bad); }
.dict-credit { margin: 0; font-size: 0.75rem; text-align: center; }
.dict-end { text-align: center; }
.dict-end h2 { margin: 0 0 0.4rem; }
@media (prefers-reduced-motion: no-preference) { .dict-w { transition: background 0.08s, box-shadow 0.08s; } }

/* ---------------------------------------------------------------------------
   Spoken drills (#drill-mode, client/drills.ts; DESIGN.md §9 "Spoken drills")
   On the practice frame (above): its head, bar, column and foot. What is the
   drills' own: the sentence's card, read left to right; what was said, marked;
   the verdict; the sentence to hear; the hint; and the end of a round. The
   card is anchored at the top and grows downward as marks come in, so nothing
   above it moves.
   --------------------------------------------------------------------------- */
#drill-mode .practice-col { align-items: stretch; text-align: left; }
#drill-mode .practice-from { text-align: center; }
#drill-mode .practice-foot-in > .drill-mic-wrap { grid-column: 2; }
#drill-mode .practice-foot-in > .practice-main { grid-column: 2; }
#drill-mode .practice-foot-in > .drill-switch { grid-column: 3; justify-self: end; }
#drill-mode [hidden] { display: none !important; }
.drill-ask { margin: 0; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.drill-en { margin: 0.3rem 0 0; font-size: 1.32rem; line-height: 1.3; font-weight: 750; letter-spacing: -0.01em; color: var(--ink); overflow-wrap: anywhere; }
.drill-hint { margin: 0.75rem 0 0; padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); background: var(--gold-soft); color: var(--ink-soft); font-size: 0.86rem; line-height: 1.4; }
.drill-case { margin: 0.6rem 0 0; color: var(--ink-soft); font-size: 0.86rem; line-height: 1.4; }
.drill-case span { color: var(--muted, var(--ink-soft)); text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.72rem; margin-right: 0.25rem; }
.drill-hint b { color: var(--ink); }
.drill-said { margin-top: 0.95rem; padding-top: 0.85rem; border-top: 1px solid var(--border); }
.drill-said-k { margin: 0 0 0.2rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.drill-said-v { margin: 0; font-size: 1.02rem; line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.drill-said-v .is-slip { color: var(--bad); font-weight: 700; text-decoration: underline wavy var(--bad); text-decoration-thickness: 1px; text-underline-offset: 4px; }
/* A slip outside the drilled grammar, on an answer marked right: fixed, not counted. */
.drill-said-v:not(.is-wrong) .is-slip { color: var(--ink); text-decoration-color: var(--gold); }
.drill-verdict { display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 0.85rem; padding: 0.7rem 0.8rem; border-radius: var(--radius); font-size: 0.9rem; line-height: 1.45; }
.drill-verdict .mark { flex: none; display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; color: #fff; font-weight: 800; font-size: 0.9rem; }
.drill-verdict p { margin: 0; color: var(--ink-soft); }
.drill-verdict p b { color: var(--ink); }
.drill-verdict.is-right { background: var(--good-soft); }
.drill-verdict.is-right .mark { background: var(--good); }
.drill-verdict.is-wrong,
.drill-verdict.is-given { background: var(--bad-soft); }
.drill-verdict.is-wrong .mark,
.drill-verdict.is-given .mark { background: var(--bad); }
.drill-verdict.is-other { background: var(--accent-soft); }
.drill-verdict.is-other .mark { background: var(--accent); }
.drill-verdict.is-unheard { background: var(--surface-2); }
.drill-verdict.is-unheard .mark { background: var(--muted); }
.drill-model { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.75rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.drill-model > span { font-size: 1rem; font-weight: 650; line-height: 1.4; color: var(--ink); overflow-wrap: anywhere; }
.drill-model small { display: block; font-weight: 500; color: var(--muted); }
.drill-play { flex: none; display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 1.5px solid var(--accent); background: var(--surface); color: var(--accent-2); font: inherit; font-size: 0.85rem; padding-left: 2px; cursor: pointer; }
.drill-play.loading { opacity: 0.6; }
.drill-play.playing { background: var(--accent-soft); }
.drill-note { margin: 0.6rem 0 0; font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.drill-checking { display: flex; gap: 0.35rem; justify-content: center; margin-top: 1rem; }
.drill-checking i { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--accent); opacity: 0.5; animation: chip-pulse 1.2s ease-in-out infinite; }
.drill-checking i:nth-child(2) { animation-delay: 0.15s; }
.drill-checking i:nth-child(3) { animation-delay: 0.3s; }
.drill-mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.drill-write { max-width: 34rem; margin: 0.55rem auto 0; }
#drill-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: 1.4rem;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--surface);
  max-height: 140px;
}
#drill-input:focus { outline: none; border-color: var(--accent); }
/* The end of a round. */
.drill-end h2 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.drill-end .score { margin: 0.25rem 0 0.9rem; font-size: 0.95rem; font-weight: 700; color: var(--accent-2); }
.drill-end ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.drill-end li { display: grid; grid-template-columns: 1.4rem 1fr auto; gap: 0.5rem; align-items: baseline; font-size: 0.92rem; }
.drill-end li .m { font-weight: 800; }
.drill-end li.is-right .m { color: var(--good); }
.drill-end li.is-miss .m { color: var(--bad); }
.drill-end li .t { font-weight: 650; color: var(--ink); }
.drill-end li .t small { display: block; font-weight: 500; color: var(--muted); font-size: 0.78rem; }
.drill-end li .n { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.drill-watch { margin-top: 1rem; padding: 0.7rem 0.8rem; border-radius: var(--radius); background: var(--surface-2); border-left: 3px solid var(--bad); font-size: 0.88rem; color: var(--ink-soft); line-height: 1.5; }
.drill-watch b { color: var(--ink); }
.drill-watch p { margin: 0.2rem 0 0; }
.drill-time { margin-top: 1rem; }
.drill-time-row { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.drill-time .day-row-bar { display: block; height: 0.4rem; }
.drill-end-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.1rem; }
.drill-end.is-goal-met { border-color: var(--gold); background: var(--gold-soft); }
.drill-goal-met { display: flex; align-items: center; gap: 0.8rem; }
.drill-goal-met p { margin: 0.2rem 0 0; font-size: 0.92rem; font-weight: 600; color: var(--ink-soft); }
.drill-goal-badge { flex: none; display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%; background: var(--gold); color: #fff; font-size: 1.3rem; font-weight: 800; animation: celebrate-emoji-bounce 0.8s var(--ease) both; }
.drill-end .drill-goal-bar { display: block; height: 0.4rem; margin: 0.9rem 0 1rem; background: color-mix(in srgb, var(--gold) 25%, transparent); }
.drill-end .drill-goal-bar span { background: var(--gold); }
.drill-end.is-goal-met .score { margin-top: 0; }
.drill-end.is-goal-met .drill-watch { background: var(--surface); }
/* More's drills row: the plan page's drawn power drill (the plan card's comes as an image, practice-kinds.ts). */
.drill-ico {
  background: #fdeadf url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M3 6.5h10.5A1.5 1.5 0 0 1 15 8v3a1.5 1.5 0 0 1-1.5 1.5H3z' fill='%23e0763a'/><rect x='1.8' y='6.5' width='1.8' height='6' rx='.7' fill='%23232b6e'/><rect x='15' y='7.6' width='2.6' height='3.8' rx='.6' fill='%23232b6e'/><path d='M17.6 9.5h5' stroke='%23697089' stroke-width='1.5' stroke-linecap='round'/><path d='M5.2 12.5h4.6l-.9 6H4.6z' fill='%23232b6e'/><rect x='10' y='12.5' width='1.7' height='2.4' rx='.5' fill='%23232b6e'/><rect x='3.2' y='18.2' width='7.6' height='3.2' rx='1' fill='%23e0763a'/></svg>") center / 62% no-repeat;
}
@media (min-width: 801px) {
  .drill-en { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  .drill-checking i { animation: none; }
  .drill-goal-badge { animation: none; }
}

/* ---------------------------------------------------------------------------
   Shadowing (src/client/shadowing.ts): in the practice frame. Under the card
   one slot of fixed height holds the voice, the learner's wave, or what was
   heard, so the card, the status and the steps never move between steps.
   --------------------------------------------------------------------------- */
#shadow-count:empty { display: none; }
.shadow-card { padding-bottom: 0.9rem; }
.shadow-es { margin: 0; font-size: 1.5rem; font-weight: 750; line-height: 1.3; letter-spacing: -0.01em; color: var(--ink); overflow-wrap: anywhere; }
.shadow-en { margin: 0.5rem 0 0; font-size: 0.95rem; line-height: 1.35; color: var(--muted); }
.shadow-show {
  margin: 0.55rem 0 0;
  border: none;
  background: none;
  color: var(--accent-2);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.shadow-show.is-gone { visibility: hidden; }
/* Alone: the sentence is said from memory until the learner asks for it. */
.shadow-card.is-blurred .shadow-es { filter: blur(9px); user-select: none; }
/* Together: the words light up as the recording says them. */
.shadow-w { color: color-mix(in srgb, var(--ink) 30%, transparent); transition: color 0.12s var(--ease); }
.shadow-w.is-said { color: var(--ink); }
.shadow-w.is-now { color: var(--accent-2); }
/* What was heard: a word not heard, never marked wrong. */
.shadow-miss { text-decoration: underline wavy var(--gold); text-decoration-thickness: 2px; text-underline-offset: 6px; }
.shadow-slot { width: 100%; min-height: 7.4rem; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.55rem; }
.shadow-orb {
  position: relative;
  width: 6rem;
  height: 6rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.shadow-orb::before { content: ''; position: absolute; inset: 13%; border-radius: 50%; background: color-mix(in srgb, var(--accent) 18%, transparent); }
.shadow-orb > span {
  position: relative;
  width: 58%;
  height: 58%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: var(--shadow-lg);
}
.shadow-orb i { width: 5px; height: 30%; border-radius: 999px; background: var(--on-accent); }
.shadow-orb i:nth-child(2), .shadow-orb i:nth-child(4) { height: 48%; }
.shadow-orb i:nth-child(3) { height: 62%; }
.shadow-orb.is-quiet { opacity: 0.35; transform: scale(0.85); }
.practice-mode.is-playing .shadow-orb i { animation: shadow-bar 0.8s var(--ease) infinite alternate; }
.practice-mode.is-playing .shadow-orb i:nth-child(2) { animation-delay: -0.3s; }
.practice-mode.is-playing .shadow-orb i:nth-child(3) { animation-delay: -0.55s; }
.practice-mode.is-playing .shadow-orb i:nth-child(4) { animation-delay: -0.15s; }
.practice-mode.is-playing .shadow-orb i:nth-child(5) { animation-delay: -0.45s; }
@keyframes shadow-bar { from { height: 22%; } to { height: 66%; } }
.shadow-wave { display: flex; gap: 4px; align-items: center; height: 3.4rem; }
.shadow-wave i { width: 5px; height: 40%; border-radius: 3px; background: var(--bad); animation: shadow-bar 0.7s var(--ease) infinite alternate; }
.shadow-wave i:nth-child(3n) { animation-delay: -0.25s; }
.shadow-wave i:nth-child(3n + 1) { animation-delay: -0.5s; }
.shadow-heard { margin: 0; padding: 0.55rem 0.75rem; border-radius: var(--radius); background: var(--gold-soft); font-size: 0.88rem; line-height: 1.4; color: var(--ink-soft); }
.shadow-heard b { color: var(--ink); }
.shadow-heard.is-all { background: var(--good-soft); }
.shadow-compare { display: flex; gap: 0.5rem; }
.shadow-play {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
}
.shadow-play span { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent-2); font-size: 0.7rem; padding-left: 2px; }
.shadow-play:disabled { opacity: 0.5; cursor: default; }
.shadow-status { margin: 0; min-height: 2.9rem; font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.shadow-status small { display: block; margin-top: 0.2rem; font-size: 0.82rem; font-weight: 500; color: var(--muted); }
.shadow-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; list-style: none; margin: 0; padding: 0; }
.shadow-steps li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem 0.28rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}
.shadow-steps li::before {
  content: attr(data-n);
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}
.shadow-steps li.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.shadow-steps li.is-on::before { background: var(--accent-strong); color: var(--on-accent); }
.shadow-steps li.is-done::before { content: '✓'; background: var(--good); color: #fff; }
.shadow-mic { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.shadow-mic p { margin: 0; font-size: 0.8rem; }
.shadow-mic .lesson-mic.recording { background: var(--bad); }
.shadow-end { text-align: left; }
.shadow-end h2 { margin: 0 0 0.4rem; font-size: 1.35rem; letter-spacing: -0.01em; }
.shadow-end p { margin: 0; color: var(--ink-soft); line-height: 1.45; }
@media (min-width: 801px) {
  .shadow-es { font-size: 1.85rem; }
  .shadow-en { font-size: 1.05rem; }
}
@media (prefers-reduced-motion: reduce) {
  .practice-mode.is-playing .shadow-orb i,
  .shadow-wave i { animation: none; }
}

/* ---------------------------------------------------------------------------
   A tutor's work copy of a student's account (work-copy.ts): a frame round the
   screen and a tag at the top, above every screen and overlay, so the tutor
   always sees whose account the tab is working on.
   --------------------------------------------------------------------------- */
.work-copy-frame {
  position: fixed;
  inset: 0;
  z-index: 4000;
  pointer-events: none;
  box-shadow: inset 0 0 0 3px var(--work-copy);
}
.work-copy-tag {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4001;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: calc(env(safe-area-inset-top) + 2px) 4px 4px 12px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--work-copy);
  color: var(--work-copy-ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: var(--shadow-sm);
}
.work-copy-tag #work-copy-who {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work-copy-tag button {
  flex: none;
  min-height: 0;
  padding: 1px 10px;
  border: 1px solid currentColor;
  border-radius: var(--radius-pill);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.work-copy-tag button:hover,
.work-copy-tag button:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}
