/* Process section with a scroll-driven animation. Builds on /styles.css. */

.process {
  --header-h: 105px;
  /* Height left to read the steps while the animation is pinned. */
  --reading-h: calc(100vh - var(--header-h));
  /* Scroll needed to play the 390 frames. */
  --scrub: 210vh;
  /* Approximate height of a step's text: centres it and holds the last one. */
  --text-h: 160px;
  padding-block: 108px;
  background: var(--ice);
}

.process-track {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
  gap: 72px;
  margin-top: 58px;
}

.process-stage {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
}

.process-steps {
  grid-column: 1;
  grid-row: 1;
}

.process-figure {
  width: 100%;
  margin: 0;
}

.process-frame {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: transparent;
}

.process-poster,
.process-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.process-frame.has-frame .process-poster {
  opacity: 0;
}

.process-steps {
  display: flex;
  flex-direction: column;
}

.process-step {
  display: flex;
  align-items: center;
  padding: 26px 0 26px 36px;
  border-left: 1px solid #c9deec;
}

.process-step > div {
  position: relative;
  max-width: 420px;
}

.process-step > div::before {
  position: absolute;
  content: "";
  left: -43px;
  top: 3px;
  width: 13px;
  height: 13px;
  border: 2px solid #c9deec;
  border-radius: 50%;
  background: var(--ice);
  transition: background-color .3s ease, border-color .3s ease, box-shadow .3s ease;
}

.process-number {
  color: var(--blue-bright);
  font-size: .72rem;
  font-weight: 800;
}

.process-step h3 {
  margin-top: 6px;
  font-size: 1.45rem;
  letter-spacing: -.04em;
  line-height: 1.3;
  transition: color .3s ease;
}

.process-step p {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: .92rem;
}

/* Scroll-driven layout. Without JS or with reduced motion the section stays
   a compact list next to a still image. */
@media (prefers-reduced-motion: no-preference) {
  /* The pinned stage already leaves room below the image. */
  .js .process {
    padding-bottom: 24px;
  }

  .js .process-stage {
    position: sticky;
    top: var(--header-h);
    height: var(--reading-h);
    display: grid;
    align-content: center;
  }

  .js .process-figure {
    width: min(100%, calc((var(--reading-h) - 96px) * 4 / 3));
    justify-self: end;
  }

  /* Each step's height follows the length of its part of the video, and its
     text stays pinned at the reading line while that part plays. The padding
     starts the first step on that line; the last step keeps its text pinned
     until the image is released. */
  .js .process-steps {
    min-height: calc(var(--scrub) + var(--reading-h));
    padding-block: calc((var(--reading-h) - var(--text-h)) / 2);
  }

  /* Content, not padding: a pinned element only travels within its parent's content. */
  .js .process-steps > li:last-child::after {
    display: block;
    content: "";
    height: var(--text-h);
  }

  .js .process-steps > li {
    display: block;
    flex: var(--span) 1 0;
    padding-block: 0;
  }

  .js .process-step > div {
    position: sticky;
    top: calc(var(--header-h) + (var(--reading-h) - var(--text-h)) / 2);
  }

  .js .process-step:not(.is-active) h3 {
    color: var(--ink-soft);
  }

  .js .process-step.is-active > div::before {
    border-color: var(--blue-bright);
    background: var(--blue-bright);
    box-shadow: 0 0 0 5px rgb(64 163 228 / 18%);
  }
}

@media (max-width: 1120px) {
  .process-track {
    gap: 48px;
  }
}

@media (max-width: 900px) {
  .process {
    --header-h: 89px;
    padding-block: 80px;
  }

  .process-track {
    gap: 32px;
  }

  .process-step h3 {
    font-size: 1.27rem;
  }
}

@media (max-width: 700px) {
  .process {
    /* Pinned image above the steps: frame width is the page width minus gutters. */
    --stage-h: calc((100vw - 40px) * .75 + 20px);
    padding-block: 68px;
  }

  .process-track {
    grid-template-columns: 1fr;
    gap: 28px;
    margin-top: 40px;
  }

  .process-stage,
  .process-steps {
    grid-column: 1;
    grid-row: auto;
  }

  .process-step {
    padding-left: 28px;
  }

  .process-step > div::before {
    left: -35px;
  }

  @media (prefers-reduced-motion: no-preference) {
    .js .process-stage {
      z-index: 3;
      height: auto;
      margin-inline: -20px;
      padding: 12px 20px 8px;
      background: var(--ice);
    }

    /* Steps fade out as they scroll under the pinned image. */
    .js .process-stage::after {
      position: absolute;
      content: "";
      left: 0;
      right: 0;
      top: 100%;
      height: 28px;
      background: linear-gradient(var(--ice), rgb(240 247 252 / 0%));
      pointer-events: none;
    }

    .js .process-figure {
      width: 100%;
    }

    /* Text pins just below the image. The negative margin ends the track,
       and so releases the image, while the last text is still pinned; the
       section padding leaves room for it. */
    .js .process {
      padding-bottom: calc(var(--text-h) + 48px);
    }

    .js .process-steps {
      min-height: calc(var(--scrub) + 24px + var(--text-h));
      margin-bottom: calc(-24px - var(--text-h));
      padding-top: 24px;
      padding-bottom: 0;
    }

    .js .process-step > div {
      top: calc(var(--header-h) + var(--stage-h) + 24px);
    }

  }
}
