/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Global keyboard focus ring (WCAG AAA High Contrast) ──
   Applies to every interactive element by default. The :focus-visible selector
   excludes mouse clicks, so the ring never flashes on tap — only on Tab/Space/
   Enter navigation. Resolves to high-contrast cyan/indigo halo with offset. */
:where(a, button, [role="button"], [role="link"], [role="menuitem"], [role="tab"],
       input, select, textarea, summary, label[tabindex]):focus-visible {
    outline: 2px solid var(--accent-cyan, #22d3ee);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.25);
}

/* ── Focus rings the zero-specificity rule above cannot reach ──
   That rule is :where(), so any component that styles its own outline or shadow wins over
   it. Three surfaces need a ring that holds:
     • Hub cards. Their chips take focus, not the card, and the card's paint containment
       clips an outline drawn outside a chip, so the card itself lights up while a chip
       inside it has keyboard or gamepad focus.
     • Dialog buttons. `.gps-shell :focus-visible` (games.css) swaps the outline for a 45%
       alpha shadow that disappears on the modal scrim; the :is() below outranks it on
       specificity, whatever order the sheets load in.
     • Gamepad navigation. gamepadBus.js moves focus with el.focus(), which a browser may not
       mark :focus-visible after a pointer click; html[data-input="pad"] (set while a pad
       drives the page) shows the ring on plain :focus as well.
   Colour is the same --accent-cyan halo as the global ring, so a theme swap is one token. */
.home-card.home-card:has(:focus-visible),
.gps-game-card.gps-game-card:has(:focus-visible),
.gps-game-card.gps-game-card:focus-visible {
    border-color: var(--accent-cyan, #22d3ee);
    box-shadow: 0 0 0 2px var(--accent-cyan, #22d3ee), 0 0 0 6px rgba(34, 211, 238, 0.22);
}

:is(dialog, [role="dialog"], [role="alertdialog"], [aria-modal="true"], .gps-modal-overlay, .gps-shell)
    :is(button, a[href], [role="button"], [role="tab"], summary):focus-visible,
html[data-input="pad"] :is(a[href], button, [role="button"], [role="tab"], input, select, summary):focus {
    outline: 2px solid var(--accent-cyan, #22d3ee);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.25);
}

html[data-input="pad"] .home-card.home-card:has(:focus),
html[data-input="pad"] .gps-game-card.gps-game-card:has(:focus) {
    border-color: var(--accent-cyan, #22d3ee);
    box-shadow: 0 0 0 2px var(--accent-cyan, #22d3ee), 0 0 0 6px rgba(34, 211, 238, 0.22);
}

/* Windows High Contrast / forced colours drop box-shadow; keep a system-coloured outline. */
@media (forced-colors: active) {
    :focus-visible,
    :is(.home-card, .gps-game-card):has(:focus-visible) {
        outline: 2px solid Highlight;
        outline-offset: 2px;
    }
}

/* Tabular figures for numbers, counters, leaderboards & timestamps to avoid layout jitter.
   Broadened from an explicit class list to the "this surface holds numbers" pattern — every
   HUD chip, score tile, time display, badge and percentage cell — so a new surface inherits
   this without having to be added to a list. `:where()` keeps specificity at zero so a
   component can still opt OUT by declaring its own font-variant. */
:where(.gps-stat-value, .prf-chip-val, .gl-fps, .timer, [data-tabular],
       /* Generic "this surface holds a number" hooks — match by suffix so a component that
          surfaces scores ("-score"), ELOs ("-elo"), times ("-time") and counts ("-count")
          inherits without being added. */
       [class$="-score"], [class$="-elo"], [class$="-time"], [class$="-count"],
       [class$="-val"], [class$="-rank"], [class$="-rating"], [class$="-pct"]) {
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ── Skip link (global so every layout can use it).
   Off-screen rather than `display: none` / `visibility: hidden`, both of which
   would take it out of the tab order and defeat the point. It reveals itself on
   :focus-visible only, so a pointer user never sees it. */
.gl-skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 1000;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    /* Not `--color-accent`: white on #6366f1 measures 4.47:1, a hair under the
       4.5:1 AA floor. A link that exists purely for accessibility has no excuse
       to miss it, so this uses a darkened accent that clears the bar in both
       schemes (white on #4338ca ≈ 8.2:1). */
    background: #4338ca;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    /* Parked just off the top edge; the transform is what hides it. */
    transform: translateY(-200%);
}

.gl-skip-link:focus-visible {
    transform: translateY(0);
    outline: 2px solid var(--color-text-primary);
    outline-offset: 2px;
}

/* ── App Loading Spinner & Blazor Error UI ── */
.loading-progress {
    position: absolute;
    display: block;
    width: 5rem;
    height: 5rem;
    inset: 38vh 0 auto 0;
    margin: 0 auto;
}
.loading-progress circle {
    fill: none;
    stroke: rgba(148, 163, 184, 0.2);
    stroke-width: 0.5rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--accent-cyan, #22d3ee);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text-secondary, #94a3b8);
    inset: calc(38vh + 6rem) 0 auto 0;
}
.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading…");
}

#blazor-error-ui {
    background: #450a0a;
    color: #fca5a5;
    border-top: 1px solid #7f1d1d;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
    display: none;
    left: 0;
    bottom: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: var(--z-error-overlay, 10000);
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}
#blazor-error-ui a.reload {
    color: #ffffff;
    background: #dc2626;
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    margin-left: 0.5rem;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: auto;
    padding: 0.25rem 0.5rem;
    font-size: 1.1rem;
}

/* ── Minimum touch target ─────────────────────────────────────────────────────
   Interactive controls under 44×44 CSS px on a phone are below Apple's 44pt
   guidance and WCAG 2.5.8's 24px floor.

   The fix is to GROW THE CONTROL (`min-height`) — it is the honest one, because
   the thing you aim at is the thing you hit. Do not use an invisible `::after`
   expansion instead: a 44px invisible box on a chip 8px from its neighbour
   overlaps that neighbour and silently steals its taps.

   Scoped to `pointer: coarse` so mouse-driven desktop layouts keep their
   current density. */
@media (pointer: coarse) {
    :where(.gl-brand, .gl-account-trigger, .gl-skip-link,
           .gl-overflow-item,
           .home-mode-chip, .home-action, .home-card-head,
           .app-notfound__link, .app-fallback-link,
           .fq-option,
           .reload,
           /* The `.pvs-btn` family is used for every interaction in
              PoVoxelStrike's lobby + game.
              Without these the buttons would render at their intrinsic height
              (~28px) and miss the 44px floor on portrait phones. */
           .pvs-btn, .pvs-btn-primary) {
        min-height: 44px;
    }

    /* Height alone is not a 44px target — these are the controls narrow enough
       that the horizontal axis was still the limiting one (the 🎮 switcher at
       42px, the 1P/2P mode chips at 37px). */
    :where(.home-mode-chip) {
        min-width: 44px;
    }

    /* min-height is inert on an inline box, and several of the above are plain
       <a>. Flex centring makes the extra height actually surround the label. */
    :where(.gl-brand, .gl-skip-link, .home-mode-chip) {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Native controls: a range is a 16px-tall strip and a select ~17px. Giving
       the element height leaves the painted track/chevron centred inside it. */
    :where(input[type="range"], select, input[type="text"], input[type="number"]) {
        min-height: 44px;
    }
}

html, body, #app {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text-primary);
}

/* Conditional glass: when the OS/user asks to reduce transparency, collapse the
   glassmorphism blur tokens to `none` in one place. Because every glass surface
   consumes `--glass-*` via `backdrop-filter: var(--glass-N)`, this single
   override strips the blur app-wide (a11y + a GPU win on low-power devices)
   without editing a single component. The 2026 `prefers-reduced-transparency`
   media feature; a no-op on browsers that don't yet support it. */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --glass-1: none;
    --glass-2: none;
    --glass-3: none;
  }}

body {
  font-family: var(--font-body);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
}

a { color: var(--color-accent); text-decoration: none; }
/* Set the SIZE as well as the family: a button whose own rule omits font-size
   would fall back to the UA default (13.3333px in Chromium), an odd off-scale
   value. A baseline here means an unstyled button is merely plain. */
button {
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.2;
}

/* Page headings are programmatically focused on route change (FocusOnNavigate,
   App.razor) so screen readers announce the new page. Sighted users must not see
   that focus.

   `:focus:not(:focus-visible)` does NOT suppress it: Chromium reports
   `:focus-visible = true` when script focuses an element the user cannot reach
   by pointer, so a ring keyed on `:focus-visible` would box the title on every
   route.

   FocusOnNavigate stamps `tabindex="-1"`, which by definition means the heading
   is NOT tab-reachable, so a focus ring on it can only ever be this navigation
   artifact and never real keyboard focus. Suppress it unconditionally there, and
   keep the accent ring only for a heading an author deliberately made
   tab-reachable with `tabindex="0"`. */
h1:focus, h2:focus, h3:focus { outline: none; }
h1[tabindex="0"]:focus-visible,
h2[tabindex="0"]:focus-visible,
h3[tabindex="0"]:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

/* ── Skeleton Loading ──
   The base class only: the shared stage is the shimmer block below. The old
   .skeleton--card / --text / --text-short / --btn / --search shapes belonged to the
   home-page skeleton that GameSkeleton replaced; nothing rendered them. */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface) 25%, var(--color-surface-hover) 50%, var(--color-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.5rem;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }}

