/* ================================================
   PERFORMANCE OPTIMIZATIONS FOR DIE RESCUE TRAINER
   ================================================ */

/* 1. GPU-ACCELERATED ANIMATIONS
   ================================ */

/* Enable GPU acceleration for all animated elements */
.navbar,
.modal,
.modal-content,
.btn,
.course-card,
.dropdown-menu,
.page-header,
.animate-float,
.social-icon,
.nav-menu,
.hamburger span {
    will-change: transform, opacity;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000px;
    perspective: 1000px;
}

/* Optimize transform-based animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate3d(0, 40px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes float {
    0%, 100% {
        transform: translate3d(0, 0, 0) rotate(0deg);
    }
    50% {
        transform: translate3d(0, -20px, 0) rotate(5deg);
    }
}

/* 2. OPTIMIZED TRANSITIONS
   ========================= */

/* Use transform instead of position properties */
.btn {
    transition: transform 0.15s cubic-bezier(0.25, 0.1, 0.25, 1),
                box-shadow 0.15s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

/* Optimize card hover effects */
.course-card {
    transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1),
                box-shadow 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.course-card:hover {
    transform: translateY(-4px);
}

/* 3. REDUCE PAINT & LAYOUT THRASHING
   =================================== */

/* Use transform for animations instead of top/left */
.modal.show {
    display: flex !important;
}

.modal-content {
    animation: modalSlideIn 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
}

@keyframes modalSlideIn {
    from {
        transform: translate3d(0, -100px, 0) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0) scale(1);
        opacity: 1;
    }
}

/* 4. OPTIMIZE SCROLL PERFORMANCE
   =============================== */

/* Enable smooth scrolling with momentum */
.courses-container,
.modal-body,
.participants-table {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Optimize fixed elements */
.navbar {
    position: fixed;
    transform: translate3d(0, 0, 0);
    contain: layout style paint;
}

/* 5. CONTENT VISIBILITY OPTIMIZATION
   =================================== */

/* Hide off-screen content for better performance */
.tab-content:not(.active) {
    content-visibility: hidden;
    contain-intrinsic-size: 0 500px;
}

.course-card:not(:hover) {
    contain: layout style paint;
}

/* 6. FONT LOADING OPTIMIZATION
   ============================= */

/* Use font-display for better perceived performance */
@font-face {
    font-family: 'Inter';
    font-display: swap;
}

@font-face {
    font-family: 'Nunito';
    font-display: swap;
}

/* 7. REDUCE COMPOSITE LAYERS
   ========================== */

/* Only create layers for elements that need them */
.page-header::before {
    will-change: transform;
    transform: translate3d(0, 0, 0);
}

/* Clean up will-change after animation */
.page-header {
    animation: slideUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.page-header[data-animated="true"] {
    will-change: auto;
}

/* 8. OPTIMIZE SHADOWS
   =================== */

/* Use box-shadow sparingly and optimize values */
.course-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.course-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* 9. REDUCE REFLOWS
   ================== */

/* Batch DOM reads and writes */
.action-bar {
    contain: layout;
    min-height: 60px; /* Prevent layout shift */
}

/* 10. ANIMATION FRAME OPTIMIZATION
    ================================ */

/* Use CSS containment for animated elements */
@keyframes pulse {
    0%, 100% {
        transform: scale3d(1, 1, 1);
    }
    50% {
        transform: scale3d(1.05, 1.05, 1.05);
    }
}

/* 11. LAZY LOADING STYLES
    ====================== */

/* Prepare elements for lazy loading */
img[loading="lazy"],
iframe[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* MINIMAL SCROLL OPTIMIZATION */
body {
    -webkit-overflow-scrolling: touch;
}

/* SMOOTH ANIMATION OPTIMIZATION */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Force GPU acceleration for smooth animations */
*:has(> [class*="animate"]),
*[class*="transition"] {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Reduced GPU acceleration - only for navbar */
.navbar {
    will-change: transform;
    transform: translateZ(0);
}

/* 12. REDUCE PAINT AREAS
    ===================== */

/* Isolate paint areas */
.footer-minimal {
    isolation: isolate;
}

.footer-background {
    will-change: auto;
    contain: strict;
}

/* 13. OPTIMIZE HOVER STATES
    ======================== */

/* Only apply hover effects on devices that support it */
@media (hover: hover) and (pointer: fine) {
    .nav-link:hover,
    .social-icon:hover,
    .btn:hover {
        will-change: transform;
    }
}

/* 14. PERFORMANCE MEDIA QUERIES
    ============================ */

/* Minimal scroll enhancements */
* {
    touch-action: manipulation;
}

/* Reduce animations on low-end devices */
@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;
    }
}


/* Optimize for high refresh rate displays */
@media (min-resolution: 2dppx) {
    .btn,
    .course-card {
        transition-duration: 0.15s;
    }
}

/* 15. CRITICAL RENDERING PATH
    ========================== */

/* Above-the-fold critical styles */
.navbar,
.hero-section {
    contain: layout style;
}

/* 16. INTERSECTION OBSERVER READY
    =============================== */

/* Prepare elements for lazy animation */
[data-animate] {
    opacity: 0;
    transform: translateY(20px);
}

[data-animate].visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1),
                transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* 17. OPTIMIZE INPUT RESPONSIVENESS
    ================================= */

input,
textarea,
select {
    touch-action: manipulation;
}

/* 18. REDUCE SELECTOR COMPLEXITY
    ============================== */

/* Use BEM or simple class selectors for better performance */
.btn--primary {
    background: var(--primary-blue);
}

.card--hover {
    transform: translateY(-4px);
}

/* 19. OPTIMIZE Z-INDEX LAYERS
    ========================== */

:root {
    --z-dropdown: 100;
    --z-modal: 200;
    --z-navbar: 50;
}

/* 20. PREVENT LAYOUT SHIFT
    ======================= */

/* Reserve space for dynamic content */
.courses-grid {
    min-height: 400px;
}

.empty-state {
    min-height: 300px;
}