/* Kneaden — guided signup (Typeform-style, one idea per screen)
 * Visual system: ambient canvas · atmospheric wash · paper grain ·
 * viewport frame · receding-stack transitions.
 * Locked palette + type (Fraunces / Inter / Plus Jakarta Sans);
 * transform/opacity motion only.
 */

:root {
  --bg: #faf6f1;
  --ink: #1f1b16;
  --ink-soft: #4a4239;
  --ink-faint: #7a7066;
  --line: #d8cfc4;
  --card: #ffffff;
  /* Role accent — swapped by JS once a role is picked. */
  --accent: #1f1b16;
  --accent-strong: #1f1b16; /* AA-safe surface for white text */
  --accent-shadow: rgba(31, 27, 22, 0.25); /* hard offset shadow on buttons */
  --frame-color: rgba(31, 27, 22, 0.9); /* signature viewport frame */
  --wash-tint: rgba(31, 27, 22, 0.04); /* atmospheric wash, neutral default */
  --error: #b3261e;
  --step-ms: 320ms;
  --step-ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quart feel */
  --frame-w: 18px;
  --display-font: 'Fraunces', Georgia, serif;
}

body[data-role='baker'] {
  --accent: #c2410c;
  --accent-strong: #c2410c; /* white on #C2410C ≈ 6.2:1 */
  --accent-shadow: rgba(194, 65, 12, 0.25);
  --frame-color: #c2410c;
  --wash-tint: rgba(194, 65, 12, 0.05);
}

