/**
 * Popups.
 *
 * Each popup is a native <dialog>, so it sits above everything (the header
 * included), keeps keyboard focus inside and closes on Esc by itself. The
 * dialog covers the whole window and scrolls on its own when its content is
 * taller than the screen; the page underneath is blurred, as on the old site
 * (rec2013049203: a 4 px backdrop blur and a 0.3 s fade).
 */

/*
 * The page stops scrolling while a popup is open. Hiding its scrollbar would
 * widen the page by the scrollbar's width and shift everything sideways, so
 * the space the scrollbar took is kept.
 */
html.bbs-popup-open {
    overflow: hidden;
    scrollbar-gutter: stable;
}

.bbs-popup {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    background: transparent;
    color: inherit;
}

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

.bbs-popup::backdrop {
    background: rgba(0, 0, 0, 0.2);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.bbs-popup[open],
.bbs-popup[open]::backdrop {
    animation: bbs-popup-fade 0.3s ease-in-out;
}

@keyframes bbs-popup-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Centres the content when it is shorter than the window, and is what the
 * close button is placed against, so the button scrolls with the popup. */
.bbs-popup__body {
    position: relative;
    display: flex;
    box-sizing: border-box;
    align-items: center;
    min-height: 100%;
}

.bbs-popup__body > * {
    width: 100%;
}

/* On narrow screens the popup runs to the sides of the window, so the close
 * button goes above it: this keeps a strip free for it there. */
@media (max-width: 959px) {
    .bbs-popup__body {
        padding-top: 52px;
    }
}

/*
 * Close button: a white disc with a dark cross, so it reads on the orange
 * card, on a white panel and on the page behind alike. popups/script.js moves
 * it to the popup's top right corner, outside the popup wherever there is
 * room, so it never covers a heading. top/right below only hold it somewhere
 * sensible until then.
 */
.bbs-popup__close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    color: #000000;
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.bbs-popup__close svg {
    display: block;
    width: 14px;
    height: 14px;
}

.bbs-popup__close:hover {
    transform: scale(1.08);
}

/* The dialog focuses the close button as it opens; no ring, as on every
 * other button on the site. */
.bbs-popup__close:focus,
.bbs-popup__close:focus-visible {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    .bbs-popup[open],
    .bbs-popup[open]::backdrop {
        animation: none;
    }

    .bbs-popup__close {
        transition: none;
    }
}
