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

:root {
  --bg: #111;
  --surface: #1e1e1e;
  --accent: #e05c00;
  --btn-active: #ff9944;
  --text: #f0f0f0;
  --muted: #888;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Flying heads layer */
#heads-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.head-obj {
  position: absolute;
  width: 64px;
  height: 64px;
  will-change: transform;
}

/* Page layout — vertically centered */
#page-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  gap: 0;
}

header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid #2a2a2a;
  width: 100%;
  max-width: 700px;
}


/* Sound buttons grid */
#soundboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 24px 0;
  width: 100%;
  max-width: 700px;
  justify-items: center;
}

/* Last odd button centers on mobile */
.sound-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  width: 50%;
  min-width: 140px;
}

.sound-btn {
  background: var(--surface);
  border: 2px solid #333;
  border-radius: 14px;
  color: var(--text);
  cursor: pointer;
  min-height: 100px;
  padding: 16px 12px 10px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sound-btn:hover {
  background: #2a2a2a;
  border-color: var(--accent);
}

.sound-btn.playing {
  background: var(--accent);
  border-color: var(--btn-active);
  color: #fff;
}

.btn-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1.3;
}

/* Progress bar — track hidden until playing, fill animates */
.progress-bar {
  display: block;
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.sound-btn.playing .progress-bar {
  opacity: 1;
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 3px;
  transition: none;
}

/* Footer */
footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 700px;
  padding-top: 16px;
}

#footer-row1 {
  display: flex;
  justify-content: center;
}

#footer-row2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#stop-all {
  background: #2a2a2a;
  border: 2px solid #444;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 12px 28px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  touch-action: manipulation;
}

#stop-all:hover { background: #333; color: var(--text); border-color: #666; }
#stop-all:active { background: #444; }

#full-song-btn {
  background: #1a1a2e;
  border: 2px solid #333;
  border-radius: 10px;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 14px 36px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  touch-action: manipulation;
  letter-spacing: 0.03em;
  width: 100%;
  max-width: 320px;
}

#full-song-btn:hover { background: #222240; border-color: var(--accent); }
#full-song-btn.playing { background: var(--accent); border-color: var(--btn-active); color: #fff; }

/* Song progress + timer */
#song-progress-wrap {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.3s;
}

#song-progress-wrap.visible { opacity: 1; }

#song-progress-bar {
  width: 100%;
  height: 12px;
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
}

#song-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: none;
}

#song-timer {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.04em;
}

/* Logo dance — only when song is playing */
@keyframes logo-dance {
  0%   { transform: translateY(0px) rotate(0deg) scaleX(1); }
  15%  { transform: translateY(-4px) rotate(-8deg) scaleX(1); }
  30%  { transform: translateY(0px) rotate(0deg) scaleX(1); }
  45%  { transform: translateY(-4px) rotate(8deg) scaleX(1); }
  60%  { transform: translateY(0px) rotate(0deg) scaleX(1); }
  72%  { transform: translateY(-2px) rotate(-5deg) scaleX(-1); }
  84%  { transform: translateY(0px) rotate(0deg) scaleX(-1); }
  92%  { transform: translateY(-2px) rotate(5deg) scaleX(1); }
  100% { transform: translateY(0px) rotate(0deg) scaleX(1); }
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  transform-origin: center bottom;
}

body.song-playing .logo {
  animation: logo-dance 2.4s ease-in-out infinite;
}

/* Button dance + light show */
@keyframes btn-dance {
  0%   { transform: translateY(0px)  rotate(0deg); }
  20%  { transform: translateY(-6px) rotate(-3deg); }
  40%  { transform: translateY(0px)  rotate(0deg); }
  60%  { transform: translateY(-6px) rotate(3deg); }
  80%  { transform: translateY(0px)  rotate(0deg); }
  100% { transform: translateY(0px)  rotate(0deg); }
}

@keyframes btn-lightshow {
  0%   { border-color: #e05c00; box-shadow: 0 0 8px #e05c0088; }
  16%  { border-color: #ff2266; box-shadow: 0 0 12px #ff226688; }
  33%  { border-color: #ffcc00; box-shadow: 0 0 12px #ffcc0088; }
  50%  { border-color: #00ccff; box-shadow: 0 0 12px #00ccff88; }
  66%  { border-color: #aa44ff; box-shadow: 0 0 12px #aa44ff88; }
  83%  { border-color: #00ff88; box-shadow: 0 0 12px #00ff8888; }
  100% { border-color: #e05c00; box-shadow: 0 0 8px #e05c0088; }
}

.sound-btn.dancing {
  animation: btn-dance 0.8s ease-in-out infinite,
             btn-lightshow 1.6s linear infinite;
}

/* Footer elements dance + light show */
#stop-all.dancing,
#full-song-btn.dancing {
  animation: btn-dance 0.9s ease-in-out infinite,
             btn-lightshow 1.8s linear infinite;
}

/* Progress wrap — dance only, no light show */
#song-progress-wrap.dancing {
  animation: btn-dance 0.9s ease-in-out infinite;
}

#stop-all.dance-stopping,
#full-song-btn.dance-stopping,
#song-progress-wrap.dance-stopping {
  animation: none !important;
  transform: translateY(0px) rotate(0deg) !important;
  transition: transform 0.5s ease-out;
}

/* Ease back to rest */
.sound-btn.dance-stopping {
  animation: none !important;
  transform: translateY(0px) rotate(0deg) !important;
  transition: transform 0.5s ease-out, border-color 0.5s ease-out, box-shadow 0.5s ease-out;
}

/* Desktop — restore normal grid, no centering tricks */
@media (min-width: 600px) {
  #soundboard {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    justify-items: stretch;
  }

  .sound-btn:last-child:nth-child(odd) {
    grid-column: auto;
    width: 100%;
  }

  .sound-btn { min-height: 120px; font-size: 1.05rem; }
}
