/*
  Color system (see README "Design rationale" for sources)
  60% neutral  --paper / --surface     calm, low-stimulation background
  30% ink      --ink / --muted / --line structure, text, borders
  10% accent   --accent                 only for the main action, selections, progress, focus
  A small warm "completing" touch: --warm, used only in the brand mark and the thank-you mark.
  State colors are always paired with an icon and text, never color alone.
  All text pairs meet WCAG AA (4.5:1); borders and controls meet 3:1.
*/
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/ahn-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/ahn-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #F3F5F9;
  --surface: #FFFFFF;
  --ink: #17213A;
  --muted: #535E73;
  --line: #DCE2EC;
  --control: #7C8598;
  --accent: #2E4CC0;
  --accent-strong: #233B9A;
  --accent-tint: #E9EEFB;
  --warm: #E0A23A;
  --error: #B3261E;
  --error-tint: #FCEEEC;
  --success: #1D7A4F;

  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.625rem;
  --step-3: clamp(1.875rem, 1.4rem + 2.2vw, 2.625rem);

  --radius-panel: 16px;
  --radius-control: 10px;
  --measure: 62rem;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.55;
}

.wrap {
  width: 100%;
  max-width: calc(var(--measure) + 3rem);
  margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0 0 1rem; }

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--accent);
  color: #fff;
  padding: .5rem 1rem;
  border-radius: var(--radius-control);
  z-index: 10;
}
.skip:focus { top: 1rem; }

/* ---------- Masthead ---------- */
.masthead { padding: 3rem 0 1.75rem; }

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: var(--step--1);
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warm);
  border: 2px solid var(--paper);
}

.masthead h1 {
  font-size: var(--step-3);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: .75rem;
}
.lede { color: var(--muted); max-width: 48rem; margin: 0; }

/* ---------- Stepper (a real 4-part sequence) ---------- */
.stepper {
  list-style: none;
  margin: 2rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
}
.stepper li {
  font-size: var(--step--1);
  color: var(--muted);
  padding-top: .65rem;
  border-top: 4px solid var(--line);
}
.stepper .num { font-weight: 700; margin-right: .35rem; }
.stepper li[aria-current="step"] { color: var(--ink); border-top-color: var(--accent); font-weight: 700; }
.stepper li.done { border-top-color: var(--accent); }
.stepper li.done .num::after { content: " ✓"; color: var(--accent); }
.stepper .name { display: inline; }

@media (max-width: 560px) {
  .stepper { display: flex; gap: .4rem; }
  .stepper li { flex: none; min-width: 2.25rem; }
  /* the current part takes the free space; a long name wraps beside its number, not under it */
  .stepper li[aria-current="step"] { flex: 1; min-width: 0; display: flex; }
  .stepper li[aria-current="step"] .num { flex: none; }
  .stepper .name { display: none; }
  .stepper li[aria-current="step"] .name { display: inline; }
}

/* ---------- Panels and sections ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.panel h2, .section-head h2 { font-size: var(--step-2); margin-bottom: .75rem; }

/* ---------- Consent-step illustration (same art as the flyer) ---------- */
.hero-art {
  margin: -2rem -2rem 1.75rem;
  aspect-ratio: 794 / 470; /* reserves the space: no layout shift */
  overflow: hidden;
  border-radius: calc(var(--radius-panel) - 1px) calc(var(--radius-panel) - 1px) 0 0;
  background: var(--ink); /* the art's own backdrop, shown while it paints */
}
.hero-art svg { display: block; width: 100%; height: 100%; }
.hero-art text { font-family: var(--font); }

