* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Segoe UI', 'Comic Sans MS', cursive, sans-serif;
  background: linear-gradient(180deg, #87ceeb 0%, #c9ecff 55%, #7fd67f 55%, #4fae4f 100%);
  color: #2c2c2c;
}

.hidden { display: none !important; }

/* ---------- Screens ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  background: #fffdf5;
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  border: 4px solid #ffd166;
}

.big-emoji { font-size: 90px; line-height: 1.1; margin-bottom: 10px; }

h1 { margin: 6px 0 10px; color: #e76f51; font-size: 2.2rem; }
h2 { color: #e76f51; margin: 0 0 12px; }
p.story { line-height: 1.6; }
.cutscene-text { font-size: 1.2rem; line-height: 1.6; min-height: 60px; }

#cutsceneEmoji {
  display: inline-block;
  animation: emoji3d 2.5s ease-in-out infinite;
}
@keyframes emoji3d {
  0%, 100% { transform: perspective(600px) rotateY(-18deg) translateZ(0); }
  50% { transform: perspective(600px) rotateY(18deg) translateZ(40px); }
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 40px;
  padding: 14px 26px;
  cursor: pointer;
  color: #fff;
  background: #f4a261;
  box-shadow: 0 4px 0 #d07f3f;
  transition: transform .1s, box-shadow .1s, filter .2s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d07f3f; }
.btn.primary { background: #2a9d8f; box-shadow: 0 4px 0 #1f756a; }
.btn.task {
  background: #e9c46a;
  color: #5a3a1a;
  box-shadow: 0 4px 0 #c9a74f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.ready {
  background: #2a9d8f;
  color: #fff;
  box-shadow: 0 4px 0 #1f756a;
  animation: glow 1.2s ease-in-out infinite;
}
.count { background: #fff; border-radius: 30px; padding: 4px 12px; font-size: .9rem; }
.status { margin-top: 14px; font-size: 1.05rem; font-weight: 600; }
.goal { font-size: 1.1rem; font-weight: 600; color: #1f5c57; }
.owned { color: #8a6d3b; font-weight: 600; }
.goal-done { color: #2a9d8f; font-weight: 700; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.shake { animation: shake .35s; }
@keyframes glow {
  0%, 100% { box-shadow: 0 4px 0 #1f756a; }
  50% { box-shadow: 0 4px 20px #2a9d8f; }
}

/* ---------- Stage layout ---------- */
#game { padding: 20px; perspective: 1400px; }
.stage {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

/* ---------- Scenes ---------- */
.scene {
  position: relative;
  width: 100%;
  border-radius: 20px;
  overflow: visible;
  transform: rotateX(8deg);
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
  perspective: 900px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .35), inset 0 0 40px rgba(0, 0, 0, .08);
  border: 4px solid #e0c68c;
}
.scene::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .14));
  border-radius: 0 0 16px 16px;
  pointer-events: none;
  z-index: 4;
}

.house-scene { height: 340px; }
.wall {
  position: absolute;
  inset: 0 0 64px 0;
  background: linear-gradient(180deg, #f7e3c3, #eed0a0);
  border-radius: 16px 16px 0 0;
}
.floor {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: linear-gradient(180deg, #c98a4b, #a8693a);
  border-top: 4px solid #8b5a2b;
  border-radius: 0 0 16px 16px;
}

.deco { position: absolute; font-size: 42px; }
.clock { top: 18px; left: 20px; transform: translateZ(10px); }
.painting { top: 16px; left: 50%; transform: translateX(-50%) translateZ(25px); font-size: 48px; }
.plant { top: 160px; left: 16px; font-size: 54px; transform: translateZ(35px); }
.rug { bottom: 8px; left: 42%; font-size: 50px; transform: translateZ(15px); }
.sofa { position: absolute; bottom: 18px; left: 30%; font-size: 70px; transform: translateZ(20px); }
.granny {
  position: absolute;
  bottom: 18px;
  left: 6%;
  font-size: 80px;
  cursor: pointer;
  animation: bob3d 3s ease-in-out infinite;
}
@keyframes bob3d {
  0%, 100% { transform: translateZ(60px) translateY(0) rotateY(-2deg); }
  50% { transform: translateZ(60px) translateY(-8px) rotateY(2deg); }
}
.cat {
  position: absolute;
  bottom: 20px;
  left: 44%;
  font-size: 46px;
  animation: bounce 2s ease-in-out infinite;
  cursor: pointer;
}
@keyframes bounce {
  0%, 100% { transform: translateZ(70px) translateY(0); }
  50% { transform: translateZ(70px) translateY(-10px); }
}

.granny, .cat, .elephant, .sofa, .door, .brother {
  text-shadow: 0 3px 0 rgba(0, 0, 0, .15), 0 6px 8px rgba(0, 0, 0, .22);
}
.granny::after, .cat::after, .elephant::after, .sofa::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: 70%;
  height: 14px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .4), transparent 70%);
  filter: blur(2px);
}

