:root {
  --bg: #0f1419;
  --bg-elev: #1a222c;
  --bg-chat: #141b22;
  --border: #2a3542;
  --text: #e7eef6;
  --muted: #8b9aab;
  --tutor: #5ec8ff;
  --you: #9ae6b4;
  --accent: #3d8bfd;
  --accent-hover: #5ca0ff;
  --warn: #f0c14b;
  --danger: #f07178;
  --ok: #7fd99a;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html.no-debug { --debug-bar: 0px; }
html.no-debug .debug-box { display: none !important; }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  /* iOS: kill rubber-band page panning ("accidentally move things
     around", USER 2026-08-13). Desktop-safe: body never scrolls
     (overflow hidden), so there is no chaining to suppress there. */
  overscroll-behavior: none;
}
html { -webkit-text-size-adjust: 100%; }
/* iOS: double-tap zoom on chrome nudges the layout — disable it on
   interactive controls only (pinch zoom elsewhere stays available).
   Desktop-safe: touch-action has no effect on mouse/keyboard input. */
button, summary, label, input, select, textarea { touch-action: manipulation; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 12% -8%, #3a2a1c 0%, var(--bg) 58%);
  color: var(--text);
}

.app {
  max-width: 1340px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem 0;
  /* Collapsed Debug bar is position:fixed — reserve it so the composer
     is never hidden behind it (LAYOUT-SHELL, 2026-08-12). */
  padding-bottom: calc(var(--debug-bar, 2.75rem) + env(safe-area-inset-bottom, 0px));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.logo {
  width: 72px; height: 72px;
  border-radius: 18px;
  object-fit: cover;
  object-position: 50% 18%;
  display: block;
  flex: 0 0 auto;
  background: #f0b429;
}
h1 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.build-stamp {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  vertical-align: middle;
  margin-left: 0.35rem;
}
.build-stamp.stale { color: #e5484d; font-weight: 700; }
.sub { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Progress score (character sheet → 0–100) */


/* Progression header (dual-signal law, docs/design-xp-progression.md):
   ability counts primary, XP journey bar secondary — never XP alone. */
.xp-board {
  flex: 0 1 260px;
  min-width: 220px;
  padding: 0.45rem 0.75rem 0.5rem;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(56, 178, 172, 0.12), rgba(43, 108, 176, 0.10));
  border: 1px solid var(--border);
  overflow: hidden;
}
.xp-ability {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.xp-journey {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.3rem;
}
.xp-level {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  cursor: help;
}
.xp-bar-wrap {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.xp-bar {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2b6cb0, #38b2ac 55%, #7fd99a);
  transition: width 0.45s ease;
  min-width: 0;
}
.xp-nums {
  font-size: 0.66rem;
  color: var(--muted);
  white-space: nowrap;
}
/* Session API cost — operator surface, lives in #debugBox (2026-08-12).
   §3.4: the unpriced flag rides this value, including the summary chip. */
.cost-board {
  flex: 1 1 220px;
  min-width: 180px;
  margin: 0;
  padding: 0.4rem 0.65rem 0.45rem;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(253, 186, 61, 0.12), rgba(253, 92, 61, 0.08));
  border: 1px solid var(--border);
}
.score-main {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.score-value {
  font-size: 1.2rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}
.score-unit {
  font-size: 0.72rem;
  color: var(--muted);
}
.score-meta {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}


.score-bar-wrap {
  margin-top: 0.35rem;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.score-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2b6cb0, #38b2ac 55%, #7fd99a);
  transition: width 0.45s ease;
  min-width: 0;
}




.toggle {
  display: flex; align-items: center; gap: 0.35rem;
  color: var(--muted); font-size: 0.85rem; cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--accent); }
/* Voice-speed slider: slider first so the thumb never shifts as the label
   text changes width while dragging. */
.voice-rate input[type="range"] { width: 88px; }
.voice-rate span { min-width: 6.4rem; white-space: nowrap; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 0.75rem;
}
.main .chat-panel { flex: 1; min-height: 0; }

.flyout-backdrop {
  position: fixed;
  inset: 0;
  z-index: 28;
  background: rgba(8, 12, 18, 0.45);
}
.flyout-backdrop[hidden] { display: none !important; }
.flyout[hidden] { display: none !important; }
.flyout {
  position: fixed;
  z-index: 30;
  top: 4.6rem;
  left: 1rem;
  width: min(380px, calc(100vw - 1.5rem));
  max-height: min(70dvh, 640px);
  overflow-y: auto;
  padding: 0;
  background: transparent;
  filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.45));
}
.flyout-morph { left: auto; right: 1rem; }
.flyout .card { margin: 0; }

@media (max-width: 1100px) {
  .voice-rate input[type="range"] { width: 72px; }
  .flyout {
    top: auto;
    bottom: calc(var(--debug-bar, 2.75rem) + 0.5rem);
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    max-height: min(62dvh, 560px);
  }
  .flyout-morph { left: 0.5rem; right: 0.5rem; }
}
@media (max-width: 900px) {
  .main { margin-top: 0.5rem; }

  /* Phone-first compaction. Debug bar + safe-area are reserved on .app
     (LAYOUT-SHELL); do not add a second bottom inset here. */
  .app {
    padding: 0.4rem 0.6rem 0;
    padding-bottom: calc(var(--debug-bar, 2.75rem) + env(safe-area-inset-bottom, 0px));
  }
  .top { align-items: flex-start; gap: 0.5rem; padding: 0.3rem 0 0.45rem; }
  .xp-board { flex: 1 1 100%; min-width: 0; padding: 0.4rem 0.6rem; }
  .sub { display: none; }
  .build-stamp { display: none; }
  .logo { width: 40px; height: 40px; border-radius: 11px; }
  h1 { font-size: 1rem; }
  .header-actions { width: 100%; gap: 0.35rem; justify-content: flex-start; }
  .header-actions .btn { padding: 0.45rem 0.6rem; font-size: 0.8rem; min-height: 44px; }
  .voice-rate input[type="range"] { width: 72px; }
  .voice-rate span { min-width: 0; font-size: 0.75rem; }

  .composer { padding: 0.5rem; flex-shrink: 0; }
  .hint.mic-status { font-size: 0.7rem; margin: 0.3rem 0.5rem 0.4rem; flex-shrink: 0; }

  .journey-toggle, .dbg-tab, .dbg-turn-btn { min-height: 44px; padding: 0.45rem 0.65rem; }
  .game-tile, .game-opt-btn, .game-check { min-height: 44px; }
  .match-wrap { flex-direction: column; }

  .sheet-modal { max-height: min(92dvh, 900px); padding: 0.75rem; }
  .sheet-head { flex-wrap: wrap; }
}

.journey-head h2 { margin: 0; }
.journey-toggle { font-size: 0.72rem; padding: 0.2rem 0.55rem; }
.journey-card.collapsed .journey-body,
.journey-card.collapsed .journey-foot { display: none; }
.j-empty {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0.2rem 0 0;
}
/* Detour banner (2026-08-10, span protocol): one-line, non-modal, never
   covers the composer; text label required (emoji optional).
   OVERLAY, not in-flow (Grok layout audit item 3): an in-flow bar stole
   ~65px from #messages on toggle and shifted the line under the
   reader's eyes. The messages pane compensates with padding-top while
   active; renderDetour preserves the visual anchor across the toggle. */
.detour-bar[hidden] { display: none !important; }
.detour-bar {
  display: flex;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--accent);
  background-color: var(--bg-chat);
  background-image: linear-gradient(
    rgba(61, 139, 253, 0.16), rgba(61, 139, 253, 0.16));
  font-size: 0.82rem;
}
.chat-panel { position: relative; }
.chat-panel.detour-active .messages {
  padding-top: calc(1rem + var(--detour-bar-height, 3.4rem));
}
/* Mode backgrounds (USER 2026-08-10: entering a chapter mode —
   focused practice / getting-to-know-your-level — must be visually
   obvious, not just a banner). Set by renderSpan per realized kind. */
