:root {
  --night: #0d131f;
  --night-2: #131a24;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #5b6577;
  --gold: #c3a669;
  --gold-deep: #8f7238;
  --gold-soft: #f3ead6;
  --ivory: #faf7f2;
  --paper: #ffffff;
  --rule: #e6dfd0;
  --rule-strong: #cfc4ad;
  --ok: #1f6f4a;
  --ok-soft: #e4f2ea;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #a3271c;
  --bad-soft: #fbe7e4;
  --sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--ivory);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(30px, 4.2vw, 44px); }
h2 { font-size: 26px; }
h3 { font-size: 19px; }
p { margin: 0 0 12px; }
a { color: var(--gold-deep); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- top band ---------- */
.band {
  background: var(--night);
  color: #e8edf4;
  border-bottom: 1px solid rgba(195, 166, 105, 0.35);
}
.band-inner {
  max-width: 1120px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; }
.brand img { height: 30px; width: auto; display: block; }
.brand-sep { width: 1px; height: 22px; background: rgba(195, 166, 105, 0.45); }
.brand-title { font-size: 14px; color: #b8c2d1; }
.band-right { font-size: 14px; color: #b8c2d1; text-align: right; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 22px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #1e293b; }
.btn-gold { background: var(--gold); color: var(--night); }
.btn-gold:hover { background: #d2b97f; }
.btn-ghost { background: transparent; border-color: var(--rule-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-danger { background: transparent; border-color: #e3b3ad; color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--muted); }
.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--rule-strong); background: var(--paper);
}
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(195, 166, 105, 0.35); }
.input[aria-invalid='true'] { border-color: var(--bad); }
textarea.input { min-height: 160px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.error-text { color: var(--bad); font-size: 14px; }
.notice { padding: 12px 16px; border-radius: var(--r-sm); font-size: 14px; }
.notice-bad { background: var(--bad-soft); color: var(--bad); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- simple centered pages ---------- */
.page { max-width: 640px; margin: 0 auto; padding: 56px 24px 80px; }
.page-wide { max-width: 760px; }
.lede { font-size: 18px; color: var(--ink-2); margin-top: 14px; }
.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 28px; }
.stack > * + * { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- test: instructions ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--paper); overflow: hidden; margin: 28px 0; }
.fact { padding: 16px 18px; border-right: 1px solid var(--rule); }
.fact:last-child { border-right: 0; }
.facts.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fact b { display: block; font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1.1; }
.fact span { font-size: 14px; color: var(--muted); }
.sections-list { list-style: none; padding: 0; margin: 0 0 24px; border-top: 1px solid var(--rule); }
.sections-list li { display: flex; justify-content: space-between; padding: 12px 2px; border-bottom: 1px solid var(--rule); }
.rules { padding-left: 20px; margin: 0 0 24px; }
.rules li { margin-bottom: 8px; }
.check-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.check-dot { width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--rule); color: var(--muted); }
.check-dot.ok { background: var(--ok); color: #fff; }
.check-dot.bad { background: var(--bad); color: #fff; }
.check-dot.wait { background: var(--gold-soft); color: var(--gold-deep); }
.consent { display: flex; gap: 12px; align-items: flex-start; margin: 22px 0; font-size: 15px; }
.consent input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.cam-preview { width: 160px; height: 120px; border-radius: var(--r-sm); background: var(--night); object-fit: cover; transform: scaleX(-1); }

/* ---------- test: question screen ---------- */
.exam { min-height: 100vh; display: flex; flex-direction: column; background: var(--ivory); }
.sections-bar { display: flex; gap: 6px; max-width: 1120px; margin: 0 auto; padding: 0 24px 14px; }
.sections-bar .seg { flex: 1; }
.seg-name { font-size: 12px; color: #8e99aa; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.seg-fill { height: 100%; background: var(--gold); width: 0; transition: width 0.4s var(--ease); }
.seg.current .seg-name { color: #e8edf4; }

.sheet-wrap { flex: 1; padding: 32px 24px 48px; position: relative; }
.sheet {
  max-width: 780px; margin: 0 auto; background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-lg); position: relative; overflow: hidden;
}
.timer-line { height: 5px; background: var(--gold-soft); }
.timer-line i { display: block; height: 100%; background: var(--gold); transform-origin: left center; }
.sheet.urgent .timer-line i { background: var(--bad); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 22px 32px 0; }
.qcount { font-size: 14px; color: var(--muted); }
.qcount strong { font-family: var(--serif); font-size: 30px; font-weight: 600; color: var(--ink); margin-right: 4px; }
.clock { text-align: right; }
.clock b { font-family: var(--serif); font-weight: 600; font-size: 34px; font-variant-numeric: tabular-nums; line-height: 1; display: block; }
.clock span { font-size: 13px; color: var(--muted); }
.sheet.urgent .clock b { color: var(--bad); }
.section-note { margin: 16px 32px 0; padding: 10px 14px; border-left: 3px solid var(--gold); background: var(--gold-soft); font-size: 14px; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.qbody { padding: 22px 32px 8px; position: relative; z-index: 1; }
.stem { font-size: 18px; white-space: pre-line; margin-bottom: 20px; }
.passage { white-space: pre-line; font-family: var(--serif); font-size: 17px; line-height: 1.65; padding: 18px 20px; background: var(--ivory); border-radius: var(--r-md); margin-bottom: 18px; }
.stem-figure { margin: 4px 0 22px; }
.stem-figure svg { display: block; max-width: 100%; height: auto; }
.stem-figure.matrix svg { width: 300px; }
.stem-figure.sequence svg { width: 100%; max-width: 560px; }
.dtable { border-collapse: collapse; margin: 0 0 20px; font-variant-numeric: tabular-nums; min-width: 320px; }
.dtable th, .dtable td { padding: 9px 18px; border-bottom: 1px solid var(--rule); text-align: left; }
.dtable .num { text-align: right; }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable th { font-size: 14px; color: var(--muted); font-weight: 600; border-bottom-color: var(--rule-strong); }
.table-scroll { overflow-x: auto; }

.options { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; }
.options.figures { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: var(--r-md); border: 1.5px solid var(--rule);
  background: var(--paper); cursor: pointer; font-size: 16px; line-height: 1.4;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.opt:hover { border-color: var(--rule-strong); background: #fdfbf7; }
.opt[aria-checked='true'] { border-color: var(--ink); background: var(--gold-soft); box-shadow: inset 0 0 0 1px var(--ink); }
.opt-key {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; border: 1.5px solid var(--rule-strong); color: var(--ink-2);
}
.opt[aria-checked='true'] .opt-key { background: var(--ink); border-color: var(--ink); color: #fff; }
.options.figures .opt { flex-direction: column; padding: 12px 10px 10px; gap: 8px; }
.options.figures .opt svg { width: 100%; max-width: 150px; height: auto; display: block; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 32px 26px; }
.sheet-foot .small { max-width: 52ch; }
.watermark { position: absolute; inset: 0; pointer-events: none; z-index: 2; opacity: 0.07; background-repeat: repeat; }
.no-select { user-select: none; -webkit-user-select: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(13, 19, 31, 0.92);
  display: grid; place-items: center; padding: 24px; color: #e8edf4;
}
.overlay .card { max-width: 480px; background: var(--paper); color: var(--ink); border-radius: var(--r-lg); padding: 30px; }
.overlay .card h2 { margin-bottom: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--night); color: #f1f4f8; padding: 12px 18px; border-radius: 999px; font-size: 14px;
  border: 1px solid rgba(195, 166, 105, 0.5);
}

/* ---------- done ---------- */
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--gold-soft); display: grid; place-items: center; margin-bottom: 22px; }

@media (max-width: 640px) {
  .band-inner { padding: 12px 16px; }
  .brand img { height: 24px; }
  .brand-sep, .brand-title { display: none; }
  .sheet-wrap { padding: 16px 10px 32px; }
  .sheet-head, .qbody, .sheet-foot { padding-left: 18px; padding-right: 18px; }
  .section-note { margin-left: 18px; margin-right: 18px; }
  .options.figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet-foot { flex-direction: column-reverse; align-items: stretch; }
  .facts:not(.three) .fact { border-right: 0; border-bottom: 1px solid var(--rule); }
  .facts.three .fact { padding: 14px 12px; }
  .facts.three .fact b { font-size: 22px; }
  .sections-bar .seg-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* =================== admin =================== */
.admin-nav { max-width: 1240px; margin: 0 auto; padding: 0 24px; display: flex; gap: 4px; }
.admin-nav button {
  background: none; border: 0; color: #9aa6b7; padding: 10px 14px 12px; font-weight: 600; font-size: 14px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.admin-nav button[aria-selected='true'] { color: #fff; border-bottom-color: var(--gold); }
.admin-nav button:hover { color: #fff; }
.admin-main { max-width: 1240px; margin: 0 auto; padding: 32px 24px 80px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.admin-head p { margin: 6px 0 0; color: var(--muted); }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.facts.wide { margin: 0 0 28px; }
.hist { width: 100%; height: auto; display: block; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .input { width: auto; min-height: 40px; padding: 6px 12px; }
.filters .search { flex: 1; min-width: 220px; }
.table-card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--rule-strong); white-space: nowrap; background: #fdfcf9; position: sticky; top: 0; }
table.data th button { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
table.data th button[data-dir]::after { content: attr(data-dir); margin-left: 4px; color: var(--gold-deep); }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: #fdfaf3; }
table.data .num { text-align: right; }
.cell-name b { display: block; font-weight: 600; }
.cell-name span { color: var(--muted); font-size: 13px; }
.score { font-family: var(--serif); font-weight: 600; font-size: 18px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill-invited { background: #eef1f5; color: #475569; }
.pill-in_progress { background: var(--gold-soft); color: var(--gold-deep); }
.pill-stalled { background: var(--warn-soft); color: var(--warn); }
.pill-completed { background: var(--ok-soft); color: var(--ok); }
.pill-clean { background: var(--ok-soft); color: var(--ok); }
.pill-review { background: var(--warn-soft); color: var(--warn); }
.pill-high { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-size: 14px; color: var(--muted); }

.drawer-back { position: fixed; inset: 0; background: rgba(13, 19, 31, 0.45); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--ivory); z-index: 41;
  overflow-y: auto; border-left: 1px solid var(--rule-strong); box-shadow: -24px 0 48px rgba(13, 19, 31, 0.18);
}
.drawer-head { position: sticky; top: 0; background: var(--paper); border-bottom: 1px solid var(--rule); padding: 20px 28px; display: flex; justify-content: space-between; gap: 16px; z-index: 2; }
.drawer-body { padding: 24px 28px 60px; }
.drawer section { margin-bottom: 30px; }
.drawer section > h3 { margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 56px; align-items: center; gap: 12px; font-size: 14px; }
.bar-track { height: 8px; background: var(--rule); border-radius: 8px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--gold); }
.flag-list { list-style: none; padding: 0; margin: 0; }
.flag-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.snaps { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.snaps figure { margin: 0; }
.snaps img { width: 100%; border-radius: var(--r-sm); display: block; background: var(--night); aspect-ratio: 4 / 3; object-fit: cover; }
.snaps figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 14px; max-height: 320px; overflow: auto; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--paper); }
.timeline li { display: flex; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--rule); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; width: 76px; }
.timeline .w { color: var(--bad); }
.answers { display: grid; gap: 8px; }
.answer { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-md); }
.answer summary { list-style: none; display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; font-size: 14px; }
.answer summary::-webkit-details-marker { display: none; }
.answer .mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.mark.ok { background: var(--ok-soft); color: var(--ok); }
.mark.no { background: var(--bad-soft); color: var(--bad); }
.mark.to { background: #eef1f5; color: #64748b; }
.answer .ans-body { padding: 4px 16px 16px 60px; font-size: 14px; }
.answer .ans-body .stem { font-size: 15px; margin-bottom: 10px; }
.answer .ans-body svg { max-width: 260px; height: auto; display: block; }
.ans-opts { display: grid; gap: 6px; }
.ans-opts.figs { grid-template-columns: repeat(4, minmax(0, 90px)); }
.ans-opt { border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 6px 10px; display: flex; gap: 8px; align-items: center; }
.ans-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.ans-opt.chosen:not(.correct) { border-color: var(--bad); background: var(--bad-soft); }
.ans-opt svg { width: 100%; }
.drop {
  border: 2px dashed var(--rule-strong); border-radius: var(--r-lg); padding: 28px; text-align: center; background: var(--paper);
}
.drop.over { border-color: var(--gold); background: var(--gold-soft); }
.switch { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.switch input { width: 20px; height: 20px; accent-color: var(--ink); margin-top: 3px; flex: none; }
.switch > span > b { display: block; }
.switch > span > span { display: block; }
.code-chip { font-family: var(--serif); font-size: 22px; letter-spacing: 0.08em; }
.admin-page .band-inner { max-width: 1240px; }

.table-title { font-family: var(--sans); font-size: 14px; font-weight: 600; margin: 4px 0 6px; color: var(--ink-2); }
.dtable tbody th { text-align: left; font-weight: 600; color: var(--ink); font-size: 15px; border-bottom: 1px solid var(--rule); }
.logbox {
  background: var(--night); color: #dbe3ee; border-radius: var(--r-md); padding: 14px 16px; margin: 0 0 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.primer ul { padding-left: 20px; margin: 0 0 12px; }
.primer li { margin-bottom: 6px; }
.answer .logbox { font-size: 11.5px; }

/* question bank */
.tpl-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.tpl-list li { border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 8px 12px; }
.tpl-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
.tpl-out:not(:empty) { margin-top: 10px; }
.answer summary .mark.to { font-size: 12px; }
#tab-bank .answer .ans-body > svg { max-width: 520px; width: 100%; }
#tab-bank .ans-opts.figs { grid-template-columns: repeat(4, minmax(0, 150px)); }
