:root {
  --bg: #0b0b10;
  --ink: #fff;
  --ink-dim: rgba(255, 255, 255, .72);
  --glass: rgba(20, 20, 28, .55);
  --glass-line: rgba(255, 255, 255, .18);
  --accent: #ff4d79;
  --stage-h: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body { display: grid; place-items: center; }

button { font: inherit; color: inherit; }
button:focus-visible, .progress:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  height: var(--stage-h);
  width: min(100vw, calc(var(--stage-h) * 9 / 16));
  background: #000;
  overflow: hidden;
  overflow: clip; /* clip, not hidden: off-screen slides must never make the stage scrollable */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  isolation: isolate;
}

@media (min-width: 700px) {
  :root { --stage-h: min(calc(100dvh - 32px), 940px); }
  .stage { border-radius: 22px; box-shadow: 0 20px 80px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .08); }
}

.slides, .everyone, .gestures { position: absolute; inset: 0; }
.slides { overflow: hidden; overflow: clip; }
.gestures { z-index: 3; }

/* ---------- slides ---------- */
.slide {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transition: transform .42s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
}
.slide.is-active { transform: none; }
.slide.is-above { transform: translateY(-100%); }
.slide.is-below { transform: translateY(100%); }
.slide.is-hidden { transform: translateY(100%); visibility: hidden; }
.slide.no-anim { transition: none; }

.slide video, .everyone video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.slide-name {
  position: absolute;
  left: 16px;
  bottom: 176px;
  font-weight: 700;
  font-size: 1.05rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, .6);
  pointer-events: none;
}

/* ---------- placeholder frames ---------- */
.ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background:
    radial-gradient(circle at 30% 20%, hsl(var(--h) 85% 62% / .55), transparent 55%),
    linear-gradient(160deg, hsl(var(--h) 70% 34%), hsl(calc(var(--h) + 50) 65% 14%));
  text-align: center;
  overflow: hidden;
}
.ph::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, .045) 0 14px, transparent 14px 28px);
}
.ph > * { position: relative; }
.ph-avatar {
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(2rem, 10vh, 5rem);
  font-weight: 800;
  background: hsl(var(--h) 80% 70%);
  color: hsl(var(--h) 70% 18%);
  box-shadow: 0 0 0 8px rgba(255, 255, 255, .14), 0 10px 40px rgba(0, 0, 0, .35);
  animation: ph-pulse 1.6s ease-in-out infinite;
}
.ph-name { font-size: 1.5rem; font-weight: 700; }
.ph-tag { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; opacity: .75; }
.ph-tc {
  font-variant-numeric: tabular-nums;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: .02em;
  padding: 4px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .35);
}
.ph-eq { display: flex; align-items: flex-end; gap: 5px; height: 36px; }
.ph-eq i {
  width: 6px;
  height: 100%;
  border-radius: 3px;
  background: rgba(255, 255, 255, .8);
  transform-origin: bottom;
  animation: ph-eq 0.9s ease-in-out infinite;
}
.ph-eq i:nth-child(2) { animation-delay: -.2s; }
.ph-eq i:nth-child(3) { animation-delay: -.45s; }
.ph-eq i:nth-child(4) { animation-delay: -.1s; }
.ph-eq i:nth-child(5) { animation-delay: -.6s; }
.ph-mode {
  position: absolute !important;
  top: 76px;
  left: 50%;
  translate: -50% 0;
  font-size: .78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .45);
  white-space: nowrap;
}
.paused .ph-avatar, .paused .ph-eq i { animation-play-state: paused; }

@keyframes ph-pulse { 50% { transform: scale(1.06); } }
@keyframes ph-eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }

/* ---------- "Everyone" layer ---------- */
.everyone {
  z-index: 2;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.everyone.on { opacity: 1; }

.grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: 1fr;
  gap: 2px;
}
.gcell { position: relative; overflow: hidden; background: #000; }
.grid .ph { position: relative; inset: auto; gap: 6px; }
.grid .ph-avatar { width: 38%; font-size: clamp(1.2rem, 4vh, 2.4rem); box-shadow: 0 0 0 4px rgba(255, 255, 255, .14); }
.grid .ph-name { font-size: .9rem; }
.grid .ph-tc { font-size: 1rem; padding: 2px 8px; }
.grid .ph-tag, .grid .ph-eq { display: none; }

/* ---------- top bar ---------- */
.top {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 14px 28px;
  background: linear-gradient(rgba(0, 0, 0, .5), transparent);
  pointer-events: none;
}
.progress {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .25);
  pointer-events: auto;
  cursor: pointer;
}
.progress::before { content: ""; position: absolute; inset: -12px 0; } /* bigger touch target */
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 2px;
  background: #fff;
}
.ticks { position: absolute; inset: 0; pointer-events: none; }
.ticks i {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 10px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--accent);
  opacity: .9;
}
.top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: .85rem;
}
.song { font-weight: 700; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); }
.who { margin-left: auto; color: var(--ink-dim); font-variant-numeric: tabular-nums; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); }
.badge {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 99px;
  background: rgba(255, 190, 40, .9);
  color: #2a1c00;
}

