/**
 * Gallery Mode - Full Screen Image Viewer
 * @package Magezix Child
 */

/* Body scroll lock when gallery is open */
body.gallery-mode-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}

/* Overlay */
.gallery-mode-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    background: #000;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overscroll-behavior: contain;
}

.gallery-mode-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Header */
.gallery-mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    flex-shrink: 0;
}

.gallery-mode-counter {
    font-size: 16px;
    font-weight: 500;
    color: #fff;
}

.gallery-mode-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.gallery-mode-play {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, background 0.2s ease;
    position: relative;
    font-size: 14px;
}

.gallery-mode-play:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Timer progress ring - animatable custom property */
@property --timer-progress {
    syntax: "<percentage>";
    inherits: false;
    initial-value: 0%;
}

/* Loading ring when playing */
.gallery-mode-play.playing::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    background: conic-gradient(var(--color-primary) var(--timer-progress), transparent 0);
    animation: timerFill 3s linear infinite;
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}

@keyframes timerFill {
    from {
        --timer-progress: 0%;
    }

    to {
        --timer-progress: 100%;
    }
}

.gallery-mode-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
    transition: opacity 0.2s ease;
}

.gallery-mode-close:hover {
    opacity: 0.7;
}

/* Image Container */
.gallery-mode-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 20px;
}

.gallery-mode-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    opacity: 0;
    visibility: hidden;
}

.gallery-mode-image.loaded {
    opacity: 1;
    visibility: visible;
    animation: slideUp 0.35s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Loader */
.gallery-mode-loader {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: galleryLoaderSpin 0.8s linear infinite;
}

@keyframes galleryLoaderSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Navigation Arrows */
.gallery-mode-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 32px;
    padding: 20px 15px;
    cursor: pointer;
    transition: background 0.2s ease;
    z-index: 10;
}

.gallery-mode-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.gallery-mode-nav.prev {
    left: 10px;
    border-radius: 0 8px 8px 0;
}

.gallery-mode-nav.next {
    right: 10px;
    border-radius: 8px 0 0 8px;
}

.gallery-mode-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Hide arrows on single image */
.gallery-mode-overlay.single-image .gallery-mode-nav {
    display: none;
}

/* Trigger Button - inherits wp-block-button__link styles */
#gallery-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    justify-content: center;
}

#gallery-mode-btn i {
    font-size: 1em;
}

/* Hide button if no images */
#gallery-mode-btn.hidden {
    display: none !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .gallery-mode-header {
        padding: 10px 15px;
    }

    .gallery-mode-counter {
        font-size: 14px;
    }

    .gallery-mode-close {
        font-size: 24px;
    }

    .gallery-mode-nav {
        padding: 15px 10px;
        font-size: 24px;
    }

    .gallery-mode-container {
        padding: 10px;
    }

    /* Sticky floating button at bottom on mobile */
    #gallery-mode-btn {
        position: fixed !important;
        bottom: 60px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 9999;
        width: auto !important;
        height: auto !important;
        padding: 14px 28px !important;
        font-size: 16px;
        border-radius: 50px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        gap: 8px;
        max-width: none !important;
        background-color: var(--color-primary) !important;
        color: #fff !important;
        border: none !important;
        font-weight: bold !important;
    }

    #gallery-mode-btn.hidden {
        display: none !important;
    }

    /* Hide button when gallery is open */
    body.gallery-mode-open #gallery-mode-btn {
        display: none !important;
    }
}

/* No scrolling when gallery is open */
body.gallery-mode-open {
    overflow: hidden;
}