/* ============================================================
   BERBURU ANGKA - style.css
   Game Edukasi Anak Usia 3-5 Tahun
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Comic Sans MS', 'Segoe UI', 'Trebuchet MS', sans-serif;
  background: #05060f;
  touch-action: manipulation;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SCREEN MANAGEMENT
   ============================================================ */

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  overflow: hidden;
}

.screen.active-screen {
  display: block;
}

/* ============================================================
   OPENING SCREEN
   ============================================================ */

#opening-screen {
  background: radial-gradient(ellipse at top, #1b1140 0%, #0a0620 55%, #05030f 100%);
}

.stars-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.star {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  animation: twinkle 2.5s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.3); }
}

.fireflies-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.firefly {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff8c4 0%, #ffe066 40%, rgba(255,224,102,0) 80%);
  box-shadow: 0 0 10px 4px rgba(255, 224, 102, 0.6);
  animation: floatFirefly 6s ease-in-out infinite;
}

@keyframes floatFirefly {
  0% { transform: translate(0, 0); opacity: 0.4; }
  25% { transform: translate(20px, -30px); opacity: 1; }
  50% { transform: translate(-15px, -60px); opacity: 0.6; }
  75% { transform: translate(25px, -30px); opacity: 1; }
  100% { transform: translate(0, 0); opacity: 0.4; }
}

.orchard-silhouette {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 35%;
  background:
    radial-gradient(circle at 15% 100%, rgba(20,10,40,0.9) 0%, rgba(20,10,40,0.9) 12%, transparent 13%),
    radial-gradient(circle at 35% 100%, rgba(20,10,40,0.9) 0%, rgba(20,10,40,0.9) 15%, transparent 16%),
    radial-gradient(circle at 60% 100%, rgba(20,10,40,0.9) 0%, rgba(20,10,40,0.9) 14%, transparent 15%),
    radial-gradient(circle at 82% 100%, rgba(20,10,40,0.9) 0%, rgba(20,10,40,0.9) 13%, transparent 14%),
    linear-gradient(to top, #120a28 0%, rgba(18,10,40,0) 100%);
  pointer-events: none;
}

.opening-content {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 20px;
  text-align: center;
}

.game-title {
  font-size: clamp(28px, 7vw, 52px);
  color: #ffe066;
  text-shadow:
    0 0 12px rgba(255, 224, 102, 0.8),
    0 0 24px rgba(255, 160, 60, 0.6),
    2px 2px 0 #7a3b00;
  animation: titleBounce 2s ease-in-out infinite;
}

@keyframes titleBounce {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-8px) rotate(1deg); }
}

.game-subtitle {
  font-size: clamp(16px, 3.5vw, 22px);
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255,255,255,0.5);
}

.fruit-preview-row {
  display: flex;
  gap: 10px;
  margin: 10px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.preview-fruit {
  width: clamp(45px, 10vw, 70px);
  height: clamp(45px, 10vw, 70px);
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(255, 224, 102, 0.5));
  animation: previewFloat 3s ease-in-out infinite;
}

.preview-fruit:nth-child(2) { animation-delay: 0.2s; }
.preview-fruit:nth-child(3) { animation-delay: 0.4s; }
.preview-fruit:nth-child(4) { animation-delay: 0.6s; }
.preview-fruit:nth-child(5) { animation-delay: 0.8s; }

@keyframes previewFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.btn-play {
  margin-top: 14px;
  padding: 16px 46px;
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: bold;
  color: #4a2600;
  background: linear-gradient(180deg, #ffe066 0%, #ffb703 60%, #fb8500 100%);
  border: 4px solid #fff3cd;
  border-radius: 50px;
  cursor: pointer;
  box-shadow:
    0 6px 0 #b45f04,
    0 10px 20px rgba(0,0,0,0.4),
    0 0 30px rgba(255, 183, 3, 0.6);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  animation: playPulse 1.6s ease-in-out infinite;
}

@keyframes playPulse {
  0%, 100% { box-shadow: 0 6px 0 #b45f04, 0 10px 20px rgba(0,0,0,0.4), 0 0 30px rgba(255,183,3,0.6); }
  50% { box-shadow: 0 6px 0 #b45f04, 0 10px 24px rgba(0,0,0,0.4), 0 0 50px rgba(255,183,3,0.9); }
}

.btn-play:active {
  transform: translateY(6px);
  box-shadow:
    0 0 0 #b45f04,
    0 4px 10px rgba(0,0,0,0.4),
    0 0 30px rgba(255, 183, 3, 0.6);
}

/* ============================================================
   GAME SCREEN
   ============================================================ */

#game-screen {
  background: #0f1f3d;
}

.game-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at top, #2a5aa0 0%, #163a6e 45%, #0a1f42 100%);
  z-index: 0;
}

.game-bg::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 22%;
  background: linear-gradient(to top, #1b6b3a 0%, #2e8b4f 60%, rgba(46,139,79,0) 100%);
}

.hud {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 12px;
  gap: 8px;
}

.hud-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  border: 3px solid rgba(255,255,255,0.4);
  border-radius: 18px;
  padding: 6px 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.hud-label {
  font-size: clamp(10px, 2.2vw, 13px);
  color: #ffffff;
  font-weight: bold;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.4);
}

.hud-value {
  font-size: clamp(20px, 5vw, 30px);
  font-weight: bold;
  color: #ffe066;
  text-shadow: 1px 2px 3px rgba(0,0,0,0.5);
}

