@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;700;900&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(4px, 1dvh, 12px) clamp(6px, 2vw, 12px);
}

h1 {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.2rem, 4vw, 3rem);
  color: #fff;
  text-shadow: 3px 3px 0 #e91e8c, 6px 6px 0 rgba(0,0,0,0.2);
  letter-spacing: 2px;
  margin-bottom: clamp(2px, 0.5dvh, 8px);
  animation: wiggle 2s ease-in-out infinite;
  line-height: 1.1;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.subtitle {
  color: #ffd6f5;
  font-size: clamp(0.7rem, 2vw, 1.1rem);
  font-weight: 700;
  margin-bottom: clamp(4px, 1dvh, 16px);
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1dvh, 16px);
  width: 100%;
  max-width: 700px;
  flex: 1;
  min-height: 0;
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.game-area::-webkit-scrollbar { display: none; }

/* Monster preview */
.monster-stage {
  background: radial-gradient(ellipse at 50% 70%, #b8f0e6 0%, #e8f8ff 60%, #c8e8ff 100%);
  border-radius: clamp(16px, 3vw, 32px);
  border: clamp(2px, 0.4vw, 5px) solid #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25), inset 0 2px 8px rgba(255,255,255,0.6);
  padding: clamp(6px, 1dvh, 16px);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: clamp(180px, 40dvh, 400px);
}

.monster-stage::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40%;
  background: linear-gradient(to top, rgba(100,200,160,0.18), transparent);
  border-radius: 0 0 27px 27px;
  pointer-events: none;
}

#layer-body { cursor: pointer; }

#monster-svg {
  width: auto;
  height: 100%;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.18));
  transition: transform 0.15s cubic-bezier(.4,2,.6,1);
}

#monster-svg.bounce {
  animation: bounce 0.35s cubic-bezier(.4,2,.6,1);
}

@keyframes bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.08) rotate(-3deg); }
  70% { transform: scale(0.96) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.monster-name-area {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: clamp(2px, 0.5dvh, 8px);
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
}

#monster-name {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.9rem, 2.5vw, 1.4rem);
  color: #5b2d8e;
  border: 3px solid #c084fc;
  border-radius: 16px;
  padding: clamp(2px, 0.5dvh, 4px) 10px;
  background: rgba(255,255,255,0.7);
  outline: none;
  text-align: center;
  width: clamp(120px, 30vw, 180px);
}

.btn-random {
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.8rem, 2vw, 1.05rem);
  padding: clamp(6px, 1dvh, 10px) clamp(12px, 3vw, 22px);
  cursor: pointer;
  box-shadow: 0 4px 0 #b91c1c, 0 6px 16px rgba(239,68,68,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 1px;
  white-space: nowrap;
}

