/*
 * The TestSeat look for every page, kit pages and admin included. Uses only the tokens in brand.css: the form-green
 * band and ink for structure, graphite for what the learner does, the highlighter for the one next thing.
 * No external fonts or scripts (the CSP allows 'self' only); no inline styles. Phone first (360px wide).
 */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-wrap: break-word;
}
main { flex: 1 0 auto; }
main:focus { outline: none; }
img, svg { max-width: 100%; height: auto; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.25; margin: 0 0 0.6em; }
h1 { font-size: 1.625rem; letter-spacing: -0.015em; text-wrap: balance; }
h2 { font-size: 1.375rem; letter-spacing: -0.01em; text-wrap: balance; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
@media (min-width: 48rem) { h1 { font-size: 1.875rem; } }
p, ul, ol, dl, table { margin: 0 0 1rem; }
a { color: var(--form); text-underline-offset: 0.2em; text-decoration-thickness: 1.5px; }
a:hover { color: var(--brand-strong); text-decoration-thickness: 2.5px; }
::selection { background: var(--mark); color: var(--ink); }
input, textarea { caret-color: var(--form); }
strong { font-weight: 700; }
code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface-alt); padding: 0.1em 0.35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

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

.visually-hidden {
  position: absolute !important; 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: 1rem; top: -5rem; z-index: 100;
  background: var(--pencil); color: #fff; padding: 0.75rem 1rem; border-radius: var(--radius-small);
  font-weight: 700;
}
.skip-link:focus { top: 1rem; color: #fff; }

.muted { color: var(--ink-muted); }
.small { font-size: 1rem; }
.lead { font-size: 1.125rem; color: var(--ink-muted); max-width: 40rem; }
.eyebrow { font-size: 1rem; font-weight: 700; color: var(--ink-muted); margin-bottom: 0.35rem; }
.num { font-variant-numeric: tabular-nums; }
/* What a page is about (the exam, the error code), set under its heading in form ink. */
.context-line { margin: -0.3rem 0 0.9rem; font-size: 1rem; font-weight: 700; color: var(--form); }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 1rem; }
@media (min-width: 48rem) { .container { padding: 0 1.5rem; } }
.page { padding-top: 1.5rem; padding-bottom: 3rem; }
.page-narrow { max-width: var(--narrow); }
.section { padding-top: 2rem; padding-bottom: 2rem; }
.stack > * + * { margin-top: 1rem; }
.cluster { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }

