/* Gallery Overlay */
#gallery-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 20px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition: opacity 0.4s ease, visibility 0.4s ease;
    height: calc(100vh + 2px);
}

/* Open State */
#gallery-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Gallery Container */
#gallery-container {
    position: relative;

    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 90vh;

    display: flex;
    flex-direction: column;

    background: #fff;
    border-radius: 16px;
    overflow: hidden;

    transform: translateY(30px) scale(0.96);
    opacity: 0;

    transition:
        transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.3s ease;
}

/* Container Open Animation */
#gallery-overlay.active #gallery-container {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Header */
.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 18px 24px;
    border-bottom: 1px solid #eee;

    flex-shrink: 0;
}

.gallery-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #111;
}

/* Close Button */
.gallery-close {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 44px;
    height: 44px;

    border: none;
    border-radius: 50%;

    background: #f1f1f1;
    color: #111;

    font-size: 32px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.25s ease,
        color 0.25s ease,
        transform 0.3s ease;
}

.gallery-close:hover {
    background: #111;
    color: #fff;
    transform: rotate(90deg);
}

.gallery-close:focus-visible {
    outline: 3px solid #777;
    outline-offset: 3px;
}

/* Individual Photo */
.gallery-photo {
    margin: 0;
    width: 100%;
    height: auto;
    display: block;
    margin-bottom: 12px;
    break-inside: avoid;
    border-radius: 8px;
}


/* Staggered Photo Animation */
@keyframes photoFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Grid */
@media (max-width: 768px) {
    #gallery-overlay {
        padding: 10px;
    }

    #gallery-container {
        max-height: calc(100% - 6px);
        border-radius: 12px;
    }

    .gallery-header {
        padding: 14px 16px;
    }
}
/* Respect Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    #gallery-overlay,
    #gallery-container,
    .gallery-close,
    .gallery-photo img {
        transition: none;
    }

    .gallery-photo {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/* Fullscreen Photo Viewer */
#photo-viewer {
    position: fixed;
    inset: 0;
    z-index: 10001;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(0, 0, 0, 0.96);
    backdrop-filter: blur(8px);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition: opacity 0.3s ease, visibility 0.3s ease;

    touch-action: pan-y;
}

#photo-viewer.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

#viewer-image {
    display: block;

    max-width: 85vw;
    max-height: 85vh;

    width: auto;
    height: auto;

    object-fit: contain;

    user-select: none;
    -webkit-user-drag: none;

    opacity: 0;
    transform: scale(0.96);

    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
}

#photo-viewer.active #viewer-image {
    opacity: 1;
    transform: scale(1);
}

/* Close Button */
.viewer-close {
    position: absolute;
    top: 20px;
    right: 25px;
    z-index: 2;

    width: 48px;
    height: 48px;

    border: none;
    border-radius: 50%;

    background: rgba(255, 255, 255, 0.12);
    color: white;

    font-size: 36px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.2s ease,
        transform 0.2s ease;
        
    outline: none;
}

.viewer-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

/* Navigation Buttons */
.viewer-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 72px;
    border: none;
    border-radius: 10px;
    background: rgb(0 0 0 / 40%);
    color: white;
    font-size: 30px;
    cursor: pointer;
    transform: translateY(-50%);
    transition: background 0.2s ease;
}

.viewer-prev {
    left: 20px;
}

.viewer-next {
    right: 20px;
}

/* Photo Counter */
.viewer-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;

    color: white;
    font-size: 14px;

    transform: translateX(-50%);
}

/* Make Gallery Photos Clickable */
.gallery-photo {
    cursor: pointer;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    #viewer-image {
        max-width: 100vw;
        max-height: 80vh;
    }

    .viewer-close {
        top: 12px;
        right: 12px;

        width: 44px;
        height: 44px;
    }

    .viewer-nav {
        width: 40px;
        height: 56px;

        font-size: 24px;
    }

    .viewer-prev {
        left: 8px;
    }

    .viewer-next {
        right: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #photo-viewer,
    #viewer-image,
    .viewer-close,
    .viewer-nav {
        transition: none;
    }
}

.photo-grid {
    columns: 200px;
    column-gap: 12px;
    padding: 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.photo-grid img {
    width: 100%;
    height: auto;
    display: block;
    margin-bottom: 12px;
    break-inside: avoid;
    border-radius: 8px;
}