/* Ignite Individual Coaching — light brand reskin.
   Typography: Playfair Display for titles, Lora for everything else (labels,
   questions, body copy, buttons).

   Mobile-first: base rules target a 360px phone. Two up-queries scale it —
   `min-width: 600px` (large phone / small tablet: type + control sizing step up)
   and `min-width: 900px` (desktop: roomier page gutters, larger logo/header).
   There are deliberately no max-width queries. */

:root {
  color-scheme: light;

  --bg: #f2f0eb;
  /* Input/control surfaces sit on top of the flat --bg fill, so they need to
     read as a distinct layer now that the page is light. */
  --surface: #fff;
  --surface-2: #f7f5f0;
  --text: #899064;
  --theme-text: #899064;
  --text-dim: #6b6b5e;
  --text-faint: #9a978c;

  --green: #4a783a;
  --green-bright: #6aaa55;
  --green-hover: #5a8a4a;

  /* Themed accent — seeded to the green brand, overridden per objetivo_treino
     at runtime by js/theme.js (issue #48). Repoint accent-coloured rules at
     these, not --green*. */
  --accent: var(--green);
  --accent-bright: var(--green-bright);
  --accent-hover: var(--green-hover);
  --accent-soft: rgba(74, 120, 58, 0.16);
  /* Lower stop of the page background gradient; equal to --bg by default so
     the page is a flat fill (js/theme.js keeps both equal on every theme). */
  --bg-accent: #f2f0eb;

  --hairline: rgba(0, 0, 0, 0.08);
  --border: rgba(0, 0, 0, 0.18);

  --error: #c23b3b;

  --font-body: "Lora", Georgia, "Times New Roman", serif;
  --font-cond: "Lora", var(--font-body);
  --font-display: "Playfair Display", var(--font-cond);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Page ground: a flat themed fill (--bg == --bg-accent for every theme in
   js/theme.js). The always-black header sits opaque on top, so no gradient
   is needed to blend into it. */
body {
  background-color: var(--bg);
  background-image: linear-gradient(180deg, var(--bg) 0, var(--bg-accent) 720px);
  background-repeat: no-repeat;
  /* background-image transitions too: modern browsers interpolate a gradient's
     colour stops when old/new value are structurally the same gradient
     (same function, same number/position of stops) — true here, only the
     colours themselves change between themes. */
  transition: background-color 0.35s ease, background-image 0.35s ease;
}

/* Theme switch (green <-> pink, js/theme.js) fades text/border/icon colour
   everywhere instead of hard-cutting. Scoped to the page content rather than
   `*` globally so it can't fight more specific component transitions (nav
   buttons, inputs, country picker, etc. already declare their own, faster,
   interaction transitions and keep winning on specificity). */
.page,
.page *,
.page-header,
.page-header * {
  transition: color 0.35s ease, background-color 0.35s ease, border-color 0.35s ease, fill 0.35s ease;
}

@media (prefers-reduced-motion: reduce) {
  html,
  body,
  .page,
  .page *,
  .page-header,
  .page-header * {
    transition: none;
  }
}

html {
  min-height: 100%;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
}

::selection {
  background: rgba(74, 120, 58, 0.4);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* Suppress the grey flash on tap; every interactive control has its own
   :hover / :active / :checked feedback. */
button,
input,
label,
.country-select__option {
  -webkit-tap-highlight-color: transparent;
}

/* --- Layout ---------------------------------------------------------------- */

.page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.page-header {
  padding: 48px 0 28px max(32px, env(safe-area-inset-left));
  background: var(--bg);
}

.logo-frame {
  display: inline-flex;
  background: var(--bg);
}

.logo-frame img {
  display: block;
  width: 32px;
  height: auto;
}

#form-root {
  padding: 8px 0 0;
}

/* Entrance animation — only when the step actually changes (renderStep adds
   .step-enter-fwd / .step-enter-back depending on nav direction). Intra-step
   re-renders (radio / checkbox toggles) skip it so the page doesn't blink on
   every click. Forward slides in from the right, back from the left — same
   left/right convention as iOS/Android step navigation. */
#form-root.step-enter-fwd > * {
  animation: slideInFwd 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
#form-root.step-enter-back > * {
  animation: slideInBack 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes slideInFwd {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    /* `none`, not translateX(0): with animation-fill-mode: both the end state
       lingers, and any real transform value keeps each field a separate
       stacking context — which would trap the country dropdown behind the
       fields that follow it in the DOM. */
    transform: none;
  }
}

@keyframes slideInBack {
  from {
    opacity: 0;
    transform: translateX(-100%);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #form-root.step-enter-fwd > *,
  #form-root.step-enter-back > * {
    animation: none;
  }
}

