/* Monster Puppet Theater — Antique Wood & Faded Storybook
   Palette follows .kiro/specs/monster-ensemble/design.md section 1. No fluorescent colors. */

:root {
  --bg-stage-dark: #1A1412;
  --wood-frame: #4A3228;
  --wood-highlight: #6E4B3A;
  --brass-accent: #C5A059;
  --curtain-red: #6B1D2F;
  --curtain-shadow: #3D0E19;
  --parchment-bg: #F2E6D0;
  --sepia-ink: #2C1E18;
  --candle: #F7C873;
  --string: rgba(212, 195, 163, 0.35);

  --brass-grad: linear-gradient(180deg, #E4C98A 0%, #C5A059 45%, #8E6F33 100%);
  --font-display: 'Palatino Linotype', 'Book Antiqua', Palatino, 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif;
  --font-body: 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', Georgia, serif;
}

* { box-sizing: border-box; }

html { background: var(--bg-stage-dark); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--parchment-bg);
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(110, 75, 58, 0.35), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 0.6), transparent 70%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 46px),
    var(--bg-stage-dark);
}

/* ---------- Marquee ---------- */
.marquee { text-align: center; padding: 28px 16px 8px; }
.marquee__eyebrow {
  margin: 0; font-size: 0.8rem; letter-spacing: 0.4em; color: var(--brass-accent); opacity: 0.85;
}
.marquee__title {
  margin: 6px 0 2px;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #F0DCA3 0%, #C5A059 50%, #8E6F33 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.6));
}
.marquee__sub { margin: 0; font-style: italic; font-size: 0.9rem; opacity: 0.6; letter-spacing: 0.12em; }

.theater { width: min(980px, 100% - 24px); margin: 0 auto; padding-bottom: 56px; }

/* ---------- Wooden frame (proscenium) ---------- */
.proscenium {
  position: relative;
  padding: 3.6% 3.6% 7.5%;
  border-radius: 10px;
  background:
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.12) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(88deg, rgba(255, 220, 170, 0.04) 0 3px, transparent 3px 17px),
    linear-gradient(180deg, var(--wood-highlight), var(--wood-frame) 40%, #3A2620);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.55),
    inset 0 0 0 5px var(--wood-highlight),
    inset 0 0 0 7px rgba(0, 0, 0, 0.5),
    inset 0 0 40px rgba(0, 0, 0, 0.5),
    0 24px 50px rgba(0, 0, 0, 0.75);
}

/* Brass corner rosettes */
.frame-corner {
  position: absolute; width: 5.2%; aspect-ratio: 1; z-index: 6;
  background: radial-gradient(circle at 35% 30%, #F0DCA3, #C5A059 45%, #6E5222 100%);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}
.frame-corner::after {
  content: ''; position: absolute; inset: 28%; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #8E6F33, #3A2A10);
}
.frame-corner--tl { top: 0.8%; left: 0.8%; }
.frame-corner--tr { top: 0.8%; right: 0.8%; }
.frame-corner--bl { bottom: 0.8%; left: 0.8%; }
.frame-corner--br { bottom: 0.8%; right: 0.8%; }

/* ---------- Stage ---------- */
.stage {
  position: relative; overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #120D0B;
  box-shadow: 0 0 0 3px #1b110d, 0 0 0 5px var(--brass-accent), 0 0 0 7px #1b110d, inset 0 0 60px rgba(0, 0, 0, 0.8);
}

/* Faded storybook backdrop: moon, hills, crooked manor, bare tree, with paper grain noise. */
.backdrop {
  position: absolute; inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 450' preserveAspectRatio='none'%3E%3Cdefs%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .95 0 0 0 0 .88 0 0 0 0 .75 0 0 0 .16 0'/%3E%3C/filter%3E%3C/defs%3E%3Ccircle cx='610' cy='105' r='70' fill='%23F2E6D0' opacity='.12'/%3E%3Ccircle cx='610' cy='105' r='46' fill='%23E8D9B5' opacity='.85'/%3E%3Ccircle cx='596' cy='96' r='8' fill='%23C9B88F' opacity='.6'/%3E%3Ccircle cx='626' cy='120' r='5' fill='%23C9B88F' opacity='.6'/%3E%3Cpath d='M0 330 Q110 262 240 312 T500 300 T800 288 V450 H0Z' fill='%232b1f1d'/%3E%3Cg fill='%231d1413'%3E%3Cpath d='M150 318 V236 L172 214 L194 236 V318Z'/%3E%3Cpath d='M130 236 L172 190 L214 236Z'/%3E%3Crect x='198' y='258' width='34' height='60'/%3E%3Cpath d='M194 258 L215 232 L236 258Z'/%3E%3Cpath d='M170 190 V170 h4 v20z'/%3E%3C/g%3E%3Cg fill='%23C5A059' opacity='.65'%3E%3Crect x='162' y='246' width='8' height='12'/%3E%3Crect x='176' y='246' width='8' height='12'/%3E%3Crect x='208' y='274' width='7' height='10'/%3E%3C/g%3E%3Cpath d='M60 330 V268 M60 290 L38 270 M60 280 L84 258 M60 300 L40 292 M84 258 L96 244 M38 270 L28 252' stroke='%231d1413' stroke-width='5' stroke-linecap='round' fill='none'/%3E%3Cpath d='M0 372 Q200 340 420 366 T800 356 V450 H0Z' fill='%23231918'/%3E%3Crect width='800' height='450' filter='url(%23n)'/%3E%3C/svg%3E") center / 100% 100% no-repeat,
    linear-gradient(180deg, #3b3040 0%, #5b4046 38%, #7d5a4b 62%, #3a2a25 100%);
  filter: sepia(0.35) saturate(0.75) brightness(0.85);
}

/* Overhead spotlight while the show is on */
.spotlight {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse 60% 85% at 50% 0%, rgba(247, 200, 115, 0.22), transparent 70%);
  transition: opacity 1.4s ease 0.5s;
}

/* Floorboards */
.floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 17%;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.45) 0 2px, transparent 2px 9%),
    repeating-linear-gradient(180deg, rgba(255, 220, 170, 0.05) 0 3px, transparent 3px 8px),
    linear-gradient(180deg, #2a1c16 0%, #4a3228 100%);
  border-top: 2px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 14px 18px -8px rgba(0, 0, 0, 0.7);
}
/* Footlight glow reflected on the floor */
.floor::after {
  content: ''; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse 70% 120% at 50% 100%, rgba(247, 200, 115, 0.5), transparent 70%);
  transition: opacity 1s ease 0.6s;
}

