/* ==========================================================================
   MandarinListen — Warm Xuan Paper × Taiwan Jade Teal × Persimmon Seal
   3 High-Contrast Themes: paper / dark / eink
   ========================================================================== */

:root,
[data-theme="paper"] {
  --bg: #f9f7f2;
  --bg-subtle: #f1ede3;
  --surface: #ffffff;
  --surface-raised: #fffdf9;
  --border: #e3ddd0;
  --border-strong: #c8bfb0;

  --ink: #1a232b;
  --ink-secondary: #485664;
  --ink-muted: #5a6774;

  --accent: #115e59;
  --accent-hover: #0d4a46;
  --accent-soft: #e3f2f0;
  --accent-ink: #ffffff;

  --warm: #b8531e;
  --warm-soft: #fbeee4;

  --ok: #1e7a4c;
  --ok-soft: #e5f5ec;
  --danger: #b8332a;
  --danger-soft: #fceae8;

  --shadow-sm: 0 1px 2px rgba(26, 35, 43, 0.05);
  --shadow-md: 0 8px 24px rgba(26, 35, 43, 0.07);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --nav-height: 68px;
  --font-sans: "Plus Jakarta Sans", "Noto Sans TC", "Noto Sans JP", "PingFang TC", system-ui, -apple-system, sans-serif;
  --font-zh: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #11161a;
  --bg-subtle: #192127;
  --surface: #1b232a;
  --surface-raised: #222c35;
  --border: #2c3843;
  --border-strong: #415160;

  --ink: #f3efe7;
  --ink-secondary: #c4ced6;
  --ink-muted: #9eb0be;

  --accent: #3eb8b0;
  --accent-hover: #53cac2;
  --accent-soft: rgba(62, 184, 176, 0.16);
  --accent-ink: #071918;

  --warm: #e69d53;
  --warm-soft: rgba(230, 157, 83, 0.16);

  --ok: #46c982;
  --ok-soft: rgba(70, 201, 130, 0.16);
  --danger: #f06e65;
  --danger-soft: rgba(240, 110, 101, 0.17);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.36);
}

[data-theme="eink"] {
  --bg: #ffffff;
  --bg-subtle: #f4f4f4;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #111111;
  --border-strong: #000000;

  --ink: #000000;
  --ink-secondary: #111111;
  --ink-muted: #222222;

  --accent: #000000;
  --accent-hover: #222222;
  --accent-soft: #eaeaea;
  --accent-ink: #ffffff;

  --warm: #000000;
  --warm-soft: #ededed;

  --ok: #000000;
  --ok-soft: #e6e6e6;
  --danger: #000000;
  --danger-soft: #e0e0e0;

  --shadow-sm: none;
  --shadow-md: none;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 18px);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

[data-theme="eink"] .topbar {
  background: #ffffff;
  backdrop-filter: none;
  border-bottom-width: 1.5px;
}

.topbar-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ctrl-pill {
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ctrl-pill:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.ctrl-pill.accent-pill {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 36%, transparent);
  color: var(--accent);
}

@media (max-width: 480px) {
  .brand-sub {
    display: none;
  }
  .ctrl-pill {
    height: 32px;
    padding: 0 8px;
    font-size: 0.74rem;
  }
}

/* ---------- In-App Browser Banner ---------- */
.inapp-banner {
  background: var(--warm-soft);
  border-bottom: 1.5px solid color-mix(in srgb, var(--warm) 40%, transparent);
  color: var(--ink);
}

.inapp-banner-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inapp-banner-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--warm);
}

.inapp-banner-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink);
  line-height: 1.5;
}

.inapp-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Main Container ---------- */
.app-main {
  max-width: 780px;
  margin: 0 auto;
  padding: 16px 16px 28px;
}

.view-panel {
  display: none;
  animation: fadeSlide 0.2s ease;
}

.view-panel.active {
  display: block;
}

[data-theme="eink"] .view-panel {
  animation: none;
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--ink);
}

.section-meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ---------- Home Hero Card ---------- */
.hero-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-md);
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.hero-greeting {
  font-size: 0.84rem;
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 4px;
}

.hero-heading {
  font-size: 1.44rem;
  font-weight: 800;
  line-height: 1.25;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.hero-desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-secondary);
}

.streak-badge {
  background: var(--warm-soft);
  color: var(--warm);
  border: 1px solid color-mix(in srgb, var(--warm) 28%, transparent);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-align: center;
  min-width: 84px;
}

.streak-num {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
}

.streak-lbl {
  font-size: 0.72rem;
  font-weight: 700;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.kpi-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 11px 10px;
  text-align: center;
  border: 1px solid var(--border);
}

.kpi-val {
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
}

.kpi-lbl {
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-top: 3px;
}

.goal-bar-wrap {
  margin-bottom: 16px;
}