.btn-random:active { transform: translateY(3px); box-shadow: 0 1px 0 #b91c1c; }

/* Part picker */
.picker-panel {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  border-radius: clamp(14px, 3vw, 28px);
  border: clamp(2px, 0.3vw, 3px) solid rgba(255,255,255,0.4);
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  width: 100%;
  overflow: hidden;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  background: rgba(0,0,0,0.12);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1;
  min-width: 0;
  padding: clamp(4px, 0.8dvh, 10px) 2px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: clamp(0.55rem, 1.5vw, 0.82rem);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  white-space: nowrap;
}

.tab-btn .tab-icon { font-size: clamp(0.9rem, 2.5vw, 1.4rem); }

.tab-btn.active {
  background: rgba(255,255,255,0.25);
  color: #fff;
  border-bottom: 3px solid #ffd700;
}

.tab-btn:hover:not(.active) { background: rgba(255,255,255,0.1); color: #fff; }

.gallery {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(clamp(56px, 14vw, 100px), 1fr));
  gap: clamp(4px, 1vw, 10px);
  padding: clamp(6px, 1vw, 14px);
}

.gallery.active { display: grid; }

.part-card {
  background: rgba(255,255,255,0.85);
  border-radius: clamp(8px, 2vw, 16px);
  border: clamp(2px, 0.3vw, 3px) solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(4px, 0.8dvh, 8px) 2px clamp(2px, 0.5dvh, 6px);
  gap: 2px;
  transition: all 0.18s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.part-card:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 6px 16px rgba(0,0,0,0.18); }
.part-card.selected { border-color: #ffd700; background: #fffde7; transform: scale(1.06); box-shadow: 0 0 0 3px #f59e0b, 0 4px 12px rgba(245,158,11,0.4); }

.part-card svg { width: clamp(36px, 10vw, 64px); height: clamp(36px, 10vw, 64px); }
.part-card .part-label { font-size: clamp(0.5rem, 1.4vw, 0.7rem); font-weight: 700; color: #6d28d9; text-align: center; }

/* Action buttons */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  flex-shrink: 0;
}

.btn-save {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.8rem, 2vw, 1.05rem);
  padding: clamp(6px, 1dvh, 10px) clamp(12px, 3vw, 22px);
  cursor: pointer;
  box-shadow: 0 4px 0 #065f46, 0 6px 16px rgba(16,185,129,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 1px;
  white-space: nowrap;
}
.btn-save:active { transform: translateY(3px); box-shadow: 0 1px 0 #065f46; }

/* Color strip — always visible */
.color-strip {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  border-radius: 999px;
  border: clamp(2px, 0.3vw, 3px) solid rgba(255,255,255,0.4);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: clamp(4px, 0.6dvh, 8px) clamp(8px, 2vw, 14px);
  display: flex;
  align-items: center;
  gap: clamp(4px, 1vw, 8px);
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.color-strip-label {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.65rem, 1.8vw, 0.85rem);
  color: #fff;
  margin-right: 2px;
  white-space: nowrap;
}

.color-swatch {
  width: clamp(24px, 5vw, 36px);
  height: clamp(24px, 5vw, 36px);
  border-radius: 50%;
  border: clamp(2px, 0.3vw, 3px) solid rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.18s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.18); box-shadow: 0 3px 10px rgba(0,0,0,0.25); border-color: #fff; }
.color-swatch.selected { border-color: #ffd700; box-shadow: 0 0 0 3px #f59e0b, 0 3px 10px rgba(245,158,11,0.4); transform: scale(1.15); }

/* Voice picker */
.voice-gallery {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(clamp(56px, 14vw, 100px), 1fr));
  gap: clamp(4px, 1vw, 10px);
  padding: clamp(6px, 1vw, 14px);
}
.voice-gallery.active { display: grid; }

.voice-card {
  background: rgba(255,255,255,0.85);
  border-radius: clamp(8px, 2vw, 16px);
  border: clamp(2px, 0.3vw, 3px) solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(4px, 0.8dvh, 12px) 2px clamp(2px, 0.5dvh, 8px);
  gap: 2px;
  transition: all 0.18s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.voice-card:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 6px 16px rgba(0,0,0,0.18); }
.voice-card.selected { border-color: #ffd700; background: #fffde7; transform: scale(1.06); box-shadow: 0 0 0 3px #f59e0b, 0 4px 12px rgba(245,158,11,0.4); }
.voice-card .voice-emoji { font-size: clamp(1.2rem, 3.5vw, 2rem); }
.voice-card .voice-label { font-size: clamp(0.5rem, 1.4vw, 0.7rem); font-weight: 700; color: #6d28d9; text-align: center; }

.sparkle {
  position: fixed;
  pointer-events: none;
  font-size: 1.6rem;
  animation: fly 0.8s ease-out forwards;
  z-index: 999;
}

@keyframes fly {
  0% { opacity: 1; transform: scale(1) translate(0,0); }
  100% { opacity: 0; transform: scale(0.5) translate(var(--dx), var(--dy)); }
}

/* Idle breathing animation on body */
#layer-body {
  transform-origin: 130px 260px;
  animation: breathe 3s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scaleY(1) scaleX(1); }
  50% { transform: scaleY(1.02) scaleX(0.99); }
}

/* Gentle floating for entire monster */
#monster-svg:not(.bounce) {
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Eye blink animation — applied via JS to .eye-white elements */
.eye-blink {
  animation: blink 0.15s ease-in-out;
}
@keyframes blink {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.05); }
}

/* Mouth open animation when speaking */
.mouth-talking {
  animation: talk 0.3s ease-in-out infinite alternate;
}
@keyframes talk {
  0% { transform: scaleY(1); }
  100% { transform: scaleY(1.4) translateY(1px); }
}

/* Arm wave on hover */
#layer-body:hover .monster-arm-right {
  animation: wave 0.6s ease-in-out 2;
  transform-origin: 190px 210px;
}
@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-20deg); }
}

/* Game controls wrapper — transparent in portrait */
.game-controls {
  display: contents;
}

/* Landscape: put monster and controls side by side */
@media (min-aspect-ratio: 4/3) and (min-width: 600px) {
  .game-area {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: start;
    max-width: 1100px;
  }
  .monster-stage {
    flex: 1 1 40%;
    min-width: 250px;
    max-height: calc(100dvh - 160px);
  }
  .game-controls {
    display: flex;
    flex: 1 1 50%;
    min-width: 280px;
    flex-direction: column;
    gap: clamp(6px, 1dvh, 12px);
  }
  .color-strip {
    order: -1;
    flex-basis: 100%;
  }
  .actions {
    order: 10;
    flex-basis: 100%;
  }
}

/* Small mobile portrait */
@media (max-width: 400px) {
  .tab-btn .tab-label { display: none; }
  .tab-btn .tab-icon { font-size: 1.3rem; }
  .tab-btn { gap: 0; padding: 6px 2px; }
}