/* The one motion moment: draw the path from the issue to the right file. */
@media (prefers-reduced-motion: no-preference) {
  .hero-art .route {
    stroke-dasharray: 1;
    animation: route-draw 1.6s ease-out .3s both;
  }
  .hero-art .route-dot { animation: fade-in .2s ease-out both; }
  .hero-art .route-dot-1 { animation-delay: .53s; }
  .hero-art .route-dot-2 { animation-delay: .8s; }
  .hero-art .route-dot-3 { animation-delay: 1.07s; }
  .hero-art .route-dot-4 { animation-delay: 1.45s; }
  .hero-art .target { animation: fade-in .45s ease-out 1.9s both; }
  .hero-art.played * { animation: none; }
}
@keyframes route-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: var(--accent-tint);
  border-radius: var(--radius-control);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.notice p { margin: 0; font-weight: 700; }
.notice-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .9rem; }
.notice-actions .btn-primary { margin-left: 0; }

.facts { margin: 1.5rem 0; display: grid; gap: .9rem; }
.facts div { display: grid; grid-template-columns: 7.5rem 1fr; gap: 1rem; }
.facts dt { font-weight: 700; }
.facts dd { margin: 0; color: var(--muted); }
@media (max-width: 560px) {
  /* label and text share a line, so the consent box is reached sooner */
  .facts { gap: .6rem; margin: 1.25rem 0; }
  .facts div { display: block; }
  .facts dt, .facts dd { display: inline; }
  .facts dt { margin-right: .4rem; }
}

.section-head { margin: .5rem 0 1.25rem; }
.section-head .section-progress {
  color: var(--accent);
  font-size: var(--step--1);
  font-weight: 700;
  margin: -.35rem 0 .5rem;
}
.section-head p { color: var(--muted); margin: 0; }

.question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 1.5rem;
  margin: 0 0 1rem;
  min-width: 0;
}
.question.has-error { border-color: var(--error); box-shadow: inset 4px 0 0 var(--error); }

.question legend, .question .q-label {
  float: left;
  width: 100%;
  padding: 0;
  font-size: var(--step-1);
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: .35rem;
}
.question legend + * { clear: both; }
.q-num { color: var(--accent); margin-right: .4rem; }
.q-hint { color: var(--muted); font-size: var(--step--1); margin: 0 0 1rem; clear: both; }
.optional { font-weight: 400; color: var(--muted); font-size: var(--step--1); }

/* ---------- Choice options ---------- */
.options { display: grid; gap: .5rem; clear: both; }

.option {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: border-color .12s, background-color .12s;
}
.option:hover { border-color: var(--control); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.option:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.option label { cursor: inherit; flex: 1; }
.option label::before { content: ""; position: absolute; inset: 0; } /* stretch the hit area to the row */

/* custom radio / checkbox, 3:1 border contrast */
.box, .dot {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 1.3rem;
  height: 1.3rem;
  margin: .15rem 0 0;
  border: 2px solid var(--control);
  background: var(--surface);
  display: grid;
  place-content: center;
  cursor: inherit;
}
.box { border-radius: 5px; }
.dot { border-radius: 50%; }
.box:checked, .dot:checked { border-color: var(--accent); background: var(--accent); }
.box:checked::after {
  content: "";
  width: .38rem;
  height: .7rem;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg);
}
.dot:checked::after {
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: #fff;
}

.other-input { margin: .25rem 0 0 2.95rem; }
.text-input, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--control);
  border-radius: var(--radius-control);
  padding: .65rem .8rem;
}
textarea { min-height: 7.5rem; resize: vertical; line-height: 1.5; }
.counter { font-size: var(--step--1); color: var(--muted); margin: .5rem 0 0; }

