:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --ink: #17201b;
  --muted: #5a665f;
  --line: #e0e6e1;
  --brand: #1f4d3a;
  --brand-ink: #ffffff;
  --accent: #c98a0b;
  --ok: #17803d;
  --ok-bg: #e5f5ea;
  --bad: #c62828;
  --bad-bg: #fdecec;
  --sel: #e5f0ea;
  --mark: #fff1a8;
  --chip: #eaeeeb;
  --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: #0e1612;
    --card: #17221c;
    --ink: #e6ede8;
    --muted: #9aaba1;
    --line: #26352d;
    --brand: #7fd1a6;
    --brand-ink: #0e1612;
    --accent: #f0b84a;
    --ok: #5fd38a;
    --ok-bg: #143322;
    --bad: #ff7a7a;
    --bad-bg: #3a1a1e;
    --sel: #1f3329;
    --mark: #5a4b12;
    --chip: #213029;
    --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; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { border: 0; background: none; padding: 4px; margin: -4px 0 -4px -8px; color: var(--brand); cursor: pointer; display: grid; place-items: center; }
.back[hidden] { display: none; }
.back svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.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 (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* unit tags */
.tag.vert { background: color-mix(in srgb, #b5651d 16%, var(--card)); color: color-mix(in srgb, #b5651d 75%, var(--ink)); }
.tag.invert { background: color-mix(in srgb, #2f6fb5 16%, var(--card)); color: color-mix(in srgb, #2f6fb5 75%, var(--ink)); }
.tag.hsl { background: color-mix(in srgb, #8a3fa8 16%, var(--card)); color: color-mix(in srgb, #8a3fa8 75%, var(--ink)); }
.tag.marks { background: none; border: 1px solid var(--line); }
.qmeta .tags { display: flex; gap: 6px; flex-wrap: wrap; }

/* segmented control */
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; margin: 0 0 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 14px; white-space: nowrap; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* question image */
.qimg { display: block; max-width: 100%; max-height: 300px; margin: 12px auto 0; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; }

/* written answers */
textarea.answer { width: 100%; min-height: 110px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 16px; line-height: 1.45; resize: vertical; }
textarea.answer:focus { outline: none; border-color: var(--brand); }
.yours { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--chip); font-size: 15px; white-space: pre-wrap; }
.yours b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.points { margin-top: 14px; }
.points h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 4px; }
.points .need { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.pt { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 11px 12px; border: 2px solid var(--line); background: var(--card); border-radius: 12px; margin-bottom: 8px; cursor: pointer; font-size: 16px; line-height: 1.35; }
.pt .box { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); display: grid; place-items: center; margin-top: -1px; }
.pt[aria-pressed="true"] { border-color: var(--ok); background: var(--ok-bg); }
.pt[aria-pressed="true"] .box { background: var(--ok); border-color: var(--ok); }
.pt[aria-pressed="true"] .box::after { content: ""; width: 10px; height: 6px; border: solid #fff; border-width: 0 0 3px 3px; transform: rotate(-45deg) translate(1px, -1px); }
.pt:disabled { cursor: default; }
.score { font-variant-numeric: tabular-nums; }

/* notes reader */
.group h2.sec:first-child { margin-top: 6px; }
.list .sub { display: block; font-size: 13px; color: var(--muted); }
.list .num { flex: none; width: 30px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.list .ttl { flex: 1; min-width: 0; text-align: left; }
.list .go { color: var(--muted); flex: none; }
article.note { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 18px; overflow-wrap: anywhere; }
article.note h1 { font-size: 22px; line-height: 1.25; margin: 14px 0 8px; letter-spacing: -.01em; }
article.note h1 + h1 { font-size: 18px; margin-top: 0; color: var(--muted); }
article.note h2 { font-size: 19px; margin: 26px 0 8px; line-height: 1.3; padding-top: 14px; border-top: 1px solid var(--line); }
article.note h3 { font-size: 17px; margin: 20px 0 6px; color: var(--brand); }
article.note h4, article.note h5 { font-size: 15px; margin: 16px 0 4px; }
article.note p, article.note li { font-size: 16px; line-height: 1.6; }
article.note p { margin: 0 0 12px; }
article.note ul, article.note ol { padding-left: 22px; margin: 0 0 12px; }
article.note li { margin: 3px 0; }
article.note li > ul, article.note li > ol { margin: 4px 0; }
article.note blockquote { margin: 10px 0 14px; padding: 8px 12px; border-left: 4px solid var(--accent); background: var(--chip); border-radius: 0 10px 10px 0; }
article.note blockquote p { margin: 4px 0; font-size: 15px; }
article.note hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
article.note code { font-size: 14px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
article.note img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; display: block; margin: 8px 0; }
article.note a { color: var(--brand); }
.tbl { overflow-x: auto; margin: 6px -16px 14px; padding: 0 16px; }
.tbl table { border-collapse: collapse; font-size: 14.5px; line-height: 1.45; min-width: 100%; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.tbl th { background: var(--chip); font-weight: 650; }
.tbl td img { max-width: 160px; margin: 0; }
article.note .flash { animation: flash 2.4s ease-out; border-radius: 6px; }
.toc { margin-bottom: 12px; }
.toc summary { cursor: pointer; font-weight: 600; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; list-style: none; }
.toc summary::-webkit-details-marker { display: none; }
.toc[open] summary { border-radius: 12px 12px 0 0; }
.toc .list { border-radius: 0 0 12px 12px; border-top: 0; }
.toc .list button { font-size: 14.5px; padding: 9px 14px; }
.pager { display: flex; gap: 10px; margin-top: 14px; }
.pager button { flex: 1; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px; cursor: pointer; font-size: 14px; }
.pager button:last-child { text-align: right; }
.pager small { display: block; color: var(--muted); font-size: 12px; }
.docmeta { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.docmeta a { color: var(--brand); font-weight: 600; }
.hit { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; cursor: pointer; }
.hit b.t { display: block; font-size: 13px; color: var(--brand); margin-bottom: 2px; }
.hit span { font-size: 15px; line-height: 1.5; }

/* exam */
.papers { display: grid; gap: 10px; }
.paper { display: block; width: 100%; text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; }
.paper[aria-pressed="true"] { border-color: var(--brand); background: var(--sel); }
.paper b { display: block; font-size: 17px; }
.paper span { font-size: 14px; color: var(--muted); }
.units { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.unitres { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.unitres .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.unitres .l { font-size: 13px; color: var(--muted); }
.grade { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-top: 4px; }
.grade.dist { background: color-mix(in srgb, var(--accent) 22%, var(--card)); color: color-mix(in srgb, var(--accent) 70%, var(--ink)); }
.grade.pass { background: var(--ok-bg); color: var(--ok); }
.grade.fail { background: var(--bad-bg); color: var(--bad); }
.hero .dist { color: var(--accent); }
.dots { grid-template-columns: repeat(15, 1fr); }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }

@media (min-width: 700px) {
  .qtext { font-size: 21px; }
  article.note { padding: 10px 28px 24px; }
  .tbl { margin: 6px -28px 14px; padding: 0 28px; }
}
