:root {
  --bg: #f7f6f2; --surface: #fff; --text: #1d1c1a; --muted: #67645c; --line: #e2dfd7;
  --accent: #2b59c3; --accent-ink: #fff; --ok: #1d7a4c; --bad: #b42318; --warn: #8a5a00;
  --paper: #fff; --radius: 10px; --top: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312; --surface: #1c1c1a; --text: #ecebe6; --muted: #a3a097; --line: #2e2d2a;
    --accent: #8fb0ff; --accent-ink: #0b1430; --ok: #5fd197; --bad: #ff8b7f; --warn: #e6b450;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 8px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.nav-open { overflow: hidden; }
a { color: var(--accent); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { position: sticky; top: 0; z-index: 10; height: var(--top); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: inherit; text-decoration: none; }
#stats { margin-left: auto; font-size: 14px; font-variant-numeric: tabular-nums; }
#menu { display: none; font-size: 20px; background: none; border: 0; border-radius: 8px; color: inherit; padding: 4px 10px; cursor: pointer; }
#menu:hover { background: var(--line); }

.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); }
#nav { position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow: auto; padding: 12px 8px 40px; border-right: 1px solid var(--line); }
#nav a { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 14px; }
#nav a:hover { background: var(--line); }
#nav a:focus-visible { outline-offset: -2px; }
#nav a.on, #nav a.on:hover { background: var(--accent); color: var(--accent-ink); }
#nav small { opacity: .75; font-variant-numeric: tabular-nums; white-space: nowrap; }
#nav a.on small { opacity: .9; }
.nav-home, .nav-subj { font-weight: 600; }
.nav-topics { margin: 2px 0 6px; }
.nav-topics a { padding-left: 22px !important; font-size: 13px !important; }

main { padding: 24px clamp(16px, 4vw, 40px) 96px; max-width: 980px; width: 100%; }
main:focus-visible { outline: none; } /* only ever focused by script after navigation; the global ring would box the whole column */
h1 { font-size: 26px; line-height: 1.25; letter-spacing: -.01em; margin: 4px 0 8px; text-wrap: balance; }
.crumb { margin: 0; font-size: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 20px; }
.card { display: block; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card h2 { font-size: 17px; line-height: 1.3; margin: 0 0 4px; text-wrap: balance; }
.card p { margin: 0; font-size: 14px; }
.card small { font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 12px 0 6px; }
.bar i { display: block; height: 100%; background: var(--ok); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; }
.filters button, .ans button, .opt span { font-size: 14px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.filters button:hover, .ans button:hover, .opt:hover span { border-color: var(--accent); }
.filters button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.topic h2 { font-size: 20px; line-height: 1.3; margin: 36px 0 12px; }
.topic h2 a { color: inherit; text-decoration: none; }
.topic h2 a:hover { text-decoration: underline; }
.topic h2 small { color: var(--muted); font-weight: 400; font-size: 14px; font-variant-numeric: tabular-nums; }
.topic > p.muted:first-child { margin: 8px 0 12px; }
.empty { padding: 8px 0; }

.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 16px; overflow: hidden; }
.q[data-r="c"] { border-color: var(--ok); }
.q[data-r="w"] { border-color: var(--bad); }
.q header { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.q .src { font-weight: 600; margin-right: auto; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.bm { background: none; border: 0; border-radius: 8px; font-size: 22px; line-height: 1; cursor: pointer; color: var(--warn); padding: 4px 6px; }
.bm:hover { background: var(--line); }
.errata { margin: 0; padding: 8px 14px; font-size: 14px; background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-bottom: 1px solid var(--line); }
.paper { background: var(--paper); padding: 8px; overflow-x: auto; }
.paper img { display: block; max-width: 100%; height: auto; margin: 0 auto; }

.ans { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.ans fieldset { border: 0; margin: 0; padding: 0; display: flex; gap: 8px; min-width: 0; }
.ans button, .opt span { min-height: 40px; }
.opt { position: relative; }
.opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.opt span { display: inline-flex; align-items: center; justify-content: center; min-width: 48px; font-weight: 600; }
.opt input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.ans input[name="nat"] { font: inherit; min-height: 40px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 170px; }
.ans .primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); padding-inline: 20px; }
.ans .primary:hover { filter: brightness(1.1); }
.ans .reveal { margin-left: auto; }

.result { padding: 12px 14px 14px; border-top: 1px solid var(--line); }
.verdict { margin: 0 0 2px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.prov { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.prov.claude { color: var(--warn); }
details.ex summary { cursor: pointer; font-weight: 600; }
.md { padding-top: 2px; overflow-wrap: anywhere; }
.md p, .md ul, .md ol { margin: .7em 0; }
.md li + li { margin-top: .2em; }
.md li > ul, .md li > ol, .md li > p { margin: .3em 0; }
.md .tbl { margin: .7em 0; overflow-x: auto; position: relative; } /* relative: KaTeX's absolutely positioned MathML boxes must not escape the scroller */
.md table { border-collapse: collapse; font-size: .95em; overflow-wrap: normal; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg); }
.md pre { margin: .7em 0; background: var(--bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #menu { display: inline-flex; }
  #nav { display: none; position: fixed; inset: var(--top) 0 0 0; z-index: 9; height: auto; padding-bottom: 80px; background: var(--surface); border-right: 0; }
  .nav-open #nav { display: block; }
  #nav a { padding: 10px 12px; }
  .ans .reveal { margin-left: 0; }
}

@media (max-width: 600px) {
  main { padding-top: 16px; }
  h1 { font-size: 23px; }
  .filters button { font-size: 13px; padding: 6px 11px; }
  .paper { padding: 6px; } /* images stay fit-to-width so every option is visible; pinch-zoom for detail */
  .ans fieldset, .ans input[name="nat"] { flex: 1 1 100%; width: auto; }
  .opt { flex: 1; }
  .opt span { display: flex; }
  .ans button { flex: 1; }
  .md th, .md td { padding: 4px 6px; }
  /* label and star share the first row (label wraps if it must); the badges sit on a second row */
  .q header { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 4px 8px; }
  .q .src { grid-column: 1 / 4; margin-right: 0; }
  .q .bm { grid-column: 4; grid-row: 1; justify-self: end; }
  .q .badge { justify-self: start; }
}
