:root {
  --game-bg: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 45%, #a5d6a7 100%);
}

.caterpillar-field {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.caterpillar-field:focus-visible {
  outline: 4px solid #ffb300;
  outline-offset: -4px;
}

/* Lawn decoration */
.lawn-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.decor-flower {
  position: absolute;
  font-size: 28px;
  opacity: 0.6;
}

.df-1 { top: 12%; left: 10%; }
.df-2 { bottom: 15%; right: 12%; }
.df-3 { bottom: 20%; left: 15%; font-size: 24px; }

/* Food Treats */
.treats-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.treat-item {
  position: absolute;
  font-size: 44px;
  line-height: 1;
  transform: translate(-50%, -50%);
  animation: treat-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), treat-bounce 1.5s infinite ease-in-out;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.15));
}

@keyframes treat-pop {
  0% { transform: translate(-50%, -50%) scale(0.2); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes treat-bounce {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.15) rotate(6deg); }
}

/* Caterpillar Container */
.caterpillar-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.cat-head {
  position: absolute;
  font-size: 78px;
  line-height: 1;
  z-index: 25;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.18));
  transition: transform 0.15s ease;
  pointer-events: none;
  transform: translate(-50%, -50%) scaleX(var(--head-flip, 1)) rotate(var(--head-rot, 0deg));
}

.cat-head.eating {
  transform: translate(-50%, -50%) scaleX(var(--head-flip, 1)) scale(1.25) rotate(-8deg);
}

.cat-head.squeaking {
  transform: translate(-50%, -50%) scaleX(var(--head-flip, 1)) scale(1.22) translateY(-10px);
}

.cat-segment {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  z-index: var(--seg-z, 15);
  transform: translate(-50%, -50%);
  animation: seg-spawn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cat-segment::after {
  content: '👟';
  position: absolute;
  bottom: -10px;
  font-size: 16px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

@keyframes seg-spawn {
  0% { transform: translate(-50%, -50%) scale(0.2); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Butterfly Metamorphosis */
.butterfly-layer {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
  animation: layer-fade 0.4s ease-out;
}

.butterfly-layer[hidden] {
  display: none !important;
}

@keyframes layer-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.butterfly-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
}

.butterfly-btn:hover,
.butterfly-btn:active {
  transform: scale(1.2) rotate(10deg);
}

.butterfly-btn:focus-visible {
  outline: 4px solid #ff9800;
  outline-offset: 4px;
}

.butterfly-btn.fly-away {
  animation: butterfly-fly-away 1.1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  pointer-events: none;
}

@keyframes butterfly-fly-away {
  0% { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
  35% { transform: translateY(-70px) scale(1.15) rotate(12deg); opacity: 1; }
  100% { transform: translateY(-380px) scale(0.35) rotate(-18deg); opacity: 0; }
}

.butterfly-icon {
  font-size: 130px;
  line-height: 1;
  display: inline-block;
  filter: drop-shadow(0 12px 28px rgba(156, 39, 176, 0.4));
  animation: butterfly-flutter 2s infinite ease-in-out;
}

@keyframes butterfly-flutter {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  25% { transform: translateY(-16px) rotate(-6deg) scale(1.08); }
  75% { transform: translateY(-10px) rotate(6deg) scale(0.95); }
}

.butterfly-banner {
  font-size: 28px;
  font-weight: 800;
  color: #6a1b9a;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 28px;
  border-radius: 24px;
  box-shadow: 0 6px 18px rgba(106, 27, 154, 0.15);
  margin-top: 16px;
  animation: banner-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes banner-pop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Sparkles Container */
.particles-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.caterpillar-spark {
  position: absolute;
  font-size: 26px;
  pointer-events: none;
  animation: spark-drift 0.9s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes spark-drift {
  0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--tx, 0px), var(--ty, -60px)) scale(1.2) rotate(var(--rot, 30deg)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cat-head,
  .cat-segment,
  .treat-item,
  .butterfly-icon,
  .butterfly-btn,
  .butterfly-btn.fly-away,
  .caterpillar-spark {
    animation: none !important;
    transition: none !important;
  }
}
