:root {
  --ink: #161616;
  --panel-bg: rgba(250, 250, 250, 0.88);
  --line: rgba(0, 0, 0, 0.15);
  --positive: #1f8f3b;
  --negative: #b9332c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Trebuchet MS", sans-serif;
  min-height: 100vh;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.3), rgba(203, 233, 255, 0.3)),
    var(--bg-image, none),
    radial-gradient(circle at 20% 10%, #c5e5ff 0, #dcefff 40%, #eef7ff 100%);
  background-size: cover, cover, cover;
  background-position: center;
}

.game-shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-bg);
  backdrop-filter: blur(4px);
  transition: background-color 140ms ease, box-shadow 140ms ease;
}

.score-copy {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.caption {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.6);
}

#score-value {
  margin: 0;
  line-height: 1;
  font-size: clamp(1.65rem, 2.4vw, 2.2rem);
}

.score-delta {
  min-width: 72px;
  text-align: center;
  font-weight: 800;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.score-delta.show {
  opacity: 1;
  transform: translateY(0);
}

.score-delta.positive {
  color: var(--positive);
}

.score-delta.negative {
  color: var(--negative);
}

#audio-toggle {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-weight: 700;
  padding: 9px 12px;
  cursor: pointer;
}

#audio-toggle:hover {
  filter: brightness(1.03);
}

#game-area {
  position: relative;
  overflow: hidden;
}

.instructions {
  position: absolute;
  left: 14px;
  top: 12px;
  z-index: 20;
  max-width: 380px;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel-bg);
}

.balloon {
  position: absolute;
  left: 0;
  top: 0;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transform-origin: center center;
  user-select: none;
  touch-action: manipulation;
  overflow: visible;
}

.balloon:hover {
  filter: brightness(1.04);
}

.balloon-image {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.balloon-fallback {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  border-radius: 48% 48% 45% 45% / 52% 52% 41% 41%;
  background: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.65), transparent 28%), var(--balloon-fill, #d7efff);
  border: 3px solid var(--balloon-stroke, #b7dff8);
}

.balloon-label {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 20%;
  z-index: 3;
  text-align: center;
  font-size: clamp(0.79rem, 1.15vw, 1.02rem);
  line-height: 1.2;
  font-weight: 800;
  color: #111;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.balloon-string {
  position: absolute;
  left: 50%;
  top: calc(100% - 16px);
  width: 26px;
  height: 56px;
  margin-left: -13px;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='56' viewBox='0 0 26 56'%3E%3Cpath d='M13 1C19 11 6 20 14 30C22 40 8 46 13 55' fill='none' stroke='rgba(94,77,56,0.72)' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center top;
}

.balloon.image-missing .balloon-image {
  display: none;
}

.balloon.image-missing .balloon-fallback {
  display: block;
}

.balloon.popped {
  animation: pop 130ms ease forwards;
}

.top-bar.flash-positive {
  background: rgba(194, 246, 209, 0.95);
  box-shadow: 0 0 0 2px rgba(43, 160, 72, 0.22) inset;
}

.top-bar.flash-negative {
  background: rgba(255, 207, 207, 0.95);
  box-shadow: 0 0 0 2px rgba(185, 51, 44, 0.18) inset;
}

.win-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
  z-index: 95;
}

.win-overlay.show {
  opacity: 1;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  background: hsl(var(--hue), 80%, 62%);
  transform: translate(-50%, -50%) rotate(0deg) scale(0.8);
  animation: confetti-burst 1500ms cubic-bezier(0.16, 0.84, 0.2, 1) forwards;
  animation-delay: var(--delay);
}

.win-banner {
  position: relative;
  z-index: 2;
  margin: 0 14px;
  max-width: min(980px, 96vw);
  text-align: center;
  font-size: clamp(1.4rem, 4.1vw, 3.1rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: #1a1a1a;
  padding: clamp(18px, 3.3vw, 36px) clamp(16px, 4vw, 40px);
  border-radius: 20px;
  border: 2px solid rgba(0, 0, 0, 0.16);
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

@keyframes pop {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.22);
  }
}

@keyframes confetti-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(0deg) scale(0.8);
  }
  10% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(
      calc(-50% + var(--dx)),
      calc(-50% + var(--dy))
    ) rotate(var(--rot)) scale(0.9);
  }
}

@media (max-width: 720px) {
  .top-bar {
    padding: 10px 12px;
  }

  .score-copy {
    gap: 8px;
  }

  #audio-toggle {
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .instructions {
    max-width: 260px;
    font-size: 0.9rem;
  }
}
