.table {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
}
/* Solo and Ranked (Brief 18): the table is the window under the header (base.css), and the cards
   size themselves from both its width and its height (container units), times --fit, which
   TC.fitTable steps down if a split or a long hand would still overflow. A big monitor gets a
   bigger table; a short laptop window a compact one. */
.table:not(.bjo) {
  --fit: 1;
  --card-w: max(36px, calc(min(max(62px, 10.5cqw), 12.5cqh, 150px) * var(--fit)));
  --ring: max(64px, calc(clamp(72px, 16cqh, 140px) * var(--fit)));
  container: bj-table / size;
  justify-content: space-between;
  max-width: max(1100px, 150dvh);
  padding-top: clamp(8px, 2.4dvh, 18px);
  padding-bottom: calc(clamp(8px, 2dvh, 16px) + env(safe-area-inset-bottom));
}
.table.locked:not(.bjo) { justify-content: center; }

/* ---------- Trays ---------- */
.tray {
  position: absolute;
  top: 16px;
  width: calc(var(--card-w) * 0.78);
  height: calc(var(--card-w) * 0.78 * 1.4);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(244, 220, 149, 0.16);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35);
}
.discard { left: 16px; }
.discard span {
  position: absolute;
  inset: 8px;
  border-radius: 6px;
  border: 1px dashed rgba(244, 220, 149, 0.18);
}
.shoe { right: 16px; }
.shoe-card {
  position: absolute;
  inset: 6px 6px 16px;
  border-radius: 6px;
  border: 3px solid #fbfaf5;
  background: repeating-linear-gradient(45deg, var(--card-back-1) 0 4px, var(--card-back-2) 4px 8px);
  box-shadow: 2px 2px 0 #e9e4d6, 4px 4px 0 #d6d0bf, 6px 6px 8px rgba(0, 0, 0, 0.4);
}
.shoe-meter {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.shoe-meter i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--gold-3), var(--gold-2));
  transform-origin: left;
  transition: transform 0.4s var(--ease);
}

/* ---------- Zones ---------- */
.zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.dealer { min-height: calc(var(--card-w) * 1.4 + 44px); }
.zone-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.cards {
  display: flex;
  justify-content: center;
  min-height: calc(var(--card-w) * 1.4);
}
.cards .card + .card { margin-left: calc(var(--card-w) * -0.58); }
.dealer .cards .card + .card { margin-left: calc(var(--card-w) * -0.42); }

