:root { --gap: 16px; --panel-width: 360px; }
body { font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0; }
.container { display: flex; flex-direction: column; height: 100vh; }
header { background:#0b4f6c; color: #fff; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
header h1 { margin: 0; font-size: 1.35rem; }
.header-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.starting-point-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.starting-point-label {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
}
.starting-point-btn {
  font: 0.82rem Arial, Helvetica, sans-serif;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.starting-point-btn:hover,
.starting-point-btn:focus-visible {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.72);
  outline: none;
}
.starting-point-btn[data-set="1"] {
  border-color: #7dd3fc;
  background: rgba(3, 105, 161, 0.55);
}
main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, var(--panel-width)); grid-template-rows: 1fr; gap: var(--gap); padding: 12px; }
.left { padding: 8px; border-right: 1px solid #eee; overflow-x: hidden; overflow-y: auto; min-width: 0; min-height: 0; }
/* Conversation section title — sits above Frame / Start controls */
.left > .conversation-heading {
  font: 600 1.1rem Arial, Helvetica, sans-serif;
  color: #111;
  margin: 0 0 10px 0;
}
.right { padding: 8px; border-left: 1px solid #eee; overflow: auto; min-width: 0; }
.controls { margin-bottom:8px; }
#trace { background: #fafafa; border: 1px solid #ddd; padding: 12px; max-height: 400px; overflow:auto; white-space: pre-wrap; }
.card { background: #fff; border: 1px solid #ddd; padding: 12px; max-height: calc(100vh - 160px); overflow:auto; }
.hidden { display: none; }
.nocard { color: #666; }
.error { color: #900; margin-bottom: 8px; }
/* Phase 6 — Card Main Text Hierarchy */

.card-main {
  margin-top: 10px;
  line-height: 1.4;
}

.card-main-hanzi {
  font-size: 1.4rem;
  font-weight: 600;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.card-main-pinyin {
  font: 0.85rem Arial, Helvetica, sans-serif;
  opacity: 0.7;
  margin-top: 2px;
}

.card-main-meaning {
  font: 0.85rem Arial, Helvetica, sans-serif;
  opacity: 0.85;
  margin-top: 6px;
}

/* Phase 6 — Character Chips */

.char-chip {
  font-size: 1rem;
  padding: 6px 10px;
  margin: 4px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.15);
  background: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: all 0.15s ease;
}

.char-chip:hover {
  background: rgba(0,0,0,0.04);
  transform: translateY(-1px);
}

.card-composition-row {
  margin-top: 6px;
}

.card-composition {
  margin-top: 8px;
}

/* Explore word: top row = next-hint (left) + close ✕ (right) */
.card-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.card-toolbar-left {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-close-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #374151;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-close-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

/* In-card progressive hints (pinyin → meaning → characters → etymology) */
.card-inhint-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.card-inhint-next {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #1a56db;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
}
.card-inhint-next:hover {
  background: #dbeafe;
}

.char-chip.char-chip-focus {
  border-color: #1a56db;
  box-shadow: 0 0 0 2px rgba(26, 86, 219, 0.25);
  background: #eff6ff;
}

.card-char-detail {
  font-size: 0.85rem;
  color: #4b5563;
  margin-top: 8px;
  padding: 8px 10px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  line-height: 1.45;
}
.card-char-detail-py {
  font-size: 0.85rem;
  color: #6b7280;
}
.card-char-detail-mean {
  margin-top: 4px;
  color: #374151;
}
.card-char-detail-etym {
  margin-top: 8px;
}
.card-char-detail-etym-empty {
  font-size: 0.75rem;
  color: #6b7280;
  font-style: italic;
}

.char-glyph-fallback .etym-origin {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #374151;
}
.char-glyph-fallback .char-fallback-py {
  color: #6b7280;
  font-weight: 500;
}
.card-char-detail-etym .etym-word {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.card-char-detail-etym .etym-char {
  font-size: 0.75rem;
  padding: 6px 8px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.card-etymology-revealed {
  margin-top: 12px;
}

.card-composition-hint {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 6px;
}

/* Card panel etymology (when available): "Show etymology" expands in place */
.card-etymology {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}
.card-etymology-trigger {
  font-size: 0.85rem;
  font-weight: 500;
  color: #1a56db;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.card-etymology-trigger:hover {
  color: #0d47a1;
}
.card-etymology-content {
  margin-top: 10px;
}
.card-etymology-content .etym-word {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card-etymology-content .etym-char {
  font-size: 0.75rem;
  padding: 6px 8px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}
.card-etymology-content .etym-hanzi {
  font-weight: 600;
  margin-right: 4px;
  font-family: "Ma Shan Zheng", cursive;
}
.card-etymology-content .etym-radical,
.card-etymology-content .etym-decomp,
.card-etymology-content .etym-origin {
  display: block;
  font-size: 0.75rem;
  color: #555;
  margin-top: 2px;
}
.card-etymology-content .etym-mnemonic {
  display: block;
  font-size: 0.75rem;
  color: #333;
  margin-top: 4px;
  font-style: italic;
}
.card-etymology-content .etym-disclaimer {
  display: block;
  font-size: 0.75rem;
  color: #888;
  margin-top: 2px;
}
.card-etymology-content .etym-word-narrative {
  flex: 1 1 100%;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: #f0f7ff;
  border-radius: 6px;
  border: 1px solid #cfe8ff;
}
.card-etymology-content .etym-narrative-type {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #1565c0;
  margin-bottom: 4px;
}
.card-etymology-content .etym-under-chars {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card-etymology-content .etym-structure,
.card-etymology-content .etym-usage-narrative {
  display: block;
  font-size: 0.75rem;
  color: #555;
  margin-top: 2px;
}
.card-etymology-content .etym-usage-narrative {
  color: #2e7d32;
}

/* Explore word (#cardPanel): one readable size for gloss, pinyin, per-character drill, etymology */
#cardPanel .card-main {
  font-size: 1rem;
}
#cardPanel .card-main-hanzi {
  font-size: 1.1rem;
}
#cardPanel .card-main-pinyin,
#cardPanel .card-main-meaning {
  font-size: 1rem;
}
#cardPanel .card-char-detail {
  font-size: 1rem;
  color: #374151;
}
#cardPanel .card-char-detail-py,
#cardPanel .card-char-detail-mean {
  font-size: 1rem;
}
#cardPanel .card-char-detail-etym-empty {
  font-size: 1rem;
}
#cardPanel .card-composition-hint {
  font-size: 1rem;
}
#cardPanel .char-glyph-fallback .etym-origin {
  font-size: 1rem;
}
#cardPanel .card-char-detail-etym .etym-word {
  font-size: 1rem;
}
#cardPanel .card-char-detail-etym .etym-char {
  font-size: 1rem;
  padding: 8px 10px;
}
/* Chip detail: user already selected the glyph — hide duplicate head char before Radical/Form lines */
#cardPanel .card-char-detail-etym .etym-hanzi {
  display: none;
}
#cardPanel .card-char-detail-etym .etym-radical,
#cardPanel .card-char-detail-etym .etym-decomp,
#cardPanel .card-char-detail-etym .etym-origin,
#cardPanel .card-char-detail-etym .etym-structure,
#cardPanel .card-char-detail-etym .etym-usage-narrative,
#cardPanel .card-char-detail-etym .etym-mnemonic,
#cardPanel .card-char-detail-etym .etym-disclaimer,
#cardPanel .card-char-detail-etym .etym-narrative-type {
  font-size: 1rem;
}
#cardPanel .card-etymology-content {
  font-size: 1rem;
}
#cardPanel .card-etymology-content .etym-char {
  font-size: 1rem;
  padding: 8px 10px;
}
#cardPanel .card-etymology-content .etym-hanzi {
  font-size: 1.1rem;
}
#cardPanel .card-etymology-content .etym-radical,
#cardPanel .card-etymology-content .etym-decomp,
#cardPanel .card-etymology-content .etym-origin,
#cardPanel .card-etymology-content .etym-mnemonic,
#cardPanel .card-etymology-content .etym-disclaimer,
#cardPanel .card-etymology-content .etym-structure,
#cardPanel .card-etymology-content .etym-usage-narrative {
  font-size: 1rem;
}
#cardPanel .card-etymology-content .etym-word-narrative {
  font-size: 1rem;
}
#cardPanel .card-etymology-content .etym-narrative-type {
  font-size: 0.85rem;
}
#cardPanel .card-inhint-next {
  font-size: 1rem;
}
#cardPanel .card-close-btn {
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
}
#cardPanel .char-chip {
  font-family: "Ma Shan Zheng", "KaiTi", "STKaiti", serif;
  font-size: 2rem;
  line-height: 1.1;
  padding: 12px 18px;
  margin: 6px 8px;
  min-width: 3.25rem;
  min-height: 3.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Headword row: Hanzi + round speaker (aligned with main word) */