/* ---------- Mode banner, header, footer ---------- */
.mode-banner {
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #f0dfb5;
  text-align: center; font-size: 1rem; font-weight: 600; padding: 0.35rem 1rem;
}
/* The band across the top of every page: the answer sheet's printed header. */
.site-header { background: var(--brand); color: var(--brand-contrast); position: relative; z-index: 20; }
.header-inner { display: flex; align-items: center; gap: 0.5rem; min-height: 64px; }
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem; margin-right: auto;
  font-weight: 800; font-size: 1.3125rem; letter-spacing: -0.015em; color: var(--brand-contrast); text-decoration: none;
  min-height: var(--tap);
}
.brand:hover { color: var(--brand-contrast); }
.brand-mark { width: 34px; height: 34px; flex: none; display: block; }
.brand-mark .mark-box { fill: var(--brand-contrast); }
.brand-mark .mark-check { fill: none; stroke: var(--brand); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.site-footer .brand-mark .mark-box { fill: var(--brand); }
.site-footer .brand-mark .mark-check { stroke: var(--brand-contrast); }
/* The name over "Practice tests": the line never drops below 16px and may wrap on a narrow phone. */
.brand-words { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-line { font-size: 1rem; font-weight: 600; letter-spacing: 0; color: #cfe8da; }

.site-nav ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; list-style: none; margin: 0; padding: 0; align-items: center; }
.site-nav a, .nav-button {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 0.25rem;
  color: inherit; text-decoration: none; font-weight: 600; font-size: 1.0625rem;
}
.site-header .site-nav a:hover, .site-header .nav-button:hover { color: var(--brand-contrast); text-decoration: underline; text-decoration-thickness: 2px; }
.site-nav a[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 3px; text-decoration-color: var(--mark); }
.nav-button { background: none; border: 0; cursor: pointer; font-family: inherit; }
.site-header :focus-visible { outline-color: var(--mark); }
.inline-form { display: inline; margin: 0; }

.site-footer { border-top: 1px solid var(--form-rule); background: var(--surface); margin-top: 2.5rem; color: var(--ink-muted); font-size: 1rem; }
.footer-inner { padding-top: 1.75rem; padding-bottom: 2rem; }
.footer-inner p { margin: 0 0 0.75rem; }
.footer-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; list-style: none; margin: 0 0 1.25rem; padding: 0; }
@media (min-width: 40rem) { .footer-links { display: flex; flex-wrap: wrap; gap: 0 1.5rem; } }
.footer-links a, .footer-support a { color: var(--ink); display: inline-flex; align-items: center; min-height: var(--tap); }
.footer-links a:hover, .footer-support a:hover { color: var(--form); }
.footer-brand { color: var(--ink-muted); }

/* ---------- Kit marketing helpers (kept for kit pages) ---------- */
.hero { background: var(--surface); border-bottom: 1px solid var(--border); padding: 2rem 0; }
.hero-title { font-size: 1.75rem; max-width: 20em; }
.steps { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); list-style: none; padding: 0; }
.section-callout { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 2rem; }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--tap); padding: 0.6rem 1.25rem; border-radius: var(--radius);
  border: 2px solid transparent; font: inherit; font-size: 1.0625rem; font-weight: 700; line-height: 1.25;
  text-align: center; text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
}
/* The main button is graphite: the learner's pencil. It sits up off the sheet and presses down. */
.button-primary { background: var(--pencil); color: #fff; box-shadow: var(--shadow-press); }
.button-primary:hover { background: var(--pencil-hover); color: #fff; text-decoration: none; }
.button-primary:active { transform: translateY(2px); box-shadow: 0 0 0 rgb(0 0 0 / 22%), 0 2px 6px rgb(26 31 28 / 14%); }
.button-secondary { background: var(--surface); color: var(--ink); border-color: var(--pencil); }
.button-secondary:hover { background: var(--form-tint); color: var(--ink); text-decoration: none; }
.button-secondary:active { transform: translateY(1px); }
.button-danger { background: var(--bad); color: #fff; }
.button-danger:hover { background: #8f1c13; color: #fff; }
.button-link { background: none; border-color: transparent; color: var(--form); padding-left: 0; padding-right: 0; text-decoration: underline; }
.button-large, .button-main { min-height: var(--tap-main); font-size: 1.125rem; padding: 0.75rem 1.5rem; }
.button-main, .button-block { display: flex; width: 100%; }
@media (min-width: 40rem) { .button-main { max-width: 26rem; } }
.button[disabled], .button[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; box-shadow: none; transform: none; }
.button-sub { display: block; font-size: 1rem; font-weight: 500; opacity: 0.86; }
.button-stack { flex-direction: column; gap: 0.1rem; }
.button-note { margin-top: 0.5rem; color: var(--ink-muted); font-size: 1rem; }

/* ---------- Forms ---------- */
form { margin: 0 0 1rem; }
.field { margin-bottom: 1.25rem; }
.field label { display: block; font-weight: 700; margin-bottom: 0.35rem; }
.optional { font-weight: 400; color: var(--ink-muted); }
.hint { color: var(--ink-muted); font-size: 1rem; margin: -0.1rem 0 0.45rem; }
.field-error { color: var(--bad); font-weight: 700; font-size: 1rem; margin: 0 0 0.45rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"],
input[type="tel"], input[type="search"], input[type="date"], select, textarea {
  display: block; width: 100%; min-height: var(--tap); padding: 0.6rem 0.8rem;
  font: inherit; font-size: 1.125rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-small);
}
textarea { min-height: 7rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--form); outline-offset: 1px; border-color: var(--form); }
.field-invalid input, .field-invalid select, .field-invalid textarea { border: 2px solid var(--bad); }
.field-check { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.7rem; align-items: start; }
.field-check input { width: 1.5rem; height: 1.5rem; margin: 0.1rem 0 0; accent-color: var(--pencil); }
.field-check label { font-weight: 400; margin: 0; }
.field-check .hint, .field-check .field-error { grid-column: 2; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-small); padding: 1rem; margin: 0 0 1.25rem; }
legend { font-weight: 700; padding: 0 0.25rem; }
.form-errors-title { font-size: 1.125rem; margin-bottom: 0.4rem; }
.form-errors ul { margin: 0; padding-left: 1.2rem; }
.form-errors a { color: var(--bad); font-weight: 600; }

/* ---------- Cards, alerts, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card > :last-child { margin-bottom: 0; }
.card-title { font-size: 1.25rem; }
.card-form { padding: 1.5rem 1.25rem; }
@media (min-width: 30rem) { .card-form { padding: 2rem; } }
.card-form .button-primary, .card-form .button-secondary, .card-form .button-danger { width: 100%; min-height: var(--tap-main); }

.flashes { margin-bottom: 1.25rem; }
.alert { border-radius: var(--radius-small); padding: 0.85rem 1rem; margin-bottom: 0.75rem; border: 1px solid; font-size: 1.0625rem; }
.alert > :last-child { margin-bottom: 0; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.alert-success { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.alert-error { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.alert a { color: inherit; font-weight: 700; }

.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: var(--radius-pill); font-size: 1rem; font-weight: 700; line-height: 1.5; white-space: nowrap; vertical-align: middle; }
.badge-neutral { background: var(--slate-bg); color: var(--slate); }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

.empty-state { text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem 1.25rem; color: var(--ink-muted); }
.empty-title { font-size: 1.25rem; color: var(--ink); }

.error-page { max-width: var(--narrow); padding: 1.5rem 0; }

/* ---------- Tables and detail lists ---------- */
.table-wrap { width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: 1rem; }
th, td { text-align: left; padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-alt); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
caption { text-align: left; font-weight: 700; padding: 0.6rem 0.85rem; }

.detail-list { margin: 0; }
.detail-list > div { display: grid; grid-template-columns: minmax(7rem, 40%) 1fr; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--ink-muted); font-weight: 600; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }
.pagination a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 0.5rem; }
.pagination-current { color: var(--ink-muted); }