/* ---------- Puppets (shared layout; each puppet's own art and motion has its section below) ---------- */
.puppets {
  position: absolute; inset: 0 5% 3% 5%;
  display: flex; justify-content: space-around; align-items: flex-start;
  padding-top: 9%;
}
.puppet {
  position: relative; width: 22%; cursor: pointer;
  transform-origin: 50% 0;
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, 0.55));
  animation: sway 4.6s ease-in-out infinite;
}
.puppet:nth-child(2) { animation-duration: 5.4s; animation-delay: -1.3s; }
.puppet:nth-child(3) { animation-duration: 4.1s; animation-delay: -2.2s; }
.puppet:nth-child(4) { animation-duration: 6.2s; animation-delay: -0.6s; }
.puppet svg {
  display: block; width: 100%; height: auto; overflow: visible;
  /* --energy (0..1) comes from the audio engine; real per-puppet motion arrives in Tasks 3, 5, 6 and 7. */
  transform: scale(calc(1 + var(--energy, 0) * 0.05));
  transform-origin: 50% 0;
}
.puppet:hover { filter: drop-shadow(0 6px 5px rgba(0, 0, 0, 0.55)) brightness(1.08); }

/* Brass nameplate at the feet of the selected puppet */
.puppet::after {
  content: attr(data-name);
  position: absolute; left: 50%; bottom: -3%; transform: translateX(-50%);
  padding: 1px 10px; border-radius: 3px; white-space: nowrap;
  font-size: clamp(8px, 1.15vw, 12px); letter-spacing: 0.1em; color: #2a1d08;
  background: var(--brass-grad);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  opacity: 0; transition: opacity 0.3s;
}
.puppet.is-selected::after { opacity: 0.95; }

.puppet .body { transform-origin: 70px 212px; transform-box: view-box; }
.puppet .zzz { opacity: 0; }
.puppet .eyes { transform-origin: 70px 140px; transition: transform 0.4s; }

/* Dozing pose (Mute, or silenced by another track's Solo) */
.puppet.is-asleep .body { filter: brightness(0.62) saturate(0.55); transform: scaleY(0.94); }
.puppet.is-asleep .eyes { transform: scaleY(0.12); }
.puppet.is-asleep .zzz { opacity: 0.9; animation: zzz 3s ease-in-out infinite; }

/* ---------- Crimson velvet curtains ---------- */
.curtain {
  position: absolute; top: 0; bottom: 0; width: 52%; z-index: 4;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 18%, transparent 70%, rgba(0, 0, 0, 0.5)),
    repeating-linear-gradient(90deg,
      rgba(0, 0, 0, 0.42) 0, rgba(255, 255, 255, 0.07) 9px, rgba(0, 0, 0, 0) 20px,
      rgba(0, 0, 0, 0.3) 34px, rgba(255, 255, 255, 0.05) 44px, rgba(0, 0, 0, 0.38) 56px),
    linear-gradient(90deg, var(--curtain-shadow), var(--curtain-red) 50%, var(--curtain-shadow));
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.7);
  transition: transform 1.3s cubic-bezier(0.65, 0, 0.25, 1);
}
.curtain::after { /* Gold fringe along the hem */
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2.6%;
  background: repeating-linear-gradient(90deg, #C5A059 0 3px, #8E6F33 3px 6px);
  opacity: 0.85;
}
.curtain--left  { left: 0;  transform-origin: left center;  border-right: 1px solid rgba(0, 0, 0, 0.5); }
.curtain--right { right: 0; transform-origin: right center; border-left: 1px solid rgba(0, 0, 0, 0.5); }

.proscenium[data-state='open'] .curtain--left,
.proscenium[data-state='curtain_call'] .curtain--left   { transform: translateX(-16%) scaleX(0.26); transition-duration: 1.7s; }
.proscenium[data-state='open'] .curtain--right,
.proscenium[data-state='curtain_call'] .curtain--right  { transform: translateX(16%) scaleX(0.26); transition-duration: 1.7s; }

.curtain-hint {
  position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); z-index: 5;
  padding: 6px 22px; border-radius: 2px; white-space: nowrap;
  font-family: var(--font-display); font-style: italic; letter-spacing: 0.22em;
  font-size: clamp(0.7rem, 1.9vw, 1.1rem);
  color: var(--brass-accent); text-shadow: 0 1px 0 #000;
  border: 1px solid rgba(197, 160, 89, 0.55); background: rgba(40, 8, 16, 0.55);
  pointer-events: none; transition: opacity 0.4s;
}
.proscenium:not([data-state='closed']) .curtain-hint { opacity: 0; }

