/* The route: how an order moves, enquiry to delivery. By default a vertical
   list with a rule down its side. With scripting and room the list pins to
   the screen and runs sideways as you scroll: a crimson line draws along the
   route and each station lights as the line reaches it. process.js writes
   the custom properties; all the motion is CSS. */

#process {
  position: relative;
  display: flow-root;
  /* The hero's grid on charcoal, with a crimson glow in the top corner. */
  background:
    radial-gradient(60% 55% at 88% 0%, rgba(var(--crimson-rgb), 0.32), transparent),
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 1.75rem 1.75rem fixed,
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 1.75rem 1.75rem fixed,
    var(--charcoal);
  color: #fff;
}

#process > h2 {
  color: #fff;
}

#process > h2 strong {
  color: var(--light-crimson);
}

#process > p {
  max-width: 44ch;
  color: rgba(255, 255, 255, 0.72);
  font-size: clamp(15px, 1.3vw, 18px);
  font-weight: 400;
  line-height: 1.5;
}

#process ol {
  display: grid;
  gap: clamp(1.5rem, 3vw, 2.5rem);
  margin: clamp(2rem, 5vw, 3.5rem) 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

#process li {
  position: relative;
  display: grid;
  gap: 0.5rem;
  padding-inline-start: clamp(1.75rem, 3vw, 2.5rem);
  border-inline-start: 1px solid rgba(255, 255, 255, 0.18);
  counter-increment: step;
}

#process li::before {
  content: counter(step, decimal-leading-zero);
  color: var(--light-crimson);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

#process li::after {
  content: "";
  position: absolute;
  inset-block-start: 0.2rem;
  inset-inline-start: -0.3rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--light-crimson);
}

#process li h3 {
  color: #fff;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}

#process li p {
  max-width: 34ch;
  color: rgba(255, 255, 255, 0.78);
  font-size: clamp(13px, 1vw, 15px);
  font-weight: 400;
}

/* Pinned: a screen-high stage that stays put while the section scrolls past
   it, with the stations running sideways underneath. */
@media (min-width: 993px) {
  html.js #process {
    min-height: calc(300svh + 14rem);
  }

  html.js #process ol {
    --top: max(5.5rem, calc(50svh - 9rem));
    --progress: 0;
    --fill: 0;
    --shift: 0px;
    --track: 100%;
    --reached: -1;
    position: sticky;
    top: 0;
    display: flex;
    align-items: flex-start;
    gap: 0;
    height: 100svh;
    margin: 0 calc(-1 * var(--pad));
    padding: var(--top) var(--pad) 0;
    overflow: clip;
  }

  /* The route: a track, and a line that fills along it. Both move with the
     stations, so the line seems to draw ahead of the scroll. */
  html.js #process ol::before,
  html.js #process ol::after {
    content: "";
    position: absolute;
    inset-block-start: calc(var(--top) + 7.5rem);
    inset-inline-start: var(--pad);
    width: var(--track);
    height: 1px;
    translate: calc(var(--progress) * var(--shift) * -1) 0;
  }

  html.js #process ol::before {
    background: rgba(255, 255, 255, 0.18);
  }

  html.js #process ol::after {
    background: var(--light-crimson);
    transform-origin: left;
    scale: var(--fill) 1;
  }

  html.js #process li {
    --on: clamp(0, var(--reached) - var(--i) + 1, 1);
    flex: 0 0 clamp(17rem, 28vw, 26rem);
    grid-template-rows: 6rem 3rem auto auto;
    align-content: start;
    gap: 0;
    padding: 0 clamp(2rem, 4vw, 4rem) 0 0;
    border: 0;
    opacity: calc(0.3 + 0.7 * var(--on));
    translate: calc(var(--progress) * var(--shift) * -1) 0;
    transition: opacity 0.8s var(--ease-out);
  }

  /* The numeral is an outline until its station is reached, then it fills. */
  html.js #process li::before {
    color: color-mix(in srgb, var(--light-crimson) calc(var(--on) * 100%), transparent);
    font-size: clamp(3.5rem, 7vw, 6rem);
    font-weight: 500;
    letter-spacing: -0.04em;
    line-height: 6rem;
    -webkit-text-stroke: 1px rgba(255, 255, 255, 0.45);
    transition: color 0.8s var(--ease-out);
  }

  /* The station sits on the route. */
  html.js #process li::after {
    inset-block-start: 7.1rem;
    inset-inline-start: 0;
    width: 0.8rem;
    height: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: color-mix(in srgb, var(--light-crimson) calc(var(--on) * 100%), var(--charcoal));
    transition:
      background-color 0.8s var(--ease-out),
      box-shadow 0.8s var(--ease-out);
  }

  html.js #process li[aria-current]::after {
    box-shadow: 0 0 0 0.45rem rgba(var(--light-crimson-rgb), 0.25);
  }

  html.js #process li h3 {
    grid-row: 3;
  }

  html.js #process li p {
    grid-row: 4;
    margin-top: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #process li,
  #process li::before,
  #process li::after {
    transition: none;
  }
}
