#lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    overflow: auto; /* Allow scrolling if content overflows */
    justify-content: center;
    align-items: center; /* Restore vertical centering */
}

#lightbox.active {
    display: flex;
}

#lightbox .lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90vh; /* Constrain to 90% of viewport height */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 20px 0; /* Vertical margin for spacing */
}

#lightbox img {
    max-width: 100%;
    max-height: 75vh; /* Reserve space for caption and buttons */
    object-fit: contain; /* Prevent image distortion */
}

#lightbox .lightbox-caption {
    color: white;
    text-align: center;
    margin-top: 10px;
    font-size: 16px;
    max-width: 100%;
    padding: 0 10px; /* Prevent text from touching edges */
}

#lightbox .close, #lightbox .prev, #lightbox .next {
    position: absolute;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 24px;
    padding: 10px;
}

#lightbox .close {
    top: 10px;
    right: 10px;
}

#lightbox .prev {
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
}

#lightbox .next {
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

/* Responsive adjustments for smaller screens */
@media screen and (max-height: 600px) {
    #lightbox img {
        max-height: 65vh; /* Further reduce image height on small screens */
    }
    #lightbox .lightbox-caption {
        font-size: 14px; /* Smaller font for captions */
    }
}