/* ─────────────────────────────────────────────────────────────────────────
   glass.css — the APPLIED glassmorphism layer.

   fx.css defines primitives and deliberately restyles nothing. This file is the
   other half: it puts those primitives onto the app's real chrome surfaces.
   Keeping them apart matters — fx.css can be loaded anywhere without risk,
   while this file is by definition opinionated and has to load last.

   WHY SELECTORS AND NOT MARKUP
   The alternative was adding `class="fx-glass fx-glass--lit"` to forty .razor
   files. That is forty diffs to review, forty chances to break a layout, and it
   scatters one visual decision across the whole component tree. The surfaces
   here already have stable, semantic class names; targeting them keeps the
   entire treatment in one reviewable place and makes it removable in one line.

   WHY THE DOUBLED SELECTORS (`.gps-modal.gps-modal`)
   Several targets are styled by Blazor scoped CSS, whose rules carry an extra
   `[b-xxxxxxxxxx]` attribute selector and therefore beat a single class. Doubling
   the class raises specificity to match, and this file loading after
   PoMiniGamesClient.styles.css wins the tie. It is not a hack for its own sake —
   without it, exactly the game HUDs that most want the treatment would silently
   not get it.

   ORDER: this file MUST stay last in index.html's stylesheet list.
   ───────────────────────────────────────────────────────────────────────── */

/* ── Shared recipe ────────────────────────────────────────────────────────
   One place to change what "a glass surface in this app" means. Everything
   below composes from these. */
