/* ================================================
   The Anchor · Onboarding Questionnaire
   Builds on tokens.css + type.css + sections.css
   Screens stack absolutely; only .is-active is visible.
   ================================================ */

html, body {
  /* questionnaire wants the full viewport feel, not page scroll */
  overflow: hidden;
  height: 100%;
}
body { padding: 0; }  /* override the global frame; we manage margins per-screen */

/* ============================================================
   STAGE — fills the viewport, holds all 8 screens
   ============================================================ */
.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--paper);
  overflow: hidden;
}

/* Thin progress rail — top of viewport, driven by JS */
.q-progress {
  position: fixed; top: 0; left: 0; right: 0;
  height: 2px; z-index: 100; pointer-events: none;
  background: var(--rule);
}
.q-progress__bar {
  height: 100%; width: 0;
  background: var(--ink);
  transition: width 480ms var(--ease-out);
}

/* Quiet top bar — brand left, screen indicator right */
.q-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(20px, 3vw, 44px) 0;
  pointer-events: none;
}
.q-top__brand,
.q-top__indicator {
  pointer-events: auto;
}
.q-top__brand {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.005em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.q-top__brand .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink);
  display: inline-block;
}
.q-top__brand .light {
  color: var(--ink-mute);
  font-weight: 400;
}
.q-top__indicator {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-mute);
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.q-top__indicator .step {
  color: var(--ink);
}
.q-top__indicator .total {
  color: var(--ink-faint);
}
.q-top__indicator .pip-row {
  display: inline-flex;
  gap: 5px;
  margin-left: 4px;
}
.q-top__indicator .pip {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--rule-strong);
  transition: background 360ms var(--ease-out);
}
.q-top__indicator .pip.is-done { background: var(--ink); }
.q-top__indicator .pip.is-current {
  background: var(--ink);
  box-shadow: 0 0 0 3px var(--paper-soft);
}

/* ============================================================
   SCREEN — one per state in the state machine
   ============================================================ */
.q-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 84px clamp(20px, 4vw, 64px) 96px;
  /* Base hidden state — snap, no transition.
     Enter/leave animations overlay this; if the animation is throttled
     (unfocused iframe etc.) the underlying state is still correct. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow-y: auto;
}
.q-screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.q-screen.is-entering {
  animation-name: q-screen-enter;
  animation-duration: 480ms;
  animation-timing-function: var(--ease-out);
  animation-fill-mode: both;
}
.q-screen.is-leaving {
  /* Keep visible during exit, but no pointer */
  visibility: visible;
  pointer-events: none;
  opacity: 0;
  animation-name: q-screen-leave;
  animation-duration: 360ms;
  animation-timing-function: var(--ease-out);
  animation-fill-mode: both;
}
@keyframes q-screen-enter {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes q-screen-leave {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-28px); }
}

.q-frame {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

/* ============================================================
   HEADER VOCABULARY (intro + per-batch)
   ============================================================ */
.q-eyebrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: clamp(28px, 3.6vw, 48px);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-mute);
}
.q-eyebrow .right {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Intro display — large; uses .illuminate letter cascade */
.q-display {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(40px, 6.2vw, 92px);
  line-height: 1.04;
  letter-spacing: -0.022em;
  color: var(--ink);
  margin: 0 0 clamp(16px, 1.4vw, 22px);
  text-wrap: balance;
  max-width: 18ch;
}
.q-trail {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: clamp(17px, 1.4vw, 22px);
  line-height: 1.5;
  letter-spacing: -0.005em;
  color: var(--ink-mute);
  margin: 0 0 clamp(32px, 3.6vw, 48px);
  max-width: 52ch;
  text-wrap: pretty;
}

/* Batch header — smaller display + trail (matches portal vocabulary) */
.q-batch-head {
  margin-bottom: clamp(28px, 3.2vw, 44px);
}
.q-batch-head .lede {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(28px, 3.6vw, 48px);
  line-height: 1.1;
  letter-spacing: -0.018em;
  color: var(--ink);
  margin: 0;
  text-wrap: balance;
}
.q-batch-head .scale-note {
  display: flex;
  gap: 28px;
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ============================================================
   INTRO — the things-to-expect mini-list + begin CTA
   ============================================================ */
.q-expects {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(20px, 1.6vw, 28px);
  margin: clamp(20px, 2.4vw, 32px) 0 clamp(40px, 4vw, 56px);
}
.q-expect {
  border-top: 1px solid var(--rule-strong);
  padding-top: 16px;
}
.q-expect .num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.q-expect .body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  margin-top: 6px;
  text-wrap: pretty;
}

.q-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: clamp(28px, 3.2vw, 44px);
}
.q-foot__note {
  font-family: var(--font-body);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-mute);
  max-width: 42ch;
}

