/* The living hub (docs/351) — the layer's own geometry and the hand-over.

   ⭐ #life IS A SIBLING OF #app, UNDER IT, and it holds his painting and the animations. render()
   replaces #app's children on every change; nothing in here is a child of #app, so no animation
   restarts when the hub re-renders. It exists ONLY while the hub is on screen (life.js removes it
   the moment another screen is drawn), and never under reduced motion.

   ⛔⛔ THE DEMOS LIVE IN #life's SHADOW ROOT, because the game's stylesheets are not the gallery's:
   app.css has a global `.row` (a flex card, 56px tall, on an opaque ground) and the banner ripple
   is built of `.row`s, and a global `img { display: block }`. In the page they came from, nothing
   styled them but their own rules; in a shadow root nothing does either.
   ⭐ ONE FILE, TWO DOCUMENTS: life.js adopts THIS sheet inside the shadow root as well. A rule is
   only ever true in one of them — `#life` and `html.pf2-life ...` match nothing inside the shadow
   tree, `.life-view` and friends match nothing in the page — so the geometry is written once.

   ⭐ THE GEOMETRY IS THE HUB'S OWN. #life copies #app's column exactly the way #fx does (a fixed
   column min(100vw, 412px) wide, centred by margin-inline, 100dvh tall), `.life-view` is `.view`
   (the column minus the nav, clipped), and the 412x891 stage is centred in it — so his painting
   at -8.5px on the stage lands exactly where `.hub-art.v2 img` puts it (left 50%, margin-left
   -214.5px), on any width. pf2_hub_life_check.mjs compares the two boxes and the painted pixels.

   ⛔ z-index 0 and FIRST in <body>: #app is positioned with no z-index and comes later, so it and
   everything in it paint above this — and nothing in the game's CSS has a negative z-index that
   could fall under it (a z-index of -1 here would put #life under body's own background). */
@media (prefers-reduced-motion: no-preference) {
  /* ---- in the page: the host ---- */
  #life {
    position: fixed; top: 0; left: 0; right: 0; margin-inline: auto; z-index: 0;
    width: min(100vw, 412px); height: 100%; height: 100dvh; max-height: 100dvh;
    overflow: hidden; pointer-events: none;
  }

  /* ---- in the shadow root: the stage (the gallery's `.stage.hub`, at the hub's geometry) ---- */
  .life-view { position: absolute; left: 0; right: 0; top: 0; bottom: var(--nav); overflow: hidden; }
  .life-stage { position: absolute; left: 50%; top: 0; width: 412px; height: 891px; margin-left: -206px; }
  /* gallery.css `* { box-sizing: border-box }` — the page the demos were drawn in */
  .life-stage, .life-stage * { box-sizing: border-box; }
  /* ⚠️ `pixelated`, like the gallery's stage and every depth layer the demos draw: the masked
     layers are pixel-identical to the gallery's pictures ONLY under nearest-neighbour sampling,
     and his castle must not change sharpness depending on which main is playing. The game's own
     `.hub-art.v2 img` is `auto`, which is why a visible hand-over crossfades (below). */
  .life-art { position: absolute; left: -8.5px; top: 0; width: 457px; height: 812px; max-width: none;
    image-rendering: pixelated; }
  /* gallery.css `.stage > .demo`: every demo root is the whole stage, clipped to it */
  .life-stage > .demo { position: absolute; inset: 0; overflow: hidden; }

  /* ---- in the page: the hand-over, the hub going see-through where the layer draws ----
     Set by life.js only once every picture the layer shows has decoded, so the hub never shows an
     empty painting. Under a cover or the loading screen it is instant; on the glass the game's own
     painting fades out over the layer (`pf2-life-fade`), because the two sample his painting
     differently (auto vs pixelated) and a swap would be a visible jump. */
  html.pf2-life:not(.pf2-life-off) #app { background: transparent; }
  html.pf2-life:not(.pf2-life-off) #app .hub-art > img { opacity: 0; }
  html.pf2-life.pf2-life-fade:not(.pf2-life-off) #app .hub-art > img { transition: opacity .3s linear; }
  /* ⚠️ the ground panel every .view carries (docs/303) is normally covered by the painting, which
     is 812 tall: clip away exactly the part the painting covered, so a view taller than 812 (a
     phone taller than 891) keeps today's panel below the picture, rule and gradient included */
  html.pf2-life:not(.pf2-life-off) #app .view::before { clip-path: inset(calc(812px - var(--band)) 0 0 0); }
}
/* the switch the :7779 lab uses to put its own copy of these layers over the game, and reduced
   motion — which life.js answers by never mounting; this is the guard for the instant between */
html.pf2-life-off #life { display: none; }
@media (prefers-reduced-motion: reduce) { #life { display: none; } }
