:root {
  --felt: #0b6b3a;
  --felt-dark: #064022;
  --gold: #f5c542;
  --gold-light: #ffe39a;
  --gold-deep: #c9952a;
  --red: #d33;
  --black: #1a1a1a;
  --bg: #0a1f14;
  --bg-deep: #030f08;
  --panel: #143a26;
  --text: #f4efe0;
  --muted: #9fb4a3;
  --teamA: #3a7bd5;
  --teamB: #d55b3a;
  --wood: #3a1f10;       /* casino table rail */
  --wood-light: #5a3520;
  --spot: rgba(255,240,200,.06);   /* warm spotlight tint */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  /* Monte Carlo floor: layered — warm spotlight pool over deep emerald, with a
     faint diamond/damask pattern so the field isn't dead-flat. */
  background:
    radial-gradient(ellipse 60% 50% at 50% 25%, var(--spot), transparent 70%),
    repeating-linear-gradient(45deg, rgba(245,197,66,.018) 0 2px, transparent 2px 24px),
    repeating-linear-gradient(-45deg, rgba(245,197,66,.018) 0 2px, transparent 2px 24px),
    radial-gradient(ellipse at center, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
/* Vignette to focus attention center-screen. */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1;
  box-shadow: inset 0 0 220px 40px rgba(0,0,0,.6);
}

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }

.card-panel {
  position: relative;
  background: linear-gradient(180deg, #18502f 0%, var(--panel) 100%);
  border: 2px solid var(--gold);
  border-radius: 18px;
  padding: 40px 48px;
  text-align: center;
  max-width: 92vw;
  /* Soft warm glow halo + inner gold hairline (double-border effect). */
  box-shadow:
    0 0 0 1px rgba(245,197,66,.35),
    0 0 40px rgba(245,197,66,.12),
    0 20px 60px rgba(0,0,0,.55),
    inset 0 0 0 1px rgba(245,197,66,.18);
  z-index: 2;
}
/* Art-deco corner ornaments — small gold L-flourishes in each corner. */
.card-panel::before,
.card-panel::after {
  content: ""; position: absolute; width: 16px; height: 16px; pointer-events: none;
  border: 2px solid var(--gold);
}
.card-panel::before {
  top: 8px; left: 8px;
  border-right: none; border-bottom: none;
  border-top-left-radius: 8px;
}
.card-panel::after {
  bottom: 8px; right: 8px;
  border-left: none; border-top: none;
  border-bottom-right-radius: 8px;
}
.card-panel h1 {
  font-size: clamp(28px, 5vw, 44px); margin-bottom: 8px; letter-spacing: 1.5px;
  /* Gold gradient fill with a warm amber glow. */
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, var(--gold-deep));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 22px rgba(245,197,66,.35);
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.4));
}
/* The red "5v5" span keeps its solid red via its own color (gradient clip is on h1). */
.card-panel h1 .red {
  color: var(--red); -webkit-text-fill-color: var(--red);
  text-shadow: 0 0 14px rgba(221,51,51,.45);
}
.card-panel h2 { margin-bottom: 14px; }
.red { color: var(--red); }
.tag { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.card-panel input {
  display: block; width: 240px; max-width: 80vw; margin: 0 auto 16px;
  padding: 12px 14px; border-radius: 10px; border: 1px solid #2c5a40;
  background: #0a2417; color: var(--text); font-size: 16px; text-align: center;
}
.card-panel button, #rematch-btn {
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 48%, var(--gold-deep) 100%);
  color: #2a1c00; border: none; padding: 12px 28px; border-radius: 10px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  /* Top gleam (inset highlight) + depth shadow. */
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 4px 0 #9c7917, 0 6px 14px rgba(0,0,0,.35);
  transition: transform .05s; margin-top: 4px;
}
.card-panel button:active, #rematch-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 2px 0 #9c7917; }
.hint { color: var(--muted); margin-top: 18px; font-size: 13px; }
.hint.tiny { font-size: 11px; margin-top: 6px; }

/* Account auth (Phase 1) */
.auth-welcome { color: var(--gold); font-size: 13px; margin: 4px 0 0; }
.auth-welcome a { color: var(--muted); text-decoration: underline; }
.auth-guest-actions { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); text-align: center; }
.auth-guest-actions .link-btn { display: inline; margin: 0; }
.auth-sep { color: var(--muted); margin: 0 6px; }
#auth-screen .card-panel { max-width: 360px; }
#auth-screen h2 { color: var(--gold); margin-bottom: 12px; text-align: center; }
#auth-screen input { margin-top: 8px; }
#auth-submit-btn { width: 100%; margin-top: 14px; }
.auth-msg { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }
#auth-mode-toggle { text-align: center; margin-top: 14px; }
#auth-mode-toggle a { color: var(--gold); text-decoration: underline; cursor: pointer; }

