/* W153 Popups */

/*
The dialog has no box of its own: it only centers the box (__inner) and holds the close button outside it.
The box takes the size of its content (sizes are set in the content), up to 90% of the window, then scrolls.
On short windows the max height is lowered, so the close button above the box always fits on screen.
*/
.w153-popups__popup {
    --w153-popups-close-size: 2rem;
    --w153-popups-close-gap: 0.75rem;
    --w153-popups-max-width: 90vw;
    /* 90% of the window, but leaving room above (and, centered, below) for the close button + gap. */
    --w153-popups-max-height: min(90vh, 100vh - 2 * (var(--w153-popups-close-size) + var(--w153-popups-close-gap) + 0.5rem));
    --w153-popups-background: #fff;
    --w153-popups-color: inherit;
    --w153-popups-radius: 0;
    --w153-popups-backdrop: rgba(0, 0, 0, 0.8);
    --w153-popups-close-color: #fff;

    box-sizing: border-box;
    width: fit-content;
    height: fit-content;
    max-width: var(--w153-popups-max-width);
    max-height: none;
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--w153-popups-color);
    /* Not clipped, so the close button can be outside the box. */
    overflow: visible;
}

@supports (height: 1dvh) {
    .w153-popups__popup {
        --w153-popups-max-height: min(90dvh, 100dvh - 2 * (var(--w153-popups-close-size) + var(--w153-popups-close-gap) + 0.5rem));
    }
}

.w153-popups__popup[open] {
    animation: w153-popups-in 0.25s ease-out;
}

.w153-popups__popup::backdrop {
    background: var(--w153-popups-backdrop);
    animation: w153-popups-fade 0.25s ease-out;
}

/* Lock page scrolling while a popup is open. */
html:has(.w153-popups__popup[open]) {
    overflow: hidden;
}

.w153-popups__inner {
    box-sizing: border-box;
    max-width: var(--w153-popups-max-width);
    max-height: var(--w153-popups-max-height);
    padding: 0;
    border-radius: var(--w153-popups-radius);
    background: var(--w153-popups-background);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: auto;
    overscroll-behavior: contain;
}

/* Above the top-right corner of the box, on the backdrop. */
.w153-popups__close {
    position: absolute;
    right: 0;
    bottom: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--w153-popups-close-size);
    height: var(--w153-popups-close-size);
    margin-bottom: var(--w153-popups-close-gap);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--w153-popups-close-color);
    cursor: pointer;
    opacity: 0.85;
}

.w153-popups__close:hover,
.w153-popups__close:focus-visible {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

/*
Defaults for the content. Wrapped in :where() so they have no specificity:
any class in the popup HTML overrides them.
*/
:where(.w153-popups__content > :first-child) {
    margin-top: 0;
}

:where(.w153-popups__content > :last-child) {
    margin-bottom: 0;
}

/* Images fit the box. */
:where(.w153-popups__content img) {
    max-width: 100%;
    height: auto;
}

/* An image placed directly in the popup (no gap under it). */
:where(.w153-popups__content > img) {
    display: block;
}

@keyframes w153-popups-in {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
}

@keyframes w153-popups-fade {
    from {
        opacity: 0;
    }
}
