/* =============================================================
   Scroll-reveal — pure-CSS entrance / scroll-driven animation layer.

   ARCHITECTURE INVARIANT (do not regress):
   Content visibility must NEVER depend on JavaScript. No static
   rule in this file (or anywhere in the theme) may set opacity:0
   on content. The "hidden" state exists only INSIDE CSS animations:

     - Scroll reveals use `animation-timeline: view()` guarded by
       @supports. The animation state derives from the element's
       viewport geometry — there is no event/callback to miss, so
       nothing can be left stranded hidden. Browsers without
       support simply show the content with no scroll animation.

     - One-shot hero entrances (here and in per-page CSS) use
       time-based `animation: … both`, which always finishes at
       the visible end state on its own.

   Everything is additionally wrapped in
   `@media screen and (prefers-reduced-motion: no-preference)`,
   so reduced-motion and print get plain visible content.

   HISTORY: the previous system pre-hid content with static
   opacity:0 (html.js-reveal-pre + .reveal, plus per-page
   .is-revealed/.is-active gates) and revealed via JS
   (IntersectionObserver / main.js). IO delivered zero callbacks in
   some mobile conditions and WP Rocket "Delay JavaScript execution"
   held main.js until first interaction, leaving content permanently
   hidden across the site. Keep any future animation work inside the
   invariant above.
   ============================================================= */

