/* ============================================
   COMPREHENSIVE IMPROVEMENTS CSS
   تحسينات شاملة للتصميم والأداء
   Cup Code Studio - 2025
============================================ */

/* ============================================
   1. PERFORMANCE OPTIMIZATIONS
============================================ */

/* Reduce animations for slow connections */
.reduce-animations *,
.reduce-animations *::before,
.reduce-animations *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
}

/* Low quality images for data saving */
.low-quality-images img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Pause animations when tab is hidden */
.pause-animations * {
    animation-play-state: paused !important;
}

/* Fonts loaded state */
body:not(.fonts-loaded) {
    opacity: 0.99; /* Force repaint */
}

body.fonts-loaded {
    opacity: 1;
}

/* ============================================
   2. IMPROVED ACCESSIBILITY
============================================ */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 3px solid #76AD3F;
    outline-offset: 3px;
    border-radius: 4px;
}

/* Remove focus outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 0;
    background: #76AD3F;
    color: white;
    padding: 1rem 2rem;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    z-index: 10000;
    font-weight: 600;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 0;
}

/* High contrast mode improvements */
@media (prefers-contrast: high) {
    .btn,
    .card,
    .project-card,
    .game-card,
    .app-card {
        border: 2px solid currentColor;
    }
    
    a {
        text-decoration: underline;
    }
}

/* ============================================
   3. RESPONSIVE IMPROVEMENTS
============================================ */

/* Better mobile touch targets */
@media (max-width: 768px) {
    .btn,
    a,
    button {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }
    
    .nav-link {
        padding: 15px 20px;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 95%;
    }
    
    .projects-grid,
    .games-grid,
    .apps-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Large screens */
@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }
    
    .projects-grid,
    .games-grid,
    .apps-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   4. IMPROVED ANIMATIONS
============================================ */

/* Smoother card hover */
.project-card,
.game-card,
.app-card,
.feature-card {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.project-card:hover,
.game-card:hover,
.app-card:hover,
.feature-card:hover {
    transform: translateY(-12px) scale(1.02);
}

/* 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 ease, height 0.6s ease;
}

.btn:active::after {
    width: 300px;
    height: 300px;
}

/* Fade in on scroll */
.fade-in-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.fade-in-scroll.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   5. IMPROVED TYPOGRAPHY
============================================ */

/* Better text rendering */
body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Improved readability */
p {
    max-width: 75ch;
    line-height: 1.7;
}

/* Better heading hierarchy */
h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    line-height: 1.2;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: clamp(1.75rem, 4vw, 2.75rem);
    line-height: 1.3;
    margin-bottom: 1.25rem;
}

h3 {
    font-size: clamp(1.5rem, 3vw, 2.25rem);
    line-height: 1.4;
    margin-bottom: 1rem;
}

/* Better link styles */
a {
    color: #76AD3F;
    text-decoration: none;
    transition: color 0.3s ease, text-decoration 0.3s ease;
}

a:hover {
    color: #5C8B2F;
    text-decoration: underline;
}

a:active {
    color: #4A6F25;
}

/* ============================================
   6. IMPROVED LOADING STATES
============================================ */

/* Better skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #e0e0e0 20%,
        #f0f0f0 40%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Loading spinner */
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(118, 173, 63, 0.2);
    border-top-color: #76AD3F;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(118, 173, 63, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    display: block;
    width: 40%;
    height: 100%;
    background: #76AD3F;
    border-radius: 2px;
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(350%);
    }
}

/* ============================================
   7. IMPROVED FORMS
============================================ */

/* Better input styles */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: white;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #76AD3F;
    box-shadow: 0 0 0 4px rgba(118, 173, 63, 0.1);
}

/* Input with icons */
.input-with-icon {
    position: relative;
}

.input-with-icon input {
    padding-right: 45px;
}

.input-with-icon i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

/* Error and success states */
input.error,
textarea.error {
    border-color: #E53935;
    background: rgba(229, 57, 53, 0.05);
}

input.success,
textarea.success {
    border-color: #2E7D32;
    background: rgba(46, 125, 50, 0.05);
}

/* ============================================
   8. IMPROVED CARDS
============================================ */

/* Better card shadows */
.card,
.project-card,
.game-card,
.app-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08),
                0 4px 16px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.4s ease, transform 0.4s ease;
}

.card:hover,
.project-card:hover,
.game-card:hover,
.app-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12),
                0 16px 48px rgba(0, 0, 0, 0.08);
}

/* Card image optimization */
.card img,
.project-card img,
.game-card img,
.app-card img {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 12px 12px 0 0;
}

/* ============================================
   9. IMPROVED BUTTONS
============================================ */

/* Better button states */
.btn {
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

/* Button loading state */
.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================
   10. DARK MODE SUPPORT
============================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg-primary: #1a1a1a;
        --color-bg-secondary: #2a2a2a;
        --color-text-primary: #ffffff;
        --color-text-secondary: #b0b0b0;
    }
    
    body {
        background: var(--color-bg-primary);
        color: var(--color-text-primary);
    }
    
    .card,
    .project-card,
    .game-card,
    .app-card {
        background: var(--color-bg-secondary);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    
    input,
    textarea,
    select {
        background: var(--color-bg-secondary);
        border-color: #404040;
        color: var(--color-text-primary);
    }
}

/* ============================================
   11. PRINT OPTIMIZATIONS
============================================ */

@media print {
    * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
    
    .header,
    .footer,
    .nav,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .container {
        width: 100%;
        max-width: none;
    }
    
    h2, h3 {
        page-break-after: avoid;
    }
}

/* ============================================
   12. UTILITY CLASSES
============================================ */

/* Visibility */
.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
}

.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;
}

/* Spacing */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-5 { margin-top: 3rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mb-5 { margin-bottom: 3rem; }

/* Text alignment */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

/* ============================================
   13. PERFORMANCE HINTS
============================================ */

/* GPU acceleration for commonly animated elements */
.header,
.nav,
.btn,
.card,
.project-card,
.game-card,
.app-card {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Contain layout for better performance */
.container,
.section {
    contain: layout style;
}

/* Content visibility for off-screen content */
.below-fold {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* ============================================
   14. SMOOTH SCROLLING
============================================ */

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
    
    html:focus-within {
        scroll-behavior: smooth;
    }
}

/* ============================================
   15. IMPROVED IMAGES
============================================ */

/* Better image loading */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Prevent layout shift */
img[width][height] {
    aspect-ratio: attr(width) / attr(height);
}

/* Better image quality on retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ============================================
   16. RTL IMPROVEMENTS
============================================ */

html[dir="rtl"] {
    text-align: right;
}

html[dir="rtl"] .projects-grid,
html[dir="rtl"] .games-grid,
html[dir="rtl"] .apps-grid {
    direction: rtl;
}

/* ============================================
   17. IMPROVED SCROLLBAR (Webkit)
============================================ */

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #76AD3F;
    border-radius: 6px;
    border: 2px solid #f1f1f1;
}

::-webkit-scrollbar-thumb:hover {
    background: #5C8B2F;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #76AD3F #f1f1f1;
}

/* ============================================
   18. BETTER SELECTION
============================================ */

::selection {
    background: #76AD3F;
    color: white;
    text-shadow: none;
}

::-moz-selection {
    background: #76AD3F;
    color: white;
    text-shadow: none;
}

/* ============================================
   END OF COMPREHENSIVE IMPROVEMENTS
============================================ */
