/* ========================================
   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
     scroll panel (the panel's content scrolls as one) or inner (the panel
            holds still and a part of its content scrolls inside it)

   A popup's actions (Add items, Submit) go in a foot (.sf-popup-foot) that
   stays at the bottom of the panel while the content scrolls.

   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 {
    /* The panel's padding around its content */
    --popup-pad: 32px;
    --popup-panel: var(--sf-gray-0);
    --popup-text: var(--sf-gray-800);
    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, var(--sf-gray-700));
    --popup-text: var(--panel-text, var(--sf-gray-100));

    :focus-visible {
        outline-color: var(--sf-gray-0);
    }
}

/* ---- 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;
}

/* A character sheet (the Game Master's view of a player's): up to 1368px,
   with 48px beside it so the panel and the X on its corner stay clear of
   the screen's sides. Phones get 24px (below). */
.sf-popup--sheet {
    padding-inline: 48px;

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

.sf-popup-scroll {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--popup-pad);
    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;
}

/* ---- scroll inner: the panel holds still, its title and anything else
   staying put, while the part marked .sf-popup-grow takes the room left
   and scrolls inside (its own content says which part of it scrolls). Its
   foot stays under it. ---- */

.sf-popup--inner .sf-popup-scroll {
    display: flex;
    flex-direction: column;
    overflow: hidden;

    > * {
        flex: none;
    }

    > .sf-popup-grow {
        flex: 0 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
}

/* ---- The foot: the popup's actions, right aligned over a rule, as wide
   as the panel and held to its bottom edge from the first scroll to the
   last (it takes the place of the panel's bottom padding, so there's none
   left to scroll into view under it) ---- */

.sf-popup-foot {
    position: sticky;
    bottom: calc(-1 * var(--popup-pad));
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 12px;
    margin: 24px calc(-1 * var(--popup-pad)) calc(-1 * var(--popup-pad));
    padding: 16px var(--popup-pad);
    background: var(--popup-panel);
    border-top: 1px solid var(--card-border, var(--sf-gray-400));
    border-radius: 0 0 8px 8px;
}

/* ---- 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(--sf-gray-50);
        --sf-btn-fg: var(--sf-gray-800);
        --sf-btn-mix: var(--sf-gray-800);
        --sf-btn-keep: 75%;

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

/* At 1768px and below, less room over and under the panel and less padding
   inside it, and a smaller title, so more of the content fits */
@media (max-width: 1768px) {
    .sf-popup {
        --popup-pad: 24px;
        padding-block: 32px;
    }

    /* A card on its own fills the taller room left */
    .sf-popup--card :is(.sf-popup-scroll, .sf-popup-body) > .sf-card {
        max-height: calc(100dvh - 64px);
    }

    .sf-popup-title,
    .sf-popup .step-head > h2 {
        font-size: 1.75rem;
    }
}

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

    /* 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 sheet keeps 24px, so its X clears the screen's side too */
    .sf-popup--sheet {
        padding-inline: 24px;
    }
}

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