/* ── Shared inline loader (single source of truth for "Loading…" states) ──
   Replaces the app's three ad-hoc idioms (bare left-aligned <p>Loading...</p>,
   themed one-offs, etc.) with one centered spinner + muted label so every list
   / lobby / leaderboard that can't use a skeleton reads identically. */
.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  text-align: center;
}
.app-loading__spinner {
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-pill);
  animation: app-spin 0.8s linear infinite;
}
@keyframes app-spin { to { transform: rotate(360deg); }}
@media (prefers-reduced-motion: reduce) {
  .app-loading__spinner { animation: none; }}

@keyframes meshShift {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.1) rotate(2deg); }
  100% { transform: scale(1) rotate(-1deg); }}

/* Home page selectors (.home-*) migrated to scoped Pages/Index.razor.css. */

/* Login gate styles migrated to scoped Components/LoginScreen.razor.css. */

/* All .home-* selectors migrated to scoped Pages/Index.razor.css. */

/* ── Single Player Page + shared button ──
   .sp-page / .sp-card frame a lobby (LobbyPanel) and .sp-btn is the sandbox's
   button; .sp-back / .sp-title / .sp-subtitle went with the old single-player
   page shell that PageHeader and LobbyPanel replaced. */
.sp-page {
  padding: 2rem 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.sp-card {
  /* A token, not the dark literal this was: on the low graphics tier (no glass fill
     from glass.css) the literal left every lobby a dark slab with dark text on it
     in the light scheme. */
  background: var(--surface-2);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 2rem;
  backdrop-filter: blur(12px);
}

/* ── High Scores — moved to scoped
     Pages/Index.razor.css and Components/HomeHighScores.razor.css ── */

/* ── Responsive ──────────────────────────────────────────────────────────────
   Canonical breakpoint scale (see --bp-* documentation in the token block).
   App chrome uses ONLY these three widths:
     ≤480px  compact phone portrait
     ≤640px  phone / small tablet portrait
     ≤960px  tablet landscape / small desktop
   Anything between them (the old 560/600/680/768/900/920/1100 one-offs) made the
   same component reflow at a different width depending on which page it was on.
   Per-game boards under css/games.css keep their own board-specific widths —
   those are tuned to a fixed aspect grid, not to the chrome. */
@media (max-width: 640px) {
  .sp-page { padding: 1rem; }
  .sp-card { padding: 1.25rem; }}

/* ── Accessibility: reduced motion ───────────────────────────────────────────
   ONE universal-selector guard, keyed on `<html data-motion="reduce">`, defined
   next to the token collapse in the :root[data-motion] block above.

   This file used to carry a second, near-identical `@media (prefers-reduced-motion)`
   universal rule. Two `*, *::before, *::after` blocks meant every element on the
   page was matched twice on every style recalc, for one behaviour.

   The OS preference is now resolved into the same attribute — by the pre-paint
   script in index.html, and kept live by appPrefs.js — exactly as the OS colour
   preference is resolved into `data-theme`. Same reasoning as the light palette:
   resolve the media query to a concrete value once, in one place, so an explicit
   user choice can win and the stylesheet has a single source of truth.

   The per-component `@media (prefers-reduced-motion: reduce)` opt-outs elsewhere
   (the spinner, the mock banner, the view transition) are narrow and still stand
   on their own — they are not universal selectors. */

/* ─────────────────────────────────────────────────────────────────────────
   Universal primitives.

   Everything below this line is a CONSUMABLE — pages and components should
   prefer these classes/tokens over inventing per-component CSS. Where a page
   still has its own copy of a primitive (e.g. a `.app-loading` variant),
   it is being phased in via per-game refactors; do not write new ones.

   Sections:
     · Viewport-fit tokens      (--gps-area-h, --gps-topbar-h)
     · State primitives         (.app-loading, .app-empty-state)
     · Component primitives     (.app-btn, .app-chip)
     · Typography defaults      (text-wrap balance/pretty, fluid-scale anchors)
     · Touch target floor       (extended selector list under @media coarse)
   ───────────────────────────────────────────────────────────────────────── */

/* ── Viewport-fit tokens ─────────────────────────────────────────────────────
   Mobile portrait fit is the brief's #1 explicit ask: "fit content within
   the viewport to eliminate vertical scrolling in mobile portrait without
   truncation". Each game/canvas page used to compute its own height from
   `100vh - NNNpx` arithmetic, which gave 7 different answers across the
   tree. Centralising the arithmetic here lets GameShell publish a single
   `--gps-area-h` value that descendants can `min(...)` against.

   `100dvh` is used in preference to `100vh` because `dvh` excludes the
   on-screen keyboard and address-bar UI on phones — `vh` over-allocates by
   ~80-120px on portrait phones and pushes the game board off the fold. The
   existing `100svh` rules stay where they are (they govern the page shell,
   not the game area). */
:root {
  /* The height GameShell computes for the game area: viewport minus the
     top-bar (sticky, ~56px) minus any layout-specific rail. Pages read it
     as `min(var(--gps-area-h), NNNpx)` so the area can never exceed the
     available space, but will also shrink on a tall narrow phone where the
     keyboard is open. Default: full dynamic viewport. */
  --gps-area-h: 100dvh;
  /* Matches the measured 64px top bar; a smaller token would make every
     fullscreen game area over-reserve and the page scroll by the difference. */
  --gps-topbar-h: 4rem;
  /* One content-well width for the full-width pages (home catalog,
     leaderboards, profile, game shells), so navigating does not read as drift.
     Pages may still opt narrower for prose. */
  --content-max: 960px;
  /* Bottom safe-area for iOS notch / gesture bar; honoured by the `.gl-page`
     padding and the GameShell's `--gps-area-h` calc. */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ── State primitives ─────────────────────────────────────────────────────
   Three viewable outcomes every list/lobby/leaderboard can be in:
     loading   — a spinner + muted label, single source of truth (was scattered
                 across the tree as ad-hoc <p>Loading...</p>)
     empty     — an illustration slot + headline + optional CTA
     error     — a recoverable failure, with retry button when a callback
                 is supplied

   Pages that currently roll their own (`<p>Loading…</p>` etc.) should
   migrate to these. */
.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  text-align: center;
}

.app-loading__spinner {
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-pill);
  animation: app-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .app-loading__spinner { animation: none; }
}

