/* ============================================
   ANIMATION SYSTEM - Kids Learning Platform
   Delightful micro-interactions and smooth transitions
   ============================================ */

/* ============================================
   ENTRANCE ANIMATIONS
   ============================================ */

/* Fade In */
.animate-fade-in {
    animation: fade-in 0.3s ease-out forwards;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Slide Up */
.animate-slide-up {
    animation: slide-up 0.3s ease-out forwards;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide Down */
.animate-slide-down {
    animation: slide-down 0.3s ease-out forwards;
}

@keyframes slide-down {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide Right (for RTL: slide in from right) */
.animate-slide-right {
    animation: slide-right 0.3s ease-out forwards;
}

@keyframes slide-right {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scale In */
.animate-scale-in {
    animation: scale-in 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Bounce In */
.animate-bounce-in {
    animation: bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Pop In (for badges, notifications) */
.animate-pop {
    animation: pop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes pop {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Stagger Entrance (for lists) */
.stagger-container .stagger-item {
    opacity: 0;
    transform: translateY(20px);
    animation: stagger-in 0.4s ease-out forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.05s; }
.stagger-item:nth-child(2) { animation-delay: 0.1s; }
.stagger-item:nth-child(3) { animation-delay: 0.15s; }
.stagger-item:nth-child(4) { animation-delay: 0.2s; }
.stagger-item:nth-child(5) { animation-delay: 0.25s; }
.stagger-item:nth-child(6) { animation-delay: 0.3s; }
.stagger-item:nth-child(7) { animation-delay: 0.35s; }
.stagger-item:nth-child(8) { animation-delay: 0.4s; }

@keyframes stagger-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   EXIT ANIMATIONS
   ============================================ */

.animate-fade-out {
    animation: fade-out 0.2s ease-in forwards;
}

@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.animate-scale-out {
    animation: scale-out 0.2s ease-in forwards;
}

@keyframes scale-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* ============================================
   INTERACTION ANIMATIONS
   ============================================ */

/* Hover Lift */
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-lift:hover {
    transform: translateY(-4px);
}

/* Hover Scale */
.hover-scale {
    transition: transform 0.2s ease;
}

.hover-scale:hover {
    transform: scale(1.02);
}

/* Hover Glow */
.hover-glow {
    transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
    box-shadow: var(--shadow-brand-lg);
}

/* Shake (for errors) */
.animate-shake {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

/* Wiggle (for attention) */
.animate-wiggle {
    animation: wiggle 0.5s ease-in-out;
}

@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-5deg);
    }
    75% {
        transform: rotate(5deg);
    }
}

/* Pulse */
.animate-pulse-slow {
    animation: pulse-slow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-slow {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Heartbeat (for favorites) */
.animate-heartbeat {
    animation: heartbeat 0.6s ease;
}

@keyframes heartbeat {
    0%, 100% {
        transform: scale(1);
    }
    15% {
        transform: scale(1.3) rotate(-5deg);
    }
    30% {
        transform: scale(1.1) rotate(5deg);
    }
    45% {
        transform: scale(1.25) rotate(-3deg);
    }
    60% {
        transform: scale(1.05) rotate(2deg);
    }
}

/* Bounce (for cart/badge updates) */
.animate-bounce-small {
    animation: bounce-small 0.5s ease;
}

@keyframes bounce-small {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-10px);
    }
    50% {
        transform: translateY(0);
    }
    75% {
        transform: translateY(-5px);
    }
}

/* ============================================
   LOADING ANIMATIONS
   ============================================ */

/* Spinner */
.animate-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Shimmer (for skeleton screens) */
.animate-shimmer {
    animation: shimmer 2s linear infinite;
    background: linear-gradient(
        90deg,
        #f1f5f9 0%,
        #e2e8f0 20%,
        #f1f5f9 40%,
        #f1f5f9 100%
    );
    background-size: 200% 100%;
}

@keyframes shimmer {
    0% {
        background-position: -200% center;
    }
    100% {
        background-position: 200% center;
    }
}

/* Dots Loading */
.loading-dots {
    display: inline-flex;
    gap: 0.375rem;
}

.loading-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--color-primary);
    animation: dots-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ============================================
   CELEBRATION ANIMATIONS
   ============================================ */

/* Confetti */
.confetti-particle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--color-primary);
    animation: confetti-fall 2s ease-out forwards;
    opacity: 0;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100%) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Success Checkmark Draw */
.success-checkmark {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: block;
    stroke-width: 3;
    stroke: var(--color-success);
    stroke-miterlimit: 10;
    box-shadow: inset 0 0 0 var(--color-success);
    animation: fill-circle 0.4s ease-in-out 0.4s forwards, scale-checkmark 0.3s ease-in-out 0.9s both;
}

.success-checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 3;
    stroke-miterlimit: 10;
    stroke: var(--color-success);
    fill: none;
    animation: stroke-circle 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.success-checkmark-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: stroke-check 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes stroke-circle {
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes stroke-check {
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes scale-checkmark {
    0%, 100% {
        transform: none;
    }
    50% {
        transform: scale3d(1.1, 1.1, 1);
    }
}

/* Star Sparkle */
.animate-sparkle {
    animation: sparkle 1s ease-in-out;
}

@keyframes sparkle {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 0.8;
    }
}

/* ============================================
   SCROLL ANIMATIONS
   ============================================ */

/* Reveal on Scroll (triggered by JS with Intersection Observer) */
.scroll-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.scroll-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Parallax Effect (subtle, applied via JS) */
.parallax {
    transition: transform 0.1s ease-out;
    will-change: transform;
}

/* ============================================
   FLOATING ANIMATIONS
   ============================================ */

/* Gentle Float */
.animate-float,
.animate-float-gentle {
    animation: float-gentle 4s ease-in-out infinite;
}

@keyframes float-gentle {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Float with Rotation */
.animate-float-rotate {
    animation: float-rotate 6s ease-in-out infinite;
}

@keyframes float-rotate {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-12px) rotate(5deg);
    }
}

/* Blob Morph (for decorative shapes) */
.animate-blob {
    animation: blob-morph 12s ease-in-out infinite;
}

@keyframes blob-morph {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    25% {
        transform: translate(10px, -10px) scale(1.05);
    }
    50% {
        transform: translate(-5px, 15px) scale(0.95);
    }
    75% {
        transform: translate(-15px, -5px) scale(1.02);
    }
}

/* ============================================
   PAGE TRANSITION HELPERS
   ============================================ */

.page-transition-enter {
    animation: page-enter 0.3s ease-out forwards;
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-transition-exit {
    animation: page-exit 0.2s ease-in forwards;
}

@keyframes page-exit {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Delay Variants */
.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; }

/* Duration Variants */
.duration-150 { animation-duration: 150ms; }
.duration-200 { animation-duration: 200ms; }
.duration-300 { animation-duration: 300ms; }
.duration-500 { animation-duration: 500ms; }
.duration-700 { animation-duration: 700ms; }
.duration-1000 { animation-duration: 1000ms; }

/* Animation Fill Mode */
.fill-forwards { animation-fill-mode: forwards; }
.fill-backwards { animation-fill-mode: backwards; }
.fill-both { animation-fill-mode: both; }

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    /* Preserve essential loading indicators */
    .animate-spin,
    .loading-dots,
    .animate-shimmer {
        animation: none;
    }
    
    .animate-spin {
        opacity: 0.7;
    }
    
    /* Disable parallax and floating effects */
    .parallax,
    .animate-float,
    .animate-float-rotate,
    .animate-blob {
        animation: none;
        transform: none;
    }
    
    /* Keep scroll reveals instant */
    .scroll-reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }
}
