/* ============================================================
   Biohma — motion system
   Rule: animate transform + opacity only. One easing family.
   Primary mechanism: native scroll-driven animations
   (animation-timeline: view()), progressively enhanced —
   a JS IntersectionObserver fallback (main.js) drives the same
   classes on browsers without support. Reduced motion cuts both.
   ============================================================ */

@property --hk { syntax: '<number>'; inherits: true; initial-value: 0; }

@keyframes hero-bg-in    { from { opacity: 0; transform: scale(1.035); } to { opacity: 1; transform: none; } }
@keyframes hero-fade-up  { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes icon-draw     { to { stroke-dashoffset: 0; } }
@keyframes ig-pulse      { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes parallax-up   { from { transform: translateY(3%); } to { transform: translateY(-3%); } }
@keyframes hk-in         { from { --hk: 0; } to { --hk: 1; } }

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

  /* ---------- Reveal on enter: generic cards -------------------------- */
  [data-reveal] { opacity: 0; transform: translateY(24px); }
  [data-reveal="eyebrow"] { transform: translateX(-12px); }
  [data-reveal="eyebrow"] .eyebrow-line { transform: scaleX(0); transform-origin: left center; }
  [data-reveal="img"] { transform: scale(1.04); }

  [data-reveal].is-in,
  [data-reveal="eyebrow"].is-in,
  [data-reveal="img"].is-in {
    opacity: 1; transform: none;
    transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
  }
  [data-reveal="eyebrow"].is-in { transition-duration: 700ms; }
  [data-reveal="eyebrow"].is-in .eyebrow-line { transform: scaleX(1); transition: transform 900ms var(--ease-out) 200ms; }
  [data-reveal="img"].is-in { transition-duration: 1400ms; }

  /* ---------- Headline mask: real per-line clip-reveal -----------------
     [data-reveal="mask"] also matches the bare [data-reveal] selector
     above (same specificity, attribute present either way), so it inherits
     opacity:0 there — cancel that here. The heading block itself is always
     visible; main.js's buildMask() does the hiding per line via
     .mask-line (overflow:hidden) wrapping .mask-line-inner
     (translateY(100%) -> 0). Reduced motion skips the split in JS entirely,
     so these classes never exist there and this rule is moot. */
  [data-reveal="mask"] { opacity: 1; transform: none; }
  .mask-line { display: block; overflow: hidden; }
  .mask-line-inner { display: block; transform: translateY(100%); transition: transform var(--dur-slow) var(--ease-out); }
  [data-reveal="mask"].is-in .mask-line-inner { transform: translateY(0); }

  /* Note: reveal-on-enter deliberately uses the IntersectionObserver + class
     path on every browser, not animation-timeline: view(). The native
     timeline is still used below for parallax (cosmetic, safe to no-op),
     but gating actual content visibility on a still-uneven-support scroll
     API risked a permanently-invisible section on browsers/engines that
     report support but never advance the timeline. Correctness for content
     wins over the compositor-only path here. */

  /* ---------- Icon draw-in (chapter openers, stat band only) ---------- */
  .icon--draw path, .icon--draw circle, .icon--draw ellipse, .icon--draw rect {
    stroke-dasharray: 1; stroke-dashoffset: 1;
  }
  .icon--draw.is-in path, .icon--draw.is-in circle, .icon--draw.is-in ellipse, .icon--draw.is-in rect {
    animation: icon-draw 1000ms var(--ease-out) forwards;
  }
  .icon--draw.is-in path:nth-child(2), .icon--draw.is-in circle:nth-child(2) { animation-delay: 60ms; }
  .icon--draw.is-in path:nth-child(3), .icon--draw.is-in circle:nth-child(3) { animation-delay: 120ms; }
  .icon--draw.is-in path:nth-child(4), .icon--draw.is-in circle:nth-child(4) { animation-delay: 180ms; }
  .icon--draw.is-in path:nth-child(5), .icon--draw.is-in circle:nth-child(5) { animation-delay: 240ms; }

  /* ---------- Globe infographic (.ig): a four-step construction, once ----
     1 the graticule draws itself in, stroke by stroke (every circle/path
     in it has pathLength="1", same technique as the continent below, not
     a fade — a sphere that just faded up read as weightless, not built)
     · 2 continent draws, then its fill fades in on top of the now-finished
     wireframe · 3 ring scales in, then keeps pulsing (.ig-pulso, below) ·
     4 the three icons draw in, 60ms apart. No leader/arrow any more (the
     globe sits beside the headline sentence instead of pointing at a
     number — see .ig-beat in components.css) and no count-up either, so
     those two steps of the original six dropped.
     Every step is gated behind .ig.is-in (main.js, same [data-reveal]
     IntersectionObserver as the rest of the page) so under reduced motion,
     where that class-driven CSS block doesn't apply at all, every element
     simply sits at its normal, final, undelayed appearance — including
     .ig-pulso, which stays at its base opacity:0 (a static ring, not an
     animated one) rather than looping. Graticule opacity is .85, not the
     .55 (and before that .34) it went through earlier — even a fully-drawn
     stroke in the original --grade-globo tone still read as barely-there
     against the paper ground, so the token itself moved darker too (see
     tokens.css). */
  .ig-grade circle, .ig-grade path {
    stroke-dasharray: 1; stroke-dashoffset: 1; opacity: .85;
    transition: stroke-dashoffset 1300ms var(--ease-out);
  }
  .ig.is-in .ig-grade circle, .ig.is-in .ig-grade path { stroke-dashoffset: 0; }

  /* The continent's fill (var(--paper), opaque — see index.html) would
     otherwise sit there solid from frame one, showing a continent-shaped
     hole in the still-drawing graticule before its own stroke has even
     drawn in; fill-opacity holds it back until the stroke is done, then
     fades it in, so the land reads as filling in AFTER it's outlined. */
  #america-do-sul path {
    stroke-dasharray: 1; stroke-dashoffset: 1; fill-opacity: 0;
    transition: stroke-dashoffset 900ms var(--ease-out) 1000ms, fill-opacity 500ms var(--ease-out) 1800ms;
  }
  .ig.is-in #america-do-sul path { stroke-dashoffset: 0; fill-opacity: 1; }

  #marca-amazonia {
    transform-box: fill-box; transform-origin: center; opacity: 0; transform: scale(.88);
    transition: opacity 400ms var(--ease-out) 2000ms, transform 400ms var(--ease-out) 2000ms;
  }
  .ig.is-in #marca-amazonia { opacity: 1; transform: scale(1); }

  /* A second, identical ring (.ig-pulso, same centre/radius, stroke-only)
     laid over the static one — the static ring stays crisp and readable
     at all times; this one expands and fades on a loop, radar-ping style,
     starting right as the real ring finishes its own scale-in (2400ms)
     so the two don't visually compete during the entrance. */
  .ig-pulso {
    transform-box: fill-box; transform-origin: center;
    opacity: 0; pointer-events: none;
  }
  .ig.is-in .ig-pulso { animation: ig-pulse 2200ms var(--ease-out) 2400ms infinite; }

  /* ---------- Parallax photo blocks ------------------------------------ */
  @supports (animation-timeline: view()) {
    .supports-stl [data-parallax] > * {
      animation: parallax-up linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
  }
  /* The "respiro" block (js/main.js, [data-parallax-js]) is driven by JS
     scroll math unconditionally, never by animation-timeline — a browser
     can pass the @supports check for that property while still failing to
     actually advance the timeline on scroll, which silently wins the
     cascade over any JS-set inline transform and freezes the effect. */

  /* ---------- Hero: one choreographed intro, once on load ----------------
     Order: photo eases up out of the deep-green base, then headline, lede,
     buttons and dots follow in a fixed stagger. Nothing is ever visible
     before its turn — the photo used to paint instantly (cached on a return
     visit) while the text trickled in behind it.
     `backwards` fill only: the animation holds the *start* state during the
     delay and then hands control back, so it can never pin opacity/transform
     against the slider's own transitions on the headlines.
     The wrapper (.hero__slides) is what animates, not the h1s. */
  .hero__bg { animation: hero-bg-in 1800ms var(--ease-out) backwards; }
  .hero__inner > * { animation: hero-fade-up 1000ms var(--ease-out) calc(380ms + var(--k, 0) * 140ms) backwards; }
  .hero__inner > :nth-child(2) { --k: 1; }
  .hero__inner > :nth-child(3) { --k: 2; }
  .hero__inner > :nth-child(4) { --k: 3; }

  /* ---------- Sibling stagger --------------------------------------------
     main.js sets --i on every [data-reveal] element regardless of
     scroll-timeline support (the reveal itself is always IO-driven — see
     note above), so this must not be scoped to .no-stl. */
  [data-reveal].is-in { transition-delay: calc(var(--i, 0) * var(--stagger)); }

  /* ---------- Header solidify --------------------------------------------
     --hk drives only .site-header's background/border alpha (layout.css) —
     never a layout-affecting property (height was dropped: animating it
     forced a synchronous layout every scroll-timeline frame across the
     entire 0-120px range, which is exactly the site's first-scroll jank).
     Scroll-driven natively where supported — no transition, no main.js
     write, so the sticky header never has to wait on the main thread
     mid-scroll. main.js keeps a JS fallback (rAF + a plain transition) for
     browsers without scroll(): see the .no-stl rule. */
  @supports (animation-timeline: scroll()) {
    .supports-stl .site-header { animation: hk-in linear both; animation-timeline: scroll(root); animation-range: 0 120px; }
  }
  .no-stl .site-header { transition: background var(--dur-base) var(--ease-standard), border-color var(--dur-base) var(--ease-standard); }

  /* ---------- View Transitions ------------------------------------------ */
  @supports (view-transition-name: none) {
    ::view-transition-group(brand-logo) { animation-duration: var(--dur-slow); }
    ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 480ms; animation-timing-function: var(--ease-standard); }
  }
}

