/* ---------------------------------------------------------------------------
   Tokens
   Pale sage paper, ink, one deep green for "the path". Calm enough for an honest
   answer at 11pm on a phone, which is where most of these get filled in.
--------------------------------------------------------------------------- */
:root {
  --paper: #ecf0ea;
  --surface: #f8faf6;
  --ink: #1a1f1c;
  --ink-2: #414a44;
  --muted: #5a645d;
  --line: #d3dad1;
  --line-strong: #b2bdb1;
  --accent: #1d5547;
  --accent-ink: #f8faf6;
  --accent-hover: #164539;
  --accent-tint: #dbe8df;
  --accent-tint-strong: #c4d9cb;
  --error: #9e3a2c;
  --error-tint: #f6e4df;

  --serif: 'Fraunces Variable', 'Iowan Old Style', Georgia, serif;
  --sans: 'Instrument Sans Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --r-sm: 8px;
  --r: 12px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --col: 40rem;
  --pad: clamp(1.25rem, 5vw, 2rem);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--line-strong) var(--paper);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--accent);
}

::selection { background: var(--accent-tint-strong); color: var(--ink); }

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 20;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--r-sm);
  text-decoration: none;
}
.skip:focus { top: 1rem; }

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

main { outline: none; }

/* ---------------------------------------------------------------------------
   Progress: a single line that fills as you go. This is the one moving thing.
--------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
}
.topbar-inner {
  max-width: calc(var(--col) + 2 * var(--pad));
  margin: 0 auto;
  padding: 1rem var(--pad) 0.9rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.count {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 3.2em;
}
.track {
  flex: 1;
  height: 3px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.track-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 500ms var(--ease-out);
}

/* ---------------------------------------------------------------------------
   Screens
--------------------------------------------------------------------------- */
.stage {
  max-width: calc(var(--col) + 2 * var(--pad));
  margin: 0 auto;
  padding: 0 var(--pad);
}

.screen {
  padding: clamp(2rem, 7vh, 4.5rem) 0 8rem;
}
.screen.is-entering {
  animation: screen-in 260ms var(--ease-out) both;
}
.screen.is-entering.from-back { animation-name: screen-in-back; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); filter: blur(2px); }
  to   { opacity: 1; transform: none; filter: none; }
}
@keyframes screen-in-back {
  from { opacity: 0; transform: translateY(-10px); filter: blur(2px); }
  to   { opacity: 1; transform: none; filter: none; }
}

.title {
  font-family: var(--serif);
  font-weight: 460;
  font-size: clamp(1.65rem, 1.1rem + 2.4vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
  margin: 0 0 0.6rem;
  outline: none;
}

.lede {
  font-size: 1.125rem;
  color: var(--ink-2);
  max-width: 34rem;
  margin: 0 0 2rem;
  text-wrap: pretty;
}

.field { margin-top: 2rem; }
.field:first-of-type { margin-top: 1.75rem; }

.field-label {
  display: block;
  font-weight: 600;
  font-size: 1.0625rem;
  margin: 0 0 0.35rem;
}
.field-hint {
  display: block;
  font-size: 0.9375rem;
  color: var(--muted);
  margin: 0 0 0.85rem;
}
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* ---------------------------------------------------------------------------
   Choices (radio / checkbox rows)
--------------------------------------------------------------------------- */
.choices {
  display: grid;
  gap: 0.5rem;
}
@media (min-width: 640px) {
  .choices.two-col { grid-template-columns: 1fr 1fr; }
}

.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 3.25rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  user-select: none;
  line-height: 1.35;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 140ms var(--ease-out);
}
.choice:active { transform: scale(0.985); }
@media (hover: hover) and (pointer: fine) {
  .choice:hover { border-color: var(--line-strong); }
}
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.choice:has(input:disabled) {
  opacity: 0.45;
  cursor: not-allowed;
}

.mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  transition: background-color 160ms ease, border-color 160ms ease;
}
.mark.box { border-radius: 5px; }
.mark.dot { border-radius: 50%; }
.mark svg {
  width: 0.8rem;
  height: 0.8rem;
  stroke: var(--accent-ink);
  stroke-width: 2.4;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 16;
  stroke-dashoffset: 16;
  transition: stroke-dashoffset 220ms var(--ease-out);
}
.mark.dot::after {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent-ink);
  transform: scale(0.4);
  opacity: 0;
  transition: transform 180ms var(--ease-out), opacity 120ms ease;
}
.choice:has(input:checked) .mark {
  background: var(--accent);
  border-color: var(--accent);
}
.choice:has(input:checked) .mark svg { stroke-dashoffset: 0; }
.choice:has(input:checked) .mark.dot::after { transform: none; opacity: 1; }

