/* Semi-parallax, pure CSS, using scroll-driven animations.

   The idea: an image sits inside a frame with `overflow: clip`. The image is
   taller than the frame, so there is spare room to slide it. A normal
   @keyframes animation moves it, but instead of running on a clock it is tied
   to scroll position via `animation-timeline`.

     scroll()  progress = how far the page has scrolled      (used by the hero)
     view()    progress = how far an element has crossed the viewport (used by bands)

   "Semi" = the image moves only a fraction slower than the page, enough to feel
   depth without making anyone seasick. */

@layer effects {
  /* Static base styles: what every browser sees */
  .parallax-band {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 70svh;
    padding: var(--space-xl) var(--space-m);
    overflow: clip;
    isolation: isolate;
    color: var(--color-on-image);
    text-align: center;

    & .parallax-img {
      position: absolute;
      inset-inline: 0;
      /* 30% taller than the frame (15% spare above and below) = room to slide */
      inset-block: -15%;
      z-index: -2;
      width: 100%;
      height: 130%;
      object-fit: cover;
    }

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: -1;
      background: rgb(0 0 0 / 0.4);
    }

    & blockquote {
      display: grid;
      gap: var(--space-s);
      max-width: 40ch;
      font-size: var(--step-2);
      font-weight: 600;
      line-height: 1.3;
      text-wrap: balance;
    }

    & cite {
      font-size: var(--step-0);
      font-style: normal;
      font-weight: 400;
      opacity: 0.85;
    }
  }

  /* Motion only for browsers that support it AND users who haven't opted out */
  @supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      /* Hero: image drifts down at ~30% of scroll speed, so it appears to lag
         behind the content. Range: from page top until 100svh scrolled. */
      .hero .hero-media {
        animation: hero-drift linear both;
        animation-timeline: scroll(root block);
        animation-range: 0 100svh;
      }

      @keyframes hero-drift {
        to {
          translate: 0 30%;
        }
      }

      /* Content fades out and rises a little as you leave the hero */
      .hero .hero-content {
        animation: hero-fade linear both;
        animation-timeline: scroll(root block);
        animation-range: 0 60svh;
      }

      @keyframes hero-fade {
        to {
          opacity: 0;
          translate: 0 -3rem;
        }
      }

      /* Mt. Makiling showcase: a "reveal" instead of a drift. The photo
         starts zoomed in and pulls back to the full view as the section
         scrolls into place, then the text rises in. view() = this element's
         own trip through the viewport, so it works wherever the section sits. */
      .view-showcase img {
        animation: view-reveal linear both;
        animation-timeline: view();
        animation-range: entry 0% cover 50%;
      }

      @keyframes view-reveal {
        from { scale: 1.25; }
        to   { scale: 1; }
      }

      .view-showcase .view-content {
        animation: rise-in linear both;
        animation-timeline: view();
        /* Done by the time the section's bottom edge (where the text is)
           reaches the bottom of the screen, so the text is never half-faded */
        animation-range: entry 20% entry 90%;
      }

      @keyframes rise-in {
        from { opacity: 0; translate: 0 2rem; }
      }

      /* Bands: the hook is ready, and the motion is yours to write (see TODO below) */
      .parallax-band .parallax-img {
        animation: band-drift linear both;
        animation-timeline: view();
        /* TODO(you): animation-range: <start> <end>;
           Common choices:
             cover 0% cover 100%   → moves the whole time the band is on screen
             entry 0% exit 100%    → same as above, written in phases
             contain 0% contain 100% → only while fully visible (snappier) */
      }

      /* TODO(you): write the band-drift keyframes (5-ish lines).
         The image has 15% of spare room above and below (see .parallax-img).
           @keyframes band-drift {
             from { translate: 0 ??%; }
             to   { translate: 0 ??%; }
           }
         Trade-off: ±5% is subtle and calm; ±12% is dramatic but can reveal
         the frame's edges if you exceed the spare room (try it and watch).
         Remember translate % is relative to the IMAGE height (130% of the band). */
    }
  }
}
