:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-elevated: #243044;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3d9cf0;
  --accent-dim: #2a6fad;
  --gold: #f0c14b;
  --gold-dim: #b8922e;
  --danger: #e85d5d;
  --success: #3ecf8e;
  --warning: #f0a030;
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --app-max: 520px;
  /* Tools row + Canasta action row (wraps) */
  --play-actions-h: 10.5rem;
  --comms-bg: #1e3a56;
  --comms-bg-elevated: #2a4d6e;
  --comms-bg-deep: #173049;
  --comms-border: rgba(120, 185, 240, 0.32);
  --comms-shadow: 0 10px 36px rgba(20, 60, 100, 0.45), 0 0 0 1px rgba(100, 175, 235, 0.12);
  --card-w: 3.55rem;
  --card-h: 5rem;
}

/* ——— Canasta board ——— */
.center-piles {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;
  padding: 0.5rem 0;
}

.pile {
  min-width: 5.5rem;
  min-height: 6.5rem;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem;
  color: var(--text);
}

.pile:disabled {
  opacity: 0.55;
}

.pile-back {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.pile-count {
  font-size: 0.75rem;
  color: var(--muted);
}

.discard-top-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 4.5rem;
}

.freeze-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(232, 93, 93, 0.25);
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.freeze-badge.hidden {
  display: none;
}

.melds-area {
  margin-bottom: 0.75rem;
}

.melds-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
}

