/**
 * Ice Arena Design System - Animations v2
 * Micro-interactions and motion library
 *
 * Features:
 * - Entrance animations
 * - Attention seekers
 * - Loading states
 * - Scroll-triggered animations
 *
 * Version: 2.0
 * Date: November 2025
 */

/* =========================================
   KEYFRAME DEFINITIONS
   ========================================= */

/* Fade animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

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

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

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

/* Scale animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    70% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        transform: scale(1.1);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Slide animations */
@keyframes slideInUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

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

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

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

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

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

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

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-4px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(4px);
    }
}

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

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: translateY(-12px);
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

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

@keyframes flash {
    0%, 50%, 100% {
        opacity: 1;
    }
    25%, 75% {
        opacity: 0;
    }
}

/* Loading animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes spinReverse {
    from {
        transform: rotate(360deg);
    }
    to {
        transform: rotate(0deg);
    }
}

@keyframes spinnerDash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes progressIndeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(200%);
    }
}

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

/* Glow effects */
@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 5px currentColor, 0 0 10px currentColor;
    }
    50% {
        box-shadow: 0 0 15px currentColor, 0 0 25px currentColor;
    }
}

@keyframes borderGlow {
    0%, 100% {
        border-color: var(--ice-400);
        box-shadow: 0 0 5px var(--ice-400);
    }
    50% {
        border-color: var(--ice-500);
        box-shadow: 0 0 15px var(--ice-500);
    }
}