/* ---------- like ---------- */
.rail {
  position: absolute;
  z-index: 5;
  right: 12px;
  bottom: 96px;
  display: grid;
  justify-items: center;
  gap: 4px;
}
.like {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 1px solid var(--glass-line);
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s;
}
.like svg { width: 30px; height: 30px; fill: var(--accent); filter: drop-shadow(0 2px 6px rgba(255, 77, 121, .5)); }
.like:active, .like.pop { transform: scale(.88); }
.count {
  font-weight: 800;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .7);
}
.count.bump { animation: bump .18s ease-out; }
.combo {
  position: absolute;
  right: 62px;
  top: 10px;
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 99px;
  font-weight: 800;
  font-size: .85rem;
  background: var(--accent);
  box-shadow: 0 4px 16px rgba(255, 77, 121, .5);
  animation: bump .18s ease-out;
}
@keyframes bump { 50% { transform: scale(1.25); } }

.hearts { position: absolute; inset: 0; z-index: 6; pointer-events: none; overflow: hidden; }
.heart {
  position: absolute;
  line-height: 1;
  translate: -50% -50%;
  animation: float var(--dur) cubic-bezier(.2, .6, .3, 1) forwards;
  will-change: transform, opacity;
}
.plus {
  position: absolute;
  translate: -50% -50%;
  font-weight: 800;
  font-size: 1.1rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .7);
  animation: float 1s ease-out forwards;
  --dx: 0px; --rot: 0deg; --rise: 90px;
}
@keyframes float {
  0%   { opacity: 0; transform: translate(0, 0) scale(.3) rotate(0); }
  12%  { opacity: 1; transform: translate(calc(var(--dx) * .15), -12px) scale(1.15) rotate(calc(var(--rot) * .2)); }
  100% { opacity: 0; transform: translate(var(--dx), calc(var(--rise) * -1)) scale(.9) rotate(var(--rot)); }
}

/* ---------- lyrics + controls ---------- */
.lyric {
  position: absolute;
  z-index: 4;
  left: 16px;
  right: 84px;
  bottom: 96px;
  margin: 0;
  min-height: 3.2em;
  display: flex;
  align-items: flex-end;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  text-shadow: 0 1px 8px rgba(0, 0, 0, .8);
  pointer-events: none;
  transition: opacity .25s;
}
.lyric:empty { opacity: 0; }

.controls {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 40px 12px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  pointer-events: none;
}
.pill {
  pointer-events: auto;
  padding: 11px 16px;
  min-height: 44px;
  border: 1px solid var(--glass-line);
  border-radius: 99px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s, color .15s, opacity .15s;
}
.pill[aria-pressed="true"] { background: #fff; color: #111; border-color: #fff; }
.pill:disabled { opacity: .4; cursor: not-allowed; }

.pause-flash {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: 84px;
  height: 84px;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  font-size: 2.2rem;
  opacity: 0;
  pointer-events: none;
}
.pause-flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.2); } }

/* ---------- start overlay ---------- */
.start {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  border: 0;
  background: radial-gradient(circle at 50% 40%, rgba(60, 20, 50, .85), rgba(8, 8, 14, .96));
  cursor: pointer;
  text-align: center;
}
.start[hidden] { display: none; }
.start-title { font-size: 2rem; font-weight: 800; }
.start-play {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  padding-left: 6px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  font-size: 2rem;
}
.start-hint { font-weight: 600; }
.start-keys { max-width: 24ch; font-size: .8rem; color: var(--ink-dim); }

@media (prefers-reduced-motion: reduce) {
  .slide { transition-duration: .01s; }
  .ph-avatar, .ph-eq i { animation: none; }
}

.everyone-on .lyric { opacity: 0; }
