:root {
  --bg: #070405;
  --velvet-0: #2b0105;
  --velvet-1: #5e0712;
  --velvet-2: #8f0e1c;
  --velvet-3: #b51b2a;
  --velvet-4: #d6343f;
  --gold-0: #5e3f12;
  --gold-1: #b4872d;
  --gold-2: #f2d27c;
  --ink: #efe6d4;

  /* screen width: as wide as fits under the valance and above the seats */
  --sw: min(78vw, calc((100vh - 300px) * 16 / 9));
  --sw: min(78vw, calc((100svh - 300px) * 16 / 9));
  --sh: calc(var(--sw) * 9 / 16);
  --mr: 0.07;                                   /* curtain wing beside the screen, as a share of its width */
  --m: calc(var(--sw) * var(--mr));
  --ow: calc(var(--sw) + 2 * var(--m));         /* stage opening */
  --top: calc(var(--sh) * 0.15);                /* valance height */
  --oh: calc(var(--top) + var(--sh) * 1.035);   /* opening height: valance + screen + the stage lip */
  --gather: calc(var(--mr) * 0.97 / (0.5 + var(--mr)));  /* open curtains stop just short of the screen: nothing may cover the YouTube player */
}

@media (max-width: 640px) {
  :root {
    --sw: min(88vw, calc((100svh - 220px) * 16 / 9));
    --mr: 0.05;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.theater {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(28px, 6vh, 64px) 0 clamp(96px, 17vh, 180px);
  overflow: hidden;
  isolation: isolate;
}

/* ---------- the room ---------- */

.walls {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(140, 24, 36, 0.28), transparent 70%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 140px),
    linear-gradient(#170709, #0c0405 55%, #040102);
  transition: filter 1.4s ease;
}

.sconce {
  position: absolute;
  top: 34%;
  width: 22px;
  height: 40px;
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(circle at 50% 35%, #fff4d6, #ffc27a 40%, #b5602a 75%, #4a1d0c);
  box-shadow:
    0 0 40px 18px rgba(255, 176, 96, 0.28),
    0 0 140px 70px rgba(255, 140, 60, 0.12);
  transition: opacity 1.4s ease;
}
.sconce--l { left: calc(50% - var(--ow) / 2 - clamp(30px, 4vw, 70px)); }
.sconce--r { right: calc(50% - var(--ow) / 2 - clamp(30px, 4vw, 70px)); }

@media (max-width: 900px) { .sconce { display: none; } }

/* ---------- stage, screen, curtains ---------- */

.stage {
  position: relative;
  width: var(--ow);
  height: var(--oh);
}

.opening {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg,
    #020101 calc(var(--top) + var(--sh)),
    #3a2418 calc(var(--top) + var(--sh)),
    #1c100b calc(var(--top) + var(--sh) + 3px),
    #0d0705 100%);
  box-shadow:
    0 0 0 clamp(6px, 0.9vw, 12px) #140809,
    0 0 0 calc(clamp(6px, 0.9vw, 12px) + 2px) rgba(180, 135, 45, 0.45),
    0 40px 90px rgba(0, 0, 0, 0.85);
}

.screen {
  position: absolute;
  left: var(--m);
  top: var(--top);
  width: var(--sw);
  height: var(--sh);
  background: #0c0c0c;
  overflow: hidden;
  transition: box-shadow 1.2s ease;
}

.leader,
.player,
.player iframe,
.vimeo,
.vimeo iframe,
.fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.fallback { background: #000; object-fit: contain; }

.leader { opacity: 0; transition: opacity 0.5s ease; }
.player, .vimeo, .fallback { opacity: 0; pointer-events: none; transition: opacity 0.35s ease; }

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(50% + 2px);
  z-index: 3;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.62) 0%, rgba(0, 0, 0, 0) 24%, rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, 0.6) 100%),
    radial-gradient(ellipse 70% 40% at 50% 46%, rgba(255, 150, 150, 0.08), transparent 70%),
    repeating-linear-gradient(90deg,
      var(--velvet-0) 0%,
      var(--velvet-1) 1.3%,
      var(--velvet-2) 2.5%,
      var(--velvet-4) 3.3%,
      var(--velvet-3) 3.9%,
      var(--velvet-1) 5.3%,
      var(--velvet-0) 6.25%);
  transition: transform 2.6s cubic-bezier(0.62, 0.02, 0.24, 1), filter 1.4s ease;
  will-change: transform;
}
.curtain::before {
  /* velvet nap */
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.32;
  mix-blend-mode: multiply;
}
.curtain::after {
  /* shadow where the two halves meet */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4%;
}
.curtain--l { left: 0; transform-origin: 0 50%; }
.curtain--l::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.5)); }
.curtain--r { right: 0; transform-origin: 100% 50%; }
.curtain--r::after { left: 0; background: linear-gradient(270deg, transparent, rgba(0, 0, 0, 0.5)); }