/* Inline error strip — the failures that do not replace the card they sit in
   (a lobby whose hub dropped, a quiz that could not connect). The page-level
   shape is .app-empty-state--error. Owned by Feedback/InlineError.razor so the
   three lobbies that used to hand-roll it read identically. */
.app-error-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-error) 45%, transparent);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-error) 12%, transparent);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.app-error-inline__text {
  flex: 1 1 12rem;
  min-width: 0;
}

/* Empty state — the "no rows yet" view on a leaderboard/lobby. Composition:
   an icon (emoji, supplied by caller), a headline, a body sentence, an
   optional action button. The icon is large (clamp-scaled) and dimmed so
   the headline reads first. */
.app-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  /* An empty state is a placeholder, so the padding stays small: bigger padding
     plus the min-height below would run to ~280px for one icon, one line of
     title and two lines of body. */
  padding: var(--space-5) var(--space-4);
  text-align: center;
  color: var(--color-text-secondary);
  /* Keep empty states inside the viewport on a portrait phone — an empty
     board should never have to scroll to read. The 28dvh middle term is the
     binding one on short viewports: this is a placeholder, not a hero. */
  min-height: clamp(9rem, 28dvh, 18rem);
}

/* Short viewports: the placeholder gives up its remaining generosity so the
   page around it fits. The icon is decorative and the min-height is a comfort
   floor, not content — both yield before anything with words in it does. */
