/* ===========================================
   Super Maths Hero - Animations CSS
   iOS Native Design - Subtle, Fluid Animations
   =========================================== */

/* ===== iOS-Style Keyframe Definitions ===== */

/* Fade Animations - Subtle */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide Animations - iOS Spring Curve */
@keyframes slideInDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideOutUp {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-20px);
    opacity: 0;
  }
}

/* iOS Sheet Animation */
@keyframes sheetIn {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes sheetOut {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

/* Scale Animations - Subtle */
@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes scaleOut {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0.95);
    opacity: 0;
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

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

/* Bounce Animations - Subtle */
@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes bounceIn {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  60% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes bounceOut {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0;
  }
}

/* Shake Animation - Subtle */
@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  20%, 60% {
    transform: translateX(-4px);
  }
  40%, 80% {
    transform: translateX(4px);
  }
}

@keyframes shakeSmall {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px);
  }
  50% {
    transform: translateX(2px);
  }
  75% {
    transform: translateX(-2px);
  }
}

/* Pulse Animation - Subtle */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

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

@keyframes pulseGlow {
  0%, 100% {
    box-shadow: var(--shadow-card), 0 0 0 0 rgba(0, 122, 255, 0.3);
  }
  50% {
    box-shadow: var(--shadow-card), 0 0 0 8px rgba(0, 122, 255, 0);
  }
}

/* Rotate Animations */
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes rotateIn {
  from {
    transform: rotate(-10deg) scale(0.9);
    opacity: 0;
  }
  to {
    transform: rotate(0deg) scale(1);
    opacity: 1;
  }
}

@keyframes wobble {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-2deg);
  }
  75% {
    transform: rotate(2deg);
  }
}

/* Float Animation - Gentle */
@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* Heartbeat Animation - Subtle */
@keyframes heartbeat {
  0%, 100% {
    transform: scale(1);
  }
  14% {
    transform: scale(1.1);
  }
  28% {
    transform: scale(1);
  }
  42% {
    transform: scale(1.1);
  }
  70% {
    transform: scale(1);
  }
}

/* Jello Animation - Subtle */
@keyframes jello {
  0%, 100% {
    transform: scale3d(1, 1, 1);
  }
  30% {
    transform: scale3d(1.05, 0.95, 1);
  }
  40% {
    transform: scale3d(0.95, 1.05, 1);
  }
  50% {
    transform: scale3d(1.03, 0.97, 1);
  }
  65% {
    transform: scale3d(0.98, 1.02, 1);
  }
  75% {
    transform: scale3d(1.01, 0.99, 1);
  }
}

/* Tada Animation - iOS Subtle */
@keyframes tada {
  0%, 100% {
    transform: scale(1) rotate(0deg);
  }
  10%, 20% {
    transform: scale(0.98) rotate(-1deg);
  }
  30%, 50%, 70%, 90% {
    transform: scale(1.02) rotate(1deg);
  }
  40%, 60%, 80% {
    transform: scale(1.02) rotate(-1deg);
  }
}

/* Flash Animation - Subtle */
@keyframes flash {
  0%, 50%, 100% {
    opacity: 1;
  }
  25%, 75% {
    opacity: 0.5;
  }
}