/* In-match control cluster (Leave + help). Pinned to the top-RIGHT corner
   (position: fixed) to match the original placement, but sized to the same
   44px height as the score panels so they align vertically.
   Color signals intent — gold = help, red = destructive Leave. */
.hud-controls {
  /* top = #game-screen padding (8px) + #hud padding-top (8px) = 16px, so the
     buttons' top edge matches the score panels' top edge and they align. */
  position: fixed; top: 16px; right: 12px; z-index: 60;
  display: flex; align-items: center; gap: 8px;
}
.hud-btn {
  height: 54px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 700; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(245,197,66,.45);
  background: rgba(0,0,0,.45); color: var(--gold);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  transition: background .15s, transform .05s, color .15s;
}
.hud-btn:hover { background: rgba(245,197,66,.2); }
.hud-btn:active { transform: translateY(1px); }
/* "?" help: square to match its single glyph. Width = height (54px). */
.hud-btn.help { width: 54px; padding: 0; font-size: 18px; }
/* Leave: red accent for destructive intent, restyled to match the pill family. */
.hud-btn.leave { background: rgba(80,12,12,.55); color: #ffd6d6; border-color: var(--red); }
.hud-btn.leave:hover { background: var(--red); color: #fff; }

/* Menu buttons */
.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.menu-buttons button, .card-panel .primary, #join-code-btn {
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 48%, var(--gold-deep) 100%);
  color: #2a1c00; border: none; padding: 12px 28px; border-radius: 10px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 4px 0 #9c7917, 0 6px 14px rgba(0,0,0,.35);
  transition: transform .05s;
}
.menu-buttons button:not(.primary), #join-code-btn {
  background: linear-gradient(180deg, #46a069, #2a6b42);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 4px 0 #1e4d2f, 0 6px 12px rgba(0,0,0,.3);
}
.menu-buttons button:active, .card-panel .primary:active, #join-code-btn:active { transform: translateY(2px); }
.join-code-row { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.code-input { width: 90px !important; margin: 0 !important; text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 700; }
#join-code-btn { padding: 12px 20px; }

/* Lobby */
.lobby-panel { min-width: 360px; }
.room-code { color: var(--gold); letter-spacing: 2px; }
.lobby-seats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 16px 0; }
.lobby-seat {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px;
  background: rgba(0,0,0,.25); font-size: 14px;
}
.lobby-seat.team-a { border-left: 3px solid var(--teamA); }
.lobby-seat.team-b { border-left: 3px solid var(--teamB); }
.lobby-seat.empty { opacity: .4; font-style: italic; }
.lobby-seat .ls-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.lobby-seat.team-a .ls-dot { background: var(--teamA); }
.lobby-seat.team-b .ls-dot { background: var(--teamB); }
.lobby-actions { margin: 10px 0; min-height: 30px; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; margin-top: 8px; text-decoration: underline; }

/* ---------- Game screen ---------- */
#game-screen { flex-direction: column; justify-content: space-between; padding: 8px; }

#hud {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 1100px; padding: 8px 16px; gap: 12px;
  position: relative; /* anchors the .game-leave-btn */
}
/* Score panels are stacked columns: the Tens row on top, a "Tricks won" line below.
   min-height keeps both Team panels (and thus the HUD row) a consistent height. */
