/* Beatbox Mixer — raised fan + 240px cybernetic hand */

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

:root {
  --bg: #0b0814;
  --text: #fff;
  --muted: #a89bc0;
  --ease: cubic-bezier(0.34, 1.25, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --hand-h: 240px;
}

html,
body {
  height: 100%;
  height: 100dvh;
}

body {
  font-family: "Nunito", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% 100%, #2a1450 0%, transparent 55%),
    radial-gradient(ellipse 40% 30% at 12% 20%, rgba(236, 72, 153, 0.18), transparent),
    radial-gradient(ellipse 35% 28% at 88% 18%, rgba(59, 130, 246, 0.16), transparent);
}

/* ----- Audio visualizer (unchanged) ----- */
.visualizer {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  gap: 3px;
  padding: 0 4px;
  pointer-events: none;
  opacity: 0.5;
}

.viz-bar {
  flex: 1 1 0;
  min-width: 0;
  height: 4%;
  border-radius: 4px 4px 0 0;
  transform-origin: bottom center;
  transition: height 0.05s linear;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.25);
}

/* ----- Header ----- */
.header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  flex-shrink: 0;
}

.header h1 {
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(100deg, #f9a8d4, #fde68a, #93c5fd, #c4b5fd);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 8s linear infinite;
  white-space: nowrap;
}

@keyframes shine {
  to {
    background-position: 200% center;
  }
}

.status {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  transition: color 0.25s ease;
}

.status.live {
  color: #fde68a;
}

.vol {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
}

.vol input {
  width: 92px;
  height: 44px;
  accent-color: #f9a8d4;
}

.stop-btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: #1a1030;
  background: linear-gradient(135deg, #fde68a, #f9a8d4);
  box-shadow: 0 4px 16px rgba(249, 168, 212, 0.35);
  transition: transform 0.2s var(--ease-out);
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .stop-btn:hover {
    transform: scale(1.04);
  }
}

.stop-btn:active {
  transform: scale(0.97);
}

/* Two fans: upper fan fills the top space, lower fan rests in the hand */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  overflow: hidden;
  padding-top: 1vh;
  /* lower fan's bottom edge sits between the hand's fingers */
  padding-bottom: calc(max(4vh, 20px) + var(--hand-h) * 0.86);
  flex-direction: column;
  align-items: center;
}

.stage--fan-high {
  /* vertical fan placement only */
}

.fan-scene {
  position: relative;
  z-index: 12;
  width: 100%;
  max-width: 1100px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 640px;
  margin: auto auto 0;
  overflow: visible;
}

.fan {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: 0;
  z-index: 2;
}

/* ----- Cards (unchanged) ----- */
.card {
  --angle: 0deg;
  --x: 0px;
  --arc: 0px;
  --lift: 0px;
  --scale: 1;
  --color: #ec4899;
  --w: 130px;
  --h: 185px;

  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) / -2);
  border: 3px solid transparent;
  padding: 0 0.45rem;
  cursor: pointer;
  border-radius: 18px;
  background: var(--color);
  color: #fff;
  font-family: inherit;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  transform-origin: center bottom;
  transform:
    translateX(var(--x))
    translateY(var(--arc))
    rotate(var(--angle))
    scale(var(--scale));
  transition:
    transform 0.55s var(--ease),
    box-shadow 0.35s ease,
    border-color 0.3s ease,
    filter 0.3s ease;
  z-index: 1;
  will-change: transform;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover:not(.active) {
    filter: brightness(1.07);
    --scale: 1.04;
    z-index: 20;
  }
}

.card:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

.card.active {
  --scale: 1.1;
  --lift: 44px;
  border-color: #fff;
  box-shadow:
    0 0 0 4px #fff,
    0 0 0 8px color-mix(in srgb, var(--color) 80%, #fff),
    0 0 32px var(--color),
    0 0 56px color-mix(in srgb, var(--color) 70%, transparent),
    0 20px 40px rgba(0, 0, 0, 0.35);
  transform:
    translateX(var(--x))
    translateY(var(--arc))
    rotate(var(--angle))
    translateY(calc(-1 * var(--lift)))
    scale(var(--scale));
  z-index: 40;
  filter: brightness(1.1);
}

.card-name {
  font-size: var(--name-size, clamp(1.05rem, 2.4vw, 1.5rem));
  font-weight: 900;
  letter-spacing: 0.01em;
  text-align: center;
  line-height: 1.1;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Tight fans (phones): name sits top-left like a playing-card index so it stays readable */
.fan--tight .card {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0.6rem 0.25rem 0;
}

.fan--tight .card-name {
  text-align: left;
}

.card.enter {
  animation: deal 0.55s var(--ease) both;
}

@keyframes deal {
  from {
    opacity: 0;
    transform: translateX(0) rotate(0deg) scale(0.4) translateY(24px);
  }
  to {
    opacity: 1;
    transform:
      translateX(var(--x))
      translateY(var(--arc))
      rotate(var(--angle))
      scale(var(--scale));
  }
}

/*
 * Cybernetic hand — 240px tall, center bottom under the fan.
 * Metallic plating + glowing joints.
 */
.hand {
  position: absolute;
  left: 50%;
  bottom: max(4vh, 20px);
  transform: translateX(-50%);
  width: auto;
  height: var(--hand-h); /* 240px */
  z-index: 10;
  pointer-events: none;
  animation: hand-servo 4s ease-in-out infinite;
}

.hand-aura {
  position: absolute;
  left: 50%;
  top: 58%;
  width: 130%;
  height: 85%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(34, 211, 238, 0.22) 0%,
    rgba(232, 121, 249, 0.12) 40%,
    transparent 70%
  );
  z-index: 0;
  animation: aura-pulse 3s ease-in-out infinite;
  pointer-events: none;
}

.hand-svg {
  position: relative;
  z-index: 1;
  display: block;
  width: auto;
  height: 100%;
  overflow: visible;
  filter:
    drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45))
    drop-shadow(0 0 12px rgba(34, 211, 238, 0.25));
}

/* Subtle joint pulse via SVG filter elements already glowing;
   extra CSS on wrist LEDs through whole-hand opacity breath */
@keyframes hand-servo {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-4px);
  }
}

@keyframes aura-pulse {
  0%,
  100% {
    opacity: 0.65;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
}

@media (max-width: 700px) {
  .header {
    flex-wrap: wrap;
    justify-content: center;
  }

  .status {
    order: 3;
    flex-basis: 100%;
    font-size: 0.8rem;
  }

  .stage {
    padding-top: 1vh;
    padding-bottom: calc(max(3vh, 12px) + var(--hand-h) * 0.86);
  }

  .hand {
    height: var(--hand-h);
    bottom: max(3vh, 12px);
  }

  .visualizer {
    gap: 2px;
    opacity: 0.4;
  }
}

/* Very short screens (phone on its side): shrink the hand so both fans fit */
@media (max-height: 560px) {
  :root {
    --hand-h: 150px;
  }

  .header {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .hand,
  .hand-aura {
    animation: none !important;
    transition-duration: 0.2s !important;
  }

  .card.enter {
    opacity: 1;
  }

  .viz-bar {
    transition: none;
  }
}
