:root {
  --bg: #efefef;
  --primary: #5c8273;
  --primary-dark: #4b6c5f;
  --primary-soft: rgba(92, 130, 115, 0.12);
  --primary-line: rgba(92, 130, 115, 0.35);
  --ink: #2b312e;
  --ink-soft: #6c7571;
  --muted: #9aa19e;
  --card: #f8f8f8;
  --line: #dfe1e0;
  --wrong: #b4695c;
  --wrong-soft: rgba(180, 105, 92, 0.1);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Segoe UI", Roboto, "Microsoft JhengHei", sans-serif;
  --font-roman: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-iansui: "Iansui", var(--font);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 20px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- 首頁 ---------- */

.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(32px + env(safe-area-inset-top)) 0 18px;
}

.home-title {
  margin: 0;
  font-family: var(--font-iansui);
  font-size: 34px;
  font-weight: 400;
  font-synthesis: none;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .home-header > div:first-child { flex: 1; min-width: 0; }

  .home-title {
    /* 扣掉頁面內距與右側兩個圖示後，讓標題在約 320–430px 的手機寬度維持單行 */
    font-size: clamp(20px, calc((100vw - 148px) / 8.7), 34px);
    letter-spacing: 0.03em;
  }
}

.home-subtitle {
  margin: 2px 0 0;
  color: var(--primary);
  font-family: var(--font-roman);
  font-size: 15px;
  letter-spacing: 0.04em;
}

.home-tools {
  display: flex;
  align-items: flex-start;
  flex: none;
  margin-right: -8px;
}

.home-tool { position: relative; }

.home-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.practice-card {
  padding: 4px 8px 10px;
  transition: transform 0.15s ease;
}

.practice-card:has(.practice-link:active) { transform: scale(0.985); }

.practice-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 6px 8px 8px;
  border-radius: 14px;
}

.practice-link:active { background: #f3f3f3; }

.segmented.practice-levels { width: 100%; }

.segmented.practice-levels button {
  flex: 1;
  min-width: 0;
  padding: 6px 2px;
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
}

.unit-icon {
  flex: none;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-iansui);
  font-size: 28px;
  font-weight: 400;
  font-synthesis: none;
}

.unit-icon.is-small { font-size: 19px; letter-spacing: -0.02em; }

.unit-icon.is-pitch {
  background: rgba(90, 115, 140, 0.14);
  color: #5a738c;
}

.unit-icon.is-type {
  background: rgba(196, 154, 46, 0.16);
  color: #b58a1e;
}

.unit-icon.is-spell {
  background: rgba(154, 112, 64, 0.14);
  color: #8f6a42;
}

.unit-body { flex: 1; min-width: 0; }

.unit-title-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.count-badge {
  flex: none;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--wrong-soft);
  color: var(--wrong);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.count-badge.home-badge {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  pointer-events: none;
}

.unit-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--font-iansui);
  font-size: 17px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 22px;
}

.unit-desc { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }

.unit-chevron { flex: none; margin-top: 1px; color: var(--muted); }

/* ---------- 頂部列 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -20px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bg);
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-family: var(--font-iansui);
  font-size: 16px;
  font-weight: 400;
  font-synthesis: none;
  text-align: center;
  letter-spacing: 0.04em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-btn:active { background: rgba(0, 0, 0, 0.05); }

/* ---------- 按鈕 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--primary); color: #fff; }

.btn-primary:active:not(:disabled) { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

.btn-ghost { background: rgba(0, 0, 0, 0.045); color: var(--ink-soft); }

.btn-block { width: 100%; }

.card {
  background: var(--card);
  border-radius: var(--radius);
}

/* ---------- 單畫面版面（不需捲動） ---------- */

.page-fit { overscroll-behavior: none; }

.page-fit .app {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
}

.page-fit .topbar { position: static; flex: none; }

/* ---------- 練習 ---------- */

.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.progress {
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.play-wrap {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 12px 0 28px;
}

.play-hanji { font-family: var(--font-iansui); font-size: 34px; font-weight: 400; font-synthesis: none; color: var(--ink-soft); }

.play-btn {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(92, 130, 115, 0.28);
  transition: transform 0.12s ease;
}

.play-btn:active { transform: scale(0.94); }

.play-btn.is-playing { background: var(--primary-dark); }

.play-btn.is-waiting { opacity: 0.55; }

.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 150px;
  max-height: 420px;
  display: flex;
  padding: 6px 4px;
  box-shadow: inset 0 0 0 1.5px transparent;
  transition: box-shadow 0.2s ease, background 0.2s ease;
}

