/**
 * Image Optimization Styles
 * Improves image loading performance and user experience
 */

/* Prevent layout shift during image loading */
img {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Image containers should have aspect ratio to prevent layout shift */
.game-image,
.tool-icon,
.console-image,
.cheat-card img {
    position: relative;
    overflow: hidden;
    background: #1a1a2e;
}

/* Placeholder for images while loading */
.img-placeholder {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* Smooth fade-in for loaded images */
img.loaded {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Error state for failed images */
img.error {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* Lazy loading blur effect (optional progressive enhancement) */
img[data-src] {
    filter: blur(10px);
    transition: filter 0.3s ease;
}

img[data-src].loaded {
    filter: blur(0);
}

/* Optimize game card images */
.game-card .game-image {
    aspect-ratio: 16 / 9;
    width: 100%;
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
}

.game-card .game-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Optimize cheat card images */
.cheat-card img,
.mod-card img {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
    object-fit: cover;
    background: #1a1a2e;
}

/* Tool icon optimization */
.tool-icon {
    aspect-ratio: 1 / 1;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.tool-icon img {
    max-width: 60px;
    max-height: 60px;
    width: auto;
    height: auto;
}

/* Console card images */
.console-card .console-image {
    aspect-ratio: 16 / 9;
    width: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.console-card .console-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Loading spinner */
.img-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Performance optimizations */
.game-image img,
.cheat-card img,
.console-image img {
    /* Enable GPU acceleration for smoother animations */
    transform: translateZ(0);
    will-change: opacity;
}

/* Reduce repaints during scroll */
.games-grid,
.tools-grid,
.console-grid {
    contain: layout style paint;
}

/* Image skeleton loader */
.img-skeleton {
    background: linear-gradient(
        90deg,
        #1a1a2e 25%,
        #16213e 50%,
        #1a1a2e 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

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

/* Responsive image optimization */
@media (max-width: 768px) {
    .game-card .game-image,
    .console-card .console-image,
    .cheat-card img {
        aspect-ratio: 4 / 3;
    }

    .tool-icon {
        width: 60px;
        height: 60px;
    }

    .tool-icon img {
        max-width: 45px;
        max-height: 45px;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    img,
    .img-placeholder {
        animation: none !important;
        transition: none !important;
    }
}

/* Print optimization - load all images for printing */
@media print {
    img[data-src] {
        filter: none !important;
    }

    .img-placeholder {
        display: none !important;
    }
}
