/* =========================================================================
   Section motion (Builder animation picker + the site-wide scroll reveal)
   =========================================================================
   See lib/themes/animations.ts for the catalog. SectionRouter — and the one
   custom template that opts into the section engine (templates/aloha-tattoos)
   — emits a hidden <span data-animation="{slug}"> MARKER immediately before a
   section. CSS targets the [data-section] element that FOLLOWS the marker
   (`+`), or its descendants depending on the effect.

   Linked by ThemeShell (every themed render) and by AlohaTattoosShell. It
   lived at the end of sections.css until 2026-10-12; it is its own sheet so
   a custom template can carry the markers without loading 500 KB of section
   rules it never uses.

   🚨 Adjacent-sibling, never a wrapper. The marker replaced a
   display:contents span around the section on 2026-09-02: a wrapped
   <section> is not a child of the framework element, so the positional
   colour recipes (`> .slot:nth-of-type(odd)`) skipped it and renumbered
   every section after it — docs/SECTION-RECIPES.md §0b, measured on a
   paying client. A hidden span is not a <section>, so it never enters that
   count.

   Reduced motion: every @keyframes block below is gated on
   `@media (prefers-reduced-motion: no-preference)` so OS-level
   accessibility wins. The 'off' slug uses the existing
   `[data-animations-off="true"]` selector (data.ts maps 'off' onto
   that wrapper attr for back-compat with the legacy section_animations_off
   render path).

   SCROLL REVEAL (2026-10-12) — how an entrance motion fires when the section
   is SEEN rather than when the page loads:

     1. With no script, the rules below run on first paint, exactly as they
        did before. A section below the fold animates unseen and is simply
        there when the reader reaches it. Nothing is ever hidden without a
        script to show it again.
     2. components/themes/SectionReveal.tsx marks every section already in
        view `.ta-in`, THEN adds `.ta-io` to <html>. Under `.ta-io`, an
        entrance section that is not yet `.ta-in` holds `animation: none;
        opacity: 0` — and when the IntersectionObserver adds `.ta-in`, the
        base rule applies again and the keyframes start from the top.
     3. The hidden state holds OPACITY ONLY, never a transform. A held
        transform makes the section the containing block for any
        position:fixed child (the nav trap, check-nav-mobile 2026-09-26);
        opacity does not, and the keyframes' own `from` supplies the offset
        the instant the animation begins, so nothing is lost visually.

   `.ta-fine` is the same gate for the free-standing content of an interior
   page (headings, paragraphs, figures outside any section) when the
   site-wide motion is on; `data-site-motion` on the shell root names which
   motion, so a slide-up site slides its paragraphs too.
   ========================================================================= */

