:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #141a22;
  --muted: #5d6773;
  --line: #dde2e8;
  --accent: #1259a8;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --ok: #1d8a4e;
  --ok-soft: #e1f4e8;
  --warn: #c98a06;
  --bad: #c9352b;
  --bad-soft: #fbe6e4;
  --new: #c6ccd4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 26, 34, .06), 0 2px 8px rgba(20, 26, 34, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318; --surface: #181d24; --surface-2: #222833; --text: #e8ecf1; --muted: #98a2ae;
    --line: #2c333e; --accent: #5ea2ef; --accent-ink: #08111c; --accent-soft: #1b2b40;
    --ok: #47c07c; --ok-soft: #14301f; --warn: #e5ac2e; --bad: #f0675d; --bad-soft: #3a1b19; --new: #3a424e;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318; --surface: #181d24; --surface-2: #222833; --text: #e8ecf1; --muted: #98a2ae;
  --line: #2c333e; --accent: #5ea2ef; --accent-ink: #08111c; --accent-soft: #1b2b40;
  --ok: #47c07c; --ok-soft: #14301f; --warn: #e5ac2e; --bad: #f0675d; --bad-soft: #3a1b19; --new: #3a424e;
  --shadow: none; 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(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
body.immersive { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
#app { max-width: 640px; margin: 0 auto; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h1.sm { font-size: 1.05rem; text-align: center; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h3 { font-size: 1rem; }
p { margin: .5em 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.pad { padding: 0 16px 16px; }
.loading { padding-top: 40vh; text-align: center; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.link { color: var(--accent); font-weight: 600; font-size: .9rem; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--bg);
}
.top.slim { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px; }
.top > span:empty { width: 40px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; min-width: 40px; text-align: right; }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.timer.low { color: var(--bad); }
.search {
  flex: 1; min-width: 0; height: 42px; border-radius: 21px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 0 16px; font: inherit;
}

/* cards & layout */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 { margin-bottom: 10px; }
.section { margin: 20px 4px 8px; font-size: .95rem; }
.section small { font-weight: 400; color: var(--muted); }
.hero { display: flex; gap: 20px; align-items: center; }
.hero-side { flex: 1; display: grid; gap: 8px; }
.kpi { display: flex; align-items: baseline; gap: 6px; }
.kpi b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .9rem; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: -2px 0 4px; }
.bar span { display: block; height: 100%; background: var(--ok); }
.ring { position: relative; width: 116px; height: 116px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .6s; }
.ring-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-text b { font-size: 1.6rem; line-height: 1; }
.ring-text small { color: var(--muted); font-size: .78rem; }
.center .ring { margin: 4px auto 8px; }

.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--new); margin: 6px 0; }
.seg.mastered { background: var(--ok); }
.seg.learning { background: var(--warn); }
.seg.wrong { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.dot.mastered { background: var(--ok); } .dot.learning { background: var(--warn); } .dot.wrong { background: var(--bad); } .dot.new { background: var(--new); }

.resume { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--accent-soft); box-shadow: none; }
.resume small { display: block; color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 20px;
  border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 650; cursor: pointer;
  text-align: center;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: .9rem; border-radius: 10px; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { display: flex; width: 100%; margin-bottom: 12px; }
.btn.big { min-height: 64px; flex-direction: column; gap: 2px; font-size: 1.08rem; }
.btn.big small { font-weight: 400; font-size: .8rem; opacity: .85; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 16px; min-height: 84px; border: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer;
}
.tile small { color: var(--muted); font-size: .82rem; }
.tile:disabled { opacity: .5; cursor: default; }
.tile:active:not(:disabled) { background: var(--surface-2); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { padding: 6px 12px; border-radius: 20px; font-weight: 650; font-size: .88rem; font-variant-numeric: tabular-nums; }
.chip.pass { background: var(--ok-soft); color: var(--ok); }
.chip.fail { background: var(--bad-soft); color: var(--bad); }

/* lists */
.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 12px 14px 16px; background: var(--surface);
  border: 0; border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; cursor: pointer;
}
.list-item > svg { color: var(--muted); width: 20px; height: 20px; }
.list-item:active { background: var(--surface-2); }
.list.flat { gap: 0; }
.list.flat .list-item { box-shadow: none; border-radius: 0; padding-left: 0; padding-right: 0; border-top: 1px solid var(--line); background: transparent; }
.li-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.li-main b { font-weight: 600; font-size: .96rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.li-main small { color: var(--muted); font-size: .82rem; }
.li-main .stack { height: 6px; margin: 4px 0 0; }
.mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; font-size: .85rem; }
.mark.ok { background: var(--ok-soft); color: var(--ok); }
.mark.bad { background: var(--bad-soft); color: var(--bad); }
.pass-t { color: var(--ok); } .fail-t { color: var(--bad); }

/* question */
.qwrap { padding-top: 4px; }
.qmeta { display: flex; align-items: center; gap: 10px; font-size: .82rem; margin-bottom: 10px; }
.qmeta .star { margin-left: auto; width: 36px; height: 36px; color: var(--muted); }
.star.on { color: var(--warn); }
.star.on svg { fill: currentColor; }
.pts { padding: 3px 9px; border-radius: 8px; font-weight: 700; background: var(--surface-2); }
.pts.p5 { background: var(--bad-soft); color: var(--bad); }
.pts.p4 { background: #fdf0d8; color: #8a5d00; }
:root[data-theme="dark"] .pts.p4 { background: #3a2d10; color: var(--warn); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pts.p4 { background: #3a2d10; color: var(--warn); } }
.st { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.st.new { color: var(--muted); } .st.wrong { color: var(--bad); } .st.learning { color: var(--warn); } .st.mastered { color: var(--ok); }
.media { margin: 0 -16px 14px; background: #000; position: relative; }
.media img, .media video { display: block; width: 100%; height: auto; max-height: 52vh; object-fit: contain; aspect-ratio: 640 / 384; }
.media.pic { background: #fff; }
.media img { cursor: zoom-in; }
.plays { position: absolute; right: 10px; top: 10px; background: rgba(0, 0, 0, .6); color: #fff; padding: 3px 8px; border-radius: 6px; }
@media (min-width: 672px) { .media { margin: 0 0 14px; border-radius: var(--radius); overflow: hidden; } }
.qtext { font-size: 1.15rem; font-weight: 650; margin-bottom: 4px; }
.hint { display: block; margin-bottom: 12px; font-size: .82rem; }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 14px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); transition: border-color .15s, background .15s;
}
.opt .box {
  flex: none; width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; color: var(--muted);
}
.opt .otext { padding-top: 2px; }
.opt .otext img { max-width: 120px; max-height: 120px; display: block; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.opt:disabled { cursor: default; color: var(--text); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.missed { border-color: var(--ok); border-style: dashed; }
.opt.missed .box { border-color: var(--ok); color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .box { background: var(--bad); border-color: var(--bad); color: #fff; }
.num-wrap { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
.num {
  font: inherit; font-size: 1.4rem; font-weight: 650; height: 56px; width: 160px; padding: 0 14px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
.num:focus { outline: none; border-color: var(--accent); }
.num-answer { font-size: 1.05rem; }
.exp { margin-top: 16px; background: var(--surface); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.exp summary { font-weight: 650; cursor: pointer; }
.exp p { color: var(--text); font-size: .95rem; }
.chap { display: block; margin-top: 12px; font-size: .8rem; }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  padding: 12px max(16px, calc((100vw - 640px) / 2 + 16px)) calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.actions .btn { min-width: 120px; }
.actions .btn:last-child { flex: 1; max-width: 260px; }
.verdict { margin-right: auto; font-weight: 750; font-size: 1.05rem; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.flagbtn { margin-right: auto; color: var(--muted); }
.flagbtn.on { color: var(--warn); }
.flagbtn.on svg { fill: currentColor; }

/* exam navigator */
.qnav { display: flex; gap: 6px; overflow-x: auto; padding: 2px 16px 10px; scrollbar-width: none; max-width: 640px; margin: 0 auto; }
.qnav::-webkit-scrollbar { display: none; }
.qnav button {
  flex: none; width: 34px; height: 34px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface);
  font-size: .82rem; font-weight: 650; cursor: pointer; position: relative; font-variant-numeric: tabular-nums;
}
.qnav button.done { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.qnav button.cur { border-color: var(--accent); border-width: 2px; }
.qnav button.flag::after { content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.facts { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
.result p { text-wrap: balance; }
.result .big-verdict { font-size: 2rem; font-weight: 800; margin: 4px 0; }
.result.pass .big-verdict { color: var(--ok); }
.result.fail .big-verdict { color: var(--bad); }

/* charts */
.cols { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.col span { width: 100%; max-width: 22px; background: var(--accent); border-radius: 4px 4px 2px 2px; min-height: 2px; }
.col small { font-size: .7rem; color: var(--muted); }
.echart { width: 100%; height: auto; display: block; stroke: none; }
.echart rect.pass { fill: var(--ok); } .echart rect.fail { fill: var(--bad); }
.echart text { fill: var(--muted); font-size: 11px; stroke: none; }
.echart .limit { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }

/* forms */
.form { display: grid; gap: 4px; }
.form label { display: flex; justify-content: space-between; align-items: center; min-height: 48px; border-bottom: 1px solid var(--line); }
.form label:last-child { border-bottom: 0; }
.form select { font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); }
.form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tabs[hidden] { display: none; }
.tabs a { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabs a.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 20;
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.zoom { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .92); display: grid; place-items: center; cursor: zoom-out; }
.zoom img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

@media (hover: hover) {
  .opt:hover:not(:disabled) { border-color: var(--accent); }
  .list-item:hover, .tile:hover:not(:disabled) { background: var(--surface-2); }
}
