:root {
  --purple: #cdb4f6;
  --blue: #a9d6f5;
  --pink: #ffd3e8;
  --accent: #ff7eb6;
  --accent-deep: #b65bd6;
  --listen: #6fd3a8;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: linear-gradient(160deg, var(--purple) 0%, var(--pink) 45%, var(--blue) 100%);
  background-attachment: fixed;
}

.stage {
  position: relative;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 5vh, 48px);
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}

/* ---------- Character ---------- */
.character-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(62vw, 320px);
  aspect-ratio: 1;
}

.character {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 18px 24px rgba(120, 70, 160, 0.28));
  will-change: transform;
  animation: float 4s ease-in-out infinite;
}

.glow {
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0) 68%);
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.4s ease;
  pointer-events: none;
}

/* idle: gentle float */
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-14px) rotate(1deg); }
}

/* talking: quick bounce */
@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.03); }
}

/* listening: soft pulse */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* happy: a celebratory pop */
@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.14) rotate(3deg); }
  70% { transform: scale(0.98) rotate(-2deg); }
  100% { transform: scale(1); }
}

.stage[data-state="talking"] .character { animation: bounce 0.5s ease-in-out infinite; }
.stage[data-state="listening"] .character { animation: pulse 1.6s ease-in-out infinite; }
.stage[data-state="listening"] .glow { opacity: 1; transform: scale(1); }
.stage[data-state="happy"] .character { animation: pop 0.9s ease; }

/* ---------- Talk button ---------- */
.talk-btn {
  position: relative;
  width: clamp(120px, 34vw, 170px);
  height: clamp(120px, 34vw, 170px);
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9ecb, var(--accent) 55%, var(--accent-deep));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 30px rgba(182, 91, 214, 0.45), inset 0 -6px 14px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, background 0.3s ease;
  touch-action: manipulation;
}
.talk-btn:active { transform: scale(0.94); }

.talk-btn .mic { display: flex; }
.talk-btn .stop { display: none; }

/* In any active (connected) state, show stop icon + recolor */
.stage[data-state="listening"] .talk-btn,
.stage[data-state="talking"] .talk-btn,
.stage[data-state="happy"] .talk-btn,
.stage[data-state="connecting"] .talk-btn {
  background: radial-gradient(circle at 35% 30%, #8fe6c4, var(--listen) 55%, #3aa884);
}
.stage[data-state="listening"] .talk-btn .mic,
.stage[data-state="talking"] .talk-btn .mic,
.stage[data-state="happy"] .talk-btn .mic { display: none; }
.stage[data-state="listening"] .talk-btn .stop,
.stage[data-state="talking"] .talk-btn .stop,
.stage[data-state="happy"] .talk-btn .stop { display: flex; }

/* Pulsing rings */
.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  opacity: 0;
  pointer-events: none;
}
.stage[data-state="listening"] .ring,
.stage[data-state="talking"] .ring {
  animation: ripple 1.8s ease-out infinite;
}
.ring-2 { animation-delay: 0.6s !important; }
.ring-3 { animation-delay: 1.2s !important; }

@keyframes ripple {
  0% { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.8); }
}

/* connecting: spinner-ish breathing button */
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(0.92); } }
.stage[data-state="connecting"] .talk-btn { animation: breathe 1s ease-in-out infinite; }

/* ---------- Text ---------- */
.hint {
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 700;
  color: #6b3fa0;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
  min-height: 1.5em;
  text-align: center;
}

.brand {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(107, 63, 160, 0.55);
}

/* Reduced motion: keep it calm */
@media (prefers-reduced-motion: reduce) {
  .character, .talk-btn, .ring { animation: none !important; }
}
