/**
 * UX Excellence Enhancements
 * Mobile-first responsive design with premium touch interactions
 * Core Web Vitals optimized for Google "Good" thresholds
 */

/* ==========================================================================
   Core Web Vitals Optimizations
   ========================================================================== */

/* Contain paint and layout for better CLS */
.header, .navigation, .section-content {
    contain: layout style paint;
}

/* Optimize for Largest Contentful Paint */
.profile-image, .section-title, .main-content {
    content-visibility: auto;
    contain-intrinsic-size: 0 200px;
}

/* Preload critical elements */
.loading-screen {
    will-change: opacity, transform;
    transform: translateZ(0);
}

/* ==========================================================================
   Enhanced Mobile Touch Interactions
   ========================================================================== */

/* Touch-friendly hit targets (minimum 48x48px) */
.touch-device .nav-item,
.touch-device .contact-link,
.touch-device .project-link,
.touch-device .skill-item {
    min-height: 48px;
    min-width: 48px;
    touch-action: manipulation;
}

/* Enhanced touch feedback */
.touch-device .nav-item:active,
.touch-device .contact-link:active,
.touch-device .project-card:active {
    transform: scale(0.96);
    transition: transform 0.1s ease;
}

/* Ripple effect container */
.ripple-container {
    position: relative;
    overflow: hidden;
    transform: translateZ(0);
}

/* Ripple effect animation */
@keyframes ripple {
    to {
        transform: translate(-50%, -50%) scale(4);
        opacity: 0;
    }
}

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    pointer-events: none;
    animation: ripple 0.6s linear;
    z-index: 1;
}

/* Touch gesture enhancements */
.touch-device .scrollable {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Prevent text selection during gestures */
.touch-device .nav-items,
.touch-device .contact-links {
    -webkit-user-select: none;
    user-select: none;
}

/* ==========================================================================
   Micro-Interactions & Animations
   ========================================================================== */

/* Smooth page transitions */
.page-transition {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.page-transition.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Enhanced hover states with magnetic effect */
.magnetic {
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.magnetic:hover {
    transform: translate(var(--magnetic-x, 0), var(--magnetic-y, 0)) scale(1.05);
}

/* Floating animation for cards */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}

.floating {
    animation: float 3s ease-in-out infinite;
}

/* Gradient text animation */
@keyframes gradient-flow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.gradient-text-animated {
    background: linear-gradient(-45deg, #3b82f6, #06b6d4, #10b981, #3b82f6);
    background-size: 400% 400%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradient-flow 4s ease infinite;
}

/* Staggered animations */
.stagger-animation > * {
    opacity: 0;
    transform: translateY(20px);
    animation: staggerIn 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.stagger-animation > *:nth-child(1) { animation-delay: 0.1s; }
.stagger-animation > *:nth-child(2) { animation-delay: 0.2s; }
.stagger-animation > *:nth-child(3) { animation-delay: 0.3s; }
.stagger-animation > *:nth-child(4) { animation-delay: 0.4s; }
.stagger-animation > *:nth-child(5) { animation-delay: 0.5s; }

@keyframes staggerIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Pulse animation for call-to-action */
.pulse-animation {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* ==========================================================================
   Advanced Loading States
   ========================================================================== */

/* Skeleton loading animation */
.skeleton {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0.1) 25%, 
        rgba(255, 255, 255, 0.2) 50%, 
        rgba(255, 255, 255, 0.1) 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

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

/* Progressive image loading */
.progressive-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progressive-image.loaded {
    opacity: 1;
}

/* ==========================================================================
   Enhanced Responsive Design
   ========================================================================== */

/* Container queries for better responsiveness */
.stat-item {
    container-type: inline-size;
}

@container (max-width: 150px) {
    .stat-value {
        font-size: 1rem;
    }
    .stat-label {
        font-size: 0.625rem;
    }
}

/* Improved mobile navigation */
@media (max-width: 768px) {
    .nav-items {
        gap: 0.5rem;
        padding: 0 1rem;
        scroll-snap-type: x mandatory;
    }
    
    .nav-item {
        scroll-snap-align: center;
        flex: 0 0 auto;
        border-radius: 1rem;
    }
}

/* Touch-specific mobile optimizations */
@media (pointer: coarse) {
    .contact-links {
        gap: 1.5rem;
    }
    
    .project-card {
        padding: 2rem;
    }
    
    .nav-item {
        padding: 1rem 1.5rem;
    }
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Optimize repaints and reflows */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* GPU acceleration for animations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimize scroll performance */
.smooth-scroll {
    scroll-behavior: smooth;
    overflow-anchor: none;
}

/* ==========================================================================
   Accessibility Enhancements (WCAG 2.1 AAA)
   ========================================================================== */

/* Enhanced focus indicators */
*:focus-visible {
    outline: 3px solid #60a5fa;
    outline-offset: 2px;
    border-radius: 4px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-text-primary: #ffffff;
        --color-text-secondary: #ffffff;
        --color-border: #ffffff;
    }
    
    .nav-item.active {
        background: #ffffff;
        color: #000000;
    }
}

/* Reduced motion preferences */
@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;
    }
    
    .loading-spinner {
        animation: none;
    }
    
    .floating {
        animation: none;
    }
}

/* ==========================================================================
   Dark Mode Enhancements
   ========================================================================== */

/* Enhanced dark mode with better contrast ratios */
@media (prefers-color-scheme: dark) {
    :root {
        --color-text-primary: #ffffff;
        --color-text-secondary: #f1f5f9;
        --color-text-muted: #e2e8f0;
    }
}

/* ==========================================================================
   Print Optimizations
   ========================================================================== */

@media print {
    .gpu-accelerated,
    .will-change-transform,
    .will-change-opacity {
        transform: none !important;
        will-change: auto !important;
    }
    
    .floating {
        animation: none !important;
    }
    
    * {
        color-adjust: exact !important;
    }
}

/* ==========================================================================
   Custom Scrollbar (Webkit)
   ========================================================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--color-primary), var(--color-secondary));
    border-radius: 4px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--color-primary-light), var(--color-secondary));
}

/* ==========================================================================
   Loading Performance Hints
   ========================================================================== */

/* Optimize images */
img {
    content-visibility: auto;
    contain-intrinsic-size: 0 200px;
}

/* Lazy loading placeholder */
.lazy-loading {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.2) 20%,
        rgba(255, 255, 255, 0.2) 60%,
        rgba(255, 255, 255, 0.1) 100%
    );
    background-size: 200% 100%;
    animation: loading-shimmer 2s linear infinite;
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: initial;
    margin: initial;
    overflow: visible;
    clip: auto;
    white-space: normal;
}