.goal-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ---------- Scope Strip & Mode Grid ---------- */
.scope-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}

.scope-strip::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  transition: all 0.15s ease;
}

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

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (max-width: 520px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.mode-btn {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  transition: transform 0.14s ease, border-color 0.15s ease, background 0.15s ease;
}

.mode-btn:hover {
  border-color: var(--accent);
  background: var(--bg-subtle);
}

.mode-btn:active {
  transform: scale(0.985);
}

.mode-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.mode-btn.primary:hover {
  background: var(--accent-hover);
}

.mode-btn.primary .mode-sub {
  color: color-mix(in srgb, var(--accent-ink) 86%, transparent);
}

.mode-ico {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.mode-btn.primary .mode-ico {
  background: rgba(255, 255, 255, 0.18);
  color: var(--accent-ink);
}

.mode-name {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
}

.mode-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* ---------- 7-Level Progress List ---------- */
.level-list {
  display: grid;
  gap: 9px;
}

.level-row {
  display: grid;
  grid-template-columns: 88px 1fr 78px;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.level-row:hover {
  border-color: var(--accent);
  background: var(--bg-subtle);
}

.level-tag {
  font-weight: 800;
  font-size: 0.88rem;
}

.level-badge-band {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 2px;
}

.level-badge-band.band-b {
  color: var(--warm);
  background: var(--warm-soft);
}

.level-badge-band.band-c {
  color: var(--ink-secondary);
  background: var(--bg-subtle);
}

.level-nums {
  text-align: right;
  font-size: 0.78rem;
  color: var(--ink-secondary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-warm {
  background: var(--warm-soft);
  border-color: color-mix(in srgb, var(--warm) 35%, transparent);
  color: var(--warm);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.8rem;
}

/* ---------- Quiz Stage (Blind & Context) ---------- */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.quiz-progress-text {
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.audio-stage {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 16px 16px;
  text-align: center;
  margin: 12px 0 14px;
  box-shadow: var(--shadow-sm);
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.stage-pill.warn {
  color: var(--warm);
  background: var(--warm-soft);
}

.play-orb {
  width: 82px;
  height: 82px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px auto 10px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 32%, transparent);
  transition: transform 0.15s ease, background 0.15s ease;
}

.play-orb:hover {
  background: var(--accent-hover);
  transform: scale(1.04);
}

.play-orb:active {
  transform: scale(0.95);
}

[data-theme="eink"] .play-orb {
  box-shadow: none;
}

.wave-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
}

.wave-bars span {
  width: 4px;
  height: 10px;
  border-radius: 99px;
  background: currentColor;
  transition: height 0.15s ease;
}

.play-orb.playing .wave-bars span {
  animation: soundPulse 0.75s ease-in-out infinite;
}

.play-orb.playing .wave-bars span:nth-child(2) { animation-delay: 0.12s; }
.play-orb.playing .wave-bars span:nth-child(3) { animation-delay: 0.24s; }
.play-orb.playing .wave-bars span:nth-child(4) { animation-delay: 0.36s; }
.play-orb.playing .wave-bars span:nth-child(5) { animation-delay: 0.48s; }

@keyframes soundPulse {
  0%, 100% { height: 8px; }
  50% { height: 28px; }
}

[data-theme="eink"] .play-orb.playing .wave-bars span {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .play-orb.playing .wave-bars span {
    animation: none;
  }
}

.audio-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.context-sentence {
  font-family: var(--font-zh);
  font-size: 1.24rem;
  font-weight: 700;
  line-height: 1.65;
  color: var(--ink);
  margin: 10px auto 6px;
  max-width: 560px;
  letter-spacing: 0.02em;
}

.cloze-blank {
  display: inline-block;
  min-width: 56px;
  border-bottom: 2.5px solid var(--accent);
  color: var(--accent);
  font-weight: 800;
  padding: 0 6px;
}

.cloze-reveal {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 800;
}

.choices-grid {
  display: grid;
  gap: 9px;
}

.choice-btn {
  width: 100%;
  min-height: 54px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.1s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-subtle);
}

.choice-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.choice-key {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--ink-secondary);
}

.choice-text {
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.35;
}

.choice-zh-wrap {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
}

.choice-hanzi {
  font-family: var(--font-zh);
  font-size: 1.18rem;
  font-weight: 800;
}

.choice-phonetic {
  font-family: var(--font-zh);
  font-size: 0.84rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.choice-btn.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.choice-btn.correct .choice-key {
  background: var(--ok);
  border-color: var(--ok);
  color: #ffffff;
}

.choice-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.choice-btn.wrong .choice-key {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

[data-theme="eink"] .choice-btn.correct {
  border-width: 3px;
}

[data-theme="eink"] .choice-btn.wrong {
  border-style: dashed;
  border-width: 2px;
}

/* ---------- Reveal Card ---------- */
.reveal-card {
  margin-top: 14px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  animation: fadeSlide 0.18s ease;
}

.reveal-word-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.reveal-hanzi {
  font-family: var(--font-zh);
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.2;
}

.reveal-phonetic {
  font-family: var(--font-zh);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.reveal-level-pill {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 999px;
}

.reveal-en {
  margin: 8px 0 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.reveal-en-full {
  margin: 4px 0 0;
  font-size: 0.83rem;
  color: var(--ink-secondary);
}

.tone-trap-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--warm-soft);
  border: 1px solid color-mix(in srgb, var(--warm) 30%, transparent);
  color: var(--ink);
  font-size: 0.82rem;
}

.tone-trap-title {
  font-weight: 800;
  color: var(--warm);
  margin: 0 0 6px;
}

.trap-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trap-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--warm) 38%, transparent);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.79rem;
  font-weight: 600;
}

.trap-pill-btn:hover {
  border-color: var(--warm);
  background: var(--bg-subtle);
}

.trap-pill-hanzi {
  font-family: var(--font-zh);
  font-weight: 800;
  font-size: 0.92rem;
}

.example-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.example-zh {
  font-family: var(--font-zh);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 4px;
}

.example-en {
  font-size: 0.86rem;
  color: var(--ink-secondary);
  margin: 0;
}

.reveal-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.reveal-scroll-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.wrong-compare-box {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.45;
}

.wrong-compare-box strong {
  color: var(--danger);
}

/* ---------- Single-Viewport Locked Quiz Mode (ML-BLIND-01/02, ML-CTX-01/02) ---------- */
body.quiz-viewport-lock {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

body.quiz-viewport-lock .app-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 10px 14px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 10px);
  display: flex;
  flex-direction: column;
}

body.quiz-viewport-lock .view-panel.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.quiz-viewport-lock .quiz-header {
  margin-bottom: 6px;
  flex-shrink: 0;
}

body.quiz-viewport-lock .progress-track {
  flex-shrink: 0;
}

body.quiz-viewport-lock #blind-stage-wrap,
body.quiz-viewport-lock #context-stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

body.quiz-viewport-lock .audio-stage {
  margin: 0;
  padding: 13px 14px 11px;
  flex-shrink: 0;
}

body.quiz-viewport-lock .stage-pill {
  margin-bottom: 8px;
}

body.quiz-viewport-lock .play-orb {
  width: 66px;
  height: 66px;
  margin: 2px auto 8px;
}

body.quiz-viewport-lock .context-sentence {
  font-size: 1.12rem;
  line-height: 1.5;
  margin: 6px auto 4px;
}

body.quiz-viewport-lock .choices-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  gap: 8px;
  align-content: start;
}