.score { display: flex; flex-direction: column; gap: 2px; padding: 6px 14px; min-height: 54px; border-radius: 16px; background: rgba(0,0,0,.25); flex-shrink: 0; }
.score-main { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.tricks-line { font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: .3px; }
.tricks-line b { font-size: 13px; color: var(--gold); }
.score.team-a { border-left: 4px solid var(--teamA); align-items: flex-start; }
.score.team-b { border-right: 4px solid var(--teamB); align-items: flex-end; }
.score b { font-size: 26px; color: var(--gold); }
.of { color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.a { background: var(--teamA); } .dot.b { background: var(--teamB); }

/* Captured-10s chip tracker — a compact 4-row grid (one per suit) of 6 chips
   each (6 copies of the 10 per suit in the mega deck = 24 total). Each chip is
   colored by the team that captured that copy; empty = uncaptured. Sits in a
   centered strip just under the HUD score bar. */
.tens-tracker {
  display: flex; flex-direction: column; gap: 3px;
  margin: 2px auto 0; padding: 6px 12px; width: fit-content;
  max-width: 460px; background: rgba(0,0,0,.28); border-radius: 12px;
  border: 1px solid rgba(245,197,66,.18);
}
.tens-row { display: flex; align-items: center; gap: 6px; }
.tens-suit-label { font-size: 15px; font-weight: 700; width: 16px; text-align: center; }
.tens-chips { display: flex; gap: 3px; }
.tens-chip {
  width: 16px; height: 16px; border-radius: 4px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.05);
}
.tens-chip.a { background: var(--teamA); border-color: rgba(255,255,255,.4); }
.tens-chip.b { background: var(--teamB); border-color: rgba(255,255,255,.4); }
.tens-chip.empty { background: transparent; border-style: dashed; border-color: rgba(255,255,255,.12); }
.center-info {
  display: flex; flex-direction: row; align-items: stretch; justify-content: center;
  gap: 10px; text-align: center; color: var(--muted); min-height: 54px;
}
/* Each stat is a small glass chip. All three share an EQUAL width (flex: 1 1 0
   + min-width) so they stay identical regardless of their content/length.
   align-items:center keeps the text vertically centered within the chip. */
.center-info > div {
  flex: 1 1 0; min-width: 120px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(245,197,66,.25);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 15px;
  line-height: 1.1;
  white-space: nowrap;
}
.trump-info b { color: var(--gold); font-size: 22px; }
.info-line b { font-size: 20px; }

#table-wrap { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
#table {
  position: relative;
  width: min(92vw, 720px);
  height: min(58vh, 460px);
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border-radius: 50%;
  /* Use padding + a wrapper-style ring via box-shadow OUTSIDE the circle so the
     mahogany rail + gold trim follow the curve (border-image would render square). */
  box-shadow:
    inset 0 0 70px rgba(0,0,0,.45),          /* felt vignette */
    inset 0 0 0 3px rgba(245,197,66,.55),     /* gold trim ring (inside the rim) */
    0 0 0 6px var(--wood),                    /* mahogany rail */
    0 0 0 8px var(--wood-light),              /* rail highlight */
    0 14px 40px rgba(0,0,0,.6);               /* drop shadow */
  z-index: 2;
}
/* Faint center monogram (decorative spade), sits behind played cards/kitty. */
#table::before {
  content: "♠";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 140px; color: rgba(255,255,255,.04);
  pointer-events: none; z-index: 0;
}
/* The played-cards + kitty sit at z-index ≥ 1 so they render above the emblem. */
#table > #center { z-index: 1; }

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 96px; text-align: center;
}
.seat .avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: #fff;
  border: 3px solid transparent;
  background: #2a2a2a;
  position: relative; /* anchors the .voice-ind badge */
}
.seat.team-a .avatar { border-color: var(--teamA); }
.seat.team-b .avatar { border-color: var(--teamB); }
.seat.me .avatar { background: var(--gold); color: #2a1c00; }
/* Active seat: a subtle gold glow (the countdown ring is the primary indicator). */
.seat.active .avatar { box-shadow: 0 0 0 3px var(--gold), 0 0 12px rgba(245,197,66,.5); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--gold), 0 0 22px var(--gold); } }

/* Turn-timer ring (drawn around the active seat's avatar). The progress fill
   animates via stroke-dashoffset (updated each second in JS); the warning state
   flashes red in the final 5 seconds, matching the server's turnWarning. */
