/* alive.css: movement tied to scroll, as a layer on top of a still page.
   The other half is assets/js/alive.js. Read its header first.

   T10 (the final version): this is round 1's kit (branch experiment/alive,
   tag version/round1), cut down to what Lars picked: the light that brings
   labels, headings and the statement up word by word, the dim over the hero,
   and the soft change between pages. Round 1's black-and-white pictures, the
   lamps behind the cards and its still red light are not here: the artists
   stay in colour and Axel's drifting glow is back (T10 brief, items 03, 13).

   The order of things in this file is the whole method:

   1. Nothing here applies until alive.js has put .alive on <html>. No script,
      Reduce Motion, or ?alive=off: none of these rules match, and the page is
      the still page, complete and readable.
   2. An effect is a set of @keyframes and one rule that names it. The keyframes
      describe the journey from "not reached" to "arrived"; they say nothing
      about time or scroll.
   3. Two drivers can play those keyframes. .alive-css is the browser's own
      scroll timeline, which runs off the main thread, so it stays in step with
      the finger even when iPhone battery saving caps scripts at 30 frames a
      second. .alive-js is for browsers without scroll timelines: the animation
      is paused and alive.js scrubs it by hand through --alive-p.
   4. Because the script driver can lag the finger by a frame, only effects
      that change LIGHT (opacity) may be named under plain .alive. An effect
      that TRAVELS (translate, scale) is named under .alive-css only, so a
      browser on the script driver simply keeps that element still. A late
      frame of light is invisible; a late frame of position is a wobble. */

/* --- The drivers ------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  /* Longhands only. The `animation` shorthand resets animation-timeline, and
     the order of these blocks must not matter. */
  html.alive [data-alive] {
    animation-timing-function: linear;
    animation-fill-mode: both;
  }

  /* The script driver: paused, and moved by a negative delay. --alive-p runs
     0 to 1, so the animation sits p of the way through its one second. */
  html.alive-js [data-alive] {
    animation-duration: 1s;
    animation-play-state: paused;
    animation-delay: calc(var(--alive-p, 0) * -1s);
  }

  @supports (animation-timeline: view()) {
    /* The browser's driver. By default an element is watched as it crosses
       the screen itself. The range comes from data-alive-range, which
       alive.js copies into these three properties. */
    html.alive-css [data-alive] {
      /* Firefox wants a duration that is not zero before it will run a
         scroll-driven animation; the timeline replaces it everywhere. */
      animation-duration: 1ms;
      /* "0px": measured against the real edges of the screen. Left to itself
         a view timeline shrinks the screen by the page's scroll-padding (the
         room main.css keeps for the fixed header), so "leaving the screen"
         would end a header's height early, and the script driver, which
         measures the real screen, would disagree with it by an eighth. */
      animation-timeline: view(block 0px);
      animation-range:
        var(--alive-range, cover) var(--alive-from, 0%)
        var(--alive-range, cover) var(--alive-to, 100%);
    }

    /* A scene: the element that is watched, for things inside it that cannot
       be watched themselves. view() watches against the nearest box that
       scrolls OR clips (overflow: hidden counts), so anything inside the
       hero, a card's image frame or the archive strip would be watching the
       wrong box and never move. Mark the outer element data-alive-scene and
       everything with data-alive inside it follows the scene instead. */
    html.alive-css [data-alive-scene] {
      view-timeline: --alive-scene block;
      view-timeline-inset: 0px;
    }

    html.alive-css [data-alive-scene] [data-alive] {
      animation-timeline: --alive-scene;
    }
  }

  /* An element whose range can never finish (it sits so low on the page that
     the page ends first) would be stuck halfway for ever. alive.js finds
     those and marks them; they stay still. */
  html.alive [data-alive][data-alive-skip] {
    animation: none;
  }
}

/* --- Effects ----------------------------------------------------------- */

/* light: comes up out of the dark as it is reached. Light only, so both
   drivers may play it. The low end stays readable: someone who stops
   mid-scroll can still read the line. T10: 0.3, up from round 1's 0.2, where
   a heading left half-lit was close to black (about #333 on the page). */