@media (prefers-reduced-motion: no-preference) {

  /* fade-in: section fades from 0 → 1 opacity over 800ms.
     🚨 Never `both`/`forwards` on a transform: a held transform (even the
     identity) makes the section the containing block for position:fixed
     children, so a nav with this animation trapped its full-screen phone
     menu inside the header (check-nav-mobile, 2026-09-26). The end state is
     the base style, so nothing needs holding. */
  [data-animation="fade-in"] + [data-section] {
    animation: ta-fade-in 0.8s ease-out 0.1s both;
  }
  @keyframes ta-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  /* slide-up: 24px translate from below + fade-in */
  [data-animation="slide-up"] + [data-section] {
    animation: ta-slide-up 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
  }
  @keyframes ta-slide-up {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* slide-left / slide-right: horizontal entrance + fade (Aloha port,
     2026-08-17 — the source site's sections slide in alternately from
     the sides). 32px is deliberate: far enough to read as direction,
     small enough that content never leaves the viewport on a phone, so
     no horizontal overflow. The section wrapper keeps overflow-x
     clipped during the animation for belt-and-braces. */
  [data-animation="slide-left"] + [data-section],
  [data-animation="slide-right"] + [data-section] {
    overflow-x: clip;
  }
  [data-animation="slide-left"] + [data-section] {
    animation: ta-slide-left 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
  }
  @keyframes ta-slide-left {
    from { opacity: 0; transform: translateX(-32px); }
    to   { opacity: 1; transform: translateX(0); }
  }
  [data-animation="slide-right"] + [data-section] {
    animation: ta-slide-right 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
  }
  @keyframes ta-slide-right {
    from { opacity: 0; transform: translateX(32px); }
    to   { opacity: 1; transform: translateX(0); }
  }

  /* stagger: children of the section enter one at a time, 80ms gap.
     Caller writes child markup with `.slot__item` or a similar class;
     this catalog assumes the variant exposes direct children that can
     be animated. We use `:nth-child(n)` delays up to 12 items. */
  [data-animation="stagger"] + [data-section] > * {
    animation: ta-fade-in 0.6s ease-out both;
  }
  [data-animation="stagger"] + [data-section] > *:nth-child(1)  { animation-delay: 0.05s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(2)  { animation-delay: 0.13s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(3)  { animation-delay: 0.21s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(4)  { animation-delay: 0.29s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(5)  { animation-delay: 0.37s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(6)  { animation-delay: 0.45s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(7)  { animation-delay: 0.53s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(8)  { animation-delay: 0.61s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(9)  { animation-delay: 0.69s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(10) { animation-delay: 0.77s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(11) { animation-delay: 0.85s; }
  [data-animation="stagger"] + [data-section] > *:nth-child(12) { animation-delay: 0.93s; }

  /* zoom-in: from scale 0.95 + opacity 0 → scale 1 + opacity 1 */
  [data-animation="zoom-in"] + [data-section] {
    animation: ta-zoom-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
  }
  @keyframes ta-zoom-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
  }

  /* spin: a slight tilt + scale, rotating up to level while fading in. Same
     fill rule as the slides: `backwards`, never held. */
  [data-animation="spin"] + [data-section] {
    animation: ta-spin 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
  }
  @keyframes ta-spin {
    from { opacity: 0; transform: rotate(-4deg) scale(0.94); }
    to   { opacity: 1; transform: rotate(0) scale(1); }
  }

  /* drift: a slow float, up and back, for as long as the section is on the
     page. Continuous, so it is NOT gated below — and it does hold a
     transform; that is why the catalog keeps it off the nav, the utility bar
     and the footer (lib/themes/animations.ts), the three with fixed-position
     descendants. */
  [data-animation="drift"] + [data-section] {
    animation: ta-drift 9s ease-in-out infinite alternate;
  }
  @keyframes ta-drift {
    from { transform: translateY(0); }
    to   { transform: translateY(-14px); }
  }

  /* --- the scroll-reveal gate (see the header) ---------------------------
     Only the ENTRANCE motions above are gated: the continuous ones below
     (Ken Burns, parallax, glow, ticker) are meant to be running whenever the
     section is on screen and lose nothing by starting early. */
  .ta-io [data-animation="fade-in"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="slide-up"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="slide-left"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="slide-right"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="zoom-in"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="spin"] + [data-section]:not(.ta-in),
  .ta-io [data-animation="stagger"] + [data-section]:not(.ta-in) > * {
    animation: none;
    opacity: 0;
  }

  /* Free-standing interior content under a site-wide motion. A transition
     rather than keyframes: these are small elements that need no delay
     choreography, and a transition cannot "run unseen" the way a keyframe
     on first paint can. The offset is the same the section keyframes use.
     The TRANSFORM is held only while hidden — a paragraph or figure has no
     position:fixed child, so the containing-block trap above does not
     apply, and `.ta-in` releases it anyway.
     The transition is declared on the REVEALED state only, so going hidden
     when the gate first closes is instant (a 0.7s fade-out on something the
     reader is about to scroll to would be seen) and only the reveal eases. */
  .ta-io .ta-fine.ta-in {
    transition:
      opacity 0.7s ease-out,
      transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .ta-io .ta-fine:not(.ta-in) { opacity: 0; }
  .ta-io [data-site-motion="slide-up"] .ta-fine:not(.ta-in) { transform: translateY(18px); }
  .ta-io [data-site-motion="slide-left"] .ta-fine:not(.ta-in) { transform: translateX(-24px); }
  .ta-io [data-site-motion="slide-right"] .ta-fine:not(.ta-in) { transform: translateX(24px); }
  .ta-io [data-site-motion="zoom-in"] .ta-fine:not(.ta-in) { transform: scale(0.97); }

  /* ken-burns: hero-specific. Slow pan + zoom on every <img> inside.
     Variants that already include kenburns inside their markup
     (HeroD) are unaffected because the rule targets the wrapper, not
     the .hero-kenburns elements those variants use. Duration 20s
     ease-in-out, alternating direction so it pans back. */
  [data-animation="ken-burns"] + [data-section] img {
    animation: ta-ken-burns 20s ease-in-out infinite alternate;
    transform-origin: center;
  }
  @keyframes ta-ken-burns {
    from { transform: scale(1) translate(0, 0); }
    to   { transform: scale(1.08) translate(-2%, -1%); }
  }

  /* parallax: shift the background or first image inside the section
     by a few pixels relative to scroll position. Simplest fallback is
     a slow infinite drift; a richer version would use scroll-timeline. */
  [data-animation="parallax"] + [data-section] {
    background-attachment: fixed;
  }
  [data-animation="parallax"] + [data-section] img:first-of-type {
    will-change: transform;
    transition: transform 0.4s ease-out;
  }

  /* glow: subtle pulsing accent ring on the section. Useful for CTAs
     and trust badges. */
  [data-animation="glow"] + [data-section] {
    animation: ta-glow 3s ease-in-out infinite;
  }
  @keyframes ta-glow {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #c9a96e) 0%, transparent); }
    50%      { box-shadow: 0 0 32px 4px color-mix(in srgb, var(--accent, #c9a96e) 18%, transparent); }
  }


  /* ticker: utility-bar announcements scroll as a marquee.
     UtilityBarF renders the notice row twice — the second copy is
     aria-hidden and hidden outright until this animation turns it on.
     Two identical tracks translated a full width left is what makes the
     loop seamless; with one track the row would visibly snap back.

     Duration scales with nothing — a fixed 28s reads steady whether the
     shop wrote one line or five, and the row simply repeats sooner when
     there is less of it. Paused on hover so a reader can finish a line
     they care about, which is the difference between an announcement and
     a thing that scrolls past.

     Living inside the reduced-motion guard is the whole safety story:
     without it the bar is a static centred row and every notice is still
     on the page. */
  [data-animation="ticker"] + [data-section="utility-bar"] .ub-notice__viewport {
    overflow: hidden;
    flex-wrap: nowrap;
    justify-content: flex-start;
    mask-image: linear-gradient(90deg, transparent 0, #000 40px, #000 calc(100% - 40px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 40px, #000 calc(100% - 40px), transparent 100%);
  }
  [data-animation="ticker"] + [data-section="utility-bar"] .ub-notice__track {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    animation: ta-ub-ticker 28s linear infinite;
  }
  [data-animation="ticker"] + [data-section="utility-bar"] .ub-notice__track--loop {
    display: flex;
  }
  [data-animation="ticker"] + [data-section="utility-bar"] .ub-notice:hover .ub-notice__track {
    animation-play-state: paused;
  }
  @keyframes ta-ub-ticker {
    from { transform: translateX(0); }
    to   { transform: translateX(-100%); }
  }

} /* end @media prefers-reduced-motion */