body.quiz-viewport-lock .choice-btn {
  min-height: 48px;
  padding: 10px 14px;
}

#blind-stage-wrap.is-revealed .audio-stage,
#blind-stage-wrap.is-revealed .choices-grid,
#context-stage-wrap.is-revealed .audio-stage,
#context-stage-wrap.is-revealed .choices-grid {
  display: none !important;
}

#blind-stage-wrap.is-revealed .reveal-card,
#context-stage-wrap.is-revealed .reveal-card {
  flex: 1;
  min-height: 0;
  margin-top: 0;
  display: flex !important;
  flex-direction: column;
  padding: 14px 16px;
}

.reveal-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.reveal-next-btn {
  flex: 1;
  min-width: 130px;
}

/* ---------- Commute Ear-Training Player ---------- */
.commute-stage {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.commute-phase {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.commute-word {
  font-family: var(--font-zh);
  font-size: 2.3rem;
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
}

.commute-phonetic {
  font-family: var(--font-zh);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  margin: 6px 0 8px;
  min-height: 1.4em;
}

.commute-en {
  font-size: 1.04rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 12px;
  min-height: 1.5em;
}

.commute-ex {
  font-family: var(--font-zh);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-secondary);
  margin: 0 auto 4px;
  max-width: 520px;
}

.commute-ex-en {
  font-size: 0.84rem;
  color: var(--ink-muted);
  margin: 0;
}

.commute-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
}

.commute-round-btn {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

.commute-round-btn.main {
  width: 68px;
  height: 68px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-size: 1.45rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (max-width: 520px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-secondary);
  margin-bottom: 5px;
}

.field select,
.field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}

/* ---------- Explorer List ---------- */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-bar input {
  flex: 1;
  min-height: 46px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.94rem;
}

.word-list {
  display: grid;
  gap: 8px;
}

.word-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.word-play-mini {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 0.96rem;
}

