/*
  HOW IT WORKS placement. Figma 146:24179: copy width 635, title height 160;
  the title bottom meets the visual top. Existing code keeps the shared 5:4 frame.
  how-it-works.js sequences the steps. how-it-works-graphics.js owns each [data-how-it-works-graphic].
  The Layers loop (Birthday Lunch zoom) lives in how-it-works-layers.js / how-it-works-layers.css.
*/

.how-it-works {
  --how-it-works-clearance: calc(var(--space-24) + var(--header-block) + var(--space-16));
  --how-it-works-stack-gap: var(--space-48);
  --how-it-works-kicker: var(--color-hero-cta);
  --how-it-works-body: #424843;
  --how-it-works-divider: #c0c8d4;
  --how-it-works-shift: var(--space-88);
  --how-it-works-visual-width: min(100vw - 2 * var(--page-gutter), 720px);
  --how-it-works-visual-height: calc(var(--how-it-works-visual-width) * 4 / 5);
  /* Entry spacing stays inside the section so its canvas reaches THE IDEA.
     The pin scrolls through this space to --how-it-works-clearance; how-it-works.js measures both for trackStart. */
  --how-it-works-lead: var(--story-section-seam-space, var(--space-128));
  --how-it-works-tail: 0px;

  /* story-sections owns the shared backdrop; keep this section unpositioned for Safari sticky. */
  grid-area: 3 / 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding-top: var(--how-it-works-lead);
  padding-bottom: var(--how-it-works-tail);
  padding-inline: var(--page-gutter);
  /* Calendar cards fan out past narrow viewports. clip, not hidden: hidden would make a scroll container and break the sticky .how-it-works__pin. */
  overflow-x: clip;
  color: var(--color-lp-headline);
}

/* Outside the measured pin track so the final item can leave the viewport naturally. */
.how-it-works-scroll-runway {
  min-height: max(60svh, var(--space-96));
  background: var(--color-how-it-works-canvas);
}

.how-it-works .how-it-works__title {
  color: inherit;
}

.how-it-works[data-how-it-works-moving] .how-it-works__item-copy,
.how-it-works[data-how-it-works-moving] .how-it-works__visual {
  will-change: opacity, transform;
}

.how-it-works__pin {
  grid-area: 1 / 1;
  align-self: start;
  z-index: 1;
  position: sticky;
  top: var(--how-it-works-clearance);
  display: grid;
  align-items: center;
  min-height: calc(100svh - var(--how-it-works-clearance));
}

.how-it-works__content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: var(--space-48);
  align-items: center;
  width: min(100%, 720px);
  margin-inline: auto;
}

.how-it-works__section-title {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-16);
  padding-bottom: var(--space-24);
}

.how-it-works__section-title::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--how-it-works-divider);
}

.how-it-works__kicker {
  margin: 0;
  color: var(--how-it-works-kicker);
}

.how-it-works__steps {
  display: grid;
  grid-template-rows: auto auto;
  row-gap: var(--space-48);
  min-height: 240px;
}

.how-it-works__scroll-indicator {
  display: none;
}

/* Frame 2147236580: one 34px track, 4px dots, 8px gaps, and a 7px scroll thumb.
   how-it-works.js shares the copy's progress; CSS easing here would make the indicator lag behind it. */
.how-it-works__scroll-step {
  position: relative;
  flex-shrink: 0;
  width: var(--space-4);
  height: calc(var(--space-4) + 30px * var(--how-it-works-step-expansion, 0));
  overflow: clip;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-soft-black) var(--how-it-works-step-opacity, 20%), transparent);
}

.how-it-works__scroll-step::after {
  content: "";
  position: absolute;
  top: calc((100% - 7px * var(--how-it-works-step-expansion, 0)) * var(--how-it-works-step-progress, 0));
  left: 0;
  width: 100%;
  height: calc(7px * var(--how-it-works-step-expansion, 0));
  border-radius: inherit;
  background: var(--color-soft-black);
  opacity: var(--how-it-works-step-expansion, 0);
}

.how-it-works__item {
  grid-area: 1 / 1;
}

.how-it-works__visual {
  position: relative;
  display: grid;
  grid-area: 2 / 1;
  align-items: start;
  justify-self: start;
  min-width: 0;
  width: var(--how-it-works-visual-width);
  height: var(--how-it-works-visual-height);
  border-radius: 12px;
}

.how-it-works__visual--decoration {
  overflow: clip;
}

