/* SCREENS ISLAND (About): a configuration of the shared scene engine (components/cloud-scene.css + .js) plus its
   screens. Markup: rendered by tools/build.py (render_screens_island) from src/data/screens-island-scene.json
   (geometry from scripts/screens-island-scene.py) and src/data/screens-island-photos.json (photos). Behavior
   (screen warping, channel-change visits): components/screens-island.js.
   Stack, bottom to top: ground shadow, three small clouds, then the island group (.cs-par > .cs-bob > .cs-breathe):
   the SCREENS (one warped container per monitor) under the ISLAND BASE (holes at the glass, so the bezels, flowers
   and leaves cover the photo edges). The screens ride the island's bob / breathe / rock because they're inside it.
   Semantic tokens only (--scene-*, --on-fill); the noise texture is a local inline SVG (no requests). */

.cloud-scene--screens {
  /* MOTION KNOBS (same meaning as the Home scene's, "px at the 600px desktop size", scaled with the scene) */
  --scene-bob: 7;         /* island group: 7px travel, one cycle = 7s */
  --scene-breathe: 0.01;  /* +1% around the island's center */
  --scene-rock: 0.5;      /* +/- 0.5deg, one cycle = 9.5s */
  --scene-drift: 5;       /* clouds: travel = 2 x 5 x --dx (horizontal) / --dy (vertical) */
  /* VISITS (components/screens-island.js reads these): gap between visits and how long one lasts */
  --visit-gap-min: 7000ms;
  --visit-gap-max: 12000ms;
  --visit-min: 5000ms;
  --visit-max: 7000ms;
  /* The static CRT look (measured defaults are written inline on the scene by the build):
     --crt-scan-period, --crt-scan-contrast, --crt-vignette, --crt-glare, --crt-tint, --crt-black, --crt-white,
     --crt-match (how far the photo moves toward the measured black / white levels) */
}

/* Parallax depth (px at 600px): island group 4, clouds 14 */
.cloud-scene--screens .ss-group { --d: 4; }
.cloud-scene--screens .ss-cloud { --d: 14; }

/* Clouds drift on their own: half-cycle durations (alternate), different delays and phases */
.ss-cloud--1 .cs-drift { --dx: 1;   --dy: 0.3; animation-duration: 5.5s;  animation-delay: -1.3s; }                                   /* 10 x 3px / 11s */
.ss-cloud--2 .cs-drift { --dx: 1.2; --dy: 0.4; animation-duration: 7s;    animation-delay: -3.1s; animation-direction: alternate-reverse; } /* 12 x 4px / 14s */
.ss-cloud--3 .cs-drift { --dx: 0.9; --dy: 0.3; animation-duration: 6.25s; animation-delay: -2.2s; }                                   /* 9 x 3px / 12.5s */

/* ---- The screens ---- */
.ss-screens { position: absolute; inset: 0; }

.ss-screen {
  /* Without JavaScript: placed on each screen's bounding box (inline %), unwarped; the bezel hides the edges.
     With JavaScript: left / top 0, sized 2x the rectified screen and warped onto the glass with matrix3d. */
  position: absolute;
  overflow: hidden;
  background: var(--scene-screen-off);
  transform-origin: 0 0;
  container-type: size;
  --crt-lo: calc(var(--crt-black, 0.1) * var(--crt-match, 0.5));
  --crt-hi: calc(1 - (1 - var(--crt-white, 0.9)) * var(--crt-match, 0.5));
}

.ss-pic,
.ss-crt,
.ss-glare,
.ss-static,
.ss-screen .qt-analog { position: absolute; inset: 0; pointer-events: none; }

