/* ---------- theme ---------- */
:root {
  color-scheme: light dark;
  --bg: #f4f2ec;
  --fg: #111111;
  --inset: 12px;
  --radius: 22px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0b0d; --fg: #f2f2f2; }
}
@media (min-width: 1021px) {
  :root { --inset: 28px; --radius: 28px; }
}

@font-face {
  font-family: "Anton";
  src: url("../assets/fonts/anton.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block; /* the intro waits for fonts.ready, so never flash a fallback */
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
}

/* ---------- the framed stage ---------- */
#stage {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + var(--inset));
  right: calc(env(safe-area-inset-right, 0px) + var(--inset));
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--inset));
  left: calc(env(safe-area-inset-left, 0px) + var(--inset));
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  isolation: isolate;
  /* Safari: make rounded overflow clipping stick for transformed children */
  -webkit-mask-image: -webkit-radial-gradient(#fff, #000);
  /* intro brings it in */
  opacity: 0;
  transform: scale(0.96);
  will-change: opacity, transform;
}

/* Source video stays decoding but invisible.
   Not display:none — iOS may throttle decode of undisplayed videos. */
#src {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  touch-action: none; /* swipes are ours; nothing scrolls */
  opacity: 0;
  transition: opacity 0.6s ease;
}
#gl.live { opacity: 1; }

/* ---------- always-visible lockup: CLAUS · face · DANSER, top centre ---------- */
#brand-lockup {
  position: absolute;
  top: 14px;
  /* centred with auto margins, NOT transform, and z-index:auto: either would
     create a stacking context and stop the words' blend reaching the video */
  left: 0;
  right: 0;
  width: max-content;
  margin: 0 auto;
  z-index: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font: 400 28px/1 "Anton", Impact, "Arial Black", sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0; /* revealed when the intro lockup lands here */
}
/* white + difference = always the inverse of the video behind it */
#brand-lockup span {
  display: block;
  color: #fff;
  mix-blend-mode: difference;
}
#brand {
  display: block;
  width: 60px;
  height: 60px;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.55));
  pointer-events: auto; /* tappable: jiggles */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- now-playing card ---------- */
#now {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0 auto;
  max-width: 560px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  /* intro slides it up */
  opacity: 0;
  transform: translateY(24px);
  will-change: opacity, transform;
}

/* The YouTube player: a real, visible player (embed terms), styled to sit
   flush inside the card so player + title read as one object. */
#yt {
  position: relative;
  flex: none;
  width: 160px;
  height: 90px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
#yt[hidden] { display: none; }
#yt iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}
#yt-off {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  font: 600 10px/1 var(--mono);
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.5);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#yt-off:hover { background: rgba(0, 0, 0, 0.85); }

#now-label {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px 6px 2px 4px;
  cursor: pointer;
  color: #fff;
}
#now-label .eyebrow {
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}
/* The title IS the picker: a native select dressed as text */
#track {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 2px 26px 2px 0;
  border: 0;
  background-color: transparent;
  color: #fff;
  font: 600 17px/1.25 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" fill="none" stroke="white" stroke-width="1.6"/></svg>');
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 11px 7px;
}
#track:focus-visible { outline: 2px solid #fff; outline-offset: 3px; border-radius: 6px; }
#track option { text-transform: none; color: #000; font: 14px system-ui, sans-serif; }

@media (min-width: 1021px) {
  #yt { width: 200px; height: 112px; }
  #track { font-size: 19px; }
}

/* ---------- intro overlay ---------- */
#intro {
  /* absolute + z-index:auto on purpose: position:fixed would create a stacking
     context and the words' mix-blend-mode could never reach the stage behind
     them. Body is viewport-sized and never scrolls, so inset:0 covers the
     screen; it paints on top because it is last in the DOM. */
  position: absolute;
  inset: 0;
  z-index: auto;
  display: grid;
  place-items: center;
  padding: 0 4vw;
  cursor: pointer; /* tap to skip */
}
#intro.done { display: none; }
/* Same row as the header lockup, just big. Words are sized off the face. */
#intro-lockup {
  --face: clamp(64px, 18vw, 200px); /* row must fit a 375px phone with margin */
  margin: 0;
  display: flex;
  align-items: center;
  gap: calc(var(--face) * 0.12);
  font: 400 calc(var(--face) * 0.6) / 1 "Anton", Impact, "Arial Black", sans-serif;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
#intro-lockup span {
  display: block;
  opacity: 0;
  /* white + difference = inverted against whatever is behind: legible over the
     light page in light mode, the dark page in dark mode, and any effect. */
  color: #fff;
  mix-blend-mode: difference;
  will-change: transform, opacity;
}
#intro-face {
  display: block;
  width: var(--face);
  height: var(--face);
  opacity: 0;
  filter: drop-shadow(0 12px 40px rgba(0, 0, 0, 0.25));
  will-change: transform, opacity, filter;
}

/* ---------- hints ---------- */
#sound-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
  font: 600 13px/1 var(--mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 28px;
  padding: 26px 34px 24px;
  pointer-events: none;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: hint-pulse 1.8s ease-in-out infinite;
}
#sound-hint .emoji { font-size: 58px; line-height: 1; letter-spacing: 0; flex: none; }
#sound-hint span:last-child { text-indent: 0.3em; }
#sound-hint[hidden] { display: none; }
@keyframes hint-pulse { 50% { opacity: 0.4; } }

#tap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  pointer-events: none;
  color: #fff;
  font: 600 13px/1 var(--mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
  animation: tap-pulse 1.6s ease-in-out infinite;
}
#tap[hidden] { display: none; }
@keyframes tap-pulse { 50% { opacity: 0.35; } }

/* ---------- fallbacks ---------- */
/* No WebGL2: raw video inside the frame, roughly stylized in CSS. */
body.no-webgl #src {
  width: 100%;
  height: 100%;
  opacity: 1;
  object-fit: cover;
  filter: grayscale(1) contrast(1.6);
}
body.no-webgl #gl { display: none; }

@media (prefers-reduced-motion: reduce) {
  #gl, #stage, #now { transition: none; }
  #sound-hint, #tap { animation: none; }
}