.how-it-works__visual--product {
  /* Height fits the immutable 1420×900 scene; the extra width extends only to the right.
     clip keeps zoom inside this visual without flattening the spatial tile layers. */
  width: max(var(--how-it-works-visual-width), calc(var(--how-it-works-visual-height) * 1420 / 900));
  overflow: clip;
  transform-style: preserve-3d;
}

/* Keep the crop on an inner wrapper so playback and Lenses controls can sit above the frame. */
.how-it-works__visual--product:has(> .how-it-works-playback-control, > .how-it-works-lenses__prompt) {
  overflow: visible;
}

.how-it-works__visual-clip {
  position: absolute;
  inset: 0;
  overflow: clip;
  border-radius: 12px;
  transform-style: preserve-3d;
}

.how-it-works__visual-product {
  /* calendar-data.js fixes 1420×900: derive width from the shared visual height, never reflow tiles. */
  --visual-stage-scale: 1;
  --visual-stage-end-x: 0deg;
  --visual-stage-end-y: 0deg;
  position: absolute;
  top: 0;
  left: 0;
  width: calc(var(--how-it-works-visual-height) * 1420 / 900);
  scale: 1;
  transform: none;
}

.how-it-works__product-frame {
  position: relative;
  width: var(--how-it-works-visual-width);
  height: var(--how-it-works-visual-height);
  overflow: visible;
  transform-style: preserve-3d;
}

/* Keep the fade cover independent so it never restyles the spatial calendar. */
.how-it-works__product-frame::before {
  --how-it-works-canvas: var(--color-how-it-works-canvas);
  content: "";
  position: absolute;
  inset: 0;
  width: max(100%, calc(var(--how-it-works-visual-height) * 1420 / 900));
  pointer-events: none;
}

/* Fade a separate cover instead of a VP ancestor; visual-product.css relies on that distinction to preserve tile depth. */
.how-it-works__product-frame::before {
  z-index: 2;
  background: var(--how-it-works-canvas);
  opacity: calc(1 - var(--how-it-works-graphic-opacity, 1));
}

.how-it-works[data-how-it-works-moving] .how-it-works__visual--product {
  will-change: auto;
}

.how-it-works[data-how-it-works-moving] .how-it-works__product-frame::before {
  will-change: opacity;
}

.how-it-works__item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-self: stretch;
  min-height: 0;
  /* how-it-works.js moves the inner copy; this stationary crop keeps it below the section-title divider. */
  overflow: clip;
  width: 100%;
}

.how-it-works__item-copy {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: var(--space-24);
  width: 100%;
}

.how-it-works__item-heading {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-16);
}

.how-it-works__item-badge {
  margin: 0;
  padding-inline: var(--space-8);
  border-radius: var(--space-4);
  background: color-mix(in srgb, var(--color-light-sky) 25%, transparent);
  color: var(--color-deep-ocean);
  font: normal 500 var(--font-size-16) / var(--line-height-24) var(--font-text);
  white-space: nowrap;
}

.how-it-works__item-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--type-h3-size);
  line-height: var(--type-h3-line-height);
  letter-spacing: var(--type-h2-letter-spacing);
}

.how-it-works__item-body {
  display: grid;
  gap: var(--space-16);
  color: var(--how-it-works-body);
  font: var(--type-body-1-font);
}

.how-it-works__item-body p {
  margin: 0;
}

.how-it-works__quote {
  margin: 0;
  padding-left: var(--space-24);
  border-left: var(--space-2) solid var(--how-it-works-kicker);
  font: var(--type-h5-font);
}

/* Figma 146:24316 supplies relative anchors; scene and card sizes remain those of the page. */
.how-it-works__decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(426 / 856 * 100%);
  height: auto;
  pointer-events: none;
}

