:root {
  --bg-a: #1b1033;
  --bg-b: #0b0718;
  --accent: #b388ff;
  --text: #ffffff;
  --subtext: rgba(255, 255, 255, 0.72);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-a), var(--bg-b));
  transition: background 1.2s ease;
  overflow: hidden;
  text-align: center;
  -webkit-font-smoothing: antialiased;
}

/* Each full-screen state is a layer; render() shows exactly one. */
.layer {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
}
.layer.show { display: flex; }

.stage { padding: 6vmin; max-width: 1400px; width: 100%; }
.kicker {
  font-size: clamp(14px, 2.2vmin, 26px);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--subtext);
  margin-bottom: 3vmin;
}
.headline {
  font-size: clamp(40px, 11vmin, 180px);
  font-weight: 800;
  line-height: 1.04;
  margin: 0;
}
.headline.reveal {
  font-size: clamp(56px, 16vmin, 280px);
  font-weight: 900;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.35);
  animation: pop 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes pop {
  0% { opacity: 0; transform: scale(0.6); }
  100% { opacity: 1; transform: scale(1); }
}
.status {
  position: fixed; bottom: 3vmin; left: 0; right: 0;
  font-size: clamp(12px, 1.8vmin, 18px); color: var(--subtext);
  z-index: 40;
}
canvas#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

/* Persistent reveal-name plate over the screensaver / question (not the reveal). */
.nameplate {
  position: fixed; top: 3.2vmin; left: 0; right: 0;
  display: none; justify-content: center;
  z-index: 25; pointer-events: none;
}
.nameplate.show { display: flex; }
.nameplate span {
  font-size: clamp(13px, 1.9vmin, 22px);
  letter-spacing: 0.32em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.66);
  background: rgba(0, 0, 0, 0.22);
  padding: 0.7vmin 2.4vmin; border-radius: 999px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  max-width: 80vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- Pairing (QR self-pairing, mirrors apps/tv) --- */
#pairing .title { font-size: clamp(40px, 9vmin, 96px); font-weight: 800; margin: 0 0 2vmin; }
#pairing .body {
  font-size: clamp(16px, 2.8vmin, 30px); color: var(--subtext);
  max-width: 820px; margin: 0 auto 5vmin; line-height: 1.4;
}
#pairing .qrframe {
  display: inline-block; background: #fff; padding: 20px; border-radius: 20px;
}
#pairing .qrframe svg,
#pairing .qrframe img {
  display: block; width: clamp(240px, 38vmin, 460px); height: auto;
  /* Keep module edges pixel-crisp at any scale — anti-aliased QR edges are
     what the in-app expo-camera decoder chokes on. */
  shape-rendering: crispEdges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#pairing .token {
  margin-top: 3vmin; font-size: clamp(18px, 3vmin, 32px);
  letter-spacing: 0.5em; font-weight: 700; color: var(--subtext);
}
#pairing .codejoin {
  margin-top: 4vmin; display: flex; gap: 1.4vmin; align-items: center;
  justify-content: center; flex-wrap: wrap;
}
#pairing .codeinput {
  font-size: clamp(18px, 2.6vmin, 28px); font-weight: 700; letter-spacing: 0.35em;
  text-align: center; text-transform: uppercase; color: var(--text);
  padding: 1.4vmin 2vmin; border-radius: 14px; min-width: 8em;
  background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0.25);
}
#pairing .codeinput::placeholder { color: rgba(255, 255, 255, 0.4); letter-spacing: 0.2em; }
#pairing .codebtn {
  font-size: clamp(18px, 2.6vmin, 28px); font-weight: 800; cursor: pointer;
  padding: 1.4vmin 3vmin; border-radius: 14px; border: 0;
  background: var(--accent); color: #18121f;
}
#pairing .codebtn:disabled { opacity: 0.5; cursor: default; }
#pairing .codeerr {
  flex-basis: 100%; margin-top: 1.2vmin; color: #ffd0e0;
  font-size: clamp(14px, 2.2vmin, 24px);
}

/* --- Reveal --- */
#reveal .bg, #photo .bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0;
}
#reveal .scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 1; }
#reveal .stage { position: relative; z-index: 2; }

/* --- Question photo --- */
#photo { background: #000; align-items: stretch; justify-content: flex-end; }
#photo .caption {
  position: relative; z-index: 2; width: 100%;
  padding: 6vmin; background: rgba(0, 0, 0, 0.45);
}
#photo .caption span { font-size: clamp(28px, 6vmin, 72px); font-weight: 800; }