/* Suppress the browser's default whole-page crossfade for the View Transition
   above — only the named `brand-logo` element (old logo -> new logo position)
   should animate; everything else keeps using the existing slide-in. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-group(brand-logo) {
  animation-duration: 0.6s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(brand-logo) {
    animation: none;
  }
}

/* --- Progress ------------------------------------------------------------- */

.progress {
  margin: 8px 0 28px;
}

.progress-label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-cond);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

.progress-track {
  width: 100%;
  height: 2px;
  background: var(--hairline);
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- Headings ------------------------------------------------------------- */

#form-root h1 {
  margin: 0 0 1.5rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* --- Text / email / tel fields ------------------------------------------ */

.field {
  display: block;
  margin-block: 1.5rem;
}

fieldset.field {
  border: none;
  padding: 0;
  margin-inline: 0;
}

.field > input[type="text"],
.field > input[type="email"],
fieldset.field legend,
.field > .tel-group {
  /* shared vertical rhythm handled per-rule below */
}

fieldset.field legend,
.field > input[type="text"] + .error,
label.field > span:first-child:not(.tel-group) {
  display: block;
}

/* the plain label text that precedes text inputs */
label.field {
  font-family: var(--font-cond);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

fieldset.field legend {
  padding: 0;
  margin-bottom: 0.75rem;
  font-family: var(--font-cond);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

.field > input[type="text"],
.field > input[type="email"] {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 14px;
  font-family: var(--font-body);
  font-size: 16px; /* >=16px so iOS Safari doesn't zoom on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.field > input::placeholder {
  color: var(--text-faint);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--accent-bright);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px rgba(74, 120, 58, 0.24);
}

button:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* --- Phone group ------------------------------------------------------------ */

.tel-group {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  align-items: stretch;
}

.flag {
  display: block;
  width: 20px;
  height: 15px;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.1);
  flex: none;
}

/* Custom country picker (replaces a native <select> so flag images can show) */
.country-select {
  position: relative;
  flex: none;
  /* opt out of the uppercase / wide-tracking label styling it sits inside */
  text-transform: none;
  letter-spacing: normal;
}

/* While open, lift the whole picker above the form fields that follow it in
   the DOM (email, etc.) so the dropdown paints on top, not behind them. */
.country-select.is-open {
  z-index: 30;
}

.country-select__toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 100%;
  min-height: 48px;
  padding: 14px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}

.country-select__caret {
  font-size: 10px;
  opacity: 0.7;
}

.country-select__list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 2px);
  left: 0;
  width: max-content;
  min-width: 0;
  max-width: calc(100vw - 32px); /* never past the viewport gutters on a phone */
  max-height: min(60vh, 320px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.country-select__option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 12px 14px; /* ~48px row — comfortable touch target */
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
}

.country-select__option.is-active,
.country-select__option:hover {
  background: var(--accent-bright);
  color: #fff;
}

.country-select__option[aria-selected="true"] {
  font-weight: 600;
}

.tel-group input[type="tel"] {
  flex: 1;
  min-width: 0; /* let it shrink inside the flex row on narrow screens */
  padding: 14px;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
}

/* --- Option buttons (radio / checkbox groups) ------------------------------ */

fieldset.field label,
label.option-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  margin: 8px 0 0;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

fieldset.field label:hover,
label.option-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

/* Hide the native control; the label row is the visible target. */
fieldset.field label input[type="radio"],
fieldset.field label input[type="checkbox"],
label.option-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Selected state — driven by the (hidden) checked input. */
fieldset.field label:has(input:checked),
label.option-button:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(74, 120, 58, 0.2), 0 0 12px rgba(74, 120, 58, 0.12);
}

/* The check mark box on the right of each option row. */
.option-mark {
  flex: none;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  font-size: 10px;
  line-height: 1;
  color: transparent;
  border: 1px solid var(--hairline);
}

fieldset.field label:has(input:checked) .option-mark,
label.option-button:has(input:checked) .option-mark {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* --- Bare (single) checkbox — keep it obvious it's a toggle ------------- */

label.field:has(> input[type="checkbox"]:only-of-type) {
  flex-direction: row;
  justify-content: flex-start;
  text-transform: none;
  letter-spacing: normal;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-dim);
}

label.field > input[type="checkbox"] {
  position: static;
  width: 18px;
  height: 18px;
  opacity: 1;
  accent-color: var(--accent);
}

/* --- Note panel -------------------------------------------------------------- */

.note {
  margin-block: 1.5rem;
  padding: 16px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  font-size: 0.95rem;
  color: var(--text-dim);
}

/* --- Errors -------------------------------------------------------------- */

