:root {
  --bg: #f6f7fb; --surface: #ffffff; --text: #1b2230; --muted: #5b6577; --line: #d9deea;
  --brand: #3b3bb3; --brand-ink: #ffffff; --brand-soft: #e9e9fb;
  --ok: #17794a; --ok-soft: #e2f5ea; --warn: #8a5a00; --warn-soft: #fff3d6; --bad: #b3261e; --bad-soft: #fde8e6;
  --focus: #1a6ef0; --radius: 10px; --gap: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d; --surface: #1b2030; --text: #e8ebf3; --muted: #a2abbd; --line: #2e3550;
    --brand: #8d8dff; --brand-ink: #101226; --brand-soft: #262a4a;
    --ok: #55d596; --ok-soft: #14301f; --warn: #f2c14e; --warn-soft: #3a2f10; --bad: #ff8c84; --bad-soft: #3d1b19; --focus: #6ea8ff;
  }
}
* { box-sizing: border-box; }
html { font-size: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; } h2 { font-size: 1.2rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: .75rem 0 .25rem; }
a { color: var(--brand); } code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.boot, .muted { color: var(--muted); } .hint { color: var(--muted); font-size: .875rem; margin: .25rem 0 0; }
.sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: 8px; z-index: 10; background: var(--surface); padding: .5rem 1rem; border-radius: 6px; }
.center { min-height: 100vh; display: grid; place-items: center; padding: var(--gap); }
.narrow { width: min(440px, 100%); } .wide { grid-column: 1 / -1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: var(--gap); }

/* shell */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding: 10px var(--gap); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 1rem; } .topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.topbar nav a.active, .topbar nav a:hover { background: var(--brand-soft); }
.who { color: var(--muted); font-size: .9rem; }
main#main { outline: none; } .page { max-width: 1180px; margin: 0 auto; padding: var(--gap); }
.row { display: flex; gap: 8px; align-items: flex-end; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; align-items: center; } .row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }

/* form controls */
.field { margin: 0 0 12px; min-width: 0; }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
label.inline { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 6px 0; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 40px; }
textarea { resize: vertical; } input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; accent-color: var(--brand); }
input:disabled, select:disabled, textarea:disabled { opacity: .7; background: var(--bg); }
.error { color: var(--bad); font-size: .9rem; margin: .25rem 0; } .ok { color: var(--ok); font-weight: 600; }
.error-box { background: var(--bad-soft); color: var(--text); border: 1px solid var(--bad); border-radius: var(--radius); padding: 12px 16px; margin-bottom: var(--gap); }
.banner { background: var(--warn-soft); border: 1px solid var(--warn); color: var(--text); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; } fieldset.plain legend { font-weight: 600; font-size: .92rem; padding: 0; }
fieldset.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin: var(--gap) 0; }
fieldset.section > legend { font-weight: 700; padding: 0 8px; } section.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin: var(--gap) 0; }
.subsection { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 8px; } .confidential { background: var(--warn-soft); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; min-height: 40px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.btn:hover:not(:disabled) { border-color: var(--brand); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); } .btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-small { padding: 4px 10px; min-height: 32px; font-size: .875rem; } .btn.active { background: var(--brand-soft); border-color: var(--brand); }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; text-decoration: underline; padding: 4px 0; font: inherit; }
.actionbar { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; margin: var(--gap) -4px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -4px 12px rgb(0 0 0 / 8%); }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; font-size: .75rem; border-radius: 999px; background: var(--brand-soft); color: var(--text); font-weight: 600; }
.badge-published { background: var(--ok-soft); color: var(--ok); } .badge-draft { background: var(--warn-soft); color: var(--warn); } .badge-archived { background: var(--line); } .badge-note { background: var(--warn-soft); color: var(--warn); }