body[data-role='courier'] {
  --accent: #0d9488;
  --accent-strong: #115e59; /* white on #115E59 ≈ 5.9:1 (teal darkened for AA) */
  --accent-shadow: rgba(13, 148, 136, 0.25);
  --frame-color: #0d9488;
  --wash-tint: rgba(13, 148, 136, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    'Inter',
    system-ui,
    -apple-system,
    sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layer 0 · ambient canvas (living background) ---------- */

#ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ---------- layers 1–2 · atmospheric wash (lighting, not a blob) ---------- */

.wash,
.wash-accent {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.wash {
  z-index: 1;
  background: radial-gradient(60% 52% at 50% 42%, #f3e9de 0%, rgba(243, 233, 222, 0) 70%);
}

.wash-accent {
  z-index: 2;
  opacity: 0;
  background: radial-gradient(60% 52% at 50% 42%, var(--wash-tint) 0%, rgba(250, 246, 241, 0) 70%);
  transition: opacity 400ms ease-in-out;
}

body[data-role] .wash-accent {
  opacity: 1;
}

/* ---------- layer 3 · paper grain (kraft, not flat digital) ---------- */

.grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.04;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- layer 30 · viewport frame (signature device) ---------- */

.frame {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  border: var(--frame-w) solid var(--frame-color);
  transition: border-color 400ms ease-in-out;
}

/* ---------- chrome: progress bar + counter + back (inside the frame) ---------- */

.progress {
  position: fixed;
  top: var(--frame-w);
  left: var(--frame-w);
  right: var(--frame-w);
  height: 2px;
  background: var(--line);
  z-index: 10;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition:
    width 300ms var(--step-ease),
    background-color 400ms ease-in-out;
}

.chrome {
  position: fixed;
  top: calc(var(--frame-w) + 2px);
  left: var(--frame-w);
  right: var(--frame-w);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  z-index: 9;
}

.step-counter {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.back-btn {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px; /* ≥44px target with line-height */
  min-height: 44px;
  cursor: pointer;
  transition: border-color 200ms ease-out;
}

.back-btn:hover {
  border-color: var(--line);
}
.back-btn[hidden] {
  display: none;
}

/* ---------- stage & steps (padded clear of the frame) ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--frame-w) + 72px) calc(var(--frame-w) + 24px) calc(var(--frame-w) + 40px);
}

.step {
  display: none;
  width: 100%;
  max-width: 620px;
  max-height: 100%;
  overflow-y: auto;
}

/* Receding-stack illusion — transform/opacity only (GPU).
 * Forward: outgoing sinks up/back (scale 0.92, -24px), incoming rises from
 * 24px below at scale 0.98. Back navigation reverses both halves. */

.step.active {
  display: block;
  animation: stack-in var(--step-ms) var(--step-ease);
}

.step.leaving {
  display: block;
  animation: stack-out var(--step-ms) var(--step-ease) forwards;
}

.step.active-back {
  display: block;
  animation: stack-in-back var(--step-ms) var(--step-ease);
}

.step.leaving-back {
  display: block;
  animation: stack-out-back var(--step-ms) var(--step-ease) forwards;
}

@keyframes stack-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes stack-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-24px) scale(0.92);
  }
}

@keyframes stack-in-back {
  from {
    opacity: 0;
    transform: translateY(-24px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes stack-out-back {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
}

/* ---------- brand assets ---------- */

.brand-lockup {
  display: block;
  width: min(80vw, 520px);
  height: auto; /* intrinsic SVG ratio (9871:5314) — never distorted */
  margin: 0 0 22px;
}

.brand-line {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0 0 22px;
}

.success-mark {
  display: block;
  width: 64px;
  height: auto;
  margin: 0 0 18px;
}

/* ---------- typography ---------- */

h1,
h2 {
  font-family: var(--display-font);
  font-variation-settings: 'opsz' 144;
  font-weight: 400;
  font-size: clamp(2.25rem, 6vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 20px;
}

.lede {
  font-size: 19px;
  color: var(--ink-soft);
  margin: 0 0 14px;
}

.body-copy {
  color: var(--ink-soft);
  margin: 0 0 14px;
}

.fine {
  font-size: 14px;
  color: var(--ink-faint);
  margin: 0 0 28px;
}

/* ---------- buttons & hints ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: #ffffff;
  background: var(--accent-strong);
  border: none;
  border-radius: 10px;
  padding: 14px 26px;
  min-height: 48px;
  cursor: pointer;
  transition:
    transform 200ms var(--step-ease),
    box-shadow 200ms var(--step-ease),
    background-color 400ms ease-in-out;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 2px 2px 0 0 var(--accent-shadow); /* hard offset, no blur */
}

.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.hint {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-faint);
  margin-left: 14px;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 28px;
}

/* ---------- inputs ---------- */

.field {
  margin-top: 6px;
}

.field label {
  display: block;
  font-family: var(--display-font);
  font-variation-settings: 'opsz' 144;
  font-size: clamp(2.25rem, 6vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  cursor: pointer;
}

.field .helper {
  font-size: 14px;
  color: var(--ink-faint);
  margin: 0 0 18px;
}

.text-input {
  display: block;
  width: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 24px;
  color: var(--ink);
  background-color: transparent;
  /* focus underline: accent line draws in from the left (0% → 100% width) */
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 0% 2px;
  border: none;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  padding: 10px 2px;
  min-height: 52px;
  outline: none;
  transition:
    background-size 250ms ease-out,
    background-image 400ms ease-in-out;
}

.text-input:focus {
  background-size: 100% 2px;
}

.text-input::placeholder {
  color: #b7ac9f;
}

.field-error {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--error);
  min-height: 22px;
  margin: 8px 0 0;
}

/* ---------- role cards ---------- */

.role-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 30px;
}

.role-card {
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 24px 22px;
  min-height: 44px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition:
    border-color var(--step-ms) var(--step-ease),
    transform var(--step-ms) var(--step-ease),
    box-shadow var(--step-ms) var(--step-ease);
}

.role-card:hover {
  transform: translateY(-2px);
}

.role-card[data-role='baker']:hover,
.role-card[data-role='baker']:focus-visible {
  border-color: #c2410c;
  box-shadow: 2px 2px 0 0 rgba(194, 65, 12, 0.25);
}

.role-card[data-role='courier']:hover,
.role-card[data-role='courier']:focus-visible {
  border-color: #0d9488;
  box-shadow: 2px 2px 0 0 rgba(13, 148, 136, 0.25);
}

.role-card .role-title {
  display: block;
  font-family: var(--display-font);
  font-variation-settings: 'opsz' 144;
  font-size: 28px;
  margin-bottom: 8px;
}

.role-card .role-sub {
  display: block;
  font-size: 15px;
  color: var(--ink-soft);
}

/* ---------- chips ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.chip {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid rgba(31, 27, 22, 0.2);
  border-radius: 999px;
  padding: 12px 22px;
  min-height: 48px;
  cursor: pointer;
  transition:
    border-color 200ms var(--step-ease),
    background-color 200ms var(--step-ease),
    color 200ms var(--step-ease),
    transform 200ms var(--step-ease);
}

.chip:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.chip.selected {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #ffffff;
}

/* ---------- story beat ---------- */

.story-points {
  list-style: none;
  margin: 22px 0 26px;
  padding: 0;
}

.story-points li {
  position: relative;
  padding-left: 26px;
  margin-bottom: 14px;
  color: var(--ink-soft);
}

.story-points li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transition: background-color 400ms ease-in-out;
}

.story-where {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 0 0 6px;
}

/* ---------- submit & success ---------- */

.recap {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 22px 0 4px;
}

.submit-error {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--error);
  margin: 16px 0 0;
}

.submit-error[hidden] {
  display: none;
}

.small-link {
  display: inline-block;
  margin-top: 26px;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  text-underline-offset: 3px;
  min-height: 44px;
  padding: 10px 0;
}

/* ---------- OTP code entry ---------- */

.otp-helper {
  font-size: 14px;
  color: var(--ink-faint);
  margin: 0 0 26px;
}

.otp-boxes {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.otp-digit {
  width: 48px;
  min-height: 56px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 26px;
  text-align: center;
  color: var(--ink);
  background-color: transparent;
  /* same accent underline that draws in on .text-input focus */
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 0% 2px;
  border: none;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  padding: 10px 2px;
  outline: none;
  transition:
    background-size 250ms ease-out,
    background-image 400ms ease-in-out,
    border-color 200ms ease-out;
}

.otp-digit:focus {
  background-size: 100% 2px;
}

.otp-boxes.has-error .otp-digit {
  border-bottom-color: var(--error);
}

.otp-boxes.is-verified .otp-digit {
  border-bottom-color: var(--accent);
  background-size: 100% 2px;
}

.otp-verified {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-strong);
  margin: 12px 0 0;
  min-height: 22px;
  transition: color 400ms ease-in-out;
}

.otp-verified[hidden] {
  display: none;
}

.otp-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 22px 0 0;
}

