/*
 * Content arriving: sections fading in as the page scrolls, and the hero's text sliding in.
 * Durations, distances and the easing are tokens (tokens.css). Hover and focus states live with their
 * components. Everything here is inside a "motion allowed" media query, so visitors who ask for reduced
 * motion see every page complete and still.
 */

@layer utilities {
  /* ---- Reveal on scroll (assets/scripts/components/reveal.js) ----
     The script adds data-reveal to content below the screen, which hides it and sets it a little low.
     data-reveal="in" brings it up and in, then the script removes the attribute. Without the script, in print
     and with reduced motion nothing matches, so nothing is hidden. Only opacity and translate change, so
     nothing else on the page moves. --reveal-step (0 to 5) delays the items of a row one after another. */
  @media screen and (prefers-reduced-motion: no-preference) {
    [data-reveal] { opacity: 0; translate: 0 var(--reveal-distance); }
    [data-reveal="in"] {
      opacity: 1; translate: 0;
      transition: opacity var(--duration-l) var(--ease-out), translate var(--duration-l) var(--ease-out);
      transition-delay: calc(var(--reveal-step, 0) * var(--reveal-stagger));
    }
  }

  /* ---- Hero entrance ----
     The text of a hero with a photo slides in as on the old site, but only a short way: the title from the
     left, the intro from the right, then the buttons rise. The photo is never hidden or faded, so the page's
     largest image paints as soon as it loads. In the slider, each slide's text comes in again when the slide
     becomes the current one (carousel.js sets data-active); before the script runs, the first slide plays.
     In the slider, data-active is set once the slide has stopped moving, so the text comes in on a still
     photo; while a slide is arriving its text is hidden. The keyframes only set where the text starts, so
     without them it's simply in place. The hero clips its sides, so the text can't cause a sideways scrollbar. */
  @media (prefers-reduced-motion: no-preference) {
    .hero--image { overflow-x: clip; }
    :is(.hero--image:not(.hero__slide), .hero__viewport:not([data-carousel-ready]) .hero__slide:first-child, .hero__slide[data-active]) {
      & .hero__title { animation: slide-in-left var(--duration-l) var(--ease-out) backwards; }
      & :is(.hero__intro, .hero__text) { animation: slide-in-right var(--duration-l) var(--ease-out) 0.12s backwards; }
      & .button-group { animation: rise-in var(--duration-l) var(--ease-out) 0.24s backwards; }
    }
    .hero__viewport[data-carousel-ready] .hero__slide:not([data-active]) :is(.hero__title, .hero__intro, .hero__text, .button-group) { opacity: 0; }
  }
  @keyframes slide-in-left { from { opacity: 0; translate: calc(var(--hero-shift) * -1) 0; } }
  @keyframes slide-in-right { from { opacity: 0; translate: var(--hero-shift) 0; } }
  @keyframes rise-in { from { opacity: 0; translate: 0 calc(var(--reveal-distance) * 2); } }

  /* ---- Appear: a notice fades in and drops a little, as menus and answers do when they open ---- */
  @keyframes appear { from { opacity: 0; translate: 0 calc(var(--appear-distance) * -1); } }
}
