:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1c1d21;
  --muted: #6b6a66;
  --line: #e2ded5;
  --accent: #2448b5;
  --accent-ink: #ffffff;
  --accent-soft: #e4e9fa;
  --ok: #1f7a4d;
  --ok-soft: #dcf1e5;
  --warn: #9a5b00;
  --warn-soft: #fbedd2;
  --bad: #b3261e;
  --bad-soft: #fbe0de;
  --rec: #d93a2b;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b; --surface: #1d2027; --surface-2: #262a33; --text: #eceae5; --muted: #9b9a95;
    --line: #2f333d; --accent: #8fa8ff; --accent-ink: #0f1424; --accent-soft: #252d48;
    --ok: #6fd3a0; --ok-soft: #173327; --warn: #f0b860; --warn-soft: #3a2d14;
    --bad: #ff8a80; --bad-soft: #3d1c1a; --rec: #ff6b5c;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161b; --surface: #1d2027; --surface-2: #262a33; --text: #eceae5; --muted: #9b9a95;
  --line: #2f333d; --accent: #8fa8ff; --accent-ink: #0f1424; --accent-soft: #252d48;
  --ok: #6fd3a0; --ok-soft: #173327; --warn: #f0b860; --warn-soft: #3a2d14;
  --bad: #ff8a80; --bad-soft: #3d1c1a; --rec: #ff6b5c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* ---------- generic ---------- */
h1 { font-size: 26px; line-height: 1.2; margin: 4px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 24px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.sub { color: var(--muted); margin: 0 0 16px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--surface-2); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--accent); min-height: 44px; padding: 0 12px; }
.btn:disabled { opacity: 0.5; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: inline-grid; place-items: center; background: var(--surface-2);
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.chip.new { background: var(--accent-soft); color: var(--accent); }
.chip.pattern { background: var(--warn-soft); color: var(--warn); }
mark { background: color-mix(in srgb, var(--warn) 22%, transparent); color: inherit; border-radius: 4px; padding: 0 2px; }

/* ---------- login ---------- */
.login { display: grid; gap: 12px; margin-top: 18vh; }
.login input {
  min-height: 52px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); font-size: 18px;
}

/* ---------- overview ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.units { display: grid; gap: 6px; }
.unit { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.unit:last-child { border-bottom: 0; }
.unit small { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .seen { background: var(--accent-soft); }
.bar .mastered { background: var(--accent); }

/* ---------- review ---------- */
.session-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.progress { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

.card { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 14px 16px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.prompt { font-size: 24px; line-height: 1.25; font-weight: 650; margin: 0; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.prompt.en { font-weight: 600; }
.gloss { color: var(--muted); font-size: 17px; margin: 4px 0 0; }
.listen-only { display: flex; align-items: center; gap: 14px; }
.listen-only .big-play { width: 60px; height: 60px; }
.listen-only .big-play svg { width: 32px; height: 32px; }
.instruction { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.hint { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: 17px; }
.hint small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.steps { display: grid; gap: 8px; margin-top: 10px; }
.mic {
  width: 100%; min-height: 52px; border-radius: 16px; border: 0;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 16px; text-align: left;
}
.mic svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; flex: none; }
.mic small { display: block; font-weight: 500; font-size: 12px; opacity: 0.85; }
.mic small:empty { display: none; }
.mic.secondary { background: var(--surface-2); color: var(--text); }
.mic.recording { background: var(--rec); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.mic.busy { opacity: 0.7; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--rec) 25%, transparent); } }
.level { height: 4px; border-radius: 2px; background: color-mix(in srgb, #fff 35%, transparent); margin-top: 6px; overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: #fff; transition: width 0.08s; }
@media (prefers-reduced-motion: reduce) { .mic.recording { animation: none; } }

.result { border-radius: 14px; padding: 10px 12px; margin-top: 8px; background: var(--surface-2); }
.result.ok { background: var(--ok-soft); }
.result.close { background: var(--warn-soft); }
.result.bad { background: var(--bad-soft); }
.result h3 { margin: 0 0 2px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.result p { margin: 3px 0 0; font-size: 15px; }
.result .heard { color: var(--muted); font-size: 13px; }
.score { margin-left: auto; font-variant-numeric: tabular-nums; }
.words { font-size: 18px; line-height: 1.5; margin: 2px 0; }
.w-ok { color: var(--ok); }
.w-unclear { color: var(--warn); text-decoration: underline dotted; text-underline-offset: 4px; }
.w-missed { color: var(--bad); text-decoration: underline wavy; text-underline-offset: 4px; }
.tips { margin: 4px 0 0; padding-left: 18px; font-size: 15px; }
.tips li { margin: 2px 0; }
.answer { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; }
.answer .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.answer .text { font-size: 17px; font-weight: 600; }

.grade-bar {
  position: sticky; bottom: calc(env(safe-area-inset-bottom) + 70px); z-index: 5;
  margin-top: 10px; padding: 8px; border-radius: 18px;
  background: var(--surface); box-shadow: 0 -2px 18px rgb(0 0 0 / 0.12);
}
.verdict { display: flex; align-items: center; gap: 8px; }
.verdict .btn.primary { min-height: 46px; padding: 0 16px; }
.verdict .btn.ghost { min-height: 40px; padding: 0 8px; font-size: 14px; }
.verdict b { font-size: 16px; padding-left: 6px; }
.verdict span { color: var(--muted); font-size: 13px; }
.override { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.override button { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; }
.override button small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.override button.on { border-color: var(--accent); background: var(--accent-soft); }
.footer-actions { display: grid; gap: 8px; margin-top: 14px; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- placeholder tools ---------- */
.soon ul { padding-left: 18px; }
.soon li { margin: 6px 0; }

/* ---------- settings sheet ---------- */
.sheet { margin-top: 16px; }
.sheet label { display: grid; gap: 6px; margin: 10px 0; font-weight: 600; }
.sheet input[type="range"] { width: 100%; accent-color: var(--accent); }
.sheet .note { color: var(--muted); font-size: 13px; font-weight: 400; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 20;
  max-width: 528px; margin: 0 auto; padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}