#cardPanel .card-headword-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}
#cardPanel .card-headword-row .card-main-hanzi {
  flex: 1;
  min-width: 0;
}
#cardPanel .card-headword-speak {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #1a56db;
  border-radius: 50%;
  background: #fff;
  color: #1a56db;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#cardPanel .card-headword-speak:hover {
  background: #e8f0fe;
}

/* English gloss for radicals / form pieces */
#cardPanel .etym-components-en {
  display: block;
  font-size: 1rem;
  color: #1e40af;
  margin-top: 4px;
  line-height: 1.4;
}
#cardPanel .etym-word-compositional {
  margin-bottom: 8px;
}

/* ── Phase 7.4: response options (each option is a panel: Chinese row + hints below) ── */
.options-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
  padding: 0 4px;
}

/* One panel per response: border/background so hints clearly sit under the Chinese in this panel */
.option-panel {
  border: 2px solid #ccc;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  width: 100%;
}
.option-panel.selected { border-color: #2563eb; background: #eff6ff; }
/* No visual "correct" cue: all options are suggested responses (Design Constitution: no correct answer). */
/* .option-panel[data-gold="true"] — reserved for internal/trace only; do not style as "the right answer". */
.option-panel[data-slot="true"] { background: #f0fdf4; border-color: #86efac; }
/* Recovery phrase colour handled by .option-panel.recovery-card rules below */
/* Discovery panel: "You interview the persona" mode ──────────────────────── */
#discoveryPanel {
  display: none;
  margin: 8px 0;
  padding: 10px 10px 12px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  /* Cards stack vertically with visible gap between them */
  display: none;
  flex-direction: column;
  gap: 8px;
}
.discovery-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: #0369a1;
  margin-bottom: 2px;
  letter-spacing: 0.03em;
}
.discovery-sub { font-weight: 400; color: #0284c7; }
.discovery-header--deflect { color: #64748b; font-weight: 600; font-style: normal; }

/* ── Discovery card shared layout ─────────────────────────────────────────── */
/* Both question and ack cards: full-width tap target with thumb-friendly height */
.option-panel.discovery-question,
.option-panel.discovery-ack {
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  /* Hairline shadow — enough to separate cards without visual weight */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.option-panel.discovery-question {
  background: #fff;
  border-color: #bae6fd;
}
.option-panel.discovery-question:hover { background: #e0f2fe; border-color: #0284c7; }
.option-panel.discovery-question .op-zh { font-size: 1.1rem; font-weight: 600; color: #0c4a6e; }
.option-panel.discovery-question .op-py { font-size: 0.75rem; color: #0369a1; }
.option-panel.discovery-question .op-en { font-size: 0.75rem; color: #555; font-style: italic; }

.option-panel.discovery-ack {
  background: #f8fafc;
  border-color: #94a3b8;
}
.option-panel.discovery-ack:hover { background: #e2e8f0; border-color: #475569; }
.option-panel.discovery-ack .op-zh { font-size: 1.1rem; font-weight: 600; color: #334155; }
.option-panel.discovery-ack .op-py { font-size: 0.75rem; color: #64748b; }
.option-panel.discovery-ack .op-en { font-size: 0.75rem; color: #64748b; font-style: italic; }

.discovery-footer {
  margin-top: 6px;
  /* No sticky — panel itself is not overflow:scroll, so sticky bottom doesn't fire.
     Full-width button is always visible without needing position tricks. */
}
.discovery-continue-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: #0369a1;
  border: 1.5px solid #0369a1;
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.02em;
  text-align: center;
  box-shadow: 0 1px 3px rgba(3, 105, 161, 0.25);
  transition: background 0.15s, box-shadow 0.15s;
}
.discovery-continue-btn:hover {
  background: #0284c7;
  border-color: #0284c7;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.4);
}


.recovery-panel-label {
  font: 0.85rem Arial, Helvetica, sans-serif;
  font-weight: 600;
  color: #b45309;
  padding: 10px 16px 6px;
}
/* Scrollable stack — fixed pixel height so iOS Safari reliably scrolls.
   Sized to show exactly 2 full cards + a partial peek of a 3rd to signal scrollability. */
.recovery-phrases-scroll {
  height: 220px;
  max-height: min(220px, 40vh);
  overflow-y: scroll;               /* 'scroll' not 'auto' — more reliable on iOS Safari */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 4px 6px 4px;
  box-sizing: border-box;
}
/* Recovery card — same flat flex-wrap layout as .option-panel.discovery-question, amber colours */
.option-panel.recovery-card {
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  cursor: pointer;
  background: #fffbeb;
  border-color: #d97706;
  border-width: 1.5px;
  border-radius: 8px;
  flex-shrink: 0;    /* do not compress — let the scroll container scroll instead */
  transition: background 0.15s, border-color 0.15s;
}
.option-panel.recovery-card:hover,
.option-panel.recovery-card:active { background: #fef3c7; border-color: #b45309; }
.option-panel.recovery-card .op-zh { font-size: 1.1rem; font-weight: 600; color: #b45309; }
.option-panel.recovery-card .op-py { font-size: 0.75rem; color: #92400e; }
.option-panel.recovery-card .op-en { font-size: 0.75rem; color: #78350f; font-style: italic; }
.recovery-phrases-list {
  max-height: 140px;
  overflow-y: auto;
  padding: 6px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.recovery-phrase-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #b45309;
  background: #fff;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 6px 10px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.recovery-phrase-row:hover {
  background: #fef3c7;
  border-color: #d97706;
}
.recovery-phrase-text {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
  padding: 0;
}
.recovery-speaker-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #d97706;
  border-radius: 50%;
  background: #fff;
  color: #b45309;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.recovery-speaker-btn:hover {
  background: #fef3c7;
  border-color: #b45309;
}

.option-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  width: 100%;
  min-height: 52px;
}
.option-btn:hover { background: rgba(0,0,0,0.03); }
/* Hint block directly under the Chinese row, inside the same panel */
.option-hint-block {
  width: 100%;
  margin: 0;
  padding: 10px 16px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fafafa;
  display: none;
}
.option-hint-block .option-hint-row {
  font: 0.85rem Arial, Helvetica, sans-serif;
  margin-top: 4px;
  color: #444;
}
.option-hint-block .option-hint-pinyin { color: #555; }
.option-hint-block .option-hint-meaning { color: #333; }
.option-hint-block .option-hint-etymology { font-size: 0.85rem; }
.option-hint-block .etym-word { margin-top: 6px; }
.option-hint-block .etym-char { margin-bottom: 6px; }
.option-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.option-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.option-speaker-btn,
.option-hint-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.option-speaker-btn:hover,
.option-hint-btn:hover {
  background: #e8f0fe;
  border-color: #1a56db;
}
.option-hint-btn {
  font-weight: 600;
  color: #555;
  font-size: 1rem;
}

.option-hanzi   { font-size: 1.4rem; font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-weight: 600; color: #0d9488; }
/* Clickable word/character spans inside options — match legacy .option-hanzi sizing */
.option-hanzi-tokens {
  display: inline;
  font-size: 1.4rem;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  color: #0d9488;
}
.option-hanzi-tokens .tok-word,
.option-hanzi-tokens .tok-word-unknown {
  color: #0d9488;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.option-hanzi-tokens .tok-word:hover,
.option-hanzi-tokens .tok-word-unknown:hover {
  color: #0f766e;
}

/* Hint cascade step 3 — etymology or character strip */
.hint-depth-block {
  font: 0.85rem/1.45 Arial, Helvetica, sans-serif;
  color: #374151;
  margin-top: 4px;
}
.hint-char-chip {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 1rem;
}

/* Card panel — short pointer to ? cascade + below */
.card-explore-tip {
  font-size: 0.75rem;
  line-height: 1.4;
  color: #6b7280;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #f3f4f6;
}
.option-pinyin  { font: 0.85rem Arial, Helvetica, sans-serif; color: #555; }
.option-meaning { font: 0.85rem Arial, Helvetica, sans-serif; color: #888; }
.option-slot-placeholder {
  display: inline-block;
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 2px;
}

/* Narrow viewports: two columns (1fr + 360px) + gap exceed ~100vw — stack main areas */
@media (max-width: 900px) {
  main {
    grid-template-columns: minmax(0, 1fr);
  }
  .left {
    border-right: none;
  }
  .right {
    border-left: none;
  }
}

/* ── Challenge Mode (C1–C4) ───────────────────────────────────────────────── */
/* Additive overlay: body.challenge-mode gates all visibility changes.
   Removing the class fully restores normal mode — no DOM cleanup needed.    */

/* Transcript: hidden so learner relies on audio only */
body.challenge-mode #transcriptPanel { display: none; }

/* Active sentence text: invisible but structurally present so TTS + DOM are unchanged.
   pointer-events: none prevents accidental token clicks before text is revealed.      */
body.challenge-mode #frameSentence {
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}

/* Mirror / reverse question buttons live in #reverseActionsRow (no inline style set by JS) */
body.challenge-mode #reverseActionsRow { display: none; }

/* Text-revealed override: body class added by _challengeRevealText() after cascade threshold */
body.challenge-mode.challenge-text-revealed #frameSentence {
  visibility: visible;
  pointer-events: auto;
  user-select: auto;
}

/* Challenge recovery zone: recovery phrase buttons, always visible in challenge mode */
#challengeRecoveryZone { display: none; }
body.challenge-mode #challengeRecoveryZone { display: block; margin-top: 10px; }

/* Toggle button: purple tint when active */
#challengeModeBtn.challenge-active {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}
#challengeModeBtn.challenge-active:hover { background: #6d28d9; border-color: #6d28d9; }

/* Controls button row — slightly larger than browser defaults for readability on all screens */
.controls-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.controls-btn-row button {
  padding: 8px 14px;
  font-size: 0.95rem;
  min-height: 38px;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #f1f5f9;
  white-space: nowrap;
}
.controls-btn-row button:hover { background: #e2e8f0; }

/* Transcript history toolbar — one compact size for Display / Speed / Segment */
.transcript-toolbar {
  display: flex;
  align-items: center;
  gap: 6px 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.transcript-toolbar label {
  font: 0.75rem Arial, Helvetica, sans-serif;
  color: #6b7280;
  flex-shrink: 0;
  line-height: 1.2;
}
.transcript-toolbar select,
.transcript-toolbar button {
  font: 0.75rem Arial, Helvetica, sans-serif !important;
  padding: 2px 5px;
  height: 22px;
  min-height: 22px;
  line-height: 1.2;
  box-sizing: border-box;
  flex-shrink: 0;
}
.transcript-toolbar select {
  max-width: 6.5rem;
}
#segmentModeToggle {
  width: 14px;
  height: 14px;
  min-height: 14px;
  margin: 0;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Mobile input usability: extra thumb padding and safe-area breathing room on iPhone */
@media (max-width: 600px) {
  /* Prevent iOS Safari auto-zoom (font must be >= 16px / 1rem on primary inputs) */
  input:not(#segmentModeToggle):not(.transcript-toolbar input),
  select:not(.transcript-toolbar select),
  textarea { font-size: 1rem !important; }

  /* Controls buttons: full 44px touch targets for iPhone */
  .controls-btn-row button {
    padding: 12px 16px;
    font-size: 1rem;
    min-height: 44px;
  }
  .option-btn { padding: 14px 12px; }

  /* Action ladder: bigger mic and suggested-responses tap targets */
  .action-ladder-btn { padding: 12px 18px; min-height: 44px; }
  .action-ladder-btn.mic-only { padding: 12px; min-width: 44px; min-height: 44px; font-size: 1.1rem; }

  /* Play / hint speaker buttons already 44px — keep consistent */
  .play-question-speaker { width: 44px; height: 44px; }

  /* Add bottom padding so content clears the iPhone home indicator */
  .container { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* ── Session Scorecard in-page panel ─────────────────────────────────────── */
.scorecard-panel-inline {
  margin-top: 16px;
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}
.scorecard-panel-inline h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0 0 10px;
}
.scorecard-placeholder {
  font-size: 0.82rem;
  color: #94a3b8;
  font-style: italic;
}
#scorecardContent {
  font-size: 0.85rem;
}
.sc-mode-badge {
  font-size: 0.72rem;
  color: #0891b2;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.progress-saved-msg {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
  font-size: 0.8rem;
  color: #059669;
  font-weight: 500;
}

/* ── Right panel Session / Progress tabs ─────────────────────────────────── */
.right-panel-tabs {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 8px;
}
.right-panel-tab {
  flex: 1;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.right-panel-tab:hover {
  color: #334155;
  background: #f8fafc;
}
.right-panel-tab--active {
  color: #0f766e;
  background: #f0fdfa;
  border-color: #99f6e4;
}
.right-panel-view--hidden {
  display: none !important;
}

/* ── Progress view (conversation journal) ────────────────────────────────── */
.progress-view {
  font-size: 0.84rem;
  color: #334155;
  line-height: 1.45;
}
.progress-headline {
  font-size: 0.95rem;
  font-weight: 500;
  color: #1e293b;
  margin: 0 0 14px;
  line-height: 1.4;
}
.progress-empty {
  padding: 8px 0 4px;
}
.progress-empty-headline {
  font-weight: 600;
  color: #475569;
  margin: 0 0 8px;
}
.progress-empty-body {
  color: #64748b;
  font-size: 0.82rem;
  margin: 0;
  line-height: 1.5;
}
.progress-chart-wrap {
  margin-bottom: 16px;
  padding: 10px 4px 4px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.progress-chart-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  padding-left: 4px;
}
.progress-stability-chart {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
}
.progress-chart-grid {
  stroke: #e2e8f0;
  stroke-width: 1;
}
.progress-chart-line {
  fill: none;
  stroke: #0d9488;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.progress-chart-dot {
  fill: #0d9488;
}
.progress-chart-dot--dim {
  fill: #cbd5e1;
}
.progress-chart-axis-label {
  font-size: 9px;
  fill: #94a3b8;
}
.progress-chart-axis-caption {
  font-size: 9px;
  fill: #94a3b8;
}
.progress-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}
.progress-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.progress-table th {
  text-align: left;
  font-weight: 600;
  color: #64748b;
  padding: 6px 4px;
  border-bottom: 1px solid #e2e8f0;
}
.progress-table td {
  padding: 7px 4px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
.progress-table tbody tr:last-child td {
  border-bottom: none;
}
.progress-tier-note {
  margin-top: 12px;
  font-size: 0.72rem;
  color: #94a3b8;
  font-style: italic;
}

.sc-row {
  margin-bottom: 12px;
}
.sc-row-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 2px;
}
.sc-raw {
  font-weight: 600;
  color: #1e293b;
  font-size: 0.88rem;
}
.sc-sep {
  color: #94a3b8;
  font-size: 0.82rem;
}
.sc-label {
  color: #0891b2;
  font-weight: 600;
  font-size: 0.88rem;
}
.sc-meaning {
  color: #64748b;
  font-size: 0.78rem;
  line-height: 1.35;
}

/* ── Scorecard reflection section (.sc-reflection) ──────────────────────── */
/* Shown at the top of #scorecardContent, above the metric rows.
   Shares .ab-section / .ab-section-title / .ab-list styles with the old
   dashboard — only the wrapper and headline are new here. */
.sc-reflection {
  margin-bottom: 14px;
}
.sc-reflection-headline {
  font-size: 0.97rem;
  font-weight: 500;
  color: #1e293b;
  line-height: 1.45;
  margin-bottom: 12px;
}
.sc-divider {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 0 0 14px;
}

/* ── Session Objective ("Today's focus") ────────────────────────────────── */
/* Shown in the scorecard panel before the session starts and at the top of
   the post-session scorecard. Two states: pre-session (.sc-objective alone)
   and post-session (.sc-objective--post, with a reflection line below). */
.sc-objective {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px 12px 8px;
  margin-bottom: 10px;
}
.sc-obj-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #0369a1;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 5px;
}
.sc-obj-text {
  font-size: 0.87rem;
  color: #1e293b;
  line-height: 1.45;
  margin: 0 0 2px;
}
/* Subtle hint shown during the session (before scorecard fills) */
.sc-obj-hint {
  font-size: 0.78rem;
  color: #94a3b8;
  font-style: italic;
  margin: 4px 0 0;
}
/* Post-session reflection line appended inside .sc-objective--post */
.sc-obj-reflection {
  font-size: 0.82rem;
  line-height: 1.4;
  margin: 7px 0 0;
  padding-top: 7px;
  border-top: 1px dashed #bae6fd;
}
.sc-obj-met {
  color: #166534;   /* green — supportive, not grade-like */
}
.sc-obj-not-met {
  color: #475569;   /* neutral grey — non-judgmental */
}
.sc-objective--post {
  margin-bottom: 0;   /* divider below provides the gap */
}

/* ── Ability Dashboard (#abilityDashboard) ──────────────────────────────── */
/* Kept for reference; the element is no longer rendered in the conversation
   window. Reflection now lives exclusively in the scorecard panel. */
.ability-dashboard {
  display: none !important;   /* guard: prevent accidental re-introduction */
}
.ab-header {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 8px;
}
.ab-headline {
  font-size: 0.97rem;
  font-weight: 500;
  color: #1e293b;
  line-height: 1.45;
  margin-bottom: 14px;
}
.ab-section {
  margin-bottom: 12px;
}
.ab-section:last-child { margin-bottom: 0; }
.ab-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}
.ab-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ab-list li {
  color: #1e293b;
  line-height: 1.55;
  padding: 1px 0;
}
.ab-list li::before {
  content: "• ";
  color: #cbd5e1;
}

/* ── Memory banner (#rememberedFacts) ────────────────────────────────────── */
/* Always visible — shows what the server remembers about the learner.
   Displayed before the first turn so learners can clear stale data. */
.remembered-facts {
  font-size: 0.78rem;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 5px 10px;
  margin: 4px 0 6px;
  line-height: 1.4;
}

/* ── Active conversation panel: prompt + mics pinned, options scroll ─────── */
.current-turn {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.current-turn-focus {
  flex-shrink: 0;
  position: relative;
  z-index: 12;
  isolation: isolate;
  background: #fff;
}

.current-turn-mics {
  flex-shrink: 0;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  position: relative;
  z-index: 13;
}

.current-turn-mics .action-ladder-btn.mic-only,
.current-turn-mics .eng-mic-btn {
  touch-action: manipulation;
  position: relative;
  z-index: 14;
}

.current-turn-options {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-top: 10px;
  margin-top: 4px;
  border-top: 2px solid #e2e8f0;
  position: relative;
  z-index: 1;
}

/* While listening: dim the whole options area so it recedes visually */
body.is-listening .current-turn-options {
  opacity: 0.72;
}
/* Block accidental sentence-option taps while listening, but keep discovery cards tappable
   so the user can switch to a blue card if the mic fails */
body.is-listening #sentenceOptionsContainer,
body.is-listening #optionsContainer {
  pointer-events: none;
  touch-action: none;
}

.recovery-panel-collapsible {
  margin-top: 10px;
}

.recovery-panel-collapsible summary.recovery-panel-toggle {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
}

.recovery-panel-collapsible summary.recovery-panel-toggle::-webkit-details-marker {
  display: none;
}

.active-partner-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 4px;
}

.active-partner-stack .frame-sentence {
  display: block;
  width: 100%;
  line-height: 1.55;
  margin: 0;
  min-height: 0;
  font-size: 1.3rem;
}

.active-partner-stack .frame-english {
  margin: 0;
}

.active-partner-stack .frame-sentence-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 2px;
}

/* When Chinese text + speaker/? are wrapped in a row, pin them side-by-side */
.active-partner-stack .frame-sentence-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 0;
}
.active-partner-stack .frame-sentence-row .frame-sentence {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}
.active-partner-stack .frame-sentence-row .frame-sentence-actions {
  margin-top: 4px;
  justify-content: flex-start;
  flex-shrink: 0;
}

.current-turn-mics .action-ladder {
  margin: 0 0 4px;
  padding: 0;
  border: none;
}

.current-turn-mics .eng-input-panel {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.current-turn #partnerHeader {
  display: none !important;
}

.current-turn .word-insight-token {
  padding: 1px 2px;
  margin: 0;
}

.frame-english {
  display: block;
  width: 100%;
  clear: both;
  font-size: 0.82rem;
  color: #64748b;
  font-style: italic;
  line-height: 1.45;
  padding: 0;
}

.current-turn .hint-row {
  display: block;
  width: 100%;
  clear: both;
  margin: 0;
  line-height: 1.45;
}

.current-turn .hint-pinyin {
  color: #475569;
  font-size: 0.85rem;
}

.current-turn .hint-meaning {
  color: #64748b;
  font-style: italic;
  font-size: 0.82rem;
}

.current-turn .partner-fact-line {
  margin: 0;
}

/* ── Trace toggle ─────────────────────────────────────────────────────────── */
.trace-details {
  margin-top: 16px;
  border-top: 1px solid #e2e8f0;
  padding-top: 6px;
}
.trace-summary {
  font-size: 0.78rem;
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 4px 0;
}
.trace-summary::-webkit-details-marker { display: none; }
.trace-summary:hover { color: #64748b; }

/* ── Speech listening state indicator (#listenStatus) ──────────────────── */
/* Subtle line below the mic — visible only after speech starts; cleared when done. */
.listen-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  max-height: 0;
  transition: opacity 0.18s ease, max-height 0.18s ease, padding 0.18s ease, color 0.3s ease;
  pointer-events: none;
  user-select: none;
}
.listen-status[data-state="listening"],
.listen-status[data-state="waiting"],
.listen-status[data-state="processing"],
.listen-status[data-state="notice"] {
  opacity: 1;
  max-height: 40px;
  padding: 5px 2px 3px;
}
.listen-status:has(.asr-interim-preview) {
  max-height: 96px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.asr-interim-preview {
  flex: 1 1 100%;
  font-size: 0.92rem;
  line-height: 1.4;
  margin-top: 2px;
  padding-left: 1.5rem;
  word-break: break-word;
}
.asr-preview-interim {
  color: #64748b;
  font-style: italic;
  opacity: 0.88;
}
.asr-preview-final {
  color: #0f172a;
  font-weight: 500;
  font-style: normal;
}
.listen-status[data-state="processing"] .asr-interim-preview {
  opacity: 0.75;
}
.listen-status[data-state="processing"] {
  transition: none;
  color: #1e40af;
}
.listen-status[data-state="listening"]  { color: #15803d; }
.listen-status[data-state="waiting"]    { color: #a16207; opacity: 0.72; }
.listen-status[data-state="notice"]     { color: #64748b; font-size: 0.78rem; }

.listen-icon { font-size: 1rem; display: inline-block; line-height: 1; }

@keyframes listen-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.3); }
}
/* Active speech: brisk pulse to convey live activity. */
.listen-status[data-state="listening"] .listen-icon {
  animation: listen-pulse 1.1s ease-in-out infinite;
}
/* Waiting: same icon, slower and shallower pulse — visually "winding down". */
.listen-status[data-state="waiting"] .listen-icon {
  animation: listen-pulse 2.2s ease-in-out infinite;
  opacity: 0.65;
}

/* CSS spinner used for the processing state (more reliable than animated emoji) */
.listen-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid #bfdbfe;
  border-top-color: #2563eb;
  border-radius: 50%;
  flex-shrink: 0;
  animation: listen-spin 0.75s linear infinite;
}
@keyframes listen-spin { to { transform: rotate(360deg); } }

/* Beta learner level gate — first-run / practice level selection */
.level-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
}
.level-gate-overlay.hidden { display: none; }
.level-gate-panel {
  max-width: 520px;
  width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 24px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.level-gate-panel h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  color: #0f172a;
}
.level-gate-sub {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.45;
}
.level-gate-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.level-gate-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.level-gate-option:hover,
.level-gate-option:focus-visible {
  border-color: #0b4f6c;
  background: #eff6ff;
  outline: none;
}
.level-gate-option-title {
  font-weight: 600;
  color: #0f172a;
}
.level-gate-option-desc {
  font-size: 0.85rem;
  color: #64748b;
}
body.comfort-mode .transcript-toolbar label[for="transcriptDisplayMode"]::after {
  content: " (comfort)";
  font-size: 0.7rem;
  color: #64748b;
}

/* ── Mobile conversation-first layout (iPhone / narrow phones) ─────────────── */
.mobile-panel-fab,
.mobile-sheet-backdrop,
.mobile-sheet-header {
  display: none;
}

@media (max-width: 768px) {
  html,
  body {
    overflow: hidden;
    height: 100%;
  }

  .container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    padding: 6px;
    min-height: 0;
    overflow: hidden;
  }

  section.left {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 6px;
    border-right: none;
    overflow: hidden;
  }

  section.left > .conversation-heading,
  section.left > .controls,
  section.left > .remembered-facts {
    flex-shrink: 0;
  }

  section.left > .conversation-heading {
    margin-bottom: 6px;
    font-size: 1rem;
  }

  .controls {
    flex-shrink: 0;
    margin-bottom: 4px;
  }

  /* Prevent iOS pull-to-refresh gesture from wiping an active session.
     overscroll-behavior: none suppresses the native elastic bounce that triggers
     page reload on mobile Chrome; beforeunload JS covers iOS Safari. */
  body.conversation-active {
    overscroll-behavior: none;
  }

  /* During conversation: pin session actions; hide setup-only controls. */
  body.conversation-active .controls {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
    padding-bottom: 4px;
    margin-bottom: 2px;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  }

  body.conversation-active .controls .frame-label,
  body.conversation-active .controls #frameSelect,
  body.conversation-active .controls #runBtn,
  body.conversation-active .controls #startFreshBtn,
  body.conversation-active .controls #challengeModeBtn {
    display: none !important;
  }

  body.conversation-active .remembered-facts {
    display: none !important;
  }

  .conversation-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 6px 0 0;
    overflow: hidden;
  }

  .transcript-panel {
    flex: 0 0 auto;
    max-height: min(20vh, 112px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .transcript-panel-label {
    display: none;
  }

  .transcript-toolbar {
    flex-shrink: 0;
    flex-wrap: nowrap;
    gap: 4px 6px;
    margin-bottom: 3px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .transcript-toolbar::-webkit-scrollbar {
    display: none;
  }

  .transcript-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .current-turn {
    flex: 1 1 auto;
    min-height: 8rem;
    overflow: hidden;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
  }

  .current-turn-focus {
    flex-shrink: 0;
  }

  .active-partner-stack .frame-sentence {
    font-size: 1.2rem;
  }

  .current-turn-mics .action-ladder {
    margin: 0 0 4px;
    gap: 8px;
  }

  .current-turn-mics .action-ladder-btn.mic-only {
    min-width: 44px;
    min-height: 44px;
  }

  .current-turn-mics .eng-input-row {
    gap: 6px;
  }

  .current-turn-mics .eng-mic-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  .current-turn-mics .eng-input-field {
    min-height: 40px;
    padding: 0.45rem 0.55rem;
  }

  .current-turn-options {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .recovery-panel-collapsible .recovery-phrases-scroll {
    height: min(160px, 30vh);
    max-height: min(160px, 30vh);
  }

  .current-turn-label {
    font-size: 0.75rem;
    margin-bottom: 4px;
    flex-shrink: 0;
  }

  body.conversation-active .conversation-heading {
    display: none;
  }

  body.conversation-active .current-turn-label {
    display: none;
  }

  /* Hide entire header (starting point + partner) once a session is running */
  body.conversation-active header {
    display: none;
  }

  body.conversation-active .transcript-panel {
    max-height: min(16vh, 92px);
  }

  /* Aside leaves document flow — overlays only */
  .right {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 0;
    padding: 0;
    border: none;
    overflow: visible;
    pointer-events: none;
    z-index: 400;
    background: transparent;
  }

  .right-explore-heading,
  #noCard {
    display: none !important;
  }

  /* Explore Word: bottom sheet when a word is opened */
  #cardPanel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 52vh;
    margin: 0;
    border: none;
    border-top: 1px solid #e2e8f0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 36px rgba(15, 23, 42, 0.2);
    z-index: 520;
    pointer-events: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  #cardPanel.hidden {
    display: none !important;
  }

  /* Session / progress bottom sheet */
  .mobile-right-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: min(72vh, 560px);
    background: #fff;
    border-radius: 14px 14px 0 0;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.14);
    pointer-events: auto;
    z-index: 480;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform 0.28s ease;
    padding: 0 12px  calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: sticky;
    top: 0;
    background: #fff;
    padding: 10px 2px 8px;
    border-bottom: 1px solid #f1f5f9;
    z-index: 1;
  }

  .mobile-sheet-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #0f172a;
  }

  .mobile-sheet-close {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
  }

  .scorecard-panel-inline {
    margin-top: 8px;
    border-top: none;
    padding-top: 0;
  }

  .scorecard-panel-inline > h2 {
    display: none;
  }

  /* Pre-conversation: compact onboarding strip with dismiss */
  body:not(.conversation-active):not(.session-ended):not(.mobile-panel-open):not(.mobile-guide-collapsed) .mobile-right-sheet {
    transform: translateY(0);
    max-height: 6.5rem;
    overflow: hidden;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  }

  body:not(.conversation-active):not(.session-ended):not(.mobile-panel-open):not(.mobile-guide-collapsed) .mobile-right-sheet .mobile-sheet-header {
    display: flex;
    padding: 6px 2px 2px;
    border-bottom: none;
  }

  body:not(.conversation-active):not(.session-ended):not(.mobile-panel-open):not(.mobile-guide-collapsed) .mobile-right-sheet .mobile-sheet-title {
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #64748b;
  }

  body:not(.conversation-active):not(.session-ended):not(.mobile-panel-open):not(.mobile-guide-collapsed) .mobile-right-sheet .right-panel-tabs {
    display: none;
  }

  body:not(.conversation-active):not(.session-ended):not(.mobile-panel-open):not(.mobile-guide-collapsed) .mobile-right-sheet #rightPanelProgress {
    display: none !important;
  }

  /* After dismiss: sheet fully hidden; reopen via FAB pill only */
  body.mobile-guide-collapsed:not(.mobile-panel-open):not(.session-ended) .mobile-right-sheet {
    transform: translateY(100%);
    max-height: 0;
    overflow: hidden;
    box-shadow: none;
  }

  /* Hide FAB while peek strip is visible — use ✕ on strip, then pill reappears */
  body:not(.mobile-guide-collapsed):not(.conversation-active):not(.session-ended):not(.mobile-panel-open) .mobile-panel-fab {
    display: none;
  }

  /* Active conversation: hide sheet until user asks */
  body.conversation-active:not(.mobile-panel-open):not(.session-ended) .mobile-right-sheet {
    transform: translateY(100%);
  }

  body.mobile-panel-open .mobile-right-sheet {
    transform: translateY(0);
    max-height: min(72vh, 560px);
  }

  body.session-ended.mobile-panel-open .mobile-right-sheet {
    transform: translateY(0);
    max-height: min(85vh, 640px);
  }

  /* FAB toggle for session/progress sheet */
  .mobile-panel-fab {
    display: block;
    position: fixed;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 460;
    padding: 10px 14px;
    font: 600 0.82rem Arial, Helvetica, sans-serif;
    color: #fff;
    background: #0b4f6c;
    border: none;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(11, 79, 108, 0.35);
    cursor: pointer;
  }

  body.mobile-panel-open .mobile-panel-fab {
    background: #475569;
  }

  body.card-sheet-open .mobile-panel-fab {
    opacity: 0;
    pointer-events: none;
  }

  .mobile-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.38);
    z-index: 510;
    pointer-events: auto;
  }

  .mobile-sheet-backdrop.hidden {
    display: none !important;
  }

  body.card-sheet-open .mobile-sheet-backdrop:not(.hidden) {
    z-index: 515;
  }

  /* ── Mobile button density — less bulk, more conversation space ─────────── */
  header {
    padding: 8px 12px;
    gap: 6px;
  }

  header h1 {
    font-size: 1.15rem;
  }

  .starting-point-bar {
    gap: 7px;
  }

  .starting-point-btn {
    padding: 4px 11px;
    font-size: 0.78rem;
  }

  .controls {
    margin-bottom: 2px;
  }

  .controls-btn-row {
    gap: 5px;
  }

  .controls-btn-row button {
    padding: 0.5rem 0.7rem;
    font-size: 0.88rem;
    min-height: 38px;
  }

  #frameSelect {
    min-height: 38px;
    padding: 0.45rem 0.5rem;
  }

  .play-question-speaker {
    width: 38px;
    height: 38px;
    font-size: 0.85rem;
  }

  .frame-sentence-actions {
    display: inline-flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
  }

  #optionsContainer {
    gap: 8px;
    margin: 8px 0;
    padding: 0 2px;
  }

  .option-btn {
    padding: 0.5rem 0.65rem;
    min-height: 42px;
    gap: 8px;
  }

  .option-hint-block {
    padding: 7px 12px 9px;
  }

  .option-speaker-btn,
  .option-hint-btn {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
  }

  .option-panel.discovery-question .op-zh,
  .option-panel.discovery-ack .op-zh,
  .option-panel.recovery-card .op-zh {
    font-size: 1rem;
  }

  #discoveryPanel {
    padding: 7px 8px 9px;
    margin: 5px 0;
    gap: 5px;
  }

  .discovery-continue-btn {
    padding: 0.45rem 0.7rem;
    font-size: 0.85rem;
    min-height: 36px;
  }

  .mobile-panel-fab {
    padding: 7px 12px;
    font-size: 0.78rem;
  }

  .level-gate-option {
    padding: 10px 12px;
  }

  .transcript-panel {
    margin-bottom: 4px;
    padding: 4px 6px;
  }

  .conversation-panel {
    margin: 2px 0 0;
  }

  .remembered-facts {
    margin-bottom: 4px;
    font-size: 0.78rem;
  }

  .right-panel-tab {
    padding: 5px 8px;
    font-size: 0.74rem;
  }
}

/* ── Longitudinal Capability Card ─────────────────────────────────────── */
.capability-card {
  margin-top: 12px;
  border-top: 1px solid #e2e8f0;
  padding-top: 12px;
}
.capability-card__inner {
  font-size: 0.82rem;
  color: #334155;
  line-height: 1.5;
}
.capability-card__title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 2px;
}
.capability-card__subtitle {
  font-size: 0.76rem;
  color: #64748b;
  margin: 0 0 10px;
}
.capability-card__loading,
.capability-card__error {
  font-size: 0.78rem;
  color: #94a3b8;
  padding: 8px 0;
}
.capability-card__empty {
  padding: 6px 0;
}
.capability-card__empty-title {
  font-weight: 500;
  margin: 0 0 4px;
  color: #475569;
}
.capability-card__empty-body {
  font-size: 0.78rem;
  color: #64748b;
  margin: 0;
}
.capability-card__inactive-note {
  font-size: 0.78rem;
  color: #94a3b8;
  font-style: italic;
  margin: 0 0 8px;
}
.capability-dims {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.capability-dim-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.capability-dim-name {
  color: #475569;
}
.capability-dim-band {
  color: #1e293b;
  font-weight: 500;
  white-space: nowrap;
  min-width: 80px;
  text-align: right;
}
.capability-band-bar {
  display: flex;
  gap: 3px;
  align-items: center;
}
.capability-band-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e2e8f0;
  display: inline-block;
}
.capability-band-pip--past {
  background: #94a3b8;
}
.capability-band-pip--active {
  background: #0ea5e9;
}
.capability-card__notes {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.capability-card__notes li {
  font-size: 0.76rem;
  color: #64748b;
  padding-left: 12px;
  position: relative;
}
.capability-card__notes li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: #0ea5e9;
}
.capability-card__disclaimer {
  font-size: 0.72rem;
  color: #94a3b8;
  font-style: italic;
  margin: 0;
}
