/* Kaiwa. One reading column, calm like a textbook page. Japanese in a Mincho
   face, kana in a gothic face, English in Fraunces. Palette and type follow
   the stand-alone kaiwa pages (reference/template.html). */
:root {
  --bg: #F2F4F6; --surface: #FFFFFF; --fg: #1B2430; --muted: #5D6B7A;
  --river: #2D5B7B; --gold: #A87A26; --line: #D8DEE5; --mine: #E7EEF4; --done: #8994A0;
  --danger: #A2412F; --ok: #3C7A4E;
  --jp: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --kana: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --latin: "Fraunces", Georgia, serif;
  --ui: "Zen Kaku Gothic New", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121821; --surface: #1A222D; --fg: #E7ECF1; --muted: #97A5B4;
    --river: #7FB0D3; --gold: #D9AA55; --line: #2A3542; --mine: #1E2B38; --done: #6B7785;
    --danger: #E08A78; --ok: #8CC79D; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121821; --surface: #1A222D; --fg: #E7ECF1; --muted: #97A5B4;
  --river: #7FB0D3; --gold: #D9AA55; --line: #2A3542; --mine: #1E2B38; --done: #6B7785;
  --danger: #E08A78; --ok: #8CC79D; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--ui); font-size: 17px; line-height: 1.6; }
body.playing { padding-bottom: 84px; }
a { color: var(--river); }
.wrap { max-width: 40rem; margin: 0 auto; padding-inline: 16px; padding-block: 16px 72px; display: flex; flex-direction: column; gap: 18px; }
.grow { flex: 1; }
.hint { font-size: 14px; color: var(--muted); margin: 0; }
.hint.small, .small { font-size: 13px; }
.hint.warn { color: var(--danger); }
.notice { margin: 0; padding: 10px 12px; border: 1px solid var(--gold); border-radius: 10px; background: var(--surface); font-size: 14px; }
.empty { list-style: none; color: var(--muted); font-size: 15px; padding: 18px 0; margin: 0; }

/* buttons and rows */
button { font: inherit; color: inherit; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row .lab { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); min-width: 4.2rem; }
.row .lab.inline { min-width: 0; margin-left: 6px; }
.row button, .set button { font-size: 14px; padding: 7px 13px; min-height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; }
.row button[aria-pressed="true"], .set button[aria-pressed="true"] { background: var(--river); border-color: var(--river); color: var(--bg); }
.row button.plain, .set button.plain { border-style: dashed; }
.row button.danger { color: var(--danger); }
.row button.small { font-size: 13px; padding: 4px 10px; min-height: 32px; }
.row .sep { width: 1px; height: 22px; background: var(--line); margin-inline: 2px; }
button:focus-visible, a:focus-visible, .turn:focus-visible, .card:focus-visible, summary:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}
button.icon { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--river); display: inline-grid; place-items: center; cursor: pointer; padding: 0; }
button.icon.on { background: var(--danger); border-color: var(--danger); color: var(--bg); }
button.ghost { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--river); font-size: 15px; padding: 6px 4px; cursor: pointer; }

/* main view */
.apphead { display: flex; flex-direction: column; gap: 2px; padding-top: 8px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark { font-family: var(--jp); font-weight: 700; font-size: 34px; line-height: 1.2; }
.brand .word { font-family: var(--latin); font-size: 20px; color: var(--muted); }
.tagline { margin: 0; font-size: 14px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; margin-inline: -16px; padding-inline: 16px; }
.tabs button { border: 0; background: none; padding: 10px 12px; font-size: 15px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--gold); font-weight: 700; }
.badge { font-size: 12px; background: var(--gold); color: var(--bg); border-radius: 999px; padding: 0 7px; margin-left: 2px; font-weight: 700; }