/* --- Screensavers --- */
#screensaver { background: radial-gradient(140% 120% at 50% 8%, #160a32, #050310 72%); overflow: hidden; }
.ss { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.ss.show { display: flex; }

/* Ambient orbs — soft radial glows that blend additively (aurora). The
   background gradient is set per-orb in JS (paintOrbs) from the palette. */
#ss-ambient { overflow: hidden; }
#ss-ambient .orb {
  position: absolute; border-radius: 50%;
  filter: blur(16px);
  mix-blend-mode: screen;
  will-change: transform;
  opacity: 0.9;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
#ss-ambient .orbA { width: 54vmin; height: 54vmin; top: 0;      left: -10vmin;  animation-name: floatA; animation-duration: 17s; }
#ss-ambient .orbB { width: 46vmin; height: 46vmin; bottom: -8vmin; right: -8vmin; animation-name: floatB; animation-duration: 23s; }
#ss-ambient .orbC { width: 62vmin; height: 62vmin; top: 16vmin; left: 30vmin;   animation-name: floatC; animation-duration: 29s; }
#ss-ambient .orbD { width: 38vmin; height: 38vmin; bottom: 6vmin; left: 4vmin;   animation-name: floatD; animation-duration: 20s; }
@keyframes floatA {
  0%,100% { transform: translate(0,0) scale(1) rotate(0deg); }
  33%     { transform: translate(16vmin,13vmin) scale(1.22) rotate(36deg); }
  66%     { transform: translate(9vmin,-10vmin) scale(0.92) rotate(-18deg); }
}
@keyframes floatB {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(-19vmin,-15vmin) scale(1.32); }
}
@keyframes floatC {
  0%,100% { transform: translate(0,0) scale(1) rotate(0deg); }
  50%     { transform: translate(-15vmin,11vmin) scale(1.16) rotate(28deg); }
}
@keyframes floatD {
  0%,100% { transform: translate(0,0) scale(1); }
  50%     { transform: translate(15vmin,-13vmin) scale(1.28); }
}
/* Depth vignette over the orbs, under the clock. */
#ss-ambient .vignette {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(120% 120% at 50% 45%, transparent 52%, rgba(0,0,0,0.6) 100%);
}
#ss-ambient .clock {
  position: relative; z-index: 2;
  color: #fff; font-size: clamp(44px, 9vmin, 112px); font-weight: 200; letter-spacing: 4px;
  text-shadow: 0 2px 50px rgba(255, 255, 255, 0.25);
}
@media (prefers-reduced-motion: reduce) {
  #ss-ambient .orb { animation: none; }
}

/* Clock */
#ss-clock { background: #000; flex-direction: column; }
#ss-clock .big { font-size: clamp(80px, 22vmin, 320px); font-weight: 200; letter-spacing: 2px; }
#ss-clock .date { font-size: clamp(20px, 4vmin, 56px); font-weight: 400; color: rgba(255,255,255,0.5); margin-top: 1vmin; }

/* Video */
#ss-video { background: #000; }
#ss-video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#ytplayer {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 100vw; height: 56.25vw; min-height: 100vh; min-width: 177.78vh;
  pointer-events: none;
}
#soundHint {
  position: absolute; bottom: 4vmin; left: 50%; transform: translateX(-50%);
  z-index: 12; padding: 12px 22px; border-radius: 999px; cursor: pointer;
  background: rgba(0,0,0,0.55); color: #fff; border: 1px solid rgba(255,255,255,0.4);
  font-size: clamp(14px, 2vmin, 22px); backdrop-filter: blur(6px);
}
#soundHint.hidden { display: none; }

/* "Scan to join" QR — only shown in legacy ?code= mode, until the reveal. */
#joinqr {
  position: fixed; top: 3vmin; right: 3vmin; z-index: 20;
  background: #fff; color: #111; border-radius: 16px; padding: 14px;
  text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  transition: opacity 0.6s ease;
}
#joinqr.hidden { opacity: 0; pointer-events: none; }
#joinqr .qrbox { width: 132px; height: 132px; }
#joinqr .label { margin-top: 6px; font-size: 13px; font-weight: 700; }
#joinqr .code { font-family: ui-monospace, monospace; font-size: 13px; letter-spacing: 2px; color: #555; }
