/* Cloud scene: the ONE shared scene engine (layers, motion, parallax, music energy, pause rules). Two configurations:
   the DJ island (Home Welcome inset; src/blocks/cloud-scene.html, positions below) and the screens island (About;
   rendered by tools/build.py, its own positions / knobs / screens in components/screens-island.css).
   Template: src/blocks/cloud-scene.html ({{>cloud-scene}} in a page); motion control: components/cloud-scene.js
   (pause when off screen / tab hidden, cursor parallax; one instance per scene, cleaned up on navigation).
   The scene fills its wrapper's width (square, sized with container query units); the PAGE sets that width
   (--home-scene-w in styles/site.css, --about-scene-w in components/about.css).
   Transparent layers, each absolutely positioned at its box (% of the canvas) so the composition stays exact. Stack, bottom to top: ground
   shadow, small clouds, then the island group: the island, then both flower layers ON TOP of it (their stems
   stand in its grass; they ride the island's bob).
   Nesting, so transforms never fight: .cs-par (parallax translate only) > .cs-bob (translateY) > .cs-breathe
   (scale + rotate) for the island group; .cs-par > .cs-sway (rotate) for flowers; .cs-par > .cs-drift for clouds.
   MOTION KNOBS (unitless; px values are "px at the 600px desktop size" and scale with the scene's width):
     --scene-motion   master multiplier for every amplitude (0 = still, 1 = default)
     --scene-bob      island group's up/down travel (px)              --scene-rock  its tilt, +/- (deg)
     --scene-breathe  island group's extra scale (0.01 = 1%)           --scene-sway  flowers' sway, +/- (deg)
     --scene-drift    small cloud 1's sideways drift, +/- (px; cloud 2 is 1.2x; up/down is ~0.3x)
   --scene-energy goes 1 -> 1.4 while music plays (html[data-playing="true"], set by components/player.js) and
   eases over 0.8s (registered property, so the running animations just grow, never restart). */
@property --scene-energy {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

.cloud-scene {
  --scene-motion: 1;
  --scene-bob: 17.5;
  --scene-breathe: 0.01;
  --scene-rock: 0.5;
  --scene-sway: 2.5;
  --scene-drift: 25;
  --scene-energy: 1;
  --k: calc(var(--scene-motion) * var(--scene-energy));
  --u: 1px; /* fallback: amplitudes in plain px (right at the 600px desktop size) */
  position: relative;
  aspect-ratio: var(--scene-aspect, 1); /* Home: square; the screens island sets its canvas ratio */
  container-type: inline-size;
  transition: --scene-energy 0.8s ease;
}
@supports (width: 1cqw) {
  .cloud-scene { --u: calc(100cqw / 600); } /* 1 "px" at the 600px desktop size, scaled with the scene */
}
html[data-playing="true"] .cloud-scene { --scene-energy: 1.4; }

.cloud-scene img {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
}

.cs-par,
.cs-bob,
.cs-breathe { position: absolute; inset: 0; }

/* Parallax: --px / --py (-1..1) from cloud-scene.js, times each layer's depth --d (px) */
.cs-par {
  --d: 0;
  transform: translate(calc(var(--px, 0) * var(--d) * var(--u)), calc(var(--py, 0) * var(--d) * var(--u)));
}
.cs-par--island { --d: 10; }

/* Positioned layers: box = left / top / width as % of the canvas */
.cs-at {
  position: absolute;
  inset: auto;
  left: var(--l);
  top: var(--t);
  width: var(--w);
}
.cs-island        { --l: 3.03%;  --t: 17.30%; --w: 95.14%; }
.cs-flower--left  { --l: 15.87%; --t: 34.13%; --w: 17.22%; --d: 5; --o: 48.7% 99.2%; } /* +5 on the island's 10 = 15px */
.cs-flower--right { --l: 71.45%; --t: 38.99%; --w: 15.95%; --d: 5; --o: 30.5% 99.1%; } /* 13px right, 1px up vs its file: matches the original */
.cs-cloud--1      { --l: 17.70%; --t: 2.87%;  --w: 26.71%; --d: 35; } /* cut from the uncut image (its own layer file is hazy) */
.cs-cloud--2      { --l: 60.85%; --t: 13.72%; --w: 22.49%; --d: 35; }

/* Static ground shadow under the island (never animated, no filter on moving layers) */
.cloud-scene__shadow {
  position: absolute;
  left: 15%;
  top: 95.5%;
  width: 70%;
  height: 8%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--scene-shadow), transparent);
}

/* Animations: durations are HALF a cycle (alternate). Each keyframe is defined once. */
.cs-bob { animation: cs-bob 3.5s ease-in-out infinite alternate; }
.cs-breathe {
  transform-origin: var(--island-origin, 50% 75%); /* Home: about where Nick sits; the screens island: its center */
  animation: cs-breathe 4s ease-in-out infinite alternate, cs-rock 4.75s ease-in-out infinite alternate;
}
.cs-sway { transform-origin: var(--o, 50% 100%); /* each flower's stem base */ animation: cs-sway 2.5s ease-in-out -0.8s infinite alternate; }
.cs-flower--right .cs-sway { animation-duration: 3.2s; animation-delay: -2.3s; }
.cs-drift { --dx: 1; --dy: 0.3; animation: cs-drift 5.5s ease-in-out infinite alternate; }
.cs-cloud--2 .cs-drift { --dx: 1.2; --dy: 0.4; animation-duration: 7s; animation-direction: alternate-reverse; }

@keyframes cs-bob {
  from { transform: translateY(calc(var(--scene-bob) * var(--k) * var(--u) * -0.5)); }
  to   { transform: translateY(calc(var(--scene-bob) * var(--k) * var(--u) * 0.5)); }
}
@keyframes cs-breathe {
  from { scale: 1; }
  to   { scale: calc(1 + var(--scene-breathe) * var(--k)); }
}
@keyframes cs-rock {
  from { rotate: calc(var(--scene-rock) * var(--k) * -1deg); }
  to   { rotate: calc(var(--scene-rock) * var(--k) * 1deg); }
}
@keyframes cs-sway {
  from { rotate: calc(var(--scene-sway) * var(--k) * -1deg); }
  to   { rotate: calc(var(--scene-sway) * var(--k) * 1deg); }
}
@keyframes cs-drift {
  from { transform: translate(calc(var(--scene-drift) * var(--dx) * var(--k) * var(--u) * -1), calc(var(--scene-drift) * var(--dy) * var(--k) * var(--u) * -1)); }
  to   { transform: translate(calc(var(--scene-drift) * var(--dx) * var(--k) * var(--u)), calc(var(--scene-drift) * var(--dy) * var(--k) * var(--u))); }
}

/* cloud-scene.js: paused while off screen or the tab is hidden; will-change only while running */
.cloud-scene.is-paused :is(.cs-bob, .cs-breathe, .cs-sway, .cs-drift) { animation-play-state: paused; }
.cloud-scene.is-running :is(.cs-bob, .cs-drift) { will-change: transform; }
.cloud-scene.is-running :is(.cs-breathe, .cs-sway) { will-change: scale, rotate; }

/* Reduced motion: a fully still scene (no animation, parallax or energy change) */
@media (prefers-reduced-motion: reduce) {
  .cloud-scene { transition: none; }
  html[data-playing="true"] .cloud-scene { --scene-energy: 1; }
  .cloud-scene :is(.cs-bob, .cs-breathe, .cs-sway, .cs-drift) { animation: none; }
  .cloud-scene .cs-par { transform: none; }
}