/* Hockey-themed animations */
@keyframes puckDrop {
    0% {
        opacity: 0;
        transform: translateY(-40px) rotate(-180deg);
    }
    60% {
        transform: translateY(5px) rotate(10deg);
    }
    80% {
        transform: translateY(-3px) rotate(-5deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
}

@keyframes iceSlide {
    from {
        opacity: 0;
        transform: translateX(-30px) skewX(-5deg);
    }
    to {
        opacity: 1;
        transform: translateX(0) skewX(0deg);
    }
}

@keyframes goalFlash {
    0%, 100% {
        background-color: transparent;
    }
    25%, 75% {
        background-color: rgba(220, 38, 38, 0.1);
    }
    50% {
        background-color: rgba(220, 38, 38, 0.2);
    }
}

/* =========================================
   ANIMATION UTILITY CLASSES
   ========================================= */

/* Base animation properties */
.animate {
    animation-duration: var(--duration-normal);
    animation-timing-function: var(--ease-out);
    animation-fill-mode: both;
}

/* Duration modifiers */
.animate-fastest { animation-duration: var(--duration-fastest); }
.animate-fast { animation-duration: var(--duration-fast); }
.animate-normal { animation-duration: var(--duration-normal); }
.animate-slow { animation-duration: var(--duration-slow); }
.animate-slower { animation-duration: var(--duration-slower); }

/* Delay modifiers */
.animate-delay-100 { animation-delay: 100ms; }
.animate-delay-200 { animation-delay: 200ms; }
.animate-delay-300 { animation-delay: 300ms; }
.animate-delay-500 { animation-delay: 500ms; }
.animate-delay-700 { animation-delay: 700ms; }
.animate-delay-1000 { animation-delay: 1000ms; }

/* Iteration modifiers */
.animate-once { animation-iteration-count: 1; }
.animate-twice { animation-iteration-count: 2; }
.animate-infinite { animation-iteration-count: infinite; }

/* Easing modifiers */
.animate-ease-linear { animation-timing-function: linear; }
.animate-ease-in { animation-timing-function: var(--ease-in); }
.animate-ease-out { animation-timing-function: var(--ease-out); }
.animate-ease-in-out { animation-timing-function: var(--ease-in-out); }
.animate-ease-spring { animation-timing-function: var(--ease-spring); }
.animate-ease-bounce { animation-timing-function: var(--ease-bounce); }

/* Fade animations */
.animate-fadeIn { animation-name: fadeIn; }
.animate-fadeOut { animation-name: fadeOut; }
.animate-fadeInUp { animation-name: fadeInUp; }
.animate-fadeInDown { animation-name: fadeInDown; }
.animate-fadeInLeft { animation-name: fadeInLeft; }
.animate-fadeInRight { animation-name: fadeInRight; }

/* Scale animations */
.animate-scaleIn { animation-name: scaleIn; }
.animate-scaleOut { animation-name: scaleOut; }
.animate-popIn { animation-name: popIn; }
.animate-bounceIn { animation-name: bounceIn; }

/* Slide animations */
.animate-slideInUp { animation-name: slideInUp; }
.animate-slideInDown { animation-name: slideInDown; }
.animate-slideInLeft { animation-name: slideInLeft; }
.animate-slideInRight { animation-name: slideInRight; }
.animate-slideOutUp { animation-name: slideOutUp; }
.animate-slideOutDown { animation-name: slideOutDown; }

/* Attention seekers */
.animate-pulse { animation-name: pulse; animation-iteration-count: infinite; }
.animate-shake { animation-name: shake; }
.animate-wiggle { animation-name: wiggle; animation-iteration-count: infinite; }
.animate-bounce { animation-name: bounce; animation-iteration-count: infinite; }
.animate-ping { animation-name: ping; animation-iteration-count: infinite; }
.animate-flash { animation-name: flash; }

/* Loading animations */
.animate-spin { animation-name: spin; animation-iteration-count: infinite; animation-timing-function: linear; }
.animate-spin-reverse { animation-name: spinReverse; animation-iteration-count: infinite; animation-timing-function: linear; }

/* Hockey-themed */
.animate-puckDrop { animation-name: puckDrop; animation-duration: 600ms; animation-timing-function: var(--ease-bounce); }
.animate-iceSlide { animation-name: iceSlide; animation-duration: 500ms; }
.animate-goalFlash { animation-name: goalFlash; animation-duration: 1s; animation-iteration-count: 3; }

/* =========================================
   SCROLL-TRIGGERED ANIMATIONS
   Use with Intersection Observer
   ========================================= */

/* Initial hidden state for scroll animations */
[data-animate] {
    opacity: 0;
}

[data-animate].is-visible {
    opacity: 1;
}

[data-animate="fadeIn"].is-visible {
    animation: fadeIn var(--duration-normal) var(--ease-out) forwards;
}

[data-animate="fadeInUp"].is-visible {
    animation: fadeInUp var(--duration-normal) var(--ease-out) forwards;
}

[data-animate="fadeInDown"].is-visible {
    animation: fadeInDown var(--duration-normal) var(--ease-out) forwards;
}

[data-animate="fadeInLeft"].is-visible {
    animation: fadeInLeft var(--duration-normal) var(--ease-out) forwards;
}

[data-animate="fadeInRight"].is-visible {
    animation: fadeInRight var(--duration-normal) var(--ease-out) forwards;
}

[data-animate="scaleIn"].is-visible {
    animation: scaleIn var(--duration-normal) var(--ease-spring) forwards;
}

[data-animate="popIn"].is-visible {
    animation: popIn var(--duration-normal) var(--ease-spring) forwards;
}

[data-animate="iceSlide"].is-visible {
    animation: iceSlide var(--duration-slow) var(--ease-out) forwards;
}

/* Stagger children animations */
[data-animate-stagger] > * {
    opacity: 0;
}

[data-animate-stagger].is-visible > *:nth-child(1) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 0ms; }
[data-animate-stagger].is-visible > *:nth-child(2) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 100ms; }
[data-animate-stagger].is-visible > *:nth-child(3) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 200ms; }
[data-animate-stagger].is-visible > *:nth-child(4) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 300ms; }
[data-animate-stagger].is-visible > *:nth-child(5) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 400ms; }
[data-animate-stagger].is-visible > *:nth-child(6) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 500ms; }
[data-animate-stagger].is-visible > *:nth-child(n+7) { animation: fadeInUp var(--duration-normal) var(--ease-out) forwards; animation-delay: 600ms; }

/* =========================================
   LOADING COMPONENTS
   ========================================= */

