/* Metagame shell — home, halls, store, cues, leagues, club.
 *
 * Self-contained on purpose. styles.css is 37KB of match-HUD rules built around
 * a full-bleed <canvas>; linking it here would drag all of that onto pages that
 * have no canvas. Both pages share semantic roles from ui-theme.css; palette
 * values live in src/ui-themes.js and remain independent of table materials.
 *
 * Layout contract: a scene fills the window. The shell is a three-row grid —
 * header, scene, tab bar — pinned to the viewport, and the page itself never
 * scrolls. Anything that overflows scrolls inside its own panel, so the header
 * and the tabs are always reachable. This is a game screen, not a document.
 */

:root {
  /* One gutter everywhere. Landscape phones put the notch and the home
   * indicator in the short edges, so the safe-area insets are added to it
   * rather than replacing it. */
  --gutter: clamp(14px, 2.2vw, 30px);
  --pad-left: calc(var(--gutter) + env(safe-area-inset-left, 0px));
  --pad-right: calc(var(--gutter) + env(safe-area-inset-right, 0px));

  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  /* The shell owns the viewport; nothing scrolls the page itself. */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(13px, 1.15vw, 16px);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* A stray drag on a phone should not rubber-band the shell. */
  touch-action: manipulation;
}

/* --- shell ---------------------------------------------------------------- */

#app {
  /* dvh, not vh: mobile browser chrome collapses and vh would overflow. */
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  /* Scene backdrops paint to the edges; the grid clips them. */
  overflow: hidden;
}

/* --- header --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(8px, env(safe-area-inset-top, 0px)) var(--pad-right) 8px var(--pad-left);
  background: var(--panel-fill);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}

.identity { display: flex; align-items: center; gap: 10px; min-width: 0; }

.avatar {
  width: clamp(34px, 3.4vw, 46px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(15px, 1.5vw, 21px);
  color: var(--accent-secondary);
  background: radial-gradient(circle at 34% 28%, var(--raised), var(--background));
  border: 2px solid var(--accent-secondary);
  flex: none;
}

.identity-text { min-width: 0; }
.identity-name {
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity-level { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.8em; }

/* Level bar and every other progress bar share one element, so they cannot
 * drift apart visually. --v is the 0..1 fill. */
.bar {
  --v: 0;
  position: relative;
  height: 6px;
  min-width: 52px;
  flex: 1;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--v) * 100%);
  border-radius: inherit;
  background: var(--secondary-fill);
}
.bar.primary::after { background: var(--primary-fill); }

.wallet { margin-left: auto; display: flex; align-items: center; gap: clamp(10px, 1.6vw, 22px); }

.purse {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* The currency marks are fixed brand assets. The concept rasters drew a
 * different glyph on every screen ($, P, B, 8), which is the one thing a player
 * must be able to read at a glance. Defined once in the sprite, never varied. */
.mark { width: 1.45em; height: 1.45em; flex: none; }

.iconbtn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line-bright);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  flex: none;
}
.iconbtn:hover { color: var(--text); border-color: var(--accent-primary); }
.iconbtn svg { width: 20px; height: 20px; }

/* --- scenes --------------------------------------------------------------- */

.scenes { position: relative; min-height: 0; }

.scene {
  position: absolute;
  inset: 0;
  display: none;
  padding: clamp(12px, 1.8vh, 22px) var(--pad-right) clamp(12px, 1.8vh, 22px) var(--pad-left);
  /* Every scene lays itself out inside the space it is given, and only its own
   * panels scroll. */
  min-height: 0;
}
.scene[data-active] { display: grid; }

.scene-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }

h1, h2, h3 { margin: 0; letter-spacing: 0.04em; }
h1 { font-size: clamp(20px, 2.6vw, 38px); font-weight: 800; }
h2 { font-size: clamp(14px, 1.35vw, 19px); font-weight: 700; }
h3 { font-size: clamp(12px, 1.1vw, 15px); font-weight: 700; }