/* ============================================================
   STATEMENT ROW — the Likert
   ============================================================ */
.q-grid {
  display: grid;
  gap: clamp(10px, 0.9vw, 16px);
  margin-bottom: clamp(28px, 3.2vw, 44px);
}

.q {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 36px 1fr 360px;
  align-items: center;
  gap: clamp(16px, 1.6vw, 28px);
  padding: clamp(18px, 1.5vw, 24px) clamp(14px, 1.4vw, 20px) clamp(20px, 1.6vw, 26px);
  border-top: 1px solid var(--rule);
  transition: background 240ms var(--ease-out);
}
.q:last-of-type {
  border-bottom: 1px solid var(--rule);
}
.q.is-answered { background: rgba(14, 13, 11, 0.025); }

.q__legend { /* hide the legend visually; screen-reader keeps it */
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
.q__num {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-transform: uppercase;
  align-self: start;
  padding-top: 4px;
  transition: color 240ms var(--ease-out);
}
.q.is-answered .q__num { color: var(--ink); }

.q__text {
  font-family: var(--font-body);
  font-size: clamp(16px, 1.2vw, 18.5px);
  line-height: 1.45;
  color: var(--ink);
  text-wrap: pretty;
}

/* Scale block — 5 cells + endpoint legend beneath */
.q__scale-wrap {
  display: grid;
  gap: 8px;
  align-self: start;
}
.q__scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  border-radius: 4px;
  overflow: hidden;
}
.q__cell {
  position: relative;
  display: block;
  cursor: pointer;
  user-select: none;
  text-align: center;
}
.q__cell input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
  margin: 0;
}
.q__cell-num {
  display: block;
  padding: 14px 0 13px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
  background: var(--paper);
  border-right: 1px solid var(--rule);
  transition-property: background, color;
  transition-duration: 200ms;
  transition-timing-function: var(--ease-out);
}
.q__cell:last-child .q__cell-num { border-right: none; }

.q__cell:hover .q__cell-num {
  background: var(--paper-soft);
  color: var(--ink);
}
.q__cell input:focus-visible + .q__cell-num {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
  background: var(--paper-soft);
  color: var(--ink);
}
.q__cell input:checked + .q__cell-num {
  background: var(--ink);
  color: var(--paper);
}

.q__ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 2px;
}

/* ============================================================
   PAGINATION — prev (ghost) + next (cascade CTA)
   ============================================================ */
.q-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.q-pager__hint {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.q-pager__hint.is-incomplete { color: rgba(14, 13, 11, 0.42); }
.q-pager__hint.is-ready { color: var(--ink); }

.ghost-back {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink-mute);
  padding: 8px 14px 8px 0;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 240ms var(--ease-out);
}
.ghost-back::before {
  content: "←";
  display: inline-block;
  transition: transform 280ms var(--ease-out);
}
.ghost-back:hover {
  color: var(--ink);
}
.ghost-back:hover::before {
  transform: translateX(-3px);
}

/* ----------- CASCADE CTA — ported from Babymama, palette-adapted */
.cta {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px 28px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  border-radius: 0;
  /* Longhand only — never var() inside shorthand. */
  transition-property: color, border-color;
  transition-duration: 450ms;
  transition-timing-function: var(--ease-out);
  transition-delay: 0s;
}
.cta::before {
  content: "";
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 0%;
  background: var(--ink);
  z-index: -1;
  transition-property: height;
  transition-duration: 560ms;
  transition-delay: 340ms;
  transition-timing-function: var(--ease-out);
}
.cta::after {
  content: "";
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 0%;
  background: var(--paper-soft);
  z-index: -2;
  transition-property: height;
  transition-duration: 560ms;
  transition-delay: 220ms;
  transition-timing-function: var(--ease-out);
}
.cta:hover::before { height: 100%; }
.cta:hover::after  { height: 100%; }
.cta:hover { color: var(--paper); }