@media (max-width: 743px) {
  .how-it-works {
    --how-it-works-stack-gap: 0px;
    /* The last mobile copy ends the section; a viewport runway here creates a large blank gap before Other features. */
    --how-it-works-tail: 0px;
    height: auto !important;
  }

  .how-it-works__pin {
    position: static;
    height: auto;
    min-height: 0;
  }

  .how-it-works__content {
    row-gap: var(--space-40);
  }

  .how-it-works__steps {
    display: flex;
    flex-direction: column;
    gap: var(--how-it-works-stack-gap);
    min-height: 0;
  }

  /*
    Each step shows its copy above the graphic. Order is visual only: how-it-works.js pairs
    [data-how-it-works-item] and [data-how-it-works-visual] by index. One pair of rules per step in index.html.
  */
  .how-it-works__steps > .how-it-works__item:nth-of-type(1) { order: 1; }
  .how-it-works__steps > .how-it-works__visual:nth-of-type(1) { order: 2; }
  .how-it-works__steps > .how-it-works__item:nth-of-type(2) { order: 3; }
  .how-it-works__steps > .how-it-works__visual:nth-of-type(2) { order: 4; }
  .how-it-works__steps > .how-it-works__item:nth-of-type(3) { order: 5; }
  .how-it-works__steps > .how-it-works__visual:nth-of-type(3) { order: 6; }
  .how-it-works__steps > .how-it-works__item:nth-of-type(4) { order: 7; }
  .how-it-works__steps > .how-it-works__visual:nth-of-type(4) { order: 8; }

  .how-it-works__steps > .how-it-works__visual {
    margin-block-start: var(--space-32);
  }

  /* The play/pause control sits 40px above its frame; this keeps it clear of the copy above. */
  .how-it-works__steps > .how-it-works__visual:has(> .how-it-works-playback-control) {
    margin-block-start: var(--space-64);
  }

  .how-it-works__steps > .how-it-works__item:not(:nth-of-type(1)) {
    margin-block-start: var(--space-128);
  }

  .how-it-works__item,
  .how-it-works__visual {
    grid-area: auto;
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
  }

  .how-it-works__item:empty,
  .how-it-works__visual:empty {
    display: none;
  }
}

@media (min-width: 1024px) {
  .how-it-works {
    --how-it-works-visual-width: min(804px, calc((min(100vw - 2 * var(--page-gutter), var(--section-track)) - var(--space-48)) / 2));
  }

  .how-it-works__pin {
    height: min(800px, calc(100svh - var(--how-it-works-clearance)));
    min-height: 0;
    top: max(var(--how-it-works-clearance), calc((100svh - 800px) / 2));
  }

  .how-it-works__content {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(160px, max-content) minmax(0, 1fr);
    column-gap: var(--space-48);
    row-gap: 0;
    align-items: stretch;
    width: min(100%, var(--section-track));
    height: 100%;
  }

  .how-it-works__section-title {
    grid-column: 1;
    grid-row: 1;
    /* min, not height: at 1024–1199px the title wraps to three lines and must grow the row, or the divider crosses it. */
    min-height: 160px;
  }

  .how-it-works__steps {
    display: contents;
    min-height: 0;
  }

  .how-it-works__item {
    grid-column: 1;
    grid-row: 2;
    height: 100%;
  }

  .how-it-works__visual {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
  }
}

/* The visual is top-aligned and its height follows the width, so centring copy over the pin row drifts low on near-square viewports.
   The copy box takes the visual's height, so both centres match at any width. The item keeps the full row as its clip box for the slide. Motion layout only; reduced motion stacks copy in flow. */
@media (min-width: 1024px) and (prefers-reduced-motion: no-preference) {
  .how-it-works__item {
    position: relative;
  }

  .how-it-works__item-copy {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: var(--how-it-works-visual-height);
    justify-content: center;
  }
}

@media (min-width: 1366px) {
  .how-it-works {
    --how-it-works-visual-width: min(804px, calc(min(100vw - 2 * var(--page-gutter), var(--section-track)) - 635px - var(--space-72)));
  }

  .how-it-works__pin {
    height: 800px;
  }

  .how-it-works__content {
    grid-template-columns: 635px minmax(0, 1fr);
    grid-template-rows: minmax(160px, max-content) minmax(0, 1fr);
    column-gap: var(--space-72);
  }

  .how-it-works__item-title {
    font-size: 40px;
    line-height: 40px;
  }
}

@media (min-width: 1367px) and (prefers-reduced-motion: no-preference) {
  .how-it-works[data-how-it-works-mode="snap"] .how-it-works__scroll-indicator {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    justify-self: end;
    width: var(--space-4);
    /* Center in the existing column gap; Figma puts it 12px above the item midpoint. */
    transform: translate(calc((var(--space-72) + var(--space-4)) / 2), calc(-1 * (var(--space-8) + var(--space-4))));
    pointer-events: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .how-it-works {
    --how-it-works-visual-width: min(100vw - 2 * var(--page-gutter), 720px);
    height: auto !important;
  }

  .how-it-works__pin {
    position: static;
    height: auto;
    min-height: 0;
  }

  .how-it-works__content {
    height: auto;
    grid-template-rows: auto;
  }

  .how-it-works__steps {
    display: flex;
    flex-direction: column;
    gap: var(--how-it-works-stack-gap);
    min-height: 0;
  }

  .how-it-works__item,
  .how-it-works__visual {
    grid-area: auto;
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
  }

  .how-it-works__item {
    width: 100%;
    height: auto;
  }

  .how-it-works__item:empty,
  .how-it-works__visual:empty {
    display: none;
  }

}
