/* ===============================================
   ANIMATIONS - Portfolio Website
   K.A. Muhammad Aasif
   =============================================== */

/* ===== FADE IN ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== SCALE ANIMATIONS ===== */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* ===== GLOW ANIMATIONS ===== */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 10px var(--accent-glow);
    }
    50% {
        box-shadow: 0 0 20px var(--accent-glow);
    }
}

@keyframes textGlow {
    0%, 100% {
        text-shadow: 0 2px 10px var(--accent-glow);
    }
    50% {
        text-shadow: 0 4px 20px var(--accent-glow);
    }
}

/* ===== SLIDE ANIMATIONS ===== */
@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===== TYPING ANIMATION ===== */
@keyframes typing {
    from {
        width: 0;
    }
    to {
        width: 100%;
    }
}

@keyframes blink {
    0%, 100% {
        border-right-color: var(--accent);
    }
    50% {
        border-right-color: transparent;
    }
}

/* ===== FLOATING ANIMATION ===== */
@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

/* ===== ROTATE ANIMATIONS ===== */
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-200deg);
    }
    to {
        opacity: 1;
        transform: rotate(0);
    }
}

/* ===== BOUNCE ANIMATION ===== */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

/* ===== SHAKE ANIMATION ===== */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* ===== PARTICLE ANIMATIONS ===== */
@keyframes particleFloat {
    0%, 100% {
        transform: translateY(0) translateX(0);
    }
    25% {
        transform: translateY(-10px) translateX(10px);
    }
    50% {
        transform: translateY(-5px) translateX(-5px);
    }
    75% {
        transform: translateY(-15px) translateX(5px);
    }
}

/* ===== RIPPLE EFFECT ===== */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* ===== SHIMMER ANIMATION ===== */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

/* ===== GRADIENT ANIMATION ===== */
@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* ===== APPLYING ANIMATIONS ===== */

/* Fade In elements */
.fade-in {
    animation: fadeIn 1s ease-in-out;
}

.fade-in-up {
    animation: fadeInUp 0.8s ease-out;
}

.fade-in-down {
    animation: fadeInDown 0.8s ease-out;
}

.fade-in-left {
    animation: fadeInLeft 0.8s ease-out;
}

.fade-in-right {
    animation: fadeInRight 0.8s ease-out;
}

/* Stagger animation delays */
.fade-in-up:nth-child(1) { animation-delay: 0.1s; }
.fade-in-up:nth-child(2) { animation-delay: 0.2s; }
.fade-in-up:nth-child(3) { animation-delay: 0.3s; }
.fade-in-up:nth-child(4) { animation-delay: 0.4s; }
.fade-in-up:nth-child(5) { animation-delay: 0.5s; }

/* Hero animations */
.hero-subtitle {
    animation: fadeInDown 0.8s ease-out;
}

.hero-title {
    animation: fadeInUp 1s ease-out 0.2s both;
}

.hero-description {
    animation: fadeInUp 1s ease-out 0.4s both;
}

.hero-tagline {
    animation: fadeInUp 1s ease-out 0.6s both;
}

.hero-subtitle-2 {
    animation: fadeInUp 1s ease-out 0.8s both;
}

.hero-buttons {
    animation: fadeInUp 1s ease-out 1s both;
}

/* Glow effect on accent elements */
.glow {
    animation: textGlow 2s ease-in-out infinite;
}

/* Typing effect for hero title */
.typing-text {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    border-right: 3px solid var(--accent);
    animation: typing 3s steps(30) 0.5s both, blink 0.75s step-end infinite;
}

/* Remove cursor after typing completes */
@media (min-width: 769px) {
    .typing-text {
        animation: typing 3s steps(30) 0.5s both, blink 0.75s step-end 4;
    }
}

/* Scroll indicator animation */
.scroll-indicator {
    animation: bounce 2s ease-in-out infinite;
}

/* Navbar scroll animation */
.navbar {
    animation: fadeInDown 0.5s ease-out;
}