@media (max-height: 780px) {
  .app-empty-state {
    padding: var(--space-3) var(--space-4);
    min-height: 0;
    gap: var(--space-2);
  }
  .app-empty-state__icon { font-size: 1.6rem; }
}

.app-empty-state__icon {
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  opacity: 0.55;
  line-height: 1;
  /* `text-wrap: balance` below keeps a multi-line emoji string from
     collapsing to its widest glyph and clipping on narrow viewports. */
}

.app-empty-state__title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

.app-empty-state__body {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.5;
  max-width: 32ch;
  color: var(--color-text-secondary);
}

.app-empty-state__action {
  margin-top: var(--space-2);
}

/* Error tone — the same card, tinted and raised. One implementation, two call
   sites: <EmptyState Tone="error"> and the <ErrorState> wrapper over it. */
.app-empty-state--error {
  padding: var(--space-6) var(--space-4);
  min-height: 0;
  /* Soft danger tint so the eye lands here before the headline. */
  background: var(--accent-danger-soft);
  border: 1px solid color-mix(in srgb, var(--accent-danger) 35%, transparent);
  border-radius: var(--radius-lg);
}

.app-empty-state--error .app-empty-state__icon {
  font-size: clamp(2rem, 4vw, 2.5rem);
}

.app-empty-state--error .app-empty-state__title {
  color: var(--accent-danger-ink);
}