@keyframes alive-light {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* dim: the opposite, for a layer of darkness laid over a picture. */
@keyframes alive-dim {
  from { opacity: 0; }
  to { opacity: var(--alive-dim-to, 0.64); }
}

@media (prefers-reduced-motion: no-preference) {
  html.alive [data-alive="light"] {
    animation-name: alive-light;
  }

  html.alive [data-alive="dim"] {
    animation-name: alive-dim;
  }
}

/* --- Words -------------------------------------------------------------
   data-alive-words splits a line of text into words that each take the
   effect, a little after the one before. alive.js builds the spans. */

.alive-word {
  /* A view timeline needs a box of its own; an inline run of text has none. */
  display: inline-block;
}

@media (prefers-reduced-motion: no-preference) {
  /* The line lights word by word, so it does not also rise as a block. */
  html.alive [data-alive-words][data-lift] {
    opacity: 1;
    translate: none;
    animation: none;
  }
}

/* --- The home page: from the hero into "Energy over genre" -------------
   The light follows the visitor down the page. As the hero leaves, the room
   goes dark behind them, and the statement comes up out of the dark word by
   word. Nothing travels. */

.hero__dim {
  position: absolute;
  inset: 0;
  /* Above the scrim (2), still inside .hero__bg, so the wordmark and the
     scroll cue stay above it. */
  z-index: 3;
  pointer-events: none;
  background: var(--bg);
  /* Still page: not there at all. */
  opacity: 0;
  /* The same fade as the still and the clip under it (.hero__still in
     main.css). Without it the darkness would end in a hard line at the bottom
     of the hero, where the picture has already dissolved into the page. */
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 62%, rgba(0, 0, 0, 0.55) 84%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 62%, rgba(0, 0, 0, 0.55) 84%, transparent 100%);
}

/* --- The Spor light (T10, from round 1) ----------------------------------
   The room where the music is: a red light behind the player, off until a
   mix plays (spor-player.js puts .is-sounding on the .room around it). It
   comes on slowly and goes off the same way, and breathes while the music
   is on. The page answers the visitor: nothing here moves until they press
   play. Round 1's second, still light in the same room is not here: Axel's
   drifting glow (#tettpaa-bg) does that job and shows through around it. */
.room {
  position: relative;
  isolation: isolate;
}

/* Behind the player: beside the photo on a wide screen, in the middle on a
   phone. */
.room-sound {
  --room-sound-x: 50%;
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2.4s ease;
}

@media (min-width: 901px) {
  .room-sound {
    --room-sound-x: 66%;
  }
}

.room.is-sounding .room-sound {
  opacity: 1;
}

/* Sized to the box's own sides, so the light has faded to nothing before the
   section ends and never stops in a line. */
.room-sound::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 46% 50% at var(--room-sound-x) 52%, rgba(227, 6, 19, 0.36) 0%, rgba(227, 6, 19, 0.17) 44%, rgba(227, 6, 19, 0.045) 78%, transparent 100%);
}

/* Grain over the light. A smooth dark-red fade has too few shades to draw
   itself and shows as rings (banding); a little noise breaks them up. Drawn
   once by the browser from an inline SVG, nothing to download. */
.room-sound::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  opacity: 0.55;
  /* The grain only where the light is, so it never greys the page around it. */
  -webkit-mask-image: radial-gradient(ellipse 46% 50% at var(--room-sound-x) 52%, #000 0%, transparent 100%);
  mask-image: radial-gradient(ellipse 46% 50% at var(--room-sound-x) 52%, #000 0%, transparent 100%);
}

/* While the music is on, the light breathes: nine seconds for one breath,
   between three quarters and full. Slow enough to be felt more than seen.
   Not with Reduce Motion: there the light is simply on. */
@keyframes room-breathe {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .room.is-sounding .room-sound::before {
    animation: room-breathe 9s ease-in-out infinite;
  }
}

/* --- Soft changes between pages ------------------------------------------
   A link to another page of the site fades from the one into the other
   instead of cutting (a cross-document view transition). The browser does
   all of it; a browser that cannot simply opens the page, as before.

   The rule that switches it on, "@view-transition { navigation: auto; }", is
   NOT here. It is written in the <head> of every page, inside a <style>. Both
   pages of a change must carry it, and the new page must have it before the
   browser reaches its <body>: in this file it arrived too late about every
   second time, and Chrome dropped the fade ("ViewTransition opt-in disabled"
   in its log). Found and proven with tools/alive-pages-check.mjs. So a new
   page needs that one line in its head, and this file for the pace below.

   Only the plain fade of the whole page. The header is not held as a layer
   of its own: header.js puts it in after the page has loaded, so the new page
   has no header yet at the moment the browser takes its picture. It is the
   same header on every page, so it fades into itself. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.4s;
  animation-timing-function: ease;
}