/* View Transitions: element identity across cross-document navigation.
   Requires <meta name="view-transition" content="same-origin"> in <head>
   (added to every page) — without it the browser never starts a
   cross-document transition and these names are inert.
   Assignment itself isn't gated by prefers-reduced-motion (naming an
   element doesn't move anything); the actual crossfade/morph is suppressed
   below for users who asked for reduced motion. */
@supports (view-transition-name: none) {
  /* Logo: named only on the header's copy — see .site-header .logo-link in layout.css. */

  /* Deliberately NOT named: the hero photo and the page <h1>. A named
     element is lifted out of the root snapshot and painted in its own group
     *above* it, so on a return to the home page the photo showed up first,
     over the still-fading root (scrim, headline, buttons), and the rest
     popped in after. Left unnamed they cross-fade together with the page,
     and the hero intro (see "Hero" above) then plays on the new page. */
}

@media (prefers-reduced-motion: reduce) {
  @supports (view-transition-name: none) {
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  }
}

/* Slide crossfade for the home hero — always transform/opacity, motion-gated by JS via inline style removal.
   Sequenced, not crossfaded: the outgoing headline leaves quickly (420ms, this
   rule) before the incoming one arrives more deliberately (1000ms, the .is-active
   rule below) — main.js holds the gap between the two so the two never overlap.
   The background photo still crossfades freely (see .hero-bg-slide). */
.hero-slide {
  grid-area: 1 / 1; align-self: end; margin: 0; opacity: 0; transform: translateY(14px);
  transition: opacity 420ms var(--ease-standard), transform 420ms var(--ease-standard);
  pointer-events: none;
}
.hero-slide.is-active {
  opacity: 1; transform: none; pointer-events: auto;
  transition: opacity 1000ms var(--ease-out), transform 1000ms var(--ease-out);
}
.hero-bg-slide { position: absolute; inset: 0; display: block; opacity: 0; transition: opacity 1600ms var(--ease-standard); }
.hero-bg-slide.is-active { opacity: 1; }
