:root {
  --felt: #1a5c38;
  --felt-dark: #124327;
  --bg: #0d2318;
  --card-w: 59px;
  --card-h: 82px;
  --gold: #e8c34a;
  --red: #d64545;
  --ink: #1c2430;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--felt) 0%, var(--bg) 90%);
  color: #eef3ee;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.view { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ------------------------------ home / lobby ------------------------------ */

.home-card {
  background: rgba(10, 26, 18, 0.75);
  border: 1px solid rgba(232, 195, 74, 0.25);
  border-radius: 16px;
  padding: 40px 48px;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; min-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.logo { font-size: 2.1rem; letter-spacing: 1px; font-weight: 800; color: #fff; text-align: center; }
.logo span { color: var(--gold); }
.logo.small { font-size: 1rem; }

.tagline { color: #9fbfae; font-size: .85rem; text-align: center; }

input {
  background: #0b1f14; color: #fff; border: 1px solid #2e5941;
  border-radius: 8px; padding: 12px 14px; font-size: 1rem; width: 100%;
  text-align: center; outline: none;
}
input:focus { border-color: var(--gold); }
#code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; }

.join-row { display: flex; gap: 8px; width: 100%; }

.btn {
  background: #274c38; color: #fff; border: 1px solid #3c7154;
  padding: 12px 22px; border-radius: 8px; font-size: 1rem; cursor: pointer;
  width: 100%; transition: transform .08s, background .15s;
}
.btn:hover:not(:disabled) { background: #336249; transform: translateY(-1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--gold); border-color: #b8952c; color: #241d05; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #f2d269; }
.btn.subtle { background: transparent; border-color: #33503f; color: #8fae9c; }
.btn.tiny { width: auto; padding: 5px 14px; font-size: .8rem; }
.btn.danger { background: #6b2a2a; border-color: #a04545; }
.btn.danger:hover:not(:disabled) { background: #8a3535; }
.btn.allin { background: #7a3fa0; border-color: #9d5cc4; }
.btn.allin:hover:not(:disabled) { background: #944ec2; }

.status { color: #9fbfae; font-size: .85rem; min-height: 1.2em; text-align: center; }

.room-code {
  background: #0b1f14; border: 1px dashed var(--gold); color: var(--gold);
  padding: 4px 14px; border-radius: 8px; letter-spacing: 6px; font-weight: 800;
}
.room-code.small { font-size: .8rem; padding: 2px 10px; letter-spacing: 3px; }

.menu-link { color: #8fae9c; font-size: .8rem; text-decoration: none; margin-top: 4px; }
.menu-link:hover { color: var(--gold); }

.lobby-list { list-style: none; width: 100%; }
.lobby-list li {
  padding: 9px 14px; border-bottom: 1px solid #234534;
  display: flex; justify-content: space-between; font-size: 1rem;
}
.lobby-list .host-tag { color: var(--gold); font-size: .8rem; }

/* ------------------------------ game layout ------------------------------ */

/* Fixed-height flex column that never scrolls (see fitGame in client.js,
   which shrinks the card size until the board fits any viewport). */
#view-game {
  justify-content: space-between;
  height: 100dvh; overflow: hidden; gap: 4px;
  /* Keep clear of notches / rounded corners on modern phones. */
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.top-bar {
  width: 100%; display: flex; justify-content: flex-end; align-items: center;
  color: #9fbfae; font-size: .9rem; position: relative; flex-shrink: 0;
}
.top-right { display: flex; gap: 8px; align-items: center; }
#hand-label {
  position: absolute; left: 50%; top: 2px; transform: translateX(-50%);
  color: #cfe8da; font-size: .85rem; white-space: nowrap;
}

.opponents {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
  margin-top: 4px; min-height: 100px;
}

.seat {
  background: #16302257; border: 2px solid transparent; border-radius: 12px;
  padding: 8px 12px; text-align: center; min-width: 108px; position: relative;
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 18px rgba(232,195,74,.45); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 10px rgba(232,195,74,.35); }
  50% { box-shadow: 0 0 22px rgba(232,195,74,.65); }
}
.seat.folded { opacity: .4; }
.seat.gone { opacity: .3; filter: grayscale(1); }
.seat .seat-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.seat .seat-chips { font-size: .85rem; color: #bcd8c8; }
.seat .seat-bet { font-size: .8rem; color: var(--gold); min-height: 1.1em; }
.seat .badges { display: flex; gap: 4px; justify-content: center; margin-top: 2px; flex-wrap: wrap; }
.badge {
  font-size: .62rem; padding: 1px 7px; border-radius: 9px; font-weight: 700; letter-spacing: .3px;
}
.badge.dealer { background: var(--gold); color: #241d05; }
.badge.sb { background: #2c5340; color: #cfe8da; }
.badge.bb { background: #3a6d54; color: #dff0e6; }
.badge.allin { background: #7a3fa0; color: #fff; }
.badge.folded { background: #444; color: #ccc; }
.badge.offline { background: var(--red); color: #fff; }
.seat .mini-cards { display: flex; justify-content: center; gap: 3px; height: 30px; margin-top: 4px; }

/* ------------------------------ table ------------------------------ */

.table-zone {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; min-height: 160px;
}
.pot-display { color: var(--gold); font-weight: 800; font-size: 1.15rem; }
.community-cards { display: flex; gap: 8px; min-height: var(--card-h); }
.phase-label { color: #9fbfae; font-size: .85rem; text-transform: uppercase; letter-spacing: 2px; }

.turn-banner { text-align: center; font-size: 1.05rem; font-weight: 700; min-height: 1.5em; color: var(--gold); }
.turn-banner.waiting { color: #9fbfae; font-weight: 400; }
.turn-timer { text-align: center; font-size: .9rem; color: #9fbfae; min-height: 1.2em; }
.turn-timer.urgent { color: var(--red); font-weight: 800; animation: pulse 1s infinite; }

/* ------------------------------ cards ------------------------------ */

/* Card faces/backs are the real SVG deck (public/cards/*.svg) — the <img>
   IS the card, this class just handles layout/sizing/interaction chrome
   around it. Aspect ratio matches the source art's 500x700 viewBox. */
.card {
  width: var(--card-w); height: var(--card-h);
  position: relative; flex-shrink: 0;
  border-radius: 8px;
  display: block;
  user-select: none;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,.35));
}
.card img { width: 100%; height: 100%; display: block; border-radius: 8px; }
.card.back { background: url('cards/back.svg') center / cover no-repeat; }
.card.empty { background: rgba(255,255,255,.06); border: 1px dashed rgba(255,255,255,.25); box-shadow: none; filter: none; }
.card.mini { width: 26px; height: 36px; border-radius: 4px; }
.card.winning { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,.5); }

/* ------------------------------ hand zone ------------------------------ */

.hand-zone { width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-bottom: 6px; }
.my-seat { font-size: .9rem; color: #9fbfae; text-align: center; }
.hole-cards { display: flex; gap: 8px; justify-content: center; }

.betting-controls { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 8px; }
.bet-row { display: flex; gap: 8px; align-items: center; }
.bet-row input[type="range"] { flex: 1; }
.bet-row input[type="number"] { width: 90px; text-align: right; padding: 8px; }
.action-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.action-row .btn { width: auto; flex: 1; min-width: 76px; padding: 10px 8px; font-size: .9rem; }

/* ------------------------------ overlays ------------------------------ */

.overlay {
  position: fixed; inset: 0; background: rgba(4, 12, 8, 0.82);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.panel {
  background: #12271b; border: 1px solid rgba(232,195,74,.3); border-radius: 16px;
  padding: 30px 36px; display: flex; flex-direction: column; gap: 14px;
  align-items: center; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.results-list { list-style: none; width: 100%; min-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.results-list li {
  padding: 10px 14px; border-bottom: 1px solid #234534; font-size: .95rem;
  display: flex; flex-direction: column; gap: 4px;
}
.results-list li.winner { background: rgba(232,195,74,.12); border-radius: 8px; }
.results-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.results-row .win-amt { color: var(--gold); font-weight: 700; }
.results-desc { color: #9fbfae; font-size: .82rem; }
.results-cards { display: flex; gap: 4px; margin-top: 2px; }
.results-actions { display: flex; gap: 10px; width: 100%; }

/* ------------------------------ rulebook ------------------------------ */

.rules-btn {
  position: fixed; top: 14px; left: 14px; z-index: 96;
  background: #274c3898; border: 1px solid #3c7154; color: #fff;
  padding: 7px 14px; border-radius: 20px; font-size: .85rem; cursor: pointer;
  backdrop-filter: blur(4px);
}
.rules-btn:hover { background: #336249; }
.rules-panel { max-width: 560px; text-align: left; }
.rules-panel h2 { text-align: center; }
.rules-body { max-height: 50vh; overflow-y: auto; font-size: .92rem; line-height: 1.6; color: #eef3ee; }
.rules-body ul { list-style: disc; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; }
.rules-body strong { color: var(--gold); }

/* ------------------------------ log & toast ------------------------------ */

.log {
  position: fixed; left: 10px; bottom: 10px; width: 230px; max-height: 26vh;
  overflow-y: auto; font-size: .74rem; color: #9fbfae;
  background: rgba(8,20,13,.6); border-radius: 8px; padding: 8px 10px;
  pointer-events: none;
}
.log div { padding: 1px 0; }
.log div:last-child { color: #e6f2ea; }

#toast-holder {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center;
}
.toast {
  background: #26483573; backdrop-filter: blur(6px);
  border: 1px solid #3c7154; color: #fff;
  padding: 10px 22px; border-radius: 24px; font-size: .95rem;
  animation: toastin .25s ease-out;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.toast.error { background: #5a2626d9; border-color: #a04545; }
.toast.big { font-size: 1.05rem; font-weight: 700; }
@keyframes toastin {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Touch devices: no hover-lift (sticks after a tap). */
@media (hover: none) {
  .card:hover, .card.winning:hover { transform: none; }
}

@media (max-width: 640px) {
  /* Card size is driven by fitGame (JS) in-game. */
  .home-card { padding: 28px 20px; min-width: 0; width: min(360px, calc(100vw - 24px)); }
  .log { display: none; }
  .seat { min-width: 78px; padding: 5px 7px; }

  /* Slim the top bar so the fixed Rules button and the right-hand controls
     never collide; the centered "Hand N" label is dropped on phones. */
  #hand-label { display: none; }
  .rules-btn { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); padding: 6px 11px; font-size: .78rem; }
  .top-bar { font-size: .8rem; }
  .top-right { gap: 5px; }
  .top-right .menu-link.tiny { font-size: 0; }
  .top-right .menu-link.tiny::after { content: '←'; font-size: 1.1rem; line-height: 1; }
  .room-code.small { letter-spacing: 2px; padding: 2px 7px; }
  .btn.tiny { padding: 4px 9px; }

  /* Betting controls: full-width rows, big tap targets. */
  .betting-controls { max-width: 100%; }
  .action-row .btn { min-width: 60px; font-size: .82rem; padding: 9px 4px; flex: 1; }
  .bet-row input[type="number"] { width: 72px; }

  /* Overlays hug the screen with a small margin. */
  .panel, .rules-panel { max-width: calc(100vw - 20px); padding: 22px 18px; }
}

/* Short viewports (landscape phones): poker's betting UI is vertically
   heavy, so compact the chrome — smaller banners, tighter gaps, slimmer
   controls — so it fits alongside the cards fitGame shrinks. */
@media (max-height: 500px) {
  #view-game { padding: 4px 10px; }
  .opponents { margin-top: 2px; min-height: 0; gap: 6px; }
  .seat { padding: 4px 7px; }
  .seat .mini-cards { height: auto; margin-top: 2px; }
  .table-zone { min-height: 0; gap: 4px; }
  .pot-display { font-size: 1rem; }
  .phase-label { font-size: .72rem; }
  .turn-banner { font-size: .9rem; min-height: 1.1em; }
  .turn-timer { font-size: .78rem; min-height: 1em; }
  .betting-controls { gap: 5px; }
  .action-row .btn { padding: 7px 4px; }
  .hole-cards { gap: 6px; }
}