.valance {
  position: absolute;
  left: -16px;
  right: -16px;
  top: -8px;
  height: calc(var(--top) + 8px);
  z-index: 5;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.3)),
    repeating-linear-gradient(90deg,
      var(--velvet-0) 0,
      var(--velvet-2) 12px,
      var(--velvet-4) 19px,
      var(--velvet-1) 30px,
      var(--velvet-0) 38px);
  box-shadow: 0 14px 22px rgba(0, 0, 0, 0.65);
  transition: filter 1.4s ease;
}
.valance::after {
  /* gold braid and fringe */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -15px;
  height: 19px;
  background:
    linear-gradient(180deg, var(--gold-2), var(--gold-1) 45%, var(--gold-0)) top / 100% 6px no-repeat,
    repeating-linear-gradient(90deg, var(--gold-2) 0 1.5px, var(--gold-1) 1.5px 3px, transparent 3px 5px) bottom / 100% 13px no-repeat;
  -webkit-mask: linear-gradient(#000 55%, rgba(0, 0, 0, 0.35));
  mask: linear-gradient(#000 55%, rgba(0, 0, 0, 0.35));
}

/* ---------- cards on the closed curtains ---------- */

.card {
  position: absolute;
  left: 50%;
  top: calc(var(--top) + var(--sh) * 0.5);
  z-index: 4;
  width: max-content;
  max-width: calc(var(--ow) - 32px);
  transform: translate(-50%, -50%);
  text-align: center;
  transition: opacity 0.6s ease, visibility 0.6s;
}
.card--end { opacity: 0; visibility: hidden; }

.card-kicker {
  margin: 0;
  font: 600 clamp(9px, calc(var(--sw) * 0.0115), 14px) / 1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold-2);
  opacity: 0.85;
}

.card-title {
  margin: 0.18em 0 0.5em;
  font-family: Anton, Impact, "Arial Narrow", sans-serif;
  font-weight: 400;
  font-size: clamp(28px, calc(var(--sw) * 0.08), 104px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff3c9 0%, #eabd57 46%, #9a6a1d 54%, #f4d47f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.55)) drop-shadow(0 10px 22px rgba(0, 0, 0, 0.6));
}

.ticket {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
  padding: 0.8em 2em 0.75em;
  border: 0;
  cursor: pointer;
  color: #7c0d18;
  background: linear-gradient(180deg, #fbf0d2, #ecdcb2);
  font: 700 clamp(11px, calc(var(--sw) * 0.014), 17px) / 1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  -webkit-mask:
    radial-gradient(circle 0.6em at 0 50%, transparent 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 0.6em at 100% 50%, transparent 97%, #000) right / 51% 100% no-repeat;
  mask:
    radial-gradient(circle 0.6em at 0 50%, transparent 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 0.6em at 100% 50%, transparent 97%, #000) right / 51% 100% no-repeat;
  transition: transform 0.2s ease, filter 0.2s ease;
}
.ticket::before {
  content: "";
  position: absolute;
  inset: 5px 1.1em;
  border: 1px dashed rgba(124, 13, 24, 0.45);
  pointer-events: none;
}
.ticket:hover { transform: translateY(-2px) rotate(-1.5deg); filter: brightness(1.06); }
.ticket:active { transform: translateY(0) rotate(0); }
.ticket:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 6px; }
.ticket-main { font-size: 1.2em; }
.ticket-sub { font-size: 0.62em; letter-spacing: 0.32em; opacity: 0.8; }

.end-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6em 1.6em;
  margin-top: 1.4em;
}
.end-links a {
  color: var(--gold-2);
  font: 600 clamp(10px, calc(var(--sw) * 0.012), 14px) / 1.2 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  border-bottom: 1px solid rgba(242, 210, 124, 0.4);
  padding-bottom: 2px;
}
.end-links a:hover { border-bottom-color: var(--gold-2); }

/* ---------- controls on the screen ---------- */

.sound {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
  font: 600 13px / 1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-radius: 999px;
}
/* below the screen, never over the YouTube player (its embed rules forbid overlays) */
.sound {
  position: absolute;
  left: 50%;
  top: calc(100% + 14px);
  z-index: 8;
  transform: translateX(-50%);
  padding: 0.9em 1.5em;
}
.notice {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1em;
  text-align: center;
  font: 600 14px / 1.4 ui-monospace, Menlo, Consolas, monospace;
  color: #ccc;
  background: #0c0c0c;
}
[hidden] { display: none !important; }

/* ---------- seats and footer ---------- */

.seats {
  position: absolute;
  left: -4vw;
  right: -4vw;
  bottom: 0;
  height: clamp(80px, 15vh, 160px);
  z-index: 6;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='120' viewBox='0 0 160 120'%3E%3Cpath d='M14 120V40C14 18 30 8 80 8s66 10 66 32v80z' fill='%23060304'/%3E%3Cpath d='M18 38C18 20 34 12 80 12s62 8 62 26' fill='none' stroke='%23ffffff' stroke-opacity='0.07' stroke-width='3'/%3E%3C/svg%3E") 0 100% / clamp(110px, 13vw, 190px) auto repeat-x,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='120' viewBox='0 0 160 120'%3E%3Cpath d='M18 120V44C18 24 32 14 80 14s62 10 62 30v76z' fill='%230d0607'/%3E%3Cpath d='M22 42C22 26 36 18 80 18s58 8 58 24' fill='none' stroke='%23ffffff' stroke-opacity='0.06' stroke-width='3'/%3E%3C/svg%3E") calc(clamp(110px, 13vw, 190px) * 0.36) calc(100% - clamp(28px, 4.5vh, 56px)) / clamp(80px, 9.5vw, 140px) auto repeat-x;
  transition: filter 1.4s ease;
}

.credits {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 7;
  text-align: center;
  font: 500 11px / 1.3 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  color: rgba(239, 230, 212, 0.38);
  transition: opacity 1.4s ease;
}

/* ---------- states ----------
   idle -> dim -> opening -> countdown -> playing -> closing -> ended */

.theater:not([data-state="idle"]):not([data-state="ended"]) .walls { filter: brightness(0.2) saturate(0.8); }
.theater:not([data-state="idle"]):not([data-state="ended"]) .sconce { opacity: 0.08; }
.theater:not([data-state="idle"]):not([data-state="ended"]) .valance,
.theater:not([data-state="idle"]):not([data-state="ended"]) .curtain { filter: brightness(0.5); }
.theater:not([data-state="idle"]):not([data-state="ended"]) .seats { filter: brightness(0.7); }
.theater:not([data-state="idle"]):not([data-state="ended"]) .credits { opacity: 0.25; }

.theater:is([data-state="opening"], [data-state="countdown"], [data-state="playing"]) .curtain {
  transform: scaleX(var(--gather));
}
.theater:is([data-state="closing"]) .curtain { transition-duration: 2.2s; }

.theater:not([data-state="idle"]) .card--start { opacity: 0; visibility: hidden; }
.theater[data-state="ended"] .card--end { opacity: 1; visibility: visible; transition-delay: 0.2s; }

.theater:is([data-state="opening"], [data-state="countdown"]) .leader { opacity: 1; }
.theater[data-state="playing"][data-source="youtube"] .player,
.theater[data-state="playing"][data-source="vimeo"] .vimeo,
.theater[data-state="playing"][data-source="mp4"] .fallback { opacity: 1; pointer-events: auto; }
.theater:is([data-state="opening"], [data-state="countdown"], [data-state="playing"]) .screen {
  box-shadow: 0 0 90px 6px rgba(210, 215, 235, 0.10);
}

@media (prefers-reduced-motion: reduce) {
  .curtain { transition-duration: 0.3s !important; }
  .walls, .sconce, .valance, .seats, .credits { transition-duration: 0.3s; }
  .ticket:hover { transform: none; }
}
