:root {
  --bg: #f4f5f7; --card: #ffffff; --ink: #18202b; --muted: #667085; --line: #e3e6eb;
  --accent: #1b2a41; --accent-ink: #ffffff; --soft: #eef1f6; --muted-bg: #d5d9e0;
  --good: #2f9e44; --warn: #e8a317; --bad: #d9480f;
  --r: 14px; --tab-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --card: #18202b; --ink: #e8ebf0; --muted: #98a2b3; --line: #2a3442;
    --accent: #8fb3ff; --accent-ink: #0f141b; --soft: #222c3a; --muted-bg: #3a4555;
    --good: #51cf66; --warn: #fcc419; --bad: #ff8a5b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --card: #18202b; --ink: #e8ebf0; --muted: #98a2b3; --line: #2a3442;
  --accent: #8fb3ff; --accent-ink: #0f141b; --soft: #222c3a; --muted-bg: #3a4555;
  --good: #51cf66; --warn: #fcc419; --bad: #ff8a5b;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.05rem; margin: 22px 0 8px; }
h3 { font-size: 1rem; margin: 18px 0 6px; }
small { font-size: .8em; }
code { font-size: .85em; background: var(--soft); padding: 1px 4px; border-radius: 4px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--accent); color: var(--accent-ink);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.gear { font-size: 1.3rem; padding: 2px 6px; }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .72rem; color: var(--muted); }
.tabbar a span { font-size: 1.25rem; line-height: 1.2; }
.tabbar a.on { color: var(--ink); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.card.center, .center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card.row-between > div { text-align: center; flex: 1; }
.big { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.right { margin-left: auto; }
.err { color: var(--bad); }
.pre { white-space: pre-wrap; margin: 8px 0 0; }

.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.count { background: var(--accent); color: var(--accent-ink); border-radius: var(--r); padding: 14px; display: flex; gap: 10px; align-items: center; }
.count.alt { background: var(--soft); color: var(--ink); }
.count b { font-size: 2.1rem; line-height: 1; }
.count span { font-size: .85rem; line-height: 1.25; }
.count small { opacity: .75; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary small { font-weight: 400; opacity: .8; width: 100%; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn.good { background: var(--good); color: #fff; border: 0; }
.btn.warn { background: var(--warn); color: #222; border: 0; }
.btn.bad { background: var(--bad); color: #fff; border: 0; }
.bad-text { color: var(--bad); }
.btn:disabled { opacity: .45; }

.bar { display: grid; grid-template-columns: 74px 1fr 92px; align-items: center; gap: 8px; padding: 6px 0; }
.bl { font-size: .9rem; }
.bv { font-size: .9rem; text-align: right; }
.bv i { color: var(--muted); font-style: normal; font-size: .8rem; }
.track { position: relative; height: 10px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; }
.tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--muted); opacity: .6; }
.verdict { font-weight: 600; margin: 12px 0 6px; }
.verdict.ok { color: var(--good); } .verdict.no { color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chip { --c: var(--accent); display: inline-block; border: 1px solid var(--line); border-left: 4px solid var(--c); background: var(--card); border-radius: 10px; padding: 8px 10px; font-size: .88rem; }
.chip em { font-style: normal; color: var(--muted); margin-left: 4px; }
.chip.sm { padding: 3px 9px; font-size: .78rem; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.tag { font-size: .7rem; background: var(--soft); border-radius: 6px; padding: 1px 6px; }

.form label { display: block; margin: 8px 0; font-size: .9rem; }
.form select, .form input[type=date], .form input[type=number], .form input[type=password], .form input:not([type]), textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
fieldset.seg { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; }
fieldset.seg label { display: flex; gap: 8px; align-items: center; }
.dim { opacity: .5; }

.qmeta { display: flex; gap: 10px; align-items: center; font-size: .82rem; color: var(--muted); flex-wrap: wrap; }
.subl { margin: 4px 0 0; font-size: .82rem; }
.qtext { font-size: 1.08rem; font-weight: 500; line-height: 1.55; }
.hint { border-left: 4px solid var(--warn); }
.answerbox { position: relative; }
.answerbox textarea { padding-right: 52px; resize: vertical; }
.mic { position: absolute; right: 8px; top: 12px; width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); font-size: 1.1rem; }
.mic.on { background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.checks label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checks label:last-child { border-bottom: 0; }
.checks input { width: 22px; height: 22px; flex: none; margin-top: 1px; }
details summary { cursor: pointer; font-weight: 600; }
details.follow summary { font-weight: 400; }
.scores { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.scores button { min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 0; }
.scores button.sug { border: 2px dashed var(--accent); }
.scores button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ai { border-left: 4px solid var(--accent); }
.ai p { margin: 8px 0; }
.oralbar { --c: var(--accent); display: flex; justify-content: space-between; background: var(--c); color: #fff; padding: 10px 14px; border-radius: var(--r); margin-bottom: 10px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; }

.flashcard { min-height: 220px; display: flex; flex-direction: column; justify-content: center; gap: 10px; cursor: pointer; }
.flashcard .chip { align-self: flex-start; }
.flashcard .fq { font-size: 1.15rem; font-weight: 600; margin: 0; }
.flashcard .fa { font-size: 1.05rem; margin: 0; padding-top: 10px; border-top: 1px solid var(--line); }

.crit { padding-left: 18px; margin: 12px 0 4px; }
.crit li.ok::marker { content: "✓  "; color: var(--good); }
.crit li.no::marker { content: "✗  "; color: var(--bad); }
.subgrid .sgrow { display: flex; align-items: center; gap: 5px 5px; margin: 5px 0; flex-wrap: wrap; }
.sgt { width: 100%; font-size: .8rem; font-weight: 700; margin-top: 4px; }
.sg { flex: 0 0 calc((100% - 40px) / 9); height: 40px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .85rem; line-height: 1; }
.sg small { font-weight: 400; font-size: .62rem; margin-top: 2px; }
.sg sup { font-size: .55rem; }
.list .li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list .li:last-child { border-bottom: 0; }
.list p { margin: 2px 0; font-size: .9rem; }
.sc { flex: none; width: 34px; height: 34px; border-radius: 17px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .85rem; }

.spinner { width: 34px; height: 34px; margin: 10px auto; border: 4px solid var(--soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: .9rem; opacity: 0; pointer-events: none;
  transition: .25s; max-width: calc(100% - 32px); z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