.filters { display: flex; flex-direction: column; gap: 10px; }
input[type="search"], input[type="number"], textarea {
  font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.row.tags button.tag { font-size: 13px; padding: 4px 11px; min-height: 32px; }
.count { margin: 0; font-size: 13px; color: var(--muted); }

.klist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.kcard { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kcard:active { background: var(--mine); }
.kmeta { font-size: 12px; letter-spacing: .04em; color: var(--gold); font-weight: 500; }
.kmeta .imp { color: var(--river); }
.ktitle { font-family: var(--jp); font-size: 23px; line-height: 1.4; font-weight: 700; }
.ksub { font-family: var(--latin); font-size: 16px; color: var(--muted); }
.ktags { font-size: 13px; color: var(--muted); }
.kprog { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.kprog.none { color: var(--done); }
.pbar { position: relative; flex: 0 0 64px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.pbar i, .pbar b { position: absolute; inset: 0 auto 0 0; }
.pbar i { background: var(--gold); opacity: .55; }
.pbar b { background: var(--river); }

.problems { border: 1px solid var(--danger); border-radius: 10px; padding: 10px 14px; background: var(--surface); font-size: 14px; }
.problems summary { color: var(--danger); font-weight: 700; cursor: pointer; }
.prob { margin-top: 10px; }
.prob .src { font-size: 12px; color: var(--muted); }
.prob ul, .report ul { margin: 4px 0 6px; padding-left: 20px; color: var(--muted); }
.report { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--surface); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.rline .st { font-weight: 700; }
.rline.ok .st { color: var(--ok); }
.rline.bad .st { color: var(--danger); }

/* settings */
.settings { display: flex; flex-direction: column; gap: 22px; }
.set { display: flex; flex-direction: column; gap: 8px; }
.set > label, .set .lbl { font-weight: 700; font-size: 15px; }
.set label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.set input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--river); }
.set input[type="number"] { width: 5rem; text-align: center; }
.set button.step { width: 40px; padding: 0; font-size: 20px; }
.set input[type="range"] { width: 100%; accent-color: var(--river); }
.set output { font-weight: 400; color: var(--muted); margin-left: 6px; }
.about { border-top: 1px solid var(--line); padding-top: 12px; }

/* practice view */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: -8px; }
.back { display: inline-flex; align-items: center; gap: 2px; text-decoration: none; font-size: 15px; padding: 6px 4px 6px 0; }
.khead { display: flex; flex-direction: column; gap: 6px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 500; }
h1 { font-family: var(--jp); font-size: clamp(28px, 8vw, 38px); line-height: 1.25; margin: 0; text-wrap: balance; }
h1 small { display: block; font-family: var(--latin); font-size: 18px; color: var(--muted); font-weight: 500; margin-top: 4px; }
.scene { font-size: 15px; color: var(--muted); margin: 0; font-style: italic; }
.meta { font-size: 12px; color: var(--muted); margin: 0; }
.bar { padding-block: 4px 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.bar .row .lab, .bar .row .lab.inline { flex-basis: 100%; min-width: 0; margin: 0 0 -2px; }

ol.turns { list-style: none; margin: 0; padding: 0; }
.turn {
  display: grid; grid-template-columns: 2.6rem 1fr auto; gap: 4px 10px; padding: 14px 6px 14px 6px;
  border-top: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.turn:last-child { border-bottom: 1px solid var(--line); }
.turn.mine { background: var(--mine); }
.turn.current { border-left-color: var(--gold); }
.turn.speaking { border-left-color: var(--river); }
.turn.done .ja, .turn.done .en, .turn.done .cue, .turn.done .kana { color: var(--done); }
.turn.flash { animation: flash 1.6s ease-out; }
.n { font-family: var(--latin); font-weight: 700; color: var(--gold); font-size: 18px; line-height: 1.7; font-variant-numeric: tabular-nums; }
.body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.acts { display: flex; flex-direction: column; gap: 6px; }
.who { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.turn.mine .who { color: var(--river); }
.hardtag { color: var(--danger); border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; font-size: 10px; letter-spacing: .1em; }
.ja { font-family: var(--jp); font-size: 22px; line-height: 1.75; font-weight: 500; }
.kana { font-family: var(--kana); font-size: 15px; color: var(--river); }
.en { font-family: var(--latin); font-size: 16px; color: var(--muted); }
.cue { font-size: 18px; color: var(--fg); }
.cue.kw { font-family: var(--jp); font-size: 21px; color: var(--river); }
.tap { font-size: 12px; color: var(--gold); }
.heard { font-size: 14px; color: var(--fg); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.heard .lab { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.heard [lang="ja"] { font-family: var(--kana); }
.match { font-size: 12px; border-radius: 999px; padding: 0 8px; border: 1px solid currentColor; }
.match.m3 { color: var(--ok); }
.match.m2 { color: var(--gold); }
.match.m1 { color: var(--danger); }

section.extra { display: flex; flex-direction: column; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
h2 { font-family: var(--jp); font-size: 22px; margin: 10px 0 0; }
h2 small { display: block; font-family: var(--ui); font-size: 13px; color: var(--muted); font-weight: 400; }
h2 a { color: var(--fg); text-decoration: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.card .p { font-size: 15px; }
.card .ja { font-size: 20px; }
.hline { cursor: pointer; }
details summary { cursor: pointer; font-size: 14px; color: var(--gold); padding-block: 2px; }
details .ja { font-size: 19px; }
.notes { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.notes p { margin: 0; }
.notes b { color: var(--fg); font-weight: 700; }
.this { border-top: 1px solid var(--line); padding-top: 4px; }

.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: 8px; align-items: center;
  padding: 12px max(16px, calc((100vw - 40rem) / 2)) calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(0 0 0 / .08);
}
.player .pstat { flex: 1; font-size: 14px; }
.player button { font-size: 15px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--river); background: var(--river); color: var(--bg); cursor: pointer; }
.player button.plain { background: none; color: var(--fg); border: 1px dashed var(--line); }
.player button[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 20;
  max-width: min(36rem, calc(100vw - 32px)); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.playing .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) { .turn .reveal { animation: fade .25s ease-out; } }
@keyframes fade { from { opacity: .3; } to { opacity: 1; } }
@keyframes flash { from { background: var(--mine); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } .turn.flash { animation: none; } }