.timer-ring {
  position: absolute; top: 50%; left: 50%;
  width: 56px; height: 56px; margin: -28px 0 0 -28px;
  transform: rotate(-90deg);      /* start the arc at 12 o'clock */
  pointer-events: none;
  z-index: 3;
}
.timer-ring-track { fill: none; stroke: rgba(0,0,0,.35); stroke-width: 3; }
.timer-ring-fill {
  fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke .2s;
}
.timer-ring.warn .timer-ring-fill { stroke: var(--red); animation: ring-flash 0.5s ease-in-out infinite alternate; }
@keyframes ring-flash { to { opacity: 0.4; } }
.seat .name { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.seat .meta { font-size: 11px; color: var(--muted); }

/* ---------- Lead-selection ceremony (spec §2.4) ---------- */
/* Face-up mini card under each avatar during the pre-game draw.
   Hidden by default (pre-flip); .reveal-N triggers a one-at-a-time flip-in. */
.lead-card {
  width: 38px; height: 52px; border-radius: 5px; background: #fff; color: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; font-weight: 800; border: 2px solid #bbb; margin: 4px 0;
  box-shadow: 0 3px 8px rgba(0,0,0,.5);
  opacity: 0;                 /* hidden until its reveal delay fires */
  transform: rotateY(90deg);  /* face-down "back" before flipping */
}
.lead-card.red { color: var(--red); }
.lead-card .lc-rank { font-size: 17px; line-height: 1; }
.lead-card .lc-suit { font-size: 18px; line-height: 1; }
/* Sequential one-at-a-time reveal: each .reveal-N card flips in after N*1300ms.
   The slow stagger lets players actually read each card before the next flips.
   A full 10-card round takes ~13s, giving the ceremony real drama. */
.lead-card.reveal-0, .lead-card.reveal-1, .lead-card.reveal-2, .lead-card.reveal-3,
.lead-card.reveal-4, .lead-card.reveal-5, .lead-card.reveal-6, .lead-card.reveal-7,
.lead-card.reveal-8, .lead-card.reveal-9 {
  animation: leadCardFlip .6s ease-out forwards;
}
.lead-card.reveal-0 { animation-delay: 0ms; }
.lead-card.reveal-1 { animation-delay: 1300ms; }
.lead-card.reveal-2 { animation-delay: 2600ms; }
.lead-card.reveal-3 { animation-delay: 3900ms; }
.lead-card.reveal-4 { animation-delay: 5200ms; }
.lead-card.reveal-5 { animation-delay: 6500ms; }
.lead-card.reveal-6 { animation-delay: 7800ms; }
.lead-card.reveal-7 { animation-delay: 9100ms; }
.lead-card.reveal-8 { animation-delay: 10400ms; }
.lead-card.reveal-9 { animation-delay: 11700ms; }
@keyframes leadCardFlip {
  from { opacity: 0; transform: rotateY(90deg) scale(.9); }
  to   { opacity: 1; transform: rotateY(0) scale(1); }
}
/* Eliminated in a shootout round: keep the old card visible but dimmed. */
.lead-card.out { opacity: .35; transform: none; }
/* Ceremony decided (winner announced): card is just visible, no re-flip on
   re-render. Prevents the whole table re-animating when the winner highlight lands. */
.lead-card.settled { opacity: 1; transform: none; }
/* Winner of the ceremony: gold border + glow + celebratory pop. */
.lead-card.winner { opacity: 1; transform: none; border-color: var(--gold); box-shadow: 0 0 14px var(--gold), 0 3px 8px rgba(0,0,0,.5); animation: leadCardWin .5s ease-out; }
@keyframes leadCardWin { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* Center banner narrating the ceremony (round, ties, winner). */
.lead-banner {
  position: absolute; top: 62%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.7); color: var(--gold); padding: 8px 18px; border-radius: 999px;
  border: 1px solid rgba(245,197,66,.4); font-size: 13px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap; z-index: 4; text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.lead-banner.hidden { display: none; }

/* "thinking" indicator — three gold dots that ripple in sequence (chat-style
   typing bubble). Replaces the old italic "thinking…" text. */
.thinking-dots { display: inline-flex; gap: 4px; align-items: center; justify-content: center; padding: 2px 0; }
.thinking-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--gold);
  opacity: .35;
  animation: dotPulse 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dotPulse {
  0%, 80%, 100% { opacity: .35; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1.15); }
}

/* center */
#center {
  position: absolute; inset: 0; pointer-events: none;
}
#played-cards {
  position: absolute; top: 50%; left: 50%; width: 0; height: 0;
}
#kitty-display {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 2;
}

