@property --hue {
  syntax: '<number>';
  inherits: true;
  initial-value: 320;
}

:root {
  --hue: 320;
  --accent: hsl(var(--hue) 100% 65%);
  --accent-2: hsl(calc(var(--hue) + 60) 100% 60%);
  --bg: #0a0214;
  --panel: rgba(30, 8, 50, 0.72);
  --line: hsl(var(--hue) 80% 60% / 0.35);
  --text: #f3eaff;
  --muted: #a99bd6;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Rubik", system-ui, sans-serif;
  touch-action: none; /* swipes control the game */
  overscroll-behavior: none;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

/* ---------- Disco background ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, #3b0a5c 0%, #1a0633 45%, #0a0214 100%);
}

/* Sweeping spotlights */
.beam {
  position: absolute;
  top: -5vh;
  width: 34vmax;
  height: 130vh;
  transform-origin: 50% 0;
  clip-path: polygon(46% 0, 54% 0, 100% 100%, 0 100%);
  mix-blend-mode: screen;
  opacity: 0.35;
  filter: blur(6px);
}
.beam-1 { left: 5%;  background: linear-gradient(#ff2e9a, transparent 80%); animation: sway 5s ease-in-out infinite; }
.beam-2 { right: 5%; background: linear-gradient(#00e5ff, transparent 80%); animation: sway 6s ease-in-out infinite reverse; }
.beam-3 { left: 35%; background: linear-gradient(#ffd21f, transparent 80%); animation: sway 7s ease-in-out -2s infinite; opacity: 0.25; }
@keyframes sway {
  0%, 100% { transform: translateX(-50%) rotate(-28deg); }
  50% { transform: translateX(-50%) rotate(28deg); }
}

/* Mirror-ball reflections spinning around the room */
.spots {
  position: absolute;
  left: 50%;
  top: 40px;
  width: 220vmax;
  height: 220vmax;
  margin: -110vmax 0 0 -110vmax;
  background:
    radial-gradient(circle, rgba(255,255,255,0.9) 0 2px, transparent 3px) 0 0 / 90px 90px,
    radial-gradient(circle, rgba(255,90,200,0.8) 0 3px, transparent 4px) 40px 25px / 140px 140px,
    radial-gradient(circle, rgba(90,230,255,0.8) 0 2px, transparent 3px) 15px 70px / 115px 115px,
    radial-gradient(circle, rgba(255,215,60,0.8) 0 2px, transparent 3px) 60px 50px / 160px 160px;
  animation: spin 40s linear infinite, twinkle 1.5s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes twinkle { 50% { opacity: 0.55; } }

/* Light-up dance floor */
.floor {
  position: absolute;
  left: -25vw;
  right: -25vw;
  bottom: -2vh;
  height: 42vh;
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  transform: perspective(500px) rotateX(55deg);
  transform-origin: 50% 100%;
  -webkit-mask: linear-gradient(transparent, #000 45%);
          mask: linear-gradient(transparent, #000 45%);
}
.floor i {
  border-radius: 4px;
  background: var(--c);
  box-shadow: 0 0 18px var(--c);
  opacity: 0.1;
  transition: opacity 0.45s ease-out;
}
.floor i.on { opacity: 0.85; transition-duration: 0.05s; }
@keyframes tile {
  0%   { opacity: 0.85; }
  30%  { opacity: 0.12; }
}
.floor.party i, .fever .floor i { animation: tile 0.25s steps(1) infinite; }
.floor.party i:nth-child(odd), .fever .floor i:nth-child(odd) { animation-delay: -0.12s; }

/* The disco ball itself */
.ball-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -16px;
  animation: dangle 4s ease-in-out infinite;
  transform-origin: 50% 0;
}
.ball-wrap .string { width: 2px; height: 22px; background: linear-gradient(#0000, #bbb); }
.ball {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.95) 0 6%, rgba(255,255,255,0) 22%),
    repeating-linear-gradient(90deg, rgba(0,0,0,0.35) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.35) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, #6d6a86, #f4f2ff 25%, #9e9bb8 45%, #ffffff 60%, #7a7794 80%, #d9d6ee);
  background-size: auto, 16px 100%, 100% 8px, 64px 100%;
  box-shadow: 0 0 25px rgba(255,255,255,0.45), inset -8px -10px 18px rgba(0,0,0,0.55);
  animation: ball-spin 3s linear infinite;
}
@keyframes ball-spin {
  to { background-position: 0 0, 16px 0, 0 0, 64px 0; }
}
@keyframes dangle { 50% { transform: rotate(4deg); } }

/* ---------- Logo ---------- */
.logo {
  font-family: "Monoton", "Bungee", sans-serif;
  font-weight: 400;
  font-size: clamp(1.6rem, 7vw, 3rem);
  letter-spacing: 0.04em;
  text-align: center;
  margin: 2px 0 8px;
  user-select: none;
}
.logo .word { display: inline-block; white-space: nowrap; }
.logo .word + .word { margin-left: 0.3em; }
.logo .word span {
  display: inline-block;
  color: var(--c);
  text-shadow: 0 0 8px var(--c), 0 0 24px var(--c);
  animation: boogie 1s ease-in-out infinite, chase 1.1s steps(1) infinite;
  animation-delay: calc(var(--i) * 0.1s);
}
@keyframes boogie {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-5px) rotate(6deg); }
}
@keyframes chase {
  0% { color: #fff; text-shadow: 0 0 6px #fff, 0 0 20px var(--c), 0 0 40px var(--c); }
  15% { color: var(--c); text-shadow: 0 0 8px var(--c), 0 0 24px var(--c); }
}

/* ---------- Layout ---------- */
.app {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.board-wrap {
  position: relative;
  border: 2px solid var(--accent);
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
  --pulse: 0;
  box-shadow:
    0 0 calc(12px + 24px * var(--pulse)) var(--accent),
    0 0 calc(60px * var(--pulse)) var(--accent-2),
    inset 0 0 calc(12px + 14px * var(--pulse)) hsl(var(--hue) 100% 60% / 0.35);
  transition: border-color 0.6s;
}

#board {
  display: block;
  width: min(300px, 60vw, calc((100vh - 315px) / 2));
  width: min(300px, 60vw, calc((100dvh - 315px) / 2));
  min-width: 180px;
  height: auto;
  background: rgba(10, 2, 20, 0.82);
}

.shake { animation: shake 0.25s; }
.shake-big { animation: shake-big 0.45s; }
@keyframes shake {
  25% { transform: translate(0, 4px); }
  60% { transform: translate(0, -2px); }
}
@keyframes shake-big {
  10% { transform: translate(-8px, 4px) rotate(-1deg); }
  30% { transform: translate(7px, -4px) rotate(1deg); }
  50% { transform: translate(-5px, 3px); }
  70% { transform: translate(4px, -2px); }
  90% { transform: translate(-2px, 1px); }
}

.levelup { animation: levelup 0.8s; }
@keyframes levelup {
  30% { box-shadow: 0 0 60px var(--accent), 0 0 120px var(--accent-2); }
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle, rgba(40, 10, 80, 0.8), rgba(8, 4, 24, 0.92));
  backdrop-filter: blur(3px);
  line-height: normal;
  text-align: center;
  padding: 16px;
}
.overlay.hidden { display: none; }
.overlay h1 {
  margin: 0;
  font-family: "Bungee", sans-serif;
  font-size: 1.8rem;
  line-height: 1.1;
  text-wrap: balance;
  color: #fff;
  text-shadow: 0 0 10px var(--accent), 0 0 30px var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.overlay p { margin: 0; color: var(--muted); }
@keyframes pulse { 50% { transform: scale(1.06); } }

button {
  font: inherit;
  font-family: "Bungee", sans-serif;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  box-shadow: 0 0 16px var(--accent);
  transition: transform 0.15s;
}
button:hover { transform: scale(1.07); }
button:active { transform: scale(0.95); }

/* ---------- Pop-ups ---------- */
.popup {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Bungee", sans-serif;
  font-size: 1.3rem;
  line-height: 1;
  white-space: pre-line;
  text-align: center;
  color: #fff;
  pointer-events: none;
  text-shadow: 0 0 8px var(--pc, var(--accent)), 0 0 20px var(--pc, var(--accent));
  animation: float-up 1.1s ease-out forwards;
}
.popup.big { font-size: 1.7rem; --pc: #ffd21f; }
.popup.combo { font-size: 1rem; --pc: #ff2e9a; }
.popup.level { font-size: 1.6rem; --pc: #00f0ff; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  30% { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}

/* ---------- Side panels ---------- */
.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 140px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 0 12px hsl(var(--hue) 100% 60% / 0.15);
}
.panel h2 {
  margin: 0 0 6px;
  font-family: "Bungee", sans-serif;
  font-weight: 400;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.panel canvas { display: block; width: 100%; max-width: 92px; height: auto; margin: 0 auto; }

.stats div { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; }
.stats span { color: var(--muted); font-size: 0.8rem; }
.stats strong {
  font-family: "Bungee", sans-serif;
  font-weight: 400;
  display: inline-block;
  text-shadow: 0 0 6px var(--accent);
}
.bump { animation: bump 0.3s; }
@keyframes bump { 40% { transform: scale(1.4); color: #ffd21f; } }

.help {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin-top: 14px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  font-size: 0.75rem;
  color: var(--muted);
}
kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 4px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  text-align: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.touch { display: none; }

@media (hover: none) and (pointer: coarse), (max-width: 560px) {
  .help { display: none; }
  .side { width: 96px; }
  .touch {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 420px;
    margin-top: 16px;
  }
  .touch button {
    padding: 14px 0;
    font-family: system-ui, sans-serif;
    font-size: 1.3rem;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--accent);
    box-shadow: 0 0 10px hsl(var(--hue) 100% 60% / 0.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Fever meter ---------- */
.meter {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#fever-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff2e9a, #ffd21f, #00e5ff);
  box-shadow: 0 0 10px #ff2e9a;
  transition: width 0.3s;
}
.fever-panel.full { animation: fever-panel 0.5s steps(1) infinite; }
.fever-panel.full #fever-fill { transition: none; }
@keyframes fever-panel { 50% { border-color: #ffd21f; box-shadow: 0 0 18px #ffd21f; } }

/* Fever mode: the whole room goes wild */
.fever { animation: hue-cycle 2s linear infinite; }
@keyframes hue-cycle { from { --hue: 0; } to { --hue: 360; } }
.fever .beam { animation-duration: 1.4s; opacity: 0.5; }
.fever .spots { animation: spin 8s linear infinite, twinkle 0.4s ease-in-out infinite; }
.fever .logo .word span { animation-duration: 0.5s, 0.4s; }

/* ---------- Overlay extras ---------- */
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
button.ghost {
  background: transparent;
  border: 2px solid var(--accent);
  box-shadow: none;
}
.hidden { display: none !important; }
.touch-hint { display: none; font-size: 0.8rem; max-width: 220px; }
@media (hover: none) and (pointer: coarse) {
  .touch-hint { display: block; }
}

/* ---------- Sound toggles ---------- */
.sound {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}
.sound .toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  font-family: system-ui, sans-serif;
  font-size: 1.1rem;
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: 0 0 10px hsl(var(--hue) 100% 60% / 0.4);
}
.sound .toggle[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }

/* ---------- DJ request ---------- */
.request {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 10px;
  max-width: min(460px, 100%);
  margin-bottom: 10px;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  box-shadow: 0 0 12px hsl(var(--hue) 100% 60% / 0.35);
  font-size: 0.85rem;
  text-align: center;
}
.request-label {
  font-family: "Bungee", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--accent);
}
#request-progress { font-family: "Bungee", sans-serif; color: #ffd21f; }
.request.fresh { animation: request-in 0.5s ease-out; }
@keyframes request-in { 0% { transform: scale(0.7); opacity: 0; } 70% { transform: scale(1.06); } }
.request.done {
  border-color: #ffd21f;
  box-shadow: 0 0 24px #ffd21f;
  animation: request-done 0.3s steps(1) 5;
}
@keyframes request-done { 50% { background: rgba(255, 210, 31, 0.3); } }

/* ---------- Dancing crowd ---------- */
.crowd { position: absolute; inset: 0; pointer-events: none; }
.dancer {
  position: absolute;
  bottom: 3vh;
  height: clamp(90px, 20vh, 180px);
  aspect-ratio: 80 / 112;
  filter: drop-shadow(0 0 6px var(--c)) drop-shadow(0 0 14px var(--c));
}
.dancer svg { width: 100%; height: 100%; overflow: visible; transition: transform 0.08s; }
.dancer path {
  fill: none;
  stroke: var(--c);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dancer .head, .dancer ellipse { fill: var(--c); }
/* Two poses per dancer: the disco point normally, twerking after a line clear */
.dancer .pose-twerk { display: none; }
.dancer.twerking .pose-twerk { display: block; }
.dancer.twerking .pose-disco { display: none; }
.face-left .pose-twerk { transform: scaleX(-1); }

/* Disco point: swap arms on every beat and bounce */
.dancer.flip .pose-disco { transform: scaleX(-1); }
.dancer.hop { animation: disco-hop 0.3s ease-out; }
@keyframes disco-hop { 30% { transform: translateY(-8%); } }

/* Twerk: squat low and bounce those hips */
.dancer .booty {
  transform-box: view-box;
  transform-origin: 40px 50px;
  animation: twerk 0.13s ease-in-out infinite alternate;
}
@keyframes twerk {
  from { transform: rotate(-12deg) translateY(2px); }
  to { transform: rotate(14deg) translateY(-3px); }
}
.dancer.twerking.hop { animation: twerk-dip 0.3s ease-out; }
@keyframes twerk-dip { 30% { transform: translateY(5%); } }
.dancer.twerking { animation: twerk-dip 0.25s ease-in-out infinite; }

/* Big moments: everybody jumps */
.dancer.cheer, .dancer.cheer.twerking { animation: cheer 0.5s ease-out 3; }
@keyframes cheer {
  40% { transform: translateY(-30%) rotate(-8deg); }
  70% { transform: translateY(-10%) rotate(6deg); }
}
.fever .dancer.hop { animation: cheer 0.4s ease-out; }
.fever .dancer.twerking.hop { animation: twerk-dip 0.2s ease-out; }

/* ---------- Phone layout ---------- */
@media (hover: none) and (pointer: coarse), (max-width: 560px) {
  body {
    justify-content: flex-start;
    min-height: 100dvh;
    padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  }

  /* Small disco ball tucked into the top-left corner */
  .ball-wrap {
    position: fixed;
    top: max(0px, env(safe-area-inset-top));
    left: 14px;
    margin: 0;
  }
  .ball-wrap .string { height: 8px; }
  .ball { width: 36px; height: 36px; background-size: auto, 9px 100%, 100% 5px, 36px 100%; }
  @keyframes ball-spin { to { background-position: 0 0, 9px 0, 0 0, 36px 0; } }

  .sound { top: max(8px, env(safe-area-inset-top)); }
  .sound .toggle { width: 34px; height: 34px; font-size: 0.95rem; }

  .logo {
    font-size: clamp(1rem, 5.3vw, 1.6rem);
    margin: 6px 0 6px;
    line-height: 1.2;
  }

  .request {
    flex-wrap: nowrap;
    gap: 6px;
    width: 100%;
    margin-bottom: 8px;
    padding: 4px 12px;
    font-size: 0.75rem;
  }
  .request-word { display: none; }
  #request-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .app { gap: 10px; width: 100%; justify-content: center; }

  /* Board fills whatever height is left over */
  #board {
    width: min(
      calc(100vw - 24px - 84px - 10px - 4px),
      calc((100dvh - 150px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2)
    );
    min-width: 120px;
  }

  .side { width: 84px; gap: 8px; }
  .panel { padding: 6px 8px; border-radius: 10px; }
  .panel h2 { font-size: 0.6rem; margin-bottom: 4px; }
  .panel canvas { max-width: 60px; }
  .meter { height: 8px; }
  .stats div { padding: 1px 0; flex-direction: column; align-items: flex-start; }
  .stats span { font-size: 0.65rem; }
  .stats strong { font-size: 0.85rem; }

  .overlay { gap: 10px; padding: 12px; }
  .overlay h1 { font-size: 1.4rem; }
  .overlay p { font-size: 0.8rem; }
  .overlay button { padding: 10px 20px; font-size: 0.85rem; }

  .touch {
    gap: 6px;
    margin-top: 10px;
    max-width: none;
  }
  .touch button { padding: 10px 0; font-size: 1.1rem; }

  .popup { font-size: 1rem; }
  .popup.big { font-size: 1.3rem; }
  .popup.level { font-size: 1.15rem; }
}
