:root {
  color-scheme: light;
  --paper: #f4f2ec;
  --sheet: #fffefa;
  --ink: #1b2430;
  --ink-2: #4a5462;
  --muted: #6d7582;
  --rule: #dcd8cd;
  --rule-strong: #bdb7a8;
  --ink-accent: #1d4a6b;
  --accent-hover: #163a55;
  --accent-soft: #e6edf2;
  --focus: #2a78d6;

  /* chart roles (validated categorical slots 1 and 2) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e8e5dc;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Helvetica, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--ink-accent); }

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

/* ---------- masthead ---------- */
.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--sheet);
}
.masthead-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mark { width: 34px; height: 34px; flex: none; }
.masthead-text { display: flex; flex-direction: column; line-height: 1.25; }
.org { font-family: var(--serif); font-weight: 600; font-size: 1rem; letter-spacing: 0.005em; }
.dept { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.02em; }

/* ---------- sheet ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 16px 40px;
  outline: none;
}

.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(27, 36, 48, 0.03);
  animation: sheet-in 380ms cubic-bezier(.2,.7,.2,1) both;
}
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.formbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sheet-body { padding: 28px 24px 24px; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-accent);
  margin: 0 0 10px;
}

h1, h2 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 14px;
  letter-spacing: -0.005em;
}
h1 { font-size: clamp(1.7rem, 4.6vw, 2.3rem); }
h2 { font-size: clamp(1.25rem, 3.6vw, 1.55rem); }

.lede { color: var(--ink-2); margin: 0 0 20px; max-width: 58ch; }
.fine { font-size: 0.85rem; color: var(--muted); }

/* ---------- intro ---------- */
.meta-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 24px;
  font-size: 0.9rem;
}
.meta-table th, .meta-table td {
  text-align: left;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.meta-table th {
  width: 40%;
  font-weight: 500;
  color: var(--muted);
  padding-right: 12px;
}
.meta-table td { font-variant-numeric: tabular-nums; }

.instructions {
  border-left: 3px solid var(--ink-accent);
  background: var(--accent-soft);
  padding: 12px 16px;
  margin: 0 0 24px;
  font-size: 0.93rem;
  color: var(--ink-2);
  border-radius: 0 4px 4px 0;
}
.instructions p { margin: 0; }
.instructions p + p { margin-top: 6px; }

/* ---------- progress ---------- */
.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
  overflow: hidden;
  margin: 0 0 22px;
}
.progress i {
  display: block;
  height: 100%;
  background: var(--ink-accent);
  border-radius: 2px;
  transition: width 400ms ease-out;
}

/* ---------- question ---------- */
.q-number {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 0 0 8px;
}
.q-text {
  font-family: var(--serif);
  font-size: clamp(1.2rem, 3.4vw, 1.45rem);
  font-weight: 400;
  line-height: 1.35;
  margin: 0 0 8px;
}
.q-help { color: var(--muted); font-size: 0.88rem; margin: 0 0 18px; }
.q-head > .q-text:last-child { margin-bottom: 18px; }

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

.choices { display: flex; flex-direction: column; gap: 8px; }