.cta__label,
.cta__arrow {
  position: relative;
  z-index: 1;
}
.cta__arrow {
  display: inline-block;
  opacity: 0;
  transform: translateX(-8px);
  transition-property: opacity, transform;
  transition-duration: 280ms;
  transition-timing-function: var(--ease-out);
}
.cta:hover .cta__arrow {
  opacity: 1;
  transform: translateX(0);
}

.cta[disabled],
.cta.is-locked {
  border-color: var(--rule-strong);
  color: var(--ink-faint);
  cursor: not-allowed;
}
.cta[disabled]::before,
.cta[disabled]::after,
.cta.is-locked::before,
.cta.is-locked::after { display: none; }
.cta[disabled]:hover,
.cta.is-locked:hover { color: var(--ink-faint); }

/* ============================================================
   DETAILS SCREEN — form fields
   ============================================================ */
.q-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(16px, 1.4vw, 22px);
  margin: clamp(20px, 2.4vw, 32px) 0 clamp(28px, 3vw, 40px);
}
.q-field {
  display: grid;
  gap: 6px;
}
.q-field.is-wide { grid-column: 1 / -1; }

.q-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.q-label .optional {
  color: var(--ink-faint);
  font-size: 10px;
}

.q-input,
.q-select,
.q-textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--rule-strong);
  padding: 12px 0 12px;
  border-radius: 0;
  transition: border-color 240ms var(--ease-out);
}
.q-input:focus,
.q-select:focus,
.q-textarea:focus {
  outline: none;
  border-bottom-color: var(--ink);
}
.q-input::placeholder,
.q-textarea::placeholder { color: var(--ink-faint); }

.q-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-mute) 50%),
                    linear-gradient(135deg, var(--ink-mute) 50%, transparent 50%);
  background-position: calc(100% - 14px) center, calc(100% - 9px) center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.q-textarea {
  resize: vertical;
  min-height: 92px;
  padding-top: 10px;
}

/* ============================================================
   SENT — confirmation
   ============================================================ */
.q-sent {
  text-align: left;
}
.q-sent .q-display { max-width: 22ch; }
.q-sent .q-trail   { max-width: 56ch; }

.q-sent__diag {
  margin-top: clamp(24px, 3vw, 40px);
  padding: 16px 18px;
  border: 1px solid var(--rule);
  background: var(--paper-soft);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-mute);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow: auto;
}
.q-sent__diag .label {
  display: block;
  margin-bottom: 8px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ============================================================
   ILLUMINATION — ink alpha 0.12 → 1.0
   Adopts portal vocabulary. JS adds .is-lit on screen enter.
   ============================================================ */
.illuminate .word-wrap {
  display: inline-block;
  white-space: nowrap;
}
.illuminate .letter,
.illuminate .word {
  color: var(--ink-faint);
  transition-property: color;
  transition-duration: 360ms;
  transition-timing-function: var(--ease-out);
  transition-delay: var(--d, 0s);
}
.illuminate .letter.is-lit,
.illuminate .word.is-lit { color: var(--ink); }
.illuminate .trail .word.is-lit,
.illuminate .lede .word.is-lit { color: var(--ink-mute); }

@media (prefers-reduced-motion: reduce) {
  .illuminate .letter,
  .illuminate .word { transition: none; color: var(--ink); }
  .illuminate .trail .word,
  .illuminate .lede .word { color: var(--ink-mute); }
  .q-screen.is-entering,
  .q-screen.is-leaving { animation: none; }
}

/* ============================================================
   RESPONSIVE — stack at narrow widths
   ============================================================ */
@media (max-width: 880px) {
  .q-screen { padding: 76px clamp(18px, 4vw, 28px) 92px; }
  .q-expects { grid-template-columns: 1fr; }
  .q { grid-template-columns: 32px 1fr; }
  .q__scale-wrap { grid-column: 1 / -1; margin-top: 6px; }
  .q-fields { grid-template-columns: 1fr; }
  .q-foot { flex-direction: column; align-items: stretch; }
  .q-foot .cta { width: 100%; }
  .q-pager { flex-direction: column-reverse; align-items: stretch; }
  .q-pager .cta { width: 100%; }
  .q-pager__hint { text-align: center; }
  .q-top__indicator .pip-row { display: none; }
}

@media (max-width: 520px) {
  .q-display { font-size: clamp(34px, 9vw, 56px); }
  .q-batch-head .lede { font-size: clamp(24px, 6.8vw, 36px); }
  .q__text { font-size: 15.5px; }
  .q__cell-num { padding: 12px 0 11px; font-size: 12.5px; }
}