.table-card {
  position: absolute;
  width: 52px; height: 74px; border-radius: 7px; background: #fff; color: #000;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  font-weight: 800; border: 3px solid #bbb;
  box-shadow: 0 6px 14px rgba(0,0,0,.55);
  left: -26px; top: -37px;
  opacity: 0;
  animation: cardFade .2s ease-out forwards;
}
.table-card.red { color: var(--red); }
.table-card.trump { border-color: #b06; box-shadow: 0 0 14px rgba(200,0,90,.6), 0 6px 14px rgba(0,0,0,.5); }
/* The winning card must always render above overlapping played cards. */
.table-card.winning { border-color: var(--gold); box-shadow: 0 0 16px var(--gold), 0 6px 14px rgba(0,0,0,.5); z-index: 5; }
.table-card .tc-rank { font-size: 22px; line-height: 1; }
.table-card .tc-suit { font-size: 24px; }
.tc-badge {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: 8px; font-weight: 800; letter-spacing: .5px; padding: 1px 4px; border-radius: 3px;
  color: #fff; white-space: nowrap;
}
.trump-badge { bottom: -12px; background: #b06; }
.win-badge { top: -12px; background: var(--gold); color: #2a1c00; }

@keyframes cardFade { from { opacity: 0; } to { opacity: 1; } }

/* Kitty card (face-down, flips on reveal) */
#kitty-display { display: flex; flex-direction: column; align-items: center; gap: 3px; }
#kitty-display.hidden { display: none; }
.kitty-label { font-size: 10px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; font-weight: 700; }
.kitty-count { font-size: 10px; color: var(--muted); }
.kitty-card {
  width: 40px; height: 56px; position: relative; transform-style: preserve-3d;
  transition: transform .5s ease;
}
.kitty-card.revealed { transform: rotateY(180deg); }
.kitty-face {
  position: absolute; inset: 0; border-radius: 5px; backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  box-shadow: 0 3px 8px rgba(0,0,0,.5);
}
.kitty-back {
  background: repeating-linear-gradient(45deg, #5b2a8a, #5b2a8a 4px, #4a1f73 4px, #4a1f73 8px);
  border: 2px solid var(--gold); color: var(--gold); font-size: 18px;
}
.kitty-front {
  background: #fff; color: #000; transform: rotateY(180deg); font-size: 15px;
  border: 2px solid #999; flex-direction: column;
}
.kitty-front.red { color: var(--red); }
.kitty-front.is-ten { border-color: var(--gold); box-shadow: 0 0 10px var(--gold), 0 3px 8px rgba(0,0,0,.5); }

/* ---------- Hand ---------- */
#hand-wrap { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 4px; }
#hand-label { font-size: 12px; color: var(--muted); transition: color .15s; }
#hand {
  display: flex; justify-content: center; flex-wrap: nowrap; overflow-x: auto;
  /* padding-top gives the hover-lift (-24px) headroom so a lifted card isn't
     clipped by the scroll container's vertical overflow (overflow-x:auto also
     constrains overflow-y to auto). 26px = lift + a hair of breathing room. */
  padding: 26px 4px 8px; max-width: 100vw; gap: 0;
}
.card {
  width: 66px; height: 92px; border-radius: 7px;
  background: #fff; color: var(--black);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 6px 7px; font-weight: 700; cursor: pointer;
  border: 2px solid #ccc; flex-shrink: 0; margin-left: -26px;
  box-shadow: 0 3px 6px rgba(0,0,0,.4); transition: transform .12s, margin .12s, box-shadow .12s;
  position: relative;
}
.card:first-child { margin-left: 0; }
/* New suit group -> extra left gap so the hand clusters into 4 piles. */
.card.suit-break { margin-left: 8px; }
.card.red { color: var(--red); }
/* Every card is hover-inspectable (lifts up to read), regardless of turn.
   This lets a waiting player plan without being able to play out of turn. */
.card:hover { transform: translateY(-24px); z-index: 10; }
/* .disabled = not playable this turn (illegal, or waiting). Stays readable —
   only slightly dimmed (was .4, now .75) so you can still inspect/plan. The
   cursor reflects intent: a legal-but-blocked card still invites inspection. */
.card.disabled { opacity: .75; }
/* .playable = your turn AND legal. Gold border + glow = "you may click me". */
.card.playable { border-color: var(--gold); box-shadow: 0 3px 6px rgba(0,0,0,.4), 0 0 10px rgba(245,197,66,.35); }
.card.playable:hover { box-shadow: 0 6px 14px rgba(0,0,0,.45), 0 0 16px rgba(245,197,66,.6); }
/* Objective cards: Tens (race-to-13) get a PERMANENT gold corner badge + a richer
   amber glow so they stay distinguishable from plain playable cards. The badge is
   additive (sits on top via ::before) so it survives every state (playable/disabled),
   and the warmer amber shadow differs from the playable gold border + glow. */
.card.is-ten { box-shadow: 0 0 14px rgba(245,197,66,.55), 0 3px 6px rgba(0,0,0,.4); }
.card.is-ten::before {
  content: "★"; position: absolute; top: -1px; right: 3px;
  font-size: 16px; line-height: 1; color: var(--gold); font-weight: 900;
  text-shadow: 0 0 5px rgba(245,197,66,.95), 0 1px 1px rgba(0,0,0,.3);
  pointer-events: none;
}
/* A playable Ten keeps the star + adds the gold playable border on top. */
.card.is-ten.playable { border-color: var(--gold); box-shadow: 0 0 16px rgba(245,197,66,.7), 0 3px 6px rgba(0,0,0,.4); }
.card .rank { font-size: 20px; line-height: 1; }
.card .suit { font-size: 22px; align-self: flex-end; }

.msg-bar {
  background: rgba(0,0,0,.6); color: var(--gold); padding: 6px 14px; border-radius: 8px;
  font-size: 13px; align-self: center;
}

/* ---------- Team Chat ---------- */
#chat-panel {
  position: fixed; right: 8px; top: 50%; width: 248px;
  height: 40vh;            /* ~half the previous full-height span */
  max-height: 360px;       /* cap on very tall screens */
  transform: translateY(-50%);  /* vertically center on the right edge */
  background: rgba(20, 58, 38, .94); border: 1px solid var(--gold); border-radius: 12px;
  display: flex; flex-direction: column; z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); overflow: hidden;
}
.chat-header {
  padding: 8px 12px; font-size: 13px; font-weight: 700; color: var(--gold);
  border-bottom: 1px solid rgba(245,197,66,.2); flex-shrink: 0;
}
.chat-team-label { font-size: 11px; font-weight: 400; }
#chat-log {
  flex: 1; overflow-y: auto; padding: 6px 8px; font-size: 12px; line-height: 1.4;
  scrollbar-width: thin; scrollbar-color: var(--muted) transparent;
}
#chat-log::-webkit-scrollbar { width: 4px; }
#chat-log::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 2px; }
.chat-row {
  padding: 3px 0 3px 6px; margin-bottom: 2px; border-left: 2px solid transparent;
  word-wrap: break-word;
}
.chat-row.team-a { border-left-color: var(--teamA); }
.chat-row.team-b { border-left-color: var(--teamB); }
.chat-name { font-weight: 700; }
.chat-text { color: var(--text); }
.chat-input-row {
  display: flex; gap: 4px; padding: 6px; border-top: 1px solid rgba(245,197,66,.2); flex-shrink: 0;
}
#chat-input {
  flex: 1; background: #0a2417; border: 1px solid #2c5a40; border-radius: 6px;
  color: var(--text); font-size: 12px; padding: 6px 8px;
}
#chat-input:focus { outline: none; border-color: var(--gold); }
#chat-send {
  background: linear-gradient(180deg, var(--gold), #d8a725); color: #2a1c00; border: none;
  border-radius: 6px; padding: 6px 10px; font-size: 14px; cursor: pointer; flex-shrink: 0;
}
#chat-send:active { transform: translateY(1px); }

