.mw4-gallery-index,
.mw4-gallery-view {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.mw4-gallery-index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.mw4-gallery-index-card {
    border: 1px solid rgba(15, 23, 42, .12);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.mw4-gallery-index-link {
    color: inherit;
    text-decoration: none;
    display: block;
}

.mw4-gallery-index-cover {
    display: block;
    aspect-ratio: 4 / 3;
    background: #eef2f6;
}

.mw4-gallery-index-cover img,
.mw4-gallery-grid img,
.mw4-gallery-random img {
    display: block;
    width: 100%;
    height: 100%;
}

.mw4-gallery-index-cover img {
    object-fit: cover;
}

.mw4-gallery-index-title {
    display: block;
    font-weight: 700;
    padding: 14px 14px 6px;
}

.mw4-gallery-index-card p {
    color: #475467;
    margin: 0;
    padding: 0 14px 14px;
}

.mw4-gallery-header {
    margin-bottom: 24px;
}

.mw4-gallery-header h1 {
    margin: 0 0 8px;
}

.mw4-gallery-header p {
    margin: 0;
    color: #475467;
}

.mw4-gallery-grid {
    display: grid;
    gap: var(--gallery-gap, 16px);
    grid-template-columns: repeat(var(--gallery-cols-desktop, 4), minmax(0, 1fr));
}

.mw4-gallery-layout-masonry_grid {
    column-count: var(--gallery-cols-desktop, 3);
    column-gap: var(--gallery-gap, 16px);
    display: block;
}

.mw4-gallery-layout-masonry_grid .mw4-gallery-item {
    break-inside: avoid;
    margin: 0 0 var(--gallery-gap, 16px);
}

.mw4-gallery-layout-featured_grid .mw4-gallery-item:first-child {
    grid-column: span 2;
    grid-row: span 2;
}

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

.mw4-gallery-item a {
    display: block;
    background: #eef2f6;
    overflow: hidden;
    border-radius: 8px;
    aspect-ratio: var(--gallery-ratio, 4 / 3);
}

.mw4-gallery-layout-masonry_grid .mw4-gallery-item a {
    aspect-ratio: auto;
}

.mw4-gallery-layout-masonry_grid .mw4-gallery-item img {
    height: auto;
}

.mw4-gallery-item img {
    object-fit: cover;
    transition: transform .18s ease;
}

.mw4-gallery-item a:hover img {
    transform: scale(1.025);
}

.mw4-gallery-item figcaption,
.mw4-gallery-random figcaption {
    margin-top: 8px;
    color: #475467;
    font-size: .92rem;
}

.mw4-gallery-empty {
    background: #f8fafc;
    border: 1px solid rgba(15, 23, 42, .1);
    border-radius: 8px;
    color: #667085;
    padding: 24px;
}

.mw4-gallery-random {
    margin: 0;
}

.mw4-gallery-random a {
    display: block;
}

.mw4-gallery-random img {
    object-fit: cover;
    border-radius: 8px;
}

.mw4-gallery-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(2, 6, 23, .92);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 56px 20px 34px;
}

.mw4-gallery-modal.is-open {
    display: flex;
}

.mw4-gallery-modal img {
    max-width: 100%;
    max-height: calc(100vh - 150px);
    object-fit: contain;
}

.mw4-gallery-modal-caption {
    color: #fff;
    text-align: center;
    max-width: 760px;
    margin: 14px auto 0;
}

.mw4-gallery-modal-button {
    position: absolute;
    border: 0;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    min-width: 44px;
    min-height: 44px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
}

.mw4-gallery-modal-close {
    top: 16px;
    right: 16px;
}

.mw4-gallery-modal-prev {
    left: 16px;
}

.mw4-gallery-modal-next {
    right: 16px;
}

@media (max-width: 900px) {
    .mw4-gallery-grid {
        grid-template-columns: repeat(var(--gallery-cols-tablet, 3), minmax(0, 1fr));
    }

    .mw4-gallery-layout-masonry_grid {
        column-count: var(--gallery-cols-tablet, 2);
    }
}

@media (max-width: 640px) {
    .mw4-gallery-index,
    .mw4-gallery-view {
        width: min(100% - 20px, 1120px);
    }

    .mw4-gallery-grid {
        grid-template-columns: repeat(var(--gallery-cols-mobile, 2), minmax(0, 1fr));
    }

    .mw4-gallery-layout-masonry_grid {
        column-count: var(--gallery-cols-mobile, 1);
    }

    .mw4-gallery-layout-featured_grid .mw4-gallery-item:first-child {
        grid-column: auto;
        grid-row: auto;
    }

    .mw4-gallery-modal {
        padding: 50px 10px 26px;
    }
}
