/* How It Works — matches Website Screens/How it works (Desktop 1–5 at 1440px, Mobile at 410px).
   The section sits behind the landing screen (negative top margin) with a pinned
   "stage". Scrolling first slides the landing screen away, then steps through
   the four steps. js/how-it-works.js turns the scroll position into:
     each photo's opacity and transform (the --p / --turn rules below are the
                 starting state; the script writes the values directly)
     the list's blur and opacity
     .is-active on the current step and caption
     the signature's traced length */

.hiw {
  --hiw-gutter: clamp(32px, 4.3vw, 62px);

  position: relative;
  z-index: 1;
  /* 100vh hidden behind the landing screen + 100vh stage + 440vh of scrolling through the steps */
  height: 640vh;
  margin-top: -100vh;
  background: var(--black);
  color: var(--white);
}

/* "How It Works" links land here: the moment the section is fully revealed */
.hiw__anchor {
  position: absolute;
  top: 100vh;
  left: 0;
}

.hiw__stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100lvh; /* the full screen with the browser bars hidden, so no gap opens at the
                     bottom when they slide away while you scroll on a phone */
  overflow: hidden;
}

/* ---------- Photos ---------- */

.hiw__photo {
  --p: 0;
  position: absolute;
  top: 50%;
  left: var(--x);
  width: 14.2vw;
  max-width: none;
  height: auto;
  aspect-ratio: 205 / 278;
  object-fit: cover;
  filter: brightness(0.55);
  opacity: var(--p);
  transform:
    translate(-50%, -50%)
    translateY(calc((1 - var(--p)) * 48px))
    rotate(calc(var(--r) * var(--turn, var(--p)))) /* starts straight, turns to its final angle as it arrives */
    scale(calc(0.92 + var(--p) * 0.08));
  will-change: transform, opacity; /* moved by js/how-it-works.js on its own GPU layer */
}

.hiw__photo:nth-child(1) { --x: 16.5%; --r: -7.6deg; }
.hiw__photo:nth-child(2) { --x: 37.6%; --r: 5.8deg; }
.hiw__photo:nth-child(3) { --x: 61.3%; --r: 3.5deg; }
.hiw__photo:nth-child(4) { --x: 83.3%; --r: -6.3deg; }

/* Dark pool behind the step list so it stays readable over the photos and signature */
.hiw__glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 640px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgb(0 0 0 / 0.9), rgb(0 0 0 / 0.6) 55%, rgb(0 0 0 / 0));
  pointer-events: none;
}

/* ---------- Signature ---------- */

.hiw__sign {
  position: absolute;
  top: 50%;
  left: -22.6vw;
  width: 126vw;
  max-width: none;
  height: auto;
  overflow: visible;
  transform: translateY(calc(-50% - 0.8vw));
  pointer-events: none;
  will-change: transform; /* own layer: tracing redraws only the line, not the photos around it */
}

.hiw__sign-path {
  fill: none;
  stroke: var(--grey);
  stroke-opacity: 0.64;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Title and intro ---------- */

.hiw__intro {
  position: absolute;
  top: 64px;
  right: var(--hiw-gutter);
  width: 27vw;
  min-width: 320px;
}

.hiw__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(36px, 3.5vw, 58px);
  line-height: 1;
  letter-spacing: -0.02em;
}

.hiw__title em {
  font-style: italic;
}

.hiw__lede {
  margin: 18px 0 0;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.4; /* 21px at 15px, chosen with the slider */
  text-align: justify;
}

/* ---------- Step list ---------- */

.hiw__steps {
  --blur: 1;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 0;
  list-style: none;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: clamp(26px, 2.5vw, 42px);
  line-height: 1.36;
  text-align: center;
  white-space: nowrap;
  filter: blur(calc(var(--blur) * 6px));
  opacity: calc(1 - var(--blur) * 0.5);
}

.hiw__step {
  color: var(--dark-grey);
  transition: color 0.4s ease;
}

/* Each step is a button that scrolls to that step */
.hiw__step-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.hiw__step:hover,
.hiw__step:has(.hiw__step-button:focus-visible) {
  color: var(--white);
}

.hiw__step-button:focus-visible {
  outline: 1px solid var(--beige);
  outline-offset: 4px;
}

.hiw__step sup {
  margin-right: 0.12em;
  font-size: 0.32em;
  vertical-align: 1.6em;
  line-height: 0;
}

.hiw__step.is-active {
  color: var(--white);
  font-style: italic;
}

/* ---------- Caption ---------- */

.hiw__captions {
  position: absolute;
  bottom: 80px;
  left: 50%;
  display: grid;
  width: min(720px, calc(100% - 2 * var(--hiw-gutter)));
  transform: translateX(-50%);
}

.hiw__caption {
  grid-area: 1 / 1;
  align-self: end;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 19.5px;
  line-height: 24px;
  text-transform: uppercase;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  /* the old caption clears quickly before the new one comes in, so they never overlap */
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.hiw__caption.is-active {
  opacity: 1;
  transform: none;
  transition: opacity 0.45s ease 0.15s, transform 0.45s ease 0.15s;
}

/* Keep the caption above the phone's bottom browser bar when it's showing */
@supports (height: 100dvh) {
  .hiw__captions { margin-bottom: calc(100lvh - 100dvh); }
}

/* ---------- Phones and tablets: one photo at a time, centred ---------- */

@media (max-width: 959px) {
  .hiw__photo {
    left: 50%;
    width: min(51vw, 320px);
  }

  .hiw__photo:nth-child(1) { --r: -8deg; }
  .hiw__photo:nth-child(2) { --r: 6deg; }
  .hiw__photo:nth-child(3) { --r: -5deg; }
  .hiw__photo:nth-child(4) { --r: 7deg; }

  .hiw__glow {
    width: 110vw;
  }

  .hiw__sign {
    left: -30vw;
    width: 137vw;
    transform: translateY(calc(-50% + 3vw));
  }

  .hiw__sign-path {
    stroke-width: 4.5;
  }

  .hiw__intro {
    top: 92px;
    right: auto;
    left: var(--hiw-gutter);
    width: auto;
    min-width: 0;
    max-width: 460px;
    padding-right: var(--hiw-gutter);
  }

  .hiw__title {
    font-size: clamp(36px, 9vw, 48px);
  }

  .hiw__lede {
    margin-top: 16px;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
  }

  .hiw__steps {
    font-size: clamp(26px, 6.8vw, 34px);
    line-height: 1.5;
  }

  .hiw__captions {
    bottom: 64px;
  }

  .hiw__caption {
    font-size: 13.5px;
    line-height: 17px;
  }
}
