.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.gallery-item {
    position: relative;
    background: #f9f9f9;
    border-radius: 4px;
    overflow: hidden;
    transition: transform 0.2s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer; /* Indicate clickability */
}

.gallery-item img {
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
    image-rendering: -webkit-optimize-contrast; /* Improve image clarity */
    image-rendering: crisp-edges; /* Prevent blurry scaling */
}

.gallery-description {
    padding: 8px;
    font-size: 12px;
    color: #666;
    background: #fff;
    border-top: 1px solid #eee;
    line-height: 1.4;
}

/* Adjust grid for larger image sizes */
.gallery-grid[data-image-size="large"],
.gallery-grid[data-image-size="full"] {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

/* Modal styles */
.gallery-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.85);
    transition: background-color 0.3s ease; /* Smooth hover transition */
}

.gallery-modal:hover {
    background-color: rgba(0, 0, 0, 0.75); /* Lighten on hover to indicate clickability */
    cursor: pointer;
}

.gallery-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Center horizontally and vertically */
    max-width: 90%;
    max-height: 85vh; /* Reduced to account for caption and close button */
    text-align: center;
    padding: 20px; /* Add padding to ensure content doesn’t touch edges */
    box-sizing: border-box;
}

.gallery-modal-image {
    max-width: 100%;
    max-height: 75vh; /* Reduced to fit within content with caption */
    object-fit: contain;
    display: block;
    margin: auto;
    border-radius: 4px;
    border: 6px solid #f0f0f0; /* Light gray border for contrast */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); /* Stronger shadow for depth */
}

.gallery-modal-close {
    position: absolute;
    top: 0; /* Moved inside content area */
    right: 0; /* Aligned with content edge */
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.6); /* Semi-transparent background */
    border-radius: 50%;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.gallery-modal-close:hover {
    background: rgba(0, 0, 0, 0.8); /* Darker background on hover */
    color: #ddd;
}

.gallery-modal-caption {
    color: #fff;
    font-size: 14px;
    margin-top: 10px;
    opacity: 0.8;
    font-style: italic;
}

/* Fallback for browsers that don't support grid */
@supports not (display: grid) {
    .gallery-grid {
        display: flex;
        flex-wrap: wrap;
    }
    
    .gallery-item {
        width: calc(33.333% - 10px);
        margin: 5px;
    }
    
    .gallery-grid[data-image-size="large"] .gallery-item,
    .gallery-grid[data-image-size="full"] .gallery-item {
        width: calc(50% - 10px);
    }
}