/* Painted page heads. Each page outside the home page opens on its own scene,
   set down as a soft ink wash like the landscape on the home page: Ivory only,
   at partial strength, so the Forest shows through, with brass for one small
   part. This file holds what the scenes share: where a scene stands in the
   head, the stage its layers are placed on, and the way it is painted in.
   Each page's own file (cjr.css, lumen.css, and so on) holds what moves.

   The drawings live in source/. A page shows still layers rendered from them
   and only moves, clips, and fades those, because redrawing a wash's filters
   on every frame made the CJR head stutter in Safari.

   BRAND.md section 2 allows no Japanese motifs beyond the logo and the home
   hero, and section 4 no painted or animated scene other than the home hero.
   These are on the owner's instruction. Loaded after inner.css. */
.page-head { overflow: hidden; isolation: isolate; }

/* The scene stands in its own column, to the right of the copy, so it never
   runs under it. --edge is the distance from the head's edge to the page
   column. Where a sector label runs down the right edge, the scene stops
   short of it. */
.paint {
  --edge: max(var(--gutter), (100cqw - 1200px) / 2);
  position: absolute;
  z-index: -1;
  top: 20%;
  bottom: 0;
  left: calc(var(--edge) + min(52cqw, 720px));
  right: var(--edge);
  pointer-events: none;
  container-type: size;
}
.page-head:has(.page-sector) .paint { right: calc(var(--edge) + 52px); }
/* The copy keeps to its side of that column: it ends 24px short of the scene,
   after the 36px a sector label reserves. */
.page-intro { max-width: min(680px, 52cqw - 60px); }

/* The stage keeps the drawing's proportions, 640 by 420 unless a scene says
   otherwise, as large as the frame allows, against its lower right corner.
   --u is one unit of the drawing, for the layers inside it. */
.stage {
  --stage-w: 640;
  --stage-h: 420;
  --u: calc(100cqw / var(--stage-w));
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(100cqw, 100cqh * var(--stage-w) / var(--stage-h));
  aspect-ratio: var(--stage-w) / var(--stage-h);
  container-type: inline-size;
}
.stage img { position: absolute; display: block; max-width: none; }
.layer { inset: 0; width: 100%; height: 100%; }

/* Painted in from the left with a soft edge, as the landscape is. The mask is
   part of the animation, not of the scene: once the wipe has crossed, the
   scene is left with no mask at all. A mask that stays on, even one that
   hides nothing, makes a phone redraw the whole scene through it on every
   frame for as long as the mist or anything else in it moves. */
@keyframes paint-in {
  from { -webkit-mask: var(--wipe) 100% 0 / 300% 100% no-repeat; mask: var(--wipe) 100% 0 / 300% 100% no-repeat; }
  to { -webkit-mask: var(--wipe) 0 0 / 300% 100% no-repeat; mask: var(--wipe) 0 0 / 300% 100% no-repeat; }
}
@keyframes drift { from { transform: translateX(calc(-26 * var(--u))); } to { transform: translateX(calc(26 * var(--u))); } }

@media (prefers-reduced-motion: no-preference) {
  .paint {
    --wipe: linear-gradient(90deg, #000 0 38%, transparent 52% 100%);
    animation: paint-in 2.4s cubic-bezier(0.55, 0, 0.25, 1) 0.2s backwards;
  }
  .layer-mist { animation: drift 22s ease-in-out infinite alternate; will-change: transform; }
}

/* On a phone there is no room beside the copy, so the scene stands behind it,
   lighter, and stops short of a sector label. */
@container (max-width: 719px) {
  .paint { top: auto; left: 0; right: var(--gutter); height: 60%; width: auto; opacity: 0.55; }
  .page-head:has(.page-sector) .paint { right: calc(var(--gutter) + 30px); }
  .page-intro { max-width: 680px; }
}