.app-empty-state--error .app-empty-state__body {
  max-width: 38ch;
  color: var(--color-text-primary);
}

/* ── Component primitives ──────────────────────────────────────────────────
   Drop-in classes for buttons, cards, chips, and links. Pages should prefer
   these over per-page copies — both for bundle size (the WASM trim audit
   removes duplicated CSS) and for the visual cohesion the brief asks for.

   Where a game needs a different visual treatment (Sand
   Playground sand palette), it can declare its own
   `--color-accent-solid` and `--accent-cyan` inside its theme root; the
   primitives below pick the new hues up automatically. */

/* Button: four variants. The 44px floor is set in the @media (pointer: coarse)
   block below; this rule only governs the visual treatment. */
.app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  font-family: var(--font-body);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              transform var(--dur-spring) var(--ease-spring),
              filter var(--dur-fast) var(--ease-standard);
  /* Containment: this button never paints outside its own box, so the
     browser can promote it to a layer without re-rasterising its parents. */
  contain: layout paint;
}

/* Down fast, back on the spring: the release is what reads as physical. */
.app-btn:active { transform: scale(0.96); transition-duration: var(--dur-fast); transition-timing-function: var(--ease-out); }
.app-btn:disabled,
.app-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.app-btn--primary {
  background: var(--color-accent-solid);
  color: var(--color-accent-contrast);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--color-accent-solid) 35%, transparent);
}

.app-btn--primary:hover {
  filter: brightness(1.1);
  border-color: rgba(255, 255, 255, 0.28);
}

.app-btn--secondary {
  background: var(--surface-1);
  border-color: var(--color-border);
  color: var(--color-text-primary);
}

.app-btn--secondary:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-secondary);
}

.app-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-secondary);
}

.app-btn--ghost:hover {
  background: var(--tint-soft);
  color: var(--color-text-primary);
}

/* Size modifiers — applied via the same `app-btn` class. */
.app-btn--sm { padding: 0.35rem 0.75rem; font-size: var(--text-xs); }
.app-btn--lg { padding: 0.75rem 1.4rem; font-size: var(--text-base); }

