.sgraphics-popup-dialog:not([open]) {
    display: none;
}

.sgraphics-popup-dialog {
    --sgp-extra: 0px;
    --sgp-side-space: max(12px, calc(0px - var(--sgp-x)));
    --sgp-target: max(44px, var(--sgp-size));
    position: fixed;
    inset: 0;
    width: fit-content;
    height: fit-content;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}

.sgraphics-popup-dialog::backdrop {
    background: rgb(0 0 0 / 72%);
}

.sgraphics-popup-dialog img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(900px, calc(100vw - 2 * var(--sgp-side-space)));
    max-height: calc(100vh - 24px - var(--sgp-extra));
    max-height: calc(100dvh - 24px - var(--sgp-extra));
}

.sgraphics-popup-dialog.outside {
    --sgp-extra: calc(var(--sgp-target) + var(--sgp-y));
    box-sizing: border-box;
}

.sgraphics-popup-dialog.outside:is(.top-left, .top-right) {
    padding-top: var(--sgp-extra);
}

.sgraphics-popup-dialog.outside:is(.bottom-left, .bottom-right) {
    padding-bottom: var(--sgp-extra);
}

.sgraphics-popup-dialog .sgraphics-popup-close {
    position: absolute;
    display: grid;
    place-items: center;
    width: var(--sgp-target);
    height: var(--sgp-target);
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    outline: none;
    text-decoration: none;
    color: var(--sgp-color);
    text-shadow: var(--sgp-shadow);
    font: var(--sgp-size)/1 system-ui, sans-serif;
    cursor: pointer;
}

.sgraphics-popup-dialog .sgraphics-popup-close:hover {
    color: var(--sgp-hover);
    background: transparent;
}

.sgraphics-popup-dialog .sgraphics-popup-close:focus-visible {
    outline: none;
    text-decoration: none;
    color: var(--sgp-hover);
}

.sgraphics-popup-dialog :is(img, .sgraphics-popup-close) {
    margin: 0;
}

.sgraphics-popup-dialog:is(.top-left, .top-right) .sgraphics-popup-close {
    top: var(--sgp-y);
}

.sgraphics-popup-dialog:is(.bottom-left, .bottom-right) .sgraphics-popup-close {
    bottom: var(--sgp-y);
}

.sgraphics-popup-dialog.outside .sgraphics-popup-close {
    --sgp-y: 0px;
}

.sgraphics-popup-dialog:is(.top-left, .bottom-left) .sgraphics-popup-close {
    left: min(var(--sgp-x), max(0px, 100% - var(--sgp-target)));
}

.sgraphics-popup-dialog:is(.top-right, .bottom-right) .sgraphics-popup-close {
    right: min(var(--sgp-x), max(0px, 100% - var(--sgp-target)));
}

html:has(.sgraphics-popup-dialog[open]) {
    overflow: hidden;
}