.messages { transition: background-color 0.6s ease; }
.chat-panel.span-placement .messages {
  background-color: #14243d;
  background-image: linear-gradient(
    rgba(61, 139, 253, 0.10), rgba(61, 139, 253, 0.03));
}
.chat-panel.span-detour .messages {
  background-color: #2b2212;
  background-image: linear-gradient(
    rgba(253, 186, 61, 0.10), rgba(253, 92, 61, 0.04));
}
.chat-panel.span-detour .detour-bar {
  border-bottom-color: #fdba3d;
  background-image: linear-gradient(
    rgba(253, 186, 61, 0.18), rgba(253, 186, 61, 0.18));
}
.detour-label { min-width: 0; overflow-wrap: anywhere; }
.detour-label b { color: var(--accent-hover); }
.detour-done {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  font-size: 0.78rem;
}
@media (max-width: 640px) {
  .detour-bar { font-size: 0.76rem; padding: 0.35rem 0.55rem; }
}

/* Progress rail (2026-08-09): chapter goals + category progress.
   Bars and counts render GRADED sheet state — they move only at chapter
   breaks. ".pv-live" lines render WITNESSED observer facts and update
   every turn. The two layers stay visually distinct on purpose. */
.pv { display: flex; flex-direction: column; gap: 0.55rem; }
.pv-sec { border-bottom: 1px solid var(--border); padding-bottom: 0.55rem; }
.pv-sec:last-child { border-bottom: 0; padding-bottom: 0; }
.pv-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pv-frac { font-family: var(--mono); font-size: 0.78rem; color: var(--text); }
.pv-lvl {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent-hover);
}
.pv-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 0.3rem 0 0.15rem;
}
.pv-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.45s ease;
}
.pv-chapter .pv-bar span { background: var(--ok); }
.pv-goals {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}
.pv-goal {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  font-size: 0.74rem;
  line-height: 1.3;
  color: var(--text);
}
.pv-goal-label { min-width: 0; overflow-wrap: anywhere; }
.pv-dot { flex-shrink: 0; font-size: 0.72rem; line-height: 1.3; color: var(--muted); }
.pv-goal.done .pv-dot { color: var(--ok); }
.pv-goal.done .pv-goal-label { color: var(--muted); }
.pv-goal.building .pv-dot { color: var(--warn); }
.pv-count { margin: 0.3rem 0 0; font-size: 0.76rem; color: var(--muted); }
.pv-count b { color: var(--text); font-weight: 700; }
.pv-live { margin: 0.25rem 0 0; font-size: 0.7rem; color: var(--ok); }
.journey-foot {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.74rem;
}

