* { box-sizing: border-box; }
html { scroll-padding-top: 120px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--body); font-size: 15px; line-height: 1.5;
}
.wrap {
  max-width: 680px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px 48px;
  display: flex; flex-direction: column; gap: 20px; min-height: 100vh;
}
main { display: flex; flex-direction: column; gap: 20px; flex: 1; }
a { color: var(--accent); text-underline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-family: var(--display); font-weight: 700; font-size: 18px; margin: 0; }
.sub { color: var(--muted); margin: 0; font-size: 14px; }
.topnav { display: flex; gap: 16px; align-items: baseline; font-size: 14px; font-weight: 500; }
.topnav .brand { font-family: var(--display); font-weight: 700; font-size: 18px; text-decoration: none; margin-right: auto; color: var(--fg); }
.topnav a[aria-current="page"] { text-decoration: underline; }
header.page { display: flex; flex-direction: column; gap: 6px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card .title { font-family: var(--display); font-weight: 700; font-size: 18px; }
.meta { color: var(--muted); font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-variant-numeric: tabular-nums; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.primary { background: var(--accent); color: var(--surface); border: 1px solid var(--accent); border-radius: 6px; padding: 9px 16px; font-weight: 600; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 9px 16px; font-weight: 600; }
.danger { color: var(--wrong); }
a.btn { display: inline-block; text-decoration: none; }
.primary:disabled, .ghost:disabled { opacity: 0.5; cursor: default; }

/* sticky bar */
.bar {
  position: sticky; top: 0; z-index: 5; background: var(--bg); padding-block: 10px;
  display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line);
}
.chip {
  font-size: 13px; font-weight: 500; padding: 5px 12px; border: 1px solid var(--line);
  background: transparent; border-radius: 999px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 14px; font-size: 14px; }
.note { font-size: 13px; color: var(--muted); margin: 0; border-left: 3px solid var(--hard); padding-left: 10px; }

/* problem list */
ol.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.item { display: flex; flex-direction: column; gap: 12px; padding: 12px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item:target { box-shadow: inset 4px 0 0 var(--accent); }
.head { display: flex; align-items: center; gap: 12px; }
.num {
  font-family: var(--display); font-weight: 700; font-size: 17px; width: 2.2em; height: 2.2em; flex: none;
  display: grid; place-items: center; border: 1.5px solid var(--line); border-radius: 50%; font-variant-numeric: tabular-nums;
}
.item.w .num { border-color: var(--wrong); color: var(--wrong); background: var(--wrong-soft); }
.item.h:not(.w) .num { border-color: var(--hard); color: var(--hard); background: var(--hard-soft); }
.spacer { flex: 1; min-width: 0; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }
.marks { display: flex; gap: 6px; flex: none; }
.mark { font-size: 13px; font-weight: 600; padding: 6px 11px; min-width: 3.4em; border: 1px solid var(--line); background: transparent; border-radius: 6px; color: var(--muted); }
.mark.mw[aria-pressed="true"] { background: var(--wrong-soft); border-color: var(--wrong); color: var(--wrong); }
.mark.mh[aria-pressed="true"] { background: var(--hard-soft); border-color: var(--hard); color: var(--hard); }
.q { display: flex; flex-direction: column; gap: 10px; min-width: 0; max-width: 65ch; font-size: 15.5px; line-height: 1.65; }
.q p { margin: 0; overflow-wrap: anywhere; }
.fig { overflow-x: auto; }
.fig svg { display: block; width: 100%; max-width: 420px; height: auto; }
.fig img { display: block; max-width: min(100%, 420px); height: auto; }
.q p.miss { color: var(--hard); font-size: 13.5px; }
.fig text { fill: var(--fg); }
.fig .ink { stroke: var(--fg); fill: none; }
.fig .dot { fill: var(--fg); }
.fig .cut { stroke: var(--wrong); fill: none; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 16px; min-width: 0; }
.choice { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 6px 12px; max-width: 100%; overflow-x: auto; overflow-y: hidden; text-align: left; display: flex; gap: 8px; align-items: baseline; }
.choice .L { font-weight: 700; color: var(--muted); font-size: 13px; }
.choice[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.choice:disabled { cursor: default; color: var(--fg); opacity: 1; }
.choice.ok { background: var(--good-soft); border-color: var(--good); }
.choice.bad { background: var(--wrong-soft); border-color: var(--wrong); }
.katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; margin: 0.6em 0; }
.acts { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13.5px; }
.solbtn { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 5px 11px; font-weight: 600; color: var(--accent); }
.solbtn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.sol { border-left: 3px solid var(--accent); padding-left: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 65ch; font-size: 14.5px; line-height: 1.7; }
.sol p { margin: 0; overflow-wrap: anywhere; }
.sol .ans { font-weight: 600; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* grade / result */
.grade { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.grade .txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.score { font-family: var(--display); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; }
.score.big { font-size: 40px; line-height: 1; }
.detail { font-size: 13.5px; color: var(--muted); }
table.res { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.res th, table.res td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.res th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
table.res tr.bad td:first-child { color: var(--wrong); font-weight: 600; }
table.res tr.blank td:first-child { color: var(--hard); }
.ok-mark { color: var(--good); font-weight: 700; }
.bad-mark { color: var(--wrong); font-weight: 700; }

/* timer */
.timer { font-family: var(--display); font-weight: 700; font-size: 26px; font-variant-numeric: tabular-nums; }
.timer.warn { color: var(--wrong); }
.navchips { display: flex; flex-wrap: wrap; gap: 4px; }
.navchips a { width: 2em; height: 2em; display: grid; place-items: center; font-size: 12px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.navchips a.done { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* review */
.rev-form { display: flex; flex-direction: column; gap: 8px; }
.rev-form select, .rev-form textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; }
.rev-form textarea { min-height: 64px; resize: vertical; }
.rev-form label { font-size: 13px; color: var(--muted); }

/* stats bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.barrow { display: grid; grid-template-columns: 7em 1fr 4em; gap: 10px; align-items: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.barrow .track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.barrow .fill { height: 100%; background: var(--accent); }
.barrow .fill.low { background: var(--wrong); }
.barrow .fill.mid { background: var(--hard); }
.barrow .fill.high { background: var(--good); }
.trend { width: 100%; height: auto; }
.trend .axis { stroke: var(--line); }
.trend .ln { stroke: var(--accent); fill: none; stroke-width: 2; }
.trend .pt { fill: var(--accent); }
.trend text { fill: var(--muted); font-size: 11px; }

footer { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
footer p { margin: 0; }
[hidden] { display: none !important; }

@media print {
  .topnav, .bar, footer, .marks, .acts, .rev-form select, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .wrap { max-width: none; padding: 0; }
  ol.list, .card { border: 0; }
  .item { break-inside: avoid; border-bottom: 1px solid #ccc; }
  .sol { display: flex !important; }
}
