/* Disable WordPress default gallery styles */
.gallery-columns-3, .gallery-size-thumbnail {
    all: unset !important;
}

/* Custom Gallery Layout */
.gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* Four columns for subsequent rows */
    gap: 5px; /* Space between items */
    width: 100%;
    max-width: 100%; /* Prevent overflow */
    box-sizing: border-box;
    margin: 20px auto; /* Center the gallery */
    overflow-x: hidden; /* Avoid horizontal scrolling */
}

/* First image spans the full width */
.gallery .gallery-item:first-child {
    grid-column: span 4; /* Full width */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Next 4 images take 25% each */
.gallery .gallery-item:nth-child(n+2):nth-child(-n+5) {
    grid-column: span 1; /* 1/4 of the row */
    margin: 0;
    padding: 0;
}

/* Hide all images after the fifth */
.gallery .gallery-item:nth-child(n+6) {
    display: none;
}

/* Style the last visible gallery item with an overlay */
.gallery .gallery-item:nth-child(5) {
    position: relative;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Dark overlay for the last visible image */
.gallery .gallery-item:nth-child(5)::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Dark overlay */
    z-index: 1; /* Ensure it's above the image */
    box-sizing: border-box;
}

/* Plus sign and count text */
.gallery .gallery-item:nth-child(5) .plus-count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 24px;
    font-weight: bold;
    z-index: 2; /* Ensure it's above the overlay */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Ensure images are responsive */
.gallery .gallery-item img {
    width: 100%;
    height: auto;
    object-fit: cover; /* Crop to fit */
    margin: 0;
    padding: 0;
    display: block;
}

/* Responsive Adjustments */
@media (max-width: 480px) {
    .gallery {
        gap: 5px; /* Maintain spacing between items */
        padding: 0 10px; /* Add small padding to prevent overflow */
    }

    .gallery .gallery-item:first-child {
        grid-column: span 4; /* Full width remains intact */
    }

    .gallery .gallery-item img {
        width: 100%;
        height: auto;
    }
}