/* 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.

   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. */
@keyframes alive-light {
  from { opacity: 0.2; }
  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); }
}

/* closeup: a picture is black and white, comes into colour while it is in
   the middle of the screen, and goes grey again as it leaves. Light only. The
   stops are symmetric, so it answers the visitor the same way in both
   directions: colour starts when about half the picture is on screen and is
   whole when all of it is. */
@keyframes alive-closeup {
  0%, 18% { filter: grayscale(1) contrast(1.08); }
  36%, 64% { filter: grayscale(0) contrast(1); }
  82%, 100% { filter: grayscale(1) contrast(1.08); }
}

/* lamp: a light that is on only while its scene is close up. The same stops
   as closeup, so a picture and the light behind it move as one. */
@keyframes alive-lamp {
  0%, 18% { opacity: 0; }
  36%, 64% { opacity: 1; }
  82%, 100% { opacity: 0; }
}

/* near: closeup for a picture nobody hovers (the photographs on Come Closer).
   Black and white while it is far, in colour while it is near, on every
   device. Light only, so both drivers may play it. */
@keyframes alive-near {
  0%, 18% { filter: grayscale(1) contrast(1.08); }
  36%, 64% { filter: grayscale(0) contrast(1); }
  82%, 100% { filter: grayscale(1) contrast(1.08); }
}

/* near, with a push-in: the same light, and the picture also grows by 6 %
   inside its frame over the whole time it is on screen, as if the visitor
   walked towards it. This one TRAVELS, so only the browser's driver plays
   it. The scale is written at the two ends only, so it runs straight through
   while the colour comes and goes. */
@keyframes alive-near-push {
  0% { filter: grayscale(1) contrast(1.08); scale: 1; }
  18% { filter: grayscale(1) contrast(1.08); }
  36%, 64% { filter: grayscale(0) contrast(1); }
  82% { filter: grayscale(1) contrast(1.08); }
  100% { filter: grayscale(1) contrast(1.08); scale: 1.06; }
}

/* push: a slow push-in and nothing else, for a picture that fills the screen.
   It travels: the browser's driver only. */
@keyframes alive-push {
  from { scale: 1; }
  to { scale: 1.08; }
}

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

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

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

  /* After the rule above and as strong as it, so where the browser drives,
     the picture gets the version that also pushes in. */
  html.alive-css [data-alive="near"] {
    animation-name: alive-near-push;
  }

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

/* closeup and lamp are the touch screen's answer to hover, so they are named
   only where there is no pointer to hover with. With a pointer the same
   elements are handled by the hover rules further down, and the kit leaves
   them alone. */
@media (prefers-reduced-motion: no-preference) and (hover: none) {
  html.alive [data-alive="closeup"] {
    animation-name: alive-closeup;
  }

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

/* --- 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 home page: close up --------------------------------------------
   "Come closer and the colour comes." Under the hero the page is black and
   white and still. The red is not a background any more: it is in the people,
   and it wakes when the visitor is close to them.

   Axel's wish, built the way his reference does it (raw-people.com):
   grayscale(1) contrast(1.08), and on hover colour and a 2.5 % zoom over half
   a second, inside a frame that clips. Their site has no touch version; ours
   is the closeup effect above.

   Every page loads this file since T8d, and only the home page has these
   cards and this strip, so the rules reach them and nothing else.

   With a pointer: plain CSS, no script needed. */
@media (hover: hover) and (pointer: fine) {
  .resident-card__img-wrap img,
  .archive-strip__poster img {
    filter: grayscale(1) contrast(1.08);
    transition: filter 0.5s ease, transform 0.5s ease;
  }

  .resident-card:hover img,
  .resident-card:focus-visible img,
  .archive-strip__item:hover img,
  .archive-strip__poster:focus-visible img {
    filter: grayscale(0) contrast(1);
  }

  .resident-card:hover img,
  .resident-card:focus-visible img {
    transform: scale(1.025);
  }

  /* The archive is the calm one: its posters get their colour back and
     nothing else. */
  .archive-strip__item:hover img {
    transform: none;
  }

  .resident-card:hover .resident-card__light,
  .resident-card:focus-visible .resident-card__light {
    opacity: 1;
  }
}

/* The red light behind a card: the room lights up where the people are. It is
   the photo's own red, spilling a little way into the dark around it. Off on
   the still page. */
.resident-card {
  position: relative;
  isolation: isolate;
}

.resident-card__light {
  position: absolute;
  z-index: -1;
  /* Wider than the card and a little taller than the picture, so it reads as
     light around it, not a frame. The gradient is gone well before its own
     edges, so nothing ends in a line. */
  top: -9%;
  right: -22%;
  bottom: 2%;
  left: -22%;
  pointer-events: none;
  background: radial-gradient(ellipse 50% 50% at 50% 48%, rgba(227, 6, 19, 0.5) 0%, rgba(227, 6, 19, 0.22) 46%, rgba(227, 6, 19, 0.06) 74%, transparent 100%);
  opacity: 0;
  transition: opacity 0.7s ease;
}

/* --- The home page: one still light at the end ---------------------------
   The drifting glow is gone from this page. What is left of the red as a
   background is one light that does not move: it stands by "Kom Tettpå" and
   comes up as the visitor reaches it (the light effect). On the still page it
   is simply on. */
#mailing-list,
.room {
  position: relative;
  isolation: isolate;
}

.room-light {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  /* Sized to the box's own sides (50% each way from the middle), so the light
     has faded to nothing before the section ends and never stops in a line
     against the footer. The red label at the top of the section sits where it
     is nearly gone, on near-black (main.css holds --red-text to 4.5:1). */
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(227, 6, 19, 0.32) 0%, rgba(227, 6, 19, 0.17) 42%, rgba(227, 6, 19, 0.05) 76%, 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, and it
   gives the light the sandy, analogue grain the old glow had. Drawn once by
   the browser from an inline SVG, 180px tiles, nothing to download. */
.room-light::after,
.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;
}

/* --- Come Closer: every scroll is a step closer --------------------------
   The page's idea is its own name. The opening photo pushes in slowly as it
   is left and the room goes dark behind the visitor (push and dim, above).
   The photographs down the page are black and white while they are far and
   in colour while they are near, and push in a little as they pass (near).
   The headings come up by light, word by word. The drifting glow is gone
   from this page too: the red is in the photographs, and in the room at the
   end. */

.come-closer__dim,
.profile-hero__dim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--bg);
  /* Still page: not there at all. The frame around it owns the dissolve
     (main.css, .come-closer__frame), so this needs no mask of its own. */
  opacity: 0;
}

.come-closer__dim {
  z-index: 1;
}

/* --- The artist pages ---------------------------------------------------
   The same three things as everywhere else and nothing new: the picture goes
   dark behind the visitor as it is left (.profile-hero__dim comes after the
   picture, the clip and the scrim in the markup and under the name, which
   stays lit), the red labels come up by light, and the page's one still red
   light stands where the music is (.room-light in the last section). */

/* The room at the end, when a mix plays. A second light, off until then,
   behind the player: beside the photo on a wide screen, in the middle on a
   phone. It comes on slowly and goes off the same way. The page answers the
   visitor: nothing here moves until they press play. */
.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;
}

.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%);
}

/* While the music is on, the light breathes: nine seconds for one breath,
   between three quarters and full. Slow enough that it is felt more than
   seen ("alive or breathing", "80 % static"). 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;
}