/* Chip: small status / filter pill. Matches the existing `.gl-overflow-item`
   styling so a chip and a menu item read as the same family. It is also every
   lobby's host / guest / ready pill and the hub connection pill. */
.app-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--surface-1);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  text-decoration: none;
  white-space: nowrap;
  contain: layout paint;
}

.app-chip--accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--color-accent) 30%, transparent);
  color: var(--accent-ink);
}

.app-chip--success {
  background: var(--accent-success-soft);
  border-color: color-mix(in srgb, var(--accent-success) 30%, transparent);
  color: var(--accent-success-ink);
}

.app-chip--warning {
  background: var(--accent-warning-soft);
  border-color: color-mix(in srgb, var(--accent-warning) 30%, transparent);
  color: var(--accent-warning-ink);
}

/* Segmented control: one choice of a few, all visible at once (the game mode
   switch, the theme picker, a run type). The selected state is read from the
   ARIA attribute the buttons already have to carry, so there is no "on" class to
   keep in step with it. A themed surface re-points the four --seg-* properties
   (Racer's start card does). */
.app-seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--seg-well, var(--surface-3));
}

.app-seg__btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--seg-ink, var(--color-text-secondary));
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  min-height: 2rem;
  padding: 0.3rem 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard);
}

.app-seg__btn:hover { color: var(--color-text-primary); }

/* --color-accent-solid, not --accent: white on --accent is a hair under AA at
   this size (see the token's note above). */
.app-seg__btn:is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]) {
  background: var(--seg-on, var(--color-accent-solid));
  color: var(--seg-on-ink, var(--color-accent-contrast));
}

.app-seg__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-seg__btn:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

/* A second, subordinate row under an accent one: the selection is a raised
   surface, not another block of accent. */
.app-seg--quiet .app-seg__btn { font-weight: 500; }

