/* Load-in choreography for the six main pages and the report pages.
   painted.js adds .is-in to each [data-reveal] block once it reaches the screen; these rules then play the
   entrances inside it, once. Principles (after Emil Kowalski's motion guidance):
   - one entrance per container: a block whose items stagger fades in without moving, so nothing moves twice;
   - lists stagger at 55ms a step, capped at eight steps, so long lists never keep anyone waiting;
   - only opacity, translate, scale and clip-path move, with a strong ease-out; individual transform
     properties (translate/scale/rotate) are used so they compose with the positioning some parts already have;
   - detail motion lands after its item: stamps press down, price bars draw, the ratings scale fills;
   - with reduced motion, none of this runs and everything is simply there. */

@media (prefers-reduced-motion: no-preference) {
  :root { --rv-ease: cubic-bezier(.23, 1, .32, 1); --rv-step: 55ms; }

  @keyframes rv-lift { from { opacity: 0; translate: 0 12px; } }
  @keyframes rv-fade { from { opacity: 0; } }
  @keyframes rv-pop { from { opacity: 0; scale: .5; } }
  @keyframes rv-press { 0% { opacity: 0; scale: 1.4; } 55% { opacity: 1; scale: .95; } 100% { scale: 1; } }
  @keyframes rv-grow-x { from { transform: scaleX(0); } }
  @keyframes rv-grow-y { from { scale: 1 0; } }
  @keyframes rv-wipe { from { clip-path: inset(0 100% 0 0); } }
  @keyframes rv-settle { from { opacity: 0; translate: 0 -18px; rotate: 5deg; } }

  /* blocks whose items stagger: the block itself only fades, so the items carry the motion */
  .js [data-reveal]:has(.report-grid, .ledger, .logbook, .rating-cards, .records, .other-ways, .fine-print, .map-pins) { transform: none; }
  .js .p-home [data-reveal]:has(.ledger).is-in { animation-name: rv-fade; }
  .js .rows[data-reveal], .js .facts[data-reveal], .js .strata[data-reveal] { transform: none; }

  /* ---------- lists: each item lifts into place, one after another ---------- */
  .is-in .report-grid > *, .is-in .ledger > *, .is-in .log-group li, .is-in .rating-cards > li, .is-in .records > li,
  .is-in .other-ways li, .is-in .fine-print li, .rows.is-in > div, .facts.is-in > div, .strata.is-in .strata-steps > li,
  .is-in .report-layout > *, .is-in .thesis > li {
    animation: rv-lift 560ms var(--rv-ease) backwards; animation-delay: var(--d, 0ms);
  }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(2) { --d: calc(var(--rv-step) * 1); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(3) { --d: calc(var(--rv-step) * 2); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(4) { --d: calc(var(--rv-step) * 3); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(5) { --d: calc(var(--rv-step) * 4); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(6) { --d: calc(var(--rv-step) * 5); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(7) { --d: calc(var(--rv-step) * 6); }
  :is(.report-grid, .ledger, ul, ol, .rows, .facts, .strata-steps, .report-layout) > :nth-child(n+8) { --d: calc(var(--rv-step) * 7); }
  /* the logbook's four groups follow each other too, so its rows read as one wave down the page */
  .logbook > .log-group:nth-child(2) li { --g: 110ms; } .logbook > .log-group:nth-child(3) li { --g: 220ms; } .logbook > .log-group:nth-child(4) li { --g: 330ms; }
  .is-in .log-group li { animation-delay: calc(var(--d, 0ms) + var(--g, 0ms)); }

  /* ---------- the call: rating stamps press down, price bars draw, figures settle ---------- */
  .is-in .stamp { animation: rv-press 460ms var(--rv-ease) backwards; animation-delay: calc(var(--d, 0ms) + 280ms); }
  .is-in .range-gap, .is-in .lr-gap { transform-origin: left center; animation: rv-grow-x 760ms var(--rv-ease) backwards; animation-delay: calc(var(--d, 0ms) + 320ms); }
  .is-in .range-price, .is-in .lr-price { animation: rv-pop 380ms var(--rv-ease) backwards; animation-delay: calc(var(--d, 0ms) + 260ms); }
  .is-in .range-target, .is-in .lr-target { transform-origin: bottom center; animation: rv-grow-y 420ms var(--rv-ease) backwards; animation-delay: calc(var(--d, 0ms) + 700ms); }
  .is-in .range-label { animation: rv-fade 420ms ease backwards; animation-delay: calc(var(--d, 0ms) + 520ms); }

  /* ---------- Methodology: the ratings scale fills left to right, Sell to Buy ---------- */
  .return-scale.is-in .seg { animation: rv-wipe 520ms var(--rv-ease) backwards; }
  .return-scale.is-in .seg:nth-child(2) { animation-delay: 140ms; }
  .return-scale.is-in .seg:nth-child(3) { animation-delay: 280ms; }
  .return-scale.is-in .seg:nth-child(4) { animation-delay: 420ms; }
  .return-scale.is-in .scale-ticks > * { animation: rv-fade 400ms ease backwards; animation-delay: 560ms; }

  /* ---------- the step sections: the heading's rule draws, then the steps follow ---------- */
  .strata .head { position: relative; border-bottom-color: transparent; }
  .strata .head::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: #16181d;
    transform-origin: left; transform: scaleX(0); transition: transform 900ms var(--rv-ease); }
  .strata.is-in .head::after { transform: none; }
  .strata.is-in .strata-steps > li { animation-delay: calc(var(--d, 0ms) + 200ms); }

  /* ---------- About me: the polaroid settles, the map's pins pop in, the records slide out ---------- */
  .portrait-old.is-in .polaroid { animation: rv-settle 900ms var(--rv-ease) backwards; animation-delay: 120ms; }
  .is-in .map-pin { animation: rv-pop 420ms var(--rv-ease) backwards; animation-delay: calc(240ms + var(--pd, 0ms)); }
  .map-pins > :nth-child(2) { --pd: 60ms; } .map-pins > :nth-child(3) { --pd: 120ms; } .map-pins > :nth-child(4) { --pd: 180ms; }
  .map-pins > :nth-child(5) { --pd: 240ms; } .map-pins > :nth-child(6) { --pd: 300ms; } .map-pins > :nth-child(n+7) { --pd: 360ms; }

  /* ---------- Contact: the postcard lifts in, then the direct ways follow ---------- */
  .orig.is-in .postcard { animation: rv-lift 700ms var(--rv-ease) backwards; }
  .is-in .other-ways li { animation-delay: calc(var(--d, 0ms) + 220ms); }

  /* ---------- report pages: the rating stamp presses down once the title is in ---------- */
  #report-hero .call .stamp { animation: rv-press 460ms var(--rv-ease) both; animation-delay: 420ms; }
}
