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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #87ceeb;
}

.hidden {
  display: none !important;
}

/* ===== Game Stage & Scenery ===== */
.game-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

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

.sky {
  position: absolute;
  inset: 0 0 42% 0;
  background: linear-gradient(180deg, #38bdf8 0%, #bae6fd 65%, #fef9c3 100%);
}

.sun {
  position: absolute;
  top: 5%;
  left: 16%;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: radial-gradient(circle, #fef08a 20%, #facc15 70%, rgba(250, 204, 21, 0) 100%);
  box-shadow: 0 0 40px rgba(250, 204, 21, 0.7);
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 50px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05));
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  top: 8%;
  left: 30%;
  width: 130px;
  height: 44px;
  animation: drift 36s linear infinite;
}
.cloud-1::before { width: 64px; height: 64px; top: -28px; left: 20px; }
.cloud-1::after { width: 48px; height: 48px; top: -18px; right: 20px; }

.cloud-2 {
  top: 14%;
  right: 22%;
  width: 100px;
  height: 36px;
  opacity: 0.85;
  animation: drift 48s linear infinite reverse;
}
.cloud-2::before { width: 48px; height: 48px; top: -22px; left: 16px; }
.cloud-2::after { width: 38px; height: 38px; top: -14px; right: 14px; }

@keyframes drift {
  0% { transform: translateX(-20px); }
  50% { transform: translateX(30px); }
  100% { transform: translateX(-20px); }
}

