/*
 * styles/scene.css - the room: layer stack, string lights, UI corner. Core-owned.
 * Stage 2 styles its own slots (#collage-slot, #film-slot drawing) and themes via tokens.
 * Only transform and opacity are animated here.
 */

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--c-room);
}

.layer { position: absolute; inset: 0; }

/* wall: plum-black base, darker floor, and a soft rose spill from the garlands */
.layer--wall {
  z-index: var(--z-wall);
  background:
    radial-gradient(95% 70% at 50% 118%, rgb(0 0 0 / 0.72), transparent 70%),
    linear-gradient(to bottom, #241722 0%, var(--c-wall) 45%, var(--c-room) 100%);
}
.layer--wall::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(140% 48% at 50% 0%, rgb(var(--c-light) / 0.09), transparent 70%),
    radial-gradient(70% 30% at 50% 22%, rgb(var(--c-light) / 0.06), transparent 75%);
  transition: opacity var(--m-switch-on) linear;
}
[data-lights="off"] .layer--wall::after { opacity: 0; transition-duration: var(--m-switch-off); }

.layer--collage { z-index: var(--z-collage); }
.layer--garland { z-index: var(--z-garland); pointer-events: none; }
.layer--guitar { z-index: var(--z-guitar); }
.layer--glow { z-index: var(--z-glow); pointer-events: none; }
.layer--film { z-index: var(--z-film); pointer-events: none; width: 100%; height: 100%; }
.layer--ui { z-index: var(--z-ui); pointer-events: none; }
.layer--ui > * { pointer-events: auto; }

/* ---- string lights (built by core/light-rig.js) ---------------------------------------- */
/* Below the guitar: light on the wall (its own svg, only the garland band: a small layer when
   it fades), wires, unlit plastic stars (always drawn; the lit ones sit above the guitar). */
.garland { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.garland__light {
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  height: calc(min(55vw, 42dvh) * 1.6);
  overflow: hidden;
  transition: opacity var(--m-switch-on) linear;
  will-change: opacity;   /* own layer: the blur is painted once, never during a switch */
}
[data-lights="off"] .garland__light { opacity: 0; transition-duration: var(--m-switch-off); }
.garland__wire { fill: none; stroke: var(--c-wire); stroke-width: 1.2; }
.garland__stem { stroke: var(--c-wire); stroke-width: 1.4; }
.garland__star {
  fill: var(--c-bulb-off);
  stroke: var(--c-bulb-rim);
  stroke-width: 0.09;          /* star units (the path is scaled to --star-size) */
  stroke-linejoin: round;
}
.garland__spill { fill: none; stroke: rgb(var(--c-light) / 0.08); stroke-linecap: round; }
.garland__pool { fill: rgb(var(--c-light) / 0.24); }
.garland__hot { fill: rgb(var(--c-light) / 0.3); }

/* Above the guitar. Switched off, the garland goes dark (bloom and lit stars fade out) and the
   shade takes the room to 25% of its light (tokens: --room-dim). Opacity changes on composited
   layers; the shade is a solid colour (no texture to paint). */
.layer--glow::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--c-shade);
  opacity: 0;
  transition: opacity var(--m-switch-on) linear;
}
[data-lights="off"] .layer--glow::before {
  opacity: calc(1 - var(--room-dim));
  transition-duration: var(--m-switch-off);
}

/* the glow layers only cover the garland band (core/light-rig.js: band = min(55vw, 42vh)) + a
   halo: small composited layers */
.glow {
  position: absolute;
  inset: 0 0 auto 0;
  height: calc(min(55vw, 42dvh) + var(--glow-size));
}
.glow__bloom, .glow__group, .glow__pulse { position: absolute; inset: 0; }
.glow__bloom, .glow__stars { transition: opacity var(--m-switch-on) linear; }
[data-lights="off"] .glow__bloom,
[data-lights="off"] .glow__stars { opacity: 0; transition-duration: var(--m-switch-off); }
.glow__group { opacity: 0.9; animation: breathe var(--m-breath-a) var(--ease-in-out) infinite alternate; }
.glow__group:nth-child(2) { animation-duration: var(--m-breath-b); animation-delay: -1.7s; }
.glow__group:nth-child(3) { animation-duration: var(--m-breath-c); animation-delay: -3.1s; }
.glow__pulse { opacity: 0; }

/* bloom: a tight bright core (the frosted star scatters the LED) inside a wide soft halo,
   close to a Gaussian falloff: no visible disc edge */