.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  background: var(--sheet);
  cursor: pointer;
  transition: border-color 120ms, background-color 120ms;
  font-size: 0.98rem;
}
.choice:hover { border-color: var(--ink-accent); background: #fbfcfd; }
.choice input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 18px; height: 18px;
  margin: 0;
  border: 1.5px solid var(--rule-strong);
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-content: center;
  transition: border-color 120ms;
}
.choice input[type="checkbox"] { border-radius: 3px; }
.choice input::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-accent);
  transform: scale(0);
  transition: transform 120ms;
}
.choice input[type="checkbox"]::before {
  width: 10px; height: 10px;
  border-radius: 0;
  background: none;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  width: 5px; height: 10px;
  transform: rotate(45deg) scale(0);
  margin-top: -2px;
}
.choice input:checked { border-color: var(--ink-accent); }
.choice input[type="checkbox"]:checked { background: var(--ink-accent); }
.choice input:checked::before { transform: scale(1); }
.choice input[type="checkbox"]:checked::before { transform: rotate(45deg) scale(1); }
.choice input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice:has(input:checked) { border-color: var(--ink-accent); background: var(--accent-soft); }
.choice .code {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------- 1-10 scale ---------- */
.scale {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}
.scale label { position: relative; }
.scale input {
  position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer;
}
.scale span {
  display: grid;
  place-items: center;
  height: 48px;
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  background: var(--sheet);
  transition: background-color 120ms, border-color 120ms, color 120ms;
  cursor: pointer;
}
.scale label:hover span { border-color: var(--ink-accent); }
.scale input:checked + span { background: var(--ink-accent); border-color: var(--ink-accent); color: #fff; }
.scale input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.scale-anchors {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- faces ---------- */
.face-ref {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px dashed var(--rule-strong);
  border-radius: 6px;
  margin: 0 0 18px;
  width: fit-content;
  max-width: 100%;
  padding-right: 28px;
  background: #fbfaf6;
}
.face-ref img {
  width: 132px;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  flex: none;
  filter: grayscale(0.15);
}
.face-ref .ref-meta { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); line-height: 1.7; }
.face-ref .ref-meta strong { color: var(--ink); font-weight: 500; }

.faces {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.face {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--sheet);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 120ms, box-shadow 120ms, transform 160ms;
}
.face:hover:not(:disabled) { border-color: var(--ink-accent); transform: translateY(-1px); }
.face img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  filter: grayscale(0.15);
}
.face .face-label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
}
.face .face-name {
  display: block;
  padding: 0 9px 8px;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--ink-2);
  min-height: 0;
  opacity: 0;
  max-height: 0;
  transition: opacity 300ms, max-height 300ms;
}
.faces.revealed .face .face-name { opacity: 1; max-height: 4em; }
.face:disabled { cursor: default; }
.face.picked { border-color: var(--ink-accent); box-shadow: 0 0 0 2px var(--ink-accent); }
.faces.revealed .face.match .face-name { color: var(--ink); font-weight: 600; }
.face .tick { color: var(--ink-accent); font-weight: 500; }

.nav { flex-wrap: wrap; }
.nav .ack-slot { flex: 1 1 auto; }
.nav > .btn:last-child { margin-left: auto; }
.nav .ack-slot:empty { display: none; }
.ack {
  margin: 0;
  text-align: right;
  font-family: var(--serif);
  font-size: 1.1rem;
  animation: sheet-in 300ms both;
}
.ack .fine { display: block; font-family: var(--sans); margin-top: 2px; }

/* ---------- nav buttons ---------- */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
}
.btn {
  appearance: none;
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  border-radius: 5px;
  padding: 11px 20px;
  cursor: pointer;
  border: 1px solid var(--ink-accent);
  background: var(--ink-accent);
  color: #fff;
  transition: background-color 120ms, opacity 120ms;
  min-height: 44px;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--ink-accent); border-color: var(--rule-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--accent-soft); }
.btn.link { background: none; border-color: transparent; color: var(--muted); padding-left: 0; }
.btn.link:hover:not(:disabled) { background: none; color: var(--ink); }

/* ---------- processing ---------- */
.processing { text-align: center; padding: 48px 24px; }
.processing .bar {
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
  max-width: 320px;
  margin: 18px auto 12px;
}
.processing .bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink-accent);
  animation: fill 1.9s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes fill { to { width: 100%; } }
.processing .step { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); min-height: 1.4em; }

