/* ============================================================
   Design tokens
   System font stack is a deliberate choice, not a fallback: this
   is a timed exam tool, and a webfont dependency means an extra
   network round trip, layout shift, and a point of failure for
   people on constrained connections or using zoom/magnification.
   Personality here comes from scale, weight, and the timer/progress
   signature rather than a display typeface.
   ============================================================ */
:root {
  --ink: #12203A;
  --ink-soft: #48566E;
  --ink-faint: #7A8699;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #DBE2EA;
  --border-strong: #B9C3D2;

  --accent: #0B7A6B;
  --accent-dark: #085F53;
  --accent-bg: #E7F4F1;
  --on-accent: #FFFFFF;

  --warn: #8A5300;
  --warn-bg: #FFF6E5;
  --danger: #A02E24;
  --danger-bg: #FCEBE9;
  --success: #17693B;
  --success-bg: #E9F6EE;

  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(18, 32, 58, 0.06), 0 8px 24px rgba(18, 32, 58, 0.06);
  --focus-ring: 0 0 0 3px rgba(11, 122, 107, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Accessibility utilities ---------- */
.sr-only, .visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Layout ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand__dot { color: var(--accent); font-weight: 700; margin: 0 2px; }
.brand__sub {
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.shell {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.footer {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
  padding: 18px 20px 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px clamp(20px, 5vw, 40px);
}

.screen[hidden] { display: none !important; }

/* ---------- Type ---------- */
h1 {
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.015em;
  margin: 4px 0 12px;
  color: var(--ink);
}
.h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 28px 0 10px;
  color: var(--ink);
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
}
.lede {
  color: var(--ink-soft);
  margin: 0 0 8px;
}

.policy-list {
  margin: 0 0 18px;
  padding-left: 1.1em;
  color: var(--ink);
}
.policy-list li { margin-bottom: 10px; }

.disclosure {
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 18px 0;
}
.disclosure summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent-dark);
}
.disclosure p {
  color: var(--ink-soft);
  font-size: 0.94rem;
}
.disclosure p:last-child { margin-bottom: 0; }

/* ---------- Forms ---------- */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 6px;
  color: var(--ink);
}
.field input[type="text"],
.field input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
.field input:focus-visible {
  border-color: var(--accent);
}
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 6px 0 0;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  min-height: 48px;
}
.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn--primary:hover { background: var(--accent-dark); }
.btn--primary:disabled {
  background: var(--border-strong);
  color: #fff;
  cursor: not-allowed;
}
.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn--ghost:hover { border-color: var(--ink-faint); }
.btn--ghost:disabled { color: var(--ink-faint); cursor: not-allowed; }
.btn--block { width: 100%; }

.actions { margin-top: 24px; }
.actions--split {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 20px auto 0;
  padding: 0 20px 20px;
}

/* ---------- Exam bar ---------- */
.exam-bar {
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 4px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 16px;
  align-items: center;
}
.exam-bar__progress { grid-column: 1 / 2; grid-row: 1 / 2; }
.exam-bar__status {
  grid-column: 1 / 2; grid-row: 2 / 3;
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.timer { grid-column: 2 / 3; grid-row: 1 / 3; display: flex; align-items: center; gap: 8px; }

.dashes {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}
.dash {
  width: 14px;
  height: 6px;
  border-radius: 3px;
  background: var(--border-strong);
}
.dash.is-answered { background: var(--accent); }
.dash.is-current { outline: 2px solid var(--ink); outline-offset: 1px; }

.timer__ring { width: 40px; height: 40px; transform: rotate(-90deg); }
.timer__track { fill: none; stroke: var(--border); stroke-width: 4; }
.timer__fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 119.4; /* 2*pi*19 */
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}
.timer.is-warn .timer__fill { stroke: var(--warn); }
.timer.is-danger .timer__fill { stroke: var(--danger); }
.timer__label {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.95rem;
  min-width: 3.4em;
}
.timer.is-warn .timer__label { color: var(--warn); }
.timer.is-danger .timer__label { color: var(--danger); }

/* ---------- Question card ---------- */
.question-card { padding: clamp(20px, 5vw, 36px); }
.question-card fieldset { border: 0; margin: 0; padding: 0; }
.question-prompt {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
  padding: 0;
  margin: 6px 0 20px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  background: #fff;
}
.option:hover { border-color: var(--accent); }
.option input[type="radio"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
}
.option.is-selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.option span { color: var(--ink); }
.option:has(input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Review ---------- */
.review-grid {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.review-item {
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  width: 100%;
}
.review-item.is-answered { border-color: var(--accent); background: var(--accent-bg); }
.review-item .status {
  display: block;
  font-weight: 500;
  color: var(--ink-faint);
  font-size: 0.78rem;
  margin-top: 2px;
}
.review-item.is-answered .status { color: var(--accent-dark); }

/* ---------- Result ---------- */
.result-score {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 6px 0 2px;
}
.result-score .of { font-size: 1.1rem; color: var(--ink-faint); font-weight: 700; }

.result-banner {
  display: inline-block;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.result-banner.pass { background: var(--success-bg); color: var(--success); }
.result-banner.fail { background: var(--danger-bg); color: var(--danger); }

.level-breakdown {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.level-breakdown li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
}
.level-breakdown .label { font-size: 0.9rem; color: var(--ink); font-weight: 600; }
.level-breakdown .score { font-size: 0.85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.level-breakdown .bar {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.level-breakdown .bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

@media (max-width: 480px) {
  .exam-bar { grid-template-columns: 1fr auto; }
  .btn { font-size: 0.95rem; padding: 12px 16px; }
}

/* ---------- Admin dashboard ---------- */
.shell--wide { max-width: 1100px; }
.table-wrap { overflow-x: auto; margin-top: 18px; }
#results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
#results-table th, #results-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#results-table th {
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#results-table .muted { color: var(--ink-faint); font-size: 0.8rem; }
#results-table tbody tr:hover { background: var(--accent-bg); }