.app-seg--quiet .app-seg__btn:is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]) {
  background: var(--color-surface);
  color: var(--color-text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

@media (pointer: coarse) {
  .app-seg__btn { min-height: 44px; }
}

/* ── Typography defaults ───────────────────────────────────────────────────
   `text-wrap: balance` for headings and `text-wrap: pretty` for body copy
   eliminates orphan / widow lines without any JS or layout work. Applied
   globally so a new component inherits it for free.

   Both are CSS Text Module Level 4; baseline support is safe enough now
   (Chrome 114+, Firefox 121+, Safari 17.5+). Browsers that don't recognise
   the property silently ignore it — the property is a layout hint, not a
   transform, so a no-op render is identical to today's. */
h1, h2, h3, h4, h5, h6,
.app-empty-state__title,
.gps-modal-title,
.gps-game-title {
  text-wrap: balance;
}

p, li, dd, blockquote,
.app-empty-state__body,
.gps-game-summary,
.gps-intro-objective {
  text-wrap: pretty;
}

/* The `:where()` selector list above is the same idea as the touch-target
   rule below: zero specificity, easy to opt out by setting `text-wrap: wrap`
   in a component rule if a balance wraps the wrong element. */

/* ── Touch target floor — extension ──────────────────────────────────────────
   The component primitives (the `.app-btn` family, `.app-chip`, `.app-link`)
   are routed through this `:where()` extension list rather than appended to the
   explicit selector list above, so the floor applies to every new component
   without re-editing the older rule. The two rules compose — the older list
   sets its selectors to 44px; this list adds the primitives. */
@media (pointer: coarse) {
  /* A chip gets the floor only when it is something to press: most are status
     labels (a lobby's "host" pill), and a 44px-tall label is just a tall label. */
  :where(.app-btn, a.app-chip, button.app-chip, .app-link,
         /* Empty/error state actions. The component renders the retry / CTA as
            `.app-btn` already, but the older selectors in this file do not
            enumerate these, so a page that rolls a plain <button> inside a state
            card still gets the floor. */
         .app-empty-state__action button) {
    min-height: 44px;
  }

  /* Game-local buttons that were under the floor on both axes (26 to 36px). */
  :where(.poeco-pill, .poeco-icon-btn, .kiosk-bar-btn, .prefs-sheet-close,
         .sp-btn, .pocabinet-stepper button, .toast-action) {
    min-height: 44px;
    min-width: 44px;
  }

  /* ── The native controls the lists above never cover.
     Both rules above enumerate CLASSES, so anything rendered as a bare
     <select>, <input type="range"> or a game-local button class would
     otherwise miss the floor (e.g. button.toast-close is 12 × 18).

     `min-height` alone is not enough here: .toast-close fails on WIDTH too, so
     both axes are set. Still zero-specificity via `:where()`, so any component
     rule can opt out by stating its own size. */
  /* A checkbox or radio inside a <label> is excluded — the label is its hit
     target, and stretching the native box to 44×44 paints a large EMPTY square
     (no tick glyph scales with it) that reads as a broken text field. Labels get
     the floor instead. */
  :where(select,
         input[type="range"],
         input[type="checkbox"]:not(label *),
         input[type="radio"]:not(label *),
         .toast-close) {
    min-height: 44px;
    min-width: 44px;
  }

  :where(label:has(> input[type="checkbox"], > input[type="radio"])) {
    min-height: 44px;
  }

  /* A range input with a 44px min-height needs the track centred in it or the
     thumb sits against the top edge of its own hit box. */
  :where(input[type="range"]) {
    align-self: center;
  }

  /* The catch-all: every button, tab, disclosure and link-styled-as-a-button, so a new
     component cannot ship under the floor (LinkAuditUiTests checks every route on a 375×667
     touch phone). Zero specificity, so a component can still state its own size; an inline
     text link is exempt (WCAG 2.5.8), and [data-tap-exempt] opts out a control that is not
     meant for a thumb. */
  :where(button, [role="button"], [role="tab"], summary, a.app-btn, a[role="tab"]):not([data-tap-exempt]) {
    min-height: 44px;
  }
  :where(button, [role="button"], [role="tab"]):not([data-tap-exempt]) {
    min-width: 44px;
  }
  :where(summary) {
    display: flex;
    align-items: center;
  }
}

/* ── Connect Five physics clone ──────────────────────────────────────────────
   js/connectfive/index.js parents the falling disc to document.body so matter.js
   can drive it in viewport coordinates without disturbing the grid. That puts it
   OUTSIDE the ConnectFivePage scoped-CSS boundary: every disc rule there compiles
   to `.cf-cell .piece[b-<hash>]`, and a body-parented div carries no scope
   attribute, so the clone matched nothing and fell as a fully transparent box.
   With its cell's static disc hidden for the flight, the board would play the
   drop sound and show nothing. These rules are
   global on purpose — the element cannot be scoped. Geometry (size, position,
   transform) stays inline in the JS, which owns it per frame. */
.cf-physics-clone {
  border-radius: 50%;
  font-size: 0;
  box-shadow: var(--disc-shadow);
}

.cf-physics-clone.red-piece {
  background: radial-gradient(circle at 34% 28%,
    var(--disc-red-lit) 0%, var(--disc-red-mid) 46%, var(--disc-red-core) 100%);
}

.cf-physics-clone.yellow-piece {
  background: radial-gradient(circle at 34% 28%,
    var(--disc-yellow-lit) 0%, var(--disc-yellow-mid) 46%, var(--disc-yellow-core) 100%);
}

/* ── Safe areas ──────────────────────────────────────────────────────────────
   index.html asks for viewport-fit=cover, which is what makes every
   env(safe-area-inset-*) in the app non-zero on a notched phone. It also lets
   the page run under the notch, so the body keeps clear of it on the three
   sides no component handles; the bottom inset is applied per component. */
body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── Dialog entry ────────────────────────────────────────────────────────────
   Every native <dialog> lands on the spring instead of snapping in. Uses the
   individual scale/translate properties so it composes with a dialog that
   positions itself with `transform`.

   No opacity in the keyframe, on purpose. An animation sits on its first keyframe
   until the browser has painted a frame with it, and on a slow frame (measured:
   750 ms under software rendering) that left the whole dialog invisible behind its
   own backdrop. Scale and position can wait for a frame; visibility cannot. */
dialog[open] { animation: po-dialog-in var(--dur-spring) var(--ease-spring); }
@keyframes po-dialog-in {
  from { scale: 0.96; translate: 0 0.6rem; }
}
