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

:root {
  --bg: #FFF7EC;
  --text: #3D2C2E;
  --text-muted: #8B7E80;
  --card: #ffffff;
  --accent-red: #FF6B6B;
  --accent-teal: #4ECDC4;
  --accent-yellow: #FFD93D;
  --accent-purple: #6C5CE7;
  --accent-orange: #FF9F43;
  --accent-green: #2ECC71;
  --shadow-sm: 0 4px 12px rgba(61, 44, 46, 0.08);
  --shadow-md: 0 8px 28px rgba(61, 44, 46, 0.12);
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.22; z-index: 0; animation: blobFloat 14s ease-in-out infinite alternate; pointer-events: none; }
.blob-1 { width: 380px; height: 380px; background: var(--accent-purple); top: -140px; left: -80px; }
.blob-2 { width: 340px; height: 340px; background: var(--accent-teal); bottom: -100px; right: -60px; animation-delay: -5s; }
.blob-3 { width: 280px; height: 280px; background: var(--accent-yellow); top: 35%; left: 55%; animation-delay: -9s; }
@keyframes blobFloat { 0%{transform:translate(0,0) scale(1)} 100%{transform:translate(24px,-32px) scale(1.06)} }

.top-bar { position: relative; z-index: 10; padding: 12px 20px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.95rem;
  color: var(--text-muted); text-decoration: none;
  padding: 8px 14px; border-radius: 14px;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(8px);
  transition: background 0.2s, color 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.9); color: var(--text); }

.game-wrapper {
  position: relative; z-index: 1; flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 24px;
  max-width: 540px; margin: 0 auto; width: 100%;
}

.game-header { text-align: center; margin-bottom: 8px; animation: fadeDown 0.5s ease both; }
.game-header h1 {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-teal));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.emoji-bounce { display: inline-block; -webkit-text-fill-color: initial; animation: emojiBounce 2s ease-in-out infinite; }
@keyframes emojiBounce { 0%,100%{transform:translateY(0) rotate(0)} 25%{transform:translateY(-6px) rotate(-8deg)} 75%{transform:translateY(-3px) rotate(6deg)} }
.subtitle { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
@keyframes fadeDown { 0%{opacity:0;transform:translateY(-18px)} 100%{opacity:1;transform:translateY(0)} }

/* Character */
.character {
  margin-bottom: 8px;
  animation: fadeDown 0.5s 0.1s ease both;
}

.character-face {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--accent-purple), #a78bfa);
  border-radius: 50%;
  position: relative;
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.3);
  transition: transform 0.3s;
}
.character-face.thinking {
  animation: charThink 0.8s ease-in-out infinite;
}
.character-face.speaking {
  animation: charSpeak 0.4s ease-in-out infinite;
}
.character-face.listening {
  box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4);
  animation: charListen 1.2s ease-in-out infinite;
}

@keyframes charThink {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}
@keyframes charSpeak {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes charListen {
  0% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4); }
  70% { box-shadow: 0 0 0 15px rgba(108, 92, 231, 0); }
  100% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0); }
}

.eye {
  position: absolute; top: 28px;
  width: 10px; height: 12px;
  background: #fff;
  border-radius: 50%;
}
.eye::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 5px; height: 5px;
  background: #2D2D2D;
  border-radius: 50%;
  transition: transform 0.2s;
}
.left-eye { left: 22px; }
.right-eye { right: 22px; }

.mouth {
  position: absolute; bottom: 20px;
  left: 50%; transform: translateX(-50%);
  width: 20px; height: 10px;
  border-radius: 0 0 10px 10px;
  background: #fff;
  transition: all 0.2s;
}
.mouth.speaking {
  animation: mouthMove 0.3s ease-in-out infinite;
}
@keyframes mouthMove {
  0%, 100% { height: 6px; width: 16px; }
  50% { height: 14px; width: 20px; }
}
.mouth.happy {
  height: 8px;
  border-radius: 0 0 12px 12px;
}

/* Answer area */
.answer-area {
  width: 100%;
  margin-bottom: 8px;
  animation: fadeDown 0.5s 0.2s ease both;
}

.answer-bubble {
  background: var(--card);
  border-radius: 20px;
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  min-height: 60px;
  transition: box-shadow 0.3s;
}
.answer-bubble::before {
  content: '';
  position: absolute; top: -8px; left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 16px;
  background: var(--card);
  border-radius: 4px;
  transform: translateX(-50%) rotate(45deg);
}
.answer-bubble.thinking {
  box-shadow: 0 0 0 2px var(--accent-purple), var(--shadow-sm);
}

.answer-text {
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
}

/* Loading dots */
.loading-dots {
  display: inline-flex; gap: 4px; align-items: center; height: 20px;
}
.loading-dots span {
  width: 8px; height: 8px;
  background: var(--accent-purple);
  border-radius: 50%;
  animation: dotBounce 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Heard text */
.heard-text {
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-purple);
  text-align: center;
  min-height: 22px;
  margin-bottom: 6px;
  opacity: 0.8;
}

/* Input area */
.input-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: fadeDown 0.5s 0.3s ease both;
}

/* Input hint */
.input-hint {
  font-family: 'Baloo 2', cursive;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-align: center;
}

.mic-btn {
  width: 96px; height: 96px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-red), #E74C3C);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 6px 24px rgba(255, 107, 107, 0.4);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s;
  position: relative;
}
.mic-btn:hover { transform: scale(1.08); box-shadow: 0 8px 32px rgba(255, 107, 107, 0.5); }
.mic-btn:active { transform: scale(0.95); }
.mic-btn.listening {
  background: linear-gradient(135deg, #E74C3C, #C0392B);
  animation: micPulse 1s ease-in-out infinite;
}
.mic-btn:disabled { opacity: 0.4; pointer-events: none; }

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.5); }
  50% { box-shadow: 0 0 0 14px rgba(255, 107, 107, 0); }
}

.mic-icon { width: 34px; height: 34px; pointer-events: none; }
.mic-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.6rem; font-weight: 800;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Type fallback */
.type-fallback {
  display: flex; gap: 8px;
  width: 100%; max-width: 400px;
}
.type-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #E8E3E4;
  border-radius: 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  outline: none;
  background: var(--card);
  transition: border-color 0.2s;
}
.type-input:focus { border-color: var(--accent-purple); }
.type-input::placeholder { color: #C0B8B9; }

.send-btn {
  width: 48px; height: 48px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, var(--accent-purple), #a78bfa);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.send-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.4; pointer-events: none; }

/* Speaker toggle */
.speaker-toggle {
  position: fixed; bottom: 16px; right: 16px;
  display: flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  background: var(--card);
  border: none;
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700; font-size: 0.75rem;
  color: var(--text-muted);
  z-index: 20;
  transition: box-shadow 0.2s;
}
.speaker-toggle:hover { box-shadow: var(--shadow-md); }
.speaker-label { pointer-events: none; }

@media (max-width: 420px) {
  .mic-btn { width: 80px; height: 80px; }
  .character-face { width: 65px; height: 65px; }
  .eye { top: 22px; width: 8px; height: 10px; }
  .eye::after { width: 4px; height: 4px; top: 3px; left: 2px; }
  .left-eye { left: 18px; }
  .right-eye { right: 18px; }
  .mouth { bottom: 16px; }
}