/* Magic Butterfly: Symmetry — Styles */

:root {
  --bg-top: #ecfdf5;
  --bg-bottom: #d1fae5;
  --stage-border: #10b981;
  --theme-primary: #f59e0b;
  --theme-glow: rgba(245, 158, 11, 0.4);
  --card-bg: #ffffff;
}

body {
  background: radial-gradient(circle at 50% 20%, #fef3c7 0%, #ecfdf5 60%, #d1fae5 100%);
  margin: 0;
  padding: 0;
  color: #064e3b;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  padding: 8px 16px 16px;
  box-sizing: border-box;
}

.header-center {
  display: none;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
}

.score-badge {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #047857;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.instruction-banner {
  margin: 4px 0 8px;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  color: #065f46;
}

/* Meadow Stage */
.meadow-stage {
  position: relative;
  width: 100%;
  height: 270px;
  max-width: 640px;
  background: radial-gradient(circle at 50% 40%, #ffffff 0%, #ecfdf5 60%, #a7f3d0 100%);
  border: 6px solid #10b981;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(16, 185, 129, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stage-sky-decor {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  height: 40px;
  pointer-events: none;
}

.floating-pollen {
  position: absolute;
  font-size: 1.4rem;
  opacity: 0.7;
}

.p1 { left: 15%; top: 6px; animation: floatPollen 8s infinite ease-in-out; }
.p2 { right: 20%; top: 12px; animation: floatPollen 10s infinite ease-in-out 1s; }
.p3 { left: 80%; top: 4px; animation: floatPollen 9s infinite ease-in-out 2s; }

.theme-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--theme-primary);
  color: #ffffff;
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 1.1rem;
  font-weight: 800;
  box-shadow: 0 3px 10px var(--theme-glow);
  z-index: 5;
  transition: background 0.4s;
}

/* 3D Butterfly Scene */
.butterfly-scene {
  perspective: 900px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
}

.butterfly-creature {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
}

.butterfly-creature.is-flying {
  animation: flyAway 2.2s forwards ease-in-out;
}

/* Wings */
.wing {
  position: relative;
  width: 145px;
  height: 175px;
  box-shadow: 0 8px 24px var(--theme-glow), inset 0 0 25px rgba(255, 255, 255, 0.6);
  border: 4px solid #ffffff;
  transform-origin: center right;
  transition: transform 0.3s;
  overflow: hidden;
}

.wing-left {
  border-radius: 80% 20% 60% 40% / 70% 30% 70% 30%;
  transform-origin: right center;
  background: var(--wing-gradient-left, linear-gradient(135deg, #fde047 0%, #fbbf24 100%));
}

.wing-right {
  border-radius: 20% 80% 40% 60% / 30% 70% 30% 70%;
  transform-origin: left center;
  background: var(--wing-gradient-right, linear-gradient(225deg, #fde047 0%, #fbbf24 100%));
}

.butterfly-creature.is-flying .wing-left {
  animation: flapLeft 0.35s infinite alternate ease-in-out;
}

.butterfly-creature.is-flying .wing-right {
  animation: flapRight 0.35s infinite alternate ease-in-out;
}

.wing-canvas {
  position: absolute;
  inset: 0;
}

/* Wing Pattern Spots & Target Slots */
.pattern-spot {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-emoji);
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.2));
  transform: translate(-50%, -50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
}

.pattern-spot:hover {
  transform: translate(-50%, -50%) scale(1.15);
}

.pattern-spot:active {
  transform: translate(-50%, -50%) scale(0.95);
}

.pattern-spot.source-target {
  animation: pulseSource 1.5s infinite ease-in-out;
}

.pattern-slot {
  position: absolute;
  width: 46px;
  height: 46px;
  border: 3px dashed rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  transition: transform 0.25s, border-color 0.25s, background-color 0.25s;
  cursor: pointer;
  padding: 0;
  outline: none;
  color: inherit;
  font-family: var(--font-emoji);
  font-size: 2rem;
  line-height: 1;
  touch-action: manipulation;
}

.pattern-slot:hover:not(.filled) {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%) scale(1.08);
}

.pattern-slot:active:not(.filled) {
  transform: translate(-50%, -50%) scale(0.95);
}

.pattern-slot.active-target {
  animation: pulseSlot 1.5s infinite ease-in-out;
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.45);
}

.pattern-slot.filled {
  border: 3px solid rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.7);
  animation: snapPop 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pattern-spot:focus-visible,
.pattern-slot:focus-visible {
  outline: 3px solid #10b981;
  outline-offset: 3px;
}

/* Butterfly Body */
.butterfly-body {
  position: relative;
  width: 22px;
  height: 120px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 -4px;
}

.antennae {
  position: absolute;
  top: -18px;
  width: 32px;
  height: 18px;
  display: flex;
  justify-content: space-between;
}

.antenna {
  width: 3px;
  height: 16px;
  background: #334155;
  border-radius: 2px;
}

.antenna.left { transform: rotate(-25deg); }
.antenna.right { transform: rotate(25deg); }

.head {
  width: 20px;
  height: 20px;
  background: #1e293b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #fff;
  z-index: 2;
}

.thorax {
  width: 16px;
  height: 35px;
  background: #334155;
  border-radius: 8px;
  margin-top: -4px;
  z-index: 1;
}

.abdomen {
  width: 12px;
  height: 55px;
  background: #475569;
  border-radius: 6px 6px 12px 12px;
  margin-top: -4px;
}

/* Jewel Palette */
.palette-section {
  width: 100%;
  max-width: 640px;
  margin: 6px 0 10px;
}