/* ---------- 5-point scale: the one bold control ---------- */
.scale { clear: both; }
.scale-keys {
  margin-top: .75rem;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
}
.scale-key { position: relative; }
.scale-key input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; left: 50%; top: 50%; pointer-events: none; }
.scale-key label {
  display: grid;
  place-items: center;
  height: 3.25rem;
  border: 2px solid var(--control);
  border-radius: var(--radius-control);
  font-weight: 700;
  font-size: var(--step-1);
  cursor: pointer;
  background: var(--surface);
  transition: background-color .12s, border-color .12s, color .12s;
}
.scale-key input:hover + label { border-color: var(--accent); }
.scale-key input:checked + label { background: var(--accent); border-color: var(--accent); color: #fff; }
.scale-ends {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: var(--step--1);
  color: var(--muted);
  margin-top: .5rem;
}
.scale-readout { font-size: var(--step--1); color: var(--ink); margin: .6rem 0 0; min-height: 1.4em; }
.scale-readout strong { color: var(--accent); }

/* ---------- Errors ---------- */
.field-error {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--error);
  font-size: var(--step--1);
  font-weight: 700;
  margin: .75rem 0 0;
  clear: both;
}
.err-icon {
  display: inline-grid;
  place-items: center;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: var(--error);
  color: #fff;
  font-size: .75rem;
  flex: none;
}
.error-summary {
  border: 2px solid var(--error);
  background: var(--error-tint);
  border-radius: var(--radius-panel);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.error-summary h2 { font-size: var(--step-0); margin-bottom: .4rem; }
.error-summary ul { margin: 0; padding-left: 1.2rem; }
.error-summary a { color: var(--error); font-weight: 700; }
.submit-error {
  color: var(--error);
  font-weight: 700;
  border-left: 4px solid var(--error);
  padding: .25rem 0 .25rem .75rem;
}

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0 calc(3rem + env(safe-area-inset-bottom));
}
.panel .actions { margin-bottom: 0; justify-content: flex-start; }
.btn {
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius-control);
  padding: .8rem 1.4rem;
  cursor: pointer;
  border: 2px solid transparent;
  min-height: 3rem;
}
.btn-primary { background: var(--accent); color: #fff; margin-left: auto; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary[aria-busy="true"] { opacity: .8; cursor: progress; }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--control); }
.btn-quiet:hover { border-color: var(--ink); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #8F1E18; }

.consent { position: relative; display: flex; gap: .75rem; align-items: flex-start; margin-top: 1.5rem; padding: .5rem 0; }
.consent label { font-weight: 700; cursor: pointer; }
.consent label::before { content: ""; position: absolute; inset: 0; } /* the whole row toggles */
.option input, .consent input { position: relative; z-index: 1; } /* the control itself stays clickable above the stretched label */

/* ---------- Thank-you ---------- */
.thanks { text-align: left; }
.thanks-mark {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--accent);
  margin-bottom: 1.25rem;
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 9px var(--warm);
}
.thanks-mark::after {
  content: "";
  width: .7rem;
  height: 1.3rem;
  border: solid #fff;
  border-width: 0 4px 4px 0;
  transform: translateY(-2px) rotate(45deg);
}
.muted { color: var(--muted); }
.share { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: 1.5rem; }
.share h3 { font-size: var(--step-1); margin-bottom: .9rem; }
.share-status { font-size: var(--step--1); color: var(--success); font-weight: 700; margin: .75rem 0 0; min-height: 1.4em; overflow-wrap: anywhere; }

/* ---------- Misc ---------- */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.foot { color: var(--muted); font-size: var(--step--1); padding-bottom: calc(2.5rem + env(safe-area-inset-bottom)); }

/* Visible keyboard focus everywhere */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.scale-key input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 3px; }
.option:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.option input:focus-visible { outline: none; }

@media (max-width: 640px) {
  .masthead { padding-top: 2rem; }
  .brand { justify-content: center; text-align: center; }
  .panel, .question { padding: 1.25rem; }
  .hero-art {
    margin: -1.25rem -1.25rem 1.25rem;
    /* Crop from the right, keeping the issue tag, the three students and
       their speech bubble (the left 520 of 794 units) whole. */
    aspect-ratio: 520 / 470;
    max-height: 38vh;
  }
  .scale-key label { height: 3rem; }
  .question legend, .question .q-label { font-size: 1.125rem; }
  .foot, .foot p { text-align: center; }

  /* Full-width start button on mobile only */
  #intro .actions { width: 100%; }
  #start { width: 100%; margin: 0; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
