:root {
  --bg: #f6f4ef;
  --surface: #fffdf9;
  --ink: #1d1c1a;
  --muted: #6c6a64;
  --line: #e3dfd5;
  --line-strong: #cfc9bb;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe9;
  --good: #1f6b3a;
  --good-soft: #e3f1e7;
  --warn: #8a5a00;
  --warn-soft: #f8ecd2;
  --bad: #a3321f;
  --bad-soft: #f8e4df;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151512; --surface: #1d1d19; --ink: #ecebe5; --muted: #9a988f;
    --line: #2e2d27; --line-strong: #44423a;
    --accent: #6fc4a2; --accent-ink: #0f1f19; --accent-soft: #1e2f28;
    --good: #7fd49a; --good-soft: #1b2e22; --warn: #e6b955; --warn-soft: #33290f;
    --bad: #ef8f7e; --bad-soft: #36201b;
  }
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.55; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 600; text-decoration: none; color: var(--ink); }
.top nav { display: flex; gap: 20px; }
.top nav a { text-decoration: none; color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; }
.top nav a.on { color: var(--ink); border-color: var(--accent); }

.page { max-width: 860px; margin: 0 auto; padding: 32px 24px 80px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--mono); }

/* buttons */
.btn { border: 1px solid var(--line-strong); background: var(--surface); padding: 7px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; color: var(--ink); font-size: .9375rem; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 4px 10px; font-size: .8125rem; }
.btn.good { border-color: var(--good); color: var(--good); }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.bad { border-color: var(--bad); color: var(--bad); }
.btn.on.good { background: var(--good-soft); } .btn.on.warn { background: var(--warn-soft); } .btn.on.bad { background: var(--bad-soft); }

/* home */
.lead { margin: 8px 0 28px; color: var(--muted); max-width: 60ch; }
.exam-list { border-top: 1px solid var(--line); }
.exam-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--line); align-items: center; }
.exam-row h2 { margin-bottom: 4px; }
.exam-row .meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: .875rem; color: var(--muted); margin-top: 8px; }
.exam-row .meta b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.import { margin-top: 40px; padding: 18px; border: 1px dashed var(--line-strong); border-radius: 8px; }
.import.drag { background: var(--accent-soft); border-color: var(--accent); }
.import p { margin: 4px 0 12px; }

/* runner layout */
.runner { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 53px); }
.side { border-right: 1px solid var(--line); padding: 20px 16px; background: var(--surface); position: sticky; top: 53px; align-self: start; height: calc(100vh - 53px); overflow-y: auto; }
.side h1 { font-size: 1.0625rem; }
.score-box { margin: 14px 0 16px; padding: 12px 0; border-block: 1px solid var(--line); }
.score-box .big { font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.side select { width: 100%; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); margin-bottom: 10px; }
.qlist { list-style: none; margin: 0; padding: 0; }
.qlist button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 5px; cursor: pointer; display: grid; grid-template-columns: 26px 1fr auto; gap: 6px; align-items: baseline; font-size: .875rem; }
.qlist button:hover { background: var(--bg); }
.qlist button.cur { background: var(--accent-soft); }
.qlist .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.qlist .s { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.qlist .s.full { color: var(--good); } .qlist .s.some { color: var(--warn); } .qlist .s.zero { color: var(--bad); }
.side-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }

.main { padding: 28px 32px 80px; max-width: 840px; width: 100%; }
.qhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.qhead .tag { font-size: .8125rem; color: var(--muted); }
.qtitle { font-size: 1.3rem; margin-bottom: 14px; }
.stem { margin-bottom: 18px; }
.stem p, .prose p { margin: 0 0 .7em; }
.figure { margin: 6px 0 18px; }
.figure img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.part { padding: 16px 0; border-top: 1px solid var(--line); }
.part-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; }
.plabel { font-weight: 600; min-width: 2ch; }
.pmarks { margin-left: auto; font-size: .8125rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ptext { flex: 1; }

.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; cursor: pointer; background: var(--surface); }
.opt:hover { border-color: var(--line-strong); }
.opt input { margin-top: 5px; accent-color: var(--accent); }
.opt.ok { border-color: var(--good); background: var(--good-soft); }
.opt.no { border-color: var(--bad); background: var(--bad-soft); }
.opt.miss { border-style: dashed; border-color: var(--good); }
.locked .opt { cursor: default; }

