/* ============================================
   ULTRA PERFORMANCE CSS
   تحسينات الأداء المتقدمة
============================================ */

/* 1. Hardware Acceleration - تسريع العتاد */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.project-card,
.game-card,
.app-card,
.feature-card,
.btn,
.hero-image {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 2. Smooth Scrolling - تمرير سلس */
html {
    scroll-behavior: smooth;
}

/* 3. Lazy Loading Images - تحميل الصور الكسول */
/* Note: Use loading="lazy" as HTML attribute, not CSS property */
img {
    content-visibility: auto;
}

/* 4. GPU Acceleration للـ Animations */
@keyframes optimizedFadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.fade-in {
    animation: optimizedFadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* 5. Reduced Motion للمستخدمين الذين يفضلون ذلك */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 6. Containment - عزل العناصر */
.project-card,
.game-card,
.app-card {
    contain: layout style paint;
}

section {
    contain: layout style;
}

/* 7. Intersection Observer للـ Animations */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.animate-on-scroll.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* 8. تحسين الـ Hover Effects */
.project-card,
.game-card,
.app-card {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.project-card:hover,
.game-card:hover,
.app-card:hover {
    transform: translateY(-8px) translateZ(0);
}

/* 9. Optimized Gradients */
.gradient-bg {
    background: linear-gradient(135deg, #76AD3F 0%, #5C8B2F 100%);
    background-attachment: fixed;
    background-size: 200% 200%;
}

/* 10. Critical CSS للـ Above the Fold */
.header {
    position: sticky;
    top: 0;
    z-index: 1000;
    contain: layout style;
}

/* 11. تحسين الـ Grid Layouts */
.projects-grid,
.games-grid,
.apps-grid {
    display: grid;
    gap: 2rem;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    contain: layout;
}

/* 12. Skeleton Loading States */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 13. Font Display Optimization */
/* Note: @font-face needs src and font-family - handled in main style.css */

/* 14. Preload Critical Resources */
/* Note: 'as' and 'crossorigin' are HTML attributes, not CSS properties - use in HTML */

/* 15. Container Queries Support */
@container (min-width: 400px) {
    .card-content {
        padding: 1.5rem;
    }
}

/* 16. Aspect Ratio للصور */
.project-image,
.game-image,
.app-image {
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

/* 17. تحسين الـ Shadows */
.project-card,
.game-card,
.app-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    filter: drop-shadow(0 0 0 transparent);
}

.project-card:hover,
.game-card:hover,
.app-card:hover {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

/* 18. Optimized Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 30px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translate3d(0, -30px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translate3d(-30px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translate3d(30px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale3d(0.9, 0.9, 1);
    }
    to {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}

/* 19. Loading Spinner Optimized */
.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #76AD3F;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    will-change: transform;
}

@keyframes spin {
    0% { transform: rotate3d(0, 0, 1, 0deg); }
    100% { transform: rotate3d(0, 0, 1, 360deg); }
}

/* 20. Page Transition */
body {
    opacity: 0;
    animation: pageLoad 0.5s ease forwards;
}

@keyframes pageLoad {
    to { opacity: 1; }
}

/* 21. Reduced Paint - تقليل إعادة الرسم */
.header,
.footer {
    contain: layout style paint;
    content-visibility: auto;
}

/* 22. Optimized Blur Effects */
.backdrop-blur {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* 23. CSS Grid Auto-fit Optimization */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    contain: layout;
}

/* 24. Scroll Snap للـ Smooth Navigation */
.scroll-container {
    scroll-snap-type: y mandatory;
    overflow-y: scroll;
}

.scroll-section {
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

/* 25. Touch Action Optimization */
.touch-enabled {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button,
a,
.btn {
    touch-action: manipulation;
}

/* 26. Image Optimization */
picture {
    display: block;
}

picture img {
    width: 100%;
    height: auto;
}

/* 27. Critical Path CSS */
.above-the-fold {
    content-visibility: visible;
}

.below-the-fold {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* 28. Optimized Filters */
.image-filter {
    filter: brightness(1);
    transition: filter 0.3s ease;
}

.image-filter:hover {
    filter: brightness(1.1);
}

/* 29. Memory Optimization للـ Large Lists */
.virtual-scroll {
    overflow: auto;
    contain: strict;
    content-visibility: auto;
}

/* 30. CSS Containment للـ Components */
.component {
    contain: layout style paint;
    content-visibility: auto;
}

/* 31. Optimized Z-index Stack */
.z-base { z-index: 1; }
.z-dropdown { z-index: 100; }
.z-sticky { z-index: 200; }
.z-fixed { z-index: 300; }
.z-modal-backdrop { z-index: 400; }
.z-modal { z-index: 500; }
.z-popover { z-index: 600; }
.z-tooltip { z-index: 700; }

/* 32. Performance Hints */
.optimize-3d {
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
}

/* 33. Pointer Events Optimization */
.overlay {
    pointer-events: none;
}

.overlay.active {
    pointer-events: auto;
}

/* 34. Will-change للـ Critical Elements */
.nav-menu,
.hero-content,
.scroll-indicator {
    will-change: transform, opacity;
}

/* 35. Optimized Media Queries */
@media (min-width: 768px) {
    .projects-grid,
    .games-grid,
    .apps-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .projects-grid,
    .games-grid,
    .apps-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1440px) {
    .projects-grid,
    .games-grid,
    .apps-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 36. Print Optimization */
@media print {
    * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a, a:visited {
        text-decoration: underline;
    }
    
    .no-print {
        display: none !important;
    }
}

/* 37. Dark Mode Optimization */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg-primary: #1a1a1a;
        --color-text-primary: #ffffff;
    }
}

/* 38. High Contrast Mode */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
}

/* 39. Reduced Data Mode */
@media (prefers-reduced-data: reduce) {
    * {
        background-image: none !important;
    }
}

/* 40. Content Visibility للـ Performance */
.lazy-section {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}
