/* ============================================================================
   MEXICAN TRAIN DOMINOES — Design tokens + first-fold game shell
   Vanilla CSS, zero dependencies. Structure:
   1. DESIGN TOKENS (color/spacing/type/radius/size) — contrast-checked for
      WCAG 2.2 AA (white-text fills sit on >=4.5:1 backgrounds).
   2. Base + header
   3. FIRST-FOLD GAME SHELL — height locked to the viewport, CSS Grid rows,
      overflow hidden, no internal scrolling; [data-fit] tiers shrink pieces
      until the whole game fits any aspect ratio.
   4. HUD toolbar / board / dominoes / hand / overlays
   5. SEO content below the fold (content-visibility for cheap off-screen paint)
   ========================================================================== */

/* ---------- 1. DESIGN TOKENS ---------- */
:root {
  /* color — text/fill pairs verified >=4.5:1 (AA normal text) */
  --bg: #eef2f6;            /* page background (light) */
  --bg-card: #ffffff;
  --ink: #1c2733;           /* body text on --bg: 13.2:1 */
  --ink-soft: #51606f;      /* secondary text on --bg-card: 5.6:1 */
  --line: #d7dee6;
  --accent: #2B567F;
  --felt-1: #2B567F;        /* table felt (game surfaces always dark) */
  --felt-2: #1d3f61;
  --felt-line: rgba(255, 255, 255, 0.14);
  --tile-face: #f8f4e9;
  --tile-edge: #d9d2bd;
  --tile-ink: #232c38;      /* pips on tile face: 11.9:1 */
  --tile-back: #c8d4e0;
  --good: #177c4e;          /* fill under white text: 5.2:1 */
  --good-glow: #2ecc83;     /* glows on dark felt only */
  --warn: #d97706;          /* accent on dark felt */
  --warn-strong: #9a5200;   /* fill under white text: 5.9:1 */
  --bad: #b23434;           /* error text on --bg-card: 5.4:1 */
  --gold: #f2c14e;
  --on-gold: #4a3800;       /* text on --gold: 6.7:1 */
  --shadow: 0 1px 2px rgba(10, 20, 30, 0.18), 0 4px 14px rgba(10, 20, 30, 0.12);

  /* spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;

  /* type scale */
  --fs-xs: 0.68rem; --fs-sm: 0.8rem; --fs-md: 0.92rem; --fs-lg: 1.1rem;

  /* shape */
  --radius: 12px; --radius-sm: 9px;

  /* game piece sizes — retuned by media queries and fit tiers */
  --tile-h: 46px;
  --train-h: 30px;
  --shell-gap: 8px;
  --header-h: 48px;
}
html[data-theme="dark"] {
  --bg: #0d141c;
  --bg-card: #16202b;
  --ink: #e8eef4;           /* 14.8:1 on --bg */
  --ink-soft: #9db0c0;      /* 8.1:1 on --bg-card */
  --line: #2a3946;
  --accent: #4f83b8;
  --felt-1: #23486e;
  --felt-2: #142f4c;
  --tile-face: #efe9d8;
  --tile-edge: #c9c1a8;
  --tile-ink: #1d2630;
  --tile-back: #7d93a9;
}

/* ---------- 2. base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--accent); }
img { max-width: 100%; }
button { font: inherit; cursor: pointer; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 0; z-index: 99; }
.skip-link:focus { left: 0; }

/* slim header: inside the first fold, scrolls away with the page */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: var(--header-h);
  padding: 6px clamp(10px, 3vw, 22px);
  background: var(--felt-1);
  color: #fff;
  box-shadow: 0 2px 10px rgba(8, 18, 30, 0.35);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand-domino {
  flex: 0 0 auto; width: 22px; height: 36px; border-radius: 5px;
  background: var(--tile-face); border: 1px solid var(--tile-edge);
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
}
.brand-domino i { flex: 1; position: relative; }
.brand-domino i:first-child::after { content: ""; position: absolute; inset: 25%; border-radius: 50%; background: var(--tile-ink); }
.brand-domino i:last-child::before, .brand-domino i:last-child::after {
  content: ""; position: absolute; width: 22%; height: 22%; border-radius: 50%; background: var(--tile-ink);
}
.brand-domino i:last-child::before { top: 14%; left: 14%; }
.brand-domino i:last-child::after { bottom: 14%; right: 14%; }
.brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 1.05rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