.door {
  position: absolute;
  right: 6%;
  bottom: 18px;
  font-size: 78px;
  border: none;
  background: none;
  cursor: pointer;
  transform: translateZ(60px);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3));
  transition: transform .2s;
}
.door:hover { transform: translateZ(80px) scale(1.15) rotate(-3deg); }

.speech-bubble {
  position: absolute;
  top: 12px;
  right: 16%;
  background: #fff;
  border: 3px solid #333;
  border-radius: 16px;
  padding: 10px 14px;
  max-width: 300px;
  font-weight: 600;
  font-size: .95rem;
  transform: translateZ(40px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .15);
}
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -14px;
  left: 30px;
  border: 8px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
}

/* ---------- Elephant scene ---------- */
.elephant-scene {
  height: 320px;
  background: linear-gradient(180deg, #a5d8ff 0%, #c9ecff 55%, #8fd684 55%, #4fae4f 100%);
}
.cage {
  position: absolute;
  left: 10%;
  bottom: 60px;
  width: 130px;
  height: 150px;
  border: 6px solid #a87b2f;
  border-radius: 12px;
  background: rgba(0, 0, 0, .12);
  z-index: 3;
  transform: translateZ(40px);
  transition: all .4s;
}
.cage .bar { position: absolute; top: 0; bottom: 0; width: 5px; background: #a87b2f; }
.b1 { left: 20%; }
.b2 { left: 48%; }
.b3 { left: 76%; }
.brother { font-size: 62px; text-align: center; line-height: 150px; }
.cage.freed { border-color: #4caf50; background: rgba(76, 175, 80, .2); transform: translateZ(40px) scale(1.05); }
.cage.freed::after { content: '🔓'; position: absolute; top: -12px; right: -12px; font-size: 30px; }
.elephant {
  position: absolute;
  right: 12%;
  bottom: 45px;
  font-size: 130px;
  transform: translateZ(90px);
  animation: sway 3s ease-in-out infinite;
}
@keyframes sway {
  0%, 100% { transform: translateZ(90px) rotate(0deg); }
  50% { transform: translateZ(90px) rotate(6deg); }
}
.elephant-speech { left: 12px; right: auto; }

/* ---------- Panel ---------- */
.panel {
  background: #fffdf5;
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 640px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  border: 3px solid #ffd166;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ---------- City ---------- */
.city-header { text-align: center; }
.places { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.place-card {
  background: #fffdf5;
  border: 3px solid #ffd166;
  border-radius: 18px;
  padding: 18px;
  width: 150px;
  cursor: pointer;
  text-align: center;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
  font-family: inherit;
}
.place-card:hover { transform: translateY(-6px) scale(1.03); box-shadow: 0 12px 24px rgba(0, 0, 0, .2); }
.place-icon { font-size: 56px; }
.place-name { font-weight: 700; margin-top: 8px; }
.place-card.home { border-color: #e76f51; animation: glow 1.2s ease-in-out infinite; }

/* ---------- City scene (3D) ---------- */
.city-scene {
  height: 360px;
  background: linear-gradient(180deg, #6ec6ff 0%, #aee4ff 42%, #6aa84f 42%, #4f9e4f 100%);
}
.city-sky {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .35), transparent 60%);
}
.skyline-building { position: absolute; top: 6%; font-size: 64px; opacity: .28; z-index: 1; }
.s1 { left: 5%; }
.s2 { left: 28%; font-size: 84px; }
.s3 { left: 56%; font-size: 72px; }
.s4 { left: 80%; font-size: 58px; }
.city-road {
  position: absolute;
  left: 18%; right: 18%; top: 30%; bottom: 0;
  background: linear-gradient(180deg, #b6b6b6, #6f6f6f);
  clip-path: polygon(49% 0%, 51% 0%, 80% 100%, 20% 100%);
  z-index: 2;
}
.city-lane {
  position: absolute;
  left: 50%; top: 30%; bottom: 0;
  width: 6px;
  transform: translateX(-50%);
  background: repeating-linear-gradient(180deg, #fff 0 18px, transparent 18px 34px);
  opacity: .85;
  z-index: 2;
}
.monkey-duo {
  position: absolute;
  left: 46%; bottom: 2%;
  font-size: 56px;
  display: flex;
  gap: 2px;
  transform: translateZ(120px);
  z-index: 6;
  cursor: pointer;
}
.monkey-duo .mc { text-shadow: 0 3px 0 rgba(0, 0, 0, .18), 0 6px 8px rgba(0, 0, 0, .25); }
.monkey-duo .mbrother { font-size: 44px; align-self: flex-end; }
.city-buildings {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  z-index: 5;
  pointer-events: none;
}
.c-building {
  position: absolute;
  border: 3px solid #ffd166;
  border-radius: 14px;
  padding: 6px 8px;
  width: 96px;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 253, 245, .94);
  cursor: pointer;
  pointer-events: auto;
  color: #3a2a1a;
  box-shadow: 0 10px 18px rgba(0, 0, 0, .28);
  transform: translateZ(var(--dz, 40px));
  transition: transform .15s, box-shadow .15s;
}
.c-building:hover {
  transform: translateZ(var(--dz, 40px)) scale(1.12);
  box-shadow: 0 14px 24px rgba(0, 0, 0, .35);
}
.c-building .build-icon { display: block; font-size: 44px; line-height: 1.1; }
.c-building .build-name { display: block; margin-top: 2px; }
.b-market { --dz: 40px; left: 4%; bottom: 12%; }
.b-bakery { --dz: 80px; left: 26%; bottom: 32%; }
.b-park { --dz: 30px; left: 54%; bottom: 24%; }
.b-fountain { --dz: 60px; left: 76%; bottom: 10%; }
.b-home {
  --dz: 110px;
  left: 38%;
  bottom: 46%;
  border-color: #e76f51;
  animation: glow 1.2s ease-in-out infinite;
}

.loc-card {
  background: #fffdf5;
  border: 3px solid #ffd166;
  border-radius: 18px;
  padding: 24px;
  max-width: 560px;
  margin: 20px auto;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  animation: locpop .45s ease-out;
}
@keyframes locpop {
  from {
    transform: perspective(800px) rotateX(18deg) translateY(40px) scale(.9);
    opacity: 0;
  }
  to {
    transform: perspective(800px) rotateX(0deg) translateY(0) scale(1);
    opacity: 1;
  }
}
.loc-card h3 { margin-top: 0; color: #e76f51; }
.loc-card button { margin: 8px; }
.back-btn { background: #ccc !important; color: #333 !important; box-shadow: 0 4px 0 #aaa !important; }

/* ---------- Overlay & minigames ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 40, .75);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay-box {
  background: #fffdf5;
  border-radius: 22px;
  padding: 20px;
  text-align: center;
  max-width: 640px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .4);
  border: 4px solid #ffd166;
}
.overlay-box h2 { margin-top: 0; }
.close-btn {
  margin-top: 12px;
  background: #e0e0e0;
  color: #333;
  border: none;
  border-radius: 30px;
  padding: 10px 20px;
  font-weight: 700;
  cursor: pointer;
}

.balloon-area {
  position: relative;
  height: 340px;
  border-radius: 16px;
  background: linear-gradient(180deg, #a5d8ff, #7fbff0 55%, #6aa84f 55%, #4f9e4f 100%);
  overflow: hidden;
  border: 3px solid #ddd;
  perspective: 500px;
  transform-style: preserve-3d;
}
.balloon {
  position: absolute;
  width: 46px;
  height: 58px;
  bottom: 12%;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, .55), transparent 42%),
    hsl(var(--hue), 78%, 58%);
  cursor: pointer;
  animation: float 5s ease-in-out infinite;
  transform: translateZ(var(--depth, 40px));
  z-index: 2;
  box-shadow: inset -4px -6px 10px rgba(0, 0, 0, .15);
}
.balloon::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 2px;
  height: 46px;
  background: rgba(0, 0, 0, .3);
}
@keyframes float {
  0%, 100% { transform: translateZ(var(--depth, 40px)) translateY(0); }
  50% { transform: translateZ(var(--depth, 40px)) translateY(-38px); }
}
.balloon.popped { animation: pop .3s forwards; }
@keyframes pop {
  0% { transform: translateZ(var(--depth, 40px)) scale(1); opacity: 1; }
  100% { transform: translateZ(var(--depth, 40px)) scale(1.8); opacity: 0; }
}

.mole-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  perspective: 700px;
}
.hole {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 100%, #2a1a0c 0%, #6b4a2f 55%, transparent 68%);
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  box-shadow: inset 0 14px 20px rgba(0, 0, 0, .5), inset 0 -4px 8px rgba(0, 0, 0, .3);
}
.mole {
  position: absolute;
  left: 50%;
  bottom: -90%;
  transform: translateX(-50%) scale(.45);
  width: 62%;
  height: 80%;
  transition: bottom .25s ease-out, transform .25s ease-out;
  cursor: pointer;
  border-radius: 48% 48% 42% 42%;
  background: radial-gradient(circle at 50% 35%, #a06a38, #5a3a1a 75%);
  transform-origin: 50% 100%;
}
.mole.up {
  bottom: 4%;
  transform: translateX(-50%) scale(1);
  z-index: 3;
}
.mole::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  height: 14px;
  background: rgba(0, 0, 0, .4);
  border-radius: 50%;
  filter: blur(3px);
}
.mole.hit { filter: brightness(1.6) saturate(1.4); }
.mole .eye { position: absolute; top: 34%; width: 9px; height: 12px; background: #222; border-radius: 50%; }
.mole .eye.l { left: 24%; }
.mole .eye.r { right: 24%; }
.mole .nose {
  position: absolute;
  top: 52%;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 9px;
  background: #e05d5d;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

.catch-area {
  position: relative;
  height: 360px;
  border-radius: 16px;
  background: linear-gradient(180deg, #a5d8ff, #c9ecff 55%, #7fd67f 55%, #5cb85c 100%);
  border: 3px solid #ddd;
  overflow: hidden;
}
.basket {
  position: absolute;
  bottom: 6px;
  font-size: 52px;
  transform: translateX(-50%);
  pointer-events: none;
  transition: left .05s;
  z-index: 5;
  filter: drop-shadow(0 10px 8px rgba(0, 0, 0, .3));
}
.falling-banana {
  position: absolute;
  font-size: 36px;
  z-index: 4;
  top: 0;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .25));
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
  perspective: 800px;
}
.m-card {
  position: relative;
  height: 84px;
  border-radius: 12px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .3s;
}
.m-card.flipped { transform: rotateY(180deg); }
.m-card .m-back, .m-card .m-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  backface-visibility: hidden;
  font-size: 34px;
}
.m-back {
  background: linear-gradient(135deg, #f4a261, #e76f51);
  color: #fff;
  font-weight: 800;
  box-shadow: inset 0 -10px 16px rgba(0, 0, 0, .2), 0 4px 8px rgba(0, 0, 0, .15);
}
.m-face {
  background: #fff;
  border: 2px solid #ffd166;
  transform: rotateY(180deg) translateZ(24px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, .15);
}
.m-card.matched .m-face { background: #c8f7c5; border-color: #4caf50; }
.m-card.matched { cursor: default; }

/* ---------- Win screen confetti ---------- */
#winScreen { position: relative; overflow: hidden; }
.win-card { position: relative; z-index: 1; }
.win-house {
  font-size: 88px;
  line-height: 1.1;
  animation: housefloat 2.5s ease-in-out infinite;
  filter: drop-shadow(0 14px 10px rgba(0, 0, 0, .25));
}
@keyframes housefloat {
  0%, 100% { transform: perspective(600px) rotateX(0deg) translateY(0); }
  50% { transform: perspective(600px) rotateX(20deg) translateY(-12px); }
}
.confetti {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: fall linear infinite;
  z-index: 0;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}