:root {
    --glass-fill: color-mix(in srgb, var(--color-surface) 42%, transparent);
    --glass-fill-strong: color-mix(in srgb, var(--color-surface) 68%, transparent);
    --glass-edge: color-mix(in srgb, var(--color-text-primary) 12%, transparent);
    --glass-edge-lit: color-mix(in srgb, var(--color-text-primary) 26%, transparent);
    --glass-inner: inset 0 1px 0 var(--glass-edge-lit);

    /* ── Over-canvas glass ──
       HUDs that float on a game's own 3D scene rather than on an app surface.
       That scene is dark in every colour scheme, so these tokens are
       deliberately NOT re-pointed in the light block below (the rule for
       per-game/canvas tokens).

       The racer and sports HUDs must not consume the ordinary `--glass-fill`,
       which light mode re-points to `rgba(255,255,255,0.58)`: a near-white panel
       carrying white text meant for a dark scene measures 1.00:1. */
    --glass-fill-canvas: rgba(8, 14, 26, 0.72);
    --glass-edge-canvas: rgba(148, 197, 255, 0.22);
    --glass-inner-canvas: inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

/* Light mode needs a *lighter* fill, not the same dark one at lower opacity —
   re-pointing the two fills is enough because everything else is derived. */
@media (prefers-color-scheme: light) {
    :root {
        --glass-fill: rgba(255, 255, 255, 0.58);
        --glass-fill-strong: rgba(255, 255, 255, 0.82);
        --glass-edge: rgba(15, 23, 42, 0.10);
        --glass-edge-lit: rgba(255, 255, 255, 0.9);
    }
}

/* ── Top bar ──────────────────────────────────────────────────────────────
   No glass: the header is the estate's .po-header (po-tokens.css), a solid
   surface that looks the same in every Po app. */

.gl-overflow-panel.gl-overflow-panel {
    background: var(--glass-fill-strong);
    border: 1px solid var(--glass-edge);
    box-shadow: var(--glass-inner), var(--elevation-3);
    -webkit-backdrop-filter: var(--glass-2);
    backdrop-filter: var(--glass-2);
}

/* ── The end-of-game modal ────────────────────────────────────────────────
   Every game funnels into this. It gets the full treatment: heavy backdrop
   blur, a lit top edge, grain, and a rotating conic ring — this is the app's
   single most-seen moment and the one place the extra compositor cost is
   unambiguously worth it. */
.gps-modal-overlay.gps-modal-overlay {
    background: color-mix(in srgb, #020617 55%, transparent);
    -webkit-backdrop-filter: blur(calc(var(--gfx-blur) * 0.6)) saturate(120%);
    backdrop-filter: blur(calc(var(--gfx-blur) * 0.6)) saturate(120%);
}

.gps-modal.gps-modal {
    position: relative;
    background: var(--glass-fill-strong);
    border: 1px solid var(--glass-edge);
    box-shadow:
        var(--glass-inner),
        var(--elevation-3),
        0 0 60px color-mix(in srgb, var(--fx-accent) 14%, transparent);
    -webkit-backdrop-filter: var(--glass-3);
    backdrop-filter: var(--glass-3);
    /* NOT overflow:hidden. game-shell.css sets overflow-y:auto so a tall modal
       (many stats + a top-3 board) can scroll on a short viewport; clipping it
       here would strand the OK button off-screen. The ring below is masked
       rather than clipped, so it does not need the clip anyway. */
}

.gps-modal.gps-modal::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.04;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* The result headline is the emotional peak of a session — the one place an
   animated gradient on text earns its keep. */
.gps-modal-title.gps-modal-title {
    background: linear-gradient(var(--fx-angle),
        var(--fx-accent), var(--fx-accent-2) 45%, var(--fx-accent-3) 70%, var(--fx-accent));
    background-size: 220% 220%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: fx-rotate-angle 7s linear infinite;
}
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
    .gps-modal-title.gps-modal-title { color: var(--color-text-primary); background: none; }}

.gps-modal-board.gps-modal-board,
.gps-modal-stats.gps-modal-stats {
    background: color-mix(in srgb, var(--color-surface) 30%, transparent);
    border: 1px solid var(--glass-edge);
    box-shadow: var(--glass-inner);
}

/* On-canvas HUD surfaces (corner panels, single HUD bars) belong in the game's own
   scoped stylesheet, using the `--glass-*-canvas` tokens above — those are the ones
   that deliberately do not follow the app colour scheme. A full-bleed HUD container
   is never a glass surface: `position: absolute; inset: 0` would paint the 72%-opaque
   canvas fill over the whole game and blur everything behind it. */

/* ── Cards, tiles and panels ──────────────────────────────────────────────
   NOT given backdrop-filter. These repeat — a home screen has a dozen game
   chips, a leaderboard has fifty rows — and each blurred surface forces its own
   compositor layer plus a re-sample of everything beneath it. A dozen of them
   halves the frame rate on integrated graphics for a difference nobody would
   notice on a 90 px tile. They get the lit edge and the sheen, which is where
   the perceived quality actually comes from.

   This rule is deliberately narrow:
     - No translucent `--glass-fill` and no shadow. These cards carry running
       text (controls, a lobby roster) with no blur behind them, and the lobby
       card's shadow is now its beat glow (LobbyPanel.razor.css). They keep
       their own opaque surface and shadow and take only the lit edge.
     - `overflow: hidden` is the game card's, which needs it to clip the
       sheen. The intro card sets its own (game-shell.css): its footer is a
       flex item that never scrolls, so OK cannot be stranded. */
.gps-game-card.gps-game-card,
.gps-intro-card.gps-intro-card,
.sp-card.sp-card {
    border: 1px solid var(--glass-edge);
}
.gps-game-card.gps-game-card {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}
.gps-game-card.gps-game-card::after {
    content: '';
    position: absolute;
    top: -50%;
    bottom: -50%;
    left: -60%;
    width: 40%;
    background: linear-gradient(100deg,
        transparent,
        rgba(255, 255, 255, 0.14) 45%,
        rgba(255, 255, 255, 0.26) 50%,
        rgba(255, 255, 255, 0.14) 55%,
        transparent);
    transform: translateX(0) skewX(-18deg);
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}
.gps-game-card.gps-game-card:hover::after,
.gps-game-card.gps-game-card:focus-visible::after {
    opacity: 1;
    animation: fx-sheen-sweep 0.75s cubic-bezier(0.22, 1, 0.36, 1);
}
.gps-modal-overlay.gps-modal-overlay { perspective: 1400px; }

/* ── Toasts ───────────────────────────────────────────────────────────────
   Few on screen at once and always over arbitrary content, so blur is
   affordable and genuinely helps legibility. */
.toast.toast {
    background: var(--glass-fill-strong);
    border: 1px solid var(--glass-edge);
    box-shadow: var(--glass-inner), var(--elevation-3);
    -webkit-backdrop-filter: var(--glass-2);
    backdrop-filter: var(--glass-2);
}

/* ── Adaptive degradation ─────────────────────────────────────────────────
   Mirrors fx.css's policy for the surfaces this file introduced. `low` drops
   every backdrop-filter to an opaque fill: the blur is the expensive part, and
   an opaque panel is a legitimate look rather than a broken one. */
:root[data-gfx='low'] .gl-top-bar.gl-top-bar,
:root[data-gfx='low'] .gps-modal.gps-modal,
:root[data-gfx='low'] .toast.toast,
:root[data-gfx='low'] .gl-overflow-panel.gl-overflow-panel,
:root[data-gfx='low'] .pb-hud.pb-hud {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--color-surface);
}

/* Same "drop the blur" treatment for the over-canvas HUDs, but landing on an
   opaque DARK panel rather than `--color-surface` — which in light mode is the
   white that would make this HUD text unreadable.

   `.pb-hud` is deliberately NOT in this group: PoBrawl's health bars sit in
   normal page flow beneath the arena, not on the canvas, and their text follows
   the theme. Giving it a dark panel put near-black text on near-black. */
:root[data-gfx='low'] .ps-hud.ps-hud,
:root[data-gfx='low'] .hud-panel.hud-panel {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgb(12, 18, 32);
}
:root[data-gfx='low'] .gps-modal.gps-modal::before,
:root[data-gfx='low'] .gps-modal.gps-modal::after {
    display: none;
}
:root[data-gfx='low'] .gps-modal-title.gps-modal-title {
    animation: none;
}

@media (prefers-reduced-motion: reduce) {
    .gps-modal.gps-modal::before,
    .gps-modal-title.gps-modal-title {
        animation: none;
    }
    .gps-game-card.gps-game-card::after {
        animation: none;
        opacity: 0;
    }}