/**
 * Hampstead Academy Animation System - CSS Animations
 * Comprehensive animation library with 35+ animations
 */

/* ===== ANIMATION BASE STYLES ===== */

.ha-animated {
    animation-fill-mode: both;
    animation-timing-function: var(--ha-animation-easing, ease);
    animation-duration: var(--ha-animation-duration, 1s);
    animation-delay: var(--ha-animation-delay, 0s);
    animation-iteration-count: var(--ha-animation-repeat, 1);
    animation-direction: var(--ha-animation-direction, normal);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .ha-animated {
        animation: none !important;
        transition: none !important;
    }
}

/* Initial state for scroll-triggered animations */
.ha-trigger-scroll:not(.ha-animate-active) {
    opacity: 0;
    visibility: hidden;
}

.ha-trigger-scroll.ha-animate-active {
    opacity: 1;
    visibility: visible;
}

/* ===== ENTRANCE ANIMATIONS ===== */

/* Fade In */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.ha-animation-fadeIn { animation-name: fadeIn; }

/* Slide In Left */
@keyframes slideInLeft {
    from {
        transform: translate3d(-100%, 0, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}
.ha-animation-slideInLeft { animation-name: slideInLeft; }

/* Slide In Right */
@keyframes slideInRight {
    from {
        transform: translate3d(100%, 0, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}
.ha-animation-slideInRight { animation-name: slideInRight; }

/* Slide In Up */
@keyframes slideInUp {
    from {
        transform: translate3d(0, 100%, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}
.ha-animation-slideInUp { animation-name: slideInUp; }

/* Slide In Down */
@keyframes slideInDown {
    from {
        transform: translate3d(0, -100%, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}
.ha-animation-slideInDown { animation-name: slideInDown; }

/* Zoom In */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale3d(0.3, 0.3, 0.3);
    }
    50% {
        opacity: 1;
    }
    to {
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-zoomIn { animation-name: zoomIn; }

/* Zoom Out */
@keyframes zoomOut {
    from {
        opacity: 0;
        transform: scale3d(1.5, 1.5, 1.5);
    }
    50% {
        opacity: 1;
    }
    to {
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-zoomOut { animation-name: zoomOut; }

/* Bounce In */
@keyframes bounceIn {
    from, 20%, 40%, 60%, 80%, to {
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }
    0% {
        opacity: 0;
        transform: scale3d(0.3, 0.3, 0.3);
    }
    20% {
        transform: scale3d(1.1, 1.1, 1.1);
    }
    40% {
        transform: scale3d(0.9, 0.9, 0.9);
    }
    60% {
        opacity: 1;
        transform: scale3d(1.03, 1.03, 1.03);
    }
    80% {
        transform: scale3d(0.97, 0.97, 0.97);
    }
    to {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-bounceIn { animation-name: bounceIn; }

/* Flip In X */
@keyframes flipInX {
    from {
        transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
        animation-timing-function: ease-in;
        opacity: 0;
    }
    40% {
        transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
        animation-timing-function: ease-in;
    }
    60% {
        transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
        opacity: 1;
    }
    80% {
        transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
    }
    to {
        transform: perspective(400px);
    }
}
.ha-animation-flipInX { animation-name: flipInX; }

/* Flip In Y */
@keyframes flipInY {
    from {
        transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
        animation-timing-function: ease-in;
        opacity: 0;
    }
    40% {
        transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
        animation-timing-function: ease-in;
    }
    60% {
        transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
        opacity: 1;
    }
    80% {
        transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
    }
    to {
        transform: perspective(400px);
    }
}
.ha-animation-flipInY { animation-name: flipInY; }

/* Rotate In */
@keyframes rotateIn {
    from {
        transform-origin: center;
        transform: rotate3d(0, 0, 1, -200deg);
        opacity: 0;
    }
    to {
        transform-origin: center;
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}
.ha-animation-rotateIn { animation-name: rotateIn; }

/* Roll In */
@keyframes rollIn {
    from {
        opacity: 0;
        transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}
.ha-animation-rollIn { animation-name: rollIn; }

/* Light Speed In */
@keyframes lightSpeedIn {
    from {
        transform: translate3d(100%, 0, 0) skewX(-30deg);
        opacity: 0;
    }
    60% {
        transform: skewX(20deg);
        opacity: 1;
    }
    80% {
        transform: skewX(-5deg);
    }
    to {
        transform: translate3d(0, 0, 0);
    }
}
.ha-animation-lightSpeedIn { animation-name: lightSpeedIn; }

/* Swing In */
@keyframes swingIn {
    0% {
        transform: rotate3d(0, 0, 1, 15deg);
        opacity: 0;
    }
    20% {
        transform: rotate3d(0, 0, 1, 10deg);
        opacity: 1;
    }
    40% {
        transform: rotate3d(0, 0, 1, -10deg);
    }
    60% {
        transform: rotate3d(0, 0, 1, 5deg);
    }
    80% {
        transform: rotate3d(0, 0, 1, -5deg);
    }
    to {
        transform: rotate3d(0, 0, 1, 0deg);
    }
}
.ha-animation-swingIn { animation-name: swingIn; }

/* Wobble In */
@keyframes wobbleIn {
    from {
        transform: translate3d(-100%, 0, 0);
        opacity: 0;
    }
    15% {
        transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
        opacity: 1;
    }
    30% {
        transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
    }
    45% {
        transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
    }
    60% {
        transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
    }
    75% {
        transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
    }
    to {
        transform: translate3d(0, 0, 0);
    }
}
.ha-animation-wobbleIn { animation-name: wobbleIn; }

/* ===== ATTENTION SEEKERS ===== */

/* Bounce */
@keyframes bounce {
    from, 20%, 53%, 80%, to {
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
        transform: translate3d(0, 0, 0);
    }
    40%, 43% {
        animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
        transform: translate3d(0, -30px, 0);
    }
    70% {
        animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
        transform: translate3d(0, -15px, 0);
    }
    90% {
        transform: translate3d(0, -4px, 0);
    }
}
.ha-animation-bounce { animation-name: bounce; }

/* Flash */
@keyframes flash {
    from, 50%, to {
        opacity: 1;
    }
    25%, 75% {
        opacity: 0;
    }
}
.ha-animation-flash { animation-name: flash; }

/* Pulse */
@keyframes pulse {
    from {
        transform: scale3d(1, 1, 1);
    }
    50% {
        transform: scale3d(1.05, 1.05, 1.05);
    }
    to {
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-pulse { animation-name: pulse; }

/* Rubber Band */
@keyframes rubberBand {
    from {
        transform: scale3d(1, 1, 1);
    }
    30% {
        transform: scale3d(1.25, 0.75, 1);
    }
    40% {
        transform: scale3d(0.75, 1.25, 1);
    }
    50% {
        transform: scale3d(1.15, 0.85, 1);
    }
    65% {
        transform: scale3d(0.95, 1.05, 1);
    }
    75% {
        transform: scale3d(1.05, 0.95, 1);
    }
    to {
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-rubberBand { animation-name: rubberBand; }

/* Shake */
@keyframes shake {
    from, to {
        transform: translate3d(0, 0, 0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translate3d(-10px, 0, 0);
    }
    20%, 40%, 60%, 80% {
        transform: translate3d(10px, 0, 0);
    }
}
.ha-animation-shake { animation-name: shake; }

/* Swing */
@keyframes swing {
    20% {
        transform: rotate3d(0, 0, 1, 15deg);
    }
    40% {
        transform: rotate3d(0, 0, 1, -10deg);
    }
    60% {
        transform: rotate3d(0, 0, 1, 5deg);
    }
    80% {
        transform: rotate3d(0, 0, 1, -5deg);
    }
    to {
        transform: rotate3d(0, 0, 1, 0deg);
    }
}
.ha-animation-swing { animation-name: swing; }

/* Tada */
@keyframes tada {
    from {
        transform: scale3d(1, 1, 1);
    }
    10%, 20% {
        transform: scale3d(0.9, 0.9, 0.9) rotate3d(0, 0, 1, -3deg);
    }
    30%, 50%, 70%, 90% {
        transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
    }
    40%, 60%, 80% {
        transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
    }
    to {
        transform: scale3d(1, 1, 1);
    }
}
.ha-animation-tada { animation-name: tada; }

/* Wobble */
@keyframes wobble {
    from {
        transform: translate3d(0, 0, 0);
    }
    15% {
        transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
    }
    30% {
        transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
    }
    45% {
        transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
    }
    60% {
        transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
    }
    75% {
        transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
    }
    to {
        transform: translate3d(0, 0, 0);
    }
}
.ha-animation-wobble { animation-name: wobble; }

/* Jello */
@keyframes jello {
    from, 11.1%, to {
        transform: translate3d(0, 0, 0);
    }
    22.2% {
        transform: skewX(-12.5deg) skewY(-12.5deg);
    }
    33.3% {
        transform: skewX(6.25deg) skewY(6.25deg);
    }
    44.4% {
        transform: skewX(-3.125deg) skewY(-3.125deg);
    }
    55.5% {
        transform: skewX(1.5625deg) skewY(1.5625deg);
    }
    66.6% {
        transform: skewX(-0.78125deg) skewY(-0.78125deg);
    }
    77.7% {
        transform: skewX(0.390625deg) skewY(0.390625deg);
    }
    88.8% {
        transform: skewX(-0.1953125deg) skewY(-0.1953125deg);
    }
}
.ha-animation-jello { animation-name: jello; }

/* Heart Beat */
@keyframes heartBeat {
    0% {
        transform: scale(1);
    }
    14% {
        transform: scale(1.3);
    }
    28% {
        transform: scale(1);
    }
    42% {
        transform: scale(1.3);
    }
    70% {
        transform: scale(1);
    }
}
.ha-animation-heartBeat { animation-name: heartBeat; }

/* ===== SPECIAL EFFECTS ===== */

/* Slot Machine Numbers */
@keyframes slotMachine {
    0% {
        transform: translateY(0);
    }
    10% {
        transform: translateY(-10%);
    }
    20% {
        transform: translateY(-20%);
    }
    30% {
        transform: translateY(-30%);
    }
    40% {
        transform: translateY(-40%);
    }
    50% {
        transform: translateY(-50%);
    }
    60% {
        transform: translateY(-60%);
    }
    70% {
        transform: translateY(-70%);
    }
    80% {
        transform: translateY(-80%);
    }
    90% {
        transform: translateY(-90%);
    }
    100% {
        transform: translateY(0);
    }
}

.ha-animation-slotMachine {
    animation-name: slotMachine;
    overflow: hidden;
    position: relative;
}

.ha-animation-slotMachine .ha-slot-number {
    display: inline-block;
    animation: slotMachine var(--ha-animation-duration, 2s) var(--ha-animation-easing, ease-out);
}

/* Typewriter Effect */
@keyframes typewriter {
    from {
        width: 0;
    }
    to {
        width: 100%;
    }
}

@keyframes blinkCursor {
    from, to {
        border-color: transparent;
    }
    50% {
        border-color: currentColor;
    }
}

.ha-animation-typewriter {
    overflow: hidden;
    border-right: 2px solid;
    white-space: nowrap;
    animation: typewriter var(--ha-animation-duration, 3s) steps(40, end),
               blinkCursor 0.75s step-end infinite;
}

/* Glitch Effect */
@keyframes glitch {
    0%, 100% {
        transform: translate(0);
    }
    20% {
        transform: translate(-2px, 2px);
    }
    40% {
        transform: translate(-2px, -2px);
    }
    60% {
        transform: translate(2px, 2px);
    }
    80% {
        transform: translate(2px, -2px);
    }
}

@keyframes glitchColor {
    0%, 100% {
        filter: hue-rotate(0deg);
    }
    25% {
        filter: hue-rotate(90deg);
    }
    50% {
        filter: hue-rotate(180deg);
    }
    75% {
        filter: hue-rotate(270deg);
    }
}

.ha-animation-glitch {
    animation: glitch var(--ha-animation-duration, 0.5s) infinite,
               glitchColor var(--ha-animation-duration, 0.5s) infinite;
}

/* Parallax Scroll */
.ha-animation-parallax {
    transform: translateZ(0);
    will-change: transform;
}

/* Morphing Shapes */
@keyframes morphing {
    0%, 100% {
        border-radius: 50% 50% 50% 50%;
        transform: rotate(0deg);
    }
    25% {
        border-radius: 60% 40% 60% 40%;
        transform: rotate(90deg);
    }
    50% {
        border-radius: 40% 60% 40% 60%;
        transform: rotate(180deg);
    }
    75% {
        border-radius: 50% 50% 30% 70%;
        transform: rotate(270deg);
    }
}

.ha-animation-morphing {
    animation: morphing var(--ha-animation-duration, 3s) infinite;
}

/* Particle Effects */
@keyframes particles {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-50px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(0);
    }
}

.ha-animation-particles::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 50%;
    animation: particles var(--ha-animation-duration, 2s) infinite;
}

/* Wave Animation */
@keyframes wave {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.ha-animation-wave {
    animation: wave var(--ha-animation-duration, 2s) infinite;
}

/* Elastic Scale */
@keyframes elasticScale {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(1.25);
    }
    40% {
        transform: scale(0.75);
    }
    50% {
        transform: scale(1.15);
    }
    65% {
        transform: scale(0.95);
    }
    75% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.ha-animation-elasticScale {
    animation: elasticScale var(--ha-animation-duration, 1s);
}

/* Magnetic Hover */
.ha-animation-magneticHover {
    transition: transform 0.3s ease;
    cursor: pointer;
}

.ha-animation-magneticHover:hover {
    transform: scale(1.1) rotate(5deg);
}

/* 3D Flip Cards */
@keyframes flipCard3D {
    0% {
        transform: perspective(400px) rotateY(0);
    }
    100% {
        transform: perspective(400px) rotateY(180deg);
    }
}

.ha-animation-flipCard3D {
    animation: flipCard3D var(--ha-animation-duration, 1s);
    transform-style: preserve-3d;
}

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

/* Animation speeds */
.ha-speed-slow { animation-duration: 2s !important; }
.ha-speed-normal { animation-duration: 1s !important; }
.ha-speed-fast { animation-duration: 0.5s !important; }
.ha-speed-very-fast { animation-duration: 0.25s !important; }

/* Animation delays */
.ha-delay-1 { animation-delay: 0.1s !important; }
.ha-delay-2 { animation-delay: 0.2s !important; }
.ha-delay-3 { animation-delay: 0.3s !important; }
.ha-delay-4 { animation-delay: 0.4s !important; }
.ha-delay-5 { animation-delay: 0.5s !important; }

/* Animation repeats */
.ha-repeat-infinite { animation-iteration-count: infinite !important; }
.ha-repeat-2 { animation-iteration-count: 2 !important; }
.ha-repeat-3 { animation-iteration-count: 3 !important; }

/* Animation directions */
.ha-direction-reverse { animation-direction: reverse !important; }
.ha-direction-alternate { animation-direction: alternate !important; }
.ha-direction-alternate-reverse { animation-direction: alternate-reverse !important; }

/* ===== RESPONSIVE ADJUSTMENTS ===== */

@media (max-width: 768px) {
    .ha-animated {
        animation-duration: calc(var(--ha-animation-duration, 1s) * 0.8);
    }
    
    /* Reduce motion on mobile for performance */
    .ha-animation-particles,
    .ha-animation-glitch,
    .ha-animation-morphing {
        animation: none;
    }
}

@media (max-width: 480px) {
    .ha-animated {
        animation-duration: calc(var(--ha-animation-duration, 1s) * 0.6);
    }
}

/* ===== ACCESSIBILITY ===== */

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    .ha-animation-glitch {
        filter: none;
    }
}

/* Reduced transparency mode */
@media (prefers-reduced-transparency: reduce) {
    .ha-animated {
        opacity: 1 !important;
    }
}

/* Print styles */
@media print {
    .ha-animated {
        animation: none !important;
        transform: none !important;
        opacity: 1 !important;
    }
}
