:root {
  --bg-gradient: linear-gradient(135deg, #f0f4ff 0%, #e8f5e9 50%, #fff8e1 100%);
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --accent-pink: #ec4899;
  --accent-orange: #f97316;
  --accent-yellow: #facc15;
  --success: #10b981;
  --success-bg: #d1fae5;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --card-bg: rgba(255, 255, 255, 0.95);
  --shadow-lg: 0 16px 32px -8px rgba(79, 70, 229, 0.15), 0 8px 16px -6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 20px -4px rgba(0, 0, 0, 0.08);
  --font-display: 'Nunito', 'Fredoka', system-ui, -apple-system, sans-serif;
  --font-body: 'Fredoka', 'Nunito', system-ui, -apple-system, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: var(--bg-gradient);
  color: var(--text-dark);
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* App Container - Centered vertically and horizontally */
.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5rem 1.25rem;
  margin: 0 auto;
  position: relative;
  z-index: 10;
}

/* Main Game Area */
.game-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.75rem;
  width: 100%;
}

/* Math Expression Card */
.math-card {
  width: 100%;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 2rem;
  padding: 1.75rem 1rem;
  box-shadow: var(--shadow-lg);
  border: 3px solid rgba(255, 255, 255, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.math-card.pop-anim {
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  0% { transform: scale(0.9) translateY(10px); opacity: 0.7; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.math-expression {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 3.4rem;
  line-height: 1;
}

.math-num {
  color: var(--primary);
  background: #eef2ff;
  border-radius: 1rem;
  padding: 0.2rem 0.5rem;
  min-width: 1.4ch;
  text-align: center;
  box-shadow: inset 0 2px 4px rgba(79, 70, 229, 0.08);
}

.math-op {
  color: var(--accent-pink);
  font-size: 2.8rem;
}

.math-eq {
  color: var(--text-muted);
}

.math-result-box {
  color: #6366f1;
  background: #f1f5f9;
  border: 3px dashed #cbd5e1;
  border-radius: 1.2rem;
  padding: 0.2rem 0.6rem;
  min-width: 1.8ch;
  text-align: center;
  transition: all 0.25s ease;
}

/* Correct / Error States for Result Box */
.math-card.is-correct {
  border-color: #34d399;
  background: #ecfdf5;
}

.math-card.is-correct .math-result-box {
  background: #10b981;
  color: #ffffff;
  border: 3px solid #059669;
  transform: scale(1.08);
}

.math-card.is-wrong {
  border-color: #f87171;
  animation: gentleShake 0.4s ease-in-out;
}

.math-card.is-wrong .math-result-box {
  background: #fee2e2;
  color: #dc2626;
  border: 3px solid #f87171;
}

@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Big Score on Failure */
.score-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.4rem 1rem;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score-big {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 5.8rem;
  line-height: 1;
  color: var(--primary);
  text-shadow: 0 4px 16px rgba(79, 70, 229, 0.18);
}

.score-label {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1.45rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.math-card.show-score {
  border-color: #cbd5e1;
  background: #ffffff;
}

/* Action Area & Larger Centered Button */
.action-area {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem 0;
  position: relative;
}

.mic-ripple-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 290px;
  height: 290px;
}

/* Concentric Shrinking 10-Second Timer Ring */
.timer-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 3;
  width: 275px;
  height: 275px;
  border: 6px solid #4f46e5;
  background: rgba(79, 70, 229, 0.05);
  box-shadow: 0 0 20px rgba(79, 70, 229, 0.25);
}

.mic-button {
  width: 165px;
  height: 165px;
  border-radius: 50%;
  border: 6px solid #ffffff;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 14px 34px rgba(79, 70, 229, 0.4);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 5;
}

.mic-button:active {
  transform: scale(0.94);
}

.mic-inner {
  width: 66px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-svg {
  width: 50px;
  height: 50px;
}

.mic-label {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  margin-top: 0.25rem;
  text-align: center;
  line-height: 1.15;
  max-width: 140px;
}

/* Listening Mode Button */
.mic-button.listening {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  box-shadow: 0 12px 32px rgba(234, 88, 12, 0.45);
  animation: pulseMic 1.2s ease-in-out infinite alternate;
}

@keyframes pulseMic {
  0% { transform: scale(1); }
  100% { transform: scale(1.06); }
}

/* Start Mode Button (Initial State) */
.mic-button.start-mode {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.45);
  animation: pulseStartBtn 1.5s ease-in-out infinite alternate;
}

/* Restart Mode Button (When Failed) */
.mic-button.restart-mode {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  box-shadow: 0 12px 30px rgba(234, 88, 12, 0.45);
  animation: pulseStartBtn 1.5s ease-in-out infinite alternate;
}

@keyframes pulseStartBtn {
  0% { transform: scale(1); }
  100% { transform: scale(1.05); }
}

/* Correct Mode Button */
.mic-button.success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 12px 32px rgba(16, 185, 129, 0.4);
}





/* PWA Banner */
.pwa-banner {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  max-width: 440px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 1.25rem;
  padding: 0.85rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
  border: 2px solid #e2e8f0;
  z-index: 500;
  animation: slideUp 0.3s ease-out;
}

.pwa-banner-text {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}

.pwa-banner-text strong {
  font-family: var(--font-display);
  color: var(--primary);
}

.pwa-banner-text span {
  color: var(--text-muted);
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-install {
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 0.45rem 0.9rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-dismiss {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

/* Utilities */
.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Media query for smaller mobile screens */
@media (max-width: 380px) {
  .math-expression {
    font-size: 2.8rem;
    gap: 0.4rem;
  }
  .mic-button {
    width: 150px;
    height: 150px;
  }
  .mic-inner {
    width: 58px;
    height: 58px;
  }
  .mic-svg {
    width: 44px;
    height: 44px;
  }
  .mic-label {
    font-size: 0.95rem;
  }
  .mic-ripple-container {
    width: 260px;
    height: 260px;
  }
}
