/**
 * Dark Mode Animations & Transitions
 * Sophisticated animation system for theme switching
 */

/* Theme Switch Animation Classes */
@keyframes themeSwitch {
    0% {
        transform: scale(1) rotate(0deg);
        filter: brightness(1);
    }
    25% {
        transform: scale(0.95) rotate(90deg);
        filter: brightness(0.8);
    }
    50% {
        transform: scale(0.9) rotate(180deg);
        filter: brightness(0.6);
    }
    75% {
        transform: scale(0.95) rotate(270deg);
        filter: brightness(0.8);
    }
    100% {
        transform: scale(1) rotate(360deg);
        filter: brightness(1);
    }
}

/* Ripple Animation for Theme Change */
@keyframes themeRipple {
    0% {
        width: 0;
        height: 0;
        opacity: 1;
    }
    100% {
        width: 200vmax;
        height: 200vmax;
        opacity: 0;
    }
}

.theme-ripple {
    position: fixed;
    border-radius: 50%;
    background: var(--gradient-primary);
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: themeRipple 1s ease-out;
    z-index: 9999;
}

/* Smooth Color Transitions - Simplified to prevent artifacts */
.theme-transitioning {
    position: relative;
}

@keyframes fadeInOut {
    0% { opacity: 0; }
    50% { opacity: 0.3; }
    100% { opacity: 0; }
}

/* Element-Specific Animations - Removed to prevent navbar artifacts */
/* Navbar transitions are now handled by specific transition properties */

@keyframes slideInLeft {
    0% {
        transform: translateX(-10px);
        opacity: 0.8;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

.theme-transitioning .section-title {
    animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
    0% {
        transform: translateY(10px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Icon Animations for Theme Toggle */
.theme-toggle-float {
    position: relative;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.theme-toggle-float:active {
    animation: pulse 0.3s ease;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* Sun/Moon Icon Rotation */
.theme-toggle-float .sun-icon {
    animation: rotateSun 20s linear infinite;
}

@keyframes rotateSun {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.theme-toggle-float.is-dark .moon-icon {
    animation: swingMoon 4s ease-in-out infinite;
}

@keyframes swingMoon {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-5deg);
    }
    75% {
        transform: rotate(5deg);
    }
}

/* Particle Effect for Theme Switch */
@keyframes particle {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--particle-x), var(--particle-y)) scale(0);
        opacity: 0;
    }
}

.theme-particle {
    position: fixed;
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
    pointer-events: none;
    animation: particle 1s ease-out forwards;
    z-index: 10001;
}

/* Staggered Animations for Elements */
[data-theme="dark"] .service-card {
    animation: fadeInScale 0.6s ease backwards;
}

[data-theme="dark"] .service-card:nth-child(1) { animation-delay: 0.1s; }
[data-theme="dark"] .service-card:nth-child(2) { animation-delay: 0.2s; }
[data-theme="dark"] .service-card:nth-child(3) { animation-delay: 0.3s; }
[data-theme="dark"] .service-card:nth-child(4) { animation-delay: 0.4s; }
[data-theme="dark"] .service-card:nth-child(5) { animation-delay: 0.5s; }
[data-theme="dark"] .service-card:nth-child(6) { animation-delay: 0.6s; }

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Glow Pulse Animation */
[data-theme="dark"] .ios-button {
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .ios-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    50% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Shimmer Effect for Dark Mode */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

[data-theme="dark"] .shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.05),
        transparent
    );
    background-size: 1000px 100%;
    animation: shimmer 3s infinite;
}

/* Border Glow Animation */
@keyframes borderGlow {
    0%, 100% {
        border-color: var(--border-primary);
        box-shadow: 0 0 5px transparent;
    }
    50% {
        border-color: var(--secondary-color);
        box-shadow: 0 0 20px rgba(124, 126, 240, 0.3);
    }
}

[data-theme="dark"] .glow-border-animated {
    animation: borderGlow 3s ease-in-out infinite;
}

/* Text Glow Animation Removed - No red glow on headers */

/* Loading Animation for Theme Switch */
.theme-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    z-index: 10002;
}

.theme-loading::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid var(--border-secondary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Morphing Background Gradient */
@keyframes morphGradient {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

[data-theme="dark"] .gradient-morph {
    background: linear-gradient(
        -45deg,
        var(--bg-primary),
        var(--bg-secondary),
        var(--bg-tertiary),
        var(--bg-card)
    );
    background-size: 400% 400%;
    animation: morphGradient 15s ease infinite;
}

/* Smooth Scroll Behavior for Theme Change */
html.theme-transitioning {
    scroll-behavior: smooth;
}

/* Reduce Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .theme-toggle-float {
        animation: none;
    }
    
    .theme-ripple {
        display: none;
    }
}

/* High Performance GPU Acceleration */
.theme-transitioning *,
[data-theme="dark"] .animated,
.theme-toggle-float,
.theme-particle {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}