/* Mobile-first styles for every page (design.md, Look and themes). Targets from the exam-taking
   spec: usable at 375px with no horizontal scroll, 16px minimum body text, 44px minimum tap
   targets. Colours are light-dark() pairs: the page follows the operating system, and
   <html data-theme> (static/js/theme.js) pins one theme. */

:root {
  color-scheme: light dark;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Cascadia Mono", "SF Mono", Menlo, Consolas,
    monospace;

  /* Surfaces, from the page behind everything to raised panels. */
  --bg: light-dark(#f4f6f9, #0e1219);
  --surface: light-dark(#ffffff, #161b24);
  --surface-2: light-dark(#f0f3f7, #1d2430);
  --surface-3: light-dark(#e5e9f0, #273041);
  --border: light-dark(#dde2ea, #2a3342);
  --border-strong: light-dark(#c3cad6, #3c4759);

  --text: light-dark(#172033, #e6eaf2);
  --text-muted: light-dark(#5a6478, #a3adbf);

  --accent: light-dark(#2f5bd3, #84a6ff);
  --accent-hover: light-dark(#244ab3, #a5beff);
  --accent-soft: light-dark(#eaf0fd, #1c2742);
  --accent-text: light-dark(#ffffff, #0b1226);

  --success: light-dark(#18794e, #4cc38a);
  --success-soft: light-dark(#e7f5ee, #11291f);
  --success-text: light-dark(#ffffff, #06231a);
  --warning: light-dark(#8a5a00, #e2b24c);
  --warning-soft: light-dark(#fdf3dc, #2e2610);
  --danger: light-dark(#c2311f, #ff8a7a);
  --danger-hover: light-dark(#a32617, #ffa598);
  --danger-soft: light-dark(#fdecea, #36191a);
  --danger-text: light-dark(#ffffff, #2a0a06);

  --focus: var(--accent);
  --shadow-sm: 0 1px 2px light-dark(rgb(16 24 40 / 6%), rgb(0 0 0 / 40%));
  --shadow:
    0 1px 3px light-dark(rgb(16 24 40 / 8%), rgb(0 0 0 / 45%)),
    0 6px 16px light-dark(rgb(16 24 40 / 5%), rgb(0 0 0 / 25%));

  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --gutter: 1rem;
  --tap: 44px;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font: 1rem/1.6 var(--font-body);
  color: var(--text);
  background: var(--bg);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  margin: 1.75em 0 0.5em;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 0;
}

h2 {
  font-size: 1.25rem;
  font-weight: 650;
}

h3 {
  font-size: 1.0625rem;
  font-weight: 650;
}

h4 {
  font-size: 1rem;
  font-weight: 650;
}

p,
ul,
ol {
  margin: 0 0 1em;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.container {
  width: 100%;
  max-width: 48rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container-wide {
  max-width: 76rem;
}

main.container {
  padding-block: 1.5rem 4rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Header ---------------------------------------------------------------------------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4rem;
}

.site-title {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  min-height: var(--tap);
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.site-title:hover {
  color: var(--text);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #8b5cf6));
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 1.125rem;
  height: 1.125rem;
}

.site-actions,
.site-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-nav form {
  margin: 0;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current] {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle {
  flex: none;
  width: var(--tap);
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: none;
}

.theme-toggle:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* The button needs theme.js, which sets data-theme; without it, it would do nothing. */
html:not([data-theme]) .theme-toggle,
:root[data-theme="dark"] .theme-toggle .icon-moon,
:root:not([data-theme="dark"]) .theme-toggle .icon-sun {
  display: none;
}

/* A phone with the admin link: the mark stands in for the name. */
@media (max-width: 26rem) {
  .site-header:has(.site-nav a) .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ---- Page furniture -------------------------------------------------------------------- */

.lede {
  max-width: 68ch;
  color: var(--text-muted);
  font-size: 1.0625rem;
}

.hint {
  color: var(--text-muted);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-bottom: 1.5rem;
}

.page-head h1,
.page-head p {
  margin-bottom: 0;
}

.page-head > div > p {
  margin-top: 0.375rem;
}

.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

.card {
  margin-block: 1.25rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card > :first-child,
.card > :first-child > :first-child {
  margin-top: 0;
}

.card > :last-child {
  margin-bottom: 0;
}

.card-grid {
  display: grid;
  gap: 1rem;
}

.card-grid > .card {
  margin: 0;
}

.card-grid-top {
  align-items: start;
}

.empty-state {
  margin-block: 1rem;
  padding: 1.75rem 1.25rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.empty-state > :last-child {
  margin-bottom: 0;
}

.empty-state strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text);
  font-size: 1.0625rem;
}

/* ---- Buttons --------------------------------------------------------------------------- */

/* Controls: 16px text so iOS Safari doesn't zoom on focus; 44px tap targets. */
button,
input,
select,
textarea {
  font: inherit;
  font-size: 1rem;
  color: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0.5rem 1.125rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s;
}

button:hover,
.button:hover {
  background: var(--accent-hover);
  color: var(--accent-text);
  text-decoration: none;
}

button:active,
.button:active {
  translate: 0 1px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  translate: none;
}

.button-secondary,
.button.button-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.button-secondary:hover,
.button.button-secondary:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-muted);
}

.button-danger {
  background: var(--danger);
  color: var(--danger-text);
}

.button-danger:hover {
  background: var(--danger-hover);
  color: var(--danger-text);
}

.button-danger-quiet {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}

.button-danger-quiet:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.button-small {
  padding-inline: 0.875rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.button-row form {
  margin: 0;
}

/* ---- Form controls --------------------------------------------------------------------- */

input:not([type="radio"], [type="checkbox"], [type="hidden"]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 2px light-dark(rgb(16 24 40 / 4%), rgb(0 0 0 / 25%));
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

input:not([type="radio"], [type="checkbox"], [type="hidden"]):hover,
select:hover,
textarea:hover {
  border-color: var(--text-muted);
}

input:not([type="radio"], [type="checkbox"], [type="hidden"]):focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

select:not([multiple]) {
  appearance: none;
  padding-right: 2.5rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 1.125rem) 50%,
    calc(100% - 0.8125rem) 50%;
  background-size: 0.3125rem 0.3125rem;
  background-repeat: no-repeat;
}

select[multiple] {
  padding: 0.25rem;
}

select[multiple] option {
  padding: 0.375rem 0.5rem;
  border-radius: 4px;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

input[type="radio"],
input[type="checkbox"] {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--accent);
}

label {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 600;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 0.5rem;
  padding: 0;
  font-weight: 600;
}

.field > .hint {
  margin: -0.125rem 0 0.5rem;
}

.field-narrow {
  max-width: 12rem;
}

/* Vertical rhythm for simple forms. */
.stack > * + * {
  margin-top: 1rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
  align-items: end;
}

.form-grid > * {
  margin: 0;
}

/* Choices as tappable cards: answer options, form radios, guide points to tick. */
.choice-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-height: var(--tap);
  margin-bottom: 0.5rem;
  padding: 0.6875rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 400;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.choice-option:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.choice-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.choice-option input {
  margin-top: 0.1875rem;
}

.choice-key {
  font-weight: 700;
  color: var(--accent);
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.75rem;
}

.choice-row .choice-option {
  flex: 1 1 14rem;
}

/* ---- Notices, pills, badges ------------------------------------------------------------ */

.notice {
  margin-block: 1rem;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.notice > :last-child {
  margin-bottom: 0;
}

.notice-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  border-left-color: var(--danger);
}

.notice-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  border-left-color: var(--success);
}

.pill,
.badge,
.status,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.0625rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

.tag {
  border-radius: 6px;
  font-weight: 500;
}

.tag code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.status::before {
  content: "";
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: currentcolor;
}

.pill-correct,
.status-approved,
.status-finished,
.status-marked {
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.badge,
.status-pending,
.status-running {
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
}

.status-failed,
.status-rejected {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-retired {
  color: var(--text-muted);
}

.pill-accent,
.status-admin {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-soft);
  color: var(--accent);
}

.status-running::before {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-running::before {
    animation: none;
  }
}

/* ---- Code and tables ------------------------------------------------------------------- */

/* Wide content scrolls inside itself so the page never scrolls sideways. */
/* Code keeps the 16px minimum: it is exam text, and a smaller input makes iOS zoom on focus. */
pre,
code,
kbd {
  font-family: var(--font-mono);
  font-size: 1em;
}

code {
  padding: 0.0625rem 0.3125rem;
  border-radius: 5px;
  background: var(--surface-2);
}

pre {
  overflow-x: auto;
  padding: 0.875rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.5;
  tab-size: 4;
}

pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.table-scroll {
  position: relative; /* keeps absolutely positioned content (.visually-hidden) inside the scroll */
  overflow-x: auto;
  margin-block: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

thead th {
  background: var(--surface-2);
  font-weight: 650;
}

/* Listings (pool, batches, allow-list, health, dashboard): a framed table with quiet headings,
   rows ruled, not boxed. */
.table-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
  padding: 0.6875rem 1rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table tbody tr:last-child > * {
  border-bottom: 0;
}

.data-table tbody tr:hover > * {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

.data-table tbody th {
  font-weight: 600;
}

.data-table .numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tr.low > * {
  background: color-mix(in srgb, var(--warning-soft) 70%, transparent);
}

.data-table tr.low:hover > * {
  background: var(--warning-soft);
}

td form {
  margin: 0;
}

.row-link {
  font-weight: 600;
  text-decoration: none;
}

.row-link:hover {
  text-decoration: underline;
}

/* ---- Questions and answer widgets: exam pages and the admin previews ------------------- */

pre.mermaid {
  overflow-x: auto;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  font-family: var(--font-body);
}

.question {
  margin-block: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.question h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.625rem;
  margin: 0 0 0.875rem;
  font-size: 1.125rem;
}

.marks {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
}

.stem > :last-child {
  margin-bottom: 0;
}

.stem table,
.case-study-body table,
.feedback table,
.advice-body table,
.guide table {
  display: block;
  overflow-x: auto;
  width: max-content;
  max-width: 100%;
  margin-bottom: 1em;
}

.answer {
  margin-top: 1rem;
}

.answer fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

textarea.code {
  font-family: var(--font-mono);
  white-space: pre;
  tab-size: 4;
  background: var(--surface-2);
}

.answer-table th,
.answer-table td {
  padding: 0.375rem 0.5rem;
}

.answer-table textarea {
  min-width: 10rem;
}

.answer-table .prefilled,
.answer-table .unused {
  background: var(--surface-2);
}

.answer-table .unused {
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 6px,
    color-mix(in srgb, var(--border) 60%, transparent) 6px 7px
  );
}

.widget-blanks {
  line-height: 2.4;
}

.widget-blanks input.blank {
  display: inline-block;
  width: 9em;
  vertical-align: middle;
}

.case-study {
  margin-bottom: 2rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.case-study summary {
  padding-block: 0.75rem;
  font-weight: 650;
  cursor: pointer;
}

.case-study[open] > summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.case-study-body {
  padding-bottom: 0.25rem;
}

figure {
  margin: 1.5rem 0;
}

figcaption {
  margin-bottom: 0.5rem;
  font-weight: 650;
}

/* Exam pages: a sticky bar with the navigator (and, on Section C, the case study), so both stay
   in reach while answering. Open panels scroll inside themselves. */
.exam-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -1.5rem calc(-1 * var(--gutter)) 1.5rem;
  padding: 0.5rem var(--gutter);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav-sections {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-section {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: var(--tap);
  padding: 0 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.nav-section:hover {
  border-color: var(--accent);
  color: var(--text);
}

.nav-section[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.nav-count {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.nav-submit {
  margin-left: auto;
}

.nav-submit .button {
  border-radius: 999px;
}

.nav-questions summary,
.exam-bar .case-study summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  font-weight: 600;
  cursor: pointer;
}

/* A flex summary loses the browser's disclosure triangle; draw one. */
.nav-questions summary::before,
.exam-bar .case-study summary::before {
  content: "▸";
  color: var(--text-muted);
}

.nav-questions[open] summary::before,
.exam-bar .case-study[open] summary::before {
  content: "▾";
}

.nav-panel,
.exam-bar .case-study-body {
  max-height: 55vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-heading {
  margin: 0.5rem 0 0.25rem;
  font-weight: 650;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tap), 1fr));
  gap: 0.375rem;
}

.nav-question {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}

.nav-question:hover {
  border-color: var(--accent);
  color: var(--text);
}

.nav-question[data-answered="true"] {
  background: var(--success);
  border-color: var(--success);
  color: var(--success-text);
}

.exam-bar .case-study {
  margin: 0.5rem 0 0;
  padding-inline: 0.875rem;
}

.exam-bar .case-study[open] > summary {
  margin-bottom: 0;
}

/* Jumps to a question land below the sticky bar. */
.question {
  scroll-margin-top: 9rem;
}

.save-state {
  min-height: 1.5rem;
  margin: 0.75rem 0 0;
  color: var(--text-muted);
}

.save-state[data-state="saved"] {
  color: var(--success);
}

.save-state[data-state="saved"]::before {
  content: "✓ " / "";
}

.save-state[data-state="error"] {
  color: var(--danger);
  font-weight: 600;
}

.exam-next {
  display: flex;
  justify-content: flex-end;
  margin-top: 2rem;
}

.abandon {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.abandon summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--danger);
  font-weight: 600;
  cursor: pointer;
}

.unanswered {
  padding: 0;
  list-style: none;
}

.unanswered li {
  display: inline-block;
  margin: 0 0.5rem 0.5rem 0;
}

.unanswered a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  text-decoration: none;
}

.unanswered a:hover {
  border-color: var(--accent);
}

/* ---- Admin ----------------------------------------------------------------------------- */

.admin-nav {
  display: flex;
  gap: 0.25rem;
  margin: -0.5rem 0 1.75rem;
  padding: 0.25rem;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}

.admin-nav a {
  display: inline-flex;
  flex: none;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.admin-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.admin-nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.stat {
  margin: 0;
  padding: 1rem 1.125rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stat strong,
.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--text-muted);
}

/* Results: one collapsible result per question (the per-question reveal), on the student's
   results page and the admin disputes page. */
.results-total {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  margin-block: 1rem 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  font-size: 1.125rem;
}

.results-total strong {
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

#results + p {
  margin-top: 1.5rem;
}

.results-progress {
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}

.results-section h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

.result {
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.result[open] {
  box-shadow: var(--shadow-sm);
}

.result > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  min-height: var(--tap);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius);
  font-weight: 650;
  cursor: pointer;
}

.result > summary:hover {
  background: var(--surface-2);
}

.result > summary::before {
  content: "▸";
  color: var(--text-muted);
}

.result[open] > summary::before {
  content: "▾";
}

.result > summary::-webkit-details-marker {
  display: none;
}

.result > summary {
  list-style: none;
}

.result-marks {
  margin-left: auto;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.result-failed .result-marks {
  color: var(--danger);
}

.result[open] > summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.result-body {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.result-body h3 {
  margin-top: 1.25rem;
  font-size: 1rem;
}

.result-body .guide {
  margin: 1.25rem 0 0;
}

.guide li.earned::after {
  content: " ✓" / " earned";
  color: var(--success);
  font-weight: 700;
}

.answer-text {
  padding: 0.625rem 0.875rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
}

.answer-blank {
  color: var(--text-muted);
  font-style: italic;
}

.answer-choice {
  padding: 0;
  list-style: none;
}

.answer-choice .option {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.answer-choice .chosen {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.answer-choice .correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.answer-choice .pill {
  margin-left: 0.25rem;
}

.blank-answer {
  padding: 0.0625rem 0.375rem;
  border-radius: 4px;
  background: var(--warning-soft);
  color: var(--text);
}

.points {
  padding-left: 1.25rem;
}

p.points {
  padding-left: 0;
  color: var(--text-muted);
}

.points-earned li::marker {
  color: var(--success);
}

.points-missed li::marker {
  color: var(--danger);
}

.feedback > :last-child {
  margin-bottom: 0;
}

.dispute {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
}

.dispute > :last-child {
  margin-bottom: 0;
}

.dispute blockquote,
.dispute-note blockquote {
  margin: 0.5rem 0 0;
  padding-left: 0.875rem;
  border-left: 3px solid var(--border-strong);
  font-style: italic;
  white-space: pre-wrap;
}

.dispute-panel {
  margin-top: 1.25rem;
}

.dispute-panel summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* not wider than the page, whatever is inside */
  gap: 2rem;
}

.review-preview > .question:first-child,
.review-preview > .case-study:first-child {
  margin-top: 0;
}

/* The marking guide: on its own in results, or attached under a question in admin previews. */
.guide {
  margin: 0 0 2rem;
  padding: 1rem 1.25rem;
  background: color-mix(in srgb, var(--success-soft) 70%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
  border-left: 4px solid var(--success);
  border-radius: var(--radius);
}

.question:has(+ .guide) {
  margin-bottom: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.question + .guide {
  border-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.guide h3 {
  margin-top: 0;
  color: var(--success);
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.guide h4 {
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
}

.guide > :last-child {
  margin-bottom: 0;
}

.guide-tags {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-left: 0;
  list-style: none;
}

/* The pool list: every column but the tags and the question stays on one line. */
.pool td:not(.pool-tags, :last-child) {
  white-space: nowrap;
}

.pool .pool-tags {
  min-width: 7.5rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.pool td:last-child {
  min-width: 16rem;
}

.review-details {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.375rem 1rem;
  margin: 0;
}

.review-details dt {
  color: var(--text-muted);
  font-weight: 600;
}

.review-details dd {
  margin: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.side-panel > .card {
  margin: 0;
}

.side-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.review-side form + form {
  margin-top: 0.75rem;
}

.kk-reference summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  font-weight: 600;
  cursor: pointer;
}

.batches td:not([colspan]) {
  white-space: nowrap;
}

.batches tr.batch:has(+ .batch-discards) > * {
  border-bottom: 0;
}

.batch-discards > td {
  padding-top: 0;
}

.batch-discards details summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.batch-discards ul {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.dispute-item {
  margin-block: 1.5rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.dispute-item-open {
  border-left: 4px solid var(--warning);
}

.dispute-item-failed {
  border-left: 4px solid var(--danger);
}

.dispute-item > h2 {
  margin-top: 0;
}

.dispute-item .result {
  margin-top: 1rem;
}

.raw-response {
  margin-top: 1rem;
}

.raw-response summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.raw-response pre {
  max-height: 24rem;
  font-size: 0.8125rem;
}

.dispute-actions {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---- Auth ------------------------------------------------------------------------------ */

.auth-card {
  max-width: 28rem;
  margin: 2rem auto 0;
  padding: 1.75rem 1.5rem;
}

.invite-card {
  max-width: 34rem;
}

.auth-card h1 {
  margin-bottom: 0.5rem;
}

.auth-card button[type="submit"] {
  width: 100%;
}

/* ---- The student dashboard ------------------------------------------------------------- */

.hero {
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin-bottom: 0.5rem;
}

.signed-in {
  color: var(--text-muted);
}

.exam-actions h2 {
  margin-top: 0;
}

.action-card p {
  color: var(--text-muted);
}

.action-card form,
.action-card .button-row {
  margin-top: auto;
}

.action-card {
  display: flex;
  flex-direction: column;
}

.action-card-primary {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background:
    linear-gradient(
      160deg,
      color-mix(in srgb, var(--accent-soft) 80%, transparent),
      transparent 70%
    ),
    var(--surface);
}

.progress {
  height: 0.5rem;
  margin: 0.75rem 0 1rem;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 999px;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.unseen ul {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 0;
  list-style: none;
}

.unseen li {
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  line-height: 1.35;
}

.unseen li strong {
  display: block;
  color: var(--text);
  font-size: 1.625rem;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.by-attempt {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.by-attempt li {
  padding: 0 0.5rem;
  background: var(--surface-2);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.rollup-table th[scope="row"] {
  font-weight: 400;
}

.rollup-table td,
.attempts-table td {
  white-space: nowrap;
}

.overall {
  font-variant-numeric: tabular-nums;
}

.meter {
  display: block;
  width: 7rem;
  height: 0.375rem;
  margin-top: 0.375rem;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 999px;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--danger);
  border-radius: inherit;
}

.meter-mid > span {
  background: var(--warning);
}

.meter-high > span {
  background: var(--success);
}

.advice-source {
  color: var(--text-muted);
}

.advice-body {
  padding: 0.25rem 1.25rem;
  border-left: 4px solid var(--accent);
}

.advice-body h3:first-child {
  margin-top: 0;
}

.attempts-table a,
.user-actions a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem 1rem;
}

.you {
  color: var(--text-muted);
}

.users td:first-child {
  font-weight: 600;
}

/* ---- Wider screens --------------------------------------------------------------------- */

@media (max-width: 30rem) {
  .unseen ul {
    grid-template-columns: minmax(0, 1fr);
  }

  .unseen li {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
  }

  .unseen li strong {
    display: inline;
    font-size: 1.25rem;
  }
}

@media (min-width: 40rem) {
  .card-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  }
}

@media (min-width: 48rem) {
  :root {
    --gutter: 1.5rem;
  }

  h1 {
    font-size: 1.875rem;
  }

  main.container {
    padding-block: 2rem 4rem;
  }

  .exam-bar {
    margin-top: -2rem;
  }

  .question {
    padding: 1.5rem;
  }

  .json-editor {
    font-size: 0.875rem;
  }
}

@media (min-width: 64rem) {
  .review-layout {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    align-items: start;
  }

  /* The editor stays in view beside a long pack; it scrolls itself if it is the taller. */
  .review-side {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}
