/* Descent frames: a staircase of photo frames stepping down and across the page, each larger than the last (far to
   near), joined by ONE drawn hairline that runs down the left of each frame and across each gap, never over a photo,
   with a line of words beside each frame. No pinning, no JS needed; part.js only draws the line in, step by step.
   Phones (the run narrower than 1024 px): the same frames in order in one column, growing from a narrow inset to edge
   to edge, the line down the left gutter, ending at the top of the edge-to-edge frame.
   Geometry in % of the run's own width (container units), so the run can be any width:
     frame i: left  = start + i x step,  step = (100 - start - last - end) / (n - 1)
              width = first x (last / first)^(i / (n - 1))         (geometric growth; linear where pow() is missing)
   Markup:
     <div class="descent-frames" style="--df-n:6">
       <ol class="df">
         <li class="df__step"><div class="df__say">words</div><figure class="df__ph"><img ...></figure></li> ...
       </ol>
       <figure class="df__land"><img ...><figcaption>...</figcaption></figure>      (optional landing photo)
     </div>
   A frame's words sit to its right while they fit; the last frame's (and the one before it, from the 5th frame on) sit
   to its left. data-side="l|r" on a .df__step overrides. Set --df-w / --df-x (unitless %) on a step to place it by hand. */

.descent-frames {
  --df-n: 6;                    /* how many frames: set it in the markup when it isn't 6 */
  --df-start: 8;                /* % of the run: the first frame's left edge */
  --df-first: 20;               /* % width of the first (farthest) frame */
  --df-last: 58;                /* % width of the last (nearest) frame */
  --df-end: 0;                  /* % left free right of the last frame (0 = it meets the edge) */
  --df-gap: 4.2cqw;             /* between frames; the tread runs through the middle of it */
  --df-off: 1.4cqw;             /* the line runs this far left of each frame */
  --df-lead: clamp(64px, 7cqw, 120px);   /* line from the start ring down to the first frame */
  --df-say-gap: 3cqw;           /* frame to words */
  --df-say-max: 40;             /* % max width of the words */
  --df-aspect: 3 / 2;
  --df-land-aspect: 16 / 8;
  --df-line: rgba(240, 238, 229, .9);    /* the hairline (pick it from the photos: the line the photos share) */
  --df-line-w: 1px;
  --df-ring: 9px;               /* the open ring the line starts from */
  --df-frame-bg: rgba(255, 255, 255, .06);
  --df-ease: cubic-bezier(.12, 0, .48, 1);  /* the long glide the line draws on */
  --df-draw: 1.1s;              /* each step's drop */
  --df-tread: .7s;              /* each tread across, starting after --df-tread-delay */
  --df-tread-delay: 1s;
  /* phones */
  --df-p-first: 60;             /* % width of the first frame */
  --df-p-near: 88;              /* % width of the second-to-last frame; the last is edge to edge */
  --df-p-gap: 40px;
  --df-p-line: 21px;            /* the gutter line's x */
  --df-p-text: 44px;            /* the words' left inset */
  --df-land-aspect-p: 4 / 3;
  container: df / inline-size;
  position: relative;
}

.df { position: relative; list-style: none; margin: var(--df-lead) 0 0; padding: 0; }
.df::before { content: ""; position: absolute; box-sizing: border-box; width: var(--df-ring); height: var(--df-ring); border: var(--df-line-w) solid var(--df-line); border-radius: 50%;
  left: calc(var(--df-start) * 1cqw - var(--df-off) - var(--df-line-w) / 2 - var(--df-ring) / 2); top: calc(-1 * var(--df-lead) - var(--df-ring)); }
.df__step { position: relative; --i: 0; }
.df__step:nth-child(2) { --i: 1; } .df__step:nth-child(3) { --i: 2; } .df__step:nth-child(4) { --i: 3; }
.df__step:nth-child(5) { --i: 4; } .df__step:nth-child(6) { --i: 5; } .df__step:nth-child(7) { --i: 6; }
.df__step:nth-child(8) { --i: 7; } .df__step:nth-child(9) { --i: 8; } .df__step:nth-child(10) { --i: 9; }
.df__step:nth-child(11) { --i: 10; } .df__step:nth-child(12) { --i: 11; }
.df__ph { position: relative; z-index: 1; margin: 0; aspect-ratio: var(--df-aspect); overflow: hidden; background: var(--df-frame-bg); }
.df__ph img { display: block; width: 100%; height: 100%; object-fit: cover; }
.df__say > :first-child { margin-top: 0; }
.df__land { position: relative; margin: var(--df-gap) 0 0; }
.df__land img { display: block; width: 100%; aspect-ratio: var(--df-land-aspect); object-fit: cover; }

/* the hairline: down the left of each frame, a tread across each gap, down into the landing. Never on a photo. */
.df__step::before, .df__step::after { content: ""; position: absolute; background: var(--df-line); pointer-events: none; }