/* Right rail removed 2026-08-12 — morphology is an in-turn card. */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
.card-head h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pill {
  font-size: 0.7rem;
  font-weight: 650;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #243b55;
  color: var(--tutor);
  border: 1px solid #2d4660;
  white-space: nowrap;
}
.pill.soft {
  background: #1e2a24;
  color: var(--ok);
  border-color: #2f5a45;
}
.pill.warn {
  background: #3a2e14;
  color: var(--warn);
  border-color: #6b5420;
}
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
}
.chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  background: #1a222c;
  border: 1px solid var(--border);
  color: var(--muted);
}
.chip.on { color: var(--you); border-color: #2f5a45; }
.chip.hot { color: var(--tutor); border-color: #2d4660; }

.morph-card { border-color: #2f4a3a; }
.morph-body { display: flex; flex-direction: column; gap: 0.75rem; }
.morph-block {
  background: #141c18;
  border: 1px solid #2a4035;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}
.morph-block h3 {
  margin: 0 0 0.2rem;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--ok);
}
.morph-lemma {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.morph-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.morph-table td {
  padding: 0.22rem 0.15rem;
  vertical-align: top;
  border-bottom: 1px solid #1e2a24;
}
.morph-table tr:last-child td { border-bottom: none; }
.morph-table .form {
  font-weight: 650;
  color: var(--text);
  font-family: var(--mono);
  white-space: nowrap;
  padding-right: 0.5rem;
}
.morph-table tr.hi .form {
  color: var(--tutor);
}
.morph-table tr.hi {
  background: rgba(61, 139, 253, 0.08);
}
.morph-table .person {
  color: var(--muted);
  font-size: 0.72rem;
  padding-right: 0.4rem;
  white-space: nowrap;
}
.morph-table .gloss { color: #b8c5d4; }
.morph-note {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}
.morph-watch {
  margin: 0.3rem 0 0;
  font-size: 0.75rem;
  color: var(--warn);
  line-height: 1.3;
}
.lex-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.lex-chip {
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 0.2rem 0.45rem;
  border-radius: 7px;
  background: #1a222c;
  border: 1px solid var(--border);
  color: var(--text);
}
.muted { color: var(--muted); font-size: 0.85rem; margin: 0; }

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.welcome-room {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1.25rem 1rem;
  pointer-events: none;
}
.welcome-room[hidden] { display: none !important; }
.welcome-room img {
  width: min(100%, 680px);
  max-height: min(78%, 680px);
  object-fit: cover;
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}
.welcome-line {
  margin: 0;
  color: #d8c4a8;
  font-size: 1.05rem;
  font-weight: 550;
  letter-spacing: 0.01em;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  z-index: 2;
  /* LAYOUT-SHELL 2026-08-12: the flex viewport is the height budget.
     No paired min/max vh — #messages is the one learner scrollport. */
  min-height: 0;
  max-height: none;
  /* The one scroller never chains its overscroll to the page (iOS
     rubber-band shell drag). Desktop-safe: body cannot scroll anyway. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: min(92%, 640px);
  padding: 0.7rem 0.95rem;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.bubble.tutor {
  align-self: flex-start;
  background: #1e2d3d;
  border: 1px solid #2d4660;
  color: var(--text);
}
.bubble.tutor .who { color: var(--tutor); }
.bubble.you {
  align-self: flex-end;
  background: #1c3328;
  border: 1px solid #2f5a45;
}
.bubble.you .who { color: var(--you); }
.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  border: none;
  padding: 0.25rem;
}
/* Autoplay-blocked voice → tappable play affordance (mobile) */
.bubble.system.tap-audio {
  cursor: pointer;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
}
.who {
  display: block;
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
  opacity: 0.9;
}

/* Structured tutor parts (recast / explain / continue) */
.bubble.tutor .part {
  margin-top: 0.45rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  white-space: pre-wrap;
  line-height: 1.4;
}
.bubble.tutor .part:first-of-type { margin-top: 0.15rem; }
.part-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
  opacity: 0.85;
}
.part-ack {
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}
.part-ack .part-label { color: var(--muted); }
.part-recast {
  background: #1a2e24;
  border: 1px solid #2f5a45;
}
.part-recast .part-label { color: var(--ok); }
.part-explain {
  background: #2a2416;
  border: 1px solid #5a4a28;
  font-size: 0.92em;
}
.part-explain .part-label { color: var(--warn); }
.part-model {
  background: #1a2238;
  border: 1px solid #3a4f7a;
}
.part-model .part-label { color: #9eb6ff; }
.part-try {
  background: #2a2618;
  border: 1px solid #6a5a28;
  font-weight: 500;
}
.part-try .part-label { color: var(--warn); }
.part-gate-fail {
  background: #3a1518;
  border: 1px solid #a04048;
  color: #f0c0c4;
}
.part-gate-fail .part-label { color: #ff8a90; font-weight: 700; }
.part-gate-fail .gate-fail-body { display: block; margin-top: 0.25rem; font-size: 0.85rem; line-height: 1.35; }
.part-gate-fail code { color: #ffd0a8; font-size: 0.8em; }
.part-image {
  background: #1a222c;
  border: 1px solid #3a4a5c;
  padding: 0.55rem 0.65rem 0.7rem;
}
.part-image .part-label { color: #9ec5ff; }
.teach-figure {
  margin: 0.35rem 0 0;
  padding: 0;
}
.teach-hotspot {
  display: block;
  width: 100%;
  max-width: 280px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
}
.teach-hotspot:hover .teach-img,
.teach-hotspot:focus-visible .teach-img {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.35);
}
.hotspot-hint {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
}
.choice-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.choice-btn {
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: #1a2836;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  min-height: 44px;
  cursor: pointer;
}
.choice-btn:hover,
.choice-btn:focus-visible {
  background: rgba(61, 139, 253, 0.18);
}
.teach-img {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f1419;
}
.teach-cap {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.teach-cap strong {
  color: var(--tutor);
  font-weight: 650;
}
.part-continue {
  background: #1a2430;
  border: 1px solid #2d4660;
}
.part-continue .part-label { color: var(--tutor); }
.mode-tag {
  font-size: 0.68rem;
  color: var(--muted);
  margin-left: 0.35rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}


.composer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.6rem;
  padding: 0.35rem 0.75rem 0.15rem;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}
.accent-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.accent-btn {
  font: inherit;
  font-size: 0.72rem;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  min-width: 1.85rem;
  padding: 0.2rem 0.35rem;
  font-weight: 650;
  cursor: pointer;
  min-height: 32px;
}
.accent-btn:hover {
  border-color: var(--accent);
}

.more-wrap { position: relative; }
.more-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 20;
  min-width: 10rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.25rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
.more-menu[hidden] { display: none !important; }
.more-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}
.more-item:hover { background: #222c38; }
.more-item.danger { color: var(--danger); }

.morph-card .card-head { gap: 0.4rem; }
.morph-card .card-head h2 { flex: 1; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: none;
  background: var(--bg-elev);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 44px;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* hard floor — iOS zooms focused inputs below 16px */
  line-height: 1.35;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}
/* Live speech caption — provisional until final STT */
.composer textarea.speech-interim {
  border-color: rgba(240, 113, 120, 0.55);
  color: #e8d5d6;
  font-style: italic;
  box-shadow: 0 0 0 2px rgba(240, 113, 120, 0.12);
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 11px;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: #4a5d72; background: #222c38; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  min-width: 4.5rem;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary.mic-locked,
.btn.primary:disabled.mic-locked {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.icon {
  width: 44px; height: 44px;
  padding: 0;
  display: grid; place-items: center;
  flex-shrink: 0;
  position: relative;
}
.btn.icon.listening {
  background: #4a1c24;
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 6px rgba(240, 113, 120, 0.15); }
}

.hint {
  margin: 0;
  padding: 0.45rem 0.9rem 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.35rem;
  transition: color 0.15s, background 0.15s;
}
.hint.mic-status {
  border-top: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.hint.listening-active,
.hint.mic-status[data-state="recording"] {
  color: #ffb4b8;
  font-weight: 600;
  background: linear-gradient(180deg, #2a1518 0%, transparent 100%);
  border-top-color: rgba(240, 113, 120, 0.35);
}
.hint.mic-status[data-state="recording"]::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  animation: rec-blink 1s step-end infinite;
}
@keyframes rec-blink {
  50% { opacity: 0.25; }
}
.hint.mic-working,
.hint.mic-status[data-state="working"] {
  color: #9ec5ff;
  font-weight: 600;
  background: linear-gradient(180deg, #152233 0%, transparent 100%);
  border-top-color: rgba(61, 139, 253, 0.3);
}
.hint.mic-working::before,
.hint.mic-status[data-state="working"]::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(158, 197, 255, 0.35);
  border-top-color: #9ec5ff;
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.hint.mic-error,
.hint.mic-status[data-state="error"] {
  color: #ffb4b8;
  font-weight: 500;
}

/* Full sheet modal */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 12, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.sheet-overlay[hidden] {
  display: none !important;
}
.sheet-modal {
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  padding-bottom: 0.35rem;
  z-index: 1;
}
.sheet-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.sheet-head-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.next-best {
  background: #1a2836;
  border: 1px solid #2d4660;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
.next-best strong { color: var(--tutor); }
.sheet-body {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

.typing {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* Loading wait (USER 2026-08-04): one indicator for every model wait —
   page open, new chat, reset, and each turn. */
.wait-bubble {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.wait-dots {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
}
.wait-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tutor, var(--muted));
  opacity: 0.35;
  animation: wait-bounce 1.2s infinite ease-in-out;
}
.wait-dots span:nth-child(2) { animation-delay: 0.18s; }
.wait-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes wait-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ——— Debug box (local tool): outbound AI requests + response meta ——— */
.debug-box {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(1340px, 100%);
  z-index: 40;
  margin: 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg-elev);
  font-family: var(--mono);
  font-size: 0.75rem;
  max-height: min(70dvh, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#debugDetails {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(70dvh, 100%);
}
.debug-summary {
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.85rem;
  user-select: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}
#debugDetails[open] > .debug-summary { color: var(--text); }
.debug-count { color: var(--tutor); }
.debug-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.debug-chip {
  font-size: 0.72rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-chat);
  color: var(--text);
}
.debug-chip.muted { color: var(--muted); font-weight: 500; }
.debug-chip.gate {
  color: #ff8a90;
  border-color: #a04048;
  background: #3a1518;
}
.debug-chip.stale {
  color: #ff8a90;
  border-color: #a04048;
  background: #3a1518;
  font-weight: 700;
}
.debug-chip[hidden],
.debug-gate-panel[hidden] { display: none !important; }
.debug-ops {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  padding: 0.55rem 0.9rem 0.45rem;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.debug-turn-meta {
  flex: 1 1 16rem;
  min-width: 12rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
  padding-top: 0.35rem;
}
.debug-gate-panel {
  flex: 1 1 100%;
  margin: 0;
  padding: 0.45rem 0.55rem;
}
.debug-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.9rem 0.5rem;
  font-family: var(--font);
}
.debug-hint { font-size: 0.72rem; }
.debug-model-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
}
.debug-model-picker select {
  font: inherit;
  font-size: 0.78rem;
  max-width: 16rem;
  background: var(--bg-chat);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.4rem;
}
.debug-model-status { font-size: 0.72rem; }
.dbg-phase {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.55rem;
  background: var(--bg-chat);
  overflow: hidden;
}
.dbg-phase-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.4rem 0.65rem;
  background: color-mix(in srgb, var(--tutor) 10%, transparent);
  border-bottom: 1px solid var(--border);
  font-family: var(--font);
  font-size: 0.8rem;
}
.dbg-phase-tag {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--tutor);
}
.dbg-phase-kind { color: var(--muted); font-size: 0.72rem; }
.dbg-phase-model { color: var(--muted); font-size: 0.72rem; margin-left: auto; }
.dbg-phase-body { padding: 0.35rem 0.5rem 0.5rem; }
.dbg-phase.missing { opacity: 0.55; }
.dbg-phase.missing .dbg-phase-head { background: transparent; }
.debug-body {
  padding: 0 0.9rem 0.8rem;
  /* One scroll surface: the inner .dbg-view scrolls; the body grows
     to ~full viewport (USER 2026-08-03: "much taller"). */
  max-height: none;
  overflow-y: visible;
}
.dbg-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-chat);
  margin-bottom: 0.5rem;
}
.dbg-entry-sum {
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  color: var(--text);
  user-select: none;
}
.dbg-faults { color: var(--warn); }
.dbg-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.6rem;
}
.dbg-model { color: var(--muted); }
.dbg-copy { font-size: 0.72rem; padding: 0.1rem 0.5rem; }
.dbg-sub {
  margin: 0.3rem 0.6rem;
  border-left: 2px solid var(--border);
  padding-left: 0.55rem;
}
.dbg-sub > summary {
  cursor: pointer;
  color: var(--tutor);
  user-select: none;
  padding: 0.15rem 0;
}
.dbg-pre {
  margin: 0.25rem 0 0.4rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  background: #0d1319;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  max-height: 18rem;
  overflow-y: auto;
  line-height: 1.45;
}
.dbg-msg { margin-bottom: 0.3rem; }
.dbg-role { color: var(--you); text-transform: uppercase; font-size: 0.68rem; }

/* Debug tabs (2026-08-03: turn selector + INPUT/OUTPUT/META) */
.dbg-turns {
  display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.45rem;
}
.dbg-turn-btn {
  font: inherit; font-size: 0.72rem; padding: 0.12rem 0.55rem;
  border: 1px solid var(--border, #444); border-radius: 999px;
  background: transparent; color: var(--muted, #999); cursor: pointer;
}
.dbg-turn-btn.active { color: inherit; border-color: var(--you, #7aa2f7); }
.dbg-turn-btn.fault { border-color: var(--warn, #e0af68); }
.dbg-tabbar {
  display: flex; align-items: center; gap: 0.4rem;
  border-bottom: 1px solid var(--border, #444);
  margin-bottom: 0.5rem; padding-bottom: 0.3rem;
}
.dbg-tab {
  font: inherit; font-size: 0.74rem; letter-spacing: 0.04em;
  padding: 0.15rem 0.6rem; border: none; background: transparent;
  color: var(--muted, #999); cursor: pointer; border-radius: 4px;
}
.dbg-tab.active {
  color: inherit; font-weight: 600;
  background: color-mix(in srgb, currentColor 12%, transparent);
}
.dbg-tabbar .dbg-model { margin-left: auto; font-size: 0.7rem; }
.dbg-view { max-height: min(40dvh, 22rem); overflow-y: auto; }
#debugDetails[open] .debug-body { overflow-y: auto; flex: 1; min-height: 0; }

/* Help modal (2026-08-10): reuses the sheet modal shell; prose styling */
.help-modal { max-width: 560px; }
.help-body {
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.55;
  padding: 0.25rem 0.25rem 0.5rem;
}
.help-body h3 {
  margin: 1rem 0 0.3rem;
  font-size: 0.95rem;
  color: var(--accent-hover);
}
.help-body h3:first-child { margin-top: 0.25rem; }
.help-body p { margin: 0.3rem 0; }
.help-body ul { margin: 0.3rem 0 0.5rem 1.2rem; padding: 0; }
.help-body li { margin: 0.25rem 0; }

/* Flowing tutor reply (labels removed 2026-08-03) */
.part-flow { margin: 0.35rem 0; }
.part-flow.part-recast { font-style: italic; opacity: 0.92; }
.part-flow.part-continue { color: var(--muted); font-size: 0.92em; }

/* Model-led game widgets — visual pass 2026-08-04 (Grok countersign) */
.game-card {
  position: relative;
  border: 1px solid rgba(122, 162, 247, 0.28);
  border-radius: 14px;
  padding: 0.9rem 1.05rem 1rem;
  margin: 0.65rem 0;
  background:
    linear-gradient(165deg, rgba(122,162,247,0.09), rgba(122,162,247,0.03) 40%, rgba(0,0,0,0.15));
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.25) inset,
    0 8px 24px rgba(0,0,0,0.22);
  animation: game-enter 0.28s ease-out;
}
@keyframes game-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.game-card::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 3px;
  border-radius: 14px 0 0 14px;
  background: var(--you, #7aa2f7);
  opacity: 0.85;
}
.game-head {
  display: flex; gap: 0.55rem; align-items: center;
  margin-bottom: 0.45rem; flex-wrap: wrap;
}
.game-kind {
  font-size: 0.65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--you, #7aa2f7);
  background: rgba(122,162,247,0.12);
  border: 1px solid rgba(122,162,247,0.35);
  border-radius: 999px; padding: 0.12rem 0.55rem;
}
.game-title { font-weight: 600; font-size: 1.02rem; letter-spacing: -0.01em; }
.game-instructions {
  color: var(--muted); font-size: 0.84rem;
  margin: 0 0 0.65rem; line-height: 1.35;
}
.game-progress { display: flex; gap: 0.28rem; margin: 0 0 0.65rem; }
.game-progress i {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.14);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.game-progress i.on {
  background: var(--you, #7aa2f7);
  border-color: transparent;
}
.match-wrap { display: flex; gap: 1rem; }
.match-col { display: flex; flex-direction: column; gap: 0.4rem; flex: 1; min-width: 0; }
.game-tile {
  font: inherit; padding: 0.45rem 0.75rem; border-radius: 10px;
  border: 1px solid var(--border, #444);
  background: rgba(255,255,255,0.03);
  color: inherit; cursor: pointer; text-align: left;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.game-tile:hover:not(:disabled) {
  border-color: rgba(122,162,247,0.55);
  background: rgba(122,162,247,0.08);
}
.game-tile.sel {
  border-color: var(--you, #7aa2f7);
  background: rgba(122,162,247,0.14);
  box-shadow: 0 0 0 1px rgba(122,162,247,0.25);
}
.game-tile.ok {
  border-color: var(--ok, #9ece6a);
  color: var(--ok, #9ece6a);
  background: rgba(158,206,106,0.08);
}
.game-tile.bad { border-color: var(--warn, #f7768e); background: rgba(247,118,142,0.08); }
.game-tile:disabled { opacity: 0.55; cursor: default; }
.game-tile.used { opacity: 0.35; }
.game-opt-btn { width: 100%; margin: 0.2rem 0; }
.game-opt-btn.reveal { opacity: 1; }
.game-q { margin: 0.55rem 0; }
.game-prompt { margin: 0 0 0.35rem; font-weight: 500; }
.game-input {
  font-family: inherit;
  font-size: 16px; /* iOS Safari: <16px computed → focus zoom */
  background: rgba(0,0,0,0.2); color: inherit;
  border: 1px solid var(--border, #444); border-radius: 10px;
  padding: 0.45rem 0.7rem; width: 100%; max-width: 22rem;
  min-height: 44px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.game-input:focus {
  outline: none;
  border-color: var(--you, #7aa2f7);
  box-shadow: 0 0 0 2px rgba(122,162,247,0.2);
}
.game-input.ok { border-color: var(--ok, #9ece6a); }
.game-input.bad { border-color: var(--warn, #f7768e); }
.game-hint {
  margin: 0.25rem 0 0; font-size: 0.85rem;
  color: var(--ok, #9ece6a); opacity: 0.9;
}
.game-tilerow { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.35rem 0; }
.game-build {
  min-height: 1.6em; font-style: normal;
  padding: 0.35rem 0.55rem; border-radius: 8px;
  border: 1px dashed var(--border, #444);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.game-build.ok { border-style: solid; border-color: var(--ok, #9ece6a); background: rgba(158,206,106,0.08); }
.game-build.bad { border-style: solid; border-color: var(--warn, #f7768e); background: rgba(247,118,142,0.08); }
.game-check { margin-top: 0.65rem; border-radius: 10px; padding: 0.4rem 0.9rem; }
.game-result {
  color: var(--muted); margin-top: 0.65rem; font-size: 0.86rem;
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
}
.game-result strong { color: inherit; font-variant-numeric: tabular-nums; }
.game-result.perfect strong { color: var(--ok, #9ece6a); }
.game-miss-list {
  margin: 0.25rem 0 0; padding-left: 1.1rem;
  color: var(--muted); font-size: 0.8rem;
}
.game-done { pointer-events: none; opacity: 0.92; }
.game-passage {
  margin: 0.5rem 0 0.75rem; padding: 0.75rem 1rem;
  border: 1px solid rgba(122,162,247,0.35);
  border-left: 3px solid var(--you, #7aa2f7);
  border-radius: 10px;
  background: rgba(0,0,0,0.22);
  font-style: normal;
  line-height: 1.45;
  letter-spacing: 0.01em;
}
.game-card.game-all-ok .game-passage {
  border-color: rgba(158,206,106,0.55);
  box-shadow: 0 0 0 1px rgba(158,206,106,0.15);
}
@keyframes game-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes game-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.game-tile.shake, .game-input.shake { animation: game-shake 0.28s ease; }
.game-tile.pop, .game-input.pop { animation: game-pop 0.22s ease; }

.cost-unpriced { color: var(--warn, #e0af68); }

/* ——— Chapter-break overlay (2026-08-09, cycle-report popup) ——— */
.cycle-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 20, 0.72);
  backdrop-filter: blur(3px);
}
.cycle-overlay.hidden { display: none; }
.cycle-card {
  width: min(440px, calc(100vw - 32px));
  max-height: min(80vh, 560px); overflow-y: auto;
  background: var(--panel, #1a1d29); color: var(--fg, #e6e6ef);
  border: 1px solid var(--border, #2c3044); border-radius: 14px;
  padding: 26px 24px; text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.cycle-card h2 { margin: 0 0 10px; font-size: 1.25rem; }
.cycle-blurb {
  color: var(--fg, #e6e6ef); line-height: 1.5;
  margin: 6px 0 16px; text-align: left;
}
.cycle-grades {
  list-style: none; margin: 0 0 16px; padding: 0; text-align: left;
}
.cycle-grades li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 4px; border-bottom: 1px solid var(--border, #2c3044);
}
.cycle-grades li:last-child { border-bottom: none; }
.cycle-kind { flex: 0 0 auto; }
.cycle-item { flex: 1 1 auto; min-width: 0; font-size: 0.92rem; }
.cycle-band {
  flex: 0 0 auto; font-size: 0.78rem; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.band-emerging { background: rgba(122, 162, 247, 0.18); color: var(--accent, #7aa2f7); }
.band-fragile  { background: rgba(224, 175, 104, 0.18); color: var(--warn, #e0af68); }
.band-known    { background: rgba(158, 206, 106, 0.18); color: var(--ok, #9ece6a); }
.cycle-level {
  display: flex; align-items: center; gap: 10px; margin: 0 0 18px;
}
.cycle-level-label { font-weight: 600; white-space: nowrap; }
.cycle-score-wrap {
  flex: 1 1 auto; height: 8px; border-radius: 999px;
  background: var(--border, #2c3044); overflow: hidden;
}
.cycle-score-bar {
  display: block; height: 100%; width: 0;
  background: var(--accent, #7aa2f7);
  transition: width 0.6s ease;
}
.cycle-score-num { color: var(--muted, #9aa0b5); font-size: 0.85rem; }
.cycle-continue { width: 100%; }


/* ——— Mic waveform (audio-direct): lives where the text box is ——— */
.mic-wave {
  flex: 1;
  min-width: 0;
  height: 44px;
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent, #d33) 8%, transparent);
}
.mic-wave canvas { display: block; width: 100%; height: 100%; }
.composer.recording #input { display: none; }
.composer.recording .mic-wave { display: block; }

/* High-demand toast: appears during provider retries, dies with them */
.demand-toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  background: var(--bg-elev, #222);
  color: var(--fg, #eee);
  border: 1px solid color-mix(in srgb, var(--accent, #d33) 50%, transparent);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  z-index: 60;
  animation: demand-in 200ms ease-out;
}
@keyframes demand-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Undo pill: one-shot rollback of the last exchange */
.undo-pill {
  display: block;
  margin: 0.35rem auto 0;
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--fg, #888) 30%, transparent);
  background: var(--bg-elev, #222);
  color: var(--fg, #eee);
  font-size: 0.85rem;
  cursor: pointer;
}
.undo-pill:hover { border-color: var(--accent, #d33); }

/* Starting-level headline on the placement card */
.cycle-headline {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0.25rem 0 0.5rem;
  color: var(--accent, #d33);
}

/* ——— Accounts: free-preview meter, gate modal, auth toasts ———
   (docs/design-accounts.md §2/§5). The dev-mode banner is the ONE
   deliberately loud element; everything else keeps the app's chrome. */
.meter-chip {
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid #6b5420;
  background: #3a2e14;
  color: var(--warn);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s;
}
.meter-chip:hover { border-color: var(--warn); }
.meter-chip.full {
  color: #ff8a90;
  border-color: #a04048;
  background: #3a1518;
}
.meter-chip[hidden] { display: none !important; }

/* Signed-in line in the More menu (non-interactive) */
.more-account {
  padding: 0.5rem 0.7rem 0.25rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16rem;
}
.more-account[hidden] { display: none !important; }

/* Gate modal: blocking cycle-overlay pattern, above every other layer */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(3px);
}
.gate-overlay.hidden { display: none; }
.gate-card {
  width: min(430px, 100%);
  max-height: min(88dvh, 640px);
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.2rem;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.gate-dev-banner {
  /* USER 2026-08-13: a PROMINENT no-card-needed message. Solid warning
     yellow, dark text — and no card form anywhere near it. */
  background: var(--warn);
  color: #201703;
  border: 2px dashed #8a6d1d;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1.35;
}
.gate-dev-banner[hidden] { display: none !important; }
.gate-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.gate-head h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  line-height: 1.3;
}
.gate-close { flex-shrink: 0; }
.gate-sub {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.gate-meter {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 1rem;
}
.gate-meter-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--warn), var(--danger));
  transition: width 0.45s ease;
}
.gate-providers {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.gate-provider-btn { width: 100%; font-weight: 600; }
.gate-or {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0;
  color: var(--muted);
  font-size: 0.75rem;
}
.gate-or::before,
.gate-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.gate-or[hidden] { display: none !important; }
.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
}
.gate-form[hidden] { display: none !important; }
.gate-label {
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.gate-input {
  padding: 0.6rem 0.75rem;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS zoom floor, same as the composer */
}
.gate-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}
#gateCode { letter-spacing: 0.35em; font-variant-numeric: tabular-nums; }
.gate-code-hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.gate-dev-code {
  margin: 0;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: #3a2e14;
  border: 1px solid #6b5420;
  color: var(--warn);
  font-size: 0.85rem;
}
.gate-dev-code[hidden] { display: none !important; }
.gate-dev-code b { font-size: 1.05rem; letter-spacing: 0.15em; }
.gate-error {
  margin: 0.6rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}
.gate-error[hidden] { display: none !important; }

/* Auth toasts (soft ask, passkey offer, confirmations): same
   bottom-center language as the demand toast, sits just above it */
.auth-toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: min(92vw, 500px);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 999px;
  padding: 0.5rem 0.7rem 0.5rem 1rem;
  font-size: 0.9rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  z-index: 70;
  animation: demand-in 200ms ease-out;
}
.auth-toast .auth-toast-btn {
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  border-radius: 999px;
  flex-shrink: 0;
  min-width: 0;
}
.auth-toast-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  flex-shrink: 0;
}
.auth-toast-x:hover { color: var(--text); }

/* ═══ MOBILE ONE-SURFACE LAYOUT (USER 2026-08-13, on iPhone) ═══
   "Chat window inside a chat window is a big problem… stuff at the top
   a banner, everything else full screen." ≤768px there is ONE surface:
   a slim fixed banner, #messages as the ONLY learner scrollport, the
   composer under it. Flyouts, Debug (open) and every modal become
   FULL-SCREEN sheets with their close control at the top. Secondary
   header controls are reparented into the More menu by app.js
   (applyMobileBanner — same nodes, ids/listeners survive).
   Desktop (>768px) is untouched: everything lives in this query.
   This block stays LAST in the file — it must win the cascade over
   the ≤1100/≤900 blocks above. */
@media (max-width: 768px) {
  /* 1) Fixed shell: the page itself can never pan or rubber-band.
     bottom lifts by --kb-gap on older iOS where the keyboard does not
     resize the layout viewport (app.js syncKeyboardGap fallback). */
  .app {
    position: fixed;
    inset: 0;
    bottom: var(--kb-gap, 0px);
    height: auto;
    max-height: none;
    max-width: none;
    margin: 0;
    padding: 0;
    /* Collapsed Debug bar (fixed) already includes its own safe-area
       padding on mobile — do not add the inset twice. */
    padding-bottom: var(--debug-bar, 2.75rem);
  }

  /* 2) Slim banner: one row — logo+title · meter chip · More. */
  .top {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    padding-top: calc(0.4rem + env(safe-area-inset-top, 0px));
    padding-left: calc(0.6rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.6rem + env(safe-area-inset-right, 0px));
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .brand { gap: 0.45rem; min-width: 0; flex: 1 1 auto; }
  .logo { width: 32px; height: 32px; border-radius: 9px; }
  h1 {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-actions {
    width: auto;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    margin-left: auto;
    gap: 0.4rem;
  }

  /* Reparented controls inside the More menu (app.js moves the nodes). */
  .more-menu {
    min-width: min(19rem, calc(100vw - 1rem));
    max-height: min(75dvh, calc(100dvh - 6rem));
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .more-menu [hidden] { display: none !important; }
  .more-menu .btn.ghost {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    font-size: 0.9rem;
    min-height: 44px;
  }
  .more-menu .btn.ghost:hover { background: #222c38; }
  .more-menu .toggle {
    padding: 0.55rem 0.7rem;
    min-height: 44px;
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
  }
  .more-menu .toggle:hover { background: #222c38; }
  .more-menu .voice-rate { color: var(--muted); }
  .more-menu .voice-rate input[type="range"] {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }
  .more-menu .voice-rate span { min-width: 0; }
  .more-menu .xp-board {
    flex: none;
    min-width: 0;
    margin: 0.35rem 0.35rem 0.5rem;
  }

  /* 3) Chat full-bleed: no inner window chrome, one scrollport. */
  .main { margin-top: 0; }
  .chat-panel { border: 0; border-radius: 0; }
  .welcome-room {
    padding: 0.6rem 0.75rem 0.4rem;
    gap: 0.5rem;
    justify-content: flex-start;
  }
  .welcome-room img {
    width: min(100%, 280px);
    max-height: min(38dvh, 260px);
    object-fit: contain;
    border-radius: 14px;
  }
  .welcome-line { font-size: 0.95rem; text-align: center; }
  .messages {
    touch-action: pan-y;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
  }

  /* 4) Flyouts (Progress, Forms) become full-screen sheets with their
     Done button riding a sticky top banner. Above the Debug bar (40). */
  .flyout,
  .flyout-morph {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: none;
    border-radius: 0;
    background: var(--bg-elev);
    filter: none;
    z-index: 45;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .flyout .card {
    border: 0;
    border-radius: 0;
    min-height: 100%;
    padding: 0 0 calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }
  .flyout .card-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 0 0.5rem;
    padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.9rem 0.6rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
  }
  .flyout .journey-body,
  .flyout .morph-body,
  .flyout .journey-foot {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  /* 5) Modals (sheet/help, chapter report, account gate): full-screen
     sheets, close control in the sticky head. Toasts stay small. */
  .sheet-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    backdrop-filter: none;
  }
  .sheet-modal {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0 0.85rem calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  .sheet-head {
    margin: 0 -0.85rem 0.75rem;
    padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.85rem 0.5rem;
    border-bottom: 1px solid var(--border);
  }
  .cycle-overlay,
  .gate-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    backdrop-filter: none;
  }
  .cycle-card,
  .gate-card {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* 6) Debug drawer: collapsed = slim full-width bottom bar; open =
     full-screen sheet (summary row is the top banner; tap toggles). */
  .debug-box {
    left: 0;
    transform: none;
    width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .debug-box:has(#debugDetails[open]) {
    top: 0;
    bottom: 0;
    max-height: none;
    border-top: 0;
    z-index: 48;
    padding-bottom: 0;
  }
  .debug-box:has(#debugDetails[open]) #debugDetails {
    max-height: none;
    flex: 1;
    min-height: 0;
  }
  .debug-box:has(#debugDetails[open]) .debug-summary {
    padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--border);
  }
  .dbg-view { touch-action: pan-y; overscroll-behavior: contain; }
  #debugDetails[open] .debug-body {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  /* Toasts: small, but clear of the home indicator. */
  .demand-toast,
  .auth-toast {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 1.5rem);
  }

  /* No element is user-resizable on mobile (nothing else sets resize). */
  textarea { resize: none; }
}
