/* ===== BASE RESET & VARIABLES ===== */
:root {
  --pitch: #2d5a27;
  --pitch-light: #3d7a35;
  --gold: #ffd700;
  --ball: #c41e3a;
  --bat: #8b4513;
  --white: #fff;
  --sky: #1a1a2e;
  --sun: #ff6b35;
  --dark: #0f1923;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', sans-serif;
  background: var(--dark);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== CANVAS ===== */
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 50;
  pointer-events: none;
}

/* ===== OVERLAYS (splash + game-over) ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease-out, visibility 0.25s ease-out;
}
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ===== BETWEEN OVER OVERLAY ===== */
.between-over {
  background: rgba(15, 25, 35, 0.92);
  backdrop-filter: blur(8px);
}
.between-over-content {
  text-align: center;
  padding: 2rem 3rem;
  border: 3px solid var(--gold);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
}
.between-over-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 6vw, 3.5rem);
  color: var(--gold);
  letter-spacing: 4px;
  margin-bottom: 0.5rem;
}
.between-over-bowler {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: var(--white);
  font-weight: 600;
}
.between-over-bowler span {
  color: var(--gold);
}
.between-over-skill {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
  color: rgba(255, 255, 255, 0.85);
  margin-top: 0.35rem;
}
.between-over-skill span {
  color: var(--gold);
  font-weight: 600;
}

/* ===== BONUS OVER OVERLAY ===== */
.bonus-overlay {
  background: rgba(15, 25, 35, 0.85);
  backdrop-filter: blur(10px);
}
.bonus-overlay-content {
  text-align: center;
  padding: 2.5rem 3.5rem;
  border: 4px solid var(--gold);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255,215,0,0.15), rgba(255,107,53,0.1));
  box-shadow: 0 0 60px rgba(255, 215, 0, 0.35);
  animation: bonus-glow 1s ease-in-out infinite alternate;
}
@keyframes bonus-glow {
  from { box-shadow: 0 0 40px rgba(255, 215, 0, 0.25); }
  to { box-shadow: 0 0 70px rgba(255, 215, 0, 0.5); }
}
.bonus-overlay-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 7vw, 4rem);
  color: var(--gold);
  letter-spacing: 6px;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}
.bonus-overlay-sub {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  color: rgba(255,255,255,0.9);
}

/* ===== SPLASH SCREEN ===== */
.splash {
  background: linear-gradient(180deg, #87ceeb 0%, #e0f6ff 40%, var(--pitch) 40%, var(--pitch-light) 100%);
}

.sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.sun {
  position: absolute;
  top: 10%; right: 15%;
  width: 80px; height: 80px;
  background: radial-gradient(circle, #fff 20%, var(--sun) 70%);
  border-radius: 50%;
  box-shadow: 0 0 60px var(--sun);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.05); } }

.cloud {
  position: absolute;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  animation: drift 20s linear infinite;
}
.cloud:nth-child(2) { top: 15%; left: -100px; width: 60px; height: 30px; animation-duration: 25s; }
.cloud:nth-child(3) { top: 25%; left: -80px; width: 80px; height: 40px; animation-duration: 22s; animation-delay: -5s; }
.cloud:nth-child(4) { top: 8%; left: -120px; width: 50px; height: 25px; animation-duration: 28s; animation-delay: -10s; }
@keyframes drift { to { transform: translateX(calc(100vw + 200px)); } }

.splash-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem;
}

.title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2.5rem, 8vw, 5rem);
  color: var(--gold);
  text-shadow: 4px 4px 0 #b8860b, 6px 6px 0 rgba(0,0,0,0.3);
  letter-spacing: 4px;
  animation: bounce 0.6s ease infinite alternate;
  margin-bottom: 0.25rem;
}

.name {
  font-family: 'Bangers', cursive;
  font-size: clamp(3rem, 12vw, 7rem);
  color: var(--white);
  text-shadow: 4px 4px 0 var(--ball), 8px 8px 0 rgba(0,0,0,0.4);
  letter-spacing: 6px;
  animation: bounce 0.6s ease infinite alternate 0.1s;
  margin-bottom: 1rem;
}
@keyframes bounce { to { transform: translateY(-8px); } }

