/**
 * Covenant Path Foundation - Animations
 * iPhone-style appear→bounce entrance animations
 * 
 * Table of Contents:
 * 1. Animation Keyframes
 * 2. Appear & Bounce Animations
 * 3. Scroll-triggered Animations
 * 4. Hover Effects
 * 5. Loading States
 * 6. Special Effects
 */

/* ===================================
   1. Animation Keyframes
   =================================== */

/* Appear from bottom with bounce - iPhone style refined */
@keyframes appearBounce {
    0% {
        opacity: 0;
        transform: translateY(8px) scale(0.995);
    }
    60% {
        opacity: 1;
        transform: translateY(-6px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Appear from left with bounce - iPhone style refined */
@keyframes appearBounceLeft {
    0% {
        opacity: 0;
        transform: translateX(-8px) scale(0.995);
    }
    60% {
        opacity: 1;
        transform: translateX(6px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* Appear from right with bounce - iPhone style refined */
@keyframes appearBounceRight {
    0% {
        opacity: 0;
        transform: translateX(8px) scale(0.995);
    }
    60% {
        opacity: 1;
        transform: translateX(-6px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* Scale up with bounce - iPhone style refined */
@keyframes scaleBounce {
    0% {
        opacity: 0;
        transform: scale(0.96);
    }
    60% {
        opacity: 1;
        transform: scale(1.03);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Fade in only */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Slide up */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide down */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide in from top (for notifications/alerts) */
@keyframes slideInTop {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Rotate in */
@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-10deg) scale(0.9);
    }
    to {
        opacity: 1;
        transform: rotate(0) scale(1);
    }
}

/* Pulse */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Shake */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* Float up and down */
@keyframes floatUpDown {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Shimmer effect */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Gradient shift */
@keyframes gradientShift {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* CPF Gradient shift animation - light-blue palette */
@keyframes cpfGradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Hero gradient with CPF light-blue palette */
.hero-gradient {
    background: var(--cpf-gradient, linear-gradient(90deg, #4DA8F7 0%, #2EA3FF 100%));
    background-size: 200% 200%;
    animation: cpfGradientShift 12s ease infinite;
}

/* CPF gradient text */
.cpf-gradient-text {
    background: var(--cpf-gradient, linear-gradient(90deg, #4DA8F7 0%, #2EA3FF 100%));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Glow pulse - using CPF Light-Blue palette */
@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 5px rgba(77, 168, 247, 0.3),
                    0 0 10px rgba(77, 168, 247, 0.2),
                    0 0 15px rgba(77, 168, 247, 0.1);
    }
    50% {
        box-shadow: 0 0 10px rgba(77, 168, 247, 0.5),
                    0 0 20px rgba(77, 168, 247, 0.3),
                    0 0 30px rgba(77, 168, 247, 0.2);
    }
}

/* Counter animation */
@keyframes countUp {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ===================================
   2. Appear & Bounce Animations
   =================================== */

/* Hero animation - longer duration for emphasis */
.animate-hero {
    animation: appearBounce 420ms cubic-bezier(0.2, 1.1, 0.3, 1) both;
}

/* Card animation - snappier for UI elements */
.animate-card {
    animation: appearBounce 320ms cubic-bezier(0.2, 1.1, 0.3, 1) both;
}

/* Base class for appear→bounce effect */
.animate-appear-bounce {
    opacity: 0;
    animation: appearBounce 420ms cubic-bezier(0.2, 1.1, 0.3, 1) forwards;
    animation-delay: var(--animation-delay, 0s);
}

.animate-appear-bounce-left {
    opacity: 0;
    animation: appearBounceLeft 420ms cubic-bezier(0.2, 1.1, 0.3, 1) forwards;
    animation-delay: var(--animation-delay, 0s);
}

.animate-appear-bounce-right {
    opacity: 0;
    animation: appearBounceRight 420ms cubic-bezier(0.2, 1.1, 0.3, 1) forwards;
    animation-delay: var(--animation-delay, 0s);
}

.animate-scale-bounce {
    opacity: 0;
    animation: scaleBounce 420ms cubic-bezier(0.2, 1.1, 0.3, 1) forwards;
    animation-delay: var(--animation-delay, 0s);
}

/* Simple animations */
.animate-fade-in {
    opacity: 0;
    animation: fadeIn 0.6s ease forwards;
    animation-delay: var(--animation-delay, 0s);
}

.animate-slide-up {
    opacity: 0;
    animation: slideUp 0.6s ease forwards;
    animation-delay: var(--animation-delay, 0s);
}

.animate-slide-down {
    opacity: 0;
    animation: slideDown 0.6s ease forwards;
    animation-delay: var(--animation-delay, 0s);
}

/* Alert/notification animation */
.animate-appear {
    opacity: 0;
    animation: slideInTop 0.4s cubic-bezier(0.2, 1.1, 0.3, 1) forwards;
}

/* iPhone-style spring animation for interactive elements */
.animate-spring {
    transition: transform 0.4s cubic-bezier(0.2, 1.1, 0.3, 1);
}

.animate-spring:active {
    transform: scale(0.95);
}

/* ===================================
   3. Scroll-triggered Animations
   =================================== */

/* Elements that animate when scrolled into view */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: var(--animation-delay, 0s);
}

.animate-on-scroll.animated {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger animation for lists */
.animate-stagger > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.animate-stagger.animated > *:nth-child(1) { transition-delay: 0.05s; }
.animate-stagger.animated > *:nth-child(2) { transition-delay: 0.1s; }
.animate-stagger.animated > *:nth-child(3) { transition-delay: 0.15s; }
.animate-stagger.animated > *:nth-child(4) { transition-delay: 0.2s; }
.animate-stagger.animated > *:nth-child(5) { transition-delay: 0.25s; }
.animate-stagger.animated > *:nth-child(6) { transition-delay: 0.3s; }
.animate-stagger.animated > *:nth-child(7) { transition-delay: 0.35s; }
.animate-stagger.animated > *:nth-child(8) { transition-delay: 0.4s; }

.animate-stagger.animated > * {
    opacity: 1;
    transform: translateY(0);
}

/* Scale on scroll */
.animate-scale-on-scroll {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: var(--animation-delay, 0s);
}

.animate-scale-on-scroll.animated {
    opacity: 1;
    transform: scale(1);
}

/* Slide from left on scroll */
.animate-slide-left-on-scroll {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: var(--animation-delay, 0s);
}

.animate-slide-left-on-scroll.animated {
    opacity: 1;
    transform: translateX(0);
}

/* Slide from right on scroll */
.animate-slide-right-on-scroll {
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: var(--animation-delay, 0s);
}

.animate-slide-right-on-scroll.animated {
    opacity: 1;
    transform: translateX(0);
}

/* ===================================
   4. Hover Effects
   =================================== */

/* Lift effect */
.hover-lift {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Scale effect */
.hover-scale {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hover-scale:hover {
    transform: scale(1.05);
}

/* Glow effect */
.hover-glow {
    transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(77, 168, 247, 0.4);
}

/* Rotate effect */
.hover-rotate {
    transition: transform 0.3s ease;
}

.hover-rotate:hover {
    transform: rotate(5deg);
}

/* Underline effect */
.hover-underline {
    position: relative;
}

.hover-underline::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-gradient);
    transition: width 0.3s ease;
}

.hover-underline:hover::after {
    width: 100%;
}

/* Button press effect */
.hover-press {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.hover-press:hover {
    transform: translateY(-2px);
}

.hover-press:active {
    transform: translateY(1px);
    box-shadow: none;
}

/* Card tilt effect (3D) */
.hover-tilt {
    transition: transform 0.3s ease;
    transform-style: preserve-3d;
}

.hover-tilt:hover {
    transform: perspective(1000px) rotateX(2deg) rotateY(-2deg);
}

/* Icon bounce on hover */
.hover-icon-bounce:hover i,
.hover-icon-bounce:hover .icon {
    animation: appearBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===================================
   5. Loading States
   =================================== */

/* Spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(77, 168, 247, 0.2);
    border-top-color: var(--primary-color, #4DA8F7);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Dots loading */
.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-200) 25%,
        var(--gray-100) 50%,
        var(--gray-200) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.skeleton-image {
    height: 200px;
}

/* ===================================
   6. Special Effects
   =================================== */

/* Gradient text animation */
.animate-gradient-text {
    background: linear-gradient(
        90deg,
        var(--primary-color),
        var(--secondary-color),
        var(--primary-color)
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 3s linear infinite;
}

/* Glowing border */
.animate-glow-border {
    position: relative;
}

.animate-glow-border::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: var(--primary-gradient);
    border-radius: inherit;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.animate-glow-border:hover::before {
    opacity: 1;
    animation: glowPulse 2s ease-in-out infinite;
}

/* Ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Parallax effect placeholder class */
.parallax {
    will-change: transform;
}

/* Count-up number animation helper */
.count-up {
    display: inline-block;
}

/* Attention grabber - subtle pulse */
.animate-attention {
    animation: pulse 2s ease-in-out infinite;
}

/* Success checkmark animation */
.animate-checkmark {
    width: 56px;
    height: 56px;
}

.animate-checkmark circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.animate-checkmark path {
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.4s forwards;
}

@keyframes stroke {
    to {
        stroke-dashoffset: 0;
    }
}

/* Floating animation for decorative elements */
.animate-float {
    animation: floatUpDown 3s ease-in-out infinite;
}

.animate-float-delayed {
    animation: floatUpDown 3s ease-in-out 1.5s infinite;
}

/* Blur-in effect */
.animate-blur-in {
    opacity: 0;
    filter: blur(10px);
    animation: blurIn 0.8s ease forwards;
    animation-delay: var(--animation-delay, 0s);
}

@keyframes blurIn {
    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* Typewriter effect helper */
.typewriter {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--primary-color);
    animation: typing 3s steps(40) forwards, blink 0.75s step-end infinite;
}

@keyframes typing {
    from {
        width: 0;
    }
    to {
        width: 100%;
    }
}

@keyframes blink {
    50% {
        border-color: transparent;
    }
}

/* Glass morphism hover effect */
.glass-hover {
    transition: all 0.3s ease;
}

.glass-hover:hover {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Magnetic button effect helper class */
.magnetic {
    transition: transform 0.3s cubic-bezier(0.2, 1.1, 0.3, 1);
}

/* Image reveal effect */
.image-reveal {
    position: relative;
    overflow: hidden;
}

.image-reveal img {
    transform: scale(1.2);
    opacity: 0;
    transition: transform 0.8s ease, opacity 0.8s ease;
}

.image-reveal.animated img {
    transform: scale(1);
    opacity: 1;
}

/* Text reveal effect */
.text-reveal {
    overflow: hidden;
}

.text-reveal span {
    display: inline-block;
    transform: translateY(100%);
    transition: transform 0.6s cubic-bezier(0.2, 1.1, 0.3, 1);
    transition-delay: var(--animation-delay, 0s);
}

.text-reveal.animated span {
    transform: translateY(0);
}

/* Morphing shape background */
.morphing-bg {
    position: relative;
}

.morphing-bg::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    animation: morph 8s ease-in-out infinite;
    z-index: -1;
}

@keyframes morph {
    0%, 100% {
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    }
    50% {
        border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
    }
}

/* ===================================
   Stagger Animation Support
   =================================== */

/* Use [data-stagger] attribute for staggered animations */
[data-stagger] > *:nth-child(1) { animation-delay: 0.05s; }
[data-stagger] > *:nth-child(2) { animation-delay: 0.1s; }
[data-stagger] > *:nth-child(3) { animation-delay: 0.15s; }
[data-stagger] > *:nth-child(4) { animation-delay: 0.2s; }
[data-stagger] > *:nth-child(5) { animation-delay: 0.25s; }
[data-stagger] > *:nth-child(6) { animation-delay: 0.3s; }
[data-stagger] > *:nth-child(7) { animation-delay: 0.35s; }
[data-stagger] > *:nth-child(8) { animation-delay: 0.4s; }

/* ===================================
   Accessibility: Reduced Motion
   =================================== */

@media (prefers-reduced-motion: reduce) {
    .animate-hero,
    .animate-card,
    .animate-appear-bounce,
    .animate-appear-bounce-left,
    .animate-appear-bounce-right,
    .animate-scale-bounce,
    .animate-fade-in,
    .animate-slide-up,
    .animate-slide-down,
    .animate-on-scroll,
    .animate-stagger > * {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    
    .morphing-bg::before {
        animation: none !important;
    }
    
    .pulse-glow,
    .floating,
    .hero-gradient {
        animation: none !important;
    }
}
