:root {
  --bg: #071018;
  --bg-2: #0c1a24;
  --felt: #0b5a38;
  --felt-2: #063d26;
  --rail: #5b3416;
  --rail-2: #2a160a;
  --gold: #e2c078;
  --gold-2: #b48a3c;
  --ink: #f4efe4;
  --muted: #9aa7b5;
  --danger: #d4524e;
  --ok: #3ecf8e;
  --call: #3d8bfd;
  --card: #f8f4ec;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --rail-w: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(1200px 600px at 50% -10%, #163247, var(--bg)); color: var(--ink); font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.red { color: #d64a4a; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; letter-spacing: 0.06em; }
.muted { color: var(--muted); }

.screen { min-height: 100dvh; }
.gate-card {
  width: min(460px, calc(100% - 32px));
  margin: 6vh auto;
  background: linear-gradient(180deg, rgba(20, 36, 48, 0.96), rgba(8, 16, 24, 0.96));
  border: 1px solid rgba(226, 192, 120, 0.25);
  border-radius: 24px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 18px; }
.brand h1 { margin: 6px 0 0; font-size: 32px; letter-spacing: 0.06em; }
.brand p { margin: 6px 0 0; color: var(--muted); }
.suit-row { display: flex; justify-content: center; gap: 12px; font-size: 22px; color: var(--gold); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 13px; color: var(--muted); }
.field input, .field select {
  background: #0b151d;
  border: 1px solid #2a3d4c;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
}
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; color: var(--ink); font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 16px 0 10px; }
.tab, .ghost, .primary {
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 10px 14px;
}
.tab { background: #13202b; color: var(--muted); border-color: #243848; }
.tab.on { color: var(--bg); background: linear-gradient(180deg, var(--gold), var(--gold-2)); font-weight: 700; }
.ghost { background: transparent; color: var(--ink); border-color: #3a5163; }
.primary {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(180deg, #f0d392, #c49a45);
  color: #1a1208;
  font-weight: 700;
  border: 0;
}
.primary.sm, .ghost.sm { width: auto; margin: 0; padding: 7px 10px; font-size: 12px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-btn svg { flex: 0 0 auto; display: block; }
.primary:disabled, .ghost:disabled { opacity: 0.45; cursor: default; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  background: rgba(5, 12, 18, 0.78);
  border-bottom: 1px solid rgba(226, 192, 120, 0.15);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.top-left, .top-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.logo { letter-spacing: 0.16em; color: var(--gold); }
.clock { color: var(--gold); font-variant-numeric: tabular-nums; }

#table-screen.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
}
.table-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 8px 16px 0;
  min-height: 0;
}
.rail {
  /* desktop: racetrack oval, wider than tall (casino Hold’em table) */
  position: relative;
  width: min(94vw, 1100px, calc(min(60vh, 520px) * 2.2));
  aspect-ratio: 2.2 / 1;
  border-radius: 999px;
  padding: 0;
  background: linear-gradient(180deg, #8a5528, var(--rail-2));
  box-shadow: inset 0 0 0 5px #2b160b, 0 18px 40px rgba(0, 0, 0, 0.45);
}
.felt {
  position: absolute;
  inset: var(--rail-w);
  border-radius: 999px;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, #14945c 0%, var(--felt) 46%, var(--felt-2) 100%);
  box-shadow:
    0 0 0 2px rgba(226, 192, 120, 0.45),
    inset 0 0 70px rgba(0, 0, 0, 0.35);
  overflow: visible;
}
.felt.is-showdown { animation: none; }
.felt.is-showdown .center-stack { visibility: hidden; }
.felt.is-showdown .table-rules { visibility: hidden; }
.felt.is-showdown .seat-cards { visibility: hidden; }
.seats { position: absolute; inset: 0; }
.seat {
  position: absolute;
  width: 112px;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 2;
}
.seat .avatar {
  width: 46px;
  height: 46px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #13202b;
  border: 2px solid #6d5630;
  font-weight: 700;
  position: relative;
  overflow: visible;
}
.seat.acting .avatar {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(226, 192, 120, 0.35);
  animation: pulse 1s ease-in-out infinite;
}
.seat-cd {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: #ffe9b0;
  text-shadow: 0 1px 4px #000;
  z-index: 3;
  pointer-events: none;
  letter-spacing: -0.04em;
}
.seat.acting .seat-cd { display: grid; }
.seat.acting .seat-initial { visibility: hidden; }
.seat.acting.cd-urgent .seat-cd { color: #ff6b6b; }
.seat.acting.cd-urgent .avatar {
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.35);
}
.seat.me .avatar { border-color: #7fd3ff; }
.seat.folded { opacity: 0.45; }
.seat.busted { opacity: 0.72; }
.seat .name { font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .stack { font-size: 12px; color: var(--gold); font-variant-numeric: tabular-nums; }
.seat .stack .pending { color: #9ad7ff; font-size: 10px; }
.seat.busted .stack { color: var(--danger); }
.seat .bet {
  position: absolute;
  display: flex;
  justify-content: center;
  font-size: 11px;
  color: #ffe9b0;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
}
.seat.vis-0 .bet { left: 50%; top: 0; transform: translate(-50%, calc(-100% - 6px)); }
.seat.vis-1 .bet { left: 100%; top: 18%; transform: translate(4px, -50%); }
.seat.vis-2 .bet { left: 100%; top: 50%; transform: translate(8px, -50%); }
.seat.vis-3 .bet { left: 100%; top: 72%; transform: translate(4px, -50%); }
.seat.vis-4 .bet { left: 50%; bottom: 0; transform: translate(-50%, calc(100% + 6px)); }
.seat.vis-5 .bet { left: 0; top: 72%; transform: translate(calc(-100% - 4px), -50%); }
.seat.vis-6 .bet { left: 0; top: 50%; transform: translate(calc(-100% - 8px), -50%); }
.seat.vis-7 .bet { left: 0; top: 18%; transform: translate(calc(-100% - 4px), -50%); }
.chip-stack {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}
.pchip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-left: -12px;
  border: 1.5px dashed rgba(255, 255, 255, 0.78);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(0, 0, 0, 0.28);
  flex: 0 0 auto;
}
.chip-stack .pchip:first-child { margin-left: 0; }
.pchip.c1 { background: radial-gradient(circle at 35% 30%, #fff, #d9d3c7); }
.pchip.c5 { background: radial-gradient(circle at 35% 30%, #e57373, #b71c1c); }
.pchip.c25 { background: radial-gradient(circle at 35% 30%, #66bb6a, #1b5e20); }
.pchip.c100 { background: radial-gradient(circle at 35% 30%, #555, #111); }
.pchip.c500 { background: radial-gradient(circle at 35% 30%, #ce93d8, #6a1b9a); }
.chip-amt {
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #ffe9b0;
  text-shadow: 0 1px 2px #000;
  font-size: 11px;
}
.pot .chip-stack { margin-top: 4px; }
.pot .chip-amt { font-size: 16px; }
.seat .tags { font-size: 10px; color: #cde7d8; min-height: 0; }
.role-badge {
  position: absolute;
  display: grid;
  place-items: center;
  font-weight: 800;
  line-height: 1;
  z-index: 4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.role-badge.dealer {
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f2f2f2;
  color: #222;
  font-size: 11px;
}
.role-badge.sb,
.role-badge.bb,
.role-badge.str {
  height: 16px;
  padding: 0 5px;
  border-radius: 8px;
  font-size: 9px;
  letter-spacing: 0.02em;
}
.role-badge.sb { bottom: -7px; left: -10px; background: #2f6fbf; color: #fff; }
.role-badge.bb { bottom: -7px; right: -10px; background: #e2c078; color: #1a1208; }
.role-badge.str { top: -7px; left: -10px; background: #6a1b9a; color: #fff; }
.timer-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--gold);
  animation: spin 1s linear infinite;
}
.center-stack {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 1;
  width: min(72%, 520px);
}
.pot { font-size: 18px; font-weight: 700; color: #ffe9b0; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.street { font-size: 12px; letter-spacing: 0.2em; color: #cde7d8; margin-bottom: 6px; }
.street:empty { display: none; margin: 0; }
.board { display: flex; justify-content: center; gap: 8px; min-height: 88px; margin-top: 8px; }
.banner {
  min-height: 24px;
  margin-top: 8px;
  font-weight: 700;
  color: #fff6d6;
  text-shadow: 0 2px 10px #000;
}
.countdown {
  min-height: 20px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  font-weight: 700;
}
.table-rules {
  position: absolute;
  left: 50%;
  top: 66%;
  transform: translate(-50%, 0);
  width: min(58%, 280px);
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(196, 214, 204, 0.42);
  font-weight: 500;
  text-align: center;
  pointer-events: none;
}
.table-rules #table-remain { font-variant-numeric: tabular-nums; }

.card {
  width: 54px;
  height: 76px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, var(--card));
  color: #1a1a1a;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 7px;
  font-weight: 800;
}
.card.deal-anim { animation: dealIn 0.32s ease both; }
.card .s { font-size: 18px; align-self: flex-end; }
.card.red { color: #c0392b; }
.card.back {
  background: repeating-linear-gradient(45deg, #1d3a66, #1d3a66 6px, #25487c 6px, #25487c 12px);
  color: transparent;
}
.card.tiny { width: 28px; height: 40px; padding: 3px; font-size: 11px; }
.hole {
  display: flex;
  gap: 8px;
  min-width: 120px;
  min-height: 88px;
  grid-column: 2;
  justify-self: center;
  margin-top: -28px;
  z-index: 4;
}
.hole .card { width: 62px; height: 88px; }

.dock {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: end;
  position: relative;
  min-height: 100px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(8, 16, 24, 0.2), rgba(8, 16, 24, 0.92));
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  max-width: min(46vw, 540px);
  z-index: 5;
}
.actions button { min-width: 68px; font-size: 13px; }
.actions .fold { background: #5a1f1f; color: #ffd0d0; border: 1px solid #8a3a3a; border-radius: 10px; padding: 7px 10px; }
.actions .check, .actions .call { background: #163a66; color: #d6e8ff; border: 1px solid #2d6db3; border-radius: 10px; padding: 7px 10px; }
.actions .raise, .actions .bet, .actions .allin { background: linear-gradient(180deg, #f0d392, #c49a45); color: #1a1208; border: 0; border-radius: 10px; padding: 7px 10px; font-weight: 700; }
.actions input[type="range"] { width: min(120px, 16vw); }
.raise-ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.raise-ctl output {
  min-width: 3.2em;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--gold);
}
.runout-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.sd-run { margin-bottom: 8px; }
.sd-run-label { font-size: 11px; letter-spacing: 0.16em; color: var(--gold); margin-bottom: 4px; }
#sd-board.board { flex-direction: column; gap: 6px; min-height: 0; }
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1a2c22;
  border: 1px solid #3d6b4e;
  font-size: 11px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 20;
}
.modal-card {
  width: min(400px, calc(100% - 32px));
  background: #13202b;
  border: 1px solid rgba(226, 192, 120, 0.3);
  border-radius: 18px;
  padding: 20px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #13202b;
  border: 1px solid var(--gold-2);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 30;
}
.settle-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.settle-table th, .settle-table td { padding: 8px; text-align: left; border-bottom: 1px solid #2a3d4c; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

@keyframes dealIn {
  from { transform: translateY(-28px) rotate(-12deg) scale(0.7); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 6px rgba(226, 192, 120, 0.12); }
}
@keyframes spin { to { transform: rotate(360deg); } }
.showdown {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  place-content: center;
  justify-items: center;
  align-items: center;
  pointer-events: none;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
}
.showdown.hidden { display: none !important; }
.sd-panel {
  width: min(92vw, 520px);
  max-width: calc(100vw - 32px);
  background: rgba(6, 14, 20, 0.94);
  border: 1px solid rgba(226, 192, 120, 0.55);
  border-radius: 18px;
  padding: 16px 18px 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  animation: sdIn 0.45s ease both;
  pointer-events: auto;
}
.sd-kicker {
  letter-spacing: 0.28em;
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 8px;
}
.sd-players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 10px 0;
}
.sd-row { min-width: 100px; }
.sd-row .name { font-size: 12px; margin-bottom: 6px; }
.sd-row.winner .name { color: var(--gold); font-weight: 700; }
.sd-row .sd-holes { display: flex; gap: 4px; justify-content: center; }
.sd-win {
  font-size: 16px;
  font-weight: 800;
  color: #ffe9b0;
  animation: sdWin 0.6s ease 0.15s both;
}
@keyframes sdIn {
  from { transform: translateY(12px) scale(0.94); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes sdWin {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (max-width: 820px), (orientation: portrait) {
  .table-wrap { padding: 6px 8px 0; }
  .rail {
    /* phone: standing racetrack, nearly full width so side seats hug the edges */
    --rail-w: 14px;
    width: min(96vw, calc(min(62vh, 640px) / 1.65));
    aspect-ratio: 1 / 1.65;
    padding: 0;
  }
  .center-stack {
    top: 42%;
    width: min(52%, 240px);
  }
  .table-rules {
    top: 63%;
    width: min(48%, 200px);
    font-size: 10px;
  }
  .board { gap: 4px; min-height: 64px; }
  .pot { font-size: 15px; }
  .seat { width: 78px; }
  .seat .avatar { width: 36px; height: 36px; font-size: 13px; }
  .seat-cd { font-size: 15px; }
  .card { width: 42px; height: 60px; }
  .hole .card { width: 52px; height: 74px; }
  .dock {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    align-items: center;
  }
  .hole { grid-column: auto; margin-top: 0; }
  .dock { min-height: 0; }
  .actions {
    position: static;
    transform: none;
    top: auto;
    right: auto;
    max-width: none;
    justify-content: center;
    width: 100%;
    min-height: 48px;
  }
  .actions button { min-width: 84px; font-size: 14px; }
  .actions .fold, .actions .check, .actions .call { padding: 10px 14px; border-radius: 12px; }
  .actions .raise, .actions .bet, .actions .allin { padding: 10px 14px; border-radius: 12px; }
  .actions input[type="range"] { width: min(160px, 28vw); }
  .actions button { min-height: 44px; flex: 1 1 30%; }
  .topbar { padding: 8px; }
  .gate-card { margin: 3vh auto; }
  .showdown {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 25;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    background: rgba(0, 0, 0, 0.5);
  }
  .sd-panel {
    width: min(88vw, 340px);
    max-height: min(72dvh, 560px);
    overflow: auto;
    margin: 0;
  }
}

@media (min-width: 1100px) and (orientation: landscape) {
  .rail { width: min(96vw, 1180px, calc(min(64vh, 560px) * 2.25)); aspect-ratio: 2.25 / 1; }
  .card { width: 60px; height: 84px; }
}
