.sp-article-cover {
    margin: 0 0 var(--sp-content-spacing);
}

.sp-article-cover img {
    display: block;
    max-width: 100%;
    max-height: 420px;
    margin: 0 auto;
    object-fit: contain;
}

.sp-article-gallery {
    position: relative;
    container-type: inline-size;
    margin: var(--sp-content-spacing) 0;
}

.content .sp-gallery-track {
    --sp-gallery-columns: 1;
    --sp-gallery-gap: 12px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% + var(--sp-gallery-gap)) / min(var(--sp-gallery-columns), var(--sp-gallery-items)) - var(--sp-gallery-gap));
    gap: var(--sp-gallery-gap);
    margin: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

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

.sp-gallery-slide {
    min-width: 0;
    margin: 0;
    scroll-snap-align: start;
}

.sp-gallery-slide a {
    display: block;
    aspect-ratio: var(--sp-gallery-ratio, 5 / 3);
    overflow: hidden;
    border-radius: 4px;
    background: var(--sp-surface-subtle);
    cursor: zoom-in;
}

.content .sp-gallery-slide img {
    width: 100%;
    height: 100% !important;
    object-fit: contain;
}

.content .sp-gallery-cover .sp-gallery-slide img {
    object-fit: cover;
}

@container (min-width: 480px) {
    .content .sp-gallery-track { --sp-gallery-columns: 2; }
}

@container (min-width: 720px) {
    .content .sp-gallery-track { --sp-gallery-columns: 3; }
}

@container (min-width: 1040px) {
    .content .sp-gallery-track { --sp-gallery-columns: 4; }
}

.content .sp-gallery-controls {
    position: absolute;
    inset: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    pointer-events: none;
}

.content .sp-gallery-controls[hidden] {
    display: none;
}

.sp-gallery-controls button,
.sp-gallery-close {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--sp-border);
    border-radius: 4px;
    background: var(--sp-surface-plain);
    color: var(--sp-text-title);
    font: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.sp-gallery-controls button:hover,
.sp-gallery-close:hover {
    color: var(--sp-accent);
    border-color: var(--sp-accent);
}

.sp-gallery-controls button {
    pointer-events: auto;
}

.sp-gallery-slide a:focus-visible,
.sp-gallery-track:focus-visible,
.sp-gallery-controls button:focus-visible,
.sp-gallery-close:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: -2px;
}

.sp-gallery-dialog {
    position: fixed;
    inset: 0;
    width: fit-content;
    height: fit-content;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    margin: auto;
    box-sizing: border-box;
    padding: 12px;
    border: 1px solid var(--sp-border);
    background: var(--sp-surface-plain);
    color: var(--sp-text-body);
}

.sp-gallery-dialog::backdrop {
    background: rgba(0, 0, 0, 0.78);
}

.sp-gallery-dialog figure {
    margin: 0;
    text-align: center;
}

.content .sp-gallery-preview {
    position: relative;
    display: grid;
    min-width: 112px;
    min-height: 72px;
    margin: 0;
    place-items: center;
    touch-action: pan-y pinch-zoom;
}

.sp-gallery-dialog img {
    max-width: calc(100vw - 58px);
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    object-fit: contain;
}

.sp-gallery-dialog figcaption {
    padding: 6px 0 0;
}

.sp-gallery-close {
    position: absolute;
    z-index: 2;
    top: 16px;
    right: 16px;
}