.target-box {
  background: rgba(255, 183, 3, 0.35);
  border-color: #ffe066;
  transform: scale(1.08);
}

.target-number {
  font-size: clamp(28px, 7vw, 42px);
  color: #ffffff;
  animation: targetPulse 1.2s ease-in-out infinite;
}

@keyframes targetPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.fruit-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
}

.flying-fruit {
  position: absolute;
  width: 90px;
  height: 90px;
  cursor: pointer;
  will-change: transform;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.35));
  touch-action: manipulation;
}

.flying-fruit img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.flying-fruit.wobble {
  animation: fruitWobble 2.4s ease-in-out infinite;
}

@keyframes fruitWobble {
  0%, 100% { margin-left: 0; }
  25% { margin-left: 14px; }
  75% { margin-left: -14px; }
}

.flying-fruit.popping {
  animation: fruitPop 0.4s ease forwards;
  pointer-events: none;
}

@keyframes fruitPop {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  60% { transform: scale(1.4) rotate(15deg); opacity: 0.9; }
  100% { transform: scale(0) rotate(30deg); opacity: 0; }
}

.flying-fruit.shaking {
  animation: fruitShake 0.5s ease;
}

@keyframes fruitShake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-10px) rotate(-8deg); }
  40% { transform: translateX(10px) rotate(8deg); }
  60% { transform: translateX(-8px) rotate(-6deg); }
  80% { transform: translateX(8px) rotate(6deg); }
}

.sparkle-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 6;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  animation: sparklePop 0.7s ease forwards;
}

@keyframes sparklePop {
  0% { transform: translate(0, 0) scale(0.4) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.3) rotate(180deg); opacity: 0; }
}

.feedback-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 7;
  pointer-events: none;
}

.score-float {
  position: absolute;
  font-size: 26px;
  font-weight: bold;
  color: #7CFC00;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.6);
  animation: floatUpFade 0.9s ease forwards;
}

@keyframes floatUpFade {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-70px); opacity: 0; }
}

.wrong-mark {
  position: absolute;
  font-size: 30px;
  animation: floatUpFade 0.7s ease forwards;
}

.level-up-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 10;
  background: linear-gradient(135deg, #ffe066, #ff9f1c);
  border: 5px solid #fff;
  border-radius: 30px;
  padding: 20px 40px;
  box-shadow: 0 0 40px rgba(255, 224, 102, 0.9);
}

.level-up-banner span {
  font-size: clamp(24px, 6vw, 40px);
  font-weight: bold;
  color: #7a3b00;
  text-shadow: 1px 1px 0 #fff;
}

.level-up-banner.show {
  animation: levelUpAnim 1.6s ease forwards;
}

@keyframes levelUpAnim {
  0% { transform: translate(-50%, -50%) scale(0) rotate(-10deg); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2) rotate(5deg); opacity: 1; }
  35% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.6) rotate(0deg); opacity: 0; }
}

/* ============================================================
   END SCREEN
   ============================================================ */

#end-screen {
  background: radial-gradient(ellipse at top, #1b1140 0%, #0a0620 55%, #05030f 100%);
}

.end-content {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  text-align: center;
}

.end-title {
  font-size: clamp(30px, 7vw, 50px);
  color: #ffe066;
  text-shadow: 0 0 15px rgba(255, 224, 102, 0.9), 2px 2px 0 #7a3b00;
  animation: titleBounce 1.6s ease-in-out infinite;
}

.end-sub {
  font-size: clamp(15px, 3.5vw, 20px);
  color: #ffffff;
}

.final-score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.15);
  border: 3px solid #ffe066;
  border-radius: 20px;
  padding: 16px 40px;
  margin-top: 10px;
}

.final-score-label {
  font-size: 16px;
  color: #fff;
  font-weight: bold;
}

.final-score-value {
  font-size: clamp(36px, 9vw, 56px);
  color: #ffe066;
  font-weight: bold;
  text-shadow: 0 0 12px rgba(255,224,102,0.8);
}

.stars-earned {
  display: flex;
  gap: 12px;
  margin: 6px 0;
}

.star-icon {
  font-size: clamp(30px, 7vw, 46px);
  opacity: 0.25;
  transform: scale(0.6);
  transition: all 0.4s ease;
}

.star-icon.earned {
  opacity: 1;
  transform: scale(1.15);
  filter: drop-shadow(0 0 10px rgba(255, 224, 102, 0.9));
  animation: starPop 0.5s ease;
}

@keyframes starPop {
  0% { transform: scale(0); }
  60% { transform: scale(1.4); }
  100% { transform: scale(1.15); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 480px) {
  .flying-fruit {
    width: 72px;
    height: 72px;
  }
  .hud-box {
    padding: 4px 2px;
  }
}

@media (min-width: 900px) {
  .flying-fruit {
    width: 110px;
    height: 110px;
  }
}

/* ============================================================
   MUSIC MUTE TOGGLE
   ============================================================ */

.mute-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 999;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255, 224, 130, 0.85);
  background: rgba(20, 14, 40, 0.55);
  color: #ffe082;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(3px);
  box-shadow: 0 0 12px rgba(255, 200, 80, 0.35);
  transition: transform 0.15s ease, background 0.2s ease;
}

.mute-btn:active {
  transform: scale(0.9);
}

.mute-btn.muted {
  color: #9aa0b0;
  border-color: rgba(154, 160, 176, 0.6);
  box-shadow: none;
}