.otp-cooldown {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.otp-cooldown[hidden] {
  display: none;
}

/* quiet inline action — same voice as .small-link, but a button */
.text-link {
  display: inline-block;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 10px 0;
  min-height: 44px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-link:disabled {
  color: var(--ink-faint);
  text-decoration: none;
  cursor: default;
}

#otp-change-number {
  margin-top: 2px;
}

/* ---------- honeypot (never visible, never focusable) ---------- */

.hp-field {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- success: verified confirmation (D11) ---------- */

.success-verified {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-strong);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 18px;
  transition:
    border-color 400ms ease-in-out,
    color 400ms ease-in-out;
}

/* ---------- focus & motion ---------- */

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

@media (prefers-reduced-motion: reduce) {
  .step.active,
  .step.active-back,
  .step.leaving,
  .step.leaving-back,
  .progress-fill,
  .role-card,
  .chip,
  .btn,
  .back-btn,
  .text-input,
  .otp-digit,
  .otp-verified,
  .success-verified,
  .frame,
  .wash-accent,
  .story-points li::before {
    animation: none;
    transition: none;
  }
  /* canvas handles its own reduced-motion path in JS (one static frame) */
}

/* ---------- small screens (390×844 first) ---------- */

@media (max-width: 560px) {
  :root {
    --frame-w: 9px;
  }
  .stage {
    padding: calc(var(--frame-w) + 76px) calc(var(--frame-w) + 20px) calc(var(--frame-w) + 32px);
    align-items: flex-start;
  }
  .role-cards {
    grid-template-columns: 1fr;
  }
  .chips {
    flex-direction: column;
  }
  .chip {
    width: 100%;
    text-align: center;
  }
  .text-input {
    font-size: 20px;
  } /* ≥16px — no iOS focus zoom */
  .otp-boxes {
    gap: 8px;
  }
  .otp-digit {
    width: 44px;
    min-height: 52px;
    font-size: 22px;
  }
  .hint {
    display: block;
    margin: 10px 0 0;
  }
  .brand-lockup {
    width: min(80vw, 420px);
  }
}

/* ---------- noscript ---------- */

.noscript-note {
  max-width: 560px;
  margin: 20vh auto 0;
  padding: 0 24px;
  font-size: 18px;
}