textarea.ans, input.ans, select.ans { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
textarea.ans { min-height: 110px; resize: vertical; }
input.ans.short { max-width: 240px; }
.match-row { display: grid; grid-template-columns: 1fr 200px; gap: 12px; align-items: center; margin: 8px 0; }
.match-row.ok select { border-color: var(--good); } .match-row.no select { border-color: var(--bad); }

.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.result { margin-top: 12px; padding: 12px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); }
.result.good { border-color: var(--good); background: var(--good-soft); }
.result.bad { border-color: var(--bad); background: var(--bad-soft); }
.result.warn { border-color: var(--warn); background: var(--warn-soft); }
.result .verdict { font-weight: 600; margin-bottom: 6px; }
.model-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 4px; }
.result .model-label:first-child { margin-top: 0; }
.guide { font-size: .875rem; color: var(--muted); margin-top: 8px; }

.nav-row { display: flex; justify-content: space-between; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

/* md */
.prose ul, .prose ol { margin: 0 0 .7em; padding-left: 1.3em; }
.prose table { border-collapse: collapse; margin: 8px 0 12px; font-size: .9375rem; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line-strong); padding: 5px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--bg); font-weight: 600; }
.prose code { font-family: var(--mono); font-size: .875em; background: var(--bg); padding: 1px 4px; border-radius: 3px; }
.prose pre { background: var(--bg); border: 1px solid var(--line); padding: 12px; border-radius: 6px; overflow-x: auto; font-family: var(--mono); font-size: .8125rem; line-height: 1.5; white-space: pre-wrap; }

/* results */
.summary-table { width: 100%; border-collapse: collapse; margin-top: 16px; font-variant-numeric: tabular-nums; }
.summary-table th, .summary-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.summary-table th { font-size: .8125rem; color: var(--muted); font-weight: 500; }
.summary-table td.r, .summary-table th.r { text-align: right; }
.summary-table a { text-decoration: none; }

/* prompts */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 20px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checks { display: flex; gap: 6px 16px; flex-wrap: wrap; }
.field .checks input { width: auto; padding: 0; }
.checks label { display: flex; white-space: nowrap; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
.promptbox { position: relative; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); margin: 10px 0 18px; }
.promptbox pre { margin: 0; padding: 14px 16px; white-space: pre-wrap; font-family: var(--mono); font-size: .8125rem; line-height: 1.55; max-height: 420px; overflow: auto; }
.promptbox .bar-top { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: .8125rem; color: var(--muted); gap: 8px; }
.notice { padding: 10px 14px; border-radius: 6px; background: var(--warn-soft); border: 1px solid var(--warn); color: var(--ink); margin: 16px 0; }

dialog { border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); max-width: 760px; width: calc(100% - 32px); padding: 20px 24px; max-height: 85vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }

@media (max-width: 820px) {
  .runner { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .qlist { max-height: 180px; overflow-y: auto; }
  .main { padding: 20px 16px 60px; }
  .exam-row { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
  .field-grid, .match-row { grid-template-columns: 1fr; }
  .top { padding: 10px 16px; }
}

/* formula sheet pop-up: one formula per line, roomy and monospace */
#fdlg .prose { font-size: 1rem; line-height: 1.55; }
#fdlg .prose p { margin: 1.1em 0 .3em; padding-top: .6em; border-top: 1px solid var(--line); }
#fdlg .prose p:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
#fdlg .prose ul { list-style: none; padding-left: 0; margin: 0; }
#fdlg .prose li { padding: 3px 0; }
#fdlg .prose code { font-size: .95em; padding: 2px 6px; white-space: pre-wrap; }
#fdlg .katex { font-size: 1.1em; }
#fdlg .katex { font-size: 1.1em; }
