body.image-viewer-open {
    overflow: hidden;
}

dialog.image-viewer:not([open]) {
    display: none;
}

dialog.image-viewer[open] {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: none;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(7, 13, 24, .97);
    color: #fff;
    display: grid;
    grid-template: auto minmax(0, 1fr) / 56px minmax(0, 1fr) 56px;
    overflow: hidden;
}

.image-viewer::backdrop {
    background: rgba(7, 13, 24, .94);
}

.image-viewer .image-viewer-bar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 8px 8px;
    background: rgba(0, 0, 0, .35);
}

.image-viewer button {
    border: 0;
    border-radius: 9px;
    padding: 10px 12px;
    min-width: 44px;
    min-height: 44px;
    background: #fff;
    color: #10213d;
    font: inherit;
    cursor: pointer;
    margin: 0;
}

.image-viewer button:disabled {
    opacity: .5;
}

.image-viewer-count {
    min-width: 50px;
    text-align: center;
}

.image-viewer .image-viewer-stage {
    grid-column: 2;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.image-viewer .image-viewer-stage.zoomed {
    cursor: grab;
}

.image-viewer .image-viewer-stage img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
    object-fit: contain;
    transform-origin: center;
    user-select: none;
    -webkit-user-select: none;
    will-change: transform;
    border-radius: 0;
    margin: 0;
    flex-shrink: 0;
}

.image-viewer .image-viewer-nav {
    align-self: center;
    font-size: 30px;
    z-index: 2;
}

.image-viewer [hidden] {
    display: none !important;
}

@media (max-width: 600px) {
    dialog.image-viewer[open] {
        grid-template: auto minmax(0, 1fr) 60px / 1fr 1fr;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .image-viewer .image-viewer-bar {
        grid-row: 1;
        gap: 5px;
    }
    .image-viewer .image-viewer-stage {
        grid-row: 2;
        grid-column: 1 / -1;
    }
    .image-viewer .image-viewer-nav {
        grid-row: 3;
        justify-self: center;
    }
}
