:root {
  --ink: #0a0507;
  --night: #14080c;
  --wine: #4a0e1c;
  --crimson: #9b1b30;
  --rose: #e8a0a8;
  --gold: #d9b67c;
  --champagne: #f4e6cf;
  --paper: #f3e8d6;
  --paper-ink: #2b1218;
  --serif: 'Cormorant Garamond', 'Cormorant', Georgia, 'Times New Roman', serif;
  --script: 'Pinyon Script', 'Snell Roundhand', 'Apple Chancery', cursive;
  /* driven from JS every frame (0..1) */
  --energy: 0;
  --beat: 0;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 110%, rgba(74, 14, 28, calc(0.55 + var(--energy) * 0.4)), transparent 60%),
    radial-gradient(80% 60% at 50% 40%, var(--night), var(--ink));
  color: var(--champagne);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 1px solid var(--gold); outline-offset: 6px; }

#bars, #burst { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#bars { z-index: 1; }
#burst { z-index: 6; }

/* film grain */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 9;
  pointer-events: none;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.9s steps(6) infinite;
}

/* ───────────── custom cursor ───────────── */
.has-cursor, .has-cursor * { cursor: none !important; }
.cursor-dot, .cursor-ring {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
}
.cursor-on .cursor-dot, .cursor-on .cursor-ring { opacity: 1; }
/* stays visible on dark night and on light paper */
.stage-live .cursor-dot, .stage-live .cursor-ring { mix-blend-mode: difference; }
.cursor-dot::before, .cursor-ring::before {
  content: '';
  position: absolute;
  border-radius: 50%;
  translate: -50% -50%;
  transition: width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
    background 0.3s, border-color 0.3s;
}
.cursor-dot::before {
  width: 6px;
  height: 6px;
  background: var(--champagne);
  box-shadow: 0 0 10px var(--gold), 0 0 22px rgba(217, 182, 124, 0.6);
}
.cursor-ring::before {
  width: calc(34px + var(--beat) * 14px);
  height: calc(34px + var(--beat) * 14px);
  border: 1px solid rgba(217, 182, 124, 0.55);
}
.cursor-hot .cursor-ring::before {
  width: 64px;
  height: 64px;
  border-color: var(--rose);
  background: rgba(155, 27, 48, 0.18);
}
.cursor-hot .cursor-dot::before { background: var(--rose); }
.cursor-down .cursor-ring::before { width: 22px; height: 22px; }
.stage-enter .cursor-ring::before { border-color: rgba(244, 230, 207, 0.25); }

/* ───────────── 1 · enter ───────────── */
.enter {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 28px;
  text-align: center;
  transition: opacity 1s, filter 1s;
}
/* the wandering light */
.enter::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle 260px at var(--mx, 50%) var(--my, 50%), rgba(232, 160, 168, 0.09), transparent 70%);
}
.enter__hidden {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(circle 170px at var(--mx, 50%) var(--my, 50%), #000 10%, transparent 100%);
  mask-image: radial-gradient(circle 170px at var(--mx, 50%) var(--my, 50%), #000 10%, transparent 100%);
}
.enter__hidden span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  rotate: var(--r);
  font-family: var(--script);
  font-size: clamp(1.4rem, 3.4vw, 2.6rem);
  color: var(--rose);
  opacity: 0.75;
  white-space: nowrap;
  text-shadow: 0 0 18px rgba(155, 27, 48, 0.8);
}

.enter__whisper {
  min-height: 1.4em;
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1.3rem, 3vw, 2rem);
  letter-spacing: 0.06em;
  color: var(--champagne);
  opacity: 0;
  filter: blur(8px);
  translate: 0 8px;
  transition: opacity 1.4s, filter 1.4s, translate 1.4s;
}
.enter__whisper.is-in { opacity: 0.85; filter: blur(0); translate: 0 0; }

