:root {
  --game-bg: linear-gradient(180deg, #dcedc8 0%, #c5e1a5 35%, #aed581 65%, #8bc34a 100%);
  --turtle-skin: #8bc34a;
  --turtle-skin-dark: #689f38;
  --shell-outer: #558b2f;
  --shell-inner: #7cb342;
  --shell-dark: #33691e;
}

/* ========================================================
   Meadow & Background
   ======================================================== */
.turtle-field {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.turtle-meadow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.meadow-sun {
  position: absolute;
  top: 6%;
  right: 8%;
  width: 76px;
  height: 76px;
  background: radial-gradient(circle, #fff9c4 0%, #ffee58 60%, rgba(255, 238, 88, 0) 100%);
  border-radius: 50%;
  filter: drop-shadow(0 0 16px #ffee58);
}

.meadow-hills {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 45%;
  background: radial-gradient(ellipse 120% 60% at 50% 100%, #7cb342 0%, #689f38 100%);
  border-radius: 50% 50% 0 0 / 20% 20% 0 0;
  box-shadow: 0 -8px 24px rgba(51, 105, 30, 0.15);
}

.flower-patch {
  position: absolute;
  font-size: 26px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.12));
  animation: flower-sway 4s ease-in-out infinite alternate;
}

.patch-1 { bottom: 18%; left: 10%; animation-delay: 0s; }
.patch-2 { bottom: 26%; right: 12%; animation-delay: 1.2s; }
.patch-3 { bottom: 12%; right: 28%; animation-delay: 2.1s; }

@keyframes flower-sway {
  0% { transform: rotate(-5deg); }
  100% { transform: rotate(5deg); }
}

.meadow-butterfly {
  position: absolute;
  top: 24%;
  left: 15%;
  font-size: 28px;
  animation: butterfly-flight 14s ease-in-out infinite;
}

@keyframes butterfly-flight {
  0% { transform: translate(0, 0) rotate(5deg); }
  25% { transform: translate(140px, -30px) rotate(-10deg); }
  50% { transform: translate(220px, 40px) rotate(15deg); }
  75% { transform: translate(90px, 60px) rotate(-8deg); }
  100% { transform: translate(0, 0) rotate(5deg); }
}

/* ========================================================
   Turtle Stage
   ======================================================== */
.turtle-stage {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(86vw, 340px);
  height: min(86vw, 340px);
}

.turtle-shadow {
  position: absolute;
  bottom: 30px;
  width: 250px;
  height: 52px;
  background: radial-gradient(ellipse at center, rgba(30, 60, 15, 0.45) 0%, rgba(30, 60, 15, 0) 70%);
  border-radius: 50%;
  z-index: 5;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.turtle-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  outline: none;
  position: relative;
  z-index: 12;
}

.turtle-btn:focus-visible .turtle-carapace {
  outline: 4px solid #ffeb3b;
  outline-offset: 6px;
}

/* ========================================================
   Turtle Body & Structure
   ======================================================== */
.turtle-body {
  --base-scale: 1;
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(var(--base-scale));
  transform-origin: center center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Tail */
.turtle-tail {
  position: absolute;
  bottom: 42px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 28px;
  background: linear-gradient(180deg, var(--turtle-skin) 0%, var(--turtle-skin-dark) 100%);
  border-radius: 0 0 12px 12px;
  border: 2px solid var(--turtle-skin-dark);
  z-index: 6;
  transform-origin: top center;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Paws / Legs */
.turtle-leg {
  position: absolute;
  width: 44px;
  height: 52px;
  background: linear-gradient(135deg, var(--turtle-skin) 0%, var(--turtle-skin-dark) 100%);
  border: 3px solid var(--turtle-skin-dark);
  border-radius: 22px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  z-index: 7;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  transform-origin: center center;
}

.leg-fl { top: 68px;  left: 20px;  transform: rotate(-35deg); }
.leg-fr { top: 68px;  right: 20px; transform: rotate(35deg); }
.leg-bl { bottom: 62px; left: 30px; transform: rotate(-55deg); }
.leg-br { bottom: 62px; right: 30px; transform: rotate(55deg); }

/* Head & Face */
.turtle-head-wrap {
  position: absolute;
  top: 48px;
  left: 50%;
  transform: translateX(-50%) translateY(-68px);
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.turtle-neck {
  width: 42px;
  height: 38px;
  background: linear-gradient(180deg, var(--turtle-skin) 0%, var(--turtle-skin-dark) 100%);
  border-left: 3px solid var(--turtle-skin-dark);
  border-right: 3px solid var(--turtle-skin-dark);
  margin-top: -8px;
  z-index: 1;
}

.turtle-head {
  position: relative;
  width: 76px;
  height: 72px;
  background: radial-gradient(circle at 50% 40%, #9ccc65 0%, var(--turtle-skin) 60%, var(--turtle-skin-dark) 100%);
  border: 3px solid var(--turtle-skin-dark);
  border-radius: 38px 38px 32px 32px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
  z-index: 2;
}

/* Eyes */
.turtle-eye {
  position: absolute;
  top: 16px;
  width: 20px;
  height: 22px;
  background: #ffffff;
  border: 2px solid #33691e;
  border-radius: 50%;
  overflow: hidden;
}

.eye-left { left: 10px; }
.eye-right { right: 10px; }

.eye-pupil {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 10px;
  height: 12px;
  background: #1b300f;
  border-radius: 50%;
}

.eye-twinkle {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 4px;
  height: 4px;
  background: #ffffff;
  border-radius: 50%;
}

/* Cheeks & Smile */
.turtle-cheek {
  position: absolute;
  top: 36px;
  width: 14px;
  height: 10px;
  background: rgba(255, 138, 128, 0.65);
  border-radius: 50%;
}

.cheek-left { left: 8px; }
.cheek-right { right: 8px; }

.turtle-smile {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 11px;
  border-bottom: 3.5px solid #2e5518;
  border-radius: 0 0 16px 16px;
}

/* ========================================================
   Carapace Shell
   ======================================================== */
.turtle-carapace {
  position: relative;
  width: 215px;
  height: 190px;
  background: radial-gradient(ellipse at 50% 35%, var(--shell-inner) 0%, var(--shell-outer) 55%, var(--shell-dark) 100%);
  border: 5px solid #2b5318;
  border-radius: 50% 50% 46% 46% / 54% 54% 46% 46%;
  box-shadow:
    inset 0 6px 12px rgba(255, 255, 255, 0.4),
    inset 0 -10px 16px rgba(0, 0, 0, 0.45),
    0 12px 28px rgba(0, 0, 0, 0.28);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.shell-scute {
  position: absolute;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3), inset 0 -3px 6px rgba(0, 0, 0, 0.3);
}

.scute-center {
  width: 60px;
  height: 52px;
  background: linear-gradient(135deg, #8bc34a 0%, #689f38 100%);
  border-radius: 12px;
  z-index: 2;
}

.scute-top {
  top: 14px;
  width: 48px;
  height: 38px;
  background: linear-gradient(180deg, #9ccc65 0%, #7cb342 100%);
  border-radius: 10px;
}

.scute-bottom {
  bottom: 14px;
  width: 52px;
  height: 38px;
  background: linear-gradient(0deg, #558b2f 0%, #689f38 100%);
  border-radius: 10px;
}

.scute-left {
  left: 18px;
  width: 42px;
  height: 48px;
  background: linear-gradient(90deg, #689f38 0%, #7cb342 100%);
  border-radius: 10px;
}

.scute-right {
  right: 18px;
  width: 42px;
  height: 48px;
  background: linear-gradient(-90deg, #689f38 0%, #7cb342 100%);
  border-radius: 10px;
}

.shell-rim {
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 4px dashed rgba(255, 238, 88, 0.4);
  pointer-events: none;
}

.shell-flower {
  position: absolute;
  top: 12px;
  right: 22px;
  font-size: 34px;
  line-height: 1;
  z-index: 15;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
  animation: flower-bob 2.5s ease-in-out infinite alternate;
}

@keyframes flower-bob {
  0% { transform: scale(1) rotate(-8deg); }
  100% { transform: scale(1.1) rotate(12deg); }
}

/* ========================================================
   Turtle States (Walk, Peek, Hide)
   ======================================================== */
/* 1. Walking State */
.turtle-body.state-walk .turtle-head-wrap {
  transform: translateX(-50%) translateY(-68px);
  opacity: 1;
  animation: head-nod 2.4s ease-in-out infinite alternate;
}

@keyframes head-nod {
  0% { transform: translateX(-50%) translateY(-68px) rotate(-2deg); }
  100% { transform: translateX(-50%) translateY(-62px) rotate(2deg); }
}

.turtle-body.state-walk .turtle-tail {
  animation: tail-wag 1.6s ease-in-out infinite alternate;
}

@keyframes tail-wag {
  0% { transform: translateX(-50%) rotate(-12deg); }
  100% { transform: translateX(-50%) rotate(12deg); }
}

.turtle-body.state-walk .leg-fl { animation: leg-waddle 1.8s ease-in-out infinite alternate; }
.turtle-body.state-walk .leg-fr { animation: leg-waddle 1.8s ease-in-out infinite alternate-reverse; }
.turtle-body.state-walk .leg-bl { animation: leg-waddle 1.8s ease-in-out infinite alternate-reverse; }
.turtle-body.state-walk .leg-br { animation: leg-waddle 1.8s ease-in-out infinite alternate; }

@keyframes leg-waddle {
  0% { transform: rotate(-25deg) scale(0.95); }
  100% { transform: rotate(-40deg) scale(1.05); }
}

/* 2. Hidden State */
.turtle-body.state-hide .turtle-head-wrap {
  transform: translateX(-50%) translateY(0px) scale(0.2);
  opacity: 0;
}

.turtle-body.state-hide .turtle-leg {
  transform: scale(0.2) translate(0, 0);
  opacity: 0;
}

.turtle-body.state-hide .turtle-tail {
  transform: translateX(-50%) translateY(-15px) scale(0.3);
  opacity: 0;
}

.turtle-body.state-hide .turtle-carapace {
  animation: shell-sleep-breathing 2.8s ease-in-out infinite alternate;
}

@keyframes shell-sleep-breathing {
  0% { transform: scale(1); }
  100% { transform: scale(1.03); }
}

/* 3. Peeking State (Ку-ку!) */
.turtle-body.state-peek .turtle-head-wrap {
  transform: translateX(-50%) translateY(-24px) scale(0.85);
  opacity: 1;
}

.turtle-body.state-peek .turtle-leg {
  transform: scale(0.3);
  opacity: 0.3;
}

.turtle-body.state-peek .turtle-carapace {
  animation: shell-peek-wobble 0.4s ease-in-out;
}

@keyframes shell-peek-wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

/* Shell Knock Wobble */
.turtle-body.knock-wobble {
  animation: shell-knock 0.3s ease-in-out;
}

@keyframes shell-knock {
  0%, 100% { transform: scale(var(--base-scale, 1)) rotate(0deg); }
  30% { transform: scale(calc(var(--base-scale, 1) * 0.95)) rotate(-4deg); }
  70% { transform: scale(calc(var(--base-scale, 1) * 1.04)) rotate(4deg); }
}

/* Turtle Speech Bubble */
.turtle-bubble {
  position: absolute;
  top: -42px;
  background: #ffffff;
  color: #2e5518;
  font-weight: 800;
  font-size: 20px;
  padding: 6px 16px;
  border-radius: 20px;
  border: 3px solid #8bc34a;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  z-index: 30;
  pointer-events: none;
  animation: bubble-bounce 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.turtle-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 8px 7px 0;
  border-style: solid;
  border-color: #8bc34a transparent transparent;
  display: block;
  width: 0;
}

@keyframes bubble-bounce {
  0% { transform: scale(0.3) translateY(15px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ========================================================
   Snack Target
   ======================================================== */
.snack-target {
  position: absolute;
  top: 10px;
  right: 0px;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #8bc34a;
  border-radius: 50%;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.15);
  z-index: 20;
  animation: snack-float 2.5s ease-in-out infinite alternate;
  transition: transform 0.2s ease;
}

.snack-target:hover {
  transform: scale(1.12);
}

.snack-target:active {
  transform: scale(0.92);
}

.snack-emoji {
  font-size: 32px;
  line-height: 1;
}

@keyframes snack-float {
  0% { transform: translateY(0); }
  100% { transform: translateY(-8px); }
}

/* ========================================================
   Action Controls Bar
   ======================================================== */
.stage-controls {
  position: relative;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  max-width: 100%;
}

.action-btn {
  background: #ffffff;
  color: #33691e;
  border: 3px solid #8bc34a;
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  padding: 10px 20px;
  box-shadow: 0 4px 12px rgba(51, 105, 30, 0.2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.action-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(51, 105, 30, 0.3);
}

.action-btn:active {
  transform: scale(0.95);
}

.action-btn.hide-btn {
  background: linear-gradient(135deg, #7cb342 0%, #558b2f 100%);
  color: #ffffff;
  border-color: #aed581;
}

.action-btn.feed-btn {
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
  color: #ffffff;
  border-color: #ffe082;
}

.action-btn.flower-btn {
  background: linear-gradient(135deg, #ec407a 0%, #d81b60 100%);
  color: #ffffff;
  border-color: #f8bbd0;
}

/* ========================================================
   Particles (Hearts, Sparkles)
   ======================================================== */
.particles-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.floating-heart {
  position: absolute;
  font-size: 26px;
  animation: heart-rise 1s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes heart-rise {
  0% { transform: translate(0, 0) scale(0.3); opacity: 1; }
  100% { transform: translate(var(--hx, 0), -70px) scale(1.2); opacity: 0; }
}

.sparkle-star {
  position: absolute;
  width: 14px;
  height: 14px;
  background: radial-gradient(circle, #fff 0%, #ffeb3b 60%, transparent 100%);
  border-radius: 50%;
  animation: star-burst 0.7s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes star-burst {
  0% { transform: translate(0, 0) scale(0.2); opacity: 1; }
  100% { transform: translate(var(--sx, 0), var(--sy, 0)) scale(1.4); opacity: 0; }
}

/* ========================================================
   Responsive Breakpoints
   ======================================================== */
@media (max-width: 360px) {
  .turtle-body {
    --base-scale: 0.85;
  }
  .stage-controls {
    gap: 8px;
  }
  .action-btn {
    font-size: 14px;
    padding: 8px 14px;
  }
}

@media (max-height: 600px) {
  .turtle-stage {
    width: min(75vw, 48vh, 260px);
    height: min(75vw, 48vh, 260px);
  }
  .turtle-body {
    --base-scale: 0.8;
  }
  .stage-controls {
    margin-top: 6px;
    gap: 8px;
  }
  .action-btn {
    padding: 8px 14px;
    font-size: 14px;
  }
}

@media (max-height: 440px) {
  .turtle-stage {
    width: min(70vw, 45vh, 200px);
    height: min(70vw, 45vh, 200px);
  }
  .turtle-body {
    --base-scale: 0.65;
  }
  .stage-controls {
    margin-top: 4px;
    gap: 6px;
  }
  .action-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
}

/* ========================================================
   Reduced Motion
   ======================================================== */
@media (prefers-reduced-motion: reduce) {
  .meadow-butterfly,
  .flower-patch,
  .snack-target,
  .turtle-carapace,
  .shell-flower,
  .turtle-bubble,
  .floating-heart,
  .sparkle-star,
  .turtle-body.knock-wobble,
  .turtle-body.state-walk .turtle-head-wrap,
  .turtle-body.state-walk .turtle-tail,
  .turtle-body.state-walk .turtle-leg {
    animation: none !important;
  }
  .turtle-head-wrap,
  .turtle-leg,
  .turtle-tail,
  .turtle-body,
  .action-btn,
  .snack-target {
    transition: none !important;
  }
}
