/* ════════════════════════════════════════════════════════
   Slingshot — aim and pop
   ════════════════════════════════════════════════════════ */

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

html, body {
  height: 100vh;
  min-height: 100vh;
  width: 100vw;
  overflow: hidden;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;  /* prevent scrolling/zooming during drag */
  color: #1a3a52;
}

body {
  position: relative;
  background: transparent;
}

/* ─── Forest scene background ──────────────────────────── */
.scene-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: -2;
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    #ffe9a8 0%,
    #ffc88c 14%,
    #ffb09a 26%,
    #ffa9c0 36%,
    #c9c0e8 48%,
    #94c5e8 60%,
    #6db3da 76%,
    #4994c0 92%,
    #2d6f9c 100%
  );
}

.sun {
  position: absolute;
  top: 8%;
  left: 12%;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff5cc 0%, #ffd76e 40%, #ff9b3c 80%, transparent 100%);
  filter: blur(2px);
  animation: sunPulse 6s ease-in-out infinite;
}
@keyframes sunPulse {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50%      { transform: scale(1.08); opacity: 1; }
}

.sun-rays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: screen;
}
.ray {
  position: absolute;
  top: -10%;
  width: 12%;
  height: 130%;
  background: linear-gradient(180deg, rgba(255, 245, 200, 0.55) 0%, rgba(255, 245, 200, 0) 80%);
  transform-origin: top left;
  filter: blur(10px);
  animation: raySway 12s ease-in-out infinite;
}
.ray-1 { left: 15%; transform: rotate(-2deg);  animation-delay: 0s; }
.ray-2 { left: 28%; transform: rotate(3deg);   animation-delay: -3s; width: 10%; }
.ray-3 { left: 8%;  transform: rotate(-6deg);  animation-delay: -6s; width: 14%; }
@keyframes raySway {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 0.25; }
}