.seal {
  position: relative;
  width: 112px;
  height: 112px;
  opacity: 0;
  scale: 0.6;
  pointer-events: none;
  transition: opacity 1.6s, scale 1.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.seal-ready .seal { opacity: 1; scale: 1; pointer-events: auto; }
.seal::before {
  /* halo */
  content: '';
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(155, 27, 48, 0.45), transparent 65%);
  animation: breathe 3.2s ease-in-out infinite;
}
.seal__wax {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 190, 190, 0.45), transparent 32%),
    radial-gradient(circle at 50% 50%, #a3203a 0, #7a1226 55%, #4a0a17 100%);
  box-shadow:
    inset 0 -6px 14px rgba(0, 0, 0, 0.55),
    inset 0 4px 10px rgba(255, 170, 170, 0.25),
    0 10px 30px rgba(0, 0, 0, 0.6),
    0 0 0 6px rgba(122, 18, 38, 0.35);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.seal__wax::after {
  /* stamped inner ring */
  content: '';
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 2px solid rgba(40, 0, 8, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 180, 180, 0.2), 0 1px 0 rgba(255, 180, 180, 0.15);
}
.seal svg { width: 42px; fill: #5c0d1d; filter: drop-shadow(0 1px 0 rgba(255, 170, 170, 0.35)) drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.5)); }
.seal:hover .seal__wax { transform: scale(1.06) rotate(-4deg); }

.enter__hint {
  font-size: 0.8rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0;
  transition: opacity 2s 1s;
}
.seal-ready .enter__hint { opacity: 0.6; animation: flicker 4s 3s infinite; }

/* breaking the seal */
.is-breaking .seal__wax { animation: crack 0.65s cubic-bezier(0.5, 0, 0.75, 0) forwards; }
.is-breaking .enter__hidden { display: none; }
.is-breaking .enter__whisper, .is-breaking .enter__hint { opacity: 0; filter: blur(10px); transition-duration: 0.5s; }
body:not(.stage-enter):not(.is-breaking) .enter { opacity: 0; pointer-events: none; }

/* ───────────── 2 · opening ───────────── */
.opening { position: fixed; inset: 0; z-index: 7; display: grid; place-items: center; pointer-events: none; }
.flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, #fff6e6 0, rgba(244, 214, 160, 0.8) 25%, rgba(155, 27, 48, 0.4) 60%, transparent 85%);
}
.stage-opening .flash { animation: flash 1.6s ease-out forwards; }

.title {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 16px;
  max-width: 100%;
  font-weight: 300;
  font-style: italic;
  font-size: clamp(2.6rem, 9vw, 7.5rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  color: var(--champagne);
  text-shadow: 0 0 30px rgba(217, 182, 124, 0.55), 0 0 80px rgba(155, 27, 48, 0.6);
  perspective: 800px;
}
.title .row { display: flex; flex-wrap: wrap; justify-content: center; width: 100%; }
.title .row + .row { padding-left: 1.2em; }
.title .word { display: inline-block; white-space: nowrap; margin: 0 0.12em; }
.title .word .ch > span { display: inline-block; opacity: 0; }
.stage-opening .title .word .ch > span, .stage-live .title .word .ch > span {
  animation: assemble 1.9s var(--d) cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ───────────── 3 · live: bouncing title + lyrics ───────────── */
.title .ch { display: inline-block; }
.stage-live .title {
  transition: translate 1.6s cubic-bezier(0.34, 1.56, 0.64, 1), scale 1.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  translate: 0 -24vh;
  scale: 0.62;
}
.stage-live .title .row { transform: scale(calc(1 + var(--beat) * 0.05)); transform-origin: 50% 80%; }
.stage-live .title .ch { animation: bob 2.6s calc(var(--i) * -0.11s) ease-in-out infinite; }

.lyrics {
  --bg: #000;
  --fg: #f4f4f2;
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter Tight', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s;
}
.lyrics.is-light { --bg: #f6f6f4; --fg: #0a0a0a; }
.stage-live.is-singing .lyrics { opacity: 1; }
/* hard cut between lines: a grey frame, then the inverted colour */
.lyrics.is-cut { animation: cut 0.16s steps(2) both; }

.lyric {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 6.2em;
  font-size: clamp(1.5rem, 3.6vw, 2.6rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
  word-spacing: 0.12em;
  text-transform: lowercase;
  /* RGB split on the beat */
  text-shadow:
    calc(var(--beat) * 4px) 0 rgba(255, 0, 70, calc(var(--beat) * 0.9)),
    calc(var(--beat) * -4px) 0 rgba(0, 210, 255, calc(var(--beat) * 0.9));
  animation: smear-in 0.22s ease-out;
}
/* unsung words keep their slot, like the gaps in "keep   it" */
.lyric .w { display: inline-block; opacity: 0; }
.lyric .w.is-sung { opacity: 1; animation: smear-in 0.2s ease-out; }

/* ───────────── hud ───────────── */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  opacity: 0;
  translate: 0 20px;
  pointer-events: none;
  transition: opacity 1.4s 1s, translate 1.4s 1s;
}
.stage-live .hud { opacity: 1; translate: 0 0; pointer-events: auto; }
.hud__track { display: grid; gap: 8px; min-width: 0; }
.hud__name { font-style: italic; font-size: 0.95rem; letter-spacing: 0.08em; color: var(--champagne); opacity: 0.75; white-space: nowrap; }
.hud__progress { display: block; width: min(220px, 40vw); height: 1px; background: rgba(244, 230, 207, 0.18); overflow: hidden; }
.hud__progress i { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); box-shadow: 0 0 8px var(--gold); }
.hud__btn {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(217, 182, 124, 0.4);
  background: rgba(20, 8, 12, 0.5);
  backdrop-filter: blur(8px);
  box-shadow: 0 0 calc(var(--beat) * 24px) rgba(217, 182, 124, 0.5);
  transition: border-color 0.3s, background 0.3s;
}
.hud__btn:hover { border-color: var(--rose); background: rgba(155, 27, 48, 0.3); }
.hud__icon { width: 12px; height: 12px; background: var(--champagne); transition: clip-path 0.3s; }
.hud__icon[data-state='play'] { clip-path: polygon(10% 0, 100% 50%, 10% 100%); }
.hud__icon[data-state='pause'] { clip-path: polygon(0 0, 35% 0, 35% 100%, 0 100%, 0 0, 65% 0, 100% 0, 100% 100%, 65% 100%, 65% 0); }
.hud__again {
  position: absolute;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  translate: -50% 0;
  font-style: italic;
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  color: var(--gold);
  animation: rise 1.4s both;
}
.hud__again[hidden] { display: none; }

/* ───────────── keyframes ───────────── */
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-6%, 4%); } 40% { transform: translate(5%, -7%); }
  60% { transform: translate(-3%, 8%); } 80% { transform: translate(7%, 2%); } 100% { transform: translate(0, 0); }
}
@keyframes breathe { 50% { scale: 1.25; opacity: 0.55; } }
@keyframes flicker { 0%, 100% { opacity: 0.6; } 48% { opacity: 0.6; } 50% { opacity: 0.15; } 52% { opacity: 0.6; } 54% { opacity: 0.3; } 56% { opacity: 0.6; } }
@keyframes crack {
  0% { transform: scale(1); filter: brightness(1); }
  25% { transform: scale(0.92) rotate(-6deg); }
  45% { transform: scale(1.04) rotate(5deg); }
  60% { transform: scale(0.96) rotate(-3deg); filter: brightness(1.3); }
  100% { transform: scale(1.9); filter: brightness(4) blur(6px); opacity: 0; }
}
@keyframes flash { 0% { opacity: 0; } 8% { opacity: 1; } 100% { opacity: 0; } }
@keyframes assemble {
  0% {
    opacity: 0;
    transform: translate3d(var(--dx), var(--dy), -400px) rotate(var(--rz)) scale(3);
    filter: blur(16px);
  }
  60% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-0.09em) rotate(-2deg); }
  60% { transform: translateY(0.05em) rotate(1.5deg); }
}
@keyframes cut { 0% { background: #4a4a4a; } 100% { background: var(--bg); } }
@keyframes smear-in {
  0% { opacity: 0.2; transform: scaleX(1.5) translateX(-0.25em); filter: blur(5px); }
  60% { opacity: 1; filter: blur(1px); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes rise { from { opacity: 0; translate: -50% 12px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .seal { opacity: 1 !important; filter: none !important; clip-path: none !important; translate: none !important; }
  .enter__whisper { opacity: 0.85; filter: none; }
}
