:root {
  --felt: #0d6b3a;
  --felt-dark: #094425;
  --rail: #3e2519;
  --rail-light: #5b3623;
  --gold: #d4af37;
  --text: #f4f0e6;
  --muted: #b4b09f;
  --card-bg: #fdfdfd;
  --card-back: linear-gradient(135deg, #6b1a1a 0%, #3a0c0c 100%);
  --red: #c0202c;
  --black: #1a1a1a;
  --active: #facc15;
  --folded: #555;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #1a1410;
  color: var(--text);
  height: 100%;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
  max-height: 100vh;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  background: #100a06;
  border-bottom: 1px solid #2a1d12;
}
.top-bar h1 {
  margin: 0;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 2px;
}
.meta {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.table-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
}

.table {
  position: relative;
  width: min(90vw, 1000px);
  aspect-ratio: 16 / 9;
  background:
    radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 75%),
    var(--felt);
  border: 14px solid var(--rail);
  border-radius: 50% / 38%;
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.5),
    0 10px 40px rgba(0,0,0,0.6);
}

.board {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pot {
  background: rgba(0,0,0,0.45);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  color: var(--gold);
  letter-spacing: 1px;
}
.pot-label { color: var(--muted); margin-right: 8px; font-size: 11px; text-transform: uppercase; }

.community {
  display: flex;
  gap: 8px;
  min-height: 92px;
}

.stage {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* seats */
.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 180px;
}
.seat-bottom { bottom: -10px; left: 50%; transform: translateX(-50%); }
.seat-top { top: -10px; left: 50%; transform: translateX(-50%); }
.seat-left { left: -10px; top: 50%; transform: translateY(-50%); }
.seat-right { right: -10px; top: 50%; transform: translateY(-50%); }

.player {
  background: rgba(0,0,0,0.55);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 140px;
  text-align: center;
  transition: all 0.2s ease;
  position: relative;
}
.player.active {
  border-color: var(--active);
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.6);
}
.player.folded { opacity: 0.45; }
.player.allin { border-color: #ef4444; }
.player .name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.player .chips {
  color: var(--gold);
  font-size: 13px;
  margin-top: 2px;
}
.player .status {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  min-height: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.player .bet {
  position: absolute;
  background: var(--gold);
  color: #1a1410;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

.dots {
  display: inline-block;
  margin-left: 2px;
}
.dots span {
  display: inline-block;
  opacity: 0;
  animation: pulse 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}
.seat-bottom .bet { top: -22px; left: 50%; transform: translateX(-50%); }
.seat-top .bet { bottom: -22px; left: 50%; transform: translateX(-50%); }
.seat-left .bet { right: -60px; top: 50%; transform: translateY(-50%); }
.seat-right .bet { left: -60px; top: 50%; transform: translateY(-50%); }

.dealer-chip {
  position: absolute;
  width: 22px; height: 22px;
  background: #fff;
  color: #000;
  border-radius: 50%;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.seat-bottom .dealer-chip { top: -10px; right: -10px; }
.seat-top .dealer-chip { bottom: -10px; right: -10px; }
.seat-left .dealer-chip { right: -10px; bottom: -10px; }
.seat-right .dealer-chip { left: -10px; bottom: -10px; }

/* hole cards */
.hole-cards {
  display: flex;
  gap: 4px;
  justify-content: center;
  min-height: 76px;
}

/* card visuals */
.card {
  width: 52px;
  height: 72px;
  border-radius: 6px;
  background: var(--card-bg);
  border: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: 'Georgia', serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  position: relative;
  user-select: none;
}
.card.lg {
  width: 60px;
  height: 84px;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card .rank { font-size: 22px; line-height: 1; }
.card .suit { font-size: 18px; line-height: 1; margin-top: 2px; }
.card.back {
  background: var(--card-back);
  border-color: #2a0808;
}
.card.back::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255,255,255,0.25);
  border-radius: 4px;
}
.card.placeholder {
  background: rgba(0,0,0,0.25);
  border: 1px dashed rgba(255,255,255,0.15);
  box-shadow: none;
}
.card.winning {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* action bar */
.action-bar {
  background: #100a06;
  border-top: 1px solid #2a1d12;
  padding: 10px 20px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
}
.action-info {
  color: var(--muted);
  font-size: 13px;
}
.action-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}
.raise-group {
  display: flex;
  gap: 4px;
  align-items: center;
}
.raise-group input {
  width: 90px;
  padding: 6px 8px;
  background: #2a1d12;
  border: 1px solid #3e2519;
  color: var(--text);
  border-radius: 4px;
  font-size: 13px;
}

button {
  background: #2a1d12;
  color: var(--text);
  border: 1px solid #3e2519;
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
}
button:hover:not(:disabled) {
  background: #3e2519;
  border-color: var(--gold);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
button.primary {
  background: var(--gold);
  color: #1a1410;
  border-color: var(--gold);
}
button.primary:hover:not(:disabled) {
  background: #f4c842;
}
button.ghost {
  background: transparent;
  border-color: #3e2519;
}

.log {
  background: #0a0604;
  color: var(--muted);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  padding: 8px 20px;
  max-height: 100px;
  overflow-y: auto;
  border-top: 1px solid #2a1d12;
}
.log .entry { margin: 2px 0; }
.log .entry.win { color: var(--gold); }
.log .entry.fold { color: #888; }
.log .entry.raise { color: #facc15; }

/* ===== Winner overlay (shared across all games) ===== */
.winner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 16, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  transition: opacity 220ms ease;
  pointer-events: none;
  backdrop-filter: blur(2px);
}
.winner-overlay.hidden { display: none; }
.winner-overlay.open { opacity: 1; }
/* Backdrop is non-interactive — only the card captures clicks, so top-bar buttons stay reachable. */
.winner-overlay .winner-card { pointer-events: auto; }

.winner-card {
  background: linear-gradient(180deg, #1a1f2e 0%, #14182a 100%);
  border: 1px solid rgba(212, 165, 87, 0.5);
  border-radius: 14px;
  padding: 36px 40px 24px;
  min-width: 320px;
  max-width: 480px;
  color: #e6e8ee;
  text-align: center;
  position: relative;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(212, 165, 87, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 220ms ease;
}
.winner-overlay.open .winner-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Accent ring around the card */
.winner-overlay.accent-gold   .winner-card { border-color: rgba(212, 165, 87, 0.55); }
.winner-overlay.accent-silver .winner-card { border-color: rgba(180, 188, 208, 0.55); }
.winner-overlay.accent-red    .winner-card { border-color: rgba(239, 68, 68, 0.55); }

/* Medal — animated pop */
.winner-medal {
  font-size: 44px;
  width: 72px;
  height: 72px;
  line-height: 72px;
  border-radius: 50%;
  margin: -64px auto 14px;
  background: radial-gradient(circle at 30% 25%, #f6cf78 0%, #d4a557 55%, #8a6a2d 100%);
  box-shadow: 0 8px 24px rgba(212, 165, 87, 0.4), inset 0 -3px 8px rgba(0, 0, 0, 0.25);
  color: #1a1f2e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: scale(0.6) rotate(-30deg);
  opacity: 0;
  transition: transform 380ms cubic-bezier(0.34, 1.56, 0.64, 1) 100ms,
              opacity 220ms ease 100ms;
}
.winner-overlay.open .winner-medal {
  transform: scale(1) rotate(0deg);
  opacity: 1;
}
.winner-overlay.accent-silver .winner-medal {
  background: radial-gradient(circle at 30% 25%, #f0f3fa 0%, #b4bcd0 55%, #6d7790 100%);
}
.winner-overlay.accent-red .winner-medal {
  background: radial-gradient(circle at 30% 25%, #ff9a9a 0%, #ef4444 55%, #7a1f1f 100%);
  color: #fff;
}

.winner-title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  color: var(--gold, #d4a557);
  letter-spacing: 0.5px;
}
.winner-overlay.accent-silver .winner-title { color: #d8dde8; }
.winner-overlay.accent-red    .winner-title { color: #ff8e8e; }

.winner-subtitle {
  margin: 0 0 16px;
  color: #a8b0c0;
  font-size: 14px;
}

.winner-stats {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.winner-stats li {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.winner-stats li:last-child { border-bottom: none; }
.winner-stats .label { color: #a8b0c0; }
.winner-stats .value { color: #e6e8ee; font-weight: 600; }

.winner-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.winner-action,
.winner-dismiss {
  font: inherit;
  cursor: pointer;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: filter 120ms ease, transform 80ms ease;
}
.winner-action.primary {
  background: var(--gold, #d4a557);
  color: #1a1f2e;
  border-color: var(--gold, #d4a557);
  font-weight: 700;
}
.winner-dismiss.ghost {
  background: transparent;
  color: #a8b0c0;
  border-color: rgba(255, 255, 255, 0.12);
}
.winner-action:hover,
.winner-dismiss:hover { filter: brightness(1.08); }
.winner-action:active,
.winner-dismiss:active { transform: translateY(1px); }

/* ===== Lobby overlay (shared across all games) ===== */
.lobby-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.lobby-overlay.hidden { display: none; }
.lobby-card {
  background: #1a1f2e;
  border: 1px solid #2a3142;
  border-radius: 12px;
  padding: 28px;
  min-width: 360px;
  max-width: 440px;
  color: #e6e8ee;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.lobby-card h2 { margin: 0 0 18px; font-size: 22px; }
.lobby-card h3 { margin: 0 0 12px; font-size: 16px; color: var(--gold, #d4a557); }
.lobby-card p  { font-size: 13px; color: #a8b0c0; margin: 6px 0 14px; }
.lobby-panel.hidden { display: none; }
.lobby-panel button {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid #3a4255;
  background: #232a3d;
  color: #e6e8ee;
  font: inherit;
  cursor: pointer;
}
.lobby-panel button.primary {
  background: var(--gold, #d4a557);
  color: #1a1f2e;
  border-color: var(--gold, #d4a557);
  font-weight: 600;
}
.lobby-panel button.ghost {
  background: transparent;
  border-color: #3a4255;
  color: #a8b0c0;
}
.lobby-panel button:hover { filter: brightness(1.1); }
.lobby-panel label {
  display: block;
  font-size: 12px;
  color: #a8b0c0;
  margin: 10px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.lobby-panel input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid #3a4255;
  border-radius: 6px;
  background: #0f1320;
  color: #e6e8ee;
  font: inherit;
  text-transform: none;
  letter-spacing: normal;
}
.lobby-panel input:focus { border-color: var(--gold, #d4a557); outline: none; }
.session-code-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0 12px;
}
.session-code-row code {
  flex: 1;
  font-size: 24px;
  letter-spacing: 4px;
  font-weight: 700;
  background: #0f1320;
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #3a4255;
  color: var(--gold, #d4a557);
  text-align: center;
}
.session-code-row button { width: auto; padding: 10px 16px; margin: 0; }
.roster {
  list-style: none;
  padding: 0;
  margin: 8px 0 14px;
  font-size: 13px;
}
.roster li {
  padding: 6px 10px;
  border-bottom: 1px solid #2a3142;
}
.lobby-status {
  margin-top: 14px;
  font-size: 12px;
  color: #ef4444;
  min-height: 1em;
}

/* ===== In-game session badge (shared) ===== */
.session-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(212, 165, 87, 0.12);
  border: 1px solid rgba(212, 165, 87, 0.4);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.session-badge.hidden { display: none; }
.session-badge-label {
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted, #a8b0c0);
  font-size: 10px;
}
.session-badge code {
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold, #d4a557);
  font-size: 13px;
}
.session-badge.copied code::after { content: ' ✓'; }
#session-leave-btn {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #ef4444;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font: inherit;
}
#session-leave-btn:hover { background: rgba(239, 68, 68, 0.15); }

/* ============================================
   MOBILE RESPONSIVE
   Breakpoints: ≤900 (tablet) · ≤640 (phone) · ≤400 (small phone)
   ============================================ */

@media (max-width: 900px) {
  html, body { overflow: auto; }
  #app {
    grid-template-rows: auto auto auto auto auto;
    height: auto;
    min-height: 100vh;
    max-height: none;
  }
  .top-bar {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .top-bar h1 { font-size: 16px; letter-spacing: 1px; }
  .meta {
    gap: 8px;
    font-size: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .table-wrap { padding: 10px; }
  .table {
    width: min(96vw, 720px);
    aspect-ratio: 4 / 3;
    border-width: 8px;
  }
  .card { width: 44px; height: 62px; }
  .card.lg { width: 50px; height: 70px; }
  .card .rank { font-size: 18px; }
  .card .suit { font-size: 14px; }
  .action-bar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px;
  }
  .action-info { font-size: 12px; order: -1; }
  .action-buttons { flex-wrap: wrap; gap: 6px; justify-content: center; }
  .raise-group input { width: 70px; font-size: 12px; }
  button { padding: 6px 10px; font-size: 12px; }
  .log { font-size: 11px; padding: 6px 12px; max-height: 70px; }
}

@media (max-width: 640px) {
  .top-bar h1 { font-size: 14px; }
  .meta { font-size: 11px; gap: 6px; }
  .meta > span, .meta > a { white-space: nowrap; }
  /* Hide the verbose hand-counter/blinds on small screens — keep critical info */
  .meta #hand-counter, .meta #blind-info, .meta #scores { display: none; }
  .meta #session-badge { font-size: 10px; padding: 3px 6px; }
  .meta #session-badge code { font-size: 11px; letter-spacing: 1px; }
  .table {
    aspect-ratio: 3 / 4;
    border-width: 6px;
    border-radius: 30% / 18%;
  }
  .card { width: 36px; height: 52px; }
  .card.lg { width: 42px; height: 60px; }
  .card .rank { font-size: 15px; }
  .card .suit { font-size: 12px; }
  .community { gap: 4px; min-height: 60px; }
  .seat { min-width: auto; gap: 2px; }
  .pot { font-size: 12px; padding: 4px 10px; }
  /* Tighten lobby + winner overlays for narrow screens */
  .winner-card, .lobby-card {
    min-width: 0;
    max-width: 96vw;
    padding: 24px 18px 16px;
  }
  .winner-title { font-size: 20px; }
  .winner-subtitle { font-size: 12px; }
  .session-code-row code { font-size: 18px; padding: 8px 10px; }
}

@media (max-width: 400px) {
  .top-bar { padding: 6px 8px; }
  .top-bar h1 { font-size: 13px; letter-spacing: 0; }
  .meta { font-size: 10px; }
  .card { width: 32px; height: 46px; }
  .card.lg { width: 38px; height: 54px; }
  .card .rank { font-size: 13px; }
  .card .suit { font-size: 10px; }
  .action-buttons button { padding: 6px 8px; font-size: 11px; }
  .log { max-height: 50px; font-size: 10px; }
}

/* === Poker mobile layout (≤640): replace elliptical absolute layout with grid === */
@media (max-width: 640px) {
  /* Prevent horizontal scroll */
  body { overflow-x: hidden; }
  .table-wrap { padding: 8px 6px; }
  .table {
    width: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    border-radius: 16px;
    border-width: 6px;
    padding: 8px;
    display: grid;
    grid-template-areas:
      "left   top    right"
      "board  board  board"
      "bottom bottom bottom";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 8px;
    min-height: 360px;
  }
  .seat { position: static; transform: none !important; gap: 4px; min-width: 0; width: 100%; align-items: center; }
  .seat-top    { grid-area: top; }
  .seat-left   { grid-area: left; }
  .seat-right  { grid-area: right; }
  .seat-bottom { grid-area: bottom; flex-direction: column-reverse; align-items: center; }
  .board {
    position: static;
    transform: none;
    grid-area: board;
    margin: 8px 0;
  }
  /* Reset chip + bet positioning so they don't reach off-screen */
  .seat .bet { position: static; transform: none; margin-top: 4px; }
  .seat .dealer-chip { position: static; margin-top: 2px; }
  /* Make player panels compact and contained */
  .seat .player {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
    padding: 4px 6px !important;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .seat .player .name { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .seat .player .chips { font-size: 10px; }
  .seat .player .last-action,
  .seat .player .position,
  .seat .player .stats {
    font-size: 9px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .hole-cards { gap: 2px; justify-content: center; }
}