/* ---------------------------------------------------------------------------
   Scale (1–5, 1–10)
--------------------------------------------------------------------------- */
.scale {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 0.4rem;
}
@media (max-width: 559px) {
  .scale.long { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.scale .choice {
  justify-content: center;
  padding: 0;
  min-height: 3.25rem;
  font-size: 1.125rem;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
}
.scale .choice:has(input:checked) {
  background: var(--accent);
  color: var(--accent-ink);
}
.scale-ends {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.55rem;
  font-size: 0.875rem;
  color: var(--muted);
}
.scale-ends span:last-child { text-align: right; }

/* ---------------------------------------------------------------------------
   Matrix (question 5): one row per source, three-way segmented control
--------------------------------------------------------------------------- */
.matrix { display: grid; gap: 0.5rem; }
.matrix-row {
  display: grid;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.matrix-label {
  font-weight: 560;
  line-height: 1.35;
}
@media (min-width: 640px) {
  .matrix-row { grid-template-columns: 1fr auto; align-items: center; gap: 1rem; }
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.3rem;
}
@media (min-width: 640px) {
  .segmented { grid-template-columns: repeat(3, auto); }
}
.seg {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 0.9375rem;
  text-align: center;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  background: var(--paper);
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 140ms var(--ease-out);
}
.seg:active { transform: scale(0.97); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.empty-note {
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r);
  color: var(--ink-2);
  margin: 0;
}

/* ---------------------------------------------------------------------------
   Text inputs
--------------------------------------------------------------------------- */
.input, .textarea {
  width: 100%;
  font: inherit;
  font-size: 1.0625rem; /* ≥16px: no zoom on iOS */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 0.8rem 1rem;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.input::placeholder, .textarea::placeholder { color: #7a837c; }
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint-strong);
}
.textarea {
  min-height: 7.5rem;
  resize: vertical;
  line-height: 1.5;
}
.input-number-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.input-number-wrap .input {
  width: 8rem;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  padding: 0.65rem 1rem;
}
.input-number-wrap .suffix { color: var(--muted); font-size: 1.125rem; }

.counter {
  display: block;
  text-align: right;
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 0.3rem;
  min-height: 1.2em;
}

/* ---------------------------------------------------------------------------
   Errors
--------------------------------------------------------------------------- */
.error-msg {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.6rem 0 0;
  color: var(--error);
  font-size: 0.9375rem;
  font-weight: 520;
}
.error-msg svg { width: 1rem; height: 1rem; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.field.has-error .choice,
.field.has-error .input,
.field.has-error .matrix-row { border-color: color-mix(in srgb, var(--error) 55%, var(--line)); }
.field.has-error .error-msg { animation: nudge 260ms var(--ease-out); }
@keyframes nudge {
  0% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.banner {
  margin: 1.5rem 0 0;
  padding: 0.9rem 1.1rem;
  border-radius: var(--r);
  background: var(--error-tint);
  color: var(--error);
  font-weight: 520;
}

/* ---------------------------------------------------------------------------
   Navigation
--------------------------------------------------------------------------- */
.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner {
  max-width: calc(var(--col) + 2 * var(--pad));
  margin: 0 auto;
  padding: 0.75rem var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.nav-hint {
  display: none;
  font-size: 0.8125rem;
  color: var(--muted);
}
.nav-hint kbd {
  font-family: var(--sans);
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
}
@media (hover: hover) and (pointer: fine) and (min-width: 640px) {
  .nav-hint { display: inline; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0 1.4rem;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 1.1rem; height: 1.1rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 200ms var(--ease-out); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink-2); padding: 0 1rem; }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--accent-hover); }
  .btn-primary:hover svg { transform: translateX(2px); }
  .btn-ghost:hover { color: var(--ink); background: color-mix(in srgb, var(--line) 50%, transparent); }
}
.btn[disabled] { opacity: 0.6; cursor: progress; }
.btn-ghost[hidden] { display: inline-flex; visibility: hidden; }

.nav-right { display: flex; align-items: center; gap: 1rem; }

.spinner {
  width: 1rem; height: 1rem;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 559px) {
  .nav-right { flex: 1; justify-content: flex-end; }
  .btn-primary { flex: 1; max-width: 16rem; }
}

/* ---------------------------------------------------------------------------
   Intro & outro
--------------------------------------------------------------------------- */
.intro .title {
  font-size: clamp(2.25rem, 1.3rem + 4.4vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 420;
  max-width: 14ch;
  margin-bottom: 1.25rem;
}
.intro .title em {
  font-style: italic;
  color: var(--accent);
}
.facts {
  list-style: none;
  padding: 0;
  margin: 0 0 2.5rem;
  display: grid;
  gap: 0.75rem;
}
.facts li {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  color: var(--ink-2);
}
.facts svg {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.15rem;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.facts strong { color: var(--ink); font-weight: 600; }

.intro .btn-primary { min-height: 3.5rem; padding: 0 1.8rem; font-size: 1.0625rem; }
.fineprint { margin-top: 1.25rem; font-size: 0.875rem; color: var(--muted); max-width: 34rem; }
.text-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.text-link:hover { text-decoration-thickness: 2px; }

.done { padding-top: clamp(3rem, 14vh, 8rem); }
.done-mark {
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 1.5rem;
}
.done-mark circle {
  fill: var(--accent-tint);
  stroke: var(--accent);
  stroke-width: 1.5;
}
.done-mark path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: draw 520ms 160ms var(--ease-out) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ---------------------------------------------------------------------------
   Reduced motion: keep fades, drop movement
--------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .screen.is-entering, .screen.is-entering.from-back { animation: fade 160ms ease both; }
  .field.has-error .error-msg { animation: none; }
  .track-fill { transition: transform 1ms; }
  .choice, .seg, .btn { transition-property: background-color, border-color, color; }
  .choice:active, .seg:active, .btn:active { transform: none; }
  .done-mark path { animation: none; stroke-dashoffset: 0; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}