.score {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font: 700 0.85rem/1 var(--font-ui);
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.score.bust { background: rgba(160, 30, 30, 0.85); border-color: var(--lose); }
.score.twentyone { color: #2b1c04; background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-color: transparent; }

/* ---------- Felt print ---------- */
.felt-print {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: clamp(12px, 3vh, 28px) 0;
  text-align: center;
  pointer-events: none;
}
/* The curved line printed on the felt, below the rules text */
.felt-print::after {
  content: '';
  width: min(760px, 92vw);
  height: clamp(28px, 6vw, 56px);
  margin-top: -6px;
  border-bottom: 2px solid rgba(244, 220, 149, 0.16);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.print-main {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.05rem, 3.2vw, 1.6rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(244, 220, 149, 0.42);
}
.print-sub {
  font-size: clamp(0.68rem, 1.8vw, 0.8rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 220, 149, 0.28);
}

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  top: calc(18px + var(--card-w) * 1.4 + 40px);
  z-index: 10;
  translate: -50% 0;
  padding: 12px 26px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.1rem, 3.6vw, 1.6rem);
  /* One line when it fits; a long message (a first Ranked visit's welcome) wraps on a phone
     instead of making the page wider than the screen. */
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  text-wrap: balance;
  color: var(--ink);
  background: rgba(2, 14, 8, 0.82);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  opacity: 0;
  scale: 0.9;
  pointer-events: none;
  transition: opacity 0.25s, scale 0.3s var(--ease);
}
.toast.show { opacity: 1; scale: 1; }
.toast.win { color: var(--win); border-color: rgba(95, 211, 148, 0.5); }
.toast.lose { color: var(--lose); border-color: rgba(255, 114, 114, 0.4); }
.toast.gold { color: #2b1c04; background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-color: transparent; box-shadow: 0 10px 40px rgba(244, 220, 149, 0.35); }

/* ---------- Player hands ---------- */
.player { flex: 1; justify-content: center; }
.hands {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px clamp(16px, 4vw, 44px);
}
.hands[data-count='3'], .hands[data-count='4'] { --card-w: clamp(52px, 8vw, 88px); }
.hand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 10px;
  border-radius: 18px;
  border: 1px solid transparent;
  transition: background 0.3s, border-color 0.3s, opacity 0.3s, translate 0.3s var(--ease);
}
.hands.multi .hand { opacity: 0.6; }
.hands.multi .hand.active {
  opacity: 1;
  translate: 0 -6px;
  background: rgba(244, 220, 149, 0.06);
  border-color: rgba(244, 220, 149, 0.35);
  box-shadow: 0 0 30px rgba(244, 220, 149, 0.08);
}
.hands.multi.over .hand { opacity: 1; }
.hand-meta { display: flex; align-items: center; gap: 8px; }
.hand-bet {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--gold-2);
}
.hand-bet::before {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, #c0392b 0 45%, transparent 46%), repeating-conic-gradient(#c0392b 0 30deg, #fff 30deg 60deg);
}
.result {
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.result:not([hidden]) { animation: pop 0.4s var(--ease); }
/* The result's row is kept from the start (Brief 18b): a hand doesn't grow when the round pays
   out, so the table never shrinks then. */
.hand > .result[hidden] { display: block !important; visibility: hidden; }
.hand > .result[hidden]::before { content: '\00a0'; }
.result.win, .result.blackjack { color: #062414; background: var(--win); }
.result.blackjack { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #2b1c04; }
.result.lose { color: #fff; background: rgba(190, 40, 40, 0.9); }
.result.push { color: #2b1c04; background: var(--push); }
@keyframes pop { from { opacity: 0; scale: 0.6; } 60% { scale: 1.08; } }

/* ---------- Bet spot ---------- */
.bet-spot { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.bet-ring {
  position: relative;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  border: 2px solid rgba(244, 220, 149, 0.4);
  box-shadow: inset 0 0 0 6px rgba(244, 220, 149, 0.06), 0 0 30px rgba(0, 0, 0, 0.2);
}
.bet-ring::after {
  content: 'BET';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(244, 220, 149, 0.28);
  transition: opacity 0.2s;
}
.bet-ring.has-chips::after { opacity: 0; }
.bet-ring.has-chips { cursor: pointer; } /* a tap takes back the top chip */
.bet-stack { position: absolute; inset: 0; display: grid; place-items: center; }
.bet-stack .chip {
  position: absolute;
  width: 58px;
  height: 58px;
  font-size: 0.82rem;
  pointer-events: none;
  translate: 0 calc(var(--n) * -5px);
}
.bet-amount {
  min-height: 1.4em;
  font-weight: 700;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.bet-amount.placed { color: var(--gold-2); }

/* ---------- Controls ---------- */
.controls { width: 100%; padding-top: 18px; display: flex; flex-direction: column; gap: 14px; }
.group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: rise 0.3s var(--ease);
}
.buyin-btn { align-self: center; }

/* (.row, the Ranked lock panel, .sr-only and the stats grid are in base.css, shared with other games.) */
/* ---------- Ranked (server-dealt) ---------- */
.rank-pill { padding: 0 14px; color: var(--gold-2); text-decoration: none; }
.rank-pill:hover { border-color: rgba(217, 180, 90, 0.55); }
.broke-panel {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 20;
  translate: -50% -50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(360px, calc(100% - 32px));
  padding: 26px 22px;
  text-align: center;
  border-radius: 20px;
  background: rgba(3, 22, 13, 0.96);
  border: 1px solid rgba(217, 180, 90, 0.45);
  box-shadow: var(--shadow);
  animation: rise 0.3s var(--ease);
}
.broke-panel h2 { margin: 0; font-family: var(--font-display); font-size: 1.5rem; color: var(--gold-2); }
.broke-panel p { margin: 0; color: var(--ink-2); }
.broke-panel .btn-gold .coin { width: 20px; height: 20px; }
.card.blank .card-face { visibility: hidden; }
/* Ranked: the hole card lifts slightly while the dealer's turn is on its way from the server. */
.dealer .card { transition: translate 0.25s var(--ease); }
.dealer .card.lift { translate: 0 calc(var(--w) * -0.1); }
/* Ranked: an answer that's taking over 1.5s. A soft light sweeps slowly across the waiting card's back. */
.card.waiting .card-back { overflow: hidden; }
.card.waiting .card-back::before {
  content: '';
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: 0;
  width: 45%;
  background: linear-gradient(90deg, transparent, rgba(255, 243, 210, 0.24), transparent);
  transform: translateX(-130%) skewX(-16deg);
  animation: shimmer 2s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-130%) skewX(-16deg); }
  60%, 100% { transform: translateX(260%) skewX(-16deg); }
}
/* Reduced motion: a gentle pulse instead. (base.css cuts every animation short there, so this one
   has to outrank that rule.) */
@media (prefers-reduced-motion: reduce) {
  .card.waiting .card-back::before { content: none; }
  .card.waiting .card-back { animation: waiting-pulse 2s ease-in-out infinite !important; }
}
@keyframes waiting-pulse { 50% { opacity: 0.72; } }

.chip-rack { display: flex; gap: clamp(10px, 3vw, 18px); }
.actions .btn { min-width: 108px; min-height: 52px; font-size: 1rem; }
.btn.suggest {
  border-color: var(--gold-2);
  box-shadow: 0 0 0 3px rgba(244, 220, 149, 0.35), 0 0 26px rgba(244, 220, 149, 0.35);
  animation: suggest 0.9s ease-in-out 2;
}
@keyframes suggest { 50% { box-shadow: 0 0 0 6px rgba(244, 220, 149, 0.15), 0 0 34px rgba(244, 220, 149, 0.5); } }
.hint-btn { min-height: 36px; font-size: 0.85rem; }

/* ---------- Solo and Ranked fit the window (Brief 18) ---------- */
/* Every height on the table follows the box: the gaps, the print and its curve, the betting
   circle, the space round the controls. */
#table .zone { gap: clamp(4px, 1.6cqh, 12px); }
#table .dealer { min-height: calc(var(--card-w) * 1.4 + clamp(28px, 6cqh, 44px)); }
#table .felt-print { margin: clamp(2px, 1.8cqh, 28px) 0; gap: clamp(2px, 0.8cqh, 6px); }
#table .felt-print::after { height: clamp(10px, 5cqh, 56px); }
#table .print-main { font-size: clamp(0.9rem, min(3.2cqw, 3.6cqh), 1.6rem); }
#table .print-sub { font-size: 0.75rem; }
#table .hands { gap: clamp(4px, 1.4cqh, 14px) clamp(10px, 3cqw, 44px); }
#table .hands[data-count='3'], #table .hands[data-count='4'] { --card-w: max(36px, calc(min(max(52px, 8cqw), 10cqh, 110px) * var(--fit))); }
#table .hand { gap: clamp(4px, 1.2cqh, 10px); padding: clamp(4px, 1.2cqh, 12px) 10px clamp(4px, 1cqh, 10px); }
#table .bet-spot { gap: clamp(4px, 1.4cqh, 12px); }
#table .bet-ring { width: var(--ring); height: var(--ring); }
#table .bet-stack .chip { width: calc(var(--ring) * 0.5); height: calc(var(--ring) * 0.5); translate: 0 calc(var(--n) * -4px); }
#table .controls { padding-top: clamp(6px, 2cqh, 18px); gap: clamp(6px, 1.6cqh, 14px); }
#table .group { gap: clamp(6px, 1.6cqh, 14px); }
/* A short window (a laptop with its browser bars): the chips and the bet's buttons on one row, and
   the print loses its small line. */
@container bj-table (max-height: 620px) and (min-width: 700px) {
  #table .group[data-group='betting'] { flex-direction: row; justify-content: center; gap: 12px 28px; }
}
@container bj-table (max-height: 560px) {
  #table .print-sub { display: none; }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .topbar .brand { display: none; }
  .topbar-title { border-left: none; padding-left: 4px; font-size: 1.05rem; color: var(--ink); }
  .pill { padding-right: 12px; }
  .table { padding-top: 12px; }
  .tray { top: 12px; width: 40px; height: 56px; }
  .discard { left: 12px; }
  .shoe { right: 12px; }
  .toast { top: calc(12px + var(--card-w) * 1.4 + 36px); }
  .actions .btn { min-width: 0; flex: 1 1 0; padding: 0 6px; } /* (one row of four: the table keeps the height) */
  .actions { width: 100%; max-width: 420px; flex-wrap: nowrap; gap: 6px; }
  .chip { width: 56px; height: 56px; }
}
@media (max-width: 480px) {
  .topbar { padding-inline: 12px; gap: 6px; }
  .topbar-heading { flex-direction: column; align-items: flex-start; gap: 3px; }
  .topbar-title { font-size: 1rem; line-height: 1.1; padding-left: 0; }
  .mode-badge { padding: 2px 7px; font-size: 0.75rem; letter-spacing: 0.04em; }
  .topbar .btn-icon { width: 36px; height: 36px; min-height: 36px; }
  .pill { gap: 6px; height: 36px; padding: 0 10px 0 6px; font-size: 0.92rem; }
  .pill .coin { width: 20px; height: 20px; }
  .credits-pill .pill-label { display: none; }
  .rank-pill { padding: 0 9px; }
  /* Ranked fills the bar (credits, rank, info, account, sound): the credits pill sheds its icon so
     the title keeps its room, and the title itself can break as "Black-" / "jack" (a soft hyphen
     in the page) rather than run into the pill. */
  .credits-pill { padding: 0 10px; }
  .credits-pill .trophy { display: none; }
}
@media (max-width: 400px) {
  /* The narrowest phones: the balance pill drops its coin and Ranked drops the separate rank pill
     (the rank is one tap away in the account menu, and on the leaderboard). */
  .topbar .pill .coin { display: none; }
  .topbar .rank-pill { display: none; }
}

/* ---------- Phones on their side (Brief 18): the controls in a column at the right ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .table:not(.bjo) {
    --side: 196px;
    --card-w: max(36px, calc(min(max(56px, 10cqw), 22cqh, 110px) * var(--fit)));
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--side);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "dealer side" "player side";
    justify-content: stretch;
    align-items: center;
    column-gap: 10px;
    max-width: none;
    padding-top: 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }
  .table.locked:not(.bjo) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "lock" "lock"; }
  #table .lock-panel { grid-area: lock; justify-self: center; padding: 18px; gap: 12px; }
  #table > .dealer { grid-area: dealer; }
  #table > .felt-print { display: none; }
  #table > .player { grid-area: player; align-self: stretch; }
  #table > .controls { grid-area: side; align-self: center; padding-top: 0; }
  #table .hands[data-count='3'], #table .hands[data-count='4'] { --card-w: max(36px, calc(min(max(48px, 7cqw), 17cqh, 90px) * var(--fit))); }
  /* The trays side by side at the top left, clear of the controls. */
  #table .tray { top: 6px; width: 36px; height: 50px; }
  #table .discard { left: max(12px, env(safe-area-inset-left)); }
  #table .shoe { right: auto; left: calc(max(12px, env(safe-area-inset-left)) + 44px); }
  /* The round's result over the side column, above the buttons (never over the cards). */
  #table .toast { left: auto; right: 12px; top: 6px; translate: none; width: var(--side); max-width: var(--side); padding: 8px 12px; font-size: 1.05rem; }
  #table .controls { padding-top: 52px; }
  #table .broke-panel { left: calc((100% - var(--side)) / 2); top: 50%; padding: 16px; gap: 10px; }
  /* The chips two by two, the buttons under them. */
  #table .group[data-group='betting'] { flex-direction: column; gap: 8px; } /* (not the short-laptop row) */
  #table .chip-rack { display: grid; grid-template-columns: repeat(2, 48px); gap: 8px 12px; }
  #table .chip { width: 48px; height: 48px; font-size: 0.85rem; }
  #table .group .row { flex-wrap: nowrap; gap: 8px; }
  #table .group .row .btn { min-height: 44px; padding: 0 14px; }
  #table .btn-lg { min-height: 44px; font-size: 0.95rem; }
  #table .actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  #table .actions .btn { min-width: 0; min-height: 44px; padding: 0 6px; }
  #table .hint-btn { min-height: 34px; }
  #table .group[data-group='settled'] .row { flex-direction: column; align-items: stretch; }
}