.error {
  display: block;
  margin-top: 0.4rem;
  color: var(--error);
  font-family: var(--font-cond);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

[aria-invalid="true"] {
  border-color: var(--error) !important;
}

/* --- Nav buttons -------------------------------------------------------------- */

.nav {
  display: flex;
  gap: 0.75rem;
  margin-top: 2rem;
}

.nav button {
  flex: 1;
  min-height: 52px;
  padding: 16px 18px;
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 0;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.nav button:hover:not([disabled]) {
  background: var(--accent-hover);
  box-shadow: 0 12px 30px rgba(74, 120, 58, 0.35);
}

.nav button:active:not([disabled]) {
  transform: scale(0.98);
}

/* "Voltar" and the error-screen retry button are secondary actions — render
   them as a ghost/outline style, never the themed (green/pink) accent fill. */
.nav button.nav-ghost {
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--hairline);
  box-shadow: none;
}

/* Voltar sits beside "Seguinte"/"Enviar" and stays compact; the retry button
   is alone in its .nav and keeps the full-width flex: 1 from ".nav button". */
.nav button.nav-ghost:not(:only-child) {
  flex: 0 0 auto;
  min-width: 96px;
}

.nav button.nav-ghost:hover:not([disabled]) {
  color: var(--text);
  border-color: rgba(74, 120, 58, 0.35);
  background: none;
}

/* Retry button (error screen): fixed neutral background, not the themed
   (green/pink) accent fill — stays readable regardless of objetivo theme. */
.nav button.nav-retry {
  color: var(--theme-text);
  background: #f2f0eb;
  box-shadow: none;
}

.nav button.nav-retry:hover:not([disabled]) {
  background: #e5e2da;
}

.nav button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

#form-root[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* --- Confirmation / error screen ---------------------------------------- */

.confirmation {
  margin: 2.5rem 0 1.5rem;
  font-family: var(--font-cond);
  font-size: 1.4rem;
  line-height: 1.6;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--text);
}

.confirmation-logo {
  display: block;
  width: 140px;
  max-width: 50%;
  height: auto;
  /* Same gap above the logo as above the retry button (.nav's margin-top),
     so the spacing reads consistently whether the logo follows the message
     directly (success) or the retry button (error). */
  margin: 2rem auto 0;
}

/* --- Landing screen ---------------------------------------------------------
   Neutral pre-form intro (issue #47). Colours/fonts use the existing tokens as
   placeholders — swap for the client's final palette when delivered. */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.5rem;
  padding: 4rem 0 1rem;
}

/* Applied only transiently (by startForm() in js/formEngine.js) around the
   landing -> step-1 swap, then removed. Same name on both = the browser
   morphs one into the other (position, size) inside that View Transition,
   instead of the logo just popping from center to the header's left spot.
   Left permanently assigned, `view-transition-name` puts #header-logo in its
   own compositing layer for the rest of the session, which is what caused
   the small flicker/jump on later, unrelated step changes (Next/Back) —
   same class of bug as the transform-stacking-context issue noted below. */
.vt-brand-logo {
  view-transition-name: brand-logo;
}

.landing-logo {
  width: 50px;
  max-width: 70%;
  height: auto;
}

.landing-tagline {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #899064;
}

.landing-message {
  margin: 0;
  max-width: 42ch;
  font-family: var(--font-cond);
  font-size: 1.05rem;
  line-height: 1.6;
  letter-spacing: 0.02em;
  color: #899064;
}

.landing-cta {
  margin-top: 0.5rem;
  min-height: 52px;
  padding: 16px 40px;
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
  background: #899064;
  border: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.landing-cta:hover {
  background: #899064;
  box-shadow: 0 12px 30px rgba(137, 144, 100, 0.35);
}

.landing-cta:active {
  transform: scale(0.98);
}

/* --- Scale up from the phone baseline ------------------------------------- */

/* Large phone / small tablet: step type and control padding back up. */
@media (min-width: 600px) {
  #form-root h1 {
    font-size: 2.4rem;
  }
  .field > input[type="text"],
  .field > input[type="email"],
  .tel-group input[type="tel"],
  .country-select__toggle,
  fieldset.field label,
  label.option-button {
    padding: 16px 18px;
    font-size: 15px;
  }
  .country-select__toggle {
    padding-inline: 10px;
  }
  .country-select__list {
    min-width: 260px;
    max-width: 340px;
  }
  .nav {
    margin-top: 2.5rem;
  }
  .nav button {
    min-height: 56px;
    padding: 18px 22px;
    font-size: 13px;
  }
  .confirmation {
    margin: 3rem 0 2rem;
    font-size: 1.6rem;
  }
  .landing-logo {
    width: 50px;
  }
  .landing-tagline {
    font-size: 1.9rem;
  }
  .landing-message {
    font-size: 1.15rem;
  }
  .landing-cta {
    min-height: 56px;
    font-size: 13px;
  }
}

/* Desktop: roomier gutters, larger brand mark and header. */
@media (min-width: 900px) {
  .page {
    padding: 0 24px 2px 50px;
  }
  .page-header {
    padding: 16px 0 2px 50px;
  }
  .logo-frame img {
    width: 38px;
  }
}
