/* Pinned section with progress — position: sticky + CSS scroll-driven animations.
   The section is tall; its inner panel sticks to the viewport while you scroll
   through it. The section's own view timeline (--pin) drives the bar, the shape
   and which step is visible. Set --steps to the number of steps. */

.pin {
  --steps: 3;
  position: relative;
  view-timeline: --pin block;
}

.pin__sticky {
  display: grid;
  gap: 32px;
  padding: 96px 28px;
}

.pin__steps {
  display: grid;
  gap: 48px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pin__bar,
.pin__shape { display: none; }

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* one screen per step, plus the screen the panel needs to stay in */
    .pin { height: calc((var(--steps) + 1) * 100svh); }

    .pin__sticky {
      position: sticky;
      top: 0;
      height: 100svh;
      align-content: center;
      padding-inline: 8vw;
      overflow: clip;
    }

    /* all the steps share one spot and take turns */
    .pin__steps { display: grid; }
    .pin__step {
      grid-area: 1 / 1;
      opacity: 0;
      animation: pin-step linear both;
      animation-timeline: --pin;
      /* each step owns its slice of the pinned scroll */
      animation-range:
        contain calc(var(--n) * 100% / var(--steps))
        contain calc((var(--n) + 1) * 100% / var(--steps));
    }
    /* the first step is already there when the panel pins; the last one stays */
    .pin__step:first-child { animation-name: pin-step-first; }
    .pin__step:last-child { animation-name: pin-step-last; }

    .pin__bar {
      display: block;
      position: absolute;
      inset: auto 8vw 48px 8vw;
      height: 4px;
      border-radius: 2px;
      overflow: hidden;
      background: #2d2924;
    }
    .pin__bar span {
      display: block;
      height: 100%;
      background: var(--accent, #ff6a3d);
      transform-origin: left;
      animation: pin-grow linear both;
      animation-timeline: --pin;
      animation-range: contain 0% contain 100%;
    }

    .pin__shape {
      display: block;
      position: absolute;
      right: 8vw;
      top: 50%;
      width: min(34vw, 420px);
      aspect-ratio: 1;
      margin-top: calc(min(34vw, 420px) / -2);
      border-radius: 28%;
      background: conic-gradient(from 200deg, #ff6a3d, #e9dcc6, #3a332b, #ff6a3d);
      opacity: 0.9;
      animation: pin-shape linear both;
      animation-timeline: --pin;
      animation-range: contain 0% contain 100%;
    }
  }
}

/* enter from below, hold, leave upwards */
@keyframes pin-step {
  0%        { opacity: 0; transform: translateY(48px); }
  20%, 80%  { opacity: 1; transform: none; }
  100%      { opacity: 0; transform: translateY(-48px); }
}
@keyframes pin-step-first {
  0%, 80% { opacity: 1; transform: none; }
  100%    { opacity: 0; transform: translateY(-48px); }
}
@keyframes pin-step-last {
  0%        { opacity: 0; transform: translateY(48px); }
  20%, 100% { opacity: 1; transform: none; }
}
@keyframes pin-grow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
@keyframes pin-shape {
  from { transform: rotate(-30deg) scale(0.7); }
  to   { transform: rotate(150deg) scale(1); }
}

/* Reduced motion and older browsers: no pinning; the steps are a normal list. */

/* demo layout */
.pin__step { max-width: 520px; }
.pin__num { color: var(--accent, #ff6a3d); font: 500 14px var(--font-mono, ui-monospace, monospace); }
.pin__step h2 { margin: 10px 0 12px; font: 700 clamp(48px, 7vw, 96px)/0.95 var(--font-display, system-ui, sans-serif); letter-spacing: -0.035em; }
.pin__step p { margin: 0; color: var(--muted, #9c9488); font-size: 19px; }
.pp-intro, .pp-outro { min-height: 80svh; display: grid; align-content: center; padding: 0 28px; }
.pp-intro h1 { margin: 12px 0 0; font: 700 clamp(44px, 7.4vw, 96px)/0.98 var(--font-display, system-ui, sans-serif); letter-spacing: -0.035em; }
.pp-outro p { color: var(--muted, #9c9488); font-size: 19px; }
@media (max-width: 760px) {
  .pin__shape { opacity: 0.25; right: -10vw; width: 70vw; margin-top: -35vw; }
}