/* Stumps decoration */
.stumps-wrap { position: relative; margin: 1rem 0; }
.stumps { display: flex; gap: 8px; justify-content: center; align-items: flex-end; perspective: 400px; }
.stump {
  width: 16px; height: 64px;
  background: linear-gradient(90deg, #654321, #8b6914, #654321);
  border-radius: 3px;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
  animation: stump-wobble 2s ease-in-out infinite;
}
.stump:nth-child(1) { animation-delay: 0s; }
.stump:nth-child(2) { animation-delay: 0.2s; }
.stump:nth-child(3) { animation-delay: 0.4s; }
@keyframes stump-wobble {
  0%, 100% { transform: rotateY(-3deg); }
  50% { transform: rotateY(3deg); }
}
.bails {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%);
  width: 52px; height: 6px;
  background: linear-gradient(180deg, #fff, #ddd);
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Ball decoration */
.ball-deco {
  width: 40px; height: 40px;
  background: radial-gradient(circle at 30% 30%, #e84a5f, var(--ball));
  border-radius: 50%;
  margin: 0.5rem auto;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
  animation: ball-spin 1s linear infinite;
}
@keyframes ball-spin { to { transform: rotate(360deg); } }

.cake {
  margin: 0.5rem 0;
  font-size: 3rem;
  animation: wiggle 0.5s ease-in-out infinite;
}
@keyframes wiggle { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }

/* Hamid running stickman — full splash area so he can run higher/lower; behind content (z < .splash-content) */
.splash-stickman-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: auto;
  z-index: 0.5;
  cursor: default;
}
#splashStickmanCanvas {
  display: block;
  width: 100%;
  height: 100%;
  vertical-align: bottom;
  pointer-events: auto;
}
.splash-stickman-bubble {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 160px;
  max-width: 240px;
  padding: 0.6rem 0.85rem;
  background: #fff;
  border: 2px solid #222;
  border-radius: 12px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.5) inset;
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1rem, 2.8vw, 1.15rem);
  font-weight: 700;
  color: #111;
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255,255,255,0.9);
  -webkit-font-smoothing: antialiased;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1;
}
.splash-stickman-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

.splash-msg {
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  color: var(--white);
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
  max-width: 400px;
  margin-bottom: 0.5rem;
}

.high-score-splash {
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 2px;
  margin-bottom: 0.5rem;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

/* ===== BUTTONS ===== */
.bat-btn {
  margin-top: 1rem;
  padding: 0.9rem 2.2rem;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--pitch);
  background: linear-gradient(180deg, var(--gold), #daa520);
  border: 4px solid #b8860b;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 0 #8b6914, 0 8px 20px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
.bat-btn:hover {
  transform: translateY(2px);
  box-shadow: 0 4px 0 #8b6914, 0 6px 15px rgba(0,0,0,0.3);
}
.bat-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #8b6914, 0 4px 10px rgba(0,0,0,0.3);
}

.song-btn {
  margin-top: 0.6rem;
  padding: 0.5rem 1.4rem;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
.song-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== SCOREBOARD HUD ===== */
.scoreboard {
  position: fixed;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 1rem;
  background: linear-gradient(135deg, rgba(15,25,35,0.92), rgba(22,33,62,0.92));
  color: var(--gold);
  padding: 0.5rem 1.2rem;
  border-radius: 10px;
  font-family: 'Bangers', cursive;
  letter-spacing: 2px;
  border: 2px solid rgba(255,215,0,0.5);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 20;
  backdrop-filter: blur(6px);
}
.sb-row { display: flex; align-items: baseline; gap: 4px; }
.sb-label { font-size: 0.7rem; opacity: 0.7; color: #aaa; }
.sb-value { font-size: 1.15rem; color: var(--white); }
.sb-sep { font-size: 0.9rem; color: #aaa; margin: 0 1px; }

/* ===== COMMENTARY BAR ===== */
.commentary {
  position: fixed;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  background: rgba(15,25,35,0.88);
  color: var(--white);
  padding: 0.45rem 1.4rem;
  border-radius: 20px;
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(0.85rem, 2vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 1px;
  border: 2px solid rgba(255,215,0,0.3);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 20;
  text-align: center;
  max-width: 90vw;
  white-space: nowrap;
  transition: opacity 0.3s;
}

/* ===== DRAG HINT ===== */
.drag-hint {
  position: fixed;
  bottom: 60px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255,215,0,0.2);
  color: var(--gold);
  padding: 0.4rem 1.2rem;
  border-radius: 16px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid rgba(255,215,0,0.4);
  z-index: 20;
  animation: hint-pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hint-pulse {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

/* ===== GAME OVER ===== */
.game-over {
  background: rgba(15,25,35,0.92);
  backdrop-filter: blur(8px);
}

.go-content {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 2rem; max-width: 400px; width: 90vw;
}

.go-new-record {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  color: var(--gold);
  letter-spacing: 3px;
  text-shadow: 2px 2px 0 #b8860b;
  animation: record-flash 0.6s ease-in-out infinite alternate;
  margin-bottom: 0.5rem;
}
@keyframes record-flash {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.1); opacity: 1; }
}

.go-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 6vw, 3rem);
  color: var(--white);
  letter-spacing: 3px;
  margin-bottom: 0.5rem;
}

.go-dismissal-reason {
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  color: #ffaa44;
  margin-bottom: 0.8rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255, 170, 68, 0.15);
  border-radius: 999px;
  border: 1px solid rgba(255, 170, 68, 0.35);
  max-width: 90%;
}

.go-face {
  width: 100px; height: 100px;
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid var(--gold);
  box-shadow: 0 0 20px rgba(255,215,0,0.3);
  margin-bottom: 1rem;
}
.go-face img { width: 100%; height: 100%; object-fit: cover; }

.go-stats {
  display: flex; gap: 1.2rem; margin-bottom: 1rem;
  flex-wrap: wrap; justify-content: center;
}
.go-stat {
  display: flex; flex-direction: column; align-items: center;
  background: rgba(255,255,255,0.08);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  min-width: 65px;
}
.go-stat-value {
  font-family: 'Bangers', cursive;
  font-size: 1.8rem; color: var(--gold); letter-spacing: 2px;
}
.go-stat-label {
  font-size: 0.7rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px;
}

.go-best {
  font-family: 'Bangers', cursive;
  font-size: 1rem; color: var(--gold);
  letter-spacing: 2px; margin-bottom: 0.5rem;
  opacity: 0.8;
}

.go-birthday {
  font-size: clamp(1rem, 3vw, 1.3rem);
  color: var(--white);
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

/* ===== MENU BUTTON ===== */
.menu-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 25;
  padding: 0.5rem 1rem;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
  background: rgba(15, 25, 35, 0.9);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  transition: background 0.2s, transform 0.1s;
}
.menu-btn:hover {
  background: rgba(30, 45, 65, 0.95);
  transform: scale(1.02);
}

/* ===== HELP OVERLAY ===== */
.help-overlay {
  background: rgba(15, 25, 35, 0.94);
  backdrop-filter: blur(10px);
}
.help-overlay-content {
  max-width: 420px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  padding: 2rem;
  border: 3px solid var(--gold);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
  text-align: left;
}
.help-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  color: var(--gold);
  letter-spacing: 3px;
  margin-bottom: 1rem;
  text-align: center;
}
.help-body {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  color: var(--white);
  line-height: 1.5;
  margin-bottom: 1.2rem;
}
.help-body p {
  margin-bottom: 0.8rem;
}
.help-body p:last-child {
  margin-bottom: 0;
}
.help-body strong {
  color: var(--gold);
}
.help-overlay-content .bat-btn {
  margin-right: 0.5rem;
}
.help-tutorial-link {
  margin-top: 0.5rem;
}