/* Card hover animations */
.service-card,
.feature-card,
.project-card,
.cert-card,
.tech-category {
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Floating animation for icons */
.feature-icon,
.service-icon,
.cert-icon {
    transition: transform 0.3s ease;
}

.feature-card:hover .feature-icon,
.service-card:hover .service-icon,
.cert-card:hover .cert-icon {
    animation: float 2s ease-in-out infinite;
}

/* Button ripple effect */
.btn {
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::after {
    width: 300px;
    height: 300px;
}

/* Section reveal animation (triggered by Intersection Observer) */
.section-reveal {
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.section-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger animation for grid items */
.stagger-item {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.stagger-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.stagger-item:nth-child(1) { transition-delay: 0.1s; }
.stagger-item:nth-child(2) { transition-delay: 0.2s; }
.stagger-item:nth-child(3) { transition-delay: 0.3s; }
.stagger-item:nth-child(4) { transition-delay: 0.4s; }
.stagger-item:nth-child(5) { transition-delay: 0.5s; }
.stagger-item:nth-child(6) { transition-delay: 0.6s; }
.stagger-item:nth-child(7) { transition-delay: 0.7s; }
.stagger-item:nth-child(8) { transition-delay: 0.8s; }

/* Tech item pulse on hover */
.tech-item:hover {
    animation: pulse 0.6s ease-in-out;
}

/* Modal animations */
.modal {
    animation: fadeIn 0.3s ease;
}

.modal-content {
    animation: scaleIn 0.4s ease-out;
}

/* Form submission animation */
.btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-submit.loading::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: rotate 0.6s linear infinite;
    margin-right: 8px;
}

/* Success/Error message animations */
.form-message {
    animation: fadeInUp 0.5s ease-out;
}

/* Navigation link hover effect */
.nav-link {
    position: relative;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--accent);
    transition: width 0.3s ease;
}

.nav-link:hover::after {
    width: 100%;
}

/* Image zoom effect */
.project-image img {
    transition: transform 0.5s ease;
}

.project-card:hover .project-image img {
    transform: scale(1.1);
}

/* Logo pulse on page load */
.logo {
    animation: pulse 1s ease-in-out 0.5s;
}

/* Accent text shimmer effect */
.accent-text {
    color: var(--accent);
    font-weight: 600;
}

/* Social icon rotation on hover */
.social-icons a:hover,
.footer-social a:hover {
    animation: rotateIn 0.5s ease-out;
}

/* Progress bar animation (if needed) */
@keyframes progressBar {
    from {
        width: 0%;
    }
    to {
        width: 100%;
    }
}

.progress-bar {
    animation: progressBar 2s ease-out;
}

/* Skeleton loading animation */
@keyframes skeleton {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 0px, var(--card-bg) 40px, var(--bg-secondary) 80px);
    background-size: 200px 100%;
    animation: skeleton 1.5s ease-in-out infinite;
}

/* Page transition animation */
.page-transition {
    animation: fadeIn 0.5s ease-in-out;
}

/* Cursor trail effect (optional) */
@keyframes cursorTrail {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

/* ===== 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;
        scroll-behavior: auto !important;
    }
    
    .typing-text {
        border-right: none;
        animation: none;
        white-space: normal;
    }
    
    .scroll-indicator {
        animation: none;
    }
}

/* ===== MOBILE OPTIMIZATION ===== */
/* Ensure elements are visible on mobile even if observer fails */
@media (max-width: 768px) {
    .section-reveal {
        opacity: 1 !important;
        transform: translateY(0) !important;
    }
    
    .stagger-item {
        opacity: 1 !important;
        transform: translateY(0) !important;
    }
    
    /* Faster animations on mobile */
    .section-reveal,
    .stagger-item {
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
    
    /* Reduce animation delays on mobile */
    .stagger-item:nth-child(n) {
        transition-delay: 0.05s !important;
    }
    
    /* Ensure domain badges are visible */
    .domain-badge,
    .about-stat-card,
    .client-card,
    .timeline-item {
        opacity: 1 !important;
        transform: translateY(0) !important;
    }
}

/* ===== PERFORMANCE OPTIMIZATION ===== */
/* Use will-change for elements that will animate */
.service-card,
.feature-card,
.project-card,
.cert-card,
.btn {
    will-change: transform, box-shadow;
}

/* Remove will-change after animation completes to save memory */
.service-card:not(:hover),
.feature-card:not(:hover),
.project-card:not(:hover),
.cert-card:not(:hover),
.btn:not(:hover) {
    will-change: auto;
}
