.yagp-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
}

.yagp-item {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
}

.yagp-image-wrapper {
    position: relative;
    display: inline-block;
}

.yagp-item img {
    display: block;
    transition: opacity 0.4s ease, filter 0.4s ease;
    max-width: 100%;
    height: auto;
}

.yagp-item img.yagp-lazy.lazy-loading {
    opacity: 0.8;
    filter: blur(1px);
    background-color: #f0f0f0;
    /* Maintain dimensions during loading */
    width: auto;
    height: auto;
}

.yagp-item img.yagp-lazy.lazy-loaded {
    opacity: 1;
    filter: none;
}

.yagp-item p {
    text-align: center;
    margin: 0.5em 0 0;
}

#yagp-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#yagp-lightbox.active {
    display: flex;
}

.yagp-top {
    width: 100%;
    color: white;
    padding: 1em;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    top: 0;
}

#yagp-close {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
}

.yagp-image-container {
    max-width: 90%;
    max-height: 70%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.yagp-image-container img {
    max-width: 100%;
    max-height: 70vh;
}

.yagp-caption {
    color: white;
    text-align: center;
    padding: 1em;
}

.yagp-caption h3 {
    margin: 0 0 0.5em;
}

.yagp-caption p {
    margin: 0;
    font-size: 0.9em;
}

.yagp-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 3em;
    cursor: pointer;
}

#yagp-prev {
    left: 1em;
}

#yagp-next {
    right: 1em;
}

/* Mobile layout (1 item per row) */
@media (max-width: 800px) {
    .yagp-grid {
        flex-direction: column;
    }

    .yagp-item {
        width: 100%;
        flex: none;
    }

    .yagp-item img {
        width: 100%;
        height: auto;
    }
}

/* Tablet layout (2 items per row) */
@media (min-width: 801px) and (max-width: 1200px) {
    .yagp-item {
        flex: 0 0 auto; /* Width will be set by JS */
    }
}

/* Desktop layout (3 items per row) */
@media (min-width: 1201px) {
    .yagp-item {
        flex: 0 0 auto; /* Width will be set by JS */
    }
}

/* Loading Spinner */
.yagp-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    pointer-events: none;
}

.yagp-spinner-circle {
    width: 40px;
    height: 40px;
    border: 3px solid #f0f0f0;
    border-top: 3px solid #999;
    border-radius: 50%;
    animation: yagp-spin 1s linear infinite;
}

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

/* Mobile lightbox adjustments */
@media (max-width: 768px) {
    .yagp-top {
        padding: 0.5em;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(5px);
        z-index: 10001;
    }
    
    #yagp-count {
        font-size: 0.9em;
        white-space: nowrap;
    }
    
    #yagp-close {
        font-size: 1.5em;
        padding: 0.2em;
        min-width: 1.5em;
        min-height: 1.5em;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .yagp-image-container {
        max-width: 95%;
        max-height: 75%;
        margin-top: 3em; /* Ensure space for top bar */
    }
    
    .yagp-arrow {
        font-size: 2em;
        padding: 0.5em;
    }
    
    #yagp-prev {
        left: 0.5em;
    }
    
    #yagp-next {
        right: 0.5em;
    }
}