:root {
  --bg: #f4f7f7;
  --surface: #ffffff;
  --surface-2: #e8efef;
  --text: #11201f;
  --muted: #5b6e6c;
  --border: #d3dfde;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --good: #15803d;
  --good-soft: #dcfce7;
  --review: #b45309;
  --review-soft: #fef3c7;
  --danger: #b91c1c;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1416;
    --surface: #132124;
    --surface-2: #1b2d31;
    --text: #e6f0ef;
    --muted: #93a8a6;
    --border: #26393d;
    --accent: #2dd4bf;
    --accent-text: #052e2b;
    --good: #4ade80;
    --good-soft: #12301f;
    --review: #fbbf24;
    --review-soft: #3a2c0c;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; border-radius: 8px; background: #fff; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 12px; }
.topbar h1, .topbar h2 { margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); color: var(--text);
  width: 44px; height: 44px; border-radius: 22px; font-size: 20px; display: grid; place-items: center; flex: none;
  cursor: pointer; text-decoration: none;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 14px 18px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.review { background: var(--review); border-color: var(--review); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.good, .btn.review { color: #0b1416; } }
.btn.block { width: 100%; }

/* Press and keyboard feedback for everything tappable. */
.btn, .big-choice, .icon-btn, .list a, .list button.item { transition: transform .08s ease, background-color .15s ease; }
.btn:active:not(:disabled), .big-choice:active, .icon-btn:active { transform: scale(.97); }
.list a:active, .list button.item:active { background: var(--surface-2); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.btn.danger { color: var(--danger); }

.big-choice {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  padding: 20px; border-radius: 20px; min-height: 84px; font-size: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  font-weight: 650; cursor: pointer; text-decoration: none;
}
.big-choice .glyph { font-size: 28px; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.big-choice.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.big-choice.primary .glyph { background: rgb(255 255 255 / 18%); }
.big-choice .sub { display: block; font-size: 14px; font-weight: 500; opacity: .8; }

/* ---------- cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--border); }
.list a, .list button.item {
  display: flex; gap: 12px; align-items: center; padding: 14px 16px; color: var(--text); text-decoration: none;
  width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.list .title { font-weight: 600; }
.list .grow { flex: 1; min-width: 0; }
.list .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); }

.chip { display: inline-block; font-size: 13px; font-weight: 650; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.review { background: var(--review-soft); color: var(--review); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats > div { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; }
.stats strong { display: block; font-size: 28px; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats strong small { font-size: 15px; font-weight: 600; color: var(--muted); }
.stats span { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.stats .good strong { color: var(--good); }
.stats .review strong { color: var(--review); }

.progressbar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; }
.progressbar .g { background: var(--good); }
.progressbar .r { background: var(--review); }

.section-label { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 4px 8px; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password] {
  width: 100%; font: inherit; font-size: 17px; padding: 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.setting .grow { flex: 1; }
.setting input[type=range] { width: 120px; accent-color: var(--accent); }
.setting input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.error { color: var(--danger); }

/* ---------- case content ---------- */
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md > :last-child { margin-bottom: 0; }
.stem { font-size: 18px; white-space: normal; }
.part { border-left: 4px solid var(--border); padding: 4px 0 4px 14px; margin: 18px 0; }
.part.current { border-left-color: var(--accent); }
.part .q { font-weight: 650; font-size: 18px; margin-bottom: 8px; }
.part .q img { display: block; margin-top: 8px; }
.answer { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
details.notes { margin-top: 12px; }
details.notes summary { cursor: pointer; font-weight: 650; padding: 8px 0; }

/* ---------- player ---------- */
.player { padding-bottom: 210px; }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
}
.dock-inner { max-width: 680px; margin: 0 auto; }
.status { display: flex; align-items: center; gap: 10px; min-height: 28px; font-weight: 650; margin-bottom: 10px; }
.status [data-r=right] { white-space: nowrap; }
.status .dot { width: 12px; height: 12px; border-radius: 6px; background: var(--muted); flex: none; }
.status.speaking .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.status.listening .dot { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-bottom: 10px; position: relative; }
.meter .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); width: 0; transition: width .1s linear; }
.controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; }
.controls .btn { min-height: 64px; font-size: 18px; }
.mark { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mark .btn { min-height: 88px; font-size: 22px; }

.empty { text-align: center; padding: 48px 16px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; z-index: 50; font-size: 15px;
}
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--surface); border-radius: 20px; padding: 20px; max-width: 420px; width: 100%; }
.modal .row { justify-content: flex-end; margin-top: 16px; }