/* Spinner */
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--ice-200);
    border-top-color: var(--ice-500);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.spinner-lg {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

.spinner-xl {
    width: 56px;
    height: 56px;
    border-width: 5px;
}

/* Dot loader */
.dots-loader {
    display: inline-flex;
    gap: var(--space-2);
}

.dots-loader .dot {
    width: 10px;
    height: 10px;
    background: var(--ice-500);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.dots-loader .dot:nth-child(1) { animation-delay: 0s; }
.dots-loader .dot:nth-child(2) { animation-delay: 0.2s; }
.dots-loader .dot:nth-child(3) { animation-delay: 0.4s; }

/* Progress bar indeterminate */
.progress-indeterminate {
    position: relative;
    height: 4px;
    background: var(--ice-100);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-indeterminate::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    animation: progressIndeterminate 1.5s ease-in-out infinite;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--rink-100) 25%,
        var(--rink-200) 50%,
        var(--rink-100) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-heading {
    height: 1.5em;
    width: 60%;
    margin-bottom: var(--space-3);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--radius-lg);
}

.skeleton-button {
    width: 120px;
    height: 40px;
    border-radius: var(--radius-lg);
}

/* =========================================
   TRANSITION UTILITIES
   ========================================= */

.transition-none { transition: none; }
.transition-all { transition-property: all; }
.transition-default {
    transition-property: color, background-color, border-color, box-shadow, transform, opacity;
    transition-duration: var(--duration-normal);
    transition-timing-function: var(--ease-out);
}
.transition-colors {
    transition-property: color, background-color, border-color;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease-out);
}
.transition-opacity {
    transition-property: opacity;
    transition-duration: var(--duration-normal);
    transition-timing-function: var(--ease-out);
}
.transition-transform {
    transition-property: transform;
    transition-duration: var(--duration-normal);
    transition-timing-function: var(--ease-spring);
}
.transition-shadow {
    transition-property: box-shadow;
    transition-duration: var(--duration-normal);
    transition-timing-function: var(--ease-out);
}

/* =========================================
   HOVER TRANSFORM UTILITIES
   ========================================= */

.hover-lift {
    transition: transform var(--duration-normal) var(--ease-spring);
}

.hover-lift:hover {
    transform: translateY(-4px);
}

.hover-scale {
    transition: transform var(--duration-normal) var(--ease-spring);
}

.hover-scale:hover {
    transform: scale(1.02);
}

.hover-scale-lg:hover {
    transform: scale(1.05);
}

.hover-glow {
    transition: box-shadow var(--duration-normal) var(--ease-out);
}

.hover-glow:hover {
    box-shadow: var(--shadow-glow-blue-lg);
}

.hover-glow-red:hover {
    box-shadow: var(--shadow-glow-red-lg);
}

/* =========================================
   MOBILE-FIRST RESPONSIVE ANIMATIONS
   ========================================= */

/*
 * Mobile Base (< 640px)
 * - Simpler, shorter animations for performance
 * - Smaller translation distances
 * - Touch-friendly alternatives to hover
 * - Reduced battery usage
 */