/* Top valance */
.valance {
  position: absolute; z-index: 5; left: 3.6%; right: 3.6%; top: 3.6%;
  height: 7.5%;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.3) 0 2px, rgba(255, 255, 255, 0.05) 2px 14px, transparent 14px 28px),
    linear-gradient(180deg, #7b2338, var(--curtain-red) 60%, var(--curtain-shadow));
  border-bottom: 3px solid var(--brass-accent);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6);
}
.valance::after { /* Scalloped edge */
  content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 55%;
  background: radial-gradient(circle at 50% 0, var(--curtain-red) 0 62%, transparent 64%) 0 0 / 8.333% 100% repeat-x;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.55));
  -webkit-mask: none;
}
.valance__tassel {
  position: absolute; top: 55%; width: 2.2%; height: 190%;
  background: var(--brass-grad); border-radius: 40% 40% 50% 50% / 20% 20% 80% 80%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); z-index: 2;
}
.valance__tassel--l { left: 2%; }
.valance__tassel--r { right: 2%; }

/* ---------- Candle footlights ---------- */
.footlights {
  position: absolute; z-index: 7; left: 9%; right: 9%; bottom: 1.4%; height: 6.2%;
  display: flex; justify-content: space-between; align-items: flex-end;
  font-size: clamp(8px, 1.45vw, 15px);
}
.footlights::before { /* Brass tray */
  content: ''; position: absolute; left: -2%; right: -2%; bottom: -0.3em; height: 0.7em;
  background: var(--brass-grad); border-radius: 0.4em;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.candle { position: relative; width: 1.2em; height: 2.8em; display: flex; justify-content: center; }
.wax {
  position: absolute; bottom: 0; width: 100%; height: 2em; border-radius: 0.25em 0.25em 0.1em 0.1em;
  background: linear-gradient(90deg, #cbb98f, #F0E3C0 40%, #cbb98f);
  box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.25);
}
.wax::after { /* Dripped wax */
  content: ''; position: absolute; top: 0; left: 18%; width: 22%; height: 55%;
  background: #F6EBCB; border-radius: 0 0 50% 50%;
}
.wick { position: absolute; bottom: 2em; width: 2px; height: 0.45em; background: #1a120d; }
.flame {
  position: absolute; bottom: 2.35em; width: 0.7em; height: 1.35em; opacity: 0;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 78%, #fffbe6 0%, var(--candle) 45%, #D97236 100%);
  box-shadow: 0 0 0.9em 0.35em rgba(247, 200, 115, 0.55), 0 0 2.4em 0.8em rgba(217, 114, 54, 0.3);
  transform-origin: 50% 100%;
  transition: opacity 0.7s ease;
  transition-delay: calc(var(--d) * 0.6);
}

/* Lit while the show is open and during the curtain call */
.proscenium[data-state='open'] .flame,
.proscenium[data-state='curtain_call'] .flame { opacity: 1; animation: flicker 1.6s ease-in-out infinite; animation-delay: var(--d); }
.proscenium[data-state='open'] .spotlight,
.proscenium[data-state='curtain_call'] .spotlight,
.proscenium[data-state='open'] .floor::after,
.proscenium[data-state='curtain_call'] .floor::after { opacity: 1; }

/* Curtain call: all puppets bow together (kept within about 1.8 s) */
.proscenium[data-state='curtain_call'] .puppet .body {
  animation: bow 1.5s ease-in-out both;
}
.proscenium[data-state='curtain_call'] .puppet:nth-child(2) .body { animation-delay: 0.06s; }
.proscenium[data-state='curtain_call'] .puppet:nth-child(3) .body { animation-delay: 0.12s; }
.proscenium[data-state='curtain_call'] .puppet:nth-child(4) .body { animation-delay: 0.18s; }

@keyframes sway { 0%, 100% { transform: rotate(-1.3deg); } 50% { transform: rotate(1.3deg); } }
@keyframes flicker {
  0%, 100% { transform: scale(1, 1) rotate(0); }
  18% { transform: scale(0.92, 1.1) rotate(-2deg); }
  42% { transform: scale(1.06, 0.93) rotate(1.5deg); }
  66% { transform: scale(0.95, 1.07) rotate(-1deg); }
  82% { transform: scale(1.03, 0.98) rotate(2deg); }
}
@keyframes bow {
  0%   { transform: rotate(0) scaleY(1); }
  32%  { transform: rotate(7deg) scaleY(0.84) translateY(6px); }
  62%  { transform: rotate(7deg) scaleY(0.84) translateY(6px); }
  100% { transform: rotate(0) scaleY(1); }
}
@keyframes zzz { 0%, 100% { transform: translateY(0); opacity: 0.55; } 50% { transform: translateY(-7px); opacity: 1; } }

/* ---------- Pumpkin puppet (Task 3) ---------- */
/* --energy (0..1, audio-synced) drives the mouth, the candle light and a small head hop.
   --lit is the candle inside the pumpkin: on while awake (and brighter with every note), out when it dozes. */
.puppet--pumpkin { --lit: 1; }
.puppet--pumpkin.is-asleep { --lit: 0.05; }
.puppet--pumpkin svg { transform: none; }          /* the generic energy pulse is replaced by real motion */
.puppet--pumpkin:focus-visible { outline: 2px solid #F7C873; outline-offset: 4px; border-radius: 8px; }

.pk-head { transform: translateY(calc(var(--energy, 0) * -2.5px)); }
.pk-hole { fill: #2a1410; stroke: #2C1E18; stroke-width: 2; stroke-linejoin: round; }
.pk-glow {
  fill: url(#pk-glow); opacity: var(--lit); transition: opacity 0.35s;
  filter: brightness(calc(0.92 + var(--energy, 0) * 0.4)) drop-shadow(0 0 calc(2px + var(--energy, 0) * 5px) rgba(247, 200, 115, 0.85));
}
.pk-halo { opacity: calc(var(--lit) * (0.18 + var(--energy, 0) * 0.5)); filter: blur(5px); animation: pk-flicker 2.3s ease-in-out infinite; }

/* mouth: closed smile at rest, opens on every note and closes as the energy decays */
.pk-mouth { transform-box: view-box; transform-origin: 70px 165px; transform: scaleY(calc(0.3 + var(--energy, 0) * 0.95)); }
.pk-mouth-1 { transform-origin: 70px 175px; transform: scale(calc(0.9 + var(--energy, 0) * 0.2), calc(0.55 + var(--energy, 0) * 0.85)); }
.pk-mouth-2 { transform-origin: 70px 167px; }
.pk-fangs { transform: translateY(calc(var(--energy, 0) * 3.5px)); }

/* eyes blink now and then; they close for good when the puppet dozes */
.pk-eyes { transform-box: fill-box; transform-origin: center; animation: pk-blink 5.8s infinite; }
.pk-lids { display: none; }
.puppet--pumpkin.is-asleep .pk-eyes { display: none !important; }
.puppet--pumpkin.is-asleep .pk-lids { display: inline; }
.puppet--pumpkin.is-asleep .pk-mouth { transform: scaleY(0.18); }
.puppet--pumpkin.is-asleep .pk-head { transform: translateY(3px); }

.pk-leg { transform-box: view-box; transform-origin: 70px 190px; animation: pk-leg 3.4s ease-in-out infinite; }
.pk-leg-r { animation-delay: -1.7s; }
.puppet--pumpkin.is-asleep .pk-leg { animation: none; }

@keyframes pk-flicker { 0%, 100% { transform: scale(1); } 40% { transform: scale(0.94); } 70% { transform: scale(1.04); } }
@keyframes pk-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } }
@keyframes pk-leg { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

/* ---------- Skeleton puppet (Task 5) ---------- */
/* The art brings its own <style> for variants and arm rotation (js/skeleton-art.js). These are the
   rules that depend on the state of the show: the beat, the dozing pose and the curtain-call gag. */
.puppet--skeleton svg { transform: none; }          /* the generic energy pulse is replaced by real motion */
.puppet--skeleton:focus-visible { outline: 2px solid #F7C873; outline-offset: 4px; border-radius: 8px; }

.sk-body {
  transform: translate(var(--sk-bx, 0px), var(--sk-by, 0px)) rotate(var(--sk-bt, 0deg)) scale(1, var(--sk-bsy, 1));
  transform-origin: 70px 231px;
}
.sk-head { transform: translateY(calc(var(--sk-kick, 0) * 4px)) rotate(calc(var(--sk-kick, 0) * 5deg)); transform-origin: 70px 143px; }
.sk-gear { transform: rotate(calc(var(--sk-snare, 0) * -5deg)); transform-origin: 70px 106px; }
.sk-key { transform: rotate(calc(var(--sk-kick, 0) * 70deg)); }

/* hugging-knees dozing pose: sits, head resting on the knees, eyes closed */
.puppet--skeleton.is-asleep .sk-standing { display: none; }
.puppet--skeleton.is-asleep .sk-seated, .puppet--skeleton.is-asleep .sk-lids { display: inline; }
.puppet--skeleton.is-asleep .sk-pupil { display: none; }
.puppet--skeleton.is-asleep .sk-head { transform: translate(0, 22px) rotate(9deg); }
.puppet--skeleton.is-asleep .sk-ribcage { transform: scaleY(0.95); transform-box: view-box; transform-origin: 70px 197px; }

/* curtain call: the skull tumbles off. gagPose() drives the variables; the generic bow is replaced. */
.puppet--skeleton.is-gag { z-index: 6; }
.puppet--skeleton.is-gag .body { animation: none !important; }
.puppet--skeleton.is-gag .sk-head { transform: translate(var(--sk-hx, 0px), var(--sk-hy, 0px)) rotate(var(--sk-hr, 0deg)); transform-origin: 70px 124px; }
.puppet--skeleton.is-gag .sk-gear { transform: none; }

/* ---------- Witch's Cauldron puppet (Task 6) ---------- */
/* --energy (0..1, audio-synced) thumps the pot, lifts the ingredient and feeds the fire. The poison
   bubbles are drawn by BubbleField (js/cauldron-art.js). --lit is the fire and the glow: on while awake. */
.puppet--cauldron { --lit: 1; }
.puppet--cauldron.is-asleep { --lit: 0.08; }
.puppet--cauldron svg { transform: none; }          /* the generic energy pulse is replaced by real motion */
.puppet--cauldron:focus-visible { outline: 2px solid #F7C873; outline-offset: 4px; border-radius: 8px; }
.puppet--cauldron .cd-static { display: none; }

/* the pot thumps on each bass note */
.cd-pot-wrap { transform-box: view-box; transform-origin: 70px 204px; transform: scale(calc(1 + var(--energy, 0) * 0.03), calc(1 - var(--energy, 0) * 0.04)); }
.cd-brew { filter: brightness(calc(0.9 + var(--energy, 0) * 0.35)); }
.cd-ripple { transform-box: fill-box; transform-origin: center; opacity: calc(var(--energy, 0) * 0.9); transform: scale(calc(0.7 + (1 - var(--energy, 0)) * 0.5)); }

/* ingredients */
.cd-ingredient { transform: translateY(calc(var(--energy, 0) * -3px)); }
.cd-ing-1 { transform: translateY(calc(var(--energy, 0) * -7px)); }
.cd-glow { opacity: calc(0.35 + var(--lit) * (0.25 + var(--energy, 0) * 0.4)); transition: opacity 0.35s;
  filter: drop-shadow(0 0 calc(1px + var(--energy, 0) * 4px) rgba(168, 240, 138, 0.9)); }
.cd-cap { transform-box: view-box; transform-origin: 70px 108px; transition: transform 0.5s; }
.cd-baby { transform-box: fill-box; transform-origin: 50% 100%; animation: cd-sway 3.6s ease-in-out infinite; }
.cd-baby-r { animation-delay: -1.8s; }
.cd-key { transform-box: fill-box; transform-origin: 20% 80%; transform: rotate(calc(var(--energy, 0) * 80deg)); }
.cd-frog-eye-closed { display: none; }
.cd-frog-pupils { animation: cd-glance 6s ease-in-out infinite; }
.cd-iris { animation: cd-look 7s ease-in-out infinite; }
.cd-pupil { transform-box: fill-box; transform-origin: center; transform: scale(calc(1 + var(--energy, 0) * 0.45)) rotate(calc(var(--energy, 0) * 25deg)); }
.cd-lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); transition: transform 0.4s; animation: cd-eyeblink 6.2s infinite; }
.cd-sparkles > * { transform-box: fill-box; transform-origin: center; animation: cd-twinkle 2.6s ease-in-out infinite; }
.cd-sparkles > .cd-spark-b { animation-delay: -0.9s; } .cd-sparkles > .cd-spark-c { animation-delay: -1.7s; }

/* fire: leaps with each note, dims to embers while the cauldron dozes */
.cd-flame { transform-box: view-box; transform-origin: 70px 224px;
  transform: scale(calc(1 + var(--energy, 0) * 0.1), calc(1 + var(--energy, 0) * 0.3)); transition: opacity 0.4s; opacity: calc(0.35 + var(--lit) * 0.65); }
.cd-fl { transform-box: fill-box; transform-origin: 50% 100%; animation: cd-flicker 1.25s ease-in-out infinite; }
.cd-fl-in { animation-duration: 0.9s; }
.cd-halo { opacity: calc(var(--lit) * (0.45 + var(--energy, 0) * 0.55)); }
.cd-sp { animation: cd-spark 1.8s ease-out infinite; }
.cd-sp-b { animation-delay: -0.5s; } .cd-sp-c { animation-delay: -1.1s; } .cd-sp-d { animation-delay: -1.5s; }

/* simmering while dozing: a few slow bubbles, nothing more */
.cd-simmer { display: none; }
.cd-sim { transform-box: fill-box; transform-origin: center; animation: cd-simmer 3.4s ease-in-out infinite; }
.cd-sim-b { animation-duration: 4.1s; animation-delay: -1.3s; } .cd-sim-c { animation-duration: 2.9s; animation-delay: -2s; }
.puppet--cauldron.is-asleep .cd-simmer { display: inline; }
.puppet--cauldron.is-asleep .cd-flame { transform: scale(0.82, 0.5); }
.puppet--cauldron.is-asleep .cd-fl { animation-duration: 3.2s; }
.puppet--cauldron.is-asleep .cd-sparks { display: none; }
.puppet--cauldron.is-asleep .cd-ingredient { transform: translateY(2px); }
.puppet--cauldron.is-asleep .cd-cap { transform: rotate(7deg) translateY(2px); }
.puppet--cauldron.is-asleep .cd-baby { animation: none; transform: rotate(-9deg); }
.puppet--cauldron.is-asleep .cd-baby-r { transform: rotate(9deg); }
.puppet--cauldron.is-asleep .cd-frog-eye { display: none; }
.puppet--cauldron.is-asleep .cd-frog-eye-closed { display: inline; }
.puppet--cauldron.is-asleep .cd-lid { transform: scaleY(1); animation: none; }
.puppet--cauldron.is-asleep .cd-iris, .puppet--cauldron.is-asleep .cd-frog-pupils { animation: none; }

/* curtain call: the pot tips forward with the others (the shared bow) and the brew sloshes */
.proscenium[data-state='curtain_call'] .cd-brew { animation: cd-slosh 1.5s ease-in-out both; transform-box: fill-box; transform-origin: center; }
.proscenium[data-state='curtain_call'] .puppet--cauldron .cd-ingredient { animation: cd-nod 1.5s ease-in-out both; transform-box: view-box; transform-origin: 70px 141px; }

@keyframes cd-flicker {
  0%, 100% { transform: scale(1, 1) skewX(0); }
  22% { transform: scale(0.9, 1.12) skewX(-3deg); }
  48% { transform: scale(1.06, 0.92) skewX(2deg); }
  74% { transform: scale(0.95, 1.08) skewX(-1.5deg); }
}
@keyframes cd-spark { 0% { transform: translate(0, 6px); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(5px, -16px); opacity: 0; } }
@keyframes cd-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes cd-glance { 0%, 38%, 100% { transform: translateX(0); } 45%, 62% { transform: translateX(-1.6px); } 70%, 90% { transform: translateX(1.6px); } }
@keyframes cd-look { 0%, 30%, 100% { transform: translate(0, 0); } 40%, 55% { transform: translate(-3.4px, 1px); } 65%, 85% { transform: translate(3.4px, -1.4px); } }
@keyframes cd-eyeblink { 0%, 94%, 100% { transform: scaleY(0); } 97% { transform: scaleY(1); } }
@keyframes cd-twinkle { 0%, 100% { transform: scale(0.6) rotate(0); opacity: 0.5; } 50% { transform: scale(1.1) rotate(25deg); opacity: 1; } }
@keyframes cd-simmer { 0% { transform: translateY(3px) scale(0.5); opacity: 0; } 30% { opacity: 1; } 70% { transform: translateY(-4px) scale(1.15); opacity: 1; } 78%, 100% { transform: translateY(-5px) scale(1.5); opacity: 0; } }
@keyframes cd-slosh { 0%, 100% { transform: scale(1) rotate(0); } 30%, 60% { transform: scale(1.04, 1.4) rotate(-5deg); } 45% { transform: scale(1.02, 1.2) rotate(4deg); } }
@keyframes cd-nod { 0%, 100% { transform: rotate(0) translateY(0); } 32%, 62% { transform: rotate(-9deg) translateY(2px); } }

/* ---------- Ghost puppet (Task 7) ---------- */
/* ghostPose() (js/ghost-art.js) sets --gh-sx / --gh-sy / --gh-lean / --gh-sus from the audio clock:
   the sheet stretches with every note and breathes while a chord is held. --lit lights the item. */
.puppet--ghost { --lit: 1; }
.puppet--ghost.is-asleep { --lit: 0.1; }
.puppet--ghost svg { transform: none; }          /* the generic energy pulse is replaced by real motion */
.puppet--ghost:focus-visible { outline: 2px solid #F7C873; outline-offset: 4px; border-radius: 8px; }

.gh-float { animation: gh-float 4.2s ease-in-out infinite; }
.gh-shadow { transform-box: fill-box; transform-origin: center; animation: gh-shadow 4.2s ease-in-out infinite; }
.gh-squash {
  transform-box: view-box; transform-origin: 70px 214px;
  transform: rotate(var(--gh-lean, 0deg)) scale(var(--gh-sx, 1), var(--gh-sy, 1));
}

/* face: the mouth opens as the pad swells; tears run on the fretful face */
.gh-mouth { transform-box: fill-box; transform-origin: 50% 30%; transform: scale(calc(0.85 + var(--gh-sus, 0) * 0.3), calc(0.8 + var(--gh-sus, 0) * 0.4)); }
.gh-closed { display: none; }
.gh-open { transform-box: fill-box; transform-origin: center; animation: gh-blink 6.4s infinite; }
.gh-tear { transform-box: fill-box; transform-origin: 50% 0; animation: gh-tear 2.8s ease-in infinite; }
.gh-tear-r { animation-delay: -1.4s; }

/* hats */
.gh-cap { transform-box: view-box; transform-origin: 70px 112px; transition: transform 0.5s; }
.gh-pom { transform-box: fill-box; transform-origin: 50% 100%; animation: gh-pom 3.6s ease-in-out infinite; }

/* items */
.gh-lit { opacity: calc(var(--lit) * (0.3 + var(--gh-sus, 0) * 0.65)); }
.gh-flame { transform-box: fill-box; transform-origin: 50% 100%; transform: scale(calc(0.85 + var(--gh-sus, 0) * 0.3)); animation: cd-flicker 1.3s ease-in-out infinite; }
.gh-glass { filter: brightness(calc(0.8 + var(--gh-sus, 0) * 0.5)); }
.gh-swing { transform-box: view-box; transform-origin: 120px 178px; animation: gh-swing 3.2s ease-in-out infinite; }
.gh-hand { transform-box: view-box; transform-origin: 120px 207px; animation: gh-tick 8s steps(8) infinite; }
.gh-quill { transform-box: view-box; transform-origin: 120px 176px; animation: gh-write 2.4s ease-in-out infinite; }
.gh-note { animation: gh-notes 1.07s ease-in-out infinite; }

/* dozing: floats low and slow, eyes shut, the hat slumps and the item rests */
.puppet--ghost.is-asleep .gh-float { animation: none; transform: translateY(5px); }
.puppet--ghost.is-asleep .gh-shadow { animation: none; transform: scale(1.12); }
.puppet--ghost.is-asleep .gh-open { display: none; }
.puppet--ghost.is-asleep .gh-closed { display: inline; }
.puppet--ghost.is-asleep .gh-mouth { transform: scale(0.55, 0.4); }
.puppet--ghost.is-asleep .gh-blush { opacity: 0.75; }
.puppet--ghost.is-asleep .gh-tear { animation: none; }
.puppet--ghost.is-asleep .gh-cap { transform: translate(3px, 5px) rotate(9deg); }
.puppet--ghost.is-asleep .gh-pom { animation: none; transform: rotate(18deg); }
.puppet--ghost.is-asleep .gh-flame { animation: none; transform: scale(0.5); }
.puppet--ghost.is-asleep .gh-swing, .puppet--ghost.is-asleep .gh-hand, .puppet--ghost.is-asleep .gh-note { animation: none; }
.puppet--ghost.is-asleep .gh-quill { animation: none; transform: rotate(-38deg); }

/* curtain call: the ghost tips forward with the others and doffs its hat */
.proscenium[data-state='curtain_call'] .puppet--ghost .gh-cap { animation: gh-doff 1.5s ease-in-out both; }

@keyframes gh-float { 0%, 100% { transform: translateY(1px); } 50% { transform: translateY(-3.5px); } }
@keyframes gh-shadow { 0%, 100% { transform: scale(1); opacity: 0.25; } 50% { transform: scale(0.86); opacity: 0.17; } }
@keyframes gh-blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
@keyframes gh-tear { 0% { transform: translateY(-2px) scale(0.5); opacity: 0; } 25% { transform: translateY(0) scale(1); opacity: 1; } 80% { transform: translateY(9px) scale(0.9); opacity: 0.85; } 100% { transform: translateY(14px) scale(0.6); opacity: 0; } }
@keyframes gh-pom { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(7deg); } }
@keyframes gh-swing { 0%, 100% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } }
@keyframes gh-tick { to { transform: rotate(360deg); } }
@keyframes gh-write { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(5deg); } }
@keyframes gh-notes { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.4px); } }
@keyframes gh-doff { 0%, 100% { transform: translate(0, 0) rotate(0); } 30%, 62% { transform: translate(-6px, -11px) rotate(-16deg); } }