.stage.is-correct { box-shadow: inset 0 0 0 1.5px var(--primary); background: #f5f8f6; }

.stage.is-wrong { box-shadow: inset 0 0 0 1.5px var(--wrong); background: #faf6f5; }

.stage svg {
  display: block;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}

.stage-letter { font-family: var(--font-iansui); font-size: 100px; font-weight: 400; font-synthesis: none; }

.stage-letter.is-initial { fill: var(--ink-soft); }

.stage-letter.is-final { fill: var(--ink); }

.stage-bracket { stroke: var(--primary-line); stroke-width: 3; stroke-linecap: round; fill: none; }

.stage-label { fill: var(--muted); font-family: var(--font); font-size: 22px; letter-spacing: 2px; }

.ink { fill: none; stroke: var(--primary); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: 0.75; }

.ink.is-unknown { stroke: var(--wrong); opacity: 0.6; }

.stage-hyphen { fill: var(--muted); }

.mark { fill: none; stroke-width: 7.5; stroke-linecap: round; stroke-linejoin: round; }

.mark.is-guess { stroke: var(--primary); }

.mark.is-correct { stroke: var(--primary); }

.mark.is-wrong { stroke: var(--wrong); opacity: 0.75; }

/* 作答前顯示提示、作答後顯示答案，高度固定讓按鈕不會移位 */
.feedback {
  flex: none;
  height: 120px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status {
  margin: 0 4px;
  color: var(--ink-soft);
  font-family: var(--font-iansui);
  font-size: 14px;
  font-weight: 400;
  font-synthesis: none;
  text-align: center;
  white-space: pre-line;
}

.status.is-warn { color: var(--wrong); }

.answer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 16px;
  text-align: center;
}

.answer p { margin: 0; }

.answer-verdict { font-size: 14px; font-weight: 600; letter-spacing: 0.06em; }

.answer-verdict.is-correct { color: var(--primary); }

.answer-verdict.is-wrong { color: var(--wrong); }

.answer-word {
  font-family: var(--font-iansui);
  font-size: 28px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.3;
}

.answer-word .hanji { margin-left: 10px; font-size: 22px; color: var(--ink-soft); }

.answer-meta { color: var(--ink-soft); font-family: var(--font-iansui); font-size: 13px; font-weight: 400; font-synthesis: none; line-height: 1.45; white-space: pre-line; }

/* 先看題目再作答的單元：音節與漢字在上方，作答後才能播放 */
.prompt {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 12px 0;
}

.prompt-word {
  margin: 0;
  font-family: var(--font-iansui);
  font-size: 38px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.2;
}

.prompt-word .hanji { margin-left: 12px; font-size: 32px; color: var(--ink-soft); }

.prompt-word.is-long { font-size: 28px; }

.prompt-word.is-long .hanji { margin-left: 8px; font-size: 24px; }

.play-btn.is-small { width: 48px; height: 48px; box-shadow: 0 4px 12px rgba(92, 130, 115, 0.24); }

.play-btn.is-small svg { width: 22px; height: 22px; }

.play-btn:disabled { opacity: 0.25; box-shadow: none; cursor: default; }

.actions {
  flex: none;
  display: flex;
  gap: 10px;
  padding-top: 12px;
}

.actions .btn { flex: 1; }

.actions .btn-ghost { flex: 0.7; }

/* ---------- 結果 ---------- */

.result-hero { flex: none; margin: 24px 0 18px; text-align: center; }

.result-score {
  font-family: var(--font-roman);
  font-size: 64px;
  font-weight: 300;
  line-height: 1.1;
  color: var(--primary);
}

.result-score small { font-size: 28px; color: var(--muted); }

.result-text { margin-top: 6px; color: var(--ink-soft); }

.review-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.review-list { flex: 0 1 auto; min-height: 0; overflow-y: auto; margin: 0; padding: 6px 0; list-style: none; }

.review-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

.review-item + .review-item { border-top: 1px solid var(--line); }

.review-hanji { width: 1.6em; font-family: var(--font-iansui); font-size: 20px; font-weight: 400; font-synthesis: none; text-align: center; }

.review-body { flex: 1; min-width: 0; }

.review-answer { font-family: var(--font-iansui); font-size: 19px; font-weight: 400; font-synthesis: none; }

.review-yours { color: var(--wrong); font-family: var(--font-iansui); font-size: 13px; font-weight: 400; font-synthesis: none; }

.mini-play {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
}

.review-title { margin: 0 4px 10px; color: var(--muted); font-size: 13px; letter-spacing: 0.06em; }

.result-actions { flex: none; display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 16px; }

@media (max-height: 620px) {
  .play-wrap { margin: 6px 0 16px; }
  .play-btn { width: 56px; height: 56px; }
  .prompt { margin: 8px 0; }
  .prompt-word { font-size: 32px; }
  .feedback { height: 112px; margin-top: 8px; }
  .answer-word { font-size: 24px; }
  .result-hero { margin: 12px 0 10px; }
  .result-score { font-size: 48px; }
}

/* ---------- 選擇題 ---------- */

.stage.is-choices { padding: 10px; }

.choice-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
}

.choice {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px var(--line);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

.choice:active:not(:disabled) { transform: scale(0.97); }

.choice:disabled { cursor: default; opacity: 0.45; }

.choice.is-picked { background: #f2f7f4; box-shadow: inset 0 0 0 2.5px var(--primary); }

.choice.is-correct { opacity: 1; background: #f2f7f4; box-shadow: inset 0 0 0 2.5px var(--primary); }

.choice.is-wrong { opacity: 1; background: #fbf4f2; box-shadow: inset 0 0 0 2.5px var(--wrong); }

.choice.is-wrong .contour { color: var(--wrong); }

.choice .pitch-svg { width: 100%; height: 100%; max-height: 120px; }

.stage.is-choices.is-correct,
.stage.is-choices.is-wrong { box-shadow: none; background: var(--card); }

.btn-placeholder { visibility: hidden; flex: 1; }

/* ---------- 拼寫 ---------- */

.stage.is-spelling { flex-direction: column; gap: 10px; }

.stage.is-type {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 28px 20px;
}

.type-input {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: center;
  font-family: var(--font-iansui);
  font-size: 42px;
  line-height: 1.3;
  color: var(--ink);
  outline: none;
}

.type-input::placeholder {
  color: var(--muted);
  font-size: 22px;
}

.type-input:disabled { opacity: 1; -webkit-text-fill-color: var(--ink); }

.spell-display {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 6px 0 2px;
}

.spell-slot {
  min-width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 6px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px var(--line);
  cursor: default;
}

.spell-slot:disabled { opacity: 1; }

.spell-slot.is-editable { cursor: pointer; }

.spell-slot.is-editable:active { transform: scale(0.97); }

.spell-slot.is-editable .spell-label { color: var(--primary); }

.spell-text { font-family: var(--font-iansui); font-size: 28px; font-weight: 400; font-synthesis: none; line-height: 1.2; white-space: nowrap; }

.spell-slot.is-t .spell-text { font-size: 20px; line-height: 1.68; }

.spell-meta {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-top: 2px;
  line-height: 1.25;
  white-space: nowrap;
}

.spell-label { color: var(--muted); font-size: 11px; }

.spell-fix { color: var(--primary); font-family: var(--font-iansui); font-size: 13px; font-weight: 400; font-synthesis: none; line-height: 1.25; }

.spell-slot.is-pending .spell-text { color: var(--line); }

.spell-slot.is-active { box-shadow: inset 0 0 0 2px var(--primary); }

.spell-slot.is-active .spell-text { color: var(--primary-line); }

.spell-slot.is-given { background: transparent; box-shadow: none; }

.spell-slot.is-given .spell-text { color: var(--ink-soft); }

.spell-slot.is-correct { background: #f2f7f4; box-shadow: inset 0 0 0 2px var(--primary); }

.spell-slot.is-correct .spell-text { color: var(--primary); }

.spell-slot.is-wrong { background: #fbf4f2; box-shadow: inset 0 0 0 2px var(--wrong); }

.spell-slot.is-wrong .spell-text { color: var(--wrong); text-decoration: line-through; text-decoration-thickness: 2px; }

.choice-grid.is-two { grid-template-rows: 1fr; }

.choice.is-text { flex-direction: column; gap: 2px; }

.choice-main { font-family: var(--font-iansui); font-size: 30px; font-weight: 400; font-synthesis: none; color: var(--ink); line-height: 1.2; }

.choice-sub { color: var(--muted); font-family: var(--font-iansui); font-size: 12px; font-weight: 400; font-synthesis: none; }

.choice.is-settled { pointer-events: none; cursor: default; }

.choice.is-settled:not(.has-audio):not(.is-correct):not(.is-wrong) { opacity: 0.45; }

.choice-play {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  pointer-events: auto;
}

.choice-play:active { transform: scale(0.94); }

.choice-play.is-playing { background: var(--primary-dark); }

.choice.is-correct .choice-main { color: var(--primary); }

.choice.is-wrong .choice-main { color: var(--wrong); }

/* ---------- 音值圖 ---------- */

.pitch-svg .staff-line { stroke-width: 1.2; }

.pitch-svg .contour line { stroke-width: 3.6; }

.pitch-svg .contour-head { stroke-width: 1.5; }

.pitch-svg .contour-stop { stroke-width: 2; fill: #fff; }

.staff-divider { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }

.staff-caption { fill: var(--ink-soft); font-family: var(--font-iansui); font-size: 13px; font-weight: 400; }

.pitch-svg.is-tiny { width: 96px; height: auto; display: block; }

.pitch-svg.is-tiny .contour line { stroke-width: 4; }

.pitch-compare { display: flex; gap: 10px; margin-top: 4px; }

.pitch-compare-item { display: flex; flex-direction: column; color: var(--primary); }

.pitch-compare-item small { font-size: 11px; line-height: 1.4; }

.pitch-compare-item.is-wrong { color: var(--wrong); }

.pitch-compare-item.is-wrong .contour { color: var(--wrong); }

.sheet-subtitle { margin: 22px 0 10px; font-size: 16px; }

.sandhi-table { padding: 4px 0; }

.sandhi-row {
  display: grid;
  grid-template-columns: 4.8em 1fr 1fr;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
}

.sandhi-row + .sandhi-row { border-top: 1px solid var(--line); }

.sandhi-word { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }

.sandhi-word strong { font-family: var(--font-iansui); font-size: 16px; font-weight: 400; font-synthesis: none; }

.sandhi-word .roman { font-family: var(--font-iansui); font-size: 13px; font-weight: 400; font-synthesis: none; }

.sandhi-word small { color: var(--muted); font-size: 11px; }

.sandhi-pitch {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.sandhi-play {
  margin-top: 2px;
  padding: 1px 7px;
  font-family: var(--font-iansui);
  font-weight: 400;
  font-synthesis: none;
  border: 0;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
}

.sandhi-play:active { background: rgba(92, 130, 115, 0.22); }

.sandhi-missing {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.sandhi-pitch small { color: var(--muted); font-size: 11px; line-height: 1.3; text-align: center; }

.sandhi-pitch.is-changed small { color: var(--primary); font-weight: 600; }

.sandhi-pitch b {
  color: var(--ink-soft);
  font-family: var(--font-roman);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---------- 題庫檢查 ---------- */

.rv-filters { flex: none; display: flex; gap: 6px; margin: 2px 0 10px; }

.rv-filters select {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.045);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.rv-card {
  flex: 1 1 0;
  min-height: 0;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 16px;
  text-align: center;
}

.rv-card-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

.rv-badge { padding: 0 8px; border-radius: 9px; font-size: 12px; line-height: 20px; }

.rv-badge.is-ok { background: var(--primary-soft); color: var(--primary); }

.rv-badge.is-edit { background: rgba(196, 149, 79, 0.16); color: #a0773a; }

.rv-badge.is-exclude { background: rgba(0, 0, 0, 0.06); color: var(--ink-soft); }

.rv-word { margin: 0; font-family: var(--font-iansui); font-size: 30px; font-weight: 400; font-synthesis: none; line-height: 1.3; }

.rv-word .hanji { margin-left: 10px; font-size: 26px; color: var(--ink-soft); }

.rv-graph-big { width: 100%; max-width: 340px; min-height: 0; flex: 0 1 auto; }

.rv-graph-big .pitch-svg { width: 100%; height: auto; max-height: 160px; display: block; }

.rv-graph-big .staff-caption { font-size: 11px; }

.rv-rule { margin: 0; color: var(--ink-soft); font-size: 14px; }

.rv-card-bottom { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; }

.rv-link {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.rv-link:disabled { opacity: 0.35; cursor: default; }

.rv-link.is-primary { color: var(--primary); font-weight: 600; }

.btn.is-current { box-shadow: inset 0 0 0 2.5px var(--ink-soft); }

.btn-primary.is-current { box-shadow: inset 0 0 0 2.5px var(--primary-dark), 0 0 0 3px var(--primary-soft); }

.rv-nav { flex: none; display: flex; justify-content: space-between; padding-top: 4px; }

.rv-footer {
  flex: none;
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.rv-edit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.rv-edit-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
}

.rv-edit-option .pitch-svg { width: 100%; height: auto; }

.rv-edit-option.is-default { box-shadow: inset 0 0 0 1.5px var(--primary-line); }

.rv-edit-option.is-current { box-shadow: inset 0 0 0 2.5px #c4954f; color: var(--ink); }

.rv-edit-cancel { margin-top: 14px; }

/* ---------- 練習設定 ---------- */

.settings { padding: 4px 0; margin-bottom: 8px; }

.credits {
  margin: 14px 4px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.credits p { margin: 0; }

.credits a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  cursor: default;
}

.setting-row + .setting-row { border-top: 1px solid var(--line); }

.setting-row.is-stack { flex-wrap: wrap; }

.setting-row.is-stack .segmented { flex: 1 1 100%; margin-top: 8px; }

.setting-row.is-stack .segmented button { flex: 1; }

label.setting-row,
button.setting-row { cursor: pointer; }

button.setting-row {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--muted);
}

button.setting-row:active { background: rgba(0, 0, 0, 0.03); }

.install-lead { margin-top: 0; }

.install-steps {
  margin: 4px 0 18px;
  padding: 0;
  list-style: none;
}

.install-steps li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 2px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
}

.install-step-num {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

.setting-name { margin: 0; font-size: 15px; font-weight: 500; }

.setting-desc { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.segmented {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.05);
}

.segmented button {
  min-width: 40px;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.segmented button.is-active {
  background: #fff;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.switch {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 48px;
  height: 28px;
  margin: 0;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch:checked { background: var(--primary); }

.switch:checked::after { transform: translateX(20px); }

.switch:focus-visible { outline: 2px solid var(--primary-line); outline-offset: 2px; }

/* ---------- 錯題本 ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.045);
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.chip.is-active { background: var(--primary); color: #fff; }

.mistake-scope {
  margin: 2px 2px 4px;
  font-family: var(--font-iansui);
  font-size: 17px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.4;
}

.chips:not([hidden]) + .chips-levels { margin-top: -6px; }

.chips-levels .chip {
  min-height: 32px;
  padding: 0 12px;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 13px;
}

.chips-levels .chip.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: none;
  font-weight: 600;
}

.chips-levels.is-root .chip {
  min-height: 36px;
  padding: 0 14px;
  background: rgba(0, 0, 0, 0.045);
  box-shadow: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 400;
}

.chips-levels.is-root .chip.is-active {
  background: var(--primary);
  color: #fff;
}

.mistake-list { margin-top: 4px; }

.mistake-list .review-item { align-items: flex-start; padding: 12px 12px 12px 16px; }

.mistake-list .review-hanji { flex: none; width: 2.2em; padding-top: 2px; }

.mistake-list .mini-play { margin-top: 4px; }

.mistake-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 6px;
  row-gap: 2px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.mistake-stat { white-space: nowrap; }

.tag {
  display: inline-block;
  margin-right: 0;
  padding: 0 7px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  line-height: 18px;
}

.mini-delete {
  flex: none;
  width: 36px;
  height: 36px;
  margin-top: 4px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mini-delete:active { background: rgba(0, 0, 0, 0.05); }

.empty-state { margin: 64px 0 0; text-align: center; }

.empty-title { margin: 0; font-size: 17px; font-weight: 600; }

.empty-text { margin: 4px 0 20px; color: var(--ink-soft); font-size: 14px; }

.mistake-footer { margin-top: 20px; }

.mistake-hint { margin: 0 4px 12px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- 說明面板 ---------- */

.help-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  background: var(--bg);
}

.help-frame {
  width: 100%;
  max-width: 480px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.help-frame .topbar { margin: 0; flex: none; }

.help-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom));
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(30, 36, 33, 0.28);
  animation: fade-in 0.2s ease;
}

.sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 10px 22px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  animation: slide-up 0.25s ease;
}

.sheet-handle { width: 40px; height: 4px; margin: 0 auto 14px; border-radius: 2px; background: rgba(0, 0, 0, 0.12); }

.sheet-title { margin: 0 0 12px; font-size: 18px; }

.help-tabs { width: auto; margin: 0 20px 14px; flex: none; }

.help-tabs button {
  flex: 1;
  min-width: 0;
  padding: 6px 4px;
  font-size: 13px;
  line-height: 1.3;
  white-space: normal;
}

.tone-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tone-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
  padding: 10px 2px 8px;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
}

.tone-cell:active { background: #fff; }

.tone-cell-no { font-size: 18px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

.tone-cell-name { color: var(--muted); font-size: 11px; line-height: 1.3; }

.tone-cell-word {
  font-size: 15px;
  line-height: 1.3;
  white-space: nowrap;
}

.tone-cell-word,
.tone-cell-word b,
.tone-cell-word .roman { font-family: var(--font-iansui); font-weight: 400; font-synthesis: none; }

.tone-cell .mini-pitch { width: 44px; height: 28px; margin-top: 2px; }

.tone-cell-value {
  color: var(--ink-soft);
  font-family: var(--font-roman);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.tone-cell-gap { min-width: 0; }

.mark-block { margin-top: 18px; }

.mark-block h3 {
  margin: 0 2px 6px;
  font-size: 15px;
  font-weight: 600;
}

.mark-block .sheet-text { margin-top: 0; }

.mark-order {
  margin: 8px 0 0;
  padding: 4px 0;
  list-style: none;
  border-radius: var(--radius);
  background: var(--card);
}

.mark-order li {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr);
  align-items: baseline;
  column-gap: 10px;
  padding: 8px 14px;
  font-size: 14px;
}

ol.mark-order li { grid-template-columns: 1.6em 3.2em minmax(0, 1fr); }

.mark-order li + li { border-top: 1px solid var(--line); }

ol.mark-order { counter-reset: mark; }

ol.mark-order li::before {
  content: counter(mark) ".";
  counter-increment: mark;
  color: var(--primary);
  font-weight: 600;
}

.mark-ex {
  color: var(--ink-soft);
  font-family: var(--font-iansui);
  font-size: 13px;
  font-weight: 400;
  font-synthesis: none;
}

.sandhi-chart-wrap { padding: 8px 4px 2px; }

.sandhi-chart { display: block; width: 100%; height: auto; }

.sandhi-chart-arrow {
  fill: none;
  stroke: #2b312e;
  stroke-width: 1.6;
  stroke-linecap: butt;
  marker-end: url(#sandhiHead);
}

.sandhi-chart-num {
  fill: #2b312e;
  font-size: 26px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.sandhi-chart-label {
  fill: #6c7571;
  font-family: var(--font-iansui);
  font-size: 12px;
  font-weight: 400;
  text-anchor: middle;
  dominant-baseline: middle;
}

/* ---------- 音值圖 ---------- */

.mini-pitch { width: 48px; height: 30px; flex: none; }

.staff-line { stroke: #cfd2d1; stroke-width: 2; }

.mini-pitch .staff-line { stroke-width: 1; }

.staff-label { fill: var(--muted); font-family: var(--font-roman); font-size: 20px; }

.contour { color: var(--primary); }

.contour line { stroke: currentColor; stroke-width: 6; stroke-linecap: round; }

.contour-head { fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }

.contour-stop { fill: var(--card); stroke: currentColor; stroke-width: 3; }

.contour.is-wrong { color: var(--wrong); opacity: 0.8; }

.contour.is-variant { opacity: 0.25; }

.mini-pitch .contour line { stroke-width: 2.2; }

.mini-pitch .contour-head { stroke-width: 1; }

.mini-pitch .contour-stop { stroke-width: 1.3; }

.roman { font-family: var(--font-iansui); font-weight: 400; font-synthesis: none; }

.sheet-text { margin: 16px 2px 0; color: var(--ink-soft); font-size: 14px; }

.sheet-text strong { color: var(--ink); font-weight: 600; }

.sheet-text .roman { font-family: var(--font-iansui); font-weight: 400; font-synthesis: none; }

@keyframes fade-in { from { opacity: 0; } }

@keyframes slide-up { from { transform: translateY(40px); opacity: 0.4; } }

@media (min-width: 560px) {
  .home-header { padding-top: calc(48px + env(safe-area-inset-top)); }
}