.jewel-palette {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 3px solid #a7f3d0;
  border-radius: 24px;
  padding: 12px;
  box-shadow: 0 4px 14px rgba(6, 78, 59, 0.08);
}

.jewel-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 3px solid #e2e8f0;
  border-radius: 18px;
  padding: 8px 12px;
  min-width: 76px;
  min-height: 76px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  color: #0f172a;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.jewel-card:hover:not(:disabled) {
  transform: translateY(-4px) scale(1.06);
  border-color: #10b981;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.25);
}

.jewel-card:focus-visible {
  outline: 3px solid #10b981;
  outline-offset: 3px;
}

.jewel-card.hint-target {
  animation: pulseCard 1.3s infinite ease-in-out;
  border-color: #10b981;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.45);
}

.jewel-card:active:not(:disabled) {
  transform: scale(0.95);
}

.jewel-card.wrong {
  animation: gentleShake 0.4s ease-in-out;
  border-color: #f59e0b;
}

.jewel-card.placed {
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0.9);
}

.jewel-icon {
  font-size: 2.2rem;
  line-height: 1;
  margin-bottom: 4px;
}

.jewel-name {
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Action Controls */
.action-bar {
  display: flex;
  justify-content: center;
  min-height: 54px;
  width: 100%;
}

.action-btn {
  border: 3px solid #fff;
  border-radius: 40px;
  color: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: 1.25rem;
  padding: 12px 36px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.next-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4), 0 3px 0 #047857;
}

.again-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.4), 0 3px 0 #1d4ed8;
}

.action-btn:hover {
  transform: translateY(-2px) scale(1.05);
}

.action-btn:active {
  transform: translateY(2px) scale(0.97);
}

/* Sparkles Overlay */
.sparkle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.sparkle-particle {
  position: absolute;
  font-size: 1.8rem;
  animation: sparkleRise 1.3s forwards ease-out;
}

/* Keyframe Animations */
@keyframes flapLeft {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-65deg); }
}

@keyframes flapRight {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(65deg); }
}

@keyframes flyAway {
  0% { transform: translateY(0) scale(1); }
  25% { transform: translateY(-20px) scale(1.05); }
  100% { transform: translateY(-350px) translateX(120px) scale(0.4); opacity: 0; }
}

@keyframes pulseSlot {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.12); }
}

@keyframes snapPop {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-20deg); opacity: 0; }
  70% { transform: translate(-50%, -50%) scale(1.2) rotate(10deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); }
}

@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

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

@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes sparkleRise {
  0% { transform: translateY(0) scale(0.5); opacity: 1; }
  100% { transform: translateY(-70px) scale(1.2); opacity: 0; }
}

@keyframes pulseSource {
  0%, 100% { transform: translate(-50%, -50%) scale(1); filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2)); }
  50% { transform: translate(-50%, -50%) scale(1.2); filter: drop-shadow(0 0 12px #ffffff); }
}

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

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .butterfly-creature.is-flying, .wing, .sparkle-particle, .floating-pollen, .action-btn,
  .pattern-spot.source-target, .jewel-card.hint-target {
    animation: none !important;
    transition: none !important;
  }
}

/* Mobile Responsive */
@media (max-width: 540px) {
  .meadow-stage {
    height: 230px;
    margin-bottom: 8px;
  }
  .wing {
    width: 115px;
    height: 145px;
  }
  .pattern-spot, .pattern-slot {
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
  }
  .palette-section {
    margin: 4px 0 8px;
  }
  .jewel-palette {
    padding: 8px 6px;
    gap: 6px;
    border-radius: 18px;
  }
  .jewel-card {
    min-width: 56px;
    min-height: 60px;
    padding: 4px 6px;
    border-radius: 14px;
  }
  .jewel-icon {
    font-size: 1.6rem;
    margin-bottom: 2px;
  }
  .jewel-name {
    font-size: 0.72rem;
  }
}

/* Compact height / Landscape screen */
@media (max-height: 600px) {
  .game-container {
    padding: 4px 10px 8px;
    justify-content: flex-start;
  }
  .status-bar {
    margin-bottom: 2px;
  }
  .score-badge {
    padding: 3px 10px;
    font-size: 0.95rem;
  }
  .instruction-banner {
    margin: 2px 0 4px;
    font-size: 0.95rem;
  }
  .meadow-stage {
    height: 180px;
    margin-bottom: 6px;
    border-radius: 20px;
    border-width: 4px;
  }
  .theme-badge {
    top: 6px;
    padding: 3px 14px;
    font-size: 0.9rem;
  }
  .butterfly-scene {
    margin-top: 14px;
  }
  .wing {
    width: 95px;
    height: 120px;
    border-width: 3px;
  }
  .butterfly-body {
    height: 85px;
    width: 16px;
  }
  .pattern-spot, .pattern-slot {
    width: 30px;
    height: 30px;
    font-size: 1.3rem;
  }
  .palette-section {
    margin: 2px 0 4px;
  }
  .jewel-palette {
    padding: 6px;
    gap: 6px;
    border-radius: 16px;
    border-width: 2px;
  }
  .jewel-card {
    min-width: 52px;
    min-height: 52px;
    padding: 3px 6px;
    border-radius: 12px;
  }
  .jewel-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
  }
  .jewel-name {
    font-size: 0.68rem;
  }
  .action-bar {
    min-height: 42px;
  }
  .action-btn {
    padding: 8px 24px;
    font-size: 1.05rem;
    min-height: 40px;
  }
}
