/* ==========================================================================
   MOTION: scroll-driven reveals for the public site
   --------------------------------------------------------------------------
   Pure CSS, driven by scroll position (animation-timeline: view()). No JS, so
   it survives Blazor enhanced navigation untouched.

   Safety rules this file keeps:
   - Everything sits inside @supports (animation-timeline: view()) and
     prefers-reduced-motion: no-preference. Browsers without support, and anyone
     who asked for reduced motion, get the page exactly as it was: visible, static.
   - Only opacity, translate, scale and clip-path move, so nothing reflows (no CLS).
   - It uses the individual `translate` / `scale` properties, never `transform`, so
     the cards' existing :hover lifts (which use transform) still compose on top.
   - Scoped to .public-layout (MainLayout), so admin and Blog Studio are untouched.
   - The home page has its own entrance system (Home2.razor); it is not repeated here.

   Easing: ease-out-cubic, a softer cousin of Home2's curve (see --mo-ease for why).
   Most ranges are in px of scroll after the element starts entering, so a tall element
   (a long itinerary day) is fully settled long before you are reading it. The grid cards
   are the exception: their ranges are in svh, so their motion finishes at the middle of
   the screen, where people actually look (Craig, 2026-11-17: "we barely get any of the
   effect because it's only just visible right at the bottom of the page").
   ========================================================================== */

@media screen and (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {

        .public-layout {
            /* Home's timed transitions use cubic-bezier(.16, 1, .3, 1), but with scroll as the
               clock that curve finishes in the first few dozen pixels and reads as a pop.
               Ease-out-cubic keeps the same character and stays visible while you scroll. */
            --mo-ease: cubic-bezier(.33, 1, .68, 1);
            /* The grid cards' glide: a soft start and a long, slow landing. With ease-out-cubic over
               320px, the reveal was 60% done while the card's top was still in the bottom tenth of
               the screen, which is why it was over before anyone looked at it. */
            --mo-glide-ease: cubic-bezier(.3, .15, .25, 1);
            --mo-settle-ease: cubic-bezier(.25, .46, .45, .94); /* ease-out-quad, for the photos */
            --mo-step: 50px; /* extra scroll per stagger step (Craig, 2026-11-17: tightened from 70px) */
        }

        /* ---------------- CARDS: fade, then glide up to a landing line ----------------
           Ranges are in svh, so they are measured where people look: the card's top edge
           against the screen, whatever the card's height (a trip card is ~700px tall).
           - Fade: from the card's top at 96% of the screen height to 70%. It finishes early,
             so a card stopped anywhere in the upper two-thirds is always fully readable.
           - Glide: from 96% to the landing line at 50%, the middle of the screen, so the last
             of the movement happens in front of the reader's eyes, not below them.
           The stagger delays only the START. Every card in a row lands on the same line, so the
           later ones visibly catch up, and no card is still moving above mid-screen. */
        .public-layout .trips-grid > .trip-card,
        .public-layout .team-grid > .team-card,
        .public-layout .blog-page-wrapper .stories-grid > .story-card,
        .public-layout .blog-page-wrapper .featured-story-card,
        .public-layout .impact-stat-card,
        .public-layout .achievement-card {
            --mo-lag: calc(var(--mo-i, 0) * var(--mo-step));
            animation: mo-fade linear both, mo-glide var(--mo-glide-ease) both;
            animation-timeline: view(), view();
            animation-range: entry calc(4svh + var(--mo-lag)) entry 30svh,
                             entry calc(4svh + var(--mo-lag)) entry 50svh;
            view-timeline: --mo-card block;
        }

        /* A gentle stagger along a row on wide screens (grids there are 3 across). */
        @media (min-width: 1024px) {
            .public-layout .trips-grid > .trip-card:nth-child(3n+2),
            .public-layout .team-grid > .team-card:nth-child(3n+2),
            .public-layout .stories-grid > .story-card:nth-child(3n+2),
            .public-layout .impact-stat-card:nth-child(3n+2),
            .public-layout .achievement-card:nth-child(3n+2) { --mo-i: 1; }

            .public-layout .trips-grid > .trip-card:nth-child(3n+3),
            .public-layout .team-grid > .team-card:nth-child(3n+3),
            .public-layout .stories-grid > .story-card:nth-child(3n+3),
            .public-layout .impact-stat-card:nth-child(3n+3),
            .public-layout .achievement-card:nth-child(3n+3) { --mo-i: 2; }
        }

        /* ---------------- PHOTOS: settle into their frame ----------------
           The cards clip their photos (overflow: hidden makes them scroll containers),
           so a photo's own view() would look at the card and never move. Instead it
           follows the card's named timeline, declared on the card above.
           It runs on past the card's landing line (to 35% of the screen), so once the card
           has arrived the photo is still visibly easing back inside its frame. A photo
           stopped mid-settle is only cropped a little tighter; nothing becomes unreadable. */
        .public-layout .trips-grid .trip-card .trip-image,
        .public-layout .team-grid .team-card-photo img,
        .public-layout .stories-grid .story-card .card-img {
            animation: mo-settle var(--mo-settle-ease) both;
            animation-timeline: --mo-card;
            animation-range: entry calc(4svh + var(--mo-lag, 0px)) entry 65svh;
        }

        /* The big featured blog photo opens like a window, on the same stretch as the photos. */
        .public-layout .blog-page-wrapper .featured-img {
            animation: mo-open var(--mo-settle-ease) both;
            animation-timeline: --mo-card;
            animation-range: entry 4svh entry 65svh;
        }

        /* ---------------- HEADINGS: rise, then the accent underline draws ----------------
           The underline starts only once the heading has mostly landed, and draws over a
           longer stretch than the rise, so the two read as two beats, not one blur. */
        .public-layout .section-title {
            animation: mo-rise-md var(--mo-ease) both;
            animation-timeline: view();
            animation-range: entry 0 entry 220px;
            view-timeline: --mo-heading block;
        }

        .public-layout .section-title::after {
            transform-origin: left center;
            animation: mo-draw-x var(--mo-ease) both;
            animation-timeline: --mo-heading;
            animation-range: entry 140px entry 380px;
        }

        /* ---------------- TRIP DETAILS: the included / not-included cards ----------------
           A little more travel than the grid cards, plus a slight lift in scale, because on
           this page they arrive one at a time and the motion has to be seen to count. */
        .public-layout .details-page-wrapper .features-block {
            transform-origin: center top;
            animation: mo-lift var(--mo-ease) both;
            animation-timeline: view();
            animation-range: entry 0 entry 360px;
        }

        /* ---------------- ITINERARY: the signature effect ----------------
           The line tracks the reader: its end sits at the middle of the screen, so it
           draws down as you scroll. entry-crossing runs from the top edge meeting the
           viewport bottom to the bottom edge meeting it, i.e. 100% = the timeline's own
           height, which makes "+ 50vh" put both ends exactly at mid-screen. */
        .public-layout .details-page-wrapper .timeline {
            view-timeline: --mo-itinerary block;
        }

        .public-layout .details-page-wrapper .timeline::before {
            transform-origin: top center;
            animation: mo-draw-y linear both;
            animation-timeline: --mo-itinerary;
            animation-range: entry-crossing 50vh entry-crossing calc(100% + 50vh);
        }

        /* Each day marker waits as a small ghost until the line reaches it, then arrives
           with a slight overshoot. The 50% bottom inset moves this timeline's viewport edge
           up to mid-screen, the same place the line's end is pinned, so the line and the
           marker meet instead of the marker popping on its own at the bottom of the screen. */
        .public-layout .details-page-wrapper .timeline-marker {
            animation: mo-arrive var(--mo-ease) both;
            animation-timeline: view(block 0 50%);
            animation-range: entry 0 entry calc(100% + 60px);
        }

        /* The day card unfolds out from behind its marker (the marker sits above it in
           z-order). It starts to the LEFT and scales from its left edge, so it can never
           push past the right edge at any width: no horizontal overflow, no media query. */
        .public-layout .details-page-wrapper .timeline-content {
            transform-origin: left center;
            animation: mo-unfold var(--mo-ease) both;
            animation-timeline: view();
            animation-range: entry 0 entry 300px;
        }

        /* ---------------- LISTS: items tick in from the bullet side, one by one ----------------
           Leftward start only, so a list row can never create horizontal overflow. */
        .public-layout .details-page-wrapper .feature-list li,
        .public-layout .details-page-wrapper .equipment-item {
            animation: mo-tick var(--mo-ease) both;
            animation-timeline: view();
            animation-range: entry 0 entry 180px;
        }
    }
}

