/**
 * Modal windows: the shared shell every window builds on.
 *
 * Each window has its own sheet in css/windows/, linked from index.html in
 * the order the sections used to appear in this file. That order is part of
 * the cascade — re-order the <link> tags and window chrome shifts.
 *
 * The scrim sits above `#hud` (z-index 10) on purpose — every frame in the
 * design dims the HUD along with the world when a window is up — and above the
 * start menu (z-index 300), whose OPTION button opens a modal before the game
 * starts. The loading and error screens hide before any modal can open.
 *
 * Wooden surfaces here are fallbacks. When the panel art arrives it replaces
 * the gradients; the layout does not change.
 */

#modalLayer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 400;
}

.modal-scrim {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    background: var(--scrim);
    display: grid;
    place-items: center;
    padding: 24px;
    animation: scrim-in 180ms ease-out both;
}

/*
 * Animations, not transitions: they play the moment the element enters the
 * document with no JS and no rAF dependency, so visibility never rests on a
 * frame callback. Only opening is animated — a lingering close delays the
 * board the player is trying to get back to.
 */
@keyframes scrim-in {
    from {
        background: transparent;
    }
}

@keyframes panel-in {
    from {
        opacity: 0;
        transform: scale(0.93) translateY(16px);
    }
    60% {
        opacity: 1;
        transform: scale(1.015) translateY(-2px);
    }
}

.modal-panel {
    position: relative;
    pointer-events: auto;
    max-width: min(1100px, 92vw);
    max-height: 86vh;
    padding: 22px 26px 26px;
    /*
     * The frame is real art, nine-sliced: the corner brackets keep their drawn
     * size while only the edges stretch, so one image fits every window from
     * the narrow Options panel to the wide Build library. Themes supply the
     * art and its measurements; `fill` paints the middle, which is why there
     * is no `background` here.
     */
    border-style: solid;
    border-width: var(--panel-border);
    border-image: var(--panel-frame) var(--panel-slice) fill stretch;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
    color: var(--panel-text);
    transform-origin: center bottom;
    will-change: transform, opacity;
    /* Slight overshoot, so the panel reads as having landed rather than faded in. */
    animation: panel-in 300ms cubic-bezier(0.2, 0.9, 0.16, 1.08) both;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/*
 * The panel takes focus only so Escape reaches the window; it is a container,
 * not a control, so it draws no focus ring — the controls inside keep their
 * own `:focus-visible` outlines for keyboard play.
 */
.modal-panel:focus {
    outline: none;
}

/*
 * Title tab, riding the frame's top edge on the left — the reference screens
 * put it there rather than centred, stepping down into the panel body. It sits
 * inside the border box (not overhanging it) so the frame art stays unbroken.
 */
.modal-title {
    align-self: flex-start;
    margin: -8px 0 12px;
    padding: 2px 4px;
    color: var(--heading);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.45);
    white-space: nowrap;
}

.modal-title.is-empty {
    display: none;
}

/* Inside the frame's top-right corner, clear of the frame art's corner bracket. */
.modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 2px solid var(--edge);
    background: transparent;
    color: var(--edge);
    font-family: inherit;
    /* Zeroed by themes that supply `--close-art`, so the glyph and the
       picture never draw on top of each other. */
    font-size: var(--chrome-glyph-size, 15px);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.modal-header {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
}

.modal-close:hover {
    transform: scale(1.06);
}

.modal-close:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.modal-body {
    min-height: 0;
    overflow: hidden;
    display: flex;
}