/* Mobile: chat becomes a slide-out drawer toggled by a button */
.chat-toggle {
  position: fixed; right: 8px; bottom: 108px; z-index: 51;
  background: rgba(20,58,38,.9); border: 1px solid var(--gold); color: var(--gold);
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}

/* Voice mic toggle — sits in the top-right .hud-controls cluster as a square
   icon button (matching .hud-btn.help). Hidden until voice actually connects;
   JS removes the `hidden` class via updateVoiceButton(). */
.hud-btn.voice {
  width: 54px; padding: 0; font-size: 18px;
}
.hud-btn.voice[aria-pressed="true"] { opacity: .7; border-style: dashed; }

/* Per-seat teammate voice indicator, rendered inside the avatar. */
.seat .voice-ind {
  position: absolute; right: -4px; bottom: -4px;
  font-size: 12px; line-height: 1; background: #11181a; border-radius: 50%;
  padding: 1px 2px; border: 1px solid rgba(255,255,255,.25);
}
.seat .voice-ind.on { border-color: var(--gold); }
.seat .voice-ind.muted { opacity: .6; }

@media (max-width: 600px) {
  .card { width: 52px; height: 72px; margin-left: -20px; }
  .card.suit-break { margin-left: 6px; }
  .card .rank { font-size: 15px; } .card .suit { font-size: 17px; }
  .seat { width: 72px; }
  .seat .avatar { width: 36px; height: 36px; font-size: 14px; }
  #table { height: 50vh; }
  #hud { font-size: 14px; flex-wrap: wrap; row-gap: 6px; }
  /* HUD center chips: let them wrap and shrink so the row doesn't overflow. */
  .center-info { flex-wrap: wrap; gap: 6px; }
  .center-info > div { min-width: 0; padding: 4px 10px; font-size: 12px; }
  /* Buttons stay accessible but shrink on narrow screens. */
  .hud-btn { height: 44px; padding: 0 12px; font-size: 13px; }
  .hud-btn.help { width: 44px; font-size: 15px; }
  /* Chat: full-width slide-up drawer on mobile */
  #chat-panel { left: 8px; right: 8px; width: auto; top: auto; bottom: 108px; height: 30vh; max-height: 280px; }
  .chat-toggle { display: flex; }
  #chat-panel.hidden { display: none; }

  /* Tutorial: stack on small screens */
  .tut-rules-layout { grid-template-columns: 1fr; }
  .tut-rules-nav { flex-direction: row; overflow-x: auto; position: static; max-height: none; }
  .tutorial-shell { width: 96vw; height: 92vh; max-width: none; }
  .tutorial-body { font-size: 14px; }
  .tut-hand, .tut-pile { flex-wrap: wrap; }
}

/* ===== Tutorial overlay (first overlay in the app) ===== */
.tutorial-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3, 15, 8, .82);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.tutorial-overlay.hidden { display: none; }