@keyframes mo-fade     { from { opacity: 0; } to { opacity: 1; } }
@keyframes mo-glide    { from { translate: 0 80px; scale: .95; } to { translate: 0 0; scale: 1; } }
@keyframes mo-rise-md  { from { opacity: 0; translate: 0 28px; } to { opacity: 1; translate: 0 0; } }
@keyframes mo-lift     { from { opacity: 0; translate: 0 56px; scale: .95; } to { opacity: 1; translate: 0 0; scale: 1; } }
@keyframes mo-tick     { from { opacity: 0; translate: -18px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes mo-settle   { from { scale: 1.14; } to { scale: 1; } }
@keyframes mo-open     { from { clip-path: inset(10% 12% 10% 12% round 1rem); scale: 1.08; } to { clip-path: inset(0 0 0 0 round 0); scale: 1; } }
@keyframes mo-draw-x   { from { scale: 0 1; } to { scale: 1 1; } }
@keyframes mo-draw-y   { from { scale: 1 0; } to { scale: 1 1; } }
@keyframes mo-arrive   { 0% { opacity: .5; scale: .7; } 65% { opacity: 1; scale: 1.12; } 100% { opacity: 1; scale: 1; } }
@keyframes mo-unfold   { from { opacity: 0; translate: -40px 0; scale: .94; } to { opacity: 1; translate: 0 0; scale: 1; } }
