:root {
  color-scheme: light;
  --bg: #f4f6f8; --card: #fff; --surface: #fff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb; --line2: #cbd5e1; --line3: #94a3b8;
  --soft: #f8fafc; --soft2: #eef2f7; --hover: #f1f5f9; --tile: #fbfdfd; --tile-hover: #f0fdfa; --sel: #ecfdf5; --pal-bg: #fafafa;
  --ok-bg: #f0fdf4; --bad-bg: #fef2f2; --bad-line: #fecaca; --bad-ink: #991b1b; --notans-bg: #fee2e2; --notans-line: #f87171;
  --warn-bg: #fffbeb; --warn-line: #fde68a; --warn-ink: #92400e; --link: #0f766e;
  --brand: #0f766e; --brand2: #134e4a;
  --ok: #15803d; --bad: #dc2626; --warn: #d97706; --purple: #7c3aed;
  --english: #2563eb; --gk: #d97706; --intelligence: #7c3aed; --maths: #059669;
  --fig-filter: none;
}
/* Dark theme: soft (not pure black/white) contrast to reduce glare for long sessions */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15181c; --card: #1c2026; --surface: #20252c; --ink: #d5dae0; --muted: #949eaa; --line: #2c333c; --line2: #3a434e; --line3: #56606c;
  --soft: #191d22; --soft2: #2a3139; --hover: #262c34; --tile: #1f242b; --tile-hover: #1d2e2c; --sel: #163b36; --pal-bg: #181c21;
  --ok-bg: #16301f; --bad-bg: #3a1d1f; --bad-line: #6b2b2e; --bad-ink: #f3b4b4; --notans-bg: #4a2224; --notans-line: #a84a4d;
  --warn-bg: #352a14; --warn-line: #6b5420; --warn-ink: #f0cf8a; --link: #5eead4;
  --brand: #0f766e; --brand2: #10302d;
  --ok: #4ade80; --bad: #f87171; --warn: #fbbf24; --purple: #8b5cf6;
  --english: #60a5fa; --gk: #fbbf24; --intelligence: #a78bfa; --maths: #34d399;
  --fig-filter: brightness(.82) contrast(.95);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; } h2 { font-size: 1.15rem; margin: 0 0 .75rem; } h3 { margin: 0 0 .75rem; }