/* ===== TUTORIAL OVERLAY ===== */
.tutorial-overlay {
  background: rgba(15, 25, 35, 0.94);
  backdrop-filter: blur(10px);
}
.tutorial-overlay-content {
  max-width: 400px;
  width: 90vw;
  padding: 2rem;
  border: 3px solid var(--gold);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
  text-align: center;
}
.tutorial-step-content {
  font-family: 'Fredoka', sans-serif;
  color: var(--white);
  min-height: 80px;
  margin-bottom: 1.5rem;
}
.tutorial-step-content .tutorial-step-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  color: var(--gold);
  letter-spacing: 2px;
  margin-bottom: 0.6rem;
}
.tutorial-step-content .tutorial-step-body {
  font-size: clamp(0.95rem, 2.2vw, 1.1rem);
  line-height: 1.5;
}
.tutorial-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  align-items: center;
}
.tutorial-nav .song-btn,
.tutorial-nav .bat-btn {
  margin-top: 0;
}

/* ===== TEA BREAK OVERLAY ===== */
.tea-break {
  background: rgba(15, 25, 35, 0.92);
  backdrop-filter: blur(8px);
}
.tea-break-content {
  text-align: center;
  padding: 2.5rem 3rem;
  border: 3px solid var(--gold);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
}
.tea-break-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 6vw, 3.5rem);
  color: var(--gold);
  letter-spacing: 4px;
  margin-bottom: 0.5rem;
}
.tea-break-msg {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 1.2rem;
}
.tea-break-btn {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
}
.tea-break-btn:first-of-type {
  margin-top: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .scoreboard { gap: 0.5rem; padding: 0.4rem 0.8rem; top: 8px; }
  .sb-value { font-size: 1rem; }
  .sb-label { font-size: 0.6rem; }
  .commentary { bottom: 10px; padding: 0.35rem 1rem; font-size: 0.8rem; }
  .drag-hint { bottom: 48px; font-size: 0.75rem; }
  .go-stats { gap: 0.6rem; }
  .go-stat { padding: 0.4rem 0.7rem; min-width: 55px; }
  .go-stat-value { font-size: 1.4rem; }
}