/* ---------- Play / Stop buttons ---------- */
.controls { display: flex; justify-content: center; gap: 18px; margin: 28px 0 24px; }
.btn {
  min-width: 150px; padding: 12px 26px; cursor: pointer;
  font-family: var(--font-display); font-size: 1.15rem; letter-spacing: 0.12em; font-weight: 700;
  color: #2a1d08; border: 0; border-radius: 6px;
  background: var(--brass-grad);
  box-shadow: 0 4px 0 #5e4818, 0 8px 14px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.2s;
}
.btn span { display: block; font-size: 0.65rem; font-weight: 400; letter-spacing: 0.3em; opacity: 0.75; }
.btn--stop { color: var(--parchment-bg); background: linear-gradient(180deg, #8a2a42, var(--curtain-red) 55%, var(--curtain-shadow)); box-shadow: 0 4px 0 #260810, 0 8px 14px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #5e4818, 0 3px 6px rgba(0, 0, 0, 0.6); }
.btn:disabled { cursor: not-allowed; filter: grayscale(0.7) brightness(0.55); }
.btn:focus-visible, .tab:focus-visible, .opt:focus-visible, .toggle:focus-visible { outline: 2px solid var(--candle); outline-offset: 3px; }

/* ---------- Program plaque: band name, song title, souvenirs ---------- */
.playbill {
  margin: 0 auto 26px; padding: 22px 26px 18px; text-align: center; border-radius: 8px;
  background:
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.12) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #3a2620, #2a1c16);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.6), inset 0 0 0 4px var(--brass-accent), inset 0 0 0 6px rgba(0, 0, 0, 0.6), 0 14px 26px rgba(0, 0, 0, 0.55);
}
.playbill__eyebrow { margin: 0; font-size: 0.75rem; letter-spacing: 0.4em; text-transform: uppercase; color: var(--brass-accent); opacity: 0.85; }
.playbill__band {
  margin: 8px 0 2px; font-family: var(--font-display); font-size: clamp(1.4rem, 3.6vw, 2.2rem); line-height: 1.2; letter-spacing: 0.03em;
  background: linear-gradient(180deg, #F0DCA3, #C5A059 55%, #8E6F33);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.6));
}
.playbill__tagline { margin: 0 0 12px; font-style: italic; font-size: 0.95rem; opacity: 0.8; }
.playbill__song { margin: 0; font-family: var(--font-display); font-style: italic; font-size: 1.2rem; color: var(--parchment-bg); }
.playbill__song::before { content: '\201C'; }
.playbill__song::after { content: '\201D'; }
.playbill__genre { margin: 2px 0 16px; font-size: 0.85rem; letter-spacing: 0.12em; opacity: 0.7; }
.playbill__actions { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.btn--small { min-width: 210px; padding: 10px 20px; font-size: 1rem; letter-spacing: 0.06em; }
.playbill__status { min-height: 1.3em; margin: 12px 0 0; font-size: 0.8rem; font-style: italic; opacity: 0.8; }

/* ---------- Editor panel (parchment) ---------- */
.tabs { display: flex; gap: 6px; padding: 0 12px; }
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 6px 8px; cursor: pointer; color: var(--parchment-bg);
  font-family: var(--font-body); font-size: 0.95rem;
  background: linear-gradient(180deg, var(--wood-highlight), var(--wood-frame));
  border: 1px solid #1b110d; border-bottom: 0; border-radius: 8px 8px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  opacity: 0.72; transition: opacity 0.2s, transform 0.2s;
}
.tab:hover { opacity: 0.95; }
.tab[aria-selected='true'] {
  opacity: 1; color: var(--sepia-ink); transform: translateY(1px);
  background: var(--parchment-bg); font-weight: 700;
}
.tab__icon { font-size: 1.25rem; }

.panel {
  --puppet: var(--brass-accent);
  padding: 20px 22px 24px; color: var(--sepia-ink);
  border-radius: 6px; border: 1px solid #1b110d;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 255, 255, 0.35), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(120, 80, 40, 0.28), transparent 60%),
    var(--parchment-bg);
  box-shadow: inset 0 0 40px rgba(120, 80, 40, 0.25), 0 12px 24px rgba(0, 0, 0, 0.55);
}
.panel__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel__title { margin: 0; font-family: var(--font-display); font-size: 1.5rem; }
.panel__role { margin: 2px 0 0; font-style: italic; font-size: 0.85rem; opacity: 0.7; }
.panel__toggles { display: flex; gap: 8px; }

.toggle {
  padding: 6px 16px; cursor: pointer; font-family: var(--font-body); font-size: 0.85rem; letter-spacing: 0.08em;
  color: var(--sepia-ink); background: transparent; border: 1.5px solid var(--sepia-ink); border-radius: 999px;
  transition: background 0.2s, color 0.2s;
}
.toggle:hover { background: rgba(44, 30, 24, 0.1); }
.toggle[aria-pressed='true'] { background: var(--sepia-ink); color: var(--parchment-bg); }

.slots { display: grid; gap: 12px; }
.slot { margin: 0; padding: 8px 12px 12px; border: 1px dashed rgba(44, 30, 24, 0.45); border-radius: 4px; }
.slot legend { padding: 0 8px; font-size: 0.9rem; }
.slot legend b { font-family: var(--font-display); margin: 0 4px; }
.slot legend small { opacity: 0.6; }
.slot__opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.opt {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 10px 8px 14px; cursor: pointer; text-align: left;
  font-family: var(--font-body); color: var(--sepia-ink);
  background: rgba(255, 255, 255, 0.35); border: 1px solid rgba(44, 30, 24, 0.35); border-radius: 4px;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.opt::before { /* Bookmark strip in the puppet color */
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: 4px 0 0 4px;
  background: var(--puppet); opacity: 0.3; transition: opacity 0.15s;
}
.opt:hover { background: rgba(255, 255, 255, 0.65); transform: translateY(-1px); }
.opt[aria-pressed='true'] {
  background: #fff7e2; border-color: var(--sepia-ink);
  box-shadow: 0 0 0 1.5px var(--brass-accent), 0 3px 8px rgba(44, 30, 24, 0.3);
}
.opt[aria-pressed='true']::before { opacity: 1; }
.opt__name { font-weight: 700; font-size: 0.92rem; }
.opt__note { font-size: 0.7rem; opacity: 0.65; font-style: italic; letter-spacing: 0.03em; }

/* ---------- Narrow screens ---------- */
@media (max-width: 640px) {
  .slot__opts { grid-template-columns: 1fr; }
  .tab__name { display: none; }
  .btn { min-width: 120px; padding: 10px 18px; }
  .curtain-hint { letter-spacing: 0.1em; }
}

@media (prefers-reduced-motion: reduce) {
  .puppet, .flame, .pk-halo, .pk-eyes, .pk-leg { animation: none !important; }
  .curtain { transition-duration: 0.01s !important; }
}
