/* ========================================
   STRANGE FRONTIERS POPUP
   ========================================
   One stylesheet for the popup, wherever it opens: the backdrop over the
   page, the panel that holds the content, and the round X on the panel's
   top right corner.

     strange-frontiers-character-creator  src/app/popup.css (this file)
                                          src/app/components/popup.tsx
     portfolio_site                       css/sf-popup.css (a copy)
                                          php/rpg/components/popup.php

   Both copies must stay identical: change it in the creator, then copy it
   to the site. The components in both repos draw the same markup and take
   the same options (see popup.tsx):

     tone   light (the site's white panel, a dark X) or dark (the creator's
            panel gray, a light X)
     size   narrow (480px), the default (720px) or wide (1100px)
     card   a card on its own: the card is the popup's edge, with no panel
            around it, and a smaller light X on its corner

   The X is the round button (css/sf-buttons.css). What's inside is its
   own component's. */

/* The page under an open popup doesn't scroll */
html.sf-popup-open {
    overflow: hidden;
}

/* ---- The backdrop: the page dimmed and blurred, the panel centered on it.
   It fades in and out. ---- */

.sf-popup {
    --popup-panel: var(--portfolio-white, #ffffff);
    --popup-text: var(--portfolio-black, #1e1f20);
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px 24px;
    background: rgba(0, 0, 0, .75);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}

.sf-popup.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity .2s ease, visibility 0s;
}

.sf-popup--dark {
    --popup-panel: var(--panel, #292b2c);
    --popup-text: var(--panel-text, #e7e8e9);

    :focus-visible {
        outline-color: var(--portfolio-white, #ffffff);
    }
}

/* ---- The panel: the popup's frame, holding the X at its corner. Its
   content scrolls inside it (.sf-popup-scroll), so the X stays put and can
   hang over the edge. ---- */

.sf-popup-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 720px;
    max-height: 100%;
    border-radius: 8px;
    background: var(--popup-panel);
    color: var(--popup-text);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}

.sf-popup--narrow .sf-popup-panel {
    max-width: 480px;
}

.sf-popup--wide .sf-popup-panel {
    max-width: 1100px;
}

.sf-popup-scroll {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 32px;
    border-radius: inherit;
}

/* A title over the content, clear of the X */
.sf-popup-title {
    margin: 0 0 16px;
    padding-right: 48px;
    color: inherit;
}

.sf-popup-body > :last-child {
    margin-bottom: 0;
}

/* ---- The X: half outside the panel's top right corner ---- */

.sf-popup-close {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    transform: translate(50%, -50%);
}

/* ---- card: the card is the popup's edge, with no panel around it, and the
   X, smaller and light, sits on its corner. The title stays for screen
   readers. A long card scrolls itself. ---- */

.sf-popup--card {
    .sf-popup-panel {
        max-width: 560px;
        border-radius: 12px;
        background: none;
        box-shadow: none;
    }

    .sf-popup-scroll {
        padding: 0;
        overflow: visible;
    }

    .sf-popup-title {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    /* View only: no pointer, and no hover border like the cards to pick */
    :is(.sf-popup-scroll, .sf-popup-body) > .sf-card {
        margin: 0;
        max-height: calc(100dvh - 128px);
        overflow-y: auto;
        cursor: default;

        &:hover {
            border-color: var(--card-edge, var(--card-border));
        }
    }

    .sf-btn.sf-popup-close {
        --sf-btn-size: 28px;
        --sf-btn-bg: var(--portfolio-near-white, #f6f6f6);
        --sf-btn-fg: var(--portfolio-black, #1e1f20);
        --sf-btn-mix: var(--portfolio-black, #1e1f20);
        --sf-btn-keep: 75%;

        svg {
            width: 12px;
            height: 12px;
        }
    }
}

@media (max-width: 767px) {
    .sf-popup {
        padding: 24px 16px;
    }

    .sf-popup-scroll {
        padding: 24px;
    }

    /* Small enough that its outer half fits the 16px beside the panel */
    .sf-popup:not(.sf-popup--card) .sf-btn.sf-popup-close {
        --sf-btn-size: 32px;
    }
}

/* A popup isn't printed */
@media print {
    .sf-popup {
        display: none !important;
    }
}
