/* ─────────────────────────────────────────────────────────────────────────
   app-shell.css — the SHARED, NON-SCOPED top-bar chrome.

   The `.gl-*` top-bar classes were authored only in MainLayout.razor.css, which
   Blazor compiles as *component-scoped* CSS (`.gl-top-bar[b-xxxxx]`). Any OTHER
   layout that reuses the same markup — notably EmptyLayout.razor, which
   copies the `gl-top-bar` header verbatim — received NONE of those styles, so
   its top bar rendered unstyled (transparent bar, native-looking Sign out
   button, mis-tinted brand).

   These rules are the single source of truth for the app-wide top bar and MUST
   stay non-scoped so every layout that renders the `gl-top-bar` header inherits
   identical chrome.

   Anything rendered by more than one layout lives HERE, and
   MainLayout.razor.css keeps only what is unique to MainLayout's markup (the
   status pills, .gl-content, the toast stack). A second scoped copy of these
   selectors would drift, and which one a user saw would depend on which layout
   rendered the bar.
   ───────────────────────────────────────────────────────────────────────── */

/* ── Page shell ──────────────────────────────────────────────────────────────
   Shared: MainLayout and EmptyLayout both render `.gl-page` as their root. */
.gl-page {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    /* Stop any sub-pixel overflow from any descendant from
       promoting a horizontal scrollbar on the page. Per-component `overflow-x:
       clip` rules (Index.razor.css) still win where they exist; this is the
       last-resort guard so a 390 px phone never lands on a sideways scroll.
       `clip` over `hidden` so a sticky descendant's box-shadow is not clipped. */
    overflow-x: clip;
}

/* Page-entry animation — GPU-only transform/opacity, runs on the compositor.
   Pairs with the @view-transition block in css/app.css for browsers that
   support the cross-document navigation API. */