/* ============================================================================
   3. FIRST-FOLD GAME SHELL
   - Exactly viewport height minus header; overflow hidden — the page never
     scrolls while playing (the SEO article starts below the fold).
   - touch-action: none kills double-tap zoom inside the game; taps stay
     instant. overscroll-behavior: none stops pull-to-refresh.
   - CSS Grid rows: HUD / hub / opponents (flexible) / your train / hand.
   - [data-fit] tiers progressively shrink pieces until everything fits.
   ========================================================================== */
.game-shell {
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h)); /* dynamic viewport: mobile URL-bar aware */
  max-width: 1200px; margin: 0 auto; padding: 8px clamp(8px, 2.5vw, 18px) 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: var(--shell-gap);
  background: radial-gradient(120% 90% at 50% 0%, var(--felt-1), var(--felt-2) 88%);
  border-radius: 0 0 var(--radius) var(--radius);
  color: #fff;
  overflow: hidden;                 /* zero scroll inside the game */
  overscroll-behavior: none;
  touch-action: none;               /* no pan/zoom gestures on the felt */
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  contain: layout paint;            /* isolate layout+paint: cheaper frames */
}
.board { display: contents; }       /* children participate in the shell grid */

/* fit tiers — JS steps through these until the fold holds everything */
.game-shell[data-fit="compact"] { --train-h: 26px; --tile-h: 44px; --shell-gap: 6px; }
.game-shell[data-fit="small"]   { --train-h: 23px; --tile-h: 40px; --shell-gap: 5px; }
.game-shell[data-fit="tiny"]    { --train-h: 20px; --tile-h: 36px; --shell-gap: 4px; }
.game-shell[data-fit="micro"]   { --train-h: 18px; --tile-h: 32px; --shell-gap: 3px; }
.game-shell[data-fit="nano"]    { --train-h: 15px; --tile-h: 28px; --shell-gap: 2px; }
/* compact paddings once we're squeezing */
.game-shell[data-fit="tiny"] .hand-zone, .game-shell[data-fit="micro"] .hand-zone, .game-shell[data-fit="nano"] .hand-zone {
  padding: 4px 8px 6px;
}
.game-shell[data-fit="tiny"] .hand, .game-shell[data-fit="micro"] .hand, .game-shell[data-fit="nano"] .hand {
  padding: 6px 2px 3px; gap: 6px;
}
.game-shell[data-fit="tiny"] .hand-heading, .game-shell[data-fit="micro"] .hand-heading, .game-shell[data-fit="nano"] .hand-heading { margin-bottom: 2px; }
.game-shell[data-fit="tiny"] .hint-bar, .game-shell[data-fit="micro"] .hint-bar, .game-shell[data-fit="nano"] .hint-bar { min-height: 13px; font-size: var(--fs-xs); }
.game-shell[data-fit="tiny"] .opp-row, .game-shell[data-fit="micro"] .opp-row, .game-shell[data-fit="nano"] .opp-row {
  padding: 4px 8px; gap: 2px 10px;
}
.game-shell[data-fit="tiny"] .opp-meta, .game-shell[data-fit="micro"] .opp-meta, .game-shell[data-fit="nano"] .opp-meta {
  flex-direction: row; align-items: center; gap: 6px; flex-wrap: wrap;
}
.game-shell[data-fit="micro"] .train-strip, .game-shell[data-fit="nano"] .train-strip { padding: 3px 6px; min-height: calc(var(--train-h) + 12px); }
.game-shell[data-fit="nano"] .opp-row { padding: 3px 8px; gap: 2px 10px; }
.game-shell[data-fit="nano"] .opp-chip { padding: 1px 6px; }
.game-shell[data-fit="nano"] .my-train-zone { padding: 3px 8px; gap: 2px; }

