/* Stanza design system — 紙色底、五房間各一專屬色、粵拼/IPA 一律等寬字 */
:root {
  --bg: #F5F5F2;
  --card: #FFFFFF;
  --ink: #1B1C1F;
  --muted: #62646C;
  --line: #E2E1DA;
  --soft: #ECEBE5;
  --c-yue: #C22E6E;
  --c-ita: #BC3F2E;
  --c-deu: #566F8C;
  --c-jpn: #3D53A0;
  --c-food: #B97C12;
  --ok: #2E7D4F;
  --bad: #B3392E;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171A;
    --card: #1E2024;
    --ink: #E9E8E4;
    --muted: #9C9EA8;
    --line: #2D2F34;
    --soft: #26282D;
    --c-yue: #E8619E;
    --c-ita: #E26A54;
    --c-deu: #93A6BE;
    --c-jpn: #8296DD;
    --c-food: #E0A343;
    --ok: #58B380;
    --bad: #E0705F;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}
:focus-visible { outline: 2px solid var(--c-jpn); outline-offset: 2px; }
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.02em; }
.topbar-info { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
}
.tabbar button {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
  border-radius: 8px;
}
.tabbar button.on { color: var(--ink); font-weight: 700; }

/* ---- generic components ---- */
.room-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.room-card.pinned { border-color: var(--acc, var(--line)); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.room-name { font-weight: 700; }
.sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 5px; border-radius: 99px; background: var(--soft); overflow: hidden; margin-top: 9px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--acc, var(--muted)); }

.btn {
  display: inline-block;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--acc, var(--ink));
  text-align: center;
}
.btn.ghost { background: var(--soft); color: var(--ink); font-weight: 500; }
.btn.big { padding: 13px 16px; width: 100%; font-size: 15px; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

.pill {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 99px;
  padding: 3px 11px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pill.on { border-color: var(--acc, var(--ink)); color: var(--acc, var(--ink)); font-weight: 600; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; margin: 12px 0; }

.h1 { font-size: 22px; font-weight: 700; margin: 14px 0 2px; }
.h2 { font-size: 16px; font-weight: 700; margin: 18px 0 8px; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0; }

/* ---- practice card ---- */
.practice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 20px;
  text-align: center;
  margin: 14px 0;
}
.practice .term { font-size: 30px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.practice .term.q { font-size: 21px; font-weight: 600; }
.practice .ipa { font-family: var(--font-mono); font-size: 15px; color: var(--acc, var(--muted)); margin-top: 8px; }
.practice .gloss { font-size: 15px; margin-top: 8px; }
.practice .warn {
  background: var(--soft);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 12px;
  text-align: left;
}
.practice .hint { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.actions { display: flex; gap: 8px; margin: 12px 0; }
.actions .btn { flex: 1; }

.grade-row { display: flex; gap: 7px; margin: 12px 0; }
.grade-row .btn { flex: 1; padding: 11px 4px; font-size: 14px; }
.grade-row .g1 { background: var(--bad); }
.grade-row .g2 { background: var(--soft); color: var(--ink); }
.grade-row .g3 { background: var(--acc, var(--ink)); }
.grade-row .g4 { background: var(--soft); color: var(--ink); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 14px 0; }
.choices .btn { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: 600; padding: 15px 8px; font-variant-numeric: tabular-nums; }
.choices .btn.hit { border-color: var(--ok); color: var(--ok); }
.choices .btn.miss { border-color: var(--bad); color: var(--bad); }

.answer-panel { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 14px; text-align: left; }
.answer-panel .de { font-size: 17px; font-weight: 650; }
.answer-panel .zh { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ---- forms ---- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.field input:focus { outline: none; border-color: var(--acc, var(--ink)); }

.line-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 9px;
}
.line-row .de { font-size: 16px; font-weight: 600; }
.line-row .de.blurred { filter: blur(6px); }
.line-row .zh { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.line-row .tools { display: flex; gap: 7px; margin-top: 9px; }
.line-row .tools .btn { font-size: 12.5px; padding: 6px 12px; }

.mono { font-family: var(--font-mono); }
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.center { text-align: center; }
.stack { display: grid; gap: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  border-radius: 99px;
  padding: 8px 18px;
  font-size: 13.5px;
  z-index: 50;
  max-width: 86vw;
}

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- M2/M3: 歌詞、假名、對話 ---- */
.lyric-line { font-size: 20px; line-height: 2.6; letter-spacing: 0.05em; overflow-wrap: anywhere; }
.lyric-line ruby rt { font-family: var(--font-mono); font-size: 9px; color: var(--c-yue); letter-spacing: 0; }
.lyric-line .ch { cursor: pointer; border-radius: 4px; }
.lyric-line .ch.multi { border-bottom: 2px dashed var(--c-yue); }
.lyric-line .ch.sel { background: var(--soft); box-shadow: 0 0 0 2px var(--c-yue); }
.line-block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.line-block.open { border-color: var(--acc, var(--line)); }
.cand-pop { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.stepper { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0; }
.stepper .st { font-size: 11px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; color: var(--muted); background: var(--card); cursor: pointer; }
.stepper .st.done { background: var(--soft); border-color: transparent; }
.stepper .st.on { background: var(--acc, var(--ink)); border-color: transparent; color: #fff; font-weight: 600; }
.yt-box { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 12px; overflow: hidden; margin: 10px 0; }
.yt-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
textarea.lyrics-input { width: 100%; min-height: 180px; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; line-height: 1.8; }
textarea.lyrics-input:focus { outline: none; border-color: var(--acc, var(--ink)); }
.kana-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; margin: 12px 0; }
.kana-grid .k { background: var(--card); border: 1px solid var(--line); border-radius: 9px; text-align: center; padding: 7px 0 5px; font-size: 17px; }
.kana-grid .k small { display: block; font-size: 9.5px; color: var(--muted); font-family: var(--font-mono); }
.kana-grid .k.got { border-color: var(--acc, var(--ink)); }
.tone-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.tone-grid .btn { padding: 12px 4px; }
.tone-grid .btn small { display: block; font-weight: 400; font-size: 10.5px; opacity: 0.75; }
.bubble { max-width: 85%; border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; font-size: 15px; }
.bubble .zh { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bubble.waiter { background: var(--card); border: 1px solid var(--line); margin-right: auto; }
.bubble.you { background: var(--soft); margin-left: auto; border: 1px solid var(--acc, var(--line)); }
.bubble.dim { opacity: 0.45; }
.songrow { cursor: pointer; }