@media (prefers-reduced-motion: no-preference) {
    .gl-page {
        /* `backwards` (not `both`): fill the FROM state before the run to avoid an
           initial flash, but do NOT retain the final transform. A retained
           `transform: translateY(0)` turns .gl-page into the containing block for
           every position:fixed descendant (game-over modal, toasts), anchoring
           them to the over-tall page instead of the viewport. */
        animation: gl-page-enter var(--dur-base) var(--ease-out) backwards;
    }

    @keyframes gl-page-enter {
        from { opacity: 0; transform: translateY(6px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* Spatial contract: Left (branding) — Center (FPS + game status) — Right (session + gear).
   The header is also the estate's .po-header (po-tokens.css): that rule owns its
   position, height, padding, surface and border. This one only adds the gap. */
.gl-top-bar {
    gap: var(--space-4);
}

.gl-top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    min-width: 0;
    flex: 0 0 auto;
}

.gl-top-bar-center {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    min-width: 0;
    padding: 0 var(--space-3);
}

.gl-top-bar-game {
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    min-width: 0;
    margin-left: auto;
    overflow: hidden;
}

.gl-brand-icon { display: inline-flex; color: var(--po-accent); }

.gl-auth {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    min-width: 0;
}

/* The account menu's trigger: the initials as a pill button. The panel it
   opens is the shared .gl-overflow-panel below. */
.gl-account-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 14rem;
    padding: 0.35rem 0.75rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    color: var(--color-text-secondary);
    font: inherit;
    font-size: var(--text-sm);
    white-space: nowrap;
    cursor: pointer;
    /* The anchor its panel positions against. Inert without anchor positioning. */
    anchor-name: --gl-anchor-account;
    transition: border-color var(--dur-base) var(--ease-standard),
                color var(--dur-base) var(--ease-standard);
}

.gl-account-trigger:hover {
    border-color: var(--color-text-secondary);
    color: var(--color-text-primary);
}

.gl-account-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gl-account-caret { font-size: 1.1em; line-height: 1; }

/* Wide screens show the name; the initial is the narrow-phone form (below). */
.gl-account-initial { display: none; }

/* (Removed: `.gl-center-action*` and `.gl-sync-pill*`. The kiosk centre-action
   button and the pending-score sync pill were both dropped from the top bar in
   the 2026-07 cleanups; no layout renders either class. ScoreSyncService still
   flushes parked scores on start and reconnect — it just reports through a toast now
   instead of a persistent pill. */

/* ── Account menu panel ───────────────────────────────────────────────────────
   Native Popover API. The trigger is a plain <button popovertarget>, the panel a
   <div popover="auto">: the browser supplies light-dismiss, Escape-to-close,
   focus management and top-layer promotion. */
.gl-overflow-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.4rem;
    min-width: 12rem;
    box-shadow: var(--elevation-1);

    /* Reset the UA popover defaults (which centre it in the viewport). */
    margin: 0;
    inset: auto;
    overflow: visible;
    color: var(--color-text-primary);

    /* ── Fallback path (no anchor positioning) ──
       The trigger lives in the top bar's right-hand rail, so pinning the panel
       under the bar's right edge lands it within a few pixels of where anchoring
       would put it. This is what Firefox and older Safari get, and it needs no
       JS measurement — which is the whole reason the panel is positioned in CSS
       rather than by a resize/scroll listener. */
    position: fixed;
    top: var(--po-header-h);
    right: var(--space-4);
}

/* Entry/exit transition for the panel.
   `@starting-style` is what makes this possible without a keyframe: a popover
   goes from `display: none` to shown, and a transition normally has no "before"
   state to start from, so the panel used to just appear. This declares that
   before-state. `allow-discrete` on `display` and `overlay` is the other half —
   without it the browser would snap both properties at the start of the
   transition and the exit animation would never be seen, because the element is
   already gone by the first frame.

   Costs nothing where unsupported: the panel simply appears instantly, exactly
   as it did before. */
.gl-overflow-panel {
    opacity: 0;
    transform: translateY(-0.35rem);
    transition:
        opacity var(--dur-fast) var(--ease-out),
        transform var(--dur-fast) var(--ease-out),
        overlay var(--dur-fast) allow-discrete,
        display var(--dur-fast) allow-discrete;
}

.gl-overflow-panel:popover-open {
    opacity: 1;
    transform: translateY(0);
}

@starting-style {
    .gl-overflow-panel:popover-open {
        opacity: 0;
        transform: translateY(-0.35rem);
    }
}

/* The dimmed page behind an open menu. ::backdrop is free with the Popover API
   and is what makes "click outside to close" legible rather than invisible. */
.gl-overflow-panel::backdrop {
    background: rgba(0, 0, 0, 0.18);
}

/* No z-index anywhere in this block: an open popover is in the TOP LAYER, above
   every stacking context on the page by definition. The old --z-dropdown value
   existed only because the <details> panel rendered in normal flow. */
@supports (anchor-name: --a) {
    .gl-overflow-panel {
        position: absolute;
        position-anchor: --gl-anchor-account;
        /* Below the trigger, right edges aligned. */
        position-area: block-end span-inline-start;
        margin-block-start: 0.4rem;
        top: auto;
        right: auto;
        /* Flip above the trigger if there isn't room below (landscape phones). */
        position-try-fallbacks: flip-block;
    }
}

.gl-overflow-item {
    display: grid;
    grid-template-columns: 1.35rem minmax(0, 1fr);
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 0.55rem 0.75rem;
    color: inherit;
    font: inherit;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Who the menu is for. The trigger shows the name too, but a name truncated to one
   initial on a phone is not an answer to "which account am I in". */
.gl-overflow-head {
    margin: 0.1rem 0.35rem 0.35rem;
    padding: 0 0.4rem 0.45rem;
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gl-overflow-head strong {
    color: var(--color-text-primary);
    font-weight: 600;
}

.gl-overflow-icon {
    font-size: 1.15rem;
    color: var(--color-text-secondary);
}

.gl-overflow-item[aria-current="page"] .gl-overflow-icon {
    color: var(--color-accent);
}

/* :focus-visible, not :focus: the menu focuses its first item when it opens, and after
   a mouse click that should not paint a highlight the pointer never asked for. */
.gl-overflow-item:hover,
.gl-overflow-item:focus-visible {
    background: var(--color-surface-hover, rgba(255, 255, 255, 0.08));
}

/* The page the player is on (aria-current="page"). */
.gl-overflow-item[aria-current="page"] {
    font-weight: 700;
    box-shadow: inset 3px 0 0 var(--color-accent);
}

/* Sign out sits apart from the destinations above it. */
.gl-overflow-item--sep {
    margin-top: 0.3rem;
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    padding-top: 0.7rem;
}

/* On mobile viewports, the BottomNav already carries Stats and Boards. */
@media (max-width: 768px) {
    .gl-overflow-item--desktop-only {
        display: none;
    }
}

/* ── Mobile portrait: mirror MainLayout's top-bar compaction ── */
@media (max-width: 640px) {
    .gl-top-bar {
        gap: var(--space-2);
    }

    .gl-top-bar-left {
        gap: var(--space-3);
        flex-shrink: 0;
    }

    .gl-top-bar-center {
        gap: var(--space-2);
        padding: 0 var(--space-2);
    }

    .gl-top-bar-game { justify-content: flex-end; }

    .gl-account-trigger { max-width: 9rem; padding: 0.3rem 0.6rem; font-size: 0.75rem; }
}

@media (max-width: 480px) {
    /* The app name stays visible at phone width (Po standard); the game title in
       the centre rail is what yields. */
    .gl-top-bar-center { padding: 0; }
    .gl-top-bar-game .gps-game-title { max-width: none; }
}

.gl-page:has(.kiosk-bar) {
    --kiosk-clearance: calc(5rem + env(safe-area-inset-bottom, 0px));
    /* Attract mode is a fixed-viewport showcase: the reserved bar height must come out
       of the page, not extend it, or every demo grew a scrollbar nobody could use. */
    height: 100dvh;
    overflow: hidden;
}

/* The reel bar floats over the bottom edge. DOM content — a board's last row, a
   ticker, a HUD panel — must not sit under it, so the content well gives back the
   bar's height while the reel runs. Games that paint to the whole viewport keep
   their own bottom-inset rules (PoMule, Sand Playground). */
.gl-page:has(.kiosk-bar) .gl-content {
    padding-bottom: var(--kiosk-clearance);
}

@media (max-width: 480px) {
    .gl-page:has(.kiosk-bar) {
        --kiosk-clearance: calc(7rem + env(safe-area-inset-bottom, 0px));
    }
}

/* ── FPS pill (top-bar FpsCounter, on every route).
   Lives here rather than in FpsCounter.razor.css because the three layouts that
   render the counter (MainLayout, BareLayout) style the rail
   around it here. The runtime sampler lives in FpsCounter; only the visual rules
   live here. */
.gl-fps {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-pill);
    /* Scheme-aware, and it has to be: a fixed translucent-dark fill with a fixed
       neon `#6bff6b` composites to ~#76777f in light mode, 3.42:1 — under the
       4.5:1 floor for 11.5px text, on every route since this pill renders on all
       of them. Scheme-invariance is right for a canvas accent and wrong for
       small text on chrome. */
    background: light-dark(rgba(255, 255, 255, 0.78), rgba(10, 12, 24, 0.55));
    border: 1px solid var(--color-border);
    color: light-dark(#116634, #6bff6b);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    min-width: 5.4ch;
    text-align: center;
    transition: color var(--dur-base) var(--ease-standard);
}

/* Same treatment for the two alert tiers — amber and red at this size fail on a
   light fill just as the green did. The hue reads the same in both schemes; only
   the lightness moves. */
.gl-fps[data-tier="warn"] { color: light-dark(#8a5300, #ffd24e); }
.gl-fps[data-tier="bad"]  { color: light-dark(#b3241c, #ff6b6b); }

@media (max-width: 640px) {
    .gl-fps {
        font-size: var(--text-xs);
        padding: 0.18rem 0.5rem;
        min-width: 4.6ch;
    }
}

/* Narrow phones: the centre rail cannot fit the FPS pill AND the game title —
   the title would truncate to a couple of glyphs beside the pill. The pill is diagnostics, the game name is identity: diagnostics
   yields. */
@media (max-width: 480px) {
    .gl-fps { display: none; }
}

/* ≤420 px with a game title in the centre rail the name would ellipsise to one
   glyph ("t…"): below that width the trigger is a round initial. The name stays
   in the button's aria-label. */
@media (max-width: 420px) {
    .gl-account-trigger {
        display: inline-grid;
        place-items: center;
        width: 2.25rem;
        height: 2.25rem;
        padding: 0;
        border-radius: 50%;
        font-weight: 700;
        color: var(--color-text-primary);
        background: var(--color-surface);
    }
    .gl-account-initial { display: inline; }
    .gl-account-name,
    .gl-account-caret { display: none; }
}

/* -- Hub launch morph --
   While js/app.js runs the card-to-title view transition it sets data-hero-nav on the root;
   routeFx's colour wipe would otherwise sweep over the morph on the same frames. */
:root[data-hero-nav] .po-route-wipe { display: none; }

/* The player's 3-letter initials, wherever they appear (top bar, account menu,
   hub banner). Monospace so the three slots keep their width; the ink token is
   the accent at a lightness that is legible as text in either scheme. */
.gl-arcade-initials {
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 0.08em;
    white-space: pre;
    color: var(--accent-ink);
}

@media (pointer: coarse) {
    .gl-account-trigger,
    .gl-overflow-item {
        min-height: 44px;
    }
    /* In a game the phone hides the title, leaving a 22px-wide logo: widen the target. */
    .gl-brand { min-width: 44px; justify-content: center; }
    @media (max-width: 420px) {
        .gl-account-trigger {
            width: 2.75rem;
            height: 2.75rem;
        }
    }
}

/* -- Settings: the one gear (.po-header__settings, po-tokens.css), upper right on every page.
   Phones keep the 44px touch floor. */
@media (pointer: coarse) {
    .po-header__settings { width: 2.75rem; height: 2.75rem; }
}

/* The title, upper left on every page: a phone used to show only the logo. It still steps
   aside while a game is up, because the game's own title fills the middle of the bar then. */
@media (max-width: 480px) {
    .gl-top-bar:not(:has(.gl-top-bar-game > *)) .gl-brand-text {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        clip-path: none;
        font-size: 1rem;
    }
}
