/* Basic reset and body styles */
body {
    margin: 0;
    font-family: sans-serif;
}

#image-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    padding: 20px;
}

/* Image Wrapper in Scroll Mode */
.image-wrapper {
    width: 300px; /* Example size */
    height: 200px;
    margin: 10px;
    background-color: #e0e0e0; /* Placeholder background */
    display: flex; /* Use flex for loader centering */
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease-in-out;
}

.image-wrapper:hover {
    transform: translateY(-5px);
}

.image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Cover the container */
    display: block;
    opacity: 0; /* Initially hidden, will fade in */
    transition: opacity 0.5s ease-in-out;
}

/* Loader animation */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    position: absolute; /* Position over the image */
    z-index: 1; /* Ensure it's above the image */
    display: block; /* Show by default until image loads */
}

/* Hide loader when image is loaded (handled by JS) */
.image-wrapper.loaded .loader {
    display: none;
}

/* Show image when loaded (handled by JS) */
.image-wrapper.loaded img {
    opacity: 1;
}


@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Gallery styles */
#gallery-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

#gallery-overlay.active {
    opacity: 1;
    visibility: visible;
}

#gallery-full-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    background-color: #333; /* Dark background for transparent images */
    transition: opacity 0.3s ease-in-out; /* For smooth image changes */
    opacity: 0; /* Initially hidden in gallery, fade in on load */
}

/* Gallery navigation buttons */
#gallery-close,
#gallery-prev,
#gallery-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 2.5em;
    cursor: pointer;
    padding: 10px 15px;
    border-radius: 50%;
    line-height: 1;
    transition: background-color 0.2s ease;
    z-index: 1001; /* Above the image */
}

#gallery-close:hover,
#gallery-prev:hover,
#gallery-next:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

#gallery-close { top: 20px; right: 20px; font-size: 3em; }
#gallery-prev { left: 20px; }
#gallery-next { right: 20px; }

/* Loader specifically for the gallery image */
#gallery-overlay .loader {
    display: none; /* Hidden by default in gallery, shown by JS */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1002;
}