.star-r7-gallery {
    width: min(1080px, calc(100% - 24px));
    max-height: calc(100dvh - 24px);
    box-sizing: border-box;
    padding: clamp(10px, 2vw, 22px);
    border: 2px solid #211b18;
    border-radius: 18px;
    color: #211b18;
    background: #fff8f4;
    overscroll-behavior: contain;
}

html[theme="dark"] .star-r7-gallery {
    color: #fff8f4;
    background: #211b18;
    border-color: #ffc2b0;
}

.star-r7-gallery::backdrop { background: #130d0cdd; }

.star-r7-gallery-toolbar,
.star-r7-gallery-navigation {
    display: flex;
    align-items: center;
    gap: 8px;
}

.star-r7-gallery-toolbar {
    justify-content: space-between;
    margin-bottom: 10px;
}

.star-r7-gallery-toolbar form,
.star-r7-gallery figure { margin: 0; }

.star-r7-gallery-toolbar button {
    min-width: 44px;
    min-height: 44px;
    padding: 5px 12px;
    border: 2px solid #211b18;
    border-radius: 999px;
    color: #130d0c !important;
    background: #10b742;
    font: inherit;
    font-weight: 700;
    line-height: 1.15;
    cursor: pointer;
}

.star-r7-gallery-toolbar button[data-gallery-step] { font-size: 1.4rem; }
.star-r7-gallery-toolbar button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -5px;
}

.star-r7-gallery-count {
    min-width: 4ch;
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.star-r7-gallery-media {
    position: relative;
    height: min(55dvh, 700px);
    overflow: hidden;
    border-radius: 8px;
    touch-action: pan-y pinch-zoom;
    background: #f8eeea;
}

html[theme="dark"] .star-r7-gallery-media { background: #171210; }

.star-r7-gallery-media > img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    /* The shared content stylesheet sets image height to auto. */
    height: 100% !important;
    margin: 0;
    object-fit: contain;
    object-position: center;
    user-select: none;
}

.star-r7-gallery figcaption { margin-top: 10px; }
.star-r7-gallery figcaption > span { display: block; }
.star-r7-gallery figcaption > p { margin: 4px 0 0; }

@media (max-width: 520px) {
    .star-r7-gallery-media {
        height: 41dvh;
        max-height: calc((100vw - 60px) * .9);
    }

    .star-r7-gallery .star-card-legend { grid-template-columns: 1fr; }
}

.star-r7-gallery-play {
    min-inline-size: 9em;
    margin-inline-start: auto;
}

.star-r7-gallery-thumbnails {
    --thumbnail-y: 0%;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding: 5px 4px;
    margin-top: 5px;
    scrollbar-width: thin;
    overscroll-behavior-inline: contain;
}

[data-cad-theme="night"] .star-r7-gallery-thumbnails { --thumbnail-y: 100%; }

.star-r7-gallery-thumbnails button {
    flex: 0 0 76px;
    box-sizing: border-box;
    aspect-ratio: 7 / 5;
    padding: 0;
    overflow: hidden;
    color: inherit;
    background: transparent;
    border-radius: 6px;
    border: 2px solid currentColor;
    cursor: pointer;
}

.star-r7-gallery-thumbnails button[aria-current] {
    border-color: #008d31;
    outline: 2px solid #008d31;
}

html[theme="dark"] .star-r7-gallery-thumbnails button[aria-current] {
    border-color: #36e171;
    outline-color: #36e171;
}

.star-r7-gallery-thumbnails button:focus-visible {
    outline: 2px dashed currentColor;
    outline-offset: 2px;
}

.star-r7-gallery-preview {
    display: block;
    width: 100%;
    height: 100%;
    background-image: url("thumbnails.webp");
    background-size: 900% 200%;
    background-position: var(--thumbnail-x) var(--thumbnail-y);
    background-repeat: no-repeat;
}

@media (max-width: 410px) {
    .star-r7-gallery-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .star-r7-gallery-navigation { gap: 5px; }
    .star-r7-gallery-toolbar button[data-gallery-step] { padding-inline: 4px; }
    .star-r7-gallery-toolbar form { grid-area: 1 / 2; }
    .star-r7-gallery-play {
        grid-area: 2 / 1 / 3 / 3;
        margin-inline-start: 0;
    }
    .star-r7-gallery-thumbnails button { flex-basis: 60px; }
}