.tutorial-shell {
  position: relative;
  background: linear-gradient(180deg, #18502f 0%, var(--panel) 100%);
  border: 2px solid var(--gold); border-radius: 18px;
  width: min(760px, 96vw); height: min(680px, 92vh);
  max-width: 760px;
  display: flex; flex-direction: column;
  box-shadow: 0 0 0 1px rgba(245,197,66,.35), 0 0 50px rgba(245,197,66,.15), 0 24px 70px rgba(0,0,0,.6);
  overflow: hidden;
}
.tutorial-close {
  position: absolute; top: 10px; right: 12px; z-index: 3;
  background: rgba(0,0,0,.4); color: var(--gold); border: 1px solid rgba(245,197,66,.4);
  width: 32px; height: 32px; border-radius: 50%; font-size: 16px; cursor: pointer; line-height: 1;
}
.tutorial-close:hover { background: rgba(245,197,66,.2); }

.tutorial-tabs {
  display: flex; gap: 6px; padding: 14px 16px 0; flex-shrink: 0;
}
.tut-tab {
  background: rgba(0,0,0,.3); color: var(--muted);
  border: 1px solid rgba(255,255,255,.1); border-bottom: none;
  padding: 8px 18px; border-radius: 10px 10px 0 0; cursor: pointer; font-size: 14px; font-weight: 700;
}
.tut-tab.active { background: var(--panel); color: var(--gold); border-color: var(--gold); }

.tutorial-body {
  flex: 1; overflow-y: auto; padding: 18px 26px 26px;
  color: var(--text); line-height: 1.55;
}
.tutorial-body h2, .tutorial-body h3, .tutorial-body h4 { color: var(--gold); margin: 14px 0 8px; }
.tutorial-body h2 { font-size: 24px; }
.tutorial-body h3 { font-size: 18px; }
.tutorial-body p { margin: 8px 0; }
.tutorial-body a { color: var(--gold); }
.tutorial-body ul, .tutorial-body ol { margin: 8px 0 8px 22px; }
.tutorial-body li { margin: 5px 0; }
.tut-list { list-style: disc; }
.tut-callout {
  background: rgba(245,197,66,.1); border: 1px solid rgba(245,197,66,.35);
  border-radius: 10px; padding: 10px 14px; margin: 12px 0; color: var(--gold-light);
}
.tut-sub { color: var(--muted); font-size: 13px; }
.tut-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.tut-table th, .tut-table td { border: 1px solid rgba(255,255,255,.15); padding: 6px 10px; text-align: left; }
.tut-table th { background: rgba(0,0,0,.25); color: var(--gold); }
.tutorial-body details { margin: 8px 0; background: rgba(0,0,0,.2); border-radius: 8px; padding: 8px 12px; }
.tutorial-body summary { cursor: pointer; color: var(--gold); font-weight: 700; }
.tutorial-body details[open] summary { margin-bottom: 6px; }

/* --- Learn mode --- */
.tut-lesson-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.tut-progress { color: var(--muted); font-size: 13px; }
.tut-dots { display: flex; gap: 6px; }
.tut-dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.2); }
.tut-dot.on { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.tut-dot.done { background: #46a069; }
.tut-lesson-title { margin-top: 2px !important; }
.tut-teach { margin-bottom: 8px; }
.tut-demo { background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 16px; min-height: 140px; }
.tut-q, .tut-context, .tut-note { font-size: 14px; margin-bottom: 10px; }
.tut-context { color: var(--muted); }
.tut-pile, .tut-hand, .tut-trick-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.tut-pile .tut-mini, .tut-hand .card { margin-left: 0; width: 48px; height: 66px; }
.tut-mini.card.is-ten { border-color: var(--gold); box-shadow: 0 0 10px var(--gold); }
.tut-mini .rank { font-size: 15px; } .tut-mini .suit { font-size: 16px; }
.tut-count-row { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.tut-count-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--gold);
  background: rgba(0,0,0,.3); color: var(--gold); font-weight: 700; font-size: 16px; cursor: pointer;
}
.tut-count-btn:hover { background: rgba(245,197,66,.15); }
.tut-count-btn.picked { background: var(--gold); color: #2a1c00; }
.tut-feedback { margin-top: 10px; font-size: 14px; }
.tut-feedback.ok { color: #8fe0a8; } .tut-feedback.no { color: var(--red); }
.tut-ex-head { font-weight: 700; color: var(--gold); margin-bottom: 6px; }
.tut-resolve-btn {
  display: block; margin: 10px auto 0;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 48%, var(--gold-deep));
  color: #2a1c00; border: none; padding: 9px 24px; border-radius: 10px; font-weight: 700; cursor: pointer;
}
.tut-resolve-btn:disabled { opacity: .5; cursor: default; }
.tut-nav { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }
.tut-prev-ex, .tut-next-ex {
  background: rgba(0,0,0,.3); color: var(--gold); border: 1px solid rgba(245,197,66,.4);
  padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}

/* Trick-row table cards reuse .table-card visuals but reset positioning/animation. */
.tut-trick-row .table-card {
  position: relative; left: auto; top: auto; opacity: 1; animation: none;
  margin: 2px; transform: none !important;
}
.tut-trick-row .tc-seat { font-size: 9px; color: #666; margin-bottom: 2px; }
.tut-trick-row .tc-order { font-size: 8px; color: #999; margin-top: 2px; }

.tut-lesson-nav { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.tut-nav-spacer { flex: 1; }
.tut-nav-btn {
  background: rgba(0,0,0,.3); color: var(--text);
  border: 1px solid rgba(255,255,255,.15); padding: 10px 22px; border-radius: 10px;
  font-weight: 700; cursor: pointer;
}
.tut-nav-btn.primary {
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 48%, var(--gold-deep));
  color: #2a1c00; border: none;
}
.tut-nav-btn:disabled { opacity: .4; cursor: default; }

/* --- Rules mode --- */
.tutorial-search {
  display: block; width: 100%; margin-bottom: 14px;
  padding: 9px 12px; border-radius: 10px; border: 1px solid #2c5a40;
  background: #0a2417; color: var(--text); font-size: 14px;
}
.tut-rules-layout { display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.tut-rules-nav {
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; align-self: start; max-height: 100%; overflow-y: auto;
}
.tut-rule-link {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: rgba(0,0,0,.2); color: var(--muted); border: 1px solid transparent;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.tut-rule-link:hover { background: rgba(245,197,66,.1); color: var(--text); }
.tut-rule-link.active { background: rgba(245,197,66,.15); color: var(--gold); border-color: rgba(245,197,66,.4); }
.tut-rule-icon { width: 18px; text-align: center; }
.tut-rules-content { min-width: 0; }
.tut-rule-section { padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.07); margin-bottom: 18px; }

/* --- Lesson score-bar demo (lesson 6) --- */
.tut-score-demo { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.tut-team { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.tut-team b { margin-left: auto; }
.tut-bar { flex: 1; height: 14px; background: rgba(0,0,0,.4); border-radius: 7px; overflow: hidden; }
.tut-fill { height: 100%; border-radius: 7px; }
.tut-fill.a { background: var(--teamA); } .tut-fill.b { background: var(--teamB); }
.dot.a { background: var(--teamA); } .dot.b { background: var(--teamB); }
.dot.a, .dot.b { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* --- "How to Play" menu button + in-match help button --- */
#howto-btn.done::after { content: " ✓"; color: #cde8d4; }

/* ===================== DEBUG PANEL (only loads via ?debug=1) ===================== */
/* A sibling of #app, fixed bottom-right, never affected by screen .hidden toggles. */
#dbg-panel {
  position: fixed; bottom: 8px; right: 8px; z-index: 99999;
  width: 420px; max-width: 95vw; height: 280px; max-height: 60vh;
  background: rgba(10,12,18,.92); color: #cde; border: 1px solid #3a4a6a;
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.6);
  display: flex; flex-direction: column; font-family: ui-monospace, Consolas, monospace; font-size: 11px;
}
#dbg-panel.dbg-collapsed { height: 30px; overflow: hidden; }
.dbg-bar { display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: rgba(255,255,255,.05); border-bottom: 1px solid #2a3a5a; }
.dbg-title { color: var(--gold); font-size: 12px; }
.dbg-spacer { flex: 1; }
.dbg-tab, .dbg-act {
  background: rgba(255,255,255,.06); color: #9ab; border: 1px solid #2a3a5a;
  border-radius: 4px; padding: 2px 6px; cursor: pointer; font-size: 10px; font-family: inherit;
}
.dbg-tab.active { background: var(--gold); color: #000; border-color: var(--gold); }
.dbg-tab:hover, .dbg-act:hover { background: rgba(255,255,255,.15); }
.dbg-search { width: 70px; background: rgba(0,0,0,.4); color: #cde; border: 1px solid #2a3a5a; border-radius: 4px; padding: 2px 4px; font-size: 10px; font-family: inherit; }
.dbg-list { flex: 1; overflow-y: auto; padding: 4px 6px; line-height: 1.5; }
.dbg-row { display: flex; gap: 6px; white-space: nowrap; }
.dbg-time { color: #5a7; flex-shrink: 0; }
.dbg-text { color: #cde; overflow: hidden; text-overflow: ellipsis; }
/* Color-code by kind for quick scanning. */
.dbg-msg .dbg-text { color: #8cf; }      /* messages: blue */
.dbg-click .dbg-text { color: #fd8; }     /* clicks: amber */
.dbg-state .dbg-text { color: #fb7; }     /* state changes: orange */
.dbg-screen .dbg-text { color: #a8f; }    /* screen transitions: purple */
