:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --ink: #161b26;
  --muted: #5d6576;
  --line: #e2e5ec;
  --brand: #1d3a6e;
  --brand-ink: #ffffff;
  --accent: #c8102e;
  --ok: #17803d;
  --ok-bg: #e5f5ea;
  --bad: #c62828;
  --bad-bg: #fdecec;
  --sel: #e8eefb;
  --mark: #fff1a8;
  --chip: #eceff5;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  --radius: 14px;
  --tabh: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --card: #181f2e;
    --ink: #e8ebf2;
    --muted: #9aa3b5;
    --line: #283246;
    --brand: #8fb0ff;
    --brand-ink: #0f1420;
    --accent: #ff6b7f;
    --ok: #5fd38a;
    --ok-bg: #143322;
    --bad: #ff7a7a;
    --bad-bg: #3a1a1e;
    --sel: #23304a;
    --mark: #5a4b12;
    --chip: #222b3d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.topmeta { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; gap: 12px; align-items: center; }
.topmeta b { color: var(--ink); }

main {
  max-width: 680px; margin: 0 auto;
  padding: 14px 16px calc(var(--tabh) + env(safe-area-inset-bottom) + 96px);
  outline: none;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 600; }

/* chips / filters */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* question card */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 18px 16px; }
.qmeta { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.tag { background: var(--chip); border-radius: 6px; padding: 2px 8px; }
.tag.new { background: var(--sel); color: var(--brand); font-weight: 600; }
.tag.miss { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.qtext { font-size: 19px; font-weight: 600; line-height: 1.4; margin: 0 0 6px; }
.statement { margin: 10px 0 4px; padding: 12px 14px; border-left: 4px solid var(--brand); background: var(--sel); border-radius: 0 10px 10px 0; font-style: italic; font-size: 18px; }
.hint { font-size: 14px; color: var(--muted); margin: 6px 0 0; }

.opts { display: grid; gap: 10px; margin-top: 16px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%;
  min-height: 56px; padding: 14px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: var(--card); font-size: 17px; line-height: 1.35;
  transition: border-color .12s, background .12s;
}
.opt .k { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; background: var(--chip); color: var(--muted); }
.opt[aria-pressed="true"] { border-color: var(--brand); background: var(--sel); }
.opt[aria-pressed="true"] .k { background: var(--brand); color: var(--brand-ink); }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.ok .k { background: var(--ok); color: #fff; }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.opt.bad .k { background: var(--bad); color: #fff; }
.opt.dim { opacity: .55; }
.opt:disabled { cursor: default; color: inherit; }
@media (hover: hover) { .opt:not(:disabled):hover { border-color: var(--brand); } }

.verdict { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; font-weight: 700; font-size: 18px; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }

.explain { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.explain h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.passage { font-size: 16px; line-height: 1.6; margin: 0 0 10px; white-space: pre-line; }
.passage .where { display: block; font-size: 13px; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }
.note { font-size: 15px; background: var(--sel); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.src { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.linkbtn { border: 0; background: none; color: var(--brand); padding: 0; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* sticky action bar */
.actionbar {
  position: fixed; left: 0; right: 0; z-index: 8;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding: 10px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.actionbar .inner { max-width: 680px; margin: 0 auto; display: flex; gap: 10px; }
.btn {
  flex: 1; min-height: 52px; border-radius: 12px; border: 0; cursor: pointer; font-weight: 700; font-size: 17px;
  background: var(--brand); color: var(--brand-ink);
}
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: 600; flex: 0 0 auto; padding: 0 18px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.danger { background: var(--bad); color: #fff; }

/* stats */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--muted); }
h2.sec { font-size: 15px; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.bar { height: 10px; border-radius: 6px; background: var(--chip); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .m { background: var(--ok); }
.bar .g { background: color-mix(in srgb, var(--ok) 45%, var(--chip)); }
.bar .w { background: color-mix(in srgb, var(--bad) 55%, var(--chip)); }
.row { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; margin: 12px 0 6px; }
.row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.days { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; align-items: end; height: 90px; }
.days div { background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.days div.zero { background: var(--chip); }
.dlabels { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; font-size: 10px; color: var(--muted); text-align: center; margin-top: 4px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 15px; }
.list > *:first-child { border-top: 0; }
.list .pass { color: var(--ok); font-weight: 700; }
.list .fail { color: var(--bad); font-weight: 700; }
.list button { border: 0; background: none; width: 100%; text-align: left; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tools { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.tools .btn { flex: 1 1 140px; min-height: 46px; font-size: 15px; }

/* mock test */
.hero { text-align: center; padding: 26px 16px; }
.hero .big { font-size: 56px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.hero .pass { color: var(--ok); }
.hero .fail { color: var(--bad); }
.dots { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; margin: 0 0 14px; }
.dots span { height: 6px; border-radius: 3px; background: var(--chip); }
.dots span.done { background: var(--brand); }
.dots span.cur { background: var(--accent); }
.dots span.ok { background: var(--ok); }
.dots span.bad { background: var(--bad); }
.timer.low { color: var(--bad); font-weight: 700; }
ul.rules { padding-left: 20px; margin: 8px 0 0; }
ul.rules li { margin: 4px 0; }

/* handbook reader */
details.ch { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.ch > summary { padding: 14px 16px; font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
details.ch > summary::-webkit-details-marker { display: none; }
details.ch > summary::after { content: "›"; transform: rotate(90deg); transition: transform .15s; color: var(--muted); }
details.ch[open] > summary::after { transform: rotate(-90deg); }
.chbody { padding: 0 16px 10px; }
.chbody h3 { font-size: 17px; margin: 22px 0 6px; }
.chbody h4 { font-size: 15px; margin: 16px 0 4px; color: var(--brand); }
.chbody p { margin: 0 0 12px; white-space: pre-line; font-size: 16px; line-height: 1.6; }
.chbody p.flash { animation: flash 2.4s ease-out; border-radius: 6px; }
@keyframes flash { 0%, 40% { background: var(--mark); } 100% { background: transparent; } }
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 16px; margin-bottom: 12px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 80px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; }

@media (min-width: 700px) {
  .qtext { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
