/* [gallery] shortcode - see themes/ms/blocks/page-media.php */

.ms-gallery {
    clear: both;
    position: relative;
    margin: 24px 0;
    --ms-gallery-gap: 16px;
}

.ms-gallery-item {
    margin: 0;
}

.ms-gallery-link {
    display: block;
    overflow: hidden;
    text-decoration: none;
}

.ms-gallery-item img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: var(--ms-gallery-ratio, 4 / 3);
    object-fit: cover;
    transition: transform 0.2s ease;
}

.ms-gallery-link:hover img {
    transform: scale(1.03);
}

.ms-gallery-caption {
    margin-top: 6px;
    font-size: 0.9em;
    line-height: 1.35;
}

/* grid */
.ms-gallery-grid .ms-gallery-track {
    display: grid;
    gap: var(--ms-gallery-gap);
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.ms-gallery-grid[style*="--ms-gallery-cols"] .ms-gallery-track {
    grid-template-columns: repeat(var(--ms-gallery-cols), minmax(0, 1fr));
}

/* strip: one scrollable row */
.ms-gallery-strip .ms-gallery-track,
.ms-gallery-slider .ms-gallery-track {
    display: flex;
    gap: var(--ms-gallery-gap);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.ms-gallery-strip .ms-gallery-item {
    flex: 0 0 calc(100% / var(--ms-gallery-cols, 4) - var(--ms-gallery-gap));
    min-width: 140px;
    scroll-snap-align: start;
}

/* slider: one slide per view by default, cols = slides per view */
.ms-gallery-slider .ms-gallery-track {
    scrollbar-width: none;
}

.ms-gallery-slider .ms-gallery-track::-webkit-scrollbar {
    display: none;
}

.ms-gallery-slider .ms-gallery-item {
    flex: 0 0 calc((100% - (var(--ms-gallery-cols, 1) - 1) * var(--ms-gallery-gap)) / var(--ms-gallery-cols, 1));
    scroll-snap-align: start;
}

.ms-gallery-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 44px;
    height: 44px;
    margin-top: -22px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font: 30px/44px Arial, sans-serif;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.ms-gallery-nav:hover,
.ms-gallery-nav:focus {
    background: rgba(0, 0, 0, 0.8);
}

.ms-gallery-nav[disabled] {
    opacity: 0.3;
    cursor: default;
}

.ms-gallery-prev {
    left: 10px;
}

.ms-gallery-next {
    right: 10px;
}

@media (max-width: 600px) {
    .ms-gallery-grid[style*="--ms-gallery-cols"] .ms-gallery-track {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ms-gallery-strip .ms-gallery-item {
        flex-basis: 70%;
    }

    .ms-gallery-slider .ms-gallery-item {
        flex-basis: 100%;
    }
}

/* arrow glyphs live in CSS so they never end up in strip_tags() text */
.ms-gallery-prev::before {
    content: "\2039";
}

.ms-gallery-next::before {
    content: "\203A";
}

/* built-in popup, used when the theme has no lightbox of its own */
.ms-lb {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100000;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.88);
}

.ms-lb-open {
    display: flex;
}

.ms-lb-lock {
    overflow: hidden;
}

.ms-lb-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 92vw;
    max-height: 92vh;
    margin: 0;
}

.ms-lb-img {
    display: block;
    max-width: 92vw;
    max-height: 82vh;
    width: auto;
    height: auto;
    object-fit: contain;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
}

.ms-lb-caption {
    margin-top: 10px;
    color: #fff;
    font: 15px/1.4 Arial, sans-serif;
    text-align: center;
}

.ms-lb-count {
    position: absolute;
    left: 16px;
    top: 14px;
    color: #fff;
    font: 14px/1 Arial, sans-serif;
    opacity: 0.8;
}

.ms-lb-close,
.ms-lb-nav {
    position: absolute;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-family: Arial, sans-serif;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ms-lb-close:hover,
.ms-lb-close:focus,
.ms-lb-nav:hover,
.ms-lb-nav:focus {
    background: rgba(255, 255, 255, 0.34);
}

.ms-lb-close {
    top: 12px;
    right: 14px;
    width: 42px;
    height: 42px;
    font-size: 28px;
    line-height: 42px;
}

.ms-lb-close::before {
    content: "\00D7";
}

.ms-lb-nav {
    top: 50%;
    width: 52px;
    height: 52px;
    margin-top: -26px;
    font-size: 36px;
    line-height: 50px;
}

.ms-lb-prev {
    left: 14px;
}

.ms-lb-next {
    right: 14px;
}

.ms-lb-prev::before {
    content: "\2039";
}

.ms-lb-next::before {
    content: "\203A";
}

@media (max-width: 600px) {
    .ms-lb-nav {
        width: 42px;
        height: 42px;
        margin-top: -21px;
        font-size: 30px;
        line-height: 40px;
    }

    .ms-lb-prev {
        left: 6px;
    }

    .ms-lb-next {
        right: 6px;
    }
}