.glow__halo {
  position: absolute;
  left: 0; top: 0;
  width: var(--glow-size);
  height: var(--glow-size);
  margin: calc(var(--glow-size) / -2) 0 0 calc(var(--glow-size) / -2);
  border-radius: 50%;
  background: radial-gradient(closest-side,
    rgb(var(--c-light) / 0.75) 0%, rgb(var(--c-light) / 0.5) 7%, rgb(var(--c-light) / 0.24) 15%,
    rgb(var(--c-light) / 0.12) 27%, rgb(var(--c-light) / 0.055) 44%, rgb(var(--c-light) / 0.018) 66%,
    rgb(var(--c-light) / 0) 100%);
}
.glow__pulse .glow__halo {
  background: radial-gradient(closest-side, rgb(var(--c-light) / 0.65) 0%, rgb(var(--c-light) / 0.22) 22%, rgb(var(--c-light) / 0) 62%);
}

/* lit stars: drawn over the plastic ones (same shapes), from the LED out to the tips */
.glow__stars { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
.glow__star {
  fill: url(#star-lit);
  stroke: rgb(255 240 245 / 0.9);  /* light caught in the frosted edge */
  stroke-width: 0.07;
  stroke-linejoin: round;
}
.glow__led { fill: url(#star-led); }
.glow__stop--core { stop-color: var(--c-bulb-core); }
.glow__stop--body { stop-color: var(--c-bulb); }
.glow__stop--edge { stop-color: var(--c-bulb-edge); }
.glow__stop--clear { stop-color: var(--c-bulb-core); stop-opacity: 0; }

/* the garland does not blink: a very slight shimmer (one star in ten of brightness, over several seconds), and no flash on the beat (the pulse layer
   that core/app.js lights on every beat is never shown) */
@keyframes breathe {
  from { opacity: 0.92; }
  to { opacity: 1; }
}
.glow__pulse { display: none; }

[data-motion="off"] .glow__group { animation: none; opacity: 0.9; }

/* ---- wall switch (bound in core/app.js) ----------------------------------------------------- */
/* An old push-button switch: pearl plate, two bakelite buttons; the one in use is pressed in.
   Lit by the garlands like the wall: darker when they are down; the symbols glow a little then,
   so the switch can be found in the dark. */
.wall-switch {
  --plate-hi: var(--c-plate-hi);
  --plate-lo: var(--c-plate-lo);
  --knob: var(--c-knob);
  position: absolute;
  right: max(var(--s-4), env(safe-area-inset-right));
  bottom: calc(max(var(--s-4), env(safe-area-inset-bottom)) + var(--tap) + var(--s-4));
  display: grid;
  padding: 13px 6px;
  border-radius: 9px;
  background:
    radial-gradient(130% 60% at 35% 0%, rgb(255 255 255 / 0.22), transparent 65%),
    linear-gradient(172deg, var(--plate-hi), var(--plate-lo));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.4),
    inset 0 -1.5px 0 rgb(0 0 0 / 0.22),
    0 0 0 1px rgb(20 10 20 / 0.45),
    2px 9px 14px -2px rgb(0 0 0 / 0.6);   /* cast on the wall, away from the lights above */
}
/* two screws */
.wall-switch::before, .wall-switch::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 6px; height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background:
    linear-gradient(35deg, transparent 42%, rgb(0 0 0 / 0.45) 43% 57%, transparent 58%),
    radial-gradient(circle at 35% 30%, var(--plate-hi), var(--plate-lo));
  box-shadow: inset 0 0 0 0.5px rgb(0 0 0 / 0.35);
}
.wall-switch::before { top: 4px; }
.wall-switch::after { bottom: 4px; }

.wall-switch__button {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.wall-switch__button:focus-visible { outline-offset: -3px; }
/* bezel in the plate + the button standing out of it */
.wall-switch__button::before {
  content: "";
  grid-area: 1 / 1;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 28%, color-mix(in srgb, var(--knob), #fff 22%), var(--knob) 55%, color-mix(in srgb, var(--knob), #000 35%));
  box-shadow:
    0 0 0 2.5px color-mix(in srgb, var(--plate-lo), #000 18%),
    0 0 0 3.5px rgb(255 255 255 / 0.35),
    0 3px 3px 2px rgb(0 0 0 / 0.42);
  transition: transform var(--m-fast) var(--ease-out), box-shadow var(--m-fast) var(--ease-out);
}
/* symbols: | on, O off (IEC 60417) */
.wall-switch__button::after {
  content: "";
  grid-area: 1 / 1;
  width: 2.5px; height: 10px;
  border-radius: 2px;
  background: var(--c-paper);
  opacity: 0.7;
  transition: transform var(--m-fast) var(--ease-out);
}
.wall-switch__button--off::after {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: none;
  box-shadow: inset 0 0 0 2px var(--c-paper);
}
/* the button in use is pressed in */
:root:not([data-lights="off"]) .wall-switch__button--on::before,
[data-lights="off"] .wall-switch__button--off::before,
.wall-switch__button:active::before {
  transform: translateY(1px) scale(0.93);
  box-shadow:
    0 0 0 2.5px color-mix(in srgb, var(--plate-lo), #000 30%),
    0 0 0 3.5px rgb(255 255 255 / 0.3),
    inset 0 2px 3px rgb(0 0 0 / 0.6);
}
:root:not([data-lights="off"]) .wall-switch__button--on::after,
[data-lights="off"] .wall-switch__button--off::after,
.wall-switch__button:active::after { transform: translateY(1px) scale(0.93); }
/* ... and its symbol shows the accent, so the state reads at a glance */
:root:not([data-lights="off"]) .wall-switch__button--on::after { background: var(--c-accent); opacity: 1; }
[data-lights="off"] .wall-switch__button--off::after { box-shadow: inset 0 0 0 2px var(--c-accent); opacity: 1; }

[data-lights="off"] .wall-switch {
  --plate-hi: color-mix(in srgb, var(--c-plate-hi), var(--c-shade) 47%);
  --plate-lo: color-mix(in srgb, var(--c-plate-lo), var(--c-shade) 47%);
  --knob: color-mix(in srgb, var(--c-knob), var(--c-shade) 40%);
}
[data-lights="off"] .wall-switch__button::after { filter: drop-shadow(0 0 2px rgb(var(--c-light) / 0.9)); }

/* ---- UI corner -------------------------------------------------------------------------- */
.scene__title {
  position: absolute;
  left: max(var(--s-4), env(safe-area-inset-left));
  bottom: max(var(--s-3), env(safe-area-inset-bottom));
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--t-title);
  line-height: 1;
  color: var(--c-accent);
  -webkit-text-stroke: 0.6px var(--c-accent-deep);
  text-shadow: 0 0 22px rgb(var(--c-light) / 0.35);
}

.scene__controls {
  position: absolute;
  right: max(var(--s-4), env(safe-area-inset-right));
  bottom: max(var(--s-4), env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  max-width: 60vw;
}

/* ---- guitar (built by core/guitar/dom-guitar.js) ------------------------------------------- */
/* lies horizontally below the garland band; --ratio (width / length of the upright photo) is set
   inline by the guitar, --guitar-len (its length on screen) comes from tokens.css */
.layer--guitar {
  display: grid;
  place-items: center;
  padding-top: min(52vw, 40dvh);
  padding-bottom: calc(var(--tap) + 2 * var(--s-4) + env(safe-area-inset-bottom));
  perspective: 1600px;
}

.guitar {
  position: relative;
  width: var(--guitar-len);
  height: calc(var(--guitar-len) * var(--ratio));
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline-offset: 10px;
}

.guitar__shadow {
  position: absolute;
  left: 3%; right: 6%; bottom: -14%;
  height: 26%;
  background: radial-gradient(50% 50% at 42% 50%, rgb(0 0 0 / 0.62), transparent 72%);
}

.guitar__sway, .guitar__tilt, .guitar__flip, .guitar__front {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}
.guitar__lay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--guitar-len) * var(--ratio));
  height: var(--guitar-len);
  transform: translate(-50%, -50%) rotate(90deg);
  transform-style: preserve-3d;
}
.guitar__sway { animation: sway 7s var(--ease-in-out) infinite alternate; }
.guitar__flip { transition: transform 900ms var(--ease-in-out); }
.guitar.is-flipped .guitar__flip { transform: rotateY(180deg); }

@keyframes sway {
  from { transform: rotate(-0.6deg) translateY(1px); }
  to { transform: rotate(0.6deg) translateY(-1px); }
}

.guitar__layer {
  position: absolute;
  height: auto;
  transform: translateZ(calc(var(--z) * 1px));
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
}
/* the back is also visibility: hidden until the turn passes 90 deg (half the flip): it never
   counts as painted while it faces away (it is not the page's largest paint) */
.guitar__layer--back {
  transform: translateZ(-14px) rotateY(180deg);
  visibility: hidden;
  transition: visibility 0s linear 450ms;
}
.guitar.is-flipped .guitar__layer--back { visibility: visible; }

/* strings canvas (core/guitar/strings.js), in the guitar's upright frame; JS sets its box */
.guitar__strings {
  position: absolute;
  transform: translateZ(6px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
}

[data-motion="off"] .guitar__sway { animation: none; }
[data-motion="off"] .guitar__flip,
[data-motion="off"] .guitar.is-flipped .guitar__flip { transition: none; transform: none; }
[data-motion="off"] .guitar__front,
[data-motion="off"] .guitar__layer--back { transition: opacity var(--m-base) linear; }
[data-motion="off"] .guitar__layer--back { transform: none; opacity: 0; transition: opacity var(--m-base) linear, visibility 0s; }
[data-motion="off"] .guitar.is-flipped .guitar__layer--back { opacity: 1; }
[data-motion="off"] .guitar.is-flipped .guitar__front { opacity: 0; }

/* WebGL guitar (core/guitar/gl-guitar.js): a transparent canvas in the same slot */
.guitar-gl canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.guitar-gl .guitar__shadow { left: 8%; right: 10%; bottom: 6%; height: 20%; }