.cloud-scene .ss-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 38%;
  opacity: 0;
  /* toward the measured black / white levels: [0,1] -> [lo, hi] */
  filter: contrast(calc((var(--crt-hi) - var(--crt-lo)) / (var(--crt-hi) + var(--crt-lo)))) brightness(calc(var(--crt-hi) + var(--crt-lo))) saturate(0.9);
}
.cloud-scene .ss-photo.is-current { opacity: 1; }
.ss-screen.is-fade .ss-photo { transition: opacity 0.3s ease; } /* CRT off: a plain crossfade */

/* Static CRT look (part of the artwork: stays with the site's CRT toggle on or off) */
.ss-crt {
  background:
    repeating-linear-gradient(to bottom,
      color-mix(in srgb, var(--scene-screen-off) calc(var(--crt-scan-contrast) * 100%), transparent) 0 calc(var(--crt-scan-period) * 0.5),
      transparent calc(var(--crt-scan-period) * 0.5) var(--crt-scan-period)),
    radial-gradient(ellipse at 50% 50%, transparent 52%, color-mix(in srgb, var(--scene-screen-off) calc(var(--crt-vignette) * 160%), transparent) 100%),
    linear-gradient(var(--crt-tint), var(--crt-tint));
  box-shadow:
    inset 0 0 7cqh color-mix(in srgb, var(--scene-screen-off) 45%, transparent),
    inset 0 0 2.5cqh color-mix(in srgb, var(--scene-screen-glow) 16%, transparent);
}
.ss-glare {
  background: linear-gradient(135deg, color-mix(in srgb, var(--scene-screen-glow) calc(var(--crt-glare) * 100%), transparent) 0%, transparent 46%);
}

/* The shared analog screen layer (components/qt-card.css): only while the site's CRT effect is on; stronger on hover */
.cloud-scene--screens:hover .qt-analog { opacity: min(1, calc(var(--analog-active) * var(--analog-intensity))); }
.cloud-scene.is-paused .qt-analog > i { animation-play-state: paused; }

/* ---- Channel change (screens-island.js adds .is-channel for ~380ms, CRT effect on): a brightness flash, a tear and
   a quick vertical roll with a little jitter, and a burst of static that fades out; the photo swaps at ~140ms ---- */
.ss-static {
  opacity: 0;
  background: var(--scene-screen-off) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='96' height='96' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 48px 48px;
}
.ss-screen.is-channel .ss-pic { animation: ss-tear 0.38s linear, ss-flash 0.38s linear; }
.ss-screen.is-channel .ss-static { animation: ss-static 0.38s linear; }

@keyframes ss-flash {
  0%   { filter: brightness(2.4); }
  18%  { filter: brightness(1); }  /* ~70ms */
  100% { filter: none; }
}
@keyframes ss-tear {
  0%   { transform: none; }
  10%  { transform: translateX(5%) skewX(-10deg); }
  20%  { transform: translate(-4%, -22%); }
  30%  { transform: translate(3%, 14%); }
  37%  { transform: translate(0, -40%); }  /* ~140ms: the new channel comes in */
  46%  { transform: translate(-2%, 10%); }
  56%  { transform: translate(1.5%, -4%); }
  70%  { transform: translateX(-1%); }
  85%  { transform: translateX(0.5%); }
  100% { transform: none; }
}
@keyframes ss-static {
  0%   { opacity: 0.3; background-position: 0 0; }
  12%  { opacity: 0.85; background-position: 17px 9px; }
  30%  { opacity: 0.9; background-position: -11px 23px; }
  45%  { opacity: 0.8; background-position: 29px -7px; }
  58%  { opacity: 0.75; background-position: -19px -15px; }  /* ~220ms, then fades out over ~160ms */
  80%  { opacity: 0.3; background-position: 7px 31px; }
  100% { opacity: 0; background-position: 0 0; }
}

/* Reduced motion: no visits (the script doesn't start them) and no channel effect; the static look stays */
@media (prefers-reduced-motion: reduce) {
  .ss-screen.is-channel .ss-pic,
  .ss-screen.is-channel .ss-static { animation: none; }
  .ss-screen.is-fade .ss-photo { transition: none; }
}