/* Distant trees as silhouette band */
.far-trees {
  position: absolute;
  bottom: 18%;
  left: 0; right: 0;
  height: 18%;
  background-image:
    radial-gradient(ellipse 60px 70px at 5% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 80px 90px at 18% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 50px 60px at 28% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 90px 110px at 42% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 60px 80px at 55% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 100px 100px at 70% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 70px 90px at 82% 100%, #2d5a3a 0 100%, transparent 100%),
    radial-gradient(ellipse 55px 65px at 95% 100%, #2d5a3a 0 100%, transparent 100%);
  background-repeat: no-repeat;
  opacity: 0.45;
}

/* Closer rolling hills */
.hills {
  position: absolute;
  bottom: 8%;
  left: 0; right: 0;
  height: 20%;
  background:
    radial-gradient(ellipse 60% 100% at 25% 100%, #5a8c4a 0%, #5a8c4a 65%, transparent 70%),
    radial-gradient(ellipse 50% 80% at 75% 100%, #6da655 0%, #6da655 70%, transparent 75%),
    radial-gradient(ellipse 45% 70% at 50% 100%, #4a7a3a 0%, #4a7a3a 70%, transparent 75%);
}

/* Foreground grass strip */
.grass {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 14%;
  background:
    linear-gradient(180deg, #4a7a3a 0%, #2d5a2a 100%);
  border-top: 3px solid #5a8c4a;
  box-shadow: inset 0 8px 20px rgba(255, 220, 120, 0.2);
}
.grass::before {
  /* Grass blade texture */
  content: '';
  position: absolute;
  top: -6px; left: 0; right: 0;
  height: 12px;
  background-image:
    linear-gradient(90deg, transparent 0 4px, #4a7a3a 4px 6px, transparent 6px 10px),
    linear-gradient(90deg, transparent 0 8px, #5a8c4a 8px 10px, transparent 10px 14px);
  background-size: 14px 12px, 18px 12px;
  background-repeat: repeat-x;
  opacity: 0.7;
}

/* Drifting leaves */
.leaves {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.leaf {
  position: absolute;
  font-size: var(--sz, 18px);
  opacity: 0.8;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
  animation: leafFall var(--dur, 14s) linear infinite;
}
@keyframes leafFall {
  0%   { transform: translate(0, 0) rotate(0); }
  25%  { transform: translate(-30px, 25vh) rotate(120deg); }
  50%  { transform: translate(20px, 50vh) rotate(240deg); }
  75%  { transform: translate(-15px, 75vh) rotate(360deg); }
  100% { transform: translate(10px, 100vh) rotate(480deg); }
}

/* ─── HUD ──────────────────────────────────────────────── */
.hud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px env(safe-area-inset-top, 12px);
  z-index: 10;
}
.hud-side { flex: 0 0 auto; min-width: 110px; }
.hud-side--right { display: flex; justify-content: flex-end; }
.hud-center { flex: 1 1 auto; display: flex; justify-content: center; }

.lives {
  display: inline-flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 14px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 18px;
}
.heart {
  display: inline-block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  transition: opacity 0.4s ease, filter 0.4s ease;
}
.heart--lost {
  filter: grayscale(100%) brightness(0.45);
  opacity: 0.4;
  animation: heartBreak 0.5s ease-out;
}
@keyframes heartBreak {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.6) rotate(8deg); filter: brightness(1.5) drop-shadow(0 0 8px #ff5560); }
  60%  { transform: scale(0.7) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 16px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 22px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  min-width: 84px;
  justify-content: center;
}
.score-icon { font-size: 20px; }
.score-num--bump {
  animation: scoreBump 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes scoreBump {
  0%   { transform: scale(1); color: #1a3a52; }
  40%  { transform: scale(1.6); color: #f5a700; }
  100% { transform: scale(1); color: #1a3a52; }
}

.mode-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.mode-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #5a7a8a;
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
  white-space: nowrap;
}
.mode-btn:active { transform: scale(0.94); }
.mode-btn--active {
  background: linear-gradient(180deg, #f97316, #c2410c);
  color: #fff;
  box-shadow: 0 2px 6px rgba(194, 65, 12, 0.55), inset 0 -2px 0 rgba(0,0,0,0.1);
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}

/* ─── Problem banner ───────────────────────────────────── */
.problem-banner {
  position: relative;
  margin: 6px auto 8px;
  padding: 10px 24px 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid #ffd96e;
  border-radius: 22px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25), inset 0 -3px 0 rgba(0,0,0,0.06);
  text-align: center;
  z-index: 5;
  width: fit-content;
  max-width: 90vw;
  animation: bannerPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.problem-banner::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border: 8px solid transparent;
  border-top-color: #ffd96e;
}
@keyframes bannerPop {
  from { transform: scale(0.6) translateY(-10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.problem-label {
  font-size: 12px;
  font-weight: 600;
  color: #5a7a8a;
  letter-spacing: 0.02em;
}
.problem-math {
  font-size: 32px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  line-height: 1.1;
}
.problem-math--changing {
  animation: problemFlip 0.32s ease;
}
@keyframes problemFlip {
  0%   { transform: rotateX(0); opacity: 1; }
  50%  { transform: rotateX(90deg); opacity: 0; }
  100% { transform: rotateX(0); opacity: 1; }
}

.streak-pill {
  position: absolute;
  top: -12px;
  right: -12px;
  background: linear-gradient(180deg, #ff7e5f, #d63031);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 2.5px solid #fff;
  box-shadow: 0 3px 8px rgba(214, 48, 49, 0.5);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  animation: streakPulse 0.8s ease-in-out infinite;
}
.streak-pill[hidden] { display: none; }
@keyframes streakPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}
.flame { font-size: 12px; }

/* ─── Ammo row ─────────────────────────────────────────── */
.ammo-row {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  z-index: 4;
}
.ammo-label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(26, 58, 82, 0.85);
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
}
.ammo-pebbles {
  display: inline-flex;
  gap: 4px;
}
.pebble {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c9b599 0%, #8b6f47 50%, #5a4530 100%);
  border: 2px solid #3a2c1c;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 -2px 0 rgba(0,0,0,0.2);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.pebble--used {
  opacity: 0.25;
  transform: scale(0.7);
  background: radial-gradient(circle at 35% 30%, #999 0%, #555 70%);
}

/* ─── Scene ────────────────────────────────────────────── */
.scene {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2;
}
.balloon-layer, .trajectory-layer, .projectile-layer, .particle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.particle-layer { z-index: 6; }
.projectile-layer { z-index: 5; }
.trajectory-layer { z-index: 3; pointer-events: none; }
.balloon-layer { z-index: 4; }

.drag-zone {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  height: 75%;
  pointer-events: auto;
  z-index: 4;
  /* invisible — just captures pointer events */
}

/* ─── Slingshot ────────────────────────────────────────── */
.slingshot-mount {
  position: absolute;
  bottom: 4%;
  left: 4%;
  width: 140px;
  height: 200px;
  z-index: 7;
  pointer-events: auto;
  cursor: grab;
}
.slingshot-mount:active { cursor: grabbing; }
.slingshot-svg, .elastic-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.elastic-svg { z-index: 1; }
.slingshot-svg { z-index: 0; }

.elastic {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
.pouch {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}
.pouch-projectile {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.pouch-projectile--hidden { opacity: 0; }

/* ─── Balloons ─────────────────────────────────────────── */
.balloon {
  position: absolute;
  top: 0;
  left: 0;
  width: 80px;
  height: 110px;
  pointer-events: none; /* targets are hit by projectile collision, not click */
  filter: drop-shadow(0 6px 8px rgba(0,0,0,0.3));
  animation: balloonBob var(--bobDur, 3s) ease-in-out infinite;
  will-change: transform;
}
@keyframes balloonBob {
  0%, 100% { transform: translate(var(--x, 0), var(--y, 0)) rotate(-2deg); }
  50%      { transform: translate(calc(var(--x, 0) + 4px), calc(var(--y, 0) - 6px)) rotate(2deg); }
}
.balloon-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.balloon-num {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  fill: #fff;
  stroke: #1a3a52;
  stroke-width: 0.8px;
  paint-order: stroke fill;
  font-size: 28px;
}

.balloon--popping {
  animation: balloonPop 0.4s ease-out forwards;
}
@keyframes balloonPop {
  0%   { transform: var(--popStart, scale(1)); opacity: 1; }
  40%  { transform: var(--popMid, scale(1.4)); opacity: 0.9; filter: brightness(1.5); }
  100% { transform: var(--popEnd, scale(0.2)); opacity: 0; }
}

/* ─── Projectile ───────────────────────────────────────── */
.projectile {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c9b599 0%, #8b6f47 50%, #5a4530 100%);
  border: 2px solid #3a2c1c;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: transform;
}

/* Trajectory preview dots */
.traj-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: var(--op, 0.7);
}

/* ─── Particles ────────────────────────────────────────── */
.confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  pointer-events: none;
  animation: confettiBurst var(--dur, 0.9s) cubic-bezier(0.3, 0.5, 0.6, 1) forwards;
}
@keyframes confettiBurst {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, 100px)) rotate(var(--rot, 720deg)); opacity: 0; }
}

.spark {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  animation: sparkRise var(--dur, 1s) ease-out forwards;
}
@keyframes sparkRise {
  0%   { transform: translate(0, 0) scale(0.3) rotate(0); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -120px)) scale(1.1) rotate(var(--rot, 360deg)); opacity: 0; }
}

.x-mark {
  position: absolute;
  font-size: 36px;
  pointer-events: none;
  font-weight: 900;
  color: #ff4040;
  text-shadow: 0 2px 0 #fff, 0 4px 12px rgba(0,0,0,0.6);
  animation: xMark 0.6s ease-out forwards;
  transform: translate(-50%, -50%);
}
@keyframes xMark {
  0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-30deg); opacity: 1; }
  30%  { transform: translate(-50%, -50%) scale(1.3) rotate(0); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(8deg); opacity: 0; }
}

.miss-dust {
  position: absolute;
  width: 50px;
  height: 16px;
  background: radial-gradient(ellipse, rgba(140,110,70,0.7) 0%, rgba(140,110,70,0) 80%);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: missDust 0.6s ease-out forwards;
}
@keyframes missDust {
  0%   { transform: translate(-50%, -50%) scale(0.3); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
}

/* ─── Floating text ────────────────────────────────────── */
.float-text {
  position: absolute;
  font-weight: 700;
  font-size: 26px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.3), 0 4px 10px rgba(0,0,0,0.5);
  pointer-events: none;
  white-space: nowrap;
  animation: floatRise 1s ease-out forwards;
  transform: translate(-50%, 0);
  z-index: 8;
}
.float-text--good { color: #ffe066; }
.float-text--combo { color: #ff7eb3; font-size: 30px; }
.float-text--big { color: #6dffe0; font-size: 36px; }
@keyframes floatRise {
  0%   { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  20%  { transform: translate(-50%, -20px) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -100px) scale(1); opacity: 0; }
}

/* ─── Screen shake ─────────────────────────────────────── */
.scene-bg--shake { animation: shake 0.35s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translate(-6px, -3px); }
  40%      { transform: translate(6px, 3px); }
  60%      { transform: translate(-4px, -2px); }
  80%      { transform: translate(4px, 2px); }
}

/* ─── Overlays ─────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 30, 50, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: overlayFade 0.3s ease;
}
@keyframes overlayFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: linear-gradient(180deg, #fff 0%, #fff8e0 100%);
  color: #1a3a52;
  border: 4px solid #ffd96e;
  border-radius: 28px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  max-width: 90vw;
  min-width: 280px;
  animation: cardPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardPop {
  from { transform: scale(0.5) translateY(40px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.overlay-emoji {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}
.overlay-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 18px;
  color: #1a3a52;
}
.overlay-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 14px;
}
.stat {
  background: #fff5e6;
  border: 3px solid #ffd9a8;
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 96px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #b97a3a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-num {
  font-size: 36px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.overlay-msg {
  font-size: 15px;
  color: #5a7a8a;
  margin-bottom: 18px;
  min-height: 1.3em;
}
.overlay-msg--new-best {
  color: #c2410c;
  font-weight: 700;
  font-size: 18px;
  animation: msgPulse 1s ease-in-out infinite;
}
@keyframes msgPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.big-btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #f97316, #c2410c);
  border: none;
  padding: 14px 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 8px 16px rgba(194, 65, 12, 0.5);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 8px rgba(194, 65, 12, 0.5);
}

/* ─── Responsive ───────────────────────────────────────── */
@media (max-width: 600px) {
  .hud { padding: 10px 8px; gap: 6px; }
  .hud-side { min-width: 0; }
  .lives { padding: 6px 10px; font-size: 16px; gap: 2px; }
  .score-pill { padding: 6px 12px; font-size: 18px; min-width: 64px; }
  .score-icon { font-size: 16px; }
  .mode-btn { font-size: 12px; padding: 5px 9px; }
  .problem-math { font-size: 28px; }
  .problem-banner { padding: 8px 18px; }
  .ammo-label { font-size: 12px; }
  .pebble { width: 14px; height: 14px; }
  .balloon { width: 64px; height: 88px; }
  .balloon-num { font-size: 24px; }
  .slingshot-mount { width: 110px; height: 160px; left: 3%; bottom: 2%; }
  .sun { width: 80px; height: 80px; }
  .overlay-card { padding: 22px 24px; min-width: 240px; }
  .overlay-emoji { font-size: 52px; }
  .overlay-title { font-size: 22px; }
  .stat-num { font-size: 28px; }
  .stat { padding: 8px 14px; min-width: 80px; }
  .big-btn { font-size: 18px; padding: 12px 28px; }
}

@media (max-width: 380px) {
  .balloon { width: 54px; height: 74px; }
  .balloon-num { font-size: 20px; }
  .slingshot-mount { width: 90px; height: 130px; }
}