/* ---------- result ---------- */
.result-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 28px;
  align-items: end;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 20px;
}
.score-label { font-size: 0.85rem; color: var(--muted); margin: 0 0 2px; }
.score {
  font-family: var(--sans);
  font-weight: 600;
  font-size: clamp(3.4rem, 12vw, 4.6rem);
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0;
}
.score small { font-size: 0.38em; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.band {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--ink-accent);
  border: 1px solid #c9d6e0;
  margin-bottom: 8px;
}
.meter {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--accent-soft);
  overflow: hidden;
}
.meter i {
  position: absolute; inset: 0 auto 0 0;
  background: var(--ink-accent);
  border-radius: 4px;
  width: 0;
  transition: width 900ms cubic-bezier(.2,.7,.2,1);
}
.meter-scale {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 0.7rem; color: var(--muted);
  margin-top: 4px;
}

.interp h3, .nextsteps h3, .figure h3 {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}
.interp p { margin: 0 0 12px; max-width: 62ch; }
.interp { margin-bottom: 22px; }

.nextsteps { margin-bottom: 26px; }
.nextsteps ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  border-top: 1px solid var(--rule);
}
.nextsteps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 0.93rem;
}
.nextsteps li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  padding-top: 2px;
}

.figure { margin: 0 0 8px; }
.figure-title {
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 0 0 4px;
  line-height: 1.3;
}
.figure-sub { font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-text { font-family: var(--sans); font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .axis-title { font-family: var(--sans); font-size: 12px; fill: var(--ink-2); font-weight: 500; }
.chart .you-label { font-family: var(--sans); font-size: 13px; font-weight: 600; fill: var(--ink); }
.chart .stat-text { font-family: var(--mono); font-size: 12px; fill: var(--ink-2); }
.chart .pt { opacity: 0; animation: pt-in 260ms ease-out forwards; }
@keyframes pt-in { from { opacity: 0; } to { opacity: 1; } }
.chart .fit { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 900ms ease-out 200ms forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.chart .you { opacity: 0; animation: you-in 420ms cubic-bezier(.3,1.6,.5,1) forwards; transform-box: fill-box; transform-origin: center; }
@keyframes you-in { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: none; } }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 0.82rem;
  color: var(--ink-2);
  margin: 0 0 6px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend .line { width: 18px; height: 2px; border-radius: 1px; background: var(--ink-2); }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 6px 9px;
  border-radius: 4px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
  opacity: 0;
  transition: opacity 100ms;
  font-variant-numeric: tabular-nums;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 600; }

.caption { font-size: 0.8rem; color: var(--muted); margin: 10px 0 0; max-width: 64ch; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  align-items: center;
}
.toast { font-size: 0.85rem; color: var(--muted); }

.sig {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--muted);
}
.sig div { border-top: 1px solid var(--rule-strong); padding-top: 4px; }
.sig .scrawl { font-family: var(--serif); font-style: italic; font-size: 1.05rem; color: var(--ink-2); display: block; margin-bottom: -2px; }

.noscript { padding: 24px; }