@supports (animation-timeline: view()) {
  @media screen and (prefers-reduced-motion: no-preference) {

    /* ------------------------------------------------------------
       Cascading fade + rise: the top-level children of each section
       group animate in as they enter the viewport. This list mirrors
       the old scroll-reveal.js `groups` array.

       Deliberately ABSENT from this list:
         - .at-final-cta-inner > * and .at-footer-top > * — at the
           very end of the document their `entry` range may never
           complete (not enough scroll left), which would strand
           them semi-transparent. They stay always-visible; the
           footer stack still has its own JS-driven grow effect.
         - .news-row__track > * — the track is its own (horizontal)
           scroll container, so view() would resolve against the
           wrong scrollport. Cards stay always-visible.
         - .careers-hero-inner > * and the news editorial hero —
           above the fold, they get a time-based load cascade below
           instead (view() is a no-op for content already past its
           entry range at load).
       ------------------------------------------------------------ */
    .at-pitch-inner             > *,
    .at-workflow-panel-inner    > *,
    .at-dealers-grid            > *,
    .at-solutions-content       > *,
    .at-twocards-inner          > *,
    .at-partners                > *,
    .at-faq-inner               > *,
    .at-faq-list                > *,
    .news-grid                  > *,
    .about-why                  > *,
    .about-process__head        > *,
    .about-timeline             > *,
    .alttune-page--careers .about-row-1 > *,
    .alttune-page--careers .about-row-2 > *,
    .openings-head              > *,
    .opening-stack              > *,
    .bad-split__copy            > * {
      animation: at-sr-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 35%;
    }

    /* Per-sibling stagger, expressed as scroll-range offsets (time
       delays don't apply to scroll timelines). Later siblings start
       and finish deeper into the entry, which reads as the same
       left→right / top→bottom cascade the JS stagger produced. */
    .at-pitch-inner             > :nth-child(2),
    .at-workflow-panel-inner    > :nth-child(2),
    .at-dealers-grid            > :nth-child(2),
    .at-solutions-content       > :nth-child(2),
    .at-twocards-inner          > :nth-child(2),
    .at-partners                > :nth-child(2),
    .at-faq-inner               > :nth-child(2),
    .at-faq-list                > :nth-child(2),
    .news-grid                  > :nth-child(2),
    .about-why                  > :nth-child(2),
    .about-process__head        > :nth-child(2),
    .about-timeline             > :nth-child(2),
    .alttune-page--careers .about-row-1 > :nth-child(2),
    .alttune-page--careers .about-row-2 > :nth-child(2),
    .openings-head              > :nth-child(2),
    .opening-stack              > :nth-child(2),
    .bad-split__copy            > :nth-child(2) {
      animation-range: entry 8% entry 43%;
    }
    .at-pitch-inner             > :nth-child(3),
    .at-workflow-panel-inner    > :nth-child(3),
    .at-dealers-grid            > :nth-child(3),
    .at-solutions-content       > :nth-child(3),
    .at-twocards-inner          > :nth-child(3),
    .at-partners                > :nth-child(3),
    .at-faq-inner               > :nth-child(3),
    .at-faq-list                > :nth-child(3),
    .news-grid                  > :nth-child(3),
    .about-why                  > :nth-child(3),
    .about-process__head        > :nth-child(3),
    .about-timeline             > :nth-child(3),
    .alttune-page--careers .about-row-1 > :nth-child(3),
    .alttune-page--careers .about-row-2 > :nth-child(3),
    .openings-head              > :nth-child(3),
    .opening-stack              > :nth-child(3),
    .bad-split__copy            > :nth-child(3) {
      animation-range: entry 15% entry 50%;
    }
    .at-pitch-inner             > :nth-child(n+4),
    .at-workflow-panel-inner    > :nth-child(n+4),
    .at-dealers-grid            > :nth-child(n+4),
    .at-solutions-content       > :nth-child(n+4),
    .at-twocards-inner          > :nth-child(n+4),
    .at-partners                > :nth-child(n+4),
    .at-faq-inner               > :nth-child(n+4),
    .at-faq-list                > :nth-child(n+4),
    .news-grid                  > :nth-child(n+4),
    .about-why                  > :nth-child(n+4),
    .about-process__head        > :nth-child(n+4),
    .about-timeline             > :nth-child(n+4),
    .alttune-page--careers .about-row-1 > :nth-child(n+4),
    .alttune-page--careers .about-row-2 > :nth-child(n+4),
    .openings-head              > :nth-child(n+4),
    .opening-stack              > :nth-child(n+4),
    .bad-split__copy            > :nth-child(n+4) {
      animation-range: entry 22% entry 57%;
    }

    /* The process steps row cascades as a group too; its three
       illustrations keep a bespoke reveal in page-about.css. */
    .about-process__steps > * {
      animation: at-sr-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 35%;
    }
    .about-process__steps > :nth-child(2)   { animation-range: entry 6% entry 41%; }
    .about-process__steps > :nth-child(3)   { animation-range: entry 12% entry 47%; }
    .about-process__steps > :nth-child(n+4) { animation-range: entry 18% entry 53%; }

    /* ---- Soft units: the container fades in as one block. ---- */
    .at-trusted,
    .at-workflow-card,
    .news-row__head,
    .bad-split__media,
    .at-solutions--static .at-solutions-banner,
    .alttune-page--about .at-section.dark .at-section-head,
    .alttune-page--careers .app-form {
      animation: at-sr-fade linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 25%;
    }

    @keyframes at-sr-rise {
      from { opacity: 0; transform: translate3d(0, 26px, 0); }
      to   { opacity: 1; transform: translate3d(0, 0, 0); }
    }
    @keyframes at-sr-fade {
      from { opacity: 0; }
      to   { opacity: 1; }
    }
  }
}

/* ----------------------------------------------------------------
   Above-the-fold load cascades (time-based, universal support).
   `both` fill guarantees these always end visible on their own.
   ---------------------------------------------------------------- */
@media screen and (prefers-reduced-motion: no-preference) {

  /* Careers hero: text column children then the photo. */
  .careers-hero-inner > * {
    animation: at-sr-load-rise 800ms cubic-bezier(.22, .61, .36, 1) both;
  }
  .careers-hero-inner > :nth-child(2)   { animation-delay: 140ms; }
  .careers-hero-inner > :nth-child(n+3) { animation-delay: 280ms; }

  /* News editorial hero: head first, then the three grid columns. */
  .news-hero-editorial__head {
    animation: at-sr-load-fade 700ms cubic-bezier(.22, .61, .36, 1) both;
  }
  .news-hero-editorial__grid > * {
    animation: at-sr-load-rise 800ms cubic-bezier(.22, .61, .36, 1) 150ms both;
  }
  .news-hero-editorial__grid > :nth-child(2)   { animation-delay: 280ms; }
  .news-hero-editorial__grid > :nth-child(n+3) { animation-delay: 410ms; }

  @keyframes at-sr-load-rise {
    from { opacity: 0; transform: translate3d(0, 22px, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 0); }
  }
  @keyframes at-sr-load-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}
