@media (max-width: 767px), (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] {
        --photo-top: max(60px, calc(env(safe-area-inset-top) + 54px));
        --photo-bottom: max(64px, calc(env(safe-area-inset-bottom) + 54px));
        --photo-left: max(12px, env(safe-area-inset-left));
        --photo-right: max(12px, env(safe-area-inset-right));
        box-sizing: border-box;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        padding: var(--photo-top) var(--photo-right) var(--photo-bottom) var(--photo-left);
        overflow: hidden;
        display: grid;
        grid-template: minmax(0, 1fr) / minmax(0, 1fr);
        place-items: center;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] figure {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
        gap: 6px;
        min-width: 0;
        width: 100%;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] .yiw-photo-brand-frame {
        width: fit-content;
        max-width: 100%;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] figure > img,
    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] .yiw-photo-brand-frame > img {
        width: auto;
        height: auto;
        max-width: calc(100vw - var(--photo-left) - var(--photo-right));
        max-height: calc(100vh - var(--photo-top) - var(--photo-bottom) - 38px);
        max-height: calc(100dvh - var(--photo-top) - var(--photo-bottom) - 38px);
        object-fit: contain;
        object-position: center;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] figcaption {
        box-sizing: border-box;
        max-width: 100%;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] button {
        width: 44px;
        height: 44px;
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] .photo-close {
        top: max(8px, env(safe-area-inset-top));
        right: var(--photo-right);
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] :is(.photo-prev, .photo-next) {
        top: auto;
        bottom: max(8px, env(safe-area-inset-bottom));
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] .photo-prev {
        left: calc(50% - 50px);
    }

    body dialog:is(.yiw-gallery-viewer, .photo-viewer)[open] .photo-next {
        right: calc(50% - 50px);
    }
}