.loading { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .ok { color: var(--ok); } .bad { color: var(--bad); }
.row { display: flex; align-items: center; } .between { justify-content: space-between; } .gap { gap: .6rem; } .wrap { flex-wrap: wrap; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .6rem 1.2rem; background: var(--brand2); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .02em; } .brand span { font-weight: 400; opacity: .8; }
.top nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.top nav a { color: #d1fae5; text-decoration: none; padding: .35rem .7rem; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255, 255, 255, .15); color: #fff; }
.page { max-width: 1100px; margin: 0 auto; padding: 1rem 1.2rem 3rem; }
.page a:not(.btn):not(.tile) { color: var(--link); }
.theme-btn { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); color: #fff; border-radius: 6px; padding: .3rem .65rem; font: inherit; font-size: .85rem; cursor: pointer; }
.theme-btn:hover { background: rgba(255, 255, 255, .22); color: #fff; }
.top nav a.sync-badge { font-size: .78rem; padding: .3rem .6rem; border: 1px solid rgba(255, 255, 255, .25); color: #d1fae5; }
.top nav a.sync-badge.ok::before { content: "● "; color: #4ade80; }
.top nav a.sync-badge.error::before, .top nav a.sync-badge.offline::before { content: "● "; color: #fbbf24; }
.top nav a.sync-badge.off { opacity: .6; }
.qimg, .opt-img { background: #fff; filter: var(--fig-filter); }
.gen-fig, .opt-svg svg { background: #fff; color: #111; border-radius: 4px; filter: var(--fig-filter); }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; margin: 0 0 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.cards .card { margin: 0; }
.stat .k { color: var(--muted); font-size: .85rem; } .stat .v { font-size: 2rem; font-weight: 800; line-height: 1.2; } .stat .v small { font-size: 1rem; color: var(--muted); font-weight: 400; }
.stat.big .v { font-size: 2.4rem; color: var(--link); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; } .grid2 .card { margin: 0 0 1rem; }
.hero { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.hero h1 { margin: 0; }
.plan ol { margin: 0; padding-left: 1.2rem; } .plan li { margin: .35rem 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line2); background: var(--surface); color: var(--ink); font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--hover); color: var(--ink); }
.btn:focus-visible, .opt:focus-visible, .pq:focus-visible, .tile:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.btn.green { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.green:hover { background: var(--brand2); color: #fff; }
.btn.purple { background: var(--purple); border-color: var(--purple); color: #fff; } .btn.purple:hover { background: #6d28d9; color: #fff; }
.btn.ghost { background: transparent; } .btn.danger { color: var(--bad); border-color: var(--bad-line); } .btn.danger:hover { background: var(--bad-bg); color: var(--bad); }
.btn.big { padding: .75rem 1.3rem; font-size: 1.05rem; font-weight: 600; } .btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.chip { border: 1px solid var(--line2); background: var(--surface); border-radius: 999px; padding: .25rem .8rem; cursor: pointer; font: inherit; font-size: .85rem; color: var(--ink); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; }
.tile { display: flex; flex-direction: column; gap: .2rem; padding: .8rem; border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--tile); }
.tile:hover { border-color: var(--brand); background: var(--tile-hover); color: var(--ink); }
.tile.english { border-left-color: var(--english); } .tile.gk { border-left-color: var(--gk); } .tile.intelligence { border-left-color: var(--intelligence); } .tile.maths { border-left-color: var(--maths); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: var(--soft); font-weight: 600; }
.card { overflow-x: auto; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; background: var(--brand); }
.dot.english, .bar-f.english { background: var(--english); } .dot.gk, .bar-f.gk { background: var(--gk); } .dot.intelligence, .bar-f.intelligence { background: var(--intelligence); } .dot.maths, .bar-f.maths { background: var(--maths); }
.tag { font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; color: var(--tag-ink, #fff); background: var(--brand); }
:root[data-theme="dark"] .tag { --tag-ink: #0f1419; }
.tag.english { background: var(--english); } .tag.gk { background: var(--gk); } .tag.intelligence { background: var(--intelligence); } .tag.maths { background: var(--maths); }

/* charts */
.chart { width: 100%; height: auto; } .chart .grid { stroke: var(--line); } .chart .ref { stroke-dasharray: 5 4; stroke-width: 1.5; } .chart .axis { font-size: 11px; fill: var(--muted); }
.bars { display: grid; gap: .4rem; } .bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr auto; gap: .6rem; align-items: center; font-size: .9rem; }
.bar-t { height: 12px; background: var(--soft2); border-radius: 6px; overflow: hidden; } .bar-f { display: block; height: 100%; background: var(--brand); }
.bar-v { color: var(--muted); font-size: .82rem; white-space: nowrap; }

/* forms */
.form { display: grid; gap: .8rem; max-width: 560px; } .form label { display: grid; gap: .25rem; font-weight: 500; }
.form label.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
input, select { font: inherit; padding: .45rem .55rem; border: 1px solid var(--line2); border-radius: 6px; background: var(--surface); color: var(--ink); }
label select { margin-left: .3rem; }

/* exam */
.exam { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--surface); }
.exam-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 1rem; background: var(--brand2); color: #fff; flex-wrap: wrap; }
.et-title { font-weight: 700; } .et-cand { opacity: .9; font-size: .9rem; }
.et-timer { font-variant-numeric: tabular-nums; font-weight: 700; background: #0b3b37; padding: .3rem .7rem; border-radius: 6px; }
.et-timer.warn { background: var(--bad); }
.sec-tabs { display: flex; gap: .3rem; padding: .4rem 1rem; border-bottom: 1px solid var(--line); background: var(--soft); overflow-x: auto; }
.sec-tab { border: 1px solid var(--line2); background: var(--surface); padding: .35rem .8rem; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap; color: var(--ink); }
.sec-tab.on { background: var(--brand); border-color: var(--brand); color: #fff; } .sec-tab small { opacity: .8; }
.exam-body { flex: 1; display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.qpane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.qhead { display: flex; gap: .6rem; align-items: baseline; padding: .6rem 1rem; border-bottom: 1px solid var(--line); }
.qhead .marks { margin-left: auto; font-size: .85rem; color: var(--muted); }
.qscroll { flex: 1; overflow-y: auto; padding: 1rem 1.2rem; }
.qtext { font-size: 1.12rem; margin-bottom: .9rem; }
.qtext u { text-decoration-thickness: 2px; text-underline-offset: 3px; }
.passage { background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; max-height: 40vh; overflow-y: auto; font-size: .98rem; }
.passage-h { font-weight: 600; margin-bottom: .3rem; } details.passage { max-height: none; } details.passage summary { cursor: pointer; font-weight: 600; }
.qimg { max-width: 100%; max-height: 300px; display: block; margin: .5rem 0 1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.qfig { margin: .5rem 0 1rem; overflow-x: auto; }
.seq { display: flex; align-items: center; gap: .4rem; } .seq-gap { width: .4rem; } .seq-q { font-size: 2rem; font-weight: 700; width: 80px; text-align: center; border: 2px dashed var(--line3); line-height: 76px; }
.gen-fig { max-width: 100%; height: auto; }
.opts { display: grid; gap: .6rem; }
.opts.figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt { display: flex; align-items: center; gap: .8rem; text-align: left; padding: .65rem .8rem; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; font: inherit; font-size: 1.05rem; color: var(--ink); }
.opt:hover { border-color: var(--line3); background: var(--surface); color: var(--ink); }
.opt.sel { border-color: var(--brand); background: var(--sel); }
.opt .ol { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--soft2); font-weight: 700; color: var(--ink); }
.opt.sel .ol { background: var(--brand); color: #fff; }
.opt-img { max-height: 110px; max-width: 100%; display: block; }
.opt-svg svg { display: block; max-width: 100%; height: auto; }
.qbtns { display: flex; gap: .5rem; flex-wrap: wrap; padding: .6rem 1rem; border-top: 1px solid var(--line); background: var(--soft); }
.qbtns .green { margin-left: auto; }
.palette { padding: .8rem; overflow-y: auto; background: var(--pal-bg); }
.pal-legend { display: grid; grid-template-columns: auto 1fr; gap: .3rem .5rem; align-items: center; font-size: .78rem; margin-bottom: .8rem; }
.pal-sec { font-weight: 700; margin: .4rem 0; font-size: .9rem; }
.pal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: .35rem; margin-bottom: 1rem; }
.pq, .pl { display: inline-grid; place-items: center; min-width: 2.2rem; height: 2.2rem; border-radius: 6px; border: 1px solid var(--line2); background: var(--surface); font: inherit; font-size: .85rem; cursor: pointer; color: var(--ink); position: relative; }
.pl { min-width: 1.8rem; height: 1.6rem; cursor: default; font-size: .75rem; }
.pq.nv, .pl.nv { background: var(--surface); }
.pq.notans, .pl.notans { background: var(--notans-bg); border-color: var(--notans-line); color: var(--bad-ink); }
.pq.ans, .pl.ans { background: #16a34a; border-color: #15803d; color: #fff; }
.pq.mark, .pl.mark { background: var(--purple); border-color: #6d28d9; color: #fff; border-radius: 50%; }
.pq.ansmark, .pl.ansmark { background: var(--purple); border-color: #6d28d9; color: #fff; border-radius: 50%; box-shadow: inset 0 -5px 0 #22c55e; }
.pq.cur { outline: 3px solid #0ea5e9; outline-offset: 1px; }
.btn.submit { width: 100%; justify-content: center; background: #b91c1c; border-color: #b91c1c; color: #fff; font-weight: 700; }
.btn.submit:hover { background: #991b1b; color: #fff; }
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; z-index: 20; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 12px; padding: 1.2rem 1.4rem; max-width: 620px; width: 100%; max-height: 90vh; overflow: auto; }
.alert { background: var(--bad-bg); color: var(--bad-ink); border: 1px solid var(--bad-line); padding: .6rem .8rem; border-radius: 8px; }
.alert.soft { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.instr ul { padding-left: 1.2rem; } .instr li { margin: .35rem 0; } .instr .tbl { max-width: 460px; margin-bottom: 1rem; }

/* review */
.rv { border: 1px solid var(--line); border-left: 4px solid var(--line3); border-radius: 10px; padding: .8rem 1rem; margin: .7rem 0; }
.rv.right { border-left-color: var(--ok); } .rv.wrong { border-left-color: var(--bad); } .rv.skip { border-left-color: var(--warn); }
.rv-h { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.res { margin-left: auto; font-weight: 700; font-size: .85rem; } .res.right { color: var(--ok); } .res.wrong { color: var(--bad); } .res.skip { color: var(--warn); }
.opts.review .opt { cursor: default; padding: .45rem .7rem; font-size: .98rem; }
.opts.review .opt.key { border-color: var(--ok); background: var(--ok-bg); } .opts.review .opt.key .ol { background: #15803d; color: #fff; }
.opts.review .opt.mine-wrong { border-color: var(--bad); background: var(--bad-bg); } .opts.review .opt.mine-wrong .ol { background: #b91c1c; color: #fff; }
.you { margin-left: auto; font-size: .75rem; color: var(--muted); }
.expl { margin: .7rem 0 .3rem; background: var(--soft); border-radius: 8px; padding: .55rem .8rem; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .85em; line-height: 1.1; margin: 0 .1em; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 .15em; }
.ovl { text-decoration: overline; }

.pal-toggle { display: none; }
@media (max-width: 860px) {
  .grid2 { grid-template-columns: 1fr; }
  .exam-body { grid-template-columns: 1fr; }
  .qpane { border-right: none; }
  .qhead { flex-wrap: wrap; }
  .qhead .marks { margin-left: 0; }
  .pal-toggle { display: inline-flex; margin-left: auto; }
  .palette { display: none; position: fixed; left: 0; right: 0; bottom: 0; max-height: 70vh; z-index: 15; border-top: 2px solid var(--line); box-shadow: 0 -8px 24px rgba(0, 0, 0, .18); }
  .exam.show-pal .palette { display: block; }
  .pal-legend { grid-template-columns: repeat(3, auto 1fr); }
  .qbtns { gap: .35rem; padding: .45rem .6rem; }
  .qbtns .btn { flex: 1 1 45%; justify-content: center; padding: .45rem .5rem; font-size: .88rem; } .qbtns .green { margin-left: 0; }
  .qscroll { padding: .8rem; }
  .opts.figs { grid-template-columns: 1fr; }
  .et-cand { display: none; }
}