.eyebrow {
  font-size: 0.76em;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.count { color: var(--accent-secondary); font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- panels & cards ------------------------------------------------------- */

.panel {
  background: var(--panel-fill);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-lift);
  /* min-width too, or a header that cannot fit on one line widens the panel
   * past its track rather than wrapping inside it. */
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
  /* A narrow rail cannot fit a title and its trailing control on one line;
   * wrapping beats pushing the control off the panel. */
  flex-wrap: wrap;
}
.panel > header > * { min-width: 0; }
/* The panel is a column flexbox; without flex:1 the body sizes to its content
 * and leaves dead space under the last row. */
.panel > .body { flex: 1; padding: 14px 16px; min-height: 0; overflow: auto; }
.panel > .body.flush { padding: 0; }

/* The only scrolling in the shell happens inside these. Thin, unobtrusive. */
.panel > .body::-webkit-scrollbar { width: 8px; }
.panel > .body::-webkit-scrollbar-thumb { background: var(--line-bright); border-radius: 99px; }

/* --- controls ------------------------------------------------------------- */

/* An inline <svg> with no width/height fills its container, which turns a small
 * button glyph into a billboard. Everything that is not explicitly sized (.mark,
 * .tab svg, .iconbtn svg) gets a sane text-relative default. */
.btn svg, .pill svg, .price svg, .seg svg, .badge svg {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

.btn {
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.85em 1.5em;
  border-radius: 11px;
  border: 1px solid var(--line-bright);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }

/* The primary action follows the active theme. */
.btn.primary {
  background: var(--primary-fill);
  border-color: var(--accent-primary);
  color: var(--on-accent);
  box-shadow: var(--control-shadow);
}
.btn.ghost { background: transparent; color: var(--accent-secondary); border-color: var(--accent-secondary); }
.btn[disabled], .btn[aria-disabled="true"] {
  cursor: not-allowed;
  filter: none;
  background: var(--panel);
  color: var(--muted);
  border-color: var(--line);
  box-shadow: none;
}
.btn.big { font-size: 1.1em; padding: 1em 2em; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.9em;
  border-radius: 999px;
  border: 1px solid var(--accent-secondary);
  color: var(--accent-secondary);
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill.primary { border-color: var(--accent-primary); color: var(--accent-primary); }
.pill.solid { background: var(--accent-primary); border-color: var(--accent-primary); color: var(--on-accent); }

/* Segmented control — one control for one piece of state. */
.seg { display: inline-flex; border: 1px solid var(--line-bright); border-radius: 999px; overflow: hidden; }
.seg button {
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-size: 0.82em;
  padding: 0.55em 1.2em;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg button[aria-selected="true"] { background: var(--accent-primary); color: var(--on-accent); }
.seg button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* --- tab bar -------------------------------------------------------------- */

.tabbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--panel-fill);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 3;
}

.tab {
  font: inherit;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: clamp(6px, 1vh, 11px) 4px;
  display: grid;
  justify-items: center;
  gap: 3px;
  color: var(--muted);
  border-top: 2px solid transparent;
  /* The separators in the concept art, kept as an inset line so the active
   * tab's top rule can still run edge to edge. */
  box-shadow: inset 1px 0 0 var(--line);
}
.tab:first-child { box-shadow: none; }
.tab svg { width: clamp(19px, 1.9vw, 25px); height: clamp(19px, 1.9vw, 25px); }
.tab span { font-size: clamp(9px, 0.82vw, 12px); font-weight: 800; letter-spacing: 0.11em; }
.tab:hover { color: var(--text); }

/* One selected-state accent across every scene. */
.tab[aria-selected="true"] {
  color: var(--accent-primary);
  border-top-color: var(--accent-primary);
  background: linear-gradient(180deg, var(--accent-wash), transparent 70%);
}

/* --- overhead table art ---------------------------------------------------
 * Drawn overhead, not in perspective. docs/PLAN.md §14 fixes the match camera
 * directly overhead; the concept rasters showed angled three-quarter rooms,
 * which promises a viewpoint the game never renders. Menu art here matches
 * what the player will actually see.
 */

.felt {
  position: relative;
  border-radius: 10px;
  aspect-ratio: 2 / 1;
  background: var(--felt-color, #1c74c4);
  border: clamp(5px, 0.7vw, 9px) solid var(--rail-color, #5b3219);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), 0 8px 22px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
/* Six pockets, as corner/side dots. */
.felt::before,
.felt::after {
  content: "";
  position: absolute;
  inset: 0;
  /* One gradient per pocket: a single background-image with three positions
   * only ever paints once. */
  background-image:
    radial-gradient(circle, #05080b 46%, transparent 47%),
    radial-gradient(circle, #05080b 46%, transparent 47%),
    radial-gradient(circle, #05080b 46%, transparent 47%);
  background-repeat: no-repeat;
  background-size: 13% 26%, 13% 26%, 11% 22%;
}
.felt::before { background-position: 1% 2%, 99% 2%, 50% 1%; }
.felt::after { background-position: 1% 98%, 99% 98%, 50% 99%; }

/* --- utility -------------------------------------------------------------- */

.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.dim { color: var(--muted); }
.nums { font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: 10px; min-height: 0; }

.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;
}

:where(button, a, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===========================================================================
 * Scenes
 *
 * Each scene is a grid sized to the space between the header and the tab bar.
 * They are written so the populated state fits without scrolling at landscape
 * sizes; panels that can grow unboundedly (rosters, collections, leaderboards)
 * scroll inside themselves rather than pushing the shell.
 * =========================================================================== */

/* --- home ----------------------------------------------------------------- */

#scene-home {
  grid-template-columns: minmax(0, 1.85fr) minmax(250px, 0.95fr);
  grid-template-rows: minmax(0, 1fr);
  gap: clamp(10px, 1.4vw, 18px);
}

/* The right column scrolls as one rail. Three panels each taking a share of a
 * short viewport clip their own contents instead; a rail keeps every panel
 * whole and moves the overflow into one obvious place. */
.rail {
  display: grid;
  gap: clamp(8px, 1.2vh, 14px);
  align-content: start;
  /* max-content, not the default auto: a panel body is `flex:1; min-height:0`,
   * which contributes ~nothing to an auto track's intrinsic height, so the rows
   * came out shorter than their own contents and every card grew its own
   * scrollbar. Sizing each row to its content keeps the cards whole and leaves
   * the rail as the single place that scrolls. */
  grid-auto-rows: max-content;
  /* ...except the last card, which also takes whatever height is left, so the
   * rail ends level with the hero instead of stopping short of it. It still
   * never shrinks below its content. */
  grid-template-rows: max-content max-content minmax(max-content, 1fr);
  /* Both axes: a grid item defaults to min-width/min-height:auto, so without
   * these the rail's content widens its own column past the viewport instead
   * of wrapping, and refuses to scroll instead of overflowing. */
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.hero {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  display: grid;
  align-content: end;
  gap: 4px;
  padding: clamp(16px, 2.4vw, 34px);
  background:
    var(--hero-art) center / cover no-repeat,
    radial-gradient(120% 90% at 70% 18%, var(--accent-wash), transparent 60%),
    linear-gradient(200deg, var(--raised), var(--background) 62%);
}
/* The hero table is overhead, angled only by a gentle rotation — a menu flourish
 * that does not imply a different camera. */
.hero .felt {
  position: absolute;
  width: 46%;
  top: 8%;
  right: 5%;
  transform: rotate(-9deg);
  opacity: 0.95;
}
.hero h1 { position: relative; font-size: clamp(24px, 3.9vw, 58px); line-height: 1.02; }
.hero h1 .accent { color: var(--accent-primary); }
.hero .sub { position: relative; color: var(--muted); font-size: clamp(13px, 1.3vw, 18px); }
.hero .actions { position: relative; display: flex; gap: 12px; flex-wrap: wrap; margin-top: clamp(10px, 1.6vh, 20px); }

.rail .panel:last-child > .body { display: flex; flex-direction: column; gap: 12px; }
/* Wraps rather than scrolling sideways; a half-cut avatar reads as broken. */
.friends { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.friend { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.friends-more { margin-top: auto; align-self: flex-start; padding: 0.45em 1em; font-size: 0.78em; }
.friend .avatar { width: 34px; font-size: 14px; border-color: var(--line-bright); color: var(--muted); }
.friend b { font-size: 0.86em; letter-spacing: 0.05em; }
.friend small { color: var(--muted); display: block; font-size: 0.78em; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.good { background: var(--status-success); }
.dot.busy { background: var(--status-warning); }
.dot.idle { background: var(--muted); }

/* --- halls ---------------------------------------------------------------- */

#scene-halls {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.6vh, 18px);
  justify-items: center;
}
#scene-halls .scene-head,
#scene-halls .hall-modes { justify-self: center; }

.halls {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 1.4vw, 20px);
  width: 100%;
  min-height: 0;
}

.hall {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: clamp(12px, 1.4vw, 18px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel-fill);
  box-shadow: var(--panel-lift);
  text-align: center;
  min-height: 0;
}
.hall > * { min-width: 0; }
.hall { position: relative; }
/* Says why one card is outlined: it is the richest room open to the player. */
.ribbon {
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.3em 0.9em;
  border-radius: 999px;
  background: var(--accent-primary);
  color: var(--on-accent);
  font-size: 0.68em;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}
.hall[data-featured] { border-color: var(--accent-primary); box-shadow: 0 0 0 1px var(--accent-primary), var(--panel-lift); }
.hall[data-locked] { opacity: 0.72; }
/* Sized by the row it gets, with a ceiling.
 *
 * Neither pure axis works alone: width-driven overflows a short viewport, and
 * height-driven goes portrait once max-width clamps it. Capping the height at
 * 130px means the derived width (260px) stays inside a card at every layout
 * this shell uses, so the table is always landscape and always fits. */
.hall .felt {
  align-self: center;
  justify-self: center;
  height: min(100%, 130px);
  width: auto;
  max-width: 100%;
}
.hall h2 { font-size: clamp(14px, 1.5vw, 22px); }

/* Entry, prize and rake as three labelled columns. The concept art showed only
 * entry and prize, an economy with no house cut that cannot fund itself. */
.stakes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}
.stakes div + div { border-left: 1px solid var(--line); }
.stakes dt { font-size: 0.7em; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stakes dd {
  margin: 2px 0 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

/* --- store ---------------------------------------------------------------- */

#scene-store {
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(10px, 1.5vh, 18px);
  justify-items: center;
}
#scene-store .scene-head { justify-self: center; text-align: center; }
/* Categories centred, restore tucked to the right of the same row. */
.store-bar { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.store-bar .seg { grid-column: 2; }
.store-bar .restore { justify-self: end; }
/* Cards keep a third of the row however many there are, and a short shelf
 * centres rather than leaving an empty slot on the right. */
.store-shelf {
  --shelf-gap: clamp(10px, 1.4vw, 18px);
  display: flex;
  justify-content: center;
  gap: var(--shelf-gap);
  width: 100%;
  min-height: 0;
}
.store-shelf .product { flex: 0 1 calc((100% - 2 * var(--shelf-gap)) / 3); }
.store-shelf .product .art .felt.illustrated { max-height: 180px; }

.store-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: clamp(10px, 1.4vw, 18px);
  width: 100%;
  min-height: 0;
}
.store-minor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 1.2vw, 16px);
  min-height: 0;
}

.product {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: clamp(11px, 1.3vw, 17px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel-fill);
  box-shadow: var(--panel-lift);
  text-align: center;
  min-height: 0;
}
.product > * { min-width: 0; }
.product.featured { text-align: left; border-color: var(--accent-primary); }
/* One explicit track each way: an implicit auto column sizes to the image's
 * intrinsic width, so "100%" below would mean the picture, not the card. */
.product .art { display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; min-height: 0; overflow: hidden; }
.product .art .felt {
  height: min(100%, 120px);
  width: auto;
  max-width: 100%;
}
.product h2 { font-size: clamp(13px, 1.4vw, 20px); }
.product .blurb { color: var(--muted); font-size: 0.82em; }

.price {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 0.6em 1.3em;
  border-radius: 10px;
  border: 1px solid var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-wash);
  justify-self: center;
}
.product.featured .price { justify-self: start; }
/* Real-money price is unknown until a storefront answers. Never hardcoded. */
.price[data-pending] { color: var(--muted); border-color: var(--line-bright); background: transparent; }


/* Painted currency packs: square art contained in whatever box the card gives. */
.pack.illustrated { width: 100%; height: 100%; max-height: 140px; min-height: 0; }
.store-shelf .pack.illustrated { max-height: 220px; }
.pack.illustrated img { display: block; width: 100%; height: 100%; object-fit: contain; }
.restore { background: none; border: 0; color: var(--accent-secondary); font: inherit; font-size: 0.82em; cursor: pointer; text-decoration: underline; }

/* --- cues ----------------------------------------------------------------- */

#scene-cues {
  grid-template-columns: minmax(0, 1.4fr) minmax(290px, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(10px, 1.4vw, 18px);
}
#scene-cues .scene-head { grid-column: 1 / -1; }

.cue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(8px, 1vw, 14px);
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.cue-card {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  padding: 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-fill);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  min-height: 0;
}
.cue-card[aria-selected="true"] { border-color: var(--accent-primary); box-shadow: 0 0 0 1px var(--accent-primary); }
.cue-card[data-locked] { opacity: 0.5; cursor: not-allowed; }
.cue-card h3 { font-size: 0.92em; }

/* A cue drawn as a tapered shaft. Not a production model — a legible token. */
.cue-art {
  align-self: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  /* The shaft is rotated, so its bounding box is taller than the element.
   * Without this it paints over whatever sits below. */
  overflow: hidden;
}
.cue-art i {
  display: block;
  width: 86%;
  height: clamp(7px, 0.9vw, 11px);
  border-radius: 99px;
  transform: rotate(-26deg);
  background: linear-gradient(90deg, #efe6d2 0 16%, var(--cue-tint, #7a4a24) 16% 88%, #2a2a30 88%);
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.55);
}

.badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 0.66em;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 0.28em 0.7em;
  border-radius: 999px;
  background: var(--accent-primary);
  color: var(--on-accent);
}
.badge.muted { background: var(--line-bright); color: var(--text); }

.cue-detail { min-height: 0; }
.cue-detail .body { display: grid; gap: clamp(7px, 1.1vh, 13px); align-content: start; }
.cue-detail .cue-art { height: clamp(48px, 9vh, 92px); }
.cue-detail .cue-art i { transform: rotate(-8deg); width: 92%; }

.stats { display: grid; gap: 6px; }
.stat { display: grid; grid-template-columns: 4.4em minmax(0, 1fr) 1.6em; align-items: center; gap: 9px; }
.stat dt { font-size: 0.74em; letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stat dd { margin: 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* Ten segments, filled from the same number the value column prints, so the
 * bar and the digit can never disagree. */
.segs { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
.segs i { height: clamp(8px, 1.1vh, 13px); border-radius: 2px; background: var(--track); }
.segs i[data-on] { background: var(--secondary-fill); }

/* --- leagues -------------------------------------------------------------- */

#scene-leagues {
  grid-template-columns: minmax(250px, 0.82fr) minmax(0, 1.9fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.4vw, 18px);
}
#scene-leagues .scene-head { grid-column: 1 / -1; }
#scene-leagues .standing { grid-row: 2 / span 2; }

.standing .body { display: grid; gap: clamp(7px, 1.2vh, 14px); justify-items: center; text-align: center; align-content: start; }

.crest {
  width: clamp(60px, 9vw, 120px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(19px, 2.7vw, 38px);
  color: #0d131b;
  clip-path: polygon(50% 0, 100% 16%, 100% 62%, 50% 100%, 0 62%, 0 16%);
  background: linear-gradient(160deg, #e8edf3, #93a3b4 52%, #cfd8e2);
}
.crest[data-metal="gold"] { background: linear-gradient(160deg, #f9e09a, #d29c28 52%, #f2c14e); }
.crest[data-metal="bronze"] { background: linear-gradient(160deg, #e0b089, #9d6134 52%, #c98c55); }
.crest[data-metal="diamond"] { background: linear-gradient(160deg, #dff4ff, #7fc4e8 52%, #bfe6fa); }

.rewards { width: 100%; border-top: 1px solid var(--line); padding-top: 10px; text-align: left; }
/* On a narrow panel the countdown drops under the heading rather than each
 * label breaking mid-phrase. */
.rewards > .row { flex-wrap: wrap; gap: 2px 8px; }
.rewards > .row .eyebrow { white-space: nowrap; }
.rewards ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.rewards li {
  display: grid;
  grid-template-columns: 4.2em auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.88em;
}
.rewards .band { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); }
.rewards .dim { font-size: 0.9em; }
.rewards li[data-you] { background: var(--accent-wash); outline: 1px solid var(--accent-line); }
.rewards li[data-you] .band, .rewards li[data-you] .purse { color: var(--accent-primary); }

.board { min-height: 0; }
.board .body { padding: 0; }
.board table { width: 100%; border-collapse: collapse; }
.board thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-size: 0.71em;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  text-align: left;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
}
.board td { padding: clamp(6px, 1vh, 11px) 16px; border-bottom: 1px solid var(--line); }
.board .rank, .board .trophies { font-variant-numeric: tabular-nums; font-weight: 700; }
.board .trophies { text-align: right; }
.board thead th:last-child { text-align: right; }
.board tr[data-you] { background: var(--accent-wash); outline: 1px solid var(--accent-line); }
.board tr[data-you] td { color: var(--accent-primary); }

/* The ranking is not contiguous here. The concept art jumped 3 → 7 silently,
 * which reads as a bug; say so instead. */
.board tr.gap td {
  text-align: center;
  font-size: 0.7em;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 5px 16px;
  background: var(--recess);
}

.event {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.6vw, 22px);
  padding: clamp(10px, 1.3vw, 17px) clamp(12px, 1.8vw, 24px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--accent-primary);
  background: linear-gradient(100deg, var(--accent-wash), var(--surface) 55%);
}
.event h2 { font-size: clamp(15px, 1.9vw, 27px); }

/* --- club ----------------------------------------------------------------- */

#scene-club {
  grid-template-columns: minmax(230px, 0.78fr) minmax(0, 2.1fr);
  gap: clamp(10px, 1.4vw, 18px);
}
.profile .body { display: grid; gap: clamp(8px, 1.3vh, 15px); justify-items: center; text-align: center; align-content: start; }
.profile .avatar { width: clamp(58px, 8vw, 104px); font-size: clamp(26px, 3.6vw, 50px); border-width: 3px; border-color: var(--accent-primary); color: var(--text); }

.statlist { width: 100%; display: grid; gap: 5px; }
.statlist div { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.statlist dt { color: var(--muted); font-size: 0.86em; }
.statlist dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }

.club .body { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 12px; padding: 0; }
.roster { min-height: 0; overflow: auto; }

/* One row shape for every member. Status appears once, as a dot and a label;
 * the action column holds an action or nothing, never a restatement of status. */
.member {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: clamp(7px, 1.1vh, 12px) 16px;
  border-bottom: 1px solid var(--line);
}
.member .avatar { width: 36px; font-size: 15px; border-color: var(--line-bright); color: var(--muted); }
.member b { letter-spacing: 0.05em; }
.member .status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.82em; }
.member .btn { padding: 0.55em 1.2em; font-size: 0.8em; }
.roster-more { padding: 10px 16px; color: var(--muted); font-size: 0.8em; letter-spacing: 0.08em; text-align: center; }

.club-foot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 12px; padding: 0 16px 14px; }
.goal {
  display: grid;
  gap: 6px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--recess);
}

/* --- portrait ------------------------------------------------------------
 * The game is landscape. In portrait the six-column tab bar and the
 * side-by-side scenes stop working, so relax to a single column and let the
 * scenes scroll internally rather than pretending to fit.
 */
@media (orientation: portrait) and (max-width: 820px) {
  #scene-home,
  #scene-cues,
  #scene-leagues,
  #scene-club,
  .store-grid,
  .halls {
    grid-template-columns: minmax(0, 1fr);
  }
  #scene-home, #scene-cues, #scene-leagues, #scene-club { grid-auto-rows: minmax(0, auto); overflow: auto; }
  .hero { grid-row: auto; min-height: 42vh; }
  #scene-leagues .standing, .event { grid-row: auto; grid-column: auto; }
  .tab span { font-size: 9px; }
}

/* --- toast ---------------------------------------------------------------
 * Most actions in this shell need a server that does not exist. Saying so out
 * loud beats a button that looks live and does nothing.
 */
#toast {
  position: absolute;
  left: 50%;
  bottom: clamp(12px, 3vh, 30px);
  transform: translateX(-50%);
  max-width: min(560px, 82vw);
  padding: 0.75em 1.35em;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: var(--surface);
  box-shadow: var(--panel-lift);
  font-size: 0.86em;
  text-align: center;
  z-index: 5;
  pointer-events: none;
}
#toast[hidden] { display: none; }

/* --- online dialog ----------------------------------------------------------
 * Create a room in a hall, or join one by its code.
 */
#online {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(7px);
}
#online[hidden] { display: none; }

.online-card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  display: grid;
  gap: 12px;
  justify-items: stretch;
  padding: 26px 28px 22px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-bright);
  background: var(--surface);
  box-shadow: var(--panel-lift);
  text-align: center;
}
.online-card h2 { margin: 0; }
.online-card .sub, .online-card .or { margin: 0; color: var(--muted); }
.online-card .or { font-size: 0.8em; letter-spacing: 0.2em; text-transform: uppercase; }
.online-join { display: grid; gap: 8px; text-align: left; }
.online-join label { font-size: 0.8em; color: var(--muted); }
.online-join .row { gap: 8px; }
.online-join input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.15em;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 0.6em 0.8em;
  border-radius: var(--radius);
  border: 1px solid var(--line-bright);
  background: transparent;
  color: inherit;
}
.online-join input::placeholder { letter-spacing: 0.04em; text-transform: none; color: var(--muted); }
.online-error { margin: 0; font-size: 0.86em; color: var(--accent-primary); }
.online-error[hidden] { display: none; }

/* The Settings sheet is shared with the table screen: settings-sheet.css.
 * Its footer buttons are this page's .btn, so they match the lobby. */
#settings .sheetfoot .btn { font-size: 0.85em; padding: 0.7em 1.4em; }


/* --- small windows --------------------------------------------------------
 * A desktop window around 800x600 leaves the home rail about 470px, ~60px shy
 * of three whole cards. Trimming the card padding closes that gap, so the
 * lobby still fits on one screen the way the genre expects, instead of the
 * rail scrolling the last card half out of view.
 *
 * Bounded below at 461px so it cannot override the tighter landscape-phone
 * rhythm set further down.
 */
@media (max-height: 700px) and (min-height: 461px) {
  .rail { gap: 8px; }
  .rail .panel > header { padding: 8px 13px; }
  .rail .panel > .body { padding: 10px 13px; }
  .friend .avatar { width: 30px; }
}

/* --- short viewports ------------------------------------------------------
 * A landscape phone is ~390px tall. After the header and the tab bar a scene
 * has roughly 270px to work with, so the generous desktop rhythm has to give.
 * Trim the chrome rather than letting cards overflow each other.
 */
@media (max-height: 460px) and (orientation: landscape) {
  .scene { padding-top: 8px; padding-bottom: 8px; }
  #scene-halls, #scene-store, #scene-leagues, #scene-cues { gap: 7px; }
  .scene-head h1 { font-size: clamp(15px, 2.2vw, 22px); }
  .hall { padding: 8px; gap: 6px; }
  /* The felt is what tells the three halls apart, so it keeps a floor even
   * when the row it sits in is squeezed. Below this it reads as a smudge. */
  .hall .felt { min-height: 40px; border-width: 4px; }
  .hall h2 { font-size: clamp(11px, 1.5vw, 15px); }
  .stakes { padding: 4px 0; }
  .stakes dt { font-size: 0.62em; letter-spacing: 0.08em; }
  .btn { padding: 0.6em 1.1em; }
  .btn.big { font-size: 0.95em; padding: 0.65em 1.3em; }
  .hero { padding: 12px; }
  .hero h1 { font-size: clamp(19px, 3.2vw, 34px); }
  .product { padding: 8px; gap: 5px; }
  .product h2 { font-size: clamp(11px, 1.5vw, 15px); }
  /* The small cards cannot fit name + blurb + art + price in this much height.
   * The blurb is the expendable one: the art is what identifies the product.
   * The featured card has the room and keeps its copy. */
  .store-minor .product .blurb { display: none; }
  .product .blurb { font-size: 0.74em; }
  .store-minor .product .art { min-height: 22px; }
  .price { padding: 0.4em 0.9em; font-size: 0.85em; }
  .product .art .felt { min-height: 30px; border-width: 4px; }
  .crest { width: clamp(44px, 7vw, 70px); font-size: clamp(15px, 2.2vw, 24px); }
  .panel > header { padding: 7px 12px; }
  .panel > .body { padding: 9px 12px; }
}

/* Generated artwork remains separate from theme-colored panels and controls. */
.felt.illustrated {
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}
.felt.illustrated::before, .felt.illustrated::after { display: none; }
.felt.illustrated img { display: block; width: 100%; height: 100%; object-fit: contain; }
.hero .felt.illustrated { width: 80%; max-height: 60%; top: 5%; right: 5%; transform: rotate(-6deg); }
.hall .felt.illustrated { width: 100%; height: 100%; max-width: none; max-height: 240px; min-height: 0; align-self: center; }
/* Fill the art box and let the image contain itself inside it. Sizing from
 * height with a fixed aspect ratio overflowed sideways (and was clipped) as
 * soon as a card was taller than it was wide. */
.product .art .felt.illustrated { width: 100%; height: 100%; max-height: 120px; min-height: 0; }
.cue-art.illustrated i {
  width: 94%;
  height: auto;
  aspect-ratio: 1536 / 100;
  border-radius: 0;
  background-image: var(--cue-image);
  background-size: 100% 1024%;
  background-position: center var(--cue-y);
  background-repeat: no-repeat;
  box-shadow: none;
}
.cue-detail .cue-art.illustrated i, .product.featured .cue-art.illustrated i { transform: rotate(-5deg); }
.avatar.portrait {
  background-image: var(--avatar-image);
  background-size: 400% 200%;
  background-position: var(--avatar-x) var(--avatar-y);
  background-repeat: no-repeat;
  overflow: hidden;
}
@media (max-height: 460px) and (orientation: landscape) {
  .hero .felt.illustrated { width: 60%; max-height: 42%; top: 2%; }
  .store-minor .product { gap: 2px; padding: 5px; }
  .store-minor .product .art { min-height: 0; }
  .store-minor .product .art .felt.illustrated { max-height: none; }
}

/* --- first-run coach (src/lobby-coach.js) -----------------------------------
 * After the tutorial the coach walks the player to their first match: a card,
 * then a spotlight on the one control to press. Everything else is dimmed and
 * inert (the blocker swallows presses outside the lit control).
 */
.coach { position: fixed; inset: 0; z-index: 30; }
.coach [hidden] { display: none !important; }
.coach-block { position: absolute; inset: 0; cursor: default; }
.coach[data-mode="card"] .coach-block {
  background: color-mix(in srgb, var(--background) 62%, transparent);
  backdrop-filter: blur(3px);
}
/* The lit hole: a huge shadow darkens everything around it. */
.coach-spot {
  position: fixed;
  border-radius: 16px;
  box-shadow: 0 0 0 9999px color-mix(in srgb, var(--background) 80%, transparent);
  outline: 3px solid var(--accent-primary);
  outline-offset: 2px;
  pointer-events: none;
  animation: coachRing 1.3s ease-in-out infinite;
}
@keyframes coachRing {
  50% { outline-offset: 7px; outline-color: color-mix(in srgb, var(--accent-primary) 45%, transparent); }
}
.coach-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 26px 24px 22px;
  border-radius: var(--radius-lg);
  background: var(--panel-fill);
  box-shadow: var(--panel-lift), 0 0 0 1px var(--line);
  text-align: center;
}
.coach-card h2 { color: var(--accent-primary); font-size: 1.5em; }
.coach-card p { margin: 0 0 6px; }
.coach-say {
  position: fixed;
  width: min(340px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  border-radius: 14px;
  background: var(--panel-fill);
  box-shadow: var(--panel-lift), 0 0 0 1px var(--accent-line);
  pointer-events: none;
}
.coach-say p { margin: 0; font-weight: 600; font-size: 0.92em; }
.coach-face {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: var(--raised);
  box-shadow: 0 0 0 2px var(--accent-primary);
}
.coach-face.big { width: 72px; height: 72px; }
.coach-face img { width: 100%; height: 100%; display: block; object-fit: cover; }
.coach-hand svg { width: 100%; height: 100%; display: block; }
/* She stands left of the card, pointing at it, where there is room; the face
 * badge stands in for her on narrower screens. */
.coach-figure {
  position: absolute;
  right: calc(100% - 36px);
  bottom: -2px;
  height: min(440px, 62vh);
  width: auto;
  aspect-ratio: 2 / 3;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}
@media (min-width: 1000px) and (min-height: 560px) {
  .coach-card { padding-left: 40px; }
  .coach-card .coach-face.big { display: none; }
}
@media (max-width: 999px), (max-height: 559px) {
  .coach-figure { display: none; }
}
.coach-hand {
  position: fixed;
  width: 40px;
  height: 40px;
  margin: -2px 0 0 -14px;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
  animation: coachTap 1.2s ease-in-out infinite;
}
@keyframes coachTap {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-4px, -6px) scale(0.92); }
}
@media (prefers-reduced-motion: reduce) {
  .coach-spot, .coach-hand { animation: none; }
}