.word-body {
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.word-line-1 {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.word-hanzi {
  font-family: var(--font-zh);
  font-weight: 800;
  font-size: 1.08rem;
}

.word-phonetic-inline {
  font-family: var(--font-zh);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.word-meta-tag {
  font-size: 0.72rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.word-en-preview {
  font-size: 0.84rem;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.state-dot {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.state-dot.mastered { background: var(--ok-soft); color: var(--ok); }
.state-dot.mistake { background: var(--danger-soft); color: var(--danger); }
.state-dot.learning { background: var(--accent-soft); color: var(--accent); }
.state-dot.new { background: var(--bg-subtle); color: var(--ink-muted); }

/* ---------- Appendix ---------- */
.appendix-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 14px;
}

.appendix-group + .appendix-group {
  margin-top: 8px;
}

.appendix-group summary {
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.appendix-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.appendix-pill {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-family: var(--font-zh);
  font-size: 0.82rem;
}

.appendix-pill:hover {
  border-color: var(--accent);
}

.affix-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.affix-item:last-child {
  border-bottom: none;
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="eink"] .bottom-nav {
  background: #ffffff;
  backdrop-filter: none;
  border-top-width: 1.5px;
}

.bottom-nav-inner {
  max-width: 780px;
  margin: 0 auto;
  height: var(--nav-height);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-muted);
  font-size: 0.71rem;
  font-weight: 600;
  position: relative;
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

.nav-item.active {
  color: var(--accent);
  font-weight: 800;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 28px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--accent);
}

/* ---------- Modals & Toast ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 22, 28, 0.56);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
}

.modal-backdrop.open {
  display: flex;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 84dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 14px);
  transform: translateX(-50%) translateY(16px);
  z-index: 70;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.attribution-box {
  font-size: 0.8rem;
  color: var(--ink-secondary);
  line-height: 1.65;
}

.attribution-box p {
  margin: 4px 0;
}

.attribution-box a,
.license-section a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.license-section {
  font-size: 0.84rem;
  color: var(--ink-secondary);
  line-height: 1.6;
  margin-bottom: 14px;
}

.license-section h4 {
  margin: 0 0 4px;
  font-size: 0.92rem;
  color: var(--ink);
}

.license-section p {
  margin: 4px 0;
}

.license-pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Global Daily Trends ---------- */
.trends-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.trends-total-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trends-total-num {
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.trends-total-lbl {
  font-size: 0.76rem;
  color: var(--ink-secondary);
}

.trends-tabs {
  display: flex;
  gap: 6px;
}

.trends-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease;
}

.trend-row:hover {
  border-color: var(--border-strong);
}

.trend-rank {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.trend-rank.top {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.trend-count {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.trend-count.hard {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--ink-secondary);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ---------- Screen Code Debug Mode (ML-* / MLM-*) ---------- */
.ml-debug-badge {
  position: fixed;
  z-index: 80;
  display: flex;
  align-items: stretch;
  max-width: calc(100vw - 20px);
  border-radius: 12px;
  border: 1.5px solid var(--accent);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  color: var(--ink);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  font-size: 0.78rem;
}

[data-theme="eink"] .ml-debug-badge {
  background: #ffffff;
  border-width: 2px;
  box-shadow: none;
}

.ml-debug-badge.pos-bl { left: 10px; bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 10px); }
.ml-debug-badge.pos-br { right: 10px; bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 10px); }
.ml-debug-badge.pos-tl { left: 10px; top: 64px; }
.ml-debug-badge.pos-tr { right: 10px; top: 64px; }

.ml-debug-main {
  text-align: left;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ml-debug-main:hover { background: var(--bg-subtle); }

.ml-debug-code {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.ml-debug-name {
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.ml-debug-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.ml-debug-tools {
  display: flex;
  align-items: center;
  border-left: 1px solid var(--border);
  background: var(--bg-subtle);
}

.ml-debug-ico {
  width: 34px;
  height: 100%;
  min-height: 40px;
  display: grid;
  place-items: center;
  font-size: 0.86rem;
  color: var(--ink-secondary);
}

.ml-debug-ico:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.ml-catalog-sheet { max-width: 640px; }

.ml-cat-rows {
  display: grid;
  gap: 7px;
}

.ml-cat-row {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.ml-cat-row:hover {
  border-color: var(--accent);
  background: var(--bg-subtle);
}

.ml-cat-row.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ml-cat-code {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--accent);
  min-width: 112px;
  flex-shrink: 0;
}

.ml-cat-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.ml-cat-name {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink);
}

.ml-cat-target {
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.ml-cat-now {
  font-size: 0.7rem;
  font-weight: 800;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

@media print {
  .topbar,
  .bottom-nav,
  .ml-debug-badge,
  .app-main {
    display: none !important;
  }
  #ml-debug-catalog {
    position: static !important;
    background: #ffffff !important;
    padding: 0 !important;
  }
  #ml-debug-catalog .modal-sheet {
    max-width: 100% !important;
    max-height: none !important;
    border: none !important;
    box-shadow: none !important;
  }
}
