:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #1b2430;
  --muted: #5b6676;
  --border: #d9e0e8;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --accent: #2f6fb0;
  --pass: #1d7a4a;
  --pass-bg: #e3f4ea;
  --fail: #b3261e;
  --fail-bg: #fbe7e5;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #18202a;
    --surface-2: #202a36;
    --text: #e6ebf1;
    --muted: #9aa6b5;
    --border: #2d3846;
    --brand: #5b9bd5;
    --brand-ink: #0c1218;
    --accent: #7fb3e6;
    --pass: #5fcf8e;
    --pass-bg: #163325;
    --fail: #ff8a80;
    --fail-bg: #3a1c1a;
    --warn: #f3c46b;
    --warn-bg: #3a2d10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .75rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.mt-1 { margin-top: 1rem; }
.pre { white-space: pre-line; }

/* ---------- layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  background: var(--brand); color: var(--brand-ink); font-weight: 800;
}
.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav a, .linkish {
  color: var(--muted); text-decoration: none; padding: .4rem .7rem; border-radius: 8px;
  font: inherit; font-size: .95rem; background: none; border: 0; cursor: pointer;
}
.nav a:hover, .linkish:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--brand); background: var(--surface-2); font-weight: 600; }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }
.container-narrow { width: 100%; max-width: 820px; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card.narrow { max-width: 440px; margin: 2rem auto; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

/* ---------- forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=number], input[type=datetime-local], input[type=file],
select, textarea {
  width: 100%; padding: .6rem .7rem; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
.field { margin-bottom: .9rem; }
.field-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; font-weight: 400; }
.code-input { font-size: 1.6rem; letter-spacing: .5rem; text-align: center; font-variant-numeric: tabular-nums; }
.checkbox { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
.checkbox input { margin-top: .3rem; width: 1.1rem; height: 1.1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand);
  color: var(--brand-ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--brand); }
.btn-danger { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-block { width: 100%; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-ok { background: var(--pass-bg); color: var(--pass); border-color: color-mix(in srgb, var(--pass) 30%, transparent); }
.flash-error { background: var(--fail-bg); color: var(--fail); border-color: color-mix(in srgb, var(--fail) 30%, transparent); }
.flash-info { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* ---------- badges & tables */
.badge {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-pass { background: var(--pass-bg); color: var(--pass); }
.badge-fail { background: var(--fail-bg); color: var(--fail); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-open { background: var(--pass-bg); color: var(--pass); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- KPI tiles */
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi .label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.kpi .value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- charts (palette validated with the dataviz checker on #fff / #18202a surfaces) */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300;
  --series-other: #a8a69f; --chart-track: #eef1f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
    --series-other: #6f6e69; --chart-track: #222c38;
  }
}
.seg.c1, .seg.c-good { fill: var(--series-1); }  .sw.c1, .sw.c-good { background: var(--series-1); }
.seg.c2, .seg.c-bad { fill: var(--series-2); }   .sw.c2, .sw.c-bad { background: var(--series-2); }
.seg.c3 { fill: var(--series-3); }  .sw.c3 { background: var(--series-3); }
.seg.c4 { fill: var(--series-4); }  .sw.c4 { background: var(--series-4); }
.seg.c5 { fill: var(--series-5); }  .sw.c5 { background: var(--series-5); }
.seg.c6 { fill: var(--series-6); }  .sw.c6 { background: var(--series-6); }
.seg.c-other, .seg.c-neutral { fill: var(--series-other); }
.sw.c-other, .sw.c-neutral { background: var(--series-other); }
.track { fill: var(--chart-track); }
.seg { stroke: var(--surface); stroke-width: 2px; stroke-linejoin: round; transition: opacity .15s; cursor: default; }
.seg.solo { stroke: none; }
svg:hover .seg { opacity: .55; }
svg .seg:hover { opacity: 1; }
.chart-card h3 { margin-bottom: .75rem; }
.pie-wrap { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.pie { width: 150px; height: 150px; flex: none; }
.pie text, .mini text { font: 700 22px system-ui, sans-serif; fill: var(--text); }
.pie .sub, .mini .sub { font-weight: 400; font-size: 12px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; font-size: .88rem; flex: 1; min-width: 150px; }
.legend li { display: flex; align-items: center; gap: .45rem; padding: .15rem 0; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); padding-left: .5rem; }
.empty-chart { color: var(--muted); font-size: .9rem; padding: 2rem 0; text-align: center; }
.legend-row { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.sw-inline { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin: 0 .25rem 0 .1rem; }
.sw-inline.c-good { background: var(--series-1); }
.sw-inline.c-bad { background: var(--series-2); }
.score-inline { font-size: 1.8rem; font-weight: 800; }
table.kv th { text-transform: none; letter-spacing: 0; font-size: .85rem; width: 45%; }
table.kv td, table.kv th { padding: .35rem .4rem; }
.answer-list { list-style: none; padding: 0; margin: .25rem 0 .75rem; }
.answer-list li { padding: .3rem .5rem; border-radius: 6px; }
.answer-list li.is-right { background: var(--pass-bg); }
.option-row { margin-bottom: .45rem; flex-wrap: nowrap; }
.option-row input[type=text] { flex: 1; }
.option-row input[type=radio] { width: 1.1rem; height: 1.1rem; flex: none; }
.options-edit { border: 0; padding: 0; margin: 0 0 .9rem; }
code { font-size: .85em; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
.mini-pies { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.mini-pie { text-align: center; }
.mini-pie .pie { width: 96px; height: 96px; }
.mini-pie .name { font-size: .82rem; font-weight: 600; min-height: 2.4em; }
.mini-pie .nums { font-size: .8rem; color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ---------- test taking */
.test-head {
  position: sticky; top: 57px; z-index: 5; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
  display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.timer { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--brand); }
.timer.low { color: var(--fail); }
.progress-text { color: var(--muted); font-size: .9rem; }
.save-state { font-size: .82rem; color: var(--muted); min-width: 7rem; text-align: right; }
.save-state.error { color: var(--fail); font-weight: 600; }
.question { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: .9rem; }
.question legend { font-weight: 600; padding: 0; margin-bottom: .6rem; }
.question fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.qnum { color: var(--muted); font-weight: 700; margin-right: .35rem; }
.opt {
  display: flex; gap: .65rem; align-items: flex-start; padding: .55rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: .45rem; cursor: pointer; font-weight: 400;
}
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: .25rem; width: 1.05rem; height: 1.05rem; flex: none; }
.opt:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.opt .ol { font-weight: 700; color: var(--muted); min-width: 1.4rem; }

/* ---------- results */
.score-hero { text-align: center; padding: 1.5rem 1rem; }
.score-hero .big { font-size: 3.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-hero .verdict { font-size: 1.2rem; font-weight: 800; margin-top: .5rem; letter-spacing: .04em; }
.verdict.pass { color: var(--pass); }
.verdict.fail { color: var(--fail); }
.delta-up { color: var(--pass); font-weight: 700; }
.delta-down { color: var(--fail); font-weight: 700; }
progress { width: 100%; min-width: 90px; height: 8px; border: 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
progress.ok::-webkit-progress-value { background: var(--pass); }
progress.ok::-moz-progress-bar { background: var(--pass); }
progress.low::-webkit-progress-value { background: var(--fail); }
progress.low::-moz-progress-bar { background: var(--fail); }
.m0 { margin: 0; }
.instructions { margin: 0; padding-left: 1.2rem; }
.instructions li { margin-bottom: .35rem; }
.ans-row.correct td:first-child { border-left: 4px solid var(--pass); }
.ans-row.wrong td:first-child { border-left: 4px solid var(--fail); }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 170px; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .container, .container-narrow { padding: 1rem 16px 2.5rem; }
  .topbar { padding: .6rem 16px; }
  .test-head { top: 0; position: sticky; }
  .score-hero .big { font-size: 2.6rem; }
  .pie { width: 120px; height: 120px; }
}
@media print {
  .topbar, .footer, .btn, .filters { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
