:root {
  --bg: #f3f7fc;
  --surface: #ffffff;
  --surface-2: #eaf1fb;
  --text: #0f1f3d;
  --muted: #5a6b85;
  --border: #d3dfef;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --primary-soft: #e0eaff;
  --accent: #0284c7;
  --good: #1f7a4d;
  --good-soft: #e3f3ea;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 78, 216, .06), 0 1px 3px rgba(29, 78, 216, .10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 1180px; }

.topbar {
  background: var(--primary); color: var(--primary-ink); padding: 12px 16px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar.wide .inner { max-width: 1180px; }
.topbar .brandwrap { display: flex; align-items: center; gap: 12px; min-width: 0; text-decoration: none; color: inherit; }
.topbar .logo { width: 46px; height: 46px; border-radius: 50%; background: #fff; flex: none; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.topbar .brand { font-weight: 700; letter-spacing: .01em; }
.topbar .brand small { display: block; font-weight: 400; opacity: .85; font-size: .8rem; }
.topbar a { color: inherit; font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.tight { padding: 14px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], textarea, select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.field { margin-bottom: 14px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.row { display: grid; gap: 12px; }
@media (min-width: 640px) { .row.two { grid-template-columns: 1fr 1fr; } .row.three { grid-template-columns: 1fr 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .95rem; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.good { background: var(--good-soft); color: var(--good); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

/* Test taking */
.progress { position: sticky; top: 56px; z-index: 9; background: var(--bg); padding: 8px 0; }
.progress .meta { display: flex; justify-content: space-between; font-size: .875rem; color: var(--muted); margin-bottom: 4px; }
.progress .bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress .bar > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.timer.low { color: var(--bad); font-weight: 700; }

.section-title { margin: 22px 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.scenario { border-left: 4px solid var(--accent); }
.scenario h3 { color: var(--accent); }
.scenario .text { white-space: pre-line; }
.question .qhead { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; }
.question .qnum { font-weight: 700; color: var(--primary); flex: none; }
.question .area { font-size: .75rem; color: var(--muted); margin-left: auto; text-align: right; }
.options { display: grid; gap: 8px; margin-top: 8px; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface); }
.option:hover { background: var(--surface-2); }
.option input { margin-top: 4px; flex: none; accent-color: var(--primary); width: 18px; height: 18px; }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option .letter { font-weight: 700; color: var(--primary); flex: none; width: 1.2em; }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.savestate { font-size: .8rem; color: var(--muted); text-align: right; min-height: 1.2em; }
.submitbar { position: sticky; bottom: 0; padding: 12px 0 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }

/* Results */
.score-hero { text-align: center; padding: 26px 18px; }
.score-hero .pct { font-size: 3.2rem; font-weight: 800; line-height: 1; color: var(--primary); }
.score-hero .pct.fail { color: var(--bad); }
.score-hero .sub { color: var(--muted); margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.stat .v { font-size: 1.3rem; font-weight: 700; }
.stat .l { font-size: .75rem; color: var(--muted); }
.areabar { margin-bottom: 12px; }
.areabar .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .95rem; }
.areabar .track { height: 12px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 4px; position: relative; }
.areabar .fill { height: 100%; border-radius: 999px; background: var(--good); }
.areabar .fill.needs_work { background: var(--bad); }
.areabar .fill.mid { background: var(--warn); }
.areabar .cohort { position: absolute; top: -3px; width: 2px; height: 18px; background: var(--text); opacity: .6; }
.areabar .sub { font-size: .78rem; color: var(--muted); }
.review .q { border-top: 1px solid var(--border); padding: 14px 0; }
.review .q:first-child { border-top: 0; }
.review .explain { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-top: 8px; font-size: .9rem; }
.legend { font-size: .78rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
.minibar { display: inline-block; height: 8px; background: var(--border); border-radius: 999px; width: 90px; vertical-align: middle; overflow: hidden; margin-right: 6px; }
.minibar > i { display: block; height: 100%; background: var(--good); }
.minibar > i.low { background: var(--bad); }
.minibar > i.mid { background: var(--warn); }

/* Admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.qr-box { display: grid; gap: 16px; align-items: start; }
@media (min-width: 720px) { .qr-box { grid-template-columns: 260px 1fr; } }
.qr-box img { width: 100%; max-width: 260px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.list { display: grid; gap: 10px; }
.list .item { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; }
.list .item.active { border-color: var(--primary); background: var(--primary-soft); }
.dist { display: flex; flex-wrap: wrap; gap: 6px; }
.dist span { font-size: .75rem; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); }
.dist span.correct { background: var(--good-soft); color: var(--good); font-weight: 700; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: flex-start; justify-content: center; padding: 20px 12px; overflow: auto; z-index: 50; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 680px; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.opt-row input[type=radio] { flex: none; accent-color: var(--primary); }
.opt-row input[type=text] { flex: 1; }
details summary { cursor: pointer; font-weight: 600; }
code, pre { font-family: Consolas, "Cascadia Mono", monospace; font-size: .85rem; }
pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; }
.code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 2rem; font-weight: 700; letter-spacing: .18em; color: var(--primary); background: var(--primary-soft); border-radius: 10px; padding: 10px 16px; display: inline-block; margin-top: 6px; }
.code.sm { font-size: 1rem; padding: 2px 8px; letter-spacing: .1em; margin: 0; }
.bankrow { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bankrow .name { flex: 1; min-width: 160px; }
.bankrow input[type=number] { width: 90px; }
.hidden { display: none !important; }