/* ---------- Stat cards (admin) ---------- */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); margin-bottom: 2rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--border-strong); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat p { margin: 0; }
.stat-title { color: var(--ink-muted); font-weight: 600; font-size: 1rem; }
.stat-value { font-size: 1.75rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat-detail { color: var(--ink-muted); font-size: 1rem; }
.stat-link { margin-top: 0.4rem !important; font-size: 1rem; }
.stat-good { border-top-color: var(--good); }
.stat-warn { border-top-color: #b7791f; }
.stat-bad { border-top-color: var(--bad); }

/* ---------- Admin shell ---------- */
.admin-shell { display: grid; gap: 1.5rem; padding-top: 1.5rem; padding-bottom: 3rem; }
@media (min-width: 56rem) { .admin-shell { grid-template-columns: 14rem 1fr; align-items: start; } }
.admin .container { max-width: 80rem; }
.admin-nav { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; }
.admin-nav-title { font-size: 1rem; font-weight: 700; color: var(--ink-muted); margin: 0.25rem 0.5rem 0.5rem; }
.admin-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; }
@media (min-width: 56rem) { .admin-nav ul { flex-direction: column; } }
.admin-nav a { display: flex; align-items: center; min-height: var(--tap); padding: 0 0.75rem; border-radius: var(--radius-small); color: var(--ink); text-decoration: none; font-weight: 600; }
.admin-nav a:hover { background: var(--surface-alt); color: var(--form); }
.admin-nav a[aria-current="page"] { background: var(--pencil); color: #fff; }
.admin-content { min-width: 0; }

/* ---------- Answer-sheet bubbles: the unit of progress ----------
 * .bub is an empty bubble printed in form ink. Filled with graphite it is something the learner did (.bub-filled);
 * green with a check it is right or done (.bub-right); graphite with a cross it is a wrong answer (.bub-wrong,
 * never red); ringed in highlighter it is the one next thing (.bub-next). .bub-new fills in once, like a pencil
 * stroke, on the bubble that just changed. Sizes: default 1.375rem, -sm, -lg. Text inside (a letter, a number) is
 * printed in form ink until the bubble is filled. */
.bub {
  --bub: 1.375rem;
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--bub); height: var(--bub); border-radius: 50%;
  border: 2px solid var(--form-line); background: var(--surface); color: var(--form);
  font-size: calc(var(--bub) * 0.5); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
.bub-sm { --bub: 1.125rem; }
.bub-lg { --bub: 2.25rem; font-size: 1rem; }
.bub-xl { --bub: 2.75rem; font-size: 1.125rem; }
.bub-filled, .bub-wrong { background: var(--pencil); border-color: var(--pencil); color: #fff; }
.bub-right { background: var(--good); border-color: var(--good); color: #fff; }
.bub-right::after {
  content: ""; width: calc(var(--bub) * 0.22); height: calc(var(--bub) * 0.42); margin-top: calc(var(--bub) * -0.08);
  border: solid #fff; border-width: 0 max(2px, calc(var(--bub) * 0.1)) max(2px, calc(var(--bub) * 0.1)) 0;
  transform: rotate(45deg);
}
.bub-wrong::before, .bub-wrong::after {
  content: ""; position: absolute; width: calc(var(--bub) * 0.5); height: max(2px, calc(var(--bub) * 0.1));
  background: #fff; border-radius: 1px; transform: rotate(45deg);
}
.bub-wrong::after { transform: rotate(-45deg); }
.bub-right, .bub-wrong, .bub-filled { font-size: 0; }
.bub-next { border-color: var(--pencil); box-shadow: 0 0 0 4px var(--mark); }
.bub-new { animation: bub-fill 0.5s var(--ease-out) both; }
@keyframes bub-fill {
  from { transform: scale(0.6); box-shadow: 0 0 0 0 var(--mark); }
  60% { transform: scale(1.12); box-shadow: 0 0 0 6px var(--mark-soft); }
  to { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}

/* A row of bubbles: today's questions, a check's questions. */
.bub-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; padding: 0; list-style: none; }
.bub-row-tight { gap: 0.22rem; }

/* The last seven days, today last. */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.25rem; margin: 0; padding: 0; list-style: none; max-width: 22rem; }
.week-day { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; }
.week-label { font-size: 1rem; line-height: 1; color: var(--ink-muted); }
.week-day.is-today .week-label { color: var(--ink); font-weight: 800; }

/* The road to Ready: five stops on one printed line, the current one highlighted. */
.road { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.road-stop { position: relative; display: grid; grid-template-columns: 2.25rem 1fr; gap: 0 0.85rem; padding-bottom: 1.1rem; }
.road-stop:last-child { padding-bottom: 0; }
.road-stop::before {
  content: ""; position: absolute; left: calc(1.125rem - 1.5px); top: 2.25rem; bottom: 0; width: 3px;
  background: var(--form-rule); border-radius: 2px;
}
.road-stop:last-child::before { display: none; }
.road-stop.is-done::before { background: var(--good); }
.road-stop .bub { grid-row: span 2; }
.road-name { display: block; font-weight: 700; line-height: 1.3; padding-top: 0.35rem; }
.road-detail { display: block; color: var(--ink-muted); font-size: 1rem; line-height: 1.4; margin-top: 0.15rem; }
.road-stop.is-current .road-name { background: linear-gradient(transparent 55%, var(--mark) 55%, var(--mark) 92%, transparent 92%); width: fit-content; }
.road-stop.is-done .road-name { color: var(--ink); }
.road-lock { display: inline-block; margin-top: 0.25rem; font-size: 1rem; font-weight: 700; color: var(--ink-muted); }

/* The road folded into one line (crew page). */
.road-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; }
.road-strip-bubs { display: flex; align-items: center; gap: 0; margin: 0; padding: 0; list-style: none; }
.road-strip-bubs .bub + .bub { margin-left: 0.85rem; }
.road-strip-bubs .bub + .bub::before {
  content: ""; position: absolute; right: calc(100% + 2px); top: 50%; width: calc(0.85rem - 4px); height: 2px;
  background: var(--form-rule); transform: translateY(-50%);
}
.road-strip-bubs .bub-right + .bub::before { background: var(--good); }
.road-strip-text { margin: 0; font-size: 1rem; font-weight: 700; }

/* A sheet: a white panel printed with a hairline in form ink. */
.sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1rem; }
.sheet > :last-child { margin-bottom: 0; }
@media (min-width: 30rem) { .sheet { padding: 1.25rem 1.25rem; } }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; margin: 0 0 0.6rem; }
.sheet-title { font-size: 1.125rem; font-weight: 800; margin: 0; }
.sheet-note { font-size: 1rem; color: var(--ink-muted); margin: 0; }
.rule-line { border: 0; border-top: 1px solid var(--form-rule); margin: 1rem 0; }

/* ---------- Motion and print ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .site-header, .site-footer, .mode-banner, .admin-nav, .skip-link { display: none; }
  body { background: #fff; }
  a { color: inherit; }
}