/* Success Checkmark Animation */
@keyframes checkmark {
  0% {
    stroke-dashoffset: 100;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

/* Confetti Fall - For celebrations */
@keyframes confettiFall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Star Burst - Subtle */
@keyframes starBurst {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(1.5) rotate(90deg);
    opacity: 0;
  }
}

/* Number Count Up */
@keyframes countUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Progress Fill */
@keyframes progressFill {
  from {
    width: 0%;
  }
}

/* Shimmer Effect */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ===== Animation Utility Classes ===== */

/* Basic Animations */
.animate-fadeIn {
  animation: fadeIn 0.25s ease-out forwards;
}

.animate-fadeOut {
  animation: fadeOut 0.25s ease-out forwards;
}

.animate-fadeInUp {
  animation: fadeInUp 0.3s ease-out forwards;
}

.animate-fadeInDown {
  animation: fadeInDown 0.3s ease-out forwards;
}

.animate-slideInDown {
  animation: slideInDown 0.3s ease-out forwards;
}

.animate-slideInUp {
  animation: slideInUp 0.3s ease-out forwards;
}

/* Scale Animations */
.animate-scaleIn {
  animation: scaleIn 0.25s ease-out forwards;
}

.animate-pop {
  animation: pop 0.2s ease-out forwards;
}

.animate-popIn {
  animation: popIn 0.3s ease-out forwards;
}

/* Bounce Animations */
.animate-bounce {
  animation: bounce 0.4s ease-out;
}

.animate-bounceIn {
  animation: bounceIn 0.35s ease-out forwards;
}

/* Shake Animations */
.animate-shake {
  animation: shake 0.4s ease-out;
}

.animate-shakeSmall {
  animation: shakeSmall 0.25s ease-out;
}

/* Pulse Animations */
.animate-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

.animate-pulseScale {
  animation: pulseScale 1.5s ease-in-out infinite;
}

.animate-pulseGlow {
  animation: pulseGlow 2s ease-in-out infinite;
}

/* Rotate Animations */
.animate-rotate {
  animation: rotate 1s linear infinite;
}

.animate-rotateIn {
  animation: rotateIn 0.3s ease-out forwards;
}

.animate-wobble {
  animation: wobble 0.4s ease-out;
}

/* Float Animation */
.animate-float {
  animation: float 3s ease-in-out infinite;
}

/* Special Animations */
.animate-heartbeat {
  animation: heartbeat 1.5s ease-in-out infinite;
}

.animate-jello {
  animation: jello 0.7s ease-out;
}

.animate-tada {
  animation: tada 0.8s ease-out;
}

.animate-flash {
  animation: flash 0.8s ease-out;
}

/* ===== Animation Delays ===== */
.delay-100 {
  animation-delay: 100ms;
}

.delay-200 {
  animation-delay: 200ms;
}

.delay-300 {
  animation-delay: 300ms;
}

.delay-400 {
  animation-delay: 400ms;
}

.delay-500 {
  animation-delay: 500ms;
}

/* ===== Animation Durations ===== */
.duration-fast {
  animation-duration: 0.15s;
}

.duration-normal {
  animation-duration: 0.25s;
}

.duration-slow {
  animation-duration: 0.4s;
}

.duration-slower {
  animation-duration: 0.6s;
}

/* ===== Animation Fill Modes ===== */
.fill-forwards {
  animation-fill-mode: forwards;
}

.fill-backwards {
  animation-fill-mode: backwards;
}

.fill-both {
  animation-fill-mode: both;
}

/* ===== Hover Animations ===== */
.hover-bounce:active {
  animation: bounce 0.3s ease-out;
}

.hover-pulse:active {
  animation: pulseScale 0.3s ease-out;
}

.hover-wobble:active {
  animation: wobble 0.3s ease-out;
}

.hover-pop:active {
  animation: pop 0.2s ease-out;
}

/* ===== Transition Classes ===== */
.transition-all {
  transition: all 0.25s ease-out;
}

.transition-fast {
  transition: all 0.15s ease-out;
}

.transition-slow {
  transition: all 0.35s ease-out;
}

.transition-transform {
  transition: transform 0.25s ease-out;
}

.transition-opacity {
  transition: opacity 0.25s ease-out;
}

/* iOS Spring Transition */
.transition-spring {
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ===== Game-Specific Animations ===== */

/* Correct Answer Animation */
.correct-animation {
  animation: bounceIn 0.35s ease-out;
}

/* Wrong Answer Animation */
.wrong-animation {
  animation: shake 0.4s ease-out;
}

/* Badge Unlock Animation */
.badge-unlock-animation {
  animation: tada 0.8s ease-out, pulseGlow 2s ease-in-out 0.8s infinite;
}

/* Level Up Animation */
.levelup-animation {
  animation: bounceIn 0.4s ease-out, pulseScale 1s ease-in-out 0.4s;
}

/* Score Update Animation */
.score-update-animation {
  animation: pop 0.2s ease-out;
}

/* Timer Warning Animation */
.timer-warning-animation {
  animation: pulseScale 0.8s ease-in-out infinite;
}

/* Timer Danger Animation */
.timer-danger-animation {
  animation: heartbeat 0.5s ease-in-out infinite;
}

/* Mascot Animations */
.mascot-idle {
  animation: float 3s ease-in-out infinite;
}

.mascot-happy {
  animation: bounce 0.4s ease-out;
}

.mascot-sad {
  animation: shakeSmall 0.3s ease-out;
}

.mascot-celebrate {
  animation: tada 0.8s ease-out;
}

/* Button Press Animation */
.btn-press {
  animation: pop 0.15s ease-out;
}

/* Card Entrance Animations - Staggered */
.card-enter-1 {
  animation: fadeInUp 0.3s ease-out forwards;
  animation-delay: 0.05s;
  opacity: 0;
}

.card-enter-2 {
  animation: fadeInUp 0.3s ease-out forwards;
  animation-delay: 0.1s;
  opacity: 0;
}

.card-enter-3 {
  animation: fadeInUp 0.3s ease-out forwards;
  animation-delay: 0.15s;
  opacity: 0;
}

/* Confetti Container */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: var(--z-toast);
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confettiFall 3s ease-out forwards;
}

/* Star Celebration */
.star-celebration {
  position: absolute;
  font-size: 1.5rem;
  animation: starBurst 0.8s ease-out forwards;
}

/* Star Collection Animation */
@keyframes starCollect {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.3);
  }
  100% {
    opacity: 0;
    transform: scale(0.5);
  }
}