/* ---------- wide: the staircase ---------- */
@container df (min-width: 1024px) {
  .df__step {
    --df-step: calc((100 - var(--df-start) - var(--df-last) - var(--df-end)) / max(1, var(--df-n) - 1));
    --df-x: calc(var(--df-start) + var(--i) * var(--df-step));
    --df-w: calc(var(--df-first) + (var(--df-last) - var(--df-first)) * var(--i) / max(1, var(--df-n) - 1));
    margin: 0 0 var(--df-gap) calc(var(--df-x) * 1cqw);
    width: calc(var(--df-w) * 1cqw);
  }
  @supports (width: calc(pow(2, 2) * 1px)) {
    .df__step { --df-w: calc(var(--df-first) * pow(var(--df-last) / var(--df-first), var(--i) / max(1, var(--df-n) - 1))); }
  }
  .df__step:last-child { margin-bottom: 0; }
  .df__step::before { left: calc(-1 * var(--df-off) - var(--df-line-w)); top: calc(-1 * var(--df-gap) / 2); width: var(--df-line-w); height: calc(100% + var(--df-gap)); transform-origin: 50% 0; }
  .df__step::after { left: calc(-1 * var(--df-off) - var(--df-line-w)); top: calc(100% + var(--df-gap) / 2); height: var(--df-line-w); width: calc(var(--df-step) * 1cqw + var(--df-line-w)); transform-origin: 0 50%; }
  .df__step:first-child::before { top: calc(-1 * var(--df-lead)); height: calc(100% + var(--df-lead) + var(--df-gap) / 2); }
  .df__step:last-child::before { height: calc(100% + var(--df-gap) / 2); }
  .descent-frames:has(> .df__land) .df__step:last-child::before { height: calc(100% + var(--df-gap) * 1.5); }   /* to the landing's top edge */
  .df__step:first-child:last-child::before { height: calc(100% + var(--df-lead)); }
  .df__step:last-child::after { display: none; }

  /* the words: right of the frame while they fit; the last two frames carry theirs on the left */
  .df__say { position: absolute; top: 0; left: calc(100% + var(--df-say-gap));
    width: min(calc(var(--df-say-max) * 1cqw), calc((100 - var(--df-x) - var(--df-w) - var(--df-start)) * 1cqw - var(--df-say-gap))); }
  .df__step:last-child:not(:first-child) .df__say, .df__step:nth-last-child(2):nth-child(n+4) .df__say, .df__step[data-side="l"] .df__say {
    left: auto; right: calc(100% + var(--df-say-gap)); text-align: right;
    width: min(calc(var(--df-say-max) * 1cqw), calc((var(--df-x) - var(--df-start)) * 1cqw - var(--df-say-gap))); }
  .df__step[data-side="r"] .df__say { left: calc(100% + var(--df-say-gap)); right: auto; text-align: left;
    width: min(calc(var(--df-say-max) * 1cqw), calc((100 - var(--df-x) - var(--df-w) - var(--df-start)) * 1cqw - var(--df-say-gap))); }

  /* the draw-in (part.js arms it on the first real scroll gesture, only for steps still below the screen) */
  .df__step.to-draw::before { transform: scaleY(0); }
  .df__step.to-draw::after { transform: scaleX(0); }
  .df__step.to-draw.is-drawn::before { transform: scaleY(1); transition: transform var(--df-draw) var(--df-ease); }
  .df__step.to-draw.is-drawn::after { transform: scaleX(1); transition: transform var(--df-tread) var(--df-ease) var(--df-tread-delay); }
}

/* ---------- phones: one column, growing from a narrow inset to edge to edge, the line down the gutter ---------- */
@container df (max-width: 1023.98px) {
  .df { margin-top: 56px; }
  .df::before { left: calc(var(--df-p-line) + var(--df-line-w) / 2 - var(--df-ring) / 2); top: calc(-1 * var(--df-ring)); }
  .df__step { width: 100%; margin: 0 0 var(--df-p-gap); }
  .df__step:last-child { margin-bottom: 0; }
  .df__ph { margin-left: auto; width: calc((var(--df-p-first) + (var(--df-p-near) - var(--df-p-first)) * var(--i) / max(1, var(--df-n) - 2)) * 1%); }
  .df__step:last-child .df__ph { width: 100%; }
  .df__say { position: relative; padding: 0 6% 18px var(--df-p-text); }
  .df__step::after { display: none; }
  .df__step::before { left: var(--df-p-line); top: 0; width: var(--df-line-w); height: calc(100% + var(--df-p-gap)); }
  /* the last frame is edge to edge: the line ends at its top edge instead of running on behind it */
  .df__step:last-child::before { display: none; }
  .df__step:last-child .df__say::before { content: ""; position: absolute; left: var(--df-p-line); top: 0; bottom: 0; width: var(--df-line-w); background: var(--df-line); }
  .df__land { margin-top: var(--df-p-gap); }
  .df__land img { aspect-ratio: var(--df-land-aspect-p); }
}

@media (prefers-reduced-motion: reduce) {
  .df__step.to-draw::before, .df__step.to-draw::after { transform: none !important; transition: none !important; }
}
