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

:root {
  --bg: #1b1730;
  --bg2: #120f22;
  --panel: #2b2348;
  --panel2: #352a57;
  --felt1: #0f4d28;
  --felt2: #0a3a1e;
  --gold: #ffd23f;
  --gold2: #e0a800;
  --cream: #fdf6e3;
  --blue: #4895ef;
  --red: #e63946;
  --green: #3fae4a;
  --line: #0a0818;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.25) 0 2px, transparent 2px 4px),
    radial-gradient(1200px 700px at 50% 0%, var(--panel2), var(--bg) 60%),
    var(--bg);
  color: var(--cream);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  image-rendering: pixelated;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
}

/* ---------- buttons / inputs ---------- */

.btn {
  font-family: inherit;
  font-size: 12px;
  color: var(--cream);
  background: var(--panel);
  border: 3px solid var(--line);
  padding: 12px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line), inset 0 2px 0 rgba(255, 255, 255, 0.12);
  text-transform: uppercase;
  image-rendering: pixelated;
  user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.big { font-size: 14px; padding: 16px 20px; width: 100%; }
.btn.small { font-size: 9px; padding: 8px 10px; }
.btn.gold { background: var(--gold); color: #3a2b00; }
.btn.green { background: var(--green); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.connected { background: var(--red); color: #fff; }

.txt, .sel {
  font-family: inherit;
  font-size: 13px;
  color: var(--cream);
  background: var(--bg2);
  border: 3px solid var(--line);
  padding: 14px;
  outline: none;
  width: 100%;
  text-transform: uppercase;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.5);
}
.txt::placeholder { color: #6b6390; }
.txt:focus, .sel:focus { border-color: var(--gold); }
.txt.code {
  text-align: center;
  letter-spacing: 0.6em;
  font-size: 20px;
  font-weight: bold;
}
.sel { text-transform: uppercase; cursor: pointer; }

.lbl {
  display: block;
  font-size: 10px;
  color: #b8aed8;
  margin: 14px 0 6px;
  letter-spacing: 0.1em;
}

.panel {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.45), inset 0 0 0 3px var(--panel2);
  padding: 22px;
}
.panel-title { font-size: 12px; color: var(--gold); margin-bottom: 8px; }
.menu-panel > .btn { margin-top: 7px; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #7a70a5;
  font-size: 10px;
  margin: 18px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 3px;
  background: var(--line);
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.06);
}

.err { color: var(--red); font-size: 10px; margin-top: 14px; text-align: center; line-height: 1.8; }
.wallet-status { color: #9fd8ae; font-size: 8px; text-align: center; line-height: 1.8; margin-top: 16px; word-break: break-all; }
.wallet-status.connected { color: var(--gold); word-break: break-all; }
.wallet-box { max-width: 420px; }

/* ---------- menu ---------- */

#screen-menu {
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-inner { width: min(430px, 92vw); padding: 24px 0; }
.logo {
  text-align: center;
  font-size: clamp(26px, 6vw, 44px);
  line-height: 1.25;
  text-shadow: 0 4px 0 var(--line);
  margin-bottom: 6px;
}
.logo-a { color: var(--cream); }
.logo-b { color: var(--gold); }
.tagline { text-align: center; font-size: 9px; color: #8f86b8; margin-bottom: 26px; letter-spacing: 0.2em; }
.fineprint { text-align: center; font-size: 8px; color: #6b6390; margin-top: 20px; line-height: 2; }
.site-footer { margin-top: 24px; text-align: center; color: #6b6390; font-size: 7px; line-height: 1.8; }
.site-footer a { color: #9fd8ae; text-decoration: none; }
.site-footer a:hover { color: var(--gold); text-decoration: underline; }
.escrow-panel { margin-top: 14px; }
.escrow-buttons { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.escrow-note { color: #8d86aa; font-size: 7px; line-height: 1.7; text-align: center; margin-top: 7px; }
.table-escrow { min-height: 0; margin: 8px auto 0; }
.host-brand { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 28px; margin: 6px auto; color: var(--cream); font-size: 9px; text-align: center; }
.host-brand img { width: 30px; height: 30px; object-fit: cover; image-rendering: pixelated; border: 2px solid var(--gold); }
.host-brand.compact { margin: 0 8px; min-width: 0; font-size: 7px; }
.host-brand.compact img { width: 22px; height: 22px; }
.host-brand-editor { display: grid; gap: 6px; margin-bottom: 12px; }
.file-input { color: var(--cream); font-family: inherit; font-size: 8px; max-width: 100%; }

.join-row { display: flex; gap: 10px; margin-top: 6px; }
.join-row .code { flex: 1; }

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

#screen-lobby { display: flex; align-items: center; justify-content: center; }
.lobby-inner { width: min(520px, 92vw); padding: 20px 0; }
.lobby-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.room-code { font-size: 11px; color: #b8aed8; }
.code-big {
  color: var(--gold);
  font-size: 26px;
  letter-spacing: 0.3em;
  text-shadow: 0 3px 0 var(--line);
}
.room-code-wrap { display: flex; align-items: center; gap: 10px; }

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}
.lobby-player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 3px solid var(--line);
  padding: 12px 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
}
.lp-avatar {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg2);
  border: 2px solid var(--line);
}
.lp-name { font-size: 11px; flex: 1; word-break: break-all; }
.lp-badge {
  font-size: 8px;
  padding: 5px 7px;
  border: 2px solid var(--line);
  color: #3a2b00;
}
.badge-ready { background: var(--gold); }
.badge-host { background: var(--green); color: #fff; }
.badge-paid { background: var(--blue); color: #fff; }
.badge-wait { background: #3d3660; color: #9c93c2; }

#btn-ready { display: block; }
.lobby-msg { text-align: center; font-size: 10px; color: #b8aed8; margin-top: 14px; line-height: 2; }
.set-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.set-row .lbl { margin: 0; flex: 1; }
.set-row .sel { width: 130px; }

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

#screen-table {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 3px solid var(--line);
  font-size: 10px;
  z-index: 5;
  flex-wrap: wrap;
}
.tb-room { color: #b8aed8; }
.tb-room span { color: var(--gold); letter-spacing: 0.15em; }
.tb-hand, .tb-pot { color: #b8aed8; }
.tb-hand span { color: var(--cream); }
.tb-pot span { color: var(--gold); }
.tb-right { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: clamp(6px, 1.5vw, 18px);
  min-height: 0;
}

.felt {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255, 255, 255, 0.05) 0 30%, transparent 70%),
    repeating-linear-gradient(45deg, var(--felt1) 0 3px, var(--felt2) 3px 6px),
    var(--felt1);
  border: 5px solid var(--line);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.4), inset 0 0 0 4px rgba(255, 255, 255, 0.05);
  padding: clamp(8px, 2vw, 22px);
  min-height: 0;
  position: relative;
}

.seats-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(6px, 1.5vw, 16px);
  z-index: 2;
}
.me-row { display: flex; justify-content: center; z-index: 3; }

.seat {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--line);
  padding: 8px 10px 10px;
  min-width: clamp(92px, 12vw, 140px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  text-align: center;
}
.seat .s-avatar {
  width: 26px;
  height: 26px;
  margin: 0 auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border: 2px solid var(--line);
}
.s-name { font-size: 9px; margin-bottom: 6px; word-break: break-all; min-height: 22px; line-height: 1.4; }
.s-chips { font-size: 11px; color: var(--gold); margin-bottom: 6px; }
.s-bet { font-size: 8px; color: #9c93c2; min-height: 12px; margin-bottom: 4px; }
.s-total { color: #9fd8ae; font-size: 8px; margin-bottom: 5px; }
.s-cards { display: flex; justify-content: center; gap: 4px; min-height: clamp(36px, 6vmin, 64px); }
.s-tag {
  display: inline-block;
  font-size: 7px;
  padding: 4px 5px;
  margin: 3px 2px 0;
  border: 2px solid var(--line);
  color: #fff;
}
.tag-dealer { background: #fff; color: #000; }
.tag-sb { background: var(--blue); }
.tag-bb { background: var(--blue); }
.tag-allin { background: var(--purple, #9b5de5); }
.tag-off { background: #55505f; }

.seat.turn-hl { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 210, 63, 0.35), 0 4px 0 rgba(0, 0, 0, 0.4); }
.seat.folded-seat { opacity: 0.45; }
.seat.mine { border-color: var(--green); }

.timer-bar {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 4px;
  background: #000;
}
.timer-bar i {
  display: block;
  height: 100%;
  background: var(--gold);
  transition: width 0.25s linear;
}

.center-row { display: flex; justify-content: center; z-index: 2; }
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 720px;
}

.video-holder {
  width: min(360px, 70%);
  aspect-ratio: 16 / 9;
  background: #000;
  border: 4px solid var(--line);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}
.video-holder.empty { width: auto; height: auto; aspect-ratio: auto; background: transparent; border: 0; box-shadow: none; overflow: visible; }
.video-holder.empty .video-hint { position: static; display: block; width: auto; height: auto; padding: 0; color: #4f7a5e; font-size: 8px; line-height: 1.8; }
.video-holder:not(.empty) { position: absolute; left: clamp(10px, 2vw, 26px); top: clamp(10px, 2vw, 26px); z-index: 4; }
.video-dragbar {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  padding: 5px 8px;
  background: rgba(10, 8, 24, 0.82);
  color: #d7cfff;
  font-size: 7px;
  letter-spacing: 0.08em;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.video-dragbar:active { cursor: grabbing; }
.video-holder iframe, .video-holder video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}
.video-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9px;
  color: #4f7a5e;
  padding: 10px;
  line-height: 2;
}

.street-label { font-size: 9px; color: #9fd8ae; letter-spacing: 0.2em; }
.community { display: flex; gap: clamp(4px, 1vw, 10px); min-height: clamp(44px, 9vmin, 92px); }
.message { font-size: 11px; color: var(--cream); text-shadow: 0 2px 0 #000; text-align: center; line-height: 1.8; min-height: 20px; }
.play-by-play { position: absolute; left: 50%; top: 67%; transform: translateX(-50%); width: min(440px, 48%); height: 70px; overflow: hidden; padding: 4px 8px; background: transparent; border: 0; color: #c8d8cd; font-size: 8px; line-height: 1.5; text-align: center; text-shadow: 0 2px 0 #062414; z-index: 3; }
.play-by-play-title { color: var(--gold); margin-bottom: 3px; }
.play-by-play-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-indicator { color: var(--gold); text-align: center; margin-bottom: 3px; }

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

.card {
  position: relative;
  width: clamp(30px, 8.5vmin, 84px);
  aspect-ratio: 190 / 270;
  background: var(--cream);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: dealIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.card img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
}
.seat .card { width: clamp(28px, 5vmin, 52px); }
.seat.mine .card { width: clamp(34px, 6vmin, 64px); }
.card.back { background: transparent; }
.card.back img { width: 100%; height: 100%; }
.card .card-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #111;
}
.card .card-fallback small { font-size: 9px; margin-top: 4px; }

@keyframes dealIn {
  0% { transform: translateY(-14px) scale(0.8); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ---------- actions ---------- */

.actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg2);
  border-top: 3px solid var(--line);
  flex-wrap: wrap;
  z-index: 5;
}
.actions .btn { min-width: clamp(88px, 14vw, 150px); }
.act-call { background: var(--blue); }
.act-raise { background: var(--gold); color: #3a2b00; }
.act-allin { background: #9b5de5; color: #fff; }

.raise-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 3px solid var(--line);
}
.raise-box input[type="range"] {
  width: clamp(140px, 24vw, 260px);
  accent-color: var(--gold);
  height: 28px;
}
.raise-val { font-size: 10px; color: var(--gold); min-width: 90px; text-align: center; }

/* ---------- chat ---------- */

.chat-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  max-width: 90vw;
  background: var(--panel);
  border-left: 3px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: transform .2s steps(4, end);
}
.chat-panel.closed { transform: translateX(100%); }
.chat-tab { position: fixed; right: 280px; top: 50%; transform: translateY(-50%); z-index: 31; width: 30px; height: 58px; padding: 0; border: 3px solid var(--line); background: var(--gold); color: #3a2b00; font-family: inherit; font-size: 14px; box-shadow: 0 4px 0 var(--line); cursor: pointer; }
.chat-panel.closed + .chat-tab { right: 0; }
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  font-size: 10px;
  border-bottom: 3px solid var(--line);
  color: var(--gold);
}
.chat-log { flex: 1; overflow-y: auto; padding: 10px; font-size: 9px; line-height: 2; }
.chat-log .chat-line { word-break: break-word; margin-bottom: 6px; }
.chat-line b { color: var(--gold); }
.chat-input-row { display: flex; gap: 6px; padding: 10px; border-top: 3px solid var(--line); }
.chat-input-row .txt { padding: 10px; font-size: 10px; }

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

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 24, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.overlay-box {
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.5), inset 0 0 0 4px var(--panel2);
  padding: 26px;
  text-align: center;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.winner-title { font-size: clamp(13px, 3vw, 20px); color: var(--gold); line-height: 1.8; }
.winner-sub { font-size: 10px; color: #b8aed8; margin-top: 10px; line-height: 2; }
.trophy { font-size: 44px; margin-bottom: 10px; }
.media-box .txt { margin: 12px 0; }
.media-btns { display: flex; gap: 8px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.help-box { max-width: 620px; }
.help-copy { text-align: left; color: #d8d0ef; font-size: 10px; line-height: 2; }
.help-copy p { margin: 0 0 14px; }
.help-copy b { color: var(--gold); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--line);
  color: var(--cream);
  border: 3px solid var(--gold);
  padding: 12px 18px;
  font-size: 10px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
  line-height: 1.8;
}

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  .topbar { font-size: 8px; gap: 8px; padding: 8px; }
  .topbar .btn { padding: 6px 8px; font-size: 8px; }
  .seat { min-width: 78px; padding: 6px; }
  .s-name { font-size: 7px; }
  .s-chips { font-size: 9px; }
  .s-cards { min-height: 30px; }
  .card { width: clamp(24px, 7.5vmin, 52px); }
  .video-holder { width: min(360px, 88%); }
  .chat-panel { width: min(300px, 86vw); }
  .chat-tab { right: min(300px, 86vw); }
  .actions { gap: 6px; }
  .actions .btn { min-width: 0; flex: 1 1 40%; padding: 13px 8px; }
  .raise-box { width: 100%; order: 10; justify-content: center; }
  .felt { padding: 8px; border-width: 4px; }
  .me-row { justify-content: center; }
  .play-by-play { top: 70%; width: 62%; font-size: 7px; }
  .message { font-size: 9px; }
  .street-label { font-size: 8px; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .video-holder { width: min(300px, 45vh); }
  .card { width: clamp(22px, 9vmin, 52px); }
}

@media (min-width: 821px) {
  #screen-table { padding-right: 0; }
}
