:root {
  --bg: #262626;
  --fg: #f2f2f2;
  --muted: #a3a3a3;
  --primary: #1677ff;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --border: #444;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: clamp(14px, 3.6vw, 16px);
  line-height: 1.45;
}

body.page-body-ab {
  overflow: hidden;
  height: 100dvh;
  max-height: 100dvh;
  /* Mobile Safari: avoid system Copy / “Look Up” when long-pressing Compare near instructional copy. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Prefer smallest viewport height so fixed bottom browser chrome is accounted for (mobile). */
@supports (height: 100svh) {
  body.page-body-ab {
    height: 100svh;
    max-height: 100svh;
  }
}

.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.page--form {
  max-width: 680px;
}

.page--stack {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* AB flow: never grow taller than the viewport; middle image area shrinks so footer stays visible. */
body.page-body-ab .page.page--stack.page--ab {
  height: 100%;
  max-height: 100%;
  /* Override .page--stack min-height:100dvh so we never exceed the (possibly svh-capped) body. */
  min-height: 0;
  overflow: hidden;
  /* ~2/3 of default `.page` top padding (16px) */
  padding-top: 11px;
}

body.page-body-ab .header--ab {
  /* ~2/3 of default 10px */
  margin-bottom: 7px;
}

body.page-body-ab .header--ab .btn-link {
  /* ~2/3 of default vertical padding (10px) on Previous */
  padding: 7px 8px;
}

body.page-body-ab .page.page--stack.page--ab .page-main--ab {
  flex: 0 1 auto;
  min-height: 0;
  overflow: visible;
}

body.page-body-ab .page.page--stack.page--ab .content--ab {
  flex: 0 1 auto;
  min-height: 0;
  /* Match .image-section: avoid clipping A/B when inner height is tight (chain was: content--ab hidden → image-section hidden). */
  overflow: visible;
}

/* Section height = content only so no empty band between A/B and Compare; tighter bottom padding. */
body.page-body-ab .page.page--stack.page--ab .image-section {
  flex: 0 1 auto;
  min-height: 0;
  /* visible: do not clip .variant-row when inner flex height is tight (overflow:hidden hid A/B in some WebViews). */
  overflow: visible;
  padding: 12px 12px 4px;
  gap: 8px;
}

/* Pinch-zoom overflow is clipped here only; keeps rounded frame look without swallowing the A/B row. */
body.page-body-ab .page.page--stack.page--ab .image-section-media {
  flex: 0 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
}

body.page-body-ab .page.page--stack.page--ab .image-frame {
  /* Allow shrinking so A/B labels below the frame are not clipped by `.image-section { overflow: hidden }` on short viewports. */
  flex: 0 1 auto;
  min-height: 0;
  max-height: none;
}

body.page-body-ab .page.page--stack.page--ab .compare-block {
  flex: 0 0 auto;
  margin-top: 12px;
}

body.page-body-ab .page.page--stack.page--ab > .ab-bottom-dock {
  flex: 0 0 auto;
}

.page.page--ab {
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
}

.page-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.header--ab {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.btn-link {
  border: none;
  background: transparent;
  color: var(--fg);
  padding: 10px 8px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-link:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #f1f5f9;
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 180ms ease;
}

.progress-text {
  min-width: 40px;
  text-align: right;
  font-weight: 700;
}

.content--ab {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.image-section {
  --ab-image-scale: 1;
  width: 100%;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.compare-block {
  margin-top: 8px;
  width: 100%;
}

.compare-btn {
  width: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  position: relative;
}

/* Loading / waiting for B decode: stays visibly “off” (inset dark mask), not the same as active primary blue. */
body.page-body-ab .compare-btn:disabled {
  cursor: not-allowed;
  color: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.48);
}

.image-frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #1e1e1e;
  /* Portrait 3:4 (width : height = 3 : 4); images use object-fit: contain inside. */
  aspect-ratio: 3 / 4;
  height: auto;
  max-height: min(72dvh, calc((100vw - 32px) * 4 / 3));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.image-frame--loading .image-zoom-inner {
  visibility: hidden;
}

.ab-image-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border-radius: inherit;
  background: #1a1a1a;
  color: var(--muted, #a3a3a3);
  font-weight: 600;
  font-size: clamp(15px, 3.8vw, 17px);
  letter-spacing: 0.04em;
  pointer-events: none;
}

.ab-image-loading-overlay[hidden] {
  display: none !important;
}

.image-zoom-inner {
  box-sizing: border-box;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
}

/* Two stacked <img>: Compare toggles visibility only (no src thrash) to avoid decode flicker. */
.ab-compare-stack {
  display: grid;
  grid-template: 1fr / 1fr;
  justify-items: center;
  align-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.ab-compare-stack .ab-compare-layer {
  grid-row: 1;
  grid-column: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ab-compare-stack .ab-compare-layer--hidden {
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

.ab-compare-stack .ab-compare-layer:not(.ab-compare-layer--hidden) {
  z-index: 1;
}

.variant-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-height: 34px;
  flex: 0 0 auto;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.variant-label {
  text-align: center;
  min-width: 18px;
  font-weight: 700;
  /* Was inherited from body `clamp(14px, 3.6vw, 16px)`; +2 steps ≈ +4px each bound. */
  font-size: clamp(18px, 4.2vw, 20px);
  color: var(--muted);
  /* Non-active A/B — more subdued so active side reads clearly. */
  opacity: 0.36;
  user-select: none;
  pointer-events: none;
  transition: color 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.variant-label.is-active {
  color: var(--fg);
  opacity: 1;
  transform: scale(1.05);
}

.ab-bottom-dock {
  margin-top: 8px;
  padding-bottom: env(safe-area-inset-bottom);
}

.hint-text {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

/* Title / section intro (under h1 or similar). */
.hint-text.hint-text--subtitle {
  margin: 0 0 16px;
  line-height: 1.35;
}

/* Survey start: allow intentional line breaks from `DEFAULT_SURVEY_DESCRIPTION` (\n). */
#surveyDescription {
  white-space: pre-line;
}

/* Tight copy tied to the field above (survey form, researcher hints). */
.hint-text.hint-text--field {
  margin: 0px 0 10px;
  font-size: 12px;
  line-height: 1.05;
  color: var(--muted);
}

.header:not(.header--ab) {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.header:not(.header--ab) h1 {
  margin: 0;
  line-height: 1.15;
}

.hint-text--ab {
  width: 100%;
  max-width: none;
  margin: 0 0 8px;
  text-align: left;
  line-height: 1.35;
  display: block;
  overflow: visible;
  /* Fixed px so body `clamp(...)` and `.ab-compact` never change this line. */
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.ab-compact .image-section {
  padding: 10px;
  gap: 8px;
}

/* AB page: do not force a floor height; JS may set max-height to fit under browser chrome. */
body.page-body-ab.ab-compact .image-frame {
  min-height: 0;
}

body.ab-compact .choice-section {
  padding-top: 10px;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-section {
  padding-top: 14px;
}

.btn {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--fg);
}

.choice-btn.is-selected {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.form-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.profile-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.profile-form > .profile-form-submit {
  margin-top: 4px;
}

.profile-form-submit {
  width: 100%;
}

.profile-form-submit.is-loading {
  cursor: wait;
  opacity: 0.92;
}

.profile-form label {
  display: grid;
  gap: 6px;
}

.profile-form input,
.profile-form select,
.profile-form textarea {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #4a4a4a;
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  /* iOS Safari: computed font-size < 16px on focused inputs triggers page zoom; keep ≥16px without changing desktop cap. */
  font-size: max(16px, 1em);
  padding: 8px 10px;
}

.profile-form input.profile-phone-input {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page--form .image-section.profile-form-card {
  padding: 14px 14px 16px;
  gap: 12px;
}

/* Survey complete: follow-up interview opt-in. */
.followup-block {
  display: grid;
  gap: 12px;
}

.followup-block__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.followup-lede {
  margin: 0;
}

/* 1.5× line height for follow-up copy (overrides .hint-text--field). */
.hint-text.hint-text--field.followup-lede {
  line-height: 1.5;
}

.followup-submit-btn {
  width: 100%;
  max-width: 100%;
}

.followup-whatsapp-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.followup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.followup-status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.followup-status.is-error {
  color: #ff9c9c;
}

/* Title above + bordered swatch area only (same vertical rhythm as .profile-form label). */
.profile-form .skin-tone-block {
  display: grid;
  gap: 6px;
}

.profile-form .skin-tone-block__label {
  color: var(--fg);
  font: inherit;
}

.skin-tone-fieldset {
  border: 1px solid #4a4a4a;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0;
}

.skin-tone-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.skin-tone-option {
  display: grid;
  gap: 6px;
  justify-items: center;
  cursor: pointer;
}

.skin-tone-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Default orb cap was 50px; “90% smaller” => 10% linear size (5px). Whole label stays tappable. */
.skin-tone-swatch {
  width: 100%;
  max-width: 42px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  background-image: var(--orb-image);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  position: relative;
  z-index: 0;
  transition: transform 120ms ease;
}

.skin-tone-label {
  font-size: 12px;
  color: var(--muted);
}

.skin-tone-option input:checked + .skin-tone-swatch {
  transform: scale(1.2);
  z-index: 1;
}

.skin-tone-option input:checked + .skin-tone-swatch + .skin-tone-label {
  color: var(--fg);
  font-weight: 700;
}

@media (max-width: 480px) {
  .page {
    padding: 14px 14px 32px;
  }

  .image-frame {
    max-height: min(64dvh, calc((100vw - 24px) * 4 / 3));
  }

  .skin-tone-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  .skin-tone-label {
    font-size: 10px;
  }
}
