/* ─────────────────────────────────────────────────────────────────────────
   game-shell.css — the SHARED game chrome.

   Every game in PoMiniGames ends on one identical screen: the centered
   end-of-game modal rendered by Components/GameShell.razor. These rules are
   that modal's single source of truth and are deliberately kept OUT of
   games.css (which is a grab-bag of per-game rules) so no game can quietly
   drift its own game-over styling.

   Owns: the modal (overlay, card, title, summary, stats grid, top-3 board,
   OK action) and the stat cells shared with it.

   If you are adding a game: do not restyle `.gps-modal*`. Pass Stats /
   GameSummary / GameKey to GameShell and inherit this.
   ───────────────────────────────────────────────────────────────────────── */

/* ── The shared card face ──
   The start card (GameIntro) and the end card (GameOverModal) are the same two
   moments of every game, so they share one geometry: radius, border and shadow.
   Only the fill differs — the intro sits on the themed surface, the end card is
   a darker glass — and both take it from the same token family below. */
:root {
  --gps-card-radius: 18px;
  --gps-card-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* ── Overlay ──
   A genuinely centered, blocking dialog: dimmed + blurred backdrop, clicks
   captured (no backdrop-dismiss — OK is the only exit), so the board behind it
   is not interactive.
   It is a native <dialog>: the dialog places itself in the top layer (above fx
   overlays, particles, toasts) and traps focus inside. The dim layer is the
   browser-provided `::backdrop` pseudo-element below. The .gps-modal selector
   owns the visible card itself (size, surface, padding, animation). */
dialog.gps-modal {
  pointer-events: auto;
  width: min(94vw, 440px);
  max-height: calc(100dvh - 2.5rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 1.3rem 1.35rem 1.15rem;
  background: var(--color-surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--color-border);
  border-radius: var(--gps-card-radius);
  box-shadow: 
    0 24px 60px -8px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  animation: gps-modal-pop 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.gps-modal-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.gps-modal-title {
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.015em;
  color: var(--color-text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

/* ── Result line ── */
.gps-game-summary {
  width: 100%;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.gps-game-summary > div > div:not(:first-child) {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

/* A summary that is a page of results rather than a line (Cabinet's standings and
   telemetry, Sports' splits table): its root element carries .gps-summary--wide, takes
   the card's width, and the card widens to hold it. Make that root a <section>, not a
   <div>, or the small-print rule above restyles its children. */
dialog.gps-modal:has(.gps-summary--wide) {
  width: min(94vw, 560px);
}
dialog.gps-modal:has(.gps-summary--wide details[open], .pocabinet-results__details--open) {
  width: min(96vw, 860px);
}

.gps-summary--wide {
  width: 100%;
}

/* ── Stats grid ── responsive telemetry tiles */
.gps-modal-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 0.4rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.gps-modal-stats:has(> :nth-child(6):last-child) {
  grid-template-columns: repeat(3, 1fr);
}

.gps-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.45rem 0.35rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.15s ease, background 0.15s ease;
}

.gps-stat:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.gps-stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
}

.gps-stat-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.2rem;
  opacity: 0.8;
}

/* ── Top-3 board ── */
.gps-modal-rank {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.5rem 0;
}

.gps-modal-rank-pos {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--color-text-primary);
}

.gps-modal-rank-of {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.gps-modal-rank-delta {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-success);
  background: var(--accent-success-soft);
  border-radius: var(--radius-pill);
  padding: 0.1rem 0.45rem;
}

.gps-modal-rank--up .gps-modal-rank-pos {
  color: var(--accent-success);
}

.gps-modal-board {
  width: 100%;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.gps-modal-board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.45rem;
  padding: 0 0.25rem;
}

.gps-modal-board-title {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
}

.gps-modal-board-unit {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gps-modal-board-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.gps-modal-board-row {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.gps-modal-board-row--1 {
  background: linear-gradient(90deg, rgba(234, 179, 8, 0.16), rgba(234, 179, 8, 0.05));
  border-color: rgba(234, 179, 8, 0.35);
}
.gps-modal-board-row--2 {
  background: linear-gradient(90deg, rgba(203, 213, 225, 0.14), rgba(203, 213, 225, 0.04));
  border-color: rgba(203, 213, 225, 0.3);
}
.gps-modal-board-row--3 {
  background: linear-gradient(90deg, rgba(217, 119, 6, 0.14), rgba(217, 119, 6, 0.04));
  border-color: rgba(217, 119, 6, 0.3);
}

.gps-modal-board-row--me {
  border-color: var(--color-accent-solid);
  box-shadow: 0 0 12px var(--color-accent-soft);
}

.gps-modal-board-rank {
  font-weight: 700;
  color: var(--color-text-secondary);
}

.gps-modal-board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-primary);
}

.gps-modal-board-value {
  font-weight: 700;
  color: var(--color-text-primary);
}

/* ── Board placeholder ──
   Holds the rank line's and the top 3's height while the board is fetched, so the card
   does not grow and push the buttons down under the player's thumb. Same classes as
   the real rows, so the heights match without restating them. */
.gps-skel {
  display: inline-block;
  border-radius: var(--radius-sm, 6px);
  background: var(--tint-soft);
  color: transparent;
}

.gps-skel--rank { width: 4.5rem; }
.gps-skel--head { width: 5rem; }
.gps-skel--line { width: 70%; }

.gps-skel-row {
  background: var(--tint-soft);
  border-color: transparent;
}

.gps-modal-skeleton {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

@media (prefers-reduced-motion: no-preference) {
  .gps-skel,
  .gps-skel-row {
    animation: gps-skel-breathe 1.2s ease-in-out infinite alternate;
  }
}

@keyframes gps-skel-breathe {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}

/* ── Action ──
   The one button, Back to main menu, across the card's width. */
.gps-play-again-actions {
  position: sticky;
  bottom: -1px;
  flex: none;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.4rem;
  padding-top: 0.5rem;
  background: var(--color-surface);
}

.gps-result-details { width: 100%; text-align: left; }
.gps-result-details[open] { max-height: 40dvh; overflow: auto; }
.gps-result-details summary { cursor: pointer; padding: 0.5rem; }
.gps-play-again-actions > div { display: contents; }

.gps-play-again-actions .app-btn {
  flex: 1 1 auto;
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  white-space: nowrap;
}

.gps-kbd {
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--color-text-secondary);
  line-height: 1;
}

.gps-kbd--primary {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  color: #ffffff;
}

@keyframes gps-modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes gps-modal-pop {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.gps-modal,
  dialog.gps-modal::backdrop {
    animation: none;
  }
}

/* Option #9: the native <dialog>::backdrop pseudo-element. What used to be
   a sibling <div class="gps-modal-overlay"> carrying the dim + blur is now
   styled here on the browser-rendered backdrop. The dialog's own top-layer
   rendering already hides the rest of the page behind a translucent layer;
   the blur + tint just match the look the old overlay had. */
dialog.gps-modal::backdrop {
    background: rgba(4, 8, 20, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: gps-modal-fade 0.22s ease-out both;
}

/* A loss: the page behind goes grey toward the edges. Static, so it stays under
   reduced motion; the low tier keeps the plain dim (grayscale is a second filter pass). */
dialog.gps-modal.gps-modal--loss::backdrop {
    background: radial-gradient(ellipse at center, rgba(4, 8, 20, 0.62) 35%, rgba(38, 40, 46, 0.9) 100%);
    backdrop-filter: blur(8px) grayscale(0.7);
    -webkit-backdrop-filter: blur(8px) grayscale(0.7);
}

:root[data-gfx='low'] dialog.gps-modal.gps-modal--loss::backdrop {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Reset native dialog defaults so our .gps-modal styles are the only
   positioning source. The user-agent stylesheet sets border, padding, and
   margin on every <dialog>, which fight our card surface unless overridden.
   Background is left to the main rule above so the card's translucent
   surface + backdrop-filter stack the same way as before. */
dialog.gps-modal {
    margin: auto;
    color: var(--color-text-primary);
}

/* ─────────────────────────────────────────────────────────────────────────
   Intro / welcome card (Components/GameIntro.razor)

   The bookend to the end-of-game modal: one centered card every game opens
   on. Deliberately styled here alongside the outro so intro + outro share
   one visual language. Sits at --z-overlay (below the game-over modal's
   --z-modal) so a game that somehow ends instantly still surfaces its result
   on top.
   ───────────────────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────────────────
   Contract: --gps-area-h.

   The CSS variable `--gps-area-h` is published by `.gps-shell` (in games.css)
   as `min(100dvh, max(18rem, 100dvh - var(--gps-topbar-h) - var(--gps-bar-h, 0px)))`.
   Game descendants should read it directly instead of computing their own
   `calc(100vh - NNNpx)` arithmetic. Layouts with extra rail chrome override the
   `--gps-bar-h` token from their own CSS so the subtraction stays accurate
   without each game having to know which layout it sits under.

   Each game computing its own `min(86vh, 820px)` would give a different answer
   per game. Centralising the arithmetic means a chrome change (a new top-bar
   row, a layout-specific drawer) only has to update one token.
   ───────────────────────────────────────────────────────────────────────── */
.gps-intro-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
  outline: none;
  animation: gps-modal-fade 0.2s ease-out both;
}

dialog.gps-intro-overlay:not([open]) { display: none; }
dialog.gps-intro-overlay::backdrop { background: transparent; }

/* The card: header, body, footer in one flex column that never scrolls. Only the body may
   (a last resort on a screen smaller than any we test); each game's content is cut to fit. */
.gps-intro-card {
  pointer-events: auto;
  width: min(94vw, 460px);
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.05rem 1.25rem 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--gps-card-radius);
  box-shadow: var(--gps-card-shadow);
  text-align: center;
  animation: gps-modal-pop 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

/* A game with a long setup (a track picker, the campaign rung, a species pick). */
.gps-intro-card--wide { width: min(96vw, 860px); }
/* The two-player select wants room for its side-by-side rosters. */
.gps-intro-card--twoplayer { width: min(96vw, 640px); }

.gps-intro-head {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.gps-intro-body {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--color-border);
}

/* Wide: info on the left, setup on the right. */
@media (min-width: 760px) {
  .gps-intro-card--wide .gps-intro-body:has(> .gps-intro-controls + .gps-intro-options) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    align-items: start;
    gap: 1.25rem;
  }
}

@media (max-width: 520px) {
  .gps-intro-overlay {
    padding: 0.75rem;
  }
  .gps-intro-card,
  .gps-intro-card--wide,
  .gps-intro-card--twoplayer {
    width: 100%;
    max-height: calc(100dvh - 1.5rem);
    gap: 0.6rem;
    padding: 1rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    animation: gps-modal-pop 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }
}

@keyframes gps-sheet-up {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: none; }
}

.gps-intro-title {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--color-text-primary);
}

.gps-intro-objective {
  margin: 0;
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.gps-intro-controls {
  width: 100%;
  text-align: left;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  line-height: 1.55;
}

.gps-intro-controls p { margin: 0 0 0.3rem; }
.gps-intro-controls p:last-child { margin-bottom: 0; }
.gps-intro-controls ul { margin: 0; padding-left: 1.1rem; }
.gps-intro-controls li { margin-bottom: 0.15rem; }

.gps-intro-section-label {
  font-size: 0.75rem; /* 12px floor (2026-09-29); was 0.65rem, ~10px, on every intro card */
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  /* No `opacity` on top of the secondary token: that computes to #75808f on
     white = 4.0:1, under the AA floor, and this label ships on EVERY game's
     intro card. The token alone is 7.5:1; the uppercase tracking already
     de-emphasises it. */
  color: var(--color-text-secondary);
  margin-bottom: 0.4rem;
}

/* Controls | How to play: two views of the one panel. */
.gps-intro-tabs {
  display: inline-flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  padding: 0.15rem;
  border-radius: 999px;
  background: var(--color-surface-hover);
}

.gps-intro-tab {
  padding: 0.2rem 0.75rem;
  border: 0;
  border-radius: 999px;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.gps-intro-tab[aria-selected="true"] {
  background: var(--color-surface);
  color: var(--color-text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.gps-intro-tab:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* A thumb needs 44px (Profile B). */
@media (pointer: coarse) {
  .gps-intro-tab { min-height: 44px; padding-inline: 0.9rem; }
}

/* Setup as a tab: only on a portrait phone, where setup below the controls made the body
   scroll (PoCapitol, Marble Race, Mule at 375x667). Wider or landscape cards keep setup beside
   the panel, so the Setup tab, and a strip that only exists for it, are hidden there. */
.gps-intro-tab--setup,
.gps-intro-tabs--setup-only { display: none; }

@media (max-width: 759px) and (min-height: 561px) {
  .gps-intro-tab--setup { display: inline-block; }
  .gps-intro-tabs--setup-only { display: inline-flex; }
  .gps-intro-section-label--setup-only { display: none; }
  .gps-intro-body[data-view="setup"] > .gps-intro-controls > .gps-intro-panel { display: none; }
  .gps-intro-body:not([data-view="setup"]) > .gps-intro-options { display: none; }
}

/* Key chips: the shell's <kbd> look. A run of them on one line reads as the controls. */
.gps-intro-controls kbd {
  display: inline-block;
  min-width: 1.1rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--color-surface-hover);
  color: var(--color-text-primary);
  font-size: 0.78rem;
  font-family: inherit;
  text-align: center;
}

.gps-intro-options {
  width: 100%;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

/* The footer: OK, and beside it any setup toggle (Actions). Never scrolls away. */
.gps-intro-actions {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

/* The card's one button is the shared .app-btn; it keeps a floor so "OK" is not a sliver. */
.gps-intro-actions .app-btn {
  min-width: 8rem;
}

.gps-intro-actions-extra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1rem;
}

/* The OK button leads the footer; a toggle beside it follows. */
.gps-intro-actions-extra { order: 1; }

.gps-intro-hint {
  flex-basis: 100%;
}

/* A short screen (a phone on its side, a small laptop window): tighter spacing, a smaller
   title, and the header on one row. */
@media (max-height: 560px) {
  .gps-intro-overlay { padding: 0.5rem; }
  .gps-intro-card,
  .gps-intro-card--wide,
  .gps-intro-card--twoplayer {
    width: min(98vw, 980px);
    max-height: calc(100dvh - 1rem);
    gap: 0.35rem;
    padding: 0.5rem 1rem 0.4rem;
  }
  .gps-intro-tabs { margin-bottom: 0.25rem; }
  .gps-intro-section-label { margin-bottom: 0.2rem; }
  .gps-intro-head {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem 0.75rem;
  }
  .gps-intro-objective { flex-basis: 100%; font-size: 0.8rem; line-height: 1.3; }
  .gps-intro-title { font-size: 1.1rem; }
  .gps-intro-body { padding-top: 0.4rem; gap: 0.5rem; }
  .gps-intro-controls { line-height: 1.4; }
  .gps-intro-actions { padding-top: 0.4rem; }
  .gps-intro-actions .app-btn { min-height: 2.5rem; padding-block: 0.35rem; }
  .gps-intro-body:has(> .gps-intro-controls + .gps-intro-options) {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    align-items: start;
    gap: 1rem;
  }
}

/* Control hints come in two forms: .keys-only for a keyboard and mouse, .touch-only for a
   touch screen. The same test the engines use to build their on-screen controls. */
.touch-only { display: none; }

@media (hover: none) and (pointer: coarse) {
  .touch-only { display: revert; }
  .keys-only { display: none; }
}

.gps-intro-hint,
.gps-intro-demo-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}


.gps-intro-demo-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.gps-intro-spinner {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: gps-intro-spin 0.8s linear infinite;
}

/* ─────────────────────────────────────────────────────────────────────────
   ConnectionStateStrip — the shared hub readout for the
   multiplayer surfaces, rendered by Components/ConnectionStateStrip.razor and
   consumed by LobbyPanel (all lobby games) and the Brawl online fight page.
   Previously each surface spelled its own "Status: <pill>" in a different
   pill vocabulary — and the fight page's `po-pill` classes were defined
   NOWHERE, so its status pills rendered as bare text. One component, one
   vocabulary, styled here where the rest of the shared chrome lives.
   ───────────────────────────────────────────────────────────────────────── */
.conn-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 0.6rem;
}

.conn-strip__label {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.conn-strip__detail {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

@keyframes gps-intro-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .gps-intro-overlay,
  .gps-intro-card { animation: none; }
  .gps-intro-spinner { animation: none; }
}

/* ── Tab diagnostics ──
   The shared panel GameShell renders for every game (GameDebugOverlay). Fixed
   to the bottom-left, above the game area, below the modal: it must never move
   the layout, never take a click from the game, and never be the only way to
   read something. Pointer-events are off for that reason — it is a readout.
   Styling matches the game chrome (same mono scale, radius and shadow tokens)
   so it reads as part of the shell rather than a game's own overlay. */
.gps-stats-toggle {
  position: fixed;
  left: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom));
  z-index: 20;
}

/* The demo reel is watched, not debugged: the pill would sit on top of games' own
   bottom-left HUD (Cabinet's leader card). PoMule also keeps colonist cards along its bottom
   edge, and on mobile viewports there is no Tab key and no spare corner. Tab still opens the panel. */
body:has(.kiosk-bar) .gps-stats-toggle,
body:has(.pm-root) .gps-stats-toggle {
  display: none;
}

@media (max-width: 768px) {
  .gps-stats-toggle {
    display: none;
  }
}

.gps-debug {
  position: fixed;
  left: 0.75rem;
  bottom: 3.75rem;
  z-index: var(--z-overlay);
  width: min(21rem, calc(100vw - 1.5rem));
  max-height: min(78vh, 42rem);
  overflow: auto;
  padding: 0.6rem 0.75rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: light-dark(rgba(255, 255, 255, 0.94), var(--color-surface));
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35), 0 1px 0 var(--color-border) inset;
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  pointer-events: auto;
}

.gps-debug-extra {
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--color-border);
}