.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;
}

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  body { font-size: 17px; }
  .masthead-inner, main { max-width: 1140px; }
  .masthead-inner { padding: 16px 24px; }
  main { padding: 28px 24px 40px; }
  .mark { width: 38px; height: 38px; }
  .org { font-size: 1.08rem; }

  .formbar { padding: 12px 40px; }
  .sheet-body { padding: 32px 40px 26px; }
  h1 { font-size: 2.55rem; }

  /* intro: title + instructions left, metadata right */
  .intro-grid {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    gap: 64px;
    align-items: start;
  }
  .intro-side .meta-table { margin: 4px 0 0; }
  .intro-main .instructions { margin-bottom: 0; }

  /* questions: question left, answers right */
  .progress { margin-bottom: 26px; }
  .q-layout {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 56px;
    align-items: start;
    min-height: 250px;
  }
  .q-text { font-size: 1.7rem; line-height: 1.3; }
  .q-help { margin-bottom: 0; }
  .choice { padding: 13px 16px; }
  .scale span { height: 56px; font-size: 1.1rem; }
  .q-multi .choices { gap: 6px; }
  .q-scale .q-body { align-self: center; }
  .q-scale .scale span { height: 64px; font-size: 1.2rem; }
  .q-multi .choice { padding: 9px 14px; font-size: 0.95rem; line-height: 1.4; }

  /* Q2: a police-lineup row, reference first */
  .q-layout.q-faces { grid-template-columns: minmax(0, 1fr); gap: 26px; min-height: 0; }
  .q-faces .q-head { max-width: 820px; }
  .lineup {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 4fr);
    gap: 28px;
    align-items: start;
  }
  .lineup .face-ref {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: auto;
    padding: 0;
    margin: 0;
    overflow: hidden;
    border-style: dashed;
  }
  .lineup .face-ref img { width: 100%; border-radius: 0; }
  .lineup .face-ref .ref-meta { padding: 7px 10px 9px; line-height: 1.6; font-size: 0.72rem; }
  .lineup .faces {
    border-left: 1px solid var(--rule);
    padding-left: 28px;
    gap: 14px;
  }

  .processing { padding: 120px 24px 130px; }

  /* report: score + interpretation + table left, chart right */
  .report-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 48px;
    align-items: start;
  }
  .report-side .nextsteps { margin-bottom: 0; }
  .result-head { gap: 8px 24px; }
  .figure-title { font-size: 1.3rem; }
  .chart .axis-text, .chart .axis-title, .chart .stat-text { font-size: 13px; }
  .chart .you-label { font-size: 14px; }
  .sig { margin-top: 32px; max-width: 640px; }
}

/* ---------- large desktop (1600+) ---------- */
@media (min-width: 1600px) {
  html { font-size: 18px; }
  body { font-size: 18px; }
  .masthead-inner, main { max-width: 1320px; }
  main { padding-top: max(40px, 5vh); }
  .formbar { padding: 14px 56px; font-size: 0.74rem; }
  .sheet-body { padding: 44px 56px 32px; }
  .q-layout { gap: 80px; min-height: 330px; }
  .intro-grid { gap: 88px; }
  .report-grid { gap: 72px; }
  .lineup { gap: 36px; }
  .lineup .faces { padding-left: 36px; gap: 18px; }
  .mark { width: 42px; height: 42px; }
}

/* ---------- single-column report: chart straight after the score ---------- */
@media (max-width: 959px) {
  .report-grid { display: flex; flex-direction: column; }
  .report-side { display: contents; }
  .result-head { order: 0; }
  .report-main { order: 1; margin-bottom: 24px; }
  .interp { order: 2; }
  .nextsteps { order: 3; }
}

/* ---------- phones ---------- */
@media (max-width: 560px) {
  main { padding: 16px 12px 28px; }
  .sheet-body { padding: 22px 16px 18px; }
  .formbar { padding: 8px 16px; }
  .faces { grid-template-columns: repeat(2, 1fr); }
  .face-ref img { width: 96px; }
  .scale { grid-template-columns: repeat(5, 1fr); }
  .scale span { height: 50px; }
  .result-head { grid-template-columns: auto 1fr; gap: 6px 18px; padding-bottom: 14px; margin-bottom: 16px; }
  .result-head .score { font-size: 3rem; }
  .result-head .band { font-size: 0.7rem; padding: 3px 8px; margin-bottom: 6px; }
  .sheet-body > .eyebrow { margin-bottom: 6px; }
  .sheet-body > h1 { font-size: 1.45rem; margin-bottom: 12px; }
  .figure-sub { margin-bottom: 8px; }
  .interp p, .nextsteps li { font-size: 0.88rem; }
  .nav .ack-slot { order: -1; flex-basis: 100%; }
  .ack { text-align: left; }
  .meta-table { font-size: 0.85rem; margin-bottom: 18px; }
  .meta-table th, .meta-table td { padding: 6px 0; }
  .meta-table th { width: 42%; }
  .lede { margin-bottom: 14px; }
  .org { font-size: 0.92rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
}