/* ---------- HUD toolbar ---------- */
.game-topbar { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.game-status { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; align-items: center; }
.pill {
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--felt-line); color: #eaf1f8;
  border-radius: 999px; padding: 3px 11px; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
.best-pill { color: var(--gold); border-color: rgba(242, 193, 78, 0.4); }
.turn-pill.on-turn { background: var(--good); border-color: var(--good); color: #fff; }
.turn-pill.ai-turn { background: rgba(0, 0, 0, 0.35); border-color: var(--felt-line); color: #fff; }
.game-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.mini-btn {
  min-height: 32px; min-width: 32px; padding: 4px 9px;
  border: 1px solid var(--felt-line); background: rgba(255, 255, 255, 0.1); color: #fff;
  border-radius: 9px; font-size: 0.9rem; font-weight: 600; line-height: 1.2;
  transition: transform 0.1s, background 0.15s;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.18); }
.mini-btn:active { transform: scale(0.94); }
.mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* every control >=44x44 on touch devices (WCAG 2.5.8 target size) */
@media (pointer: coarse) {
  .mini-btn { min-width: 44px; min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .end-btn { width: 44px; height: 44px; }
  .primary-btn, .ghost-btn { min-height: 44px; }
}

/* ---------- hub row: engine + boneyard + Mexican train ---------- */
.hub-row { display: flex; gap: 10px; align-items: stretch; min-width: 0; }
.engine-hub {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--felt-line);
}
.hub-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 1px; opacity: 0.75; }
.boneyard {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, 0.05); border: 1.5px dashed rgba(255, 255, 255, 0.3);
  border-radius: 10px; padding: 8px 12px; color: #fff; cursor: default;
  transition: border-color 0.2s, transform 0.12s;
}
.boneyard.can-draw { cursor: pointer; border-color: var(--gold); }
.boneyard.can-draw:hover { transform: translateY(-2px); }
.boneyard.can-draw .by-stack { animation: byfloat 1.6s ease-in-out infinite; }
@keyframes byfloat { 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .boneyard.can-draw .by-stack { animation: none; } }
.by-stack { position: relative; width: 30px; height: 42px; }
.by-stack i {
  position: absolute; inset: 0; border-radius: 4px;
  background: linear-gradient(160deg, #dbe6f1, var(--tile-back)); border: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.by-stack i:nth-child(1) { transform: rotate(-7deg) translate(-3px, 2px); }
.by-stack i:nth-child(2) { transform: rotate(5deg) translate(3px, -1px); }
.by-stack i:nth-child(3) { transform: rotate(-1deg); }
.by-info { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.by-info b { font-size: 0.98rem; font-variant-numeric: tabular-nums; }
.by-info small { font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.9px; opacity: 0.7; }
.mexican-train-zone { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.train-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.train-name { font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.train-tag {
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.public-tag { background: rgba(255, 255, 255, 0.14); color: #dce8f4; }
.open-tag { background: var(--warn-strong); color: #fff; }
.pending-tag { background: var(--gold); color: var(--on-gold); }

/* serpentine train strips (wrap, never scroll) */
.train-strip {
  position: relative; display: block; min-width: 0; overflow: hidden;
  background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm); padding: 6px 8px; min-height: calc(var(--train-h) + 20px);
}
.train-rows { display: flex; flex-direction: column; gap: 4px; }
.train-row { display: flex; align-items: center; gap: 3px; min-width: 0; }
.train-row.rev { flex-direction: row-reverse; } /* packs right, continuing from the row above */
.train-empty-note { font-size: var(--fs-sm); opacity: 0.65; font-style: italic; padding: 0 4px 0 0; white-space: nowrap; }
.end-btn {
  flex: 0 0 auto; align-self: center; margin: 0 2px;
  width: 36px; height: 36px; border-radius: 50%; border: 2px dashed rgba(255, 255, 255, 0.5);
  background: rgba(30, 158, 99, 0.12); color: #fff; font-weight: 800; font-size: 0.95rem;
  visibility: hidden;
}
.end-btn.on { visibility: visible; }
.end-btn.on.show { animation: pulse 1.1s ease-in-out infinite; }
.end-btn.cover-slot { border-color: var(--gold); background: rgba(242, 193, 78, 0.3); font-size: 0.72rem; letter-spacing: -0.2px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 133, 0.55); }
  55% { box-shadow: 0 0 0 9px rgba(46, 204, 133, 0); }
}
@media (prefers-reduced-motion: reduce) { .end-btn.show { animation: none; } }

/* ---------- player bands (opponents + yours) ---------- */
.opponent-rows { display: grid; grid-template-columns: 1fr; gap: 8px; align-content: safe center; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.opponent-rows::-webkit-scrollbar { display: none; }
.opp-row {
  display: grid; grid-template-columns: 178px minmax(0, 1fr); gap: 6px 14px; align-items: center;
  background: rgba(255, 255, 255, 0.055); border: 1px solid var(--felt-line);
  border-left: 3px solid var(--pc, #9db0c0);
  border-radius: 10px; padding: 8px 10px 8px 9px;
  transition: box-shadow 0.2s, border-color 0.2s, background 0.2s;
}
.opp-row.active-turn {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--pc, #9db0c0);
  box-shadow: 0 0 0 1px var(--pc, #9db0c0) inset, 0 0 18px -6px var(--pc, #9db0c0);
}
.opp-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.opp-name { font-size: 0.95rem; font-weight: 800; display: flex; align-items: center; gap: 7px; min-width: 0; }
.opp-name .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 6px var(--pc, transparent); }
.opp-sub { display: flex; gap: 5px; flex-wrap: wrap; }
.opp-chip { font-size: var(--fs-xs); font-weight: 700; background: rgba(0, 0, 0, 0.3); border-radius: 999px; padding: 1.5px 8px; white-space: nowrap; }
.opp-chip.score { background: rgba(255, 255, 255, 0.16); }
.opp-row .train-strip { min-height: calc(var(--train-h) * 0.82 + 16px); }

.my-train-zone {
  display: grid; gap: 4px;
  background: rgba(255, 255, 255, 0.055); border: 1px solid var(--felt-line);
  border-left: 3px solid var(--pc, #4fb677);
  border-radius: 10px; padding: 8px 10px;
  transition: box-shadow 0.2s, border-color 0.2s, background 0.2s;
}
.my-train-zone.active-turn {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--pc, #4fb677);
  box-shadow: 0 0 0 1px var(--pc, #4fb677) inset, 0 0 18px -6px var(--pc, #4fb677);
}
.my-strip { min-height: calc(var(--train-h) + 22px); }

/* ---------- dominoes ---------- */
.domino {
  --h: var(--train-h);
  position: relative; flex: 0 0 auto;
  width: calc(var(--h) * 0.52 + var(--h)); height: var(--h);
  background: linear-gradient(160deg, #fffdf6, var(--tile-face) 55%);
  border: 1px solid var(--tile-edge); border-radius: 5px;
  display: grid; grid-template-columns: 1fr 1fr;
  box-shadow: 0 1px 2px rgba(8, 15, 25, 0.4);
  overflow: hidden; touch-action: manipulation;
}
.domino::after {
  content: ""; position: absolute; top: 8%; bottom: 8%; left: 50%; width: 1px;
  background: rgba(35, 44, 56, 0.45);
}
.domino .half { position: relative; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 9%; }
.domino .pip {
  width: 66%; height: 66%; place-self: center; border-radius: 50%; background: var(--tile-ink);
  box-shadow: inset 0 1.5px 2px rgba(0, 0, 0, 0.4);
}
.domino .num {
  grid-area: 1 / 1 / -1 / -1; place-self: center;
  width: 88%; height: 88%; display: grid; place-items: center;
  font-weight: 800; color: var(--tile-ink); font-size: calc(var(--h) * 0.36); line-height: 1;
  background: rgba(35, 44, 56, 0.07); border-radius: 50%;
}
.domino.vert { width: var(--h); height: calc(var(--h) * 1.52); grid-template-columns: none; grid-template-rows: 1fr 1fr; }
.domino.vert::after { left: 8%; right: 8%; top: 50%; bottom: auto; width: auto; height: 1px; }
.domino.vert .half { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.domino.back { background: linear-gradient(160deg, #dbe6f1, var(--tile-back)); }
.domino.back .half { visibility: hidden; }
.domino.big { --h: var(--tile-h); }
.domino.dim { opacity: 0.45; }
.domino.playable { cursor: pointer; outline: 2px solid transparent; }
.domino.playable::before {
  content: ""; position: absolute; inset: -1px; border-radius: 5px;
  box-shadow: 0 0 0 2.5px var(--good-glow), 0 5px 16px rgba(46, 204, 131, 0.9), 0 0 24px rgba(46, 204, 131, 0.55);
  pointer-events: none;
}
.domino.selected::before {
  content: ""; position: absolute; inset: -1px; border-radius: 5px;
  box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(242, 193, 78, 0.8); pointer-events: none;
}
.domino.hinted::before {
  content: ""; position: absolute; inset: -1px; border-radius: 5px;
  box-shadow: 0 0 0 3px #7ec8ff, 0 0 14px rgba(126, 200, 255, 0.9); pointer-events: none;
  animation: hintblink 0.6s ease-in-out 3;
}
@keyframes hintblink { 50% { opacity: 0.15; } }
.domino.just-placed { animation: drop 0.24s ease-out; }
@keyframes drop { from { transform: scale(1.28); opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .domino.just-placed { animation: none; } }

.train-row .domino.dbl-perp {
  width: calc(var(--train-h) * 0.62); height: calc(var(--train-h) * 0.94);
  grid-template-columns: 1fr; grid-template-rows: 1fr 1fr;
  border-radius: 4px; margin: 0 2px;
}
.train-row .domino.dbl-perp::after { left: 10%; right: 10%; top: 50%; width: auto; height: 1px; }
.train-row .domino.dbl-perp .half .num { font-size: calc(var(--train-h) * 0.26); }
.train-row .domino.dbl-perp.unsatisfied {
  box-shadow: 0 0 0 2px var(--gold), 0 0 8px rgba(242, 193, 78, 0.8);
}

/* ---------- hand ---------- */
.hand-zone {
  background: var(--bg-card); border: 1px solid var(--line);
  border-top: 3px solid var(--pc, var(--line));
  border-radius: var(--radius); padding: 8px 10px 10px; box-shadow: var(--shadow);
  color: var(--ink);
}
.hand-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.hand-heading > span { font-weight: 700; font-size: var(--fs-md); }
.primary-btn {
  border: none; background: var(--good); color: #fff; font-weight: 700;
  border-radius: 10px; padding: 9px 16px; font-size: var(--fs-md);
  box-shadow: 0 2px 8px rgba(23, 124, 78, 0.4);
}
.primary-btn.warn { background: var(--warn-strong); box-shadow: 0 2px 8px rgba(154, 82, 0, 0.4); }
.primary-btn[hidden] { display: none; }
.primary-btn:active { transform: scale(0.97); }
.ghost-btn {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  border-radius: 10px; padding: 9px 14px; font-weight: 600;
}
.hand {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 8px; padding: 10px 4px 6px;
}
.hand .domino { border-radius: 7px; transition: transform 0.16s ease; }
.hand .domino.playable { transform: translateY(-9px); }
.hand .domino.playable:not(.selected)::before { border-radius: 7px; }
.hand .domino.playable:hover, .hand .domino.playable:focus-visible { transform: translateY(-12px); }
@media (prefers-reduced-motion: reduce) { .hand .domino { transition: none; } .hand .domino.playable { transform: none; } }
.hint-bar { min-height: 18px; font-size: var(--fs-sm); color: var(--ink-soft); padding: 2px 4px 0; }
.hint-bar.bad-pips { color: var(--bad); font-weight: 600; }

/* ---------- landscape / short screens: two-column fold ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --tile-h: 42px; --train-h: 26px; --header-h: 44px; }
  .game-shell {
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top  top"
      "hub  side"
      "mine side"
      "hand hand";
  }
  .game-topbar { grid-area: top; }
  .hub-row { grid-area: hub; flex-direction: column; gap: 6px; }
  .engine-hub { flex-direction: row; align-items: center; gap: 12px; padding: 4px 10px; }
  .boneyard { flex-direction: row; justify-content: center; gap: 12px; padding: 4px 12px; }
  .by-stack { width: 22px; height: 30px; }
  .mexican-train-zone { width: 100%; }
  .opponent-rows { grid-area: side; align-content: start; }
  .my-train-zone { grid-area: mine; }
  .hand-zone { grid-area: hand; }
  /* narrow side column: stack meta above the train so strips keep full width */
  .opp-row { grid-template-columns: 1fr; }
}

/* ---------- overlays & dialogs (lightweight layers over the felt) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 14, 22, 0.62); padding: 16px; backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.dialog {
  width: 100%; max-width: 480px; max-height: min(86dvh, 640px); overflow-y: auto;
  background: var(--bg-card); color: var(--ink); border-radius: 16px;
  padding: 18px 18px 16px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.dialog .dialog-title { margin: 0 0 10px; font-size: 1.25rem; font-weight: 700; line-height: 1.25; }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dialog-actions .primary-btn { flex: 1 1 auto; }
.pause-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pause-stats { margin: 0 0 12px; color: var(--ink-soft); font-size: var(--fs-sm); }
.help-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.help-list strong { color: var(--accent); }
.help-more { font-size: var(--fs-sm); color: var(--ink-soft); margin-bottom: 0; }

.score-table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.score-table th, .score-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.score-table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); }
.score-table td.num, .score-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.score-table tr.winner td { background: rgba(30, 158, 99, 0.12); font-weight: 700; }
.score-table .you-row td:first-child::after { content: " (you)"; opacity: 0.7; font-weight: 400; font-size: 0.8em; }
.end-stats { margin-top: 10px; font-size: var(--fs-sm); color: var(--ink-soft); }

.field { display: block; margin: 0 0 12px; font-weight: 600; font-size: var(--fs-md); }
.field select {
  display: block; width: 100%; margin-top: 5px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
}
.field-note { font-weight: 400; color: var(--ink-soft); font-size: var(--fs-sm); }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: var(--fs-md); margin: 4px 0 6px; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--good); }

.toasts {
  position: fixed; top: calc(var(--header-h) + 8px); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 50; width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: rgba(20, 30, 42, 0.94); color: #fff; border-radius: 10px;
  padding: 9px 14px; font-size: var(--fs-sm); font-weight: 600; text-align: center;
  box-shadow: var(--shadow); animation: toastin 0.22s ease-out;
}
.toast.good { background: rgba(21, 122, 79, 0.96); }
.toast.warn { background: rgba(154, 82, 0, 0.96); }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- SEO content (below the fold; paint cost ~0 while playing) ---------- */
.content-grid {
  max-width: 1080px; margin: 26px auto 0; padding: 0 clamp(10px, 3vw, 22px) 40px;
  display: grid; grid-template-columns: 1fr; gap: 26px;
  content-visibility: auto; contain-intrinsic-size: auto 3200px;
}
.content-main h1 { font-size: clamp(1.55rem, 4.5vw, 2.3rem); line-height: 1.2; margin: 10px 0 14px; }
.content-main h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); margin: 28px 0 10px; }
.content-main h3 { font-size: clamp(1.05rem, 2.6vw, 1.25rem); margin: 24px 0 8px; }
.content-main p, .content-main li { color: var(--ink); font-size: 0.98rem; }
.content-main ul, .content-main ol { padding-left: 22px; }
.content-main li { margin: 5px 0; }
.content-meta { color: var(--ink-soft); font-size: 0.84rem; margin: -4px 0 18px; }
.quick-facts {
  background: var(--bg-card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; margin: 18px 0; font-size: 0.93rem;
}
.faq details { background: var(--bg-card); border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px; margin: 8px 0; }
.faq summary { cursor: pointer; font-weight: 700; padding: 8px 0; }
.faq details[open] summary { color: var(--accent); }
.content-side { display: grid; gap: 14px; align-content: start; }
.side-card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.side-card h2 { margin: 0 0 10px; font-size: 1.02rem; }
.feature-list, .link-list, .ref-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; font-size: 0.92rem; }
.link-list a { text-decoration: none; font-weight: 600; }
.link-list a:hover { text-decoration: underline; }
.ref-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.ref-list dt { font-weight: 700; color: var(--ink-soft); }
.ref-list dd { margin: 0; }
.site-footer { max-width: 1080px; margin: 0 auto; padding: 0 20px 46px; color: var(--ink-soft); font-size: 0.88rem; }
.site-footer a { color: var(--accent); }
.footnote { color: var(--ink-soft); }

/* ---------- responsive piece sizes ---------- */
@media (min-width: 640px) {
  :root { --tile-h: 54px; --train-h: 34px; }
}
@media (max-width: 639px) {
  .opp-row { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .hub-row { flex-direction: column; }
  .engine-hub { flex-direction: row; align-items: center; gap: 12px; padding: 6px 12px; }
  .mexican-train-zone { width: 100%; }
  .boneyard { flex-direction: row; justify-content: center; gap: 12px; padding: 6px 14px; }
}
@media (max-width: 420px) {
  :root { --tile-h: 42px; --train-h: 27px; }
  .brand-name { font-size: 0.9rem; }
}
@media (display-mode: standalone) {
  .site-header { padding-top: max(6px, env(safe-area-inset-top)); }
  .game-shell { height: calc(100vh - var(--header-h) - env(safe-area-inset-top)); height: calc(100dvh - var(--header-h) - env(safe-area-inset-top)); }
}
:focus-visible { outline: 3px solid #7ec8ff; outline-offset: 2px; border-radius: 6px; }
.opp-chip.open-chip { background: var(--warn-strong); color: #fff; }