.gps-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--color-border);
}

.gps-debug-title {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.gps-debug-close {
  appearance: none;
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.gps-debug-close:hover,
.gps-debug-close:focus-visible {
  background: var(--color-surface-hover);
  color: var(--color-text-primary);
}

.gps-debug-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.12rem 0.75rem;
  margin: 0;
}

.gps-debug-grid dt {
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.62rem;
  white-space: nowrap;
}

.gps-debug-grid dd {
  margin: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
}

.gps-debug-hint {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0.5rem 0 0;
  padding-top: 0.4rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.6rem;
  color: var(--color-text-secondary);
}

.gps-debug-dot { opacity: 0.5; }

.gps-debug-ok { color: light-dark(#15803d, #4ade80); }
.gps-debug-warn { color: light-dark(#b45309, #fbbf24); }
.gps-debug-bad { color: light-dark(#b91c1c, #f87171); }

/* ── Game Shell Styles ── */

/* The SwipeBack wrapper is .gl-content's only child on game routes. Stretching it
   across the content well lets .gps-shell (below) fill exactly that space. */
.gps-shell-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.gps-shell {
  display: flex;
  flex-direction: column;
  /* Fill the content well instead of demanding a full viewport: the shell
     renders INSIDE .gl-content — below the ~56px top bar and above the ~42px
     footer — so `min-height: 100dvh` would add ~98px of dead vertical scroll on
     every viewport. .gl-content is already flex:1 of .gl-page (min-height:
     100svh), so stretching to the well keeps the game filling the visible screen
     minus real chrome, and the page only scrolls when a game's content is
     genuinely taller than that. */
  flex: 1 0 auto;
  min-height: 0;
  background: var(--color-bg);
  /* Option #1: turn .gps-shell into a container so per-game components
     (Marble Race's canvas, Racer's HUD, etc.) can react to their own slot
     width via @container, instead of every game carrying its own
     `@media (max-width: 640px)` block. `inline-size` (not `size`) avoids
     re-layout when the height changes — only the inline axis is observed,
     which is what every current consumer wants. */
  container-type: inline-size;
  container-name: gps;
  /* Publish `--gps-area-h` so descendants can `min()` against a single
     source of truth instead of computing their own `100vh - 220px` style
     arithmetic. Default: viewport minus top-bar. Layouts with their own
     rail publish `--gps-bar-h` from their own CSS,
     which this calc honours automatically. `100dvh` (not `100vh`) because
     mobile URL bars inflate `vh` by ~80-120px on portrait phones.
     The `min()` clamp at 18rem prevents the area collapsing on a fully
     split-screen mobile where `100dvh` can briefly go < 100px during a
     keyboard-driven viewport resize. */
  --gps-area-h: min(100dvh, max(18rem, 100dvh - var(--gps-topbar-h) - var(--gps-bar-h, 0px)));
}

/* Phones show the fixed bottom nav (Layout/BottomNav), and .gl-content reserves its height
   as bottom padding. Subtract the same amount here, or every game sized to --gps-area-h
   spills under the nav and scrolls the page. Keep in step with MainLayout.razor.css. */
@media (max-width: 768px) {
  .gps-shell { --gps-bar-h: calc(4.25rem + env(safe-area-inset-bottom)); }
}

/* Universal game title — every game page binds `<Title>` to a fragment that
   reads "🔴 Connect Five" / "❌ Tic Tac Toe" / etc. Renders as the first child
   of the chrome slot so the user can always identify which game they're in
   without scrolling. Truncates gracefully on narrow screens. */
.gps-game-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  min-width: 0;
  /* 14ch is the right cap for a phone and the wrong one for everything else
     (titles like "🌿 PoEcosystem · A living island" would ellipsise on a
     desktop), so it is scoped to phone widths by the media query below. */
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  /* This is a real <h1> in the chrome slot. Strip the
     browser-default margins so it sits inline next to the back-link without
     re-flowing the bar. */
  margin: 0;
}

/* The narrow-screen half of the title cap above. On a phone the top bar also
   carries the brand, the FPS pill and the auth controls, so the title genuinely
   does have to yield — 14ch is what fits beside them. Above this breakpoint the
   bar has room and the title shows in full. */
@media (max-width: 640px) {
  .gps-game-title { max-width: 14ch; }
}

/* On phones the bar is tight — demote the back link to the brand area
   instead of crowding the title. */

/* Live ELO badge shown in the top bar beside the player identity during
   single-player rated games. Projected by GameShell into MainLayout's
   `game-elo` section outlet (so it lands inside `.gl-auth`, not the game
   header). Amber to read as a "your standing" chip, distinct from the cyan
   turn / status badges. */
.gps-elo-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: rgba(250, 204, 21, 0.16);
  /* --accent-amber on this tint measures 1.38:1 in light mode, so the ink
     variant is used. */
  color: var(--accent-amber-ink);
  border: 1px solid rgba(250, 204, 21, 0.4);
}
/* On narrow phones the identity label is already hidden (see MainLayout.css);
   drop the ELO chip too so the top bar keeps Sign out on one line. */
@media (max-width: 480px) {
  .gps-elo-badge { display: none; }}

/* ── "This game needs 3D graphics" ──
   Shown in place of the game when a required WebGL context could not be
   created. Reads as a normal empty-state card, not an error dump. */
.gps-nogl {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
  max-width: 34rem;
  margin: auto;
  padding: 2rem 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  pointer-events: auto;
}

.gps-nogl-icon { font-size: 2.5rem; line-height: 1; }

.gps-nogl-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

.gps-nogl-body {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.gps-nogl-link {
  margin-top: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.gps-nogl-link:hover {
  border-color: var(--color-accent-solid);
  background: var(--color-accent-solid);
  color: var(--color-accent-contrast);
}

/* Secondary escape row so a player on a non-WebGL
   device can pick a 2D game without backing up to the catalog grid first. */
.gps-nogl-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.gps-nogl-or {
  font-size: 0.8rem;
  color: var(--color-text-soft);
  margin: 0 0.15rem;
}

.gps-nogl-link--chip {
  margin-top: 0;
  background: var(--surface-2);
}

/* Visually hidden but still in the accessibility tree — the clip-rect technique
   rather than `display:none`/`visibility:hidden`, both of which would stop screen
   readers announcing the live region entirely. */
.gps-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.gps-game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  /* Containing block for fullscreen game roots. A game root is
     `position: absolute; inset: 0` and expects to fill the *game area*; with no
     positioned ancestor it resolves against the viewport and slides under the
     fixed top bar. */
  position: relative;
}

/* A phone on its side has about 326px under the top bar; 48px of padding is a
   seventh of it. */
@media (max-height: 500px) {
  .gps-game-area { padding: 0.5rem 1rem; }
}

/* By default the game-area is transparent to pointer events so
   that lobby forms / join screens inside the same shell remain clickable.
   Pages that need the area to swallow pointer events (gameplay canvases with
   drag/touch handling) must opt in via .gps-game-area--clickable. */
.gps-game-area {
  pointer-events: none;
}

.gps-game-area--clickable {
  pointer-events: auto;
}

.gps-game-area--fullscreen {
  padding: 0;
}

/* Cabinet on a phone held sideways: the app's top bar would take a sixth of a 390px-tall view,
   so it steps aside while a race (not the demo, which has no pause card) is on screen. Pause →
   Quit, Leave race online, and the results' Back to all games are the ways out. Pure CSS on the
   page's own class, so the bar is back on the start card, the lobby and every other page. */
@media (orientation: landscape) and (max-height: 500px) {
  .gl-page:has(.pocabinet-race:not(.pocabinet-race--demo)) .gl-top-bar {
    display: none;
  }
}

/* Marble Race's canvas is appended by scene.js, so it carries no razor scope
   attribute and a scoped `.mr-canvas-host canvas { width/height: 100% }` rule
   in PoMarbleRacePage.razor.css cannot match it — the element would render at
   its ATTRIBUTE size (host height × devicePixelRatio) and the host's
   overflow:hidden would amputate everything past the first DPR-quadrant.
   This unscoped rule sizes the element to its host; the backing store stays
   at host × dpr (renderer.setSize with updateStyle=false), which is the
   crisp-DPR pairing. */
.mr-canvas-host > canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Every direct child of .gps-game-area should also pass clicks through so
   the lobby forms (which don't set --clickable) keep working without
   opting every inner element in. */
.gps-game-area > * {
  pointer-events: auto;
}

/* Mobile fullscreen: a fullscreen game area on phones needs to
   stretch its single child to fill the entire shell — the default
   `align-items: center; justify-content: center` would letterbox a tall
   vertical canvas (the Marble Race track) into a small box at the top.
   games.css is the right home for this rule: .gps-game-area is the parent
   shell, not a scoped-by-component element, so a razor-scoped stylesheet
   cannot reach it. The `--fullscreen` modifier already cleared the
   padding; this overrides the centering to let the child fill both axes.
   Option #1: also @container, so the same logic triggers when the SHELL
   (not the viewport) is narrow — a side panel on desktop squeezes the game
   to phone-shaped and the canvas now stretches to fill it. */
@container gps (max-width: 40rem) {
  .gps-game-area--fullscreen {
    align-items: stretch;
    justify-content: stretch;
  }
}

/* ── Unified `.gps-*` game styles ──
   Replaces ad-hoc `<h1>` / `<h2>` in game bodies. */
.gps-phase-h {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

/* Universal card wrapper — every game landing / lobby / recap uses this so
   pre-game surfaces share the same shadow + radius + padding. */
.gps-game-card {
  width: min(92vw, 480px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--elevation-1);
}

/* Universal focus-visible ring for every input / button in the in-game shell.
   Was scattered as `box-shadow: 0 0 0 3px rgba(99,102,241,0.35);` in a half-
   dozen places — now derives from --accent-ring so a palette swap is one rule. */
.gps-shell :focus-visible {
  /* The outline survives a game's own box-shadow (board cells, sockets), which would
     otherwise replace the ring at equal specificity and hide focus entirely. */
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-color: var(--accent);
}
.gps-error { color: #fca5a5; font-weight: 600; }

/* ── Result ceremony (js/platform/resultCeremony.js, deck idea #19) ───────────
   While the ceremony runs the dialog carries data-ceremony, and data-beats grows
   "freeze headline rank record action" as each beat lands. Only opacity and translate
   move: every line stays in the accessibility tree and the footer is never hidden, so a
   screen reader and a keyboard have the whole result from the first frame. Reduced
   motion never gets data-ceremony at all. */
dialog.gps-modal[data-ceremony] .gps-game-summary,
dialog.gps-modal[data-ceremony] .gps-modal-stats,
dialog.gps-modal[data-ceremony] .gps-result-details,
dialog.gps-modal[data-ceremony] .gps-modal-rank,
dialog.gps-modal[data-ceremony] .gps-modal-board,
dialog.gps-modal[data-ceremony] .gps-modal-skeleton {
  opacity: 0;
  translate: 0 8px;
  transition: opacity 0.26s ease-out, translate 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

dialog.gps-modal[data-beats~="headline"] .gps-game-summary,
dialog.gps-modal[data-beats~="headline"] .gps-modal-stats,
dialog.gps-modal[data-beats~="headline"] .gps-result-details,
dialog.gps-modal[data-beats~="rank"] .gps-modal-rank,
dialog.gps-modal[data-beats~="rank"] .gps-modal-board,
dialog.gps-modal[data-beats~="rank"] .gps-modal-skeleton {
  opacity: 1;
  translate: 0 0;
}

dialog.gps-modal[data-ceremony][data-beats~="record"] .gps-modal-stats .gps-stat:first-child {
  animation: gps-ceremony-record 0.9s ease-out 1;
}

dialog.gps-modal[data-ceremony][data-beats~="action"] .gps-play-again-actions .app-btn--primary {
  animation: gps-ceremony-action 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3) 1;
}

@keyframes gps-ceremony-record {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--fx-accent, #fbbf24) 70%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

@keyframes gps-ceremony-action {
  0% { scale: 1; }
  45% { scale: 1.06; }
  100% { scale: 1; }
}

.gps-ceremony-skip {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: var(--color-text-muted, inherit);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.gps-ceremony-skip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Safe areas (Profile B) ────────────────────────────────────────────────────
   One rule for every game instead of one per game: the play area keeps clear of a notch,
   rounded corners and the home indicator. A fullscreen game area has no padding and its game
   places its own HUD inside the insets. The end card shrinks by the insets too. */
.gps-game-area:not(.gps-game-area--fullscreen) {
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}
@media (max-height: 500px) {
  .gps-game-area:not(.gps-game-area--fullscreen) {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }
}
dialog.gps-modal {
  max-height: calc(100dvh - 2.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* ── The end card on a short phone (Profile B: no scrollbar) ─────────────────────
   A 667px phone could not fit summary + six stats + rank + top 3 + details + the button.
   Tighter spacing first; then the top-3 board steps aside (the leaderboard page has it,
   and the rank line still says where you placed). */
@media (max-height: 740px) {
  dialog.gps-modal { gap: 0.55rem; padding: 0.9rem 1rem 0.85rem; }
  .gps-modal-stats { gap: 0.35rem; }
  .gps-result-details[open] { max-height: 28dvh; }
}
@media (max-height: 680px) {
  .gps-modal-board { display: none; }
}

/* ── The start card's map dropdown, beside OK ──────────────────────────────────
   A labelled native <select>: one control, keyboard and screen-reader ready, and on a phone
   the OS picker. It leads the footer row (OK follows) and takes the row on a narrow card. */
.gps-intro-map {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}
.gps-intro-map-label {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.gps-intro-map-select {
  min-height: 2.5rem;
  min-width: 11rem;
  max-width: 100%;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 8px);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font: inherit;
  font-weight: 600;
}
.gps-intro-map-select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
@media (pointer: coarse) {
  .gps-intro-map-select { min-height: 44px; }
}
@media (max-width: 520px) {
  .gps-intro-map { flex-basis: 100%; justify-content: center; }
  .gps-intro-map-select { flex: 1 1 auto; }
}