.hills {
  position: absolute;
  bottom: 38%;
  left: -10%;
  right: -10%;
  height: 140px;
  background: radial-gradient(ellipse at 25% 100%, #a3e635 0%, #84cc16 60%, transparent 61%),
              radial-gradient(ellipse at 75% 100%, #bef264 0%, #65a30d 62%, transparent 63%);
}

.meadow {
  position: absolute;
  inset: 52% 0 0 0;
  background: linear-gradient(180deg, #a3e635 0%, #65a30d 45%, #4d7c0f 100%);
}

.pond {
  position: absolute;
  bottom: -4%;
  left: 14%;
  width: 48%;
  height: 17%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, #7dd3fc 0%, #0ea5e9 65%, #0284c7 100%);
  border: 6px solid #84cc16;
  box-shadow: inset 0 6px 14px rgba(255, 255, 255, 0.5);
}

/* ===== Extra Random Background Themes ===== */
/* 2. Ocean / Underwater */
.scenery.theme-ocean .sky {
  inset: 0 0 22% 0;
  background: linear-gradient(180deg, #0284c7 0%, #0ea5e9 45%, #38bdf8 100%);
}
.scenery.theme-ocean .sun {
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 110px;
  background: radial-gradient(circle, rgba(255,255,255,0.9) 10%, rgba(186,230,253,0.4) 55%, rgba(56,189,248,0) 100%);
  box-shadow: 0 0 60px rgba(255,255,255,0.6);
}
.scenery.theme-ocean .cloud {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 34px;
  height: 34px;
}
.scenery.theme-ocean .cloud::before { width: 18px; height: 18px; top: -26px; left: 26px; }
.scenery.theme-ocean .cloud::after { width: 12px; height: 12px; top: 24px; right: -16px; }
.scenery.theme-ocean .hills {
  bottom: 18%;
  background: radial-gradient(ellipse at 25% 100%, #0369a1 0%, #0284c7 60%, transparent 61%),
              radial-gradient(ellipse at 75% 100%, #075985 0%, #0369a1 62%, transparent 63%);
}
.scenery.theme-ocean .meadow {
  inset: 76% 0 0 0;
  background: linear-gradient(180deg, #fde68a 0%, #f59e0b 100%);
}
.scenery.theme-ocean .pond { display: none; }

/* 3. Starry Night */
.scenery.theme-night .sky {
  background: linear-gradient(180deg, #0f172a 0%, #1e1b4b 60%, #312e81 100%);
}
.scenery.theme-night .sun {
  top: 7%;
  left: 72%;
  width: 68px;
  height: 68px;
  background: radial-gradient(circle, #fef9c3 30%, #fde047 80%, rgba(253,224,71,0) 100%);
  box-shadow: 0 0 36px rgba(254, 240, 138, 0.85);
}
.scenery.theme-night .cloud {
  background: rgba(199, 210, 254, 0.22);
}
.scenery.theme-night .hills {
  background: radial-gradient(ellipse at 25% 100%, #312e81 0%, #1e1b4b 60%, transparent 61%),
              radial-gradient(ellipse at 75% 100%, #4338ca 0%, #312e81 62%, transparent 63%);
}
.scenery.theme-night .meadow {
  background: linear-gradient(180deg, #1e3a8a 0%, #172554 100%);
}
.scenery.theme-night .pond {
  border-color: #3730a3;
  background: radial-gradient(ellipse at center, #60a5fa 0%, #1d4ed8 70%, #1e3a8a 100%);
}

/* 4. Warm Sunset */
.scenery.theme-sunset .sky {
  background: linear-gradient(180deg, #fb7185 0%, #fdba74 55%, #fef08a 100%);
}
.scenery.theme-sunset .sun {
  top: 22%;
  left: 48%;
  width: 96px;
  height: 96px;
  background: radial-gradient(circle, #fff7ed 20%, #fb923c 70%, rgba(251,146,60,0) 100%);
}
.scenery.theme-sunset .cloud {
  background: rgba(255, 237, 213, 0.78);
}
.scenery.theme-sunset .hills {
  background: radial-gradient(ellipse at 25% 100%, #c084fc 0%, #a855f7 60%, transparent 61%),
              radial-gradient(ellipse at 75% 100%, #e879f9 0%, #9333ea 62%, transparent 63%);
}
.scenery.theme-sunset .meadow {
  background: linear-gradient(180deg, #84cc16 0%, #4d7c0f 100%);
}

/* 5. Candy Pastel Park */
.scenery.theme-candy .sky {
  background: linear-gradient(180deg, #f472b6 0%, #fbcfe8 55%, #fef9c3 100%);
}
.scenery.theme-candy .sun {
  top: 8%;
  left: 20%;
  background: radial-gradient(circle, #ffffff 25%, #fde047 75%, rgba(253,224,71,0) 100%);
}
.scenery.theme-candy .hills {
  background: radial-gradient(ellipse at 25% 100%, #6ee7b7 0%, #34d399 60%, transparent 61%),
              radial-gradient(ellipse at 75% 100%, #5eead4 0%, #2dd4bf 62%, transparent 63%);
}
.scenery.theme-candy .meadow {
  background: linear-gradient(180deg, #34d399 0%, #059669 100%);
}
.scenery.theme-candy .pond {
  border-color: #6ee7b7;
  background: radial-gradient(ellipse at center, #a5f3fc 0%, #22d3ee 70%, #0891b2 100%);
}

/* ===== Top HUD ===== */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  pointer-events: none;
}

.hud-end {
  justify-content: flex-end;
}

.hud-btn {
  pointer-events: auto;
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid #fff8e1;
  background: radial-gradient(circle at 30% 30%, #d97706, #92400e);
  box-shadow: 0 6px 0 #78350f, 0 10px 18px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}

.hud-btn:active {
  transform: translateY(3px) scale(0.96);
  box-shadow: 0 3px 0 #78350f, 0 5px 10px rgba(0, 0, 0, 0.25);
}

.hud-right-group {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.hud-btn-sm {
  width: 54px;
  height: 54px;
}

.hud-btn-sm.muted {
  opacity: 0.7;
  filter: grayscale(0.5);
}

.hud-emoji {
  font-size: 26px;
  line-height: 1;
}

.hud-icon {
  width: 40px;
  height: 40px;
}

.hud-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  background: #ef4444;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.hud-center {
  pointer-events: auto;
}

.level-pill {
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #f59e0b;
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 17px;
  font-weight: 800;
  color: #78350f;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-pill .dot {
  color: #f59e0b;
}

/* ===== Playfield ===== */
.playfield {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.board-wrapper {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.28));
}

.board-wrapper canvas {
  display: block;
}

.completed-canvas {
  position: absolute;
  inset: 0;
  cursor: pointer;
  animation: pop-celebrate 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.completed-canvas.gin-pulse {
  animation: gin-bounce 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-celebrate {
  0% { transform: scale(0.92); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes gin-bounce {
  0% { transform: scale(1); }
  45% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.pieces-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.puzzle-piece {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.38));
  transform: scale(0.95);
  transform-origin: top left;
  transition: transform 0.16s ease, filter 0.14s ease;
  will-change: left, top, transform;
}

.puzzle-piece.dragging {
  cursor: grabbing;
  transform: scale(1.02);
  filter: drop-shadow(0 16px 22px rgba(0, 0, 0, 0.4));
  z-index: 100 !important;
  transition: transform 0.12s ease;
}

.puzzle-piece.snapped {
  cursor: default;
  pointer-events: none;
  filter: none;
  transform: scale(1);
  transition: left 0.18s cubic-bezier(0.22, 1, 0.36, 1),
              top 0.18s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.18s ease;
}

.puzzle-piece.returning {
  transition: left 0.28s cubic-bezier(0.22, 1, 0.36, 1),
              top 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 150;
}

.quick-upload-btn {
  position: absolute;
  bottom: 16px;
  right: 18px;
  z-index: 25;
  padding: 10px 18px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 5px 0 #9a3412, 0 8px 16px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.quick-upload-btn:active {
  transform: translateY(2px);
}

/* ===== Win Banner (Speech Learning + Open Eggs) ===== */
.win-banner {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: min(92vw, 680px);
  animation: pop-celebrate 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.speak-pill {
  padding: 12px 20px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 0 #1d4ed8, 0 10px 18px rgba(0, 0, 0, 0.25);
}

.open-eggs-pill {
  padding: 12px 22px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #92400e, 0 10px 18px rgba(0, 0, 0, 0.25);
  animation: float-hint 1.5s ease-in-out infinite;
}

/* ===== Multi-Egg Reward Overlay ===== */
.egg-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.egg-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
}

.egg-stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 780px;
  width: 100%;
  animation: egg-enter 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes egg-enter {
  0% { transform: scale(0.3) translateY(60px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.egg-hint {
  background: #fffbeb;
  color: #92400e;
  border: 3px solid #fbbf24;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 19px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  animation: float-hint 1.8s ease-in-out infinite;
}

@keyframes float-hint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.eggs-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.egg-card {
  position: relative;
  width: 124px;
  height: 152px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  transition: transform 0.12s ease;
}

.egg-card.falling {
  animation: egg-fall-from-sky 0.72s cubic-bezier(0.22, 1.28, 0.36, 1) both;
}

@keyframes egg-fall-from-sky {
  0% {
    transform: translateY(-75vh) scale(0.8) rotate(-10deg);
    opacity: 0;
  }
  70% {
    transform: translateY(12px) scale(1.04) rotate(4deg);
    opacity: 1;
  }
  88% {
    transform: translateY(-6px) scale(0.98) rotate(-2deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
    opacity: 1;
  }
}

.egg-card:active {
  transform: scale(0.93);
}

.egg-svg {
  position: relative;
  width: 110px;
  height: 132px;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.35));
  animation: egg-wobble 2s ease-in-out infinite;
  transform-origin: center 80%;
}

.egg-card.cracking .egg-svg {
  animation: egg-shake 0.32s ease-in-out;
}

.egg-card.exploded .egg-svg {
  animation: egg-explode 0.36s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.egg-tap-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: #b45309;
  font-size: 12px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid #f59e0b;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

@keyframes egg-wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

@keyframes egg-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-9px) rotate(-11deg); }
  50% { transform: translateX(9px) rotate(11deg); }
  75% { transform: translateX(-6px) rotate(-7deg); }
}

@keyframes egg-explode {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.28); opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}

.hatched-surprise {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: surprise-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes surprise-pop {
  0% { transform: scale(0.2) rotate(-14deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.surprise-emoji {
  font-size: 76px;
  line-height: 1;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}

.surprise-label {
  font-size: 13px;
  font-weight: 800;
  color: #fef08a;
  text-shadow: 0 2px 0 #78350f;
}

.egg-footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.next-level-btn {
  padding: 15px 34px;
  border-radius: 999px;
  border: 4px solid #fff;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #15803d, 0 14px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease;
  animation: pop-celebrate 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.next-level-btn:active {
  transform: translateY(3px);
  box-shadow: 0 4px 0 #15803d;
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  background: #fffbeb;
  border: 5px solid #f59e0b;
  border-radius: 26px;
  padding: 22px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.modal-card-sm {
  max-width: 440px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  color: #78350f;
  font-size: 22px;
  font-weight: 900;
}

.modal-close {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #fde68a;
  color: #78350f;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
}

.modal-desc {
  color: #92400e;
  font-size: 14px;
  line-height: 1.45;
}

.gallery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-btn {
  padding: 11px 18px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #9a3412;
}

.secondary-btn {
  padding: 11px 18px;
  border-radius: 14px;
  border: 2px solid #f59e0b;
  background: #fef3c7;
  color: #78350f;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 4px;
}

.gallery-item {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 4px solid #fcd34d;
  background: #fff;
  aspect-ratio: 4 / 3;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.gallery-item:hover {
  transform: scale(1.03);
}

.gallery-item.active-photo {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.35);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.gallery-delete {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(239, 68, 68, 0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.gallery-edit {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(59, 130, 246, 0.92);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

/* Settings */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #fef3c7;
  border-radius: 14px;
  color: #78350f;
  font-weight: 700;
  font-size: 15px;
}

.setting-select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #f59e0b;
  background: #fff;
  color: #78350f;
  font-weight: 700;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.25s;
  border-radius: 28px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s;
  border-radius: 50%;
}
input:checked + .slider { background-color: #22c55e; }
input:checked + .slider:before { transform: translateX(22px); }

@media (max-width: 640px) {
  .hud-btn { width: 52px; height: 52px; }
  .hud-icon { width: 32px; height: 32px; }
  .level-pill { font-size: 14px; padding: 6px 14px; }
  .quick-upload-btn { font-size: 13px; padding: 8px 14px; bottom: 10px; right: 10px; }
}