/* Mobile: Use simpler fade-only animations */
@keyframes fadeInUpMobile {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Mobile: Shorter animation distances */
.animate-fadeInUp {
    animation-name: fadeInUpMobile;
    animation-duration: var(--duration-fast);
}

.animate-fadeInDown {
    animation-name: fadeInDown;
    --translate-distance: 12px;
}

.animate-fadeInLeft,
.animate-fadeInRight {
    animation-duration: var(--duration-fast);
}

/* Mobile: Disable complex hover transforms (touch doesn't have hover) */
.hover-lift:hover,
.hover-scale:hover,
.hover-scale-lg:hover {
    transform: none;
}

/* Mobile: Use active states instead of hover for touch feedback */
.hover-lift:active {
    transform: scale(0.98);
}

.hover-scale:active,
.hover-scale-lg:active {
    transform: scale(0.98);
}

/* Mobile: Simplified stagger - only first 4 items */
[data-animate-stagger].is-visible > *:nth-child(n+5) {
    animation-delay: 200ms;
}

/* Mobile: Smaller spinner sizes */
.spinner-xl {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

/* Mobile: Skeleton animation optimization */
.skeleton {
    animation-duration: 2s; /* Slower = less battery drain */
}

/*
 * Small screens and up (640px+)
 * - Restore fuller animations
 */
@media (min-width: 640px) {
    .animate-fadeInUp {
        animation-name: fadeInUp;
        animation-duration: var(--duration-normal);
    }

    /* Restore hover transforms on devices with hover capability */
    @media (hover: hover) {
        .hover-lift:hover {
            transform: translateY(-4px);
        }

        .hover-scale:hover {
            transform: scale(1.02);
        }

        .hover-scale-lg:hover {
            transform: scale(1.05);
        }
    }

    .skeleton {
        animation-duration: 1.5s;
    }
}

/*
 * Tablet and up (768px+)
 * - Full animation capabilities
 */
@media (min-width: 768px) {
    .spinner-xl {
        width: 56px;
        height: 56px;
        border-width: 5px;
    }

    /* Full stagger timing restored */
    [data-animate-stagger].is-visible > *:nth-child(5) { animation-delay: 400ms; }
    [data-animate-stagger].is-visible > *:nth-child(6) { animation-delay: 500ms; }
    [data-animate-stagger].is-visible > *:nth-child(n+7) { animation-delay: 600ms; }
}

/*
 * Desktop and up (1024px+)
 * - Full complex animations
 * - Longer hover effects
 */
@media (min-width: 1024px) {
    /* Hover lift can be more pronounced on desktop */
    @media (hover: hover) {
        .hover-lift:hover {
            transform: translateY(-6px);
        }
    }
}

/* =========================================
   TOUCH DEVICE OPTIMIZATIONS
   ========================================= */

/* Detect touch-only devices */
@media (hover: none) and (pointer: coarse) {
    /* Disable all hover-based animations */
    .hover-lift,
    .hover-scale,
    .hover-scale-lg,
    .hover-glow {
        transition: transform var(--duration-fast) var(--ease-out);
    }

    .hover-lift:hover,
    .hover-scale:hover,
    .hover-scale-lg:hover {
        transform: none;
    }

    .hover-glow:hover {
        box-shadow: none;
    }

    /* Active states for touch feedback */
    .hover-lift:active,
    .hover-scale:active,
    .hover-scale-lg:active {
        transform: scale(0.97);
        transition-duration: var(--duration-fastest);
    }

    /* Disable infinite animations that drain battery */
    .animate-pulse,
    .animate-wiggle,
    .animate-bounce,
    .animate-ping {
        animation-iteration-count: 3;
    }

    /* Skeleton slower to save battery */
    .skeleton {
        animation-duration: 2.5s;
    }
}

/* =========================================
   REDUCED MOTION
   ========================================= */

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

    [data-animate],
    [data-animate-stagger] > * {
        opacity: 1;
        animation: none !important;
    }

    .spinner,
    .dots-loader .dot,
    .progress-indeterminate::after,
    .skeleton {
        animation: none;
    }

    /* Static fallback for spinner */
    .spinner {
        border-color: var(--ice-500);
        border-top-color: transparent;
        border-right-color: transparent;
    }

    /* Static fallback for skeleton */
    .skeleton {
        background: var(--rink-100);
    }

    .hover-lift:hover,
    .hover-scale:hover,
    .hover-scale-lg:hover {
        transform: none;
    }

    /* Ensure touch active states still work for feedback */
    .hover-lift:active,
    .hover-scale:active,
    .hover-scale-lg:active {
        transform: scale(0.98);
        transition-duration: 0.01ms !important;
    }
}

/* =========================================
   JAVASCRIPT HELPER
   Intersection Observer for scroll animations
   ========================================= */

/*
Add this JavaScript to enable scroll animations:

const observerOptions = {
    threshold: 0.1,
    rootMargin: '0px 0px -50px 0px'
};

const animationObserver = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add('is-visible');
            // Optional: unobserve after animation
            // animationObserver.unobserve(entry.target);
        }
    });
}, observerOptions);

// Observe all elements with data-animate attribute
document.querySelectorAll('[data-animate], [data-animate-stagger]').forEach(el => {
    animationObserver.observe(el);
});
*/