/* list */
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 12px 0; } .filters input[type=search] { grid-column: span 2; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; } table.grid th, table.grid td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); } td.num { text-align: right; } .title-link { font-weight: 600; }
.pager { display: flex; align-items: center; gap: 12px; padding: 12px 0; flex-wrap: wrap; } .empty { padding: 32px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.plainlist { list-style: none; margin: 0 0 12px; padding: 0; } .plainlist li { padding: 6px 0; border-bottom: 1px solid var(--line); gap: 8px; }

/* editor */
.live-wrap { margin-top: 8px; } .markup { overflow-wrap: anywhere; } .markup p { margin: .5rem 0; } .live { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.math-display { display: block; text-align: center; margin: .5rem 0; } .math:not(.math-rendered) { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--brand-soft); border-radius: 4px; padding: 0 4px; }
.asset-list, .options, .numerics, .codes { list-style: none; margin: 0 0 12px; padding: 0; }
.asset { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.thumb { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px; align-self: start; } .thumb img { width: 100%; height: auto; display: block; border-radius: 4px; }
.upload-preview { max-width: 240px; max-height: 160px; border: 1px solid var(--line); border-radius: 8px; display: block; margin: 8px 0; }
.uploader { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 12px 16px; margin-top: 12px; }
.option-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.numeric-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 8px; align-items: end; margin-bottom: 4px; }
.readiness ul { margin: .25rem 0 0 1.2rem; padding: 0; } .codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; } .codes code { font-size: 1.1rem; }
.secret { font-size: 1.3rem; letter-spacing: .08em; background: var(--bg); padding: 10px 14px; border-radius: 8px; user-select: all; overflow-wrap: anywhere; } .wrap { overflow-wrap: anywhere; }

/* dialogs & preview */
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: min(1000px, 96vw); width: 100%; }
.dialog::backdrop { background: rgb(10 12 24 / 55%); } dialog.dialog:not(.preview) { max-width: 460px; }
.device-stage { background: var(--bg); border-radius: 8px; padding: 16px; margin-top: 8px; overflow: auto; max-height: 72vh; }
.device { margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; transition: max-width .15s; }
.device-mobile { max-width: 375px; } .device-tablet { max-width: 768px; } .device-desktop { max-width: 100%; }
.sq-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .sq-num { font-weight: 700; } .sq-marks { color: var(--muted); font-size: .9rem; }
.sq-figure { margin: 12px 0; } .sq-figure img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: block; }
.sq-answer { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; } .sq-answer legend { font-weight: 600; color: var(--muted); font-size: .9rem; padding: 0; }
.sq-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 400; } .sq-option:hover { border-color: var(--brand); }
.sq-input { max-width: 100%; } .sq-upload { margin-top: 12px; }
.toasts { position: fixed; right: 12px; bottom: 12px; display: grid; gap: 8px; z-index: 50; max-width: min(380px, 92vw); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgb(0 0 0 / 25%); } .toast-error { background: var(--bad); color: #fff; }

/* tablet */
@media (max-width: 960px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid3 { grid-template-columns: 1fr; } .numeric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* phone: tables become cards, editor goes single column */
@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; } .asset { grid-template-columns: 1fr; } .page { padding: 12px; } .filters input[type=search] { grid-column: 1 / -1; }
  table.grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { padding: 10px 12px; border-bottom: 1px solid var(--line); } table.grid td { border: 0; padding: 2px 0; text-align: left; }
  table.grid td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .8rem; }
  table.grid td:first-child::before { content: none; } td.num { text-align: left; }
  .option-row { grid-template-columns: auto minmax(0, 1fr); } .option-row .btn { grid-column: 2; justify-self: start; } .actionbar .btn { flex: 1 1 45%; }
  .topbar { position: static; } .codes { grid-template-columns: 1fr; }
  .topbar nav { flex: 1 1 100%; order: 5; }
}
@media (prefers-reduced-motion: reduce) { .device { transition: none; } }

/* ---- exam builder ---- */
.picker { align-items: start; } .picks { margin: 8px 0; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pick-n { width: 1.8rem; font-weight: 700; color: var(--muted); } .pick-t { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; } .pick-actions { display: flex; gap: 4px; }
dialog.room-dialog { max-width: 1240px; width: 98vw; height: 94vh; padding: 12px; overflow: auto; }
dialog.room-dialog .room { min-height: 0; } dialog.room-dialog .room-bar { position: static; }