.melds-side-label {
  width: 100%;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.meld-pile {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.35rem 0.45rem;
  max-width: 100%;
  color: inherit;
}

.meld-pile.selected {
  outline: 2px solid var(--accent);
}

.meld-pile.canasta-pure {
  border-color: rgba(240, 193, 75, 0.55);
  box-shadow: 0 0 0 1px rgba(240, 193, 75, 0.25);
}

.meld-pile.canasta-mixed {
  border-color: rgba(180, 180, 200, 0.45);
}

.meld-rank {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  margin-right: 0.25rem;
  text-transform: uppercase;
}

.card-face {
  width: var(--card-w);
  height: var(--card-h);
  background: #f7f4ec;
  color: #1a1a1a;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0.25rem 0.3rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.card-face.is-red {
  color: #c62828;
}

.card-face.selected {
  outline: 2px solid var(--accent);
  transform: translateY(-4px);
}

.card-face.card-face-sm {
  width: 2.2rem;
  height: 3.1rem;
  padding: 0.15rem;
  font-size: 0.7rem;
}

.card-face.card-wild {
  background: linear-gradient(145deg, #fff8e1, #ffe0b2);
}

.card-face.card-red-three {
  background: #ffcdd2;
}

.card-face.card-black-three {
  background: #cfd8dc;
}

.card-rank {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.1;
}

.scores-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.score-chip {
  background: var(--bg-card);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.opponents {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.opponent-chip {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.opponent-chip.is-turn {
  border-color: var(--accent);
}

.opp-name {
  font-weight: 700;
}

.opp-meta {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.turn-banner.is-you {
  color: var(--gold);
  font-weight: 700;
}

.play-actions-canasta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.play-actions-canasta .btn-primary,
.play-actions-canasta .btn-secondary,
.play-actions-canasta .btn-ghost-sm {
  width: auto;
  flex: 1 1 auto;
  min-width: 4.5rem;
  padding: 0.55rem 0.65rem;
  font-size: 0.8rem;
}

.deal-end-summary {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.deal-end-row {
  padding: 0.65rem 0.75rem;
  background: var(--bg-elevated);
  border-radius: 10px;
  font-size: 0.9rem;
}

.hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 156, 240, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(240, 193, 75, 0.08), transparent),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  width: 100%;
  box-shadow: 0 4px 16px rgba(61, 156, 240, 0.35);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-ghost-sm,
.btn-sm,
.btn-copy-link,
.btn-copy-icon,
.btn-danger-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  width: auto;
}

.btn-danger-sm {
  background: rgba(232, 93, 93, 0.2);
  color: var(--danger);
  border: 1px solid rgba(232, 93, 93, 0.4);
}

.app {
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  min-height: 100vh;
}

/* Match games.jonheaton.com: title + volume centered in the header */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.25rem 0 0.5rem;
  margin-bottom: 0.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 55%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand .sound-control {
  margin: 0.5rem auto 0;
  justify-self: center;
}

.brand .conn-status {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.conn-status.is-live {
  color: var(--success);
}

.conn-status.is-down {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.hint,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field input,
.field select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg);
  color: var(--text);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0.5rem 0;
}

.home-history-link,
.home-footer-links {
  text-align: center;
  margin-top: 1.25rem;
  line-height: 1.5;
}

.home-history-link a,
.home-footer-links a {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.home-footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.home-footer-sep {
  color: var(--muted);
  opacity: 0.55;
  margin: 0 0.35rem;
  user-select: none;
}

/* ---------- Static help pages (rules / how-to-play) ---------- */
.doc-page {
  padding-bottom: 3rem;
}

.doc-back {
  display: inline-block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.doc-back:hover {
  color: var(--text);
  text-decoration: underline;
}

.doc-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 0.85rem;
  margin: 0.25rem 0 1rem;
  font-size: 0.88rem;
}

.doc-nav a {
  color: var(--muted);
  text-decoration: none;
}

.doc-nav a:hover {
  color: var(--text);
  text-decoration: underline;
}

.doc-nav a[aria-current='page'] {
  color: var(--gold);
  font-weight: 600;
}

.doc-article h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.doc-article h3 {
  margin: 1.35rem 0 0.45rem;
  font-size: 1.05rem;
  color: var(--gold);
  font-weight: 700;
}

.doc-article h4 {
  margin: 0 0 0.4rem;
  font-size: 0.98rem;
  color: var(--text);
}

.doc-article p,
.doc-article li,
.doc-article dd {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
}

.doc-article ul,
.doc-article ol {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.25rem;
}

.doc-article li {
  margin-bottom: 0.35rem;
}

.doc-article a {
  color: var(--accent);
}

.doc-lead {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 0 0 0.75rem;
}

.doc-dl {
  margin: 0.5rem 0 0.85rem;
}

.doc-dl dt {
  font-weight: 700;
  margin-top: 0.55rem;
  color: var(--text);
}

.doc-dl dd {
  margin: 0.2rem 0 0.35rem 0;
  color: var(--muted);
  line-height: 1.5;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 1rem;
  font-size: 0.92rem;
}

.doc-table th,
.doc-table td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.doc-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doc-table td:last-child {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--gold);
  font-weight: 600;
}

.doc-callout {
  margin: 0.75rem 0 1rem;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  background: rgba(61, 156, 240, 0.08);
  border: 1px solid rgba(61, 156, 240, 0.28);
}

.doc-callout p:last-child {
  margin-bottom: 0;
}

.doc-example {
  margin: 0.5rem 0 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.doc-example p {
  margin: 0.35rem 0;
  color: var(--muted);
}

.doc-example p:first-child {
  margin-top: 0;
}

.doc-example p:last-child {
  margin-bottom: 0;
}

.doc-example strong {
  color: var(--text);
}

.doc-footer-links {
  margin: 1.5rem 0 0.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.doc-footer-links a {
  font-weight: 600;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.color-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.color-swatch.is-selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.color-swatch.is-taken {
  opacity: 0.35;
  cursor: not-allowed;
}

.public-games-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.public-games-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.public-games-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.public-games-list li:last-child {
  border-bottom: none;
}

.visibility-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.radio-label,
.checkbox-label {
  display: flex;
  flex-direction: row;
  gap: 0.55rem;
  align-items: flex-start;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

/*
 * .field label { display: block } and .field input { width: 100% } would otherwise
 * stack checkbox/radio above the description and stretch the control full-width.
 */
.field label.checkbox-label,
.field label.radio-label {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  margin-bottom: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.35;
  cursor: pointer;
}

.field label.checkbox-label input[type='checkbox'],
.field label.radio-label input[type='radio'],
.field .checkbox-label input[type='checkbox'],
.field .radio-label input[type='radio'] {
  width: auto;
  min-width: 1.1rem;
  height: auto;
  margin: 0.2rem 0 0;
  padding: 0;
  flex: 0 0 auto;
  align-self: flex-start;
  accent-color: var(--accent);
  border: none;
  background: transparent;
  box-shadow: none;
}

.field label.checkbox-label > span,
.field label.radio-label > span {
  flex: 1 1 auto;
  min-width: 0;
}

.room-code-box {
  text-align: center;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(240, 193, 75, 0.25);
}

.room-code-box .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.room-code-box .code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin: 0.25rem 0;
}

.invite-link-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
}

.invite-link {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
  max-width: 70%;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.avatar-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--muted);
  margin-left: auto;
}

.badge.ready {
  background: rgba(62, 207, 142, 0.2);
  color: var(--success);
}

.badge.host {
  background: rgba(240, 193, 75, 0.2);
  color: var(--gold);
}

.lobby-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.lobby-btn-row .btn-primary,
.lobby-btn-row .btn-secondary {
  width: 100%;
}

.game-start-banner,
.vote-kick-banner,
.spectator-banner {
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.game-start-banner {
  background: rgba(61, 156, 240, 0.2);
  border: 1px solid rgba(61, 156, 240, 0.4);
}

.vote-kick-banner {
  background: rgba(240, 160, 48, 0.15);
  border: 1px solid rgba(240, 160, 48, 0.4);
}

.spectator-banner {
  background: rgba(139, 155, 180, 0.15);
  border: 1px solid rgba(139, 155, 180, 0.3);
}

/* Play */
#screen-play {
  padding-bottom: calc(var(--play-actions-h) + 2rem);
}

/* Fixed play action dock (Bank pattern: tools + primary row) */
.play-actions {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--app-max);
  z-index: 320;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  background: linear-gradient(
    to top,
    var(--bg) 0%,
    var(--bg) 78%,
    rgba(15, 20, 25, 0.92) 92%,
    transparent 100%
  );
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.play-actions-secondary {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 0 1 auto;
  min-height: 0;
}

.play-actions-tools {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.4rem;
  width: 100%;
}

.play-actions-tools .play-tool-btn {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  margin-top: 0;
  padding: 0.45rem 0.4rem;
  font-size: 0.82rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
}

.play-actions-tools .play-tool-btn .chat-unread {
  min-width: 1.1rem;
  height: 1.1rem;
  font-size: 0.65rem;
}

.play-actions-row {
  display: flex;
  flex-direction: row;
  gap: 0.4rem;
  width: 100%;
  flex: 0 0 auto;
}

.play-actions-row .btn-primary,
.play-actions-row .btn-secondary,
.play-actions-row .btn-ghost-sm {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 0.75rem 0.35rem;
  font-size: 0.88rem;
}

.play-actions .is-ghost,
.play-actions .hidden {
  display: none !important;
  visibility: hidden;
  pointer-events: none;
}

/* Play chrome: deal left, room code right (sound lives under brand title) */
.top-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
  color: var(--muted);
  gap: 0.4rem 0.5rem;
}

#play-deal {
  justify-self: start;
  min-width: 0;
}

.top-bar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  justify-self: end;
  min-width: 0;
}

.turn-banner {
  text-align: center;
  font-weight: 700;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 10px;
  background: var(--bg-elevated);
}

.turn-banner.is-you {
  background: rgba(62, 207, 142, 0.18);
  color: var(--success);
}

.last-action {
  display: block;
  width: 100%;
  text-align: center;
  margin: 0 0 0.65rem;
  min-height: 1.2em;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: default;
}

.last-action.is-peekable {
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.last-action.is-peekable:hover {
  border-color: rgba(61, 156, 240, 0.4);
  background: rgba(61, 156, 240, 0.1);
  color: var(--accent);
}

.last-action:disabled {
  opacity: 1;
  cursor: default;
}

.scores-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.score-chip {
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.score-chip.is-turn {
  border-color: var(--success);
}

.opponents {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.opponent-seat {
  flex: 1;
  min-width: 5rem;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.opponent-seat.is-turn {
  border-color: var(--success);
}

.table-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.hand-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.hand-sweeps {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: none;
  white-space: nowrap;
}

.table-cards,
.hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: var(--card-h);
  align-items: flex-start;
}

.playing-card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 9px;
  background: #f7f4ef;
  color: #121212;
  border: 2px solid transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
  font-weight: 800;
  font-size: 1.25rem;
  cursor: pointer;
  user-select: none;
  position: relative;
  padding: 0.2rem 0.1rem 0.25rem;
  line-height: 1;
}

.playing-card.red {
  color: #c62828;
}

.playing-card.black {
  color: #0a0a0a;
}

/* Black suits share the same high-contrast black (green club tint hurt legibility) */
.playing-card.suit-C:not(.red) .suit,
.playing-card.suit-S:not(.red) .suit {
  color: #0a0a0a;
}

.playing-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(61, 156, 240, 0.45);
  transform: translateY(-4px);
}

.playing-card.special::after {
  content: "★";
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.65rem;
  color: var(--gold-dim);
}

.playing-card .rank {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.playing-card .rank.rank-10 {
  font-size: 1.15rem;
  letter-spacing: -0.06em;
}

.playing-card .suit {
  font-size: 1.7rem;
  line-height: 1;
  font-weight: 700;
  margin-top: 0.02rem;
}

.build-card {
  width: auto;
  min-width: calc(var(--card-w) * 1.35);
  height: var(--card-h);
  border-radius: 8px;
  background: linear-gradient(145deg, #2a3d55, #1a2838);
  border: 2px solid var(--gold);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0.25rem;
}

.build-card.selected {
  box-shadow: 0 0 0 2px var(--accent);
}

.build-card .build-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gold);
}

.card-back {
  width: 1.4rem;
  height: 2rem;
  border-radius: 4px;
  background: linear-gradient(135deg, #2a5a8c, #1a3a5c);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: inline-block;
  margin: 0 1px;
  vertical-align: top;
}

.opponent-backs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  min-height: 2rem;
  margin: 0.2rem 0;
}

/* Deal-out animation: cards fly in staggered from above the pile */
@keyframes deal-fly-in {
  0% {
    opacity: 0;
    transform: translateY(-2.75rem) scale(0.45) rotate(-12deg);
  }
  55% {
    opacity: 1;
    transform: translateY(0.12rem) scale(1.06) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

/* Hand refill: slightly longer arc so mid-round deals are obvious */
@keyframes deal-fly-in-hand {
  0% {
    opacity: 0;
    transform: translateY(-3.25rem) scale(0.4) rotate(-14deg);
  }
  50% {
    opacity: 1;
    transform: translateY(0.18rem) scale(1.08) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

.playing-card.deal-in,
.build-card.deal-in,
.card-back.deal-in {
  /* Disable button transform transition so it does not fight keyframes */
  transition: none;
  animation: deal-fly-in 0.45s cubic-bezier(0.22, 1.15, 0.36, 1) both;
  animation-delay: calc(var(--deal-i, 0) * 75ms);
}

.playing-card.deal-in.deal-in-hand {
  animation-name: deal-fly-in-hand;
  animation-duration: 0.52s;
  animation-delay: calc(var(--deal-i, 0) * 90ms);
}

.hand-area.is-dealing {
  box-shadow: 0 0 0 1px rgba(240, 193, 75, 0.35), 0 0 20px rgba(240, 193, 75, 0.12);
  border-color: rgba(240, 193, 75, 0.4);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .playing-card.deal-in,
  .playing-card.deal-in.deal-in-hand,
  .build-card.deal-in,
  .card-back.deal-in {
    animation: none;
  }
}

.hand-area {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 2px solid transparent;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.hand-area.is-turn {
  border-color: var(--success);
  box-shadow: 0 0 0 1px rgba(62, 207, 142, 0.35), 0 0 18px rgba(62, 207, 142, 0.12);
}

.standings {
  margin: 0;
  padding-left: 1.25rem;
}

.standings li {
  margin: 0.4rem 0;
}

/*
 * Toast — must not set both top and bottom (that stretches the box full-screen).
 * Platform-shell uses .show / .error; keep width content-sized.
 */
.toast {
  position: fixed;
  left: 50%;
  right: auto;
  top: auto;
  bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(120%);
  width: max-content;
  max-width: min(90vw, 22rem);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0.7rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
  z-index: 400;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

.toast.error,
.toast.is-error {
  border-color: rgba(232, 93, 93, 0.5);
  background: #3a1f24;
}

/* Chat/voice panel styles: see /css/comms.css (Bank communications UI) */

/* Build value chooser (tap targets, no keyboard) */
.build-modal-card {
  width: min(22rem, 100%);
}

.build-value-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.85rem 0 0.75rem;
}

.build-value-options:has(> :only-child) {
  grid-template-columns: 1fr;
}

.build-value-btn {
  width: 100%;
  margin: 0;
  padding: 0.95rem 0.75rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.build-modal-empty {
  margin: 0.75rem 0;
  text-align: center;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: min(20rem, 100%);
  box-shadow: var(--shadow);
}

.modal-card h3 {
  margin: 0 0 0.5rem;
}

.modal-card input[type="number"],
.modal-card input[type="text"] {
  width: 100%;
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg);
  color: var(--text);
}

/* Capture preview overlay */
.capture-preview {
  pointer-events: none;
  z-index: 70;
}

.capture-preview.is-peek {
  pointer-events: auto;
}

.capture-preview-close {
  width: 100%;
  margin-top: 0.85rem;
}

/* Last hand of the deal — "CARDS!" */
.cards-exclaim {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(ellipse 55% 40% at 50% 45%, rgba(240, 193, 75, 0.22), transparent 70%);
}

.cards-exclaim.hidden {
  display: none;
}

.cards-exclaim-burst {
  font-size: clamp(2.75rem, 12vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow:
    0 0 24px rgba(240, 193, 75, 0.65),
    0 4px 0 rgba(0, 0, 0, 0.35),
    0 8px 28px rgba(0, 0, 0, 0.45);
  transform: scale(0.6);
  opacity: 0;
}

.cards-exclaim-burst.is-anim {
  animation: cards-exclaim-pop 2.6s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

@keyframes cards-exclaim-pop {
  0% {
    opacity: 0;
    transform: scale(0.45) rotate(-6deg);
  }
  12% {
    opacity: 1;
    transform: scale(1.18) rotate(2deg);
  }
  28% {
    transform: scale(0.96) rotate(-1deg);
  }
  40% {
    transform: scale(1.05) rotate(0deg);
  }
  75% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.08) translateY(-0.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cards-exclaim-burst.is-anim {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

.capture-preview-card {
  width: min(22rem, 100%);
  text-align: center;
  border: 1px solid rgba(62, 207, 142, 0.35);
  animation: capture-pop 0.25s ease-out;
}

@keyframes capture-pop {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.capture-preview-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin: 0.85rem 0 0.5rem;
  min-height: var(--card-h);
}

.capture-preview-cards .playing-card {
  cursor: default;
  pointer-events: none;
}

.capture-preview-cards .playing-card.is-played {
  box-shadow: 0 0 0 2px var(--gold), 0 4px 12px rgba(240, 193, 75, 0.35);
}

.capture-preview-points {
  margin-top: 0.35rem;
  font-size: 0.9rem;
}

.capture-preview-points .points-total {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.capture-preview-points .points-line {
  color: var(--muted);
  font-size: 0.82rem;
}

.capture-preview-points .points-none {
  color: var(--muted);
  font-size: 0.85rem;
}

/* End-of-deal score tally */
.deal-summary {
  z-index: 75;
  align-items: flex-start;
  overflow-y: auto;
  padding: 1rem 1rem 2rem;
}

.deal-summary-card {
  width: min(26rem, 100%);
  margin: auto;
}

.deal-summary-players {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.85rem 0 1rem;
}

.deal-player-card {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  text-align: left;
}

.deal-player-card.is-you {
  border-color: rgba(61, 156, 240, 0.45);
}

.deal-player-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.deal-player-name {
  font-weight: 700;
}

.deal-player-pts {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--gold);
  white-space: nowrap;
}

.deal-player-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.deal-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.deal-stat-grid.deal-stat-grid-split {
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.85rem;
  align-items: start;
}

.deal-stat-col {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.deal-stat {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  color: var(--muted);
  padding: 0.15rem 0;
}

.deal-stat .stat-label {
  min-width: 0;
}

.deal-stat .stat-val {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.deal-stat.deal-stat-round {
  margin-top: 0.2rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
}

.deal-stat.deal-stat-round .stat-val {
  color: var(--gold);
  font-weight: 800;
}

.deal-stat.is-highlight {
  background: rgba(240, 193, 75, 0.12);
  border: 1px solid rgba(240, 193, 75, 0.35);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  color: var(--gold);
  font-weight: 700;
}

.deal-stat.is-highlight .stat-val {
  color: var(--gold);
  font-weight: 800;
}

.deal-stat.is-highlight.little {
  background: rgba(125, 207, 255, 0.1);
  border-color: rgba(125, 207, 255, 0.35);
  color: #9ad4ff;
}

.deal-stat.is-highlight.little .stat-val {
  color: #c5e8ff;
}

.deal-stat.is-winner .stat-val {
  color: var(--success);
}

.deal-stat.is-empty {
  opacity: 0.5;
}

.deal-stat.is-empty .stat-val {
  color: var(--muted);
  font-weight: 500;
}

.deal-summary-ready-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  justify-content: center;
}

.deal-ready-chip {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg);
  color: var(--muted);
}

.deal-ready-chip.is-ready {
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--success);
  background: rgba(62, 207, 142, 0.12);
}

.deal-summary-wait {
  text-align: center;
  margin: 0.55rem 0 0;
}