.star-collect {
  position: fixed;
  font-size: 2rem;
  pointer-events: none;
  z-index: 1000;
  transition: all 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.star-collect.flying {
  animation: starCollect 0.6s ease-out forwards;
}

/* Shimmer Loading */
.shimmer {
  background: linear-gradient(
    90deg,
    var(--ios-fill-quaternary) 0%,
    var(--ios-fill-tertiary) 50%,
    var(--ios-fill-quaternary) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* ===== Screen Directional Transitions ===== */
@keyframes slideOutLeft {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(-30%); opacity: 0; }
}

@keyframes slideInRight {
  from { transform: translateX(30%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(30%); opacity: 0; }
}

@keyframes slideInLeft {
  from { transform: translateX(-30%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.screen-slide-out-left {
  animation: slideOutLeft 0.3s ease-out forwards;
}

.screen-slide-in-right {
  animation: slideInRight 0.3s ease-out forwards;
}

.screen-slide-out-right {
  animation: slideOutRight 0.3s ease-out forwards;
}

.screen-slide-in-left {
  animation: slideInLeft 0.3s ease-out forwards;
}

/* ===== Title Staggered Entry ===== */
@keyframes titlePop {
  0% { transform: scale(0.5) translateY(20px); opacity: 0; }
  70% { transform: scale(1.1) translateY(-5px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.title-stagger .title-super {
  display: inline-block;
  animation: titlePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  animation-delay: 0.1s;
  opacity: 0;
}

.title-stagger .title-maths {
  display: inline-block;
  animation: titlePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  animation-delay: 0.25s;
  opacity: 0;
}

.title-stagger .title-hero {
  display: inline-block;
  animation: titlePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  animation-delay: 0.4s;
  opacity: 0;
}

/* ===== Play Button Glow ===== */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 4px 15px rgba(176, 136, 249, 0.4); }
  50% { box-shadow: 0 4px 25px rgba(176, 136, 249, 0.6), 0 0 40px rgba(255, 143, 177, 0.3); }
}

.btn-play {
  animation: glowPulse 2s ease-in-out infinite;
}

/* ===== Daily Challenge Shimmer ===== */
@keyframes borderShimmer {
  0% { border-color: rgba(176, 136, 249, 0.3); }
  50% { border-color: rgba(255, 143, 177, 0.6); }
  100% { border-color: rgba(176, 136, 249, 0.3); }
}

.daily-challenge-card:not(.completed) {
  animation: borderShimmer 3s ease-in-out infinite;
}

/* ===== Question Timer Enhanced ===== */
.question-timer-fill {
  transition: width 1s linear, background-color 0.5s ease;
}

.question-timer-fill.warning {
  background: linear-gradient(90deg, #FFB347, #FFD93D) !important;
}

.question-timer-fill.danger {
  background: linear-gradient(90deg, #FF8585, #FF4444) !important;
  animation: shakeSmall 0.5s ease-out infinite;
}

/* ===== Floating Score Points ===== */
@keyframes floatScore {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.2); }
}

.floating-score {
  position: fixed;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--accent-purple);
  pointer-events: none;
  z-index: 1000;
  animation: floatScore 1s ease-out forwards;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===== Mascot Breathing ===== */
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.mascot-breathe {
  animation: breathe 4s ease-in-out infinite;
}

/* ===== Choice Buttons Stagger ===== */
.choice-btn.stagger-enter {
  animation: fadeInUp 0.3s ease-out forwards;
  opacity: 0;
}

.choice-btn.stagger-enter:nth-child(1) { animation-delay: 0ms; }
.choice-btn.stagger-enter:nth-child(2) { animation-delay: 50ms; }
.choice-btn.stagger-enter:nth-child(3) { animation-delay: 100ms; }
.choice-btn.stagger-enter:nth-child(4) { animation-delay: 150ms; }

/* ===== Problem Entry Animation ===== */
@keyframes problemEntry {
  from { transform: translateY(15px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.problem-enter {
  animation: problemEntry 0.35s ease-out forwards;
}

/* ===== Countdown Overlay ===== */
@keyframes countdownPop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes countdownFade {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

.countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.countdown-number {
  font-family: var(--font-display);
  font-size: 120px;
  font-weight: 700;
  color: white;
  text-shadow: 0 4px 20px rgba(176, 136, 249, 0.5);
  animation: countdownPop 0.5s ease-out forwards;
}

.countdown-number.fade-out {
  animation: countdownFade 0.3s ease-out forwards;
}

.countdown-go {
  font-family: var(--font-display);
  font-size: 80px;
  font-weight: 700;
  color: var(--accent-green);
  text-shadow: 0 4px 20px rgba(102, 222, 147, 0.5);
  animation: countdownPop 0.5s ease-out forwards;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .animate-float,
  .animate-bounce,
  .animate-pulse,
  .animate-pulseScale,
  .animate-heartbeat,
  .mascot-idle,
  .timer-warning-animation,
  .timer-danger-animation,
  .btn-play,
  .daily-challenge-card:not(.completed),
  .mascot-breathe {
    animation: none !important;
  }
}
