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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #e9f4ff;
  background:
    radial-gradient(120% 80% at 20% 0%, #1d4e7a 0%, transparent 60%),
    radial-gradient(100% 70% at 100% 100%, #0f5a63 0%, transparent 55%),
    linear-gradient(160deg, #0b1d33 0%, #0a2840 55%, #072030 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- field ---------- */

.field {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.bubble {
  position: absolute;
  width: var(--size);
  height: var(--size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  transform: translate(-50%, -50%);
  animation: spawn 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.bubble:focus {
  outline: none;
}

.bubble:focus-visible .skin {
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.85),
    inset 0 0 calc(var(--size) * 0.18) hsla(var(--h), 90%, 75%, 0.45);
}

.skin {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95) 0 5%, rgba(255, 255, 255, 0) 13%),
    radial-gradient(circle at 70% 76%, rgba(255, 255, 255, 0.35) 0 3%, rgba(255, 255, 255, 0) 9%),
    radial-gradient(circle at 50% 50%,
      hsla(var(--h), 90%, 70%, 0.04) 0%,
      hsla(var(--h), 90%, 72%, 0.08) 52%,
      hsla(calc(var(--h) + 40), 95%, 72%, 0.32) 72%,
      hsla(calc(var(--h) + 110), 95%, 78%, 0.7) 92%,
      hsla(calc(var(--h) + 160), 95%, 85%, 0.85) 100%);
  box-shadow:
    inset 0 0 calc(var(--size) * 0.18) hsla(var(--h), 90%, 75%, 0.45),
    0 0 calc(var(--size) * 0.12) hsla(var(--h), 90%, 70%, 0.18);
  animation: drift var(--dur) ease-in-out var(--delay) infinite alternate;
  transition: transform 140ms ease;
}

@media (hover: hover) {
  .bubble:hover .skin {
    transform: scale(1.06);
  }
}

.bubble.popping {
  pointer-events: none;
  animation: pop 170ms ease-out forwards;
}

.bubble.fading {
  pointer-events: none;
  animation: fade 300ms ease-in forwards;
}

@keyframes spawn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes pop {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  40% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(1.22);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.35);
  }
}

@keyframes fade {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6);
  }
}

@keyframes drift {
  from {
    transform: translate(0, 0);
  }
  to {
    transform: translate(var(--dx), var(--dy));
  }
}

/* ---------- burst droplets ---------- */

.burst {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.drop {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: hsla(var(--h), 95%, 85%, 0.95);
  box-shadow: 0 0 6px hsla(var(--h), 95%, 75%, 0.8);
  animation: fly 420ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes fly {
  from {
    opacity: 1;
    transform: rotate(var(--a)) translateX(calc(var(--r) * 0.5)) scale(1);
  }
  to {
    opacity: 0;
    transform: rotate(var(--a)) translateX(calc(var(--r) * 1.05)) scale(0.3);
  }
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 10;
}

.hud-title {
  padding: 8px 14px 9px;
  border-radius: 14px;
  background: rgba(8, 24, 42, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.hud-count {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(233, 244, 255, 0.7);
  font-variant-numeric: tabular-nums;
}

.hud-count span {
  display: inline-block;
  color: #9fe7ff;
  font-weight: 700;
}

.hud-count span.bump {
  animation: bump 220ms ease-out;
}

@keyframes bump {
  40% {
    transform: scale(1.35);
  }
}

.mute {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 24, 42, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #e9f4ff;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.mute:hover {
  background: rgba(20, 50, 80, 0.6);
}

.mute:active {
  transform: scale(0.94);
}

.mute:focus-visible {
  outline: 2px solid #9fe7ff;
  outline-offset: 2px;
}

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-off,
.mute[aria-pressed="true"] .icon-on {
  display: none;
}

.mute[aria-pressed="true"] .icon-off {
  display: block;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(8, 24, 42, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  letter-spacing: 0.05em;
  color: rgba(233, 244, 255, 0.85);
  pointer-events: none;
  z-index: 10;
  transition: opacity 600ms ease, transform 600ms ease;
}

.hint.gone {
  opacity: 0;
  transform: translate(-50%, 10px);
}

@media (prefers-reduced-motion: reduce) {
  .skin {
    animation: none;
  }

  .bubble {
    animation-duration: 1ms;
  }

  .drop {
    display: none;
  }
}
