:root {
  --bg:#fafaf9; --card:#fff; --text:#1c1917; --muted:#6b6560; --line:#e7e5e4; --soft:#f5f5f4;
  --accent:#1d4ed8; --accent-soft:#dbeafe; --ok:#15803d; --okbg:#f0fdf4; --bad:#b91c1c; --badbg:#fef2f2; --warn:#b45309;
  --grid:#e7e5e4; --shadow:0 8px 30px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0c0a09; --card:#1c1917; --text:#f5f5f4; --muted:#a8a29e; --line:#2e2a27; --soft:#262220;
    --accent:#60a5fa; --accent-soft:#1e3a5f; --ok:#4ade80; --okbg:#052e16; --bad:#f87171; --badbg:#3f0d0d; --warn:#fbbf24;
    --grid:#2e2a27; --shadow:0 8px 30px rgba(0,0,0,.5);
  }
  .q-body svg, .stimulus svg, .rationale svg, .q-body img:not(.math-img), .stimulus img:not(.math-img), .rationale img:not(.math-img) { background:#fff; border-radius:6px; color:#000; }
  img.math-img { filter:invert(.93); }
  .btn { color:#0c0a09 !important; }
  canvas.pdfpage { filter:none; }
}
* { box-sizing:border-box; }
[hidden] { display:none !important; }
html { -webkit-text-size-adjust:100%; }
body { margin:0; background:var(--bg); color:var(--text); font:16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color:var(--accent); }
.wrap { max-width:900px; margin:0 auto; padding:0 16px; }
main.wrap { padding-top:16px; padding-bottom:64px; }
select, button, input, textarea { font:inherit; color:inherit; }
select, input[type=number], input[type=date], input[type=search] { background:var(--card); border:1px solid var(--line); border-radius:6px; padding:4px 8px; max-width:100%; }
h3 { font-size:15px; margin:22px 0 8px; }
.muted { color:var(--muted); } .small { font-size:13px; } .ok { color:var(--ok); } .bad { color:var(--bad); }
pre { background:var(--soft); border:1px solid var(--line); border-radius:6px; padding:8px 10px; overflow-x:auto; font-size:13px; }
code { font-size:.92em; }

/* header */
header.top { position:sticky; top:0; z-index:20; background:var(--bg); border-bottom:1px solid var(--line); }
.top-inner { display:flex; align-items:center; gap:14px; flex-wrap:wrap; padding-top:10px; padding-bottom:10px; }
h1 { font-size:17px; margin:0; font-weight:650; }
nav { display:flex; gap:2px; flex-wrap:wrap; }
nav button { background:none; border:0; padding:5px 10px; border-radius:6px; cursor:pointer; color:var(--muted); font-weight:500; }
nav button.on { background:var(--card); color:var(--text); box-shadow:0 0 0 1px var(--line); }
#sync { margin-left:auto; font-size:13px; color:var(--warn); }
#sync.linked { color:var(--ok); }
#dl { position:relative; border-top:1px solid var(--line); font-size:13px; color:var(--muted); }
#dl .dl-fill { position:absolute; left:0; top:0; bottom:0; width:0; background:var(--accent-soft); transition:width .3s; }
#dl .dl-text { position:relative; padding-top:4px; padding-bottom:4px; }
body.testing nav, body.testing #dl { display:none; }

/* generic */
.bar-top { display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:12px; color:var(--muted); font-size:14px; font-variant-numeric:tabular-nums; }
.bar-top b { color:var(--text); }
.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:24px; }
.panel { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:14px 18px; margin-bottom:14px; }
.panel h3 { margin-top:4px; }
.panel.danger { border-color:color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn { background:var(--accent); color:#fff; border:0; border-radius:8px; padding:8px 16px; cursor:pointer; font-weight:500; }
.btn:disabled { opacity:.4; cursor:default; }
.btn-lite { background:var(--card); border:1px solid var(--line); border-radius:8px; padding:6px 12px; cursor:pointer; }
.btn-lite:hover { border-color:var(--muted); }
.btn.small, .btn-lite.small { padding:3px 10px; font-size:13px; }
.filebtn { display:inline-block; }
.hint { margin-top:10px; font-size:12px; color:var(--muted); text-align:right; }
.chip { background:var(--card); border:1px solid var(--line); border-radius:999px; padding:3px 12px; cursor:pointer; font-size:13px; }
.chip:hover { border-color:var(--muted); } .chip.accent { border-color:var(--accent); color:var(--accent); }
.toast { position:fixed; left:50%; bottom:24px; transform:translateX(-50%); background:var(--text); color:var(--bg); padding:10px 16px; border-radius:8px; z-index:100; box-shadow:var(--shadow); max-width:90vw; font-size:14px; }
.empty { color:var(--muted); font-size:14px; padding:12px 14px; }
table.data { border-collapse:collapse; width:100%; font-size:14px; font-variant-numeric:tabular-nums; }
table.data th, table.data td { text-align:left; padding:6px 10px; border-bottom:1px solid var(--line); }
table.data tr[data-open] { cursor:pointer; } table.data tr[data-open]:hover { background:var(--soft); }
.table-wrap { overflow-x:auto; background:var(--card); border:1px solid var(--line); border-radius:10px; }

/* question */
.meta { font-size:13px; color:var(--muted); margin-bottom:10px; display:flex; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.meta-r { display:flex; gap:8px; align-items:center; }
.band, .bandtag { font-size:11px; font-weight:600; padding:1px 7px; border-radius:10px; border:1px solid var(--line); white-space:nowrap; }
.band.b7, .bandtag.b7, .band.b6, .bandtag.b6 { color:var(--bad); border-color:var(--bad); }
.band.b4, .bandtag.b4, .band.b5, .bandtag.b5 { color:var(--warn); border-color:var(--warn); }
.q-tools { display:flex; gap:10px; align-items:center; margin-bottom:12px; font-size:13px; color:var(--muted); flex-wrap:wrap; }
.tool { background:none; border:1px solid var(--line); border-radius:6px; padding:2px 8px; cursor:pointer; display:inline-flex; gap:6px; align-items:center; color:var(--muted); font-size:13px; }
.tool.on, .flag.on, .mark.on { color:var(--bad); border-color:var(--bad); }
.elapsed { margin-left:auto; font-variant-numeric:tabular-nums; }
.stimulus { border-left:3px solid var(--line); padding-left:14px; margin-bottom:12px; }
.stimulus p:first-child, .stem p:first-child, .rationale p:first-child { margin-top:0; }
.stem { font-weight:500; }
figure { margin:12px 0; overflow-x:auto; }
.q-body svg, .stimulus svg, .rationale svg { max-width:100%; height:auto; }
.q-body img, .stimulus img, .rationale img { max-width:100%; }
img.math-img { vertical-align:middle; }
.q-body table, .stimulus table, .rationale table { border-collapse:collapse; margin:8px 0; font-size:14px; }
.q-body td, .q-body th, .stimulus td, .stimulus th, .rationale td, .rationale th { border:1px solid var(--line); padding:4px 10px; text-align:center; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }
.italic { font-style:italic; }
math { font-size:1.08em; }
.choices { display:flex; flex-direction:column; gap:8px; margin-top:16px; }
.choice-row { display:flex; gap:8px; align-items:stretch; }
.choice { flex:1; display:flex; gap:12px; text-align:left; background:transparent; border:1px solid var(--line); border-radius:8px; padding:10px 14px; cursor:pointer; }
.choice:hover:not(:disabled) { border-color:var(--muted); }
.choice p { margin:0; } .choice .l { font-weight:600; min-width:1.2em; }
.choice.sel { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.choice.right { border-color:var(--ok); background:var(--okbg); }
.choice.wrong { border-color:var(--bad); background:var(--badbg); }
.choice:disabled { cursor:default; }
.strike { display:none; width:34px; background:none; border:1px solid var(--line); border-radius:8px; cursor:pointer; color:var(--muted); font-weight:600; text-decoration:line-through; }
.elim-on .strike { display:block; }
.choice-row.struck .choice { opacity:.45; } .choice-row.struck .choice .c { text-decoration:line-through; }
.choice-row.struck .strike { color:var(--text); text-decoration:none; }
.spr { margin-top:16px; display:flex; flex-direction:column; gap:4px; }
.spr input { width:200px; padding:8px 10px; border:1px solid var(--line); border-radius:8px; background:transparent; }
.spr-hint { font-size:12px; color:var(--muted); }
.actions { margin-top:18px; display:flex; gap:12px; align-items:center; flex-wrap:wrap; }
.verdict { font-weight:600; } .verdict.ok { color:var(--ok); } .verdict.bad { color:var(--bad); }
.prior { margin-top:14px; font-size:14px; color:var(--muted); }
.notes { display:block; width:100%; margin-top:14px; min-height:64px; padding:10px 12px; resize:vertical; font-size:15px; background:transparent; border:1px solid var(--line); border-radius:8px; }
.notes:focus { outline:none; border-color:var(--accent); }
.rationale { margin-top:18px; padding-top:14px; border-top:1px solid var(--line); font-size:15px; }

/* welcome */
.welcome ul { padding-left:20px; margin:8px 0 12px; font-size:15px; }
.welcome li { margin:4px 0; }

/* practice settings */
.presets { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.grid2 .span2 { grid-column:1 / -1; }
fieldset { border:1px solid var(--line); border-radius:8px; padding:8px 12px; margin:0; min-width:0; }
legend { font-size:13px; font-weight:600; padding:0 4px; }
label.row, summary.row { display:flex; justify-content:space-between; align-items:center; gap:10px; font-size:14px; padding:3px 0; }
.bands { display:grid; grid-template-columns:1fr 1fr; column-gap:14px; }
.dom-row { display:grid; grid-template-columns:1fr auto; align-items:start; gap:8px; padding:3px 0; font-size:14px; }
.dom-row summary { cursor:pointer; }
.skills { display:flex; flex-direction:column; padding:4px 0 6px 18px; font-size:13px; }

/* stats */
.tiles { display:grid; grid-template-columns:repeat(auto-fill, minmax(130px, 1fr)); gap:8px; margin-bottom:10px; }
.tile { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:10px 14px; }
.tile .k { font-size:12px; color:var(--muted); }
.tile .v { font-size:20px; font-weight:600; font-variant-numeric:tabular-nums; }
.tile.hero .v { font-size:28px; }
.charts { display:grid; grid-template-columns:repeat(auto-fit, minmax(300px, 1fr)); gap:12px; margin:12px 0; }
figure.chart { margin:0; background:var(--card); border:1px solid var(--line); border-radius:10px; padding:10px 12px; }
figure.chart figcaption { font-size:14px; font-weight:600; margin-bottom:4px; }
figure.chart svg { width:100%; height:auto; display:block; }
figure.chart details { font-size:13px; }
svg .grid { stroke:var(--grid); stroke-width:1; }
svg .axis { fill:var(--muted); font-size:11px; }
svg .mark { fill:var(--accent); }
svg .line-mark { fill:none; stroke:var(--accent); stroke-width:2; stroke-linejoin:round; }
svg .cross { stroke:var(--muted); stroke-dasharray:3 3; }
svg .dot { fill:var(--accent); stroke:var(--card); stroke-width:2; }
svg .hit { cursor:default; }
.chart-tip { position:fixed; z-index:60; pointer-events:none; background:var(--text); color:var(--bg); font-size:12px; padding:4px 8px; border-radius:6px; }
.empty-chart { padding:40px 0; text-align:center; }
.srow { display:grid; grid-template-columns:1fr 90px 44px 58px 70px; gap:10px; align-items:center; padding:5px 12px; font-size:14px; font-variant-numeric:tabular-nums; }
.srow .num { text-align:right; }
.srow.head { font-size:12px; color:var(--muted); }
.srow.total { font-weight:600; }
.srow.skill { padding-left:30px; cursor:pointer; color:var(--muted); }
.srow.skill:hover { background:var(--soft); color:var(--text); }
.bar { height:6px; background:var(--line); border-radius:3px; overflow:hidden; }
.bar i { display:block; height:100%; background:var(--accent); border-radius:3px; }
.group { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:6px 0; }
.group details > summary { list-style:none; cursor:pointer; }
.group details > summary::-webkit-details-marker { display:none; }
.group details > summary .name::before { content:'▸ '; color:var(--muted); }
.group details[open] > summary .name::before { content:'▾ '; }
.group details > summary:hover { background:var(--soft); }
.focus li { font-size:14px; }

/* browse / lists */
.filters { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:10px; }
.filters select, .filters input { flex:1 1 150px; min-width:0; }
ol.list { list-style:none; margin:0 0 8px; padding:0; border:1px solid var(--line); border-radius:10px; background:var(--card); }
ol.list li { display:flex; gap:10px; padding:8px 14px; border-bottom:1px solid var(--line); font-size:14px; cursor:pointer; align-items:center; }
ol.list li:last-child { border-bottom:0; }
ol.list li:hover { background:var(--soft); }
ol.list .m { min-width:2.2em; font-weight:700; }
ol.list .n { color:var(--muted); min-width:2em; font-variant-numeric:tabular-nums; }
ol.list .t { flex:1; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
ol.list .sk { color:var(--muted); margin-right:6px; }

/* modal & floating panels */
.modal { position:fixed; inset:0; z-index:50; background:rgba(0,0,0,.45); display:flex; justify-content:center; align-items:flex-start; overflow-y:auto; padding:32px 12px; }
.modal-inner { position:relative; width:100%; max-width:820px; }
.modal-x { position:absolute; right:-6px; top:-14px; z-index:2; width:32px; height:32px; border-radius:50%; border:1px solid var(--line); background:var(--card); cursor:pointer; }
.float-panel { position:fixed; right:16px; bottom:16px; z-index:70; background:var(--card); border:1px solid var(--line); border-radius:10px; box-shadow:var(--shadow); display:flex; flex-direction:column; overflow:hidden; }
.fp-head { display:flex; justify-content:space-between; align-items:center; padding:6px 10px; font-size:13px; font-weight:600; border-bottom:1px solid var(--line); cursor:move; touch-action:none; user-select:none; }
.fp-head button { background:none; border:0; cursor:pointer; font-size:14px; padding:2px 6px; }
.calc { width:min(420px, 94vw); height:min(480px, 70vh); }
.calc.big { width:min(820px, 96vw); height:min(640px, 84vh); }
.calc iframe { flex:1; border:0; width:100%; background:#fff; }
.refsheet { width:min(420px, 94vw); max-height:80vh; }
.ref-body { padding:10px 14px; overflow-y:auto; font-size:14px; }
.ref-body th { text-align:left; padding:3px 10px 3px 0; font-weight:600; vertical-align:top; } .ref-body td { padding:3px 0; }

/* test runner */
body.testing main.wrap { max-width:1200px; }
.runner { display:flex; flex-direction:column; min-height:calc(100vh - 110px); }
.runner.center { align-items:center; justify-content:center; text-align:center; }
.run-top { display:flex; align-items:center; gap:12px; flex-wrap:wrap; padding:8px 0 10px; border-bottom:1px solid var(--line); }
.run-title { font-weight:600; flex:1; min-width:180px; }
.run-tools { display:flex; gap:6px; flex-wrap:wrap; }
.timer { display:flex; align-items:center; gap:8px; font-weight:600; font-variant-numeric:tabular-nums; font-size:18px; }
.timer.warn .t { color:var(--bad); }
.timer.big { font-size:40px; justify-content:center; margin:12px 0; }
.run-main { flex:1; padding:16px 0 24px; }
.run-bottom { position:sticky; bottom:0; background:var(--bg); display:flex; gap:8px; align-items:center; padding:10px 0; border-top:1px solid var(--line); }
.grow { flex:1; }
.rq.split { display:grid; grid-template-columns:1fr 1fr; gap:28px; }
.rq-left { border-right:1px solid var(--line); padding-right:24px; }
.rq-left .stimulus { border:0; padding:0; }
.rq-head { display:flex; gap:10px; align-items:center; background:var(--soft); border-radius:6px; padding:4px 8px; margin-bottom:12px; }
.qnum { background:var(--text); color:var(--bg); font-weight:700; border-radius:4px; padding:0 8px; }
.navpop { position:fixed; left:50%; bottom:64px; transform:translateX(-50%); z-index:40; background:var(--card); border:1px solid var(--line); border-radius:10px; box-shadow:var(--shadow); padding:14px; width:min(460px, 94vw); }
.qgrid { display:flex; flex-wrap:wrap; gap:6px; margin:8px 0; }
.qgrid button { width:38px; height:38px; border:1px dashed var(--muted); border-radius:6px; background:var(--card); cursor:pointer; font-weight:600; position:relative; }
.qgrid button.answered { border:1px solid var(--accent); background:var(--accent-soft); }
.qgrid button.marked::after { content:'⚑'; position:absolute; top:-9px; right:-5px; color:var(--bad); font-size:12px; }
.qgrid button.current { outline:2px solid var(--text); }
.legend { font-size:12px; color:var(--muted); display:flex; gap:6px; align-items:center; flex-wrap:wrap; }
.lg { display:inline-block; width:12px; height:12px; border:1px dashed var(--muted); border-radius:3px; }
.lg.answered { border:1px solid var(--accent); background:var(--accent-soft); }
.lg.marked { border:1px solid var(--bad); }
.review-page { max-width:560px; margin:0 auto; text-align:center; } .review-page .qgrid { justify-content:center; }
.results .tiles { margin-top:8px; }
.keygrid { display:grid; grid-template-columns:repeat(auto-fill, minmax(190px, 1fr)); gap:4px 12px; font-size:13px; font-variant-numeric:tabular-nums; }
.keygrid .ok, .keygrid .bad { color:var(--text); } .keygrid .bad b { color:var(--bad); } .keygrid .ok b { color:var(--ok); }

/* official test: pages + answer sheet */
.off-split { display:grid; grid-template-columns:1fr 250px; gap:14px; flex:1; min-height:0; padding-top:12px; }
.pages { overflow-y:auto; max-height:calc(100vh - 150px); background:var(--soft); border-radius:8px; padding:8px; }
canvas.pdfpage { display:block; margin:0 auto 10px; background:#fff; box-shadow:0 1px 4px rgba(0,0,0,.2); max-width:100%; }
.sheet { overflow-y:auto; max-height:calc(100vh - 150px); background:var(--card); border:1px solid var(--line); border-radius:8px; padding:8px 10px; }
.sheet-head { font-weight:600; font-size:14px; display:flex; justify-content:space-between; margin-bottom:6px; }
.sheet-row { display:flex; align-items:center; gap:6px; padding:3px 0; border-bottom:1px solid var(--line); }
.sheet-row .n { width:24px; text-align:right; font-weight:600; font-size:13px; font-variant-numeric:tabular-nums; }
.bubbles { display:flex; gap:4px; flex:1; }
.bubbles button { width:28px; height:28px; border-radius:50%; border:1px solid var(--muted); background:var(--card); cursor:pointer; font-size:12px; font-weight:600; }
.bubbles button.on { background:var(--accent); border-color:var(--accent); color:var(--card); }
.gridin { flex:1; min-width:0; width:100%; padding:3px 6px; border:1px solid var(--line); border-radius:6px; background:transparent; }
.flagq { background:none; border:0; cursor:pointer; color:var(--muted); opacity:.5; } .flagq.on { color:var(--bad); opacity:1; }
.sheet .submit { width:100%; margin-top:10px; }
.plan-scores { display:grid; grid-template-columns:repeat(auto-fit, minmax(150px, 1fr)); gap:10px; margin-bottom:12px; }
.plan-scores label { display:flex; flex-direction:column; font-size:13px; gap:4px; }
.suggestion ul { padding-left:20px; }

@media (max-width:720px) {
  .card { padding:16px; }
  .grid2 { grid-template-columns:1fr; }
  .rq.split { grid-template-columns:1fr; gap:12px; }
  .rq-left { border-right:0; padding-right:0; border-bottom:1px solid var(--line); padding-bottom:12px; }
  .srow { grid-template-columns:1fr 50px 40px 52px; } .srow .seen { display:none; }
  .off-split { grid-template-columns:1fr; }
  .off-split .sheet { position:fixed; left:0; right:0; bottom:0; max-height:45vh; z-index:30; border-radius:12px 12px 0 0; transform:translateY(calc(100% - 40px)); transition:transform .2s; }
  .off-split.sheet-open .sheet { transform:none; }
  .pages { max-height:none; padding-bottom:50px; }
  nav button { padding:5px 7px; }
}
