/* Performance Optimizations for EgyDead - Lighthouse Audit Fixes */

/* Critical CSS - Above the fold content */
:root {
    --primary-color: #adff2f;
    --bg-dark: #1a1a1a;
    --bg-darker: #0d0d0d;
    --text-light: #ffffff;
    --text-gray: #cccccc;
    --border-color: #333333;
    --shadow-dark: rgba(0, 0, 0, 0.5);
    --gradient-primary: linear-gradient(135deg, var(--bg-dark), var(--bg-darker));
}

/* Performance optimizations */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-darker);
    color: var(--text-light);
    direction: rtl;
    text-align: right;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Accessibility improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for accessibility */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color);
    color: var(--bg-dark);
    padding: 8px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 4px;
    font-weight: bold;
}

.skip-link:focus {
    top: 6px;
}

/* Optimized loading states */
.loading {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

.loading.active {
    display: block;
}

/* Image optimization */
img {
    max-width: 100%;
    height: auto;
    display: block;
    border: 0;
}

/* Lazy loading placeholder */
img[data-src] {
    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; }
}

/* Button accessibility improvements */
button,
.btn,
[role="button"] {
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-family: inherit;
    font-size: inherit;
    position: relative;
    overflow: hidden;
}

button:hover,
.btn:hover,
[role="button"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-dark);
}

button:active,
.btn:active,
[role="button"]:active {
    transform: translateY(0);
}

button:disabled,
.btn:disabled,
[role="button"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Link accessibility improvements */
a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: #c7ff5a;
    text-decoration: underline;
}

a:visited {
    color: #9adf2a;
}

/* Form accessibility */
input,
textarea,
select {
    font-family: inherit;
    font-size: inherit;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 12px;
    background: var(--bg-dark);
    color: var(--text-light);
    transition: border-color 0.3s ease;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(173, 255, 47, 0.2);
}

/* Performance: Reduce layout shifts */
.hero {
    min-height: 70vh;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.movie-card,
.series-card {
    aspect-ratio: 2/3;
    background: var(--bg-dark);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease;
}

/* Optimize animations for performance */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #00ff00;
        --text-light: #ffffff;
        --bg-dark: #000000;
        --border-color: #ffffff;
    }
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    body {
        background: var(--bg-darker);
        color: var(--text-light);
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .hero {
        min-height: 50vh;
    }
    
    button,
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
}

/* Print styles */
@media print {
    .header,
    .footer,
    .sidebar,
    .ads,
    button,
    .btn {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}

/* Utility classes for accessibility */
.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;
}

.focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Performance: GPU acceleration for animations */
.hero-slide,
.movie-card,
.animated {
    will-change: transform;
    transform: translateZ(0);
}

/* Optimize font rendering */
.text-optimized {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Container queries for responsive design */
@container (min-width: 768px) {
    .movie-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .hero-slider {
        animation: none;
    }
    
    .movie-card {
        transition: none;
    }
}

/* Improve text contrast */
.high-contrast {
    color: var(--text-light);
    background: var(--bg-darker);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Optimize for touch devices */
@media (pointer: coarse) {
    button,
    .btn,
    a {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Performance: Contain layout and paint */
.movie-section,
.series-section {
    contain: layout style paint;
}

/* Optimize scrolling performance */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-dark);
}

.scroll-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.scroll-container::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.scroll-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.scroll-container::-webkit-scrollbar-thumb:hover {
    background: #c7ff5a;
}
