:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --panel: #1c2331;
  --border: #2d3748;
  --text: #e6edf3;
  --muted: #8b98a9;
  --gold: #d4af37;
  --gold-dim: #a8892b;
  --green: #2ea15f;
  --red: #e5534b;
  --felt: #1f5c3d;
  --felt-dark: #17452e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
/* comfortable tapping: no 300ms delay, no accidental text selection on controls */
button, .sit-btn, .card, select, .tabs button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* horizontal scroll container for wide tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
a { color: var(--gold); text-decoration: none; }
h1, h2, h3 { font-weight: 700; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

.btn {
  display: inline-block; border: none; cursor: pointer; border-radius: 8px;
  padding: 10px 18px; font-size: 15px; font-weight: 600;
  background: var(--gold); color: #14181f; transition: filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 15px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-dim); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.muted { color: var(--muted); }
.gold { color: var(--gold); }
.pos { color: #4cc38a; }
.neg { color: var(--red); }
.mono { font-variant-numeric: tabular-nums; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2d1c1c; color: #ffb4ae; border: 1px solid var(--red);
  padding: 12px 20px; border-radius: 10px; z-index: 1000; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.ok { background: #14291e; color: #7ee2b8; border-color: var(--green); }
.toast.show { opacity: 1; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 420px; max-width: 92vw; max-height: 90vh; overflow-y: auto; }
.hidden { display: none !important; }

/* ---------- landing ---------- */
.hero { text-align: center; padding: 90px 20px 60px; }
.hero .logo { font-size: 46px; letter-spacing: 2px; }
.hero .logo span { color: var(--gold); }
.hero p.tag { color: var(--muted); font-size: 18px; margin: 14px 0 30px; }
.suits { font-size: 26px; letter-spacing: 12px; margin-bottom: 18px; }
.suits .r { color: var(--red); }
.cards3 { display: flex; gap: 24px; justify-content: center; margin: 46px 0; flex-wrap: wrap; }
.infocard { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: 300px; text-align: left; }
.infocard h3 { color: var(--gold); margin-bottom: 8px; font-size: 16px; }
.infocard p { color: var(--muted); font-size: 14px; line-height: 1.5; }
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 0; }

/* ---------- app shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar .brand { font-weight: 800; letter-spacing: 1px; font-size: 17px; }
.topbar .brand span { color: var(--gold); }
.topbar .right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.balance-chip { background: var(--panel); border: 1px solid var(--gold-dim); color: var(--gold); border-radius: 999px; padding: 6px 14px; font-weight: 700; }
.tabs { display: flex; gap: 4px; padding: 10px 20px 0; background: var(--bg2); border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 600;
  padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--gold); border-bottom-color: var(--gold); }
.view { padding: 24px 20px; max-width: 1100px; margin: 0 auto; }

.lobby-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.table-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; cursor: pointer; transition: border-color .15s; }
.table-card:hover { border-color: var(--gold-dim); }
.table-card .game-badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 5px; background: var(--felt); color: #9be2bc; margin-bottom: 8px;
}
.table-card h3 { font-size: 17px; margin-bottom: 6px; }
.table-card .meta { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- poker table ---------- */
.table-wrap { position: relative; max-width: 900px; margin: 0 auto; }
.felt {
  position: relative; width: 100%; aspect-ratio: 16/9;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 75%);
  border: 10px solid #3a2b18; border-radius: 45% / 60%;
  box-shadow: inset 0 0 60px rgba(0,0,0,.5);
}
.felt .center { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); text-align: center; width: 100%; }
.board { display: flex; gap: 6px; justify-content: center; min-height: 58px; }
.pot-label { margin-top: 8px; color: #ffe9a8; font-weight: 700; font-size: 15px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.phase-label { color: #bfe6cf; font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: 1px; }

.card {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 40px; height: 56px; border-radius: 6px; background: #f7f5ef; color: #1a1a1a;
  font-weight: 800; font-size: 16px; line-height: 1; box-shadow: 0 2px 5px rgba(0,0,0,.4);
  user-select: none;
}
.card.red { color: #c0262d; }
.card.back { background: repeating-linear-gradient(45deg, #5a2a2a, #5a2a2a 4px, #6e3434 4px, #6e3434 8px); color: transparent; }
.card.sm { width: 30px; height: 42px; font-size: 12px; border-radius: 4px; }
.card .suit { font-size: 13px; }
.card.sm .suit { font-size: 10px; }

.seat-spot { position: absolute; width: 130px; transform: translate(-50%, -50%); text-align: center; }
.seat-box {
  background: rgba(13,17,23,.88); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 6px 8px; font-size: 13px;
}
.seat-box.me { border-color: var(--gold); }
.seat-box.turn { border-color: #4cc38a; box-shadow: 0 0 12px rgba(76,195,138,.5); }
.seat-box.folded { opacity: .45; }
.seat-box .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-box .st { color: var(--gold); font-weight: 600; font-size: 12px; }
.seat-box .tag { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.seat-cards { display: flex; gap: 3px; justify-content: center; margin-top: 4px; min-height: 42px; }
.bet-chip {
  position: absolute; background: rgba(0,0,0,.55); color: #ffe9a8; border-radius: 999px;
  padding: 2px 9px; font-size: 12px; font-weight: 700; transform: translate(-50%, -50%); white-space: nowrap;
}
.dealer-btn {
  position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; color: #111;
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  transform: translate(-50%, -50%); box-shadow: 0 1px 4px rgba(0,0,0,.5);
  z-index: 3;
}
.board { position: relative; z-index: 2; }
.sit-btn {
  background: rgba(212,175,55,.15); border: 1.5px dashed var(--gold-dim); color: var(--gold);
  border-radius: 10px; padding: 10px 8px; font-size: 12px; font-weight: 700; cursor: pointer; width: 100%;
}
.sit-btn:hover { background: rgba(212,175,55,.3); }

.action-bar {
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  margin: 18px auto 8px; max-width: 700px; min-height: 52px;
}
.action-bar .amount-box { display: flex; gap: 8px; align-items: center; }
.action-bar input[type=range] { width: 180px; }
.action-bar input[type=number] { width: 110px; }
.timer-bar { height: 4px; background: var(--border); border-radius: 2px; max-width: 700px; margin: 0 auto; overflow: hidden; }
.timer-bar > div { height: 100%; background: var(--green); transition: width .3s linear; }

.game-log {
  max-width: 900px; margin: 14px auto; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 12.5px; color: var(--muted);
  height: 120px; overflow-y: auto; font-family: ui-monospace, Menlo, monospace;
}

/* ---------- house (admin) view ---------- */
.god-view {
  max-width: 900px; margin: 0 auto 14px;
  background: rgba(212,175,55,.08); border: 1px solid var(--gold-dim); border-radius: 10px;
  padding: 10px 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.god-view .gv-label {
  color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: 1px; margin-right: 6px;
}
.seat-box.winning {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(212,175,55,.75);
  background: rgba(45,35,10,.92);
}
.seat-box .win-tag {
  font-size: 10px; font-weight: 800; letter-spacing: 1px; color: #14181f;
  background: var(--gold); border-radius: 4px; padding: 1px 6px; display: inline-block; margin-top: 3px;
}
.seat-box .proj { font-size: 10px; color: var(--gold); margin-top: 2px; }

/* ---------- OFC ---------- */
.ofc-boards { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.ofc-board { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; min-width: 250px; }
.ofc-board.turn { border-color: #4cc38a; box-shadow: 0 0 10px rgba(76,195,138,.4); }
.ofc-board h4 { font-size: 14px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.ofc-row { display: flex; gap: 4px; margin: 6px 0; min-height: 44px; align-items: center; }
.ofc-row .row-label { width: 20px; font-size: 10px; color: var(--muted); text-transform: uppercase; }
.ofc-slot {
  width: 30px; height: 42px; border: 1.5px dashed var(--border); border-radius: 4px;
}
.ofc-slot.drop-ok { border-color: var(--gold); background: rgba(212,175,55,.12); cursor: pointer; }
.ofc-hand { display: flex; gap: 8px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
.ofc-hand .card { cursor: pointer; width: 46px; height: 64px; font-size: 18px; }
.ofc-hand .card.selected { outline: 3px solid var(--gold); transform: translateY(-6px); }
.ofc-hand .card.staged { opacity: .35; }
.ofc-hand .card.discard-pick { outline: 3px solid var(--red); transform: translateY(6px); }
.ofc-result { font-size: 13px; margin-top: 6px; }

/* ============================================================
   MOBILE — most players are on phones, so this is the primary
   experience rather than an afterthought.
   ============================================================ */
@media (max-width: 760px) {
  /* --- shell --- */
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .brand { font-size: 12px; letter-spacing: .3px; white-space: nowrap; }
  .topbar .brand .muted { display: none; }          /* role suffix — the page makes it obvious */
  .topbar .right { gap: 6px; font-size: 13px; }
  .topbar .right .muted { display: none; }          /* name is redundant on small screens */
  .topbar .right .btn { white-space: nowrap; padding: 8px 10px; font-size: 12px; }

  /* stat cards go two-up so they don't eat the whole screen */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .stat-grid .panel { padding: 12px; }
  .stat-grid .panel > div:nth-child(2) { font-size: 21px !important; }
  .stat-grid .panel > div:first-child { font-size: 10px !important; }
  .stat-grid .panel .muted:last-child { font-size: 11px; }
  .balance-chip { padding: 5px 11px; font-size: 13px; }
  .btn { padding: 11px 16px; font-size: 15px; }      /* keep tap targets ≥44px tall */
  .btn.sm { padding: 8px 12px; font-size: 13px; }
  .view { padding: 14px 12px calc(18px + env(safe-area-inset-bottom)); }
  .container { padding: 0 14px; }

  .tabs { padding: 6px 8px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { padding: 10px 12px; font-size: 13px; white-space: nowrap; }

  .panel { padding: 15px; border-radius: 10px; }
  h2 { font-size: 19px; }

  /* --- landing --- */
  .hero { padding: 46px 16px 30px; }
  .hero .logo { font-size: 30px; letter-spacing: 1px; }
  .hero p.tag { font-size: 15px; }
  .suits { font-size: 20px; letter-spacing: 8px; }
  .cards3 { gap: 14px; margin: 28px 0; }
  .infocard { width: 100%; }

  /* --- data tables become horizontally scrollable --- */
  .two-col { grid-template-columns: 1fr; gap: 14px; }
  table.data { font-size: 13px; min-width: 560px; }
  table.data th, table.data td { padding: 8px 8px; }
  .table-scroll table.data { min-width: 620px; }
  .panel:has(> table.data) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* the rake tables are narrow enough to fit */
  #rakeTable, #rakeAgentTable { min-width: 0; font-size: 12.5px; }

  /* --- modals become bottom sheets --- */
  .modal-backdrop { align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    max-height: 92vh;
  }
  .modal input, .modal select { font-size: 16px; }   /* 16px stops iOS zoom-on-focus */
  input, select, textarea { font-size: 16px; }

  /* --- lobby --- */
  .lobby-grid { grid-template-columns: 1fr; gap: 12px; }
  .table-card { padding: 15px; }

  /* --- poker table: portrait felt --- */
  #view-table { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .felt {
    aspect-ratio: 3/4;
    border-radius: 46% / 32%;
    border-width: 6px;
  }
  .seat-spot { width: 84px; }
  .seat-box { padding: 4px 4px; font-size: 11px; border-radius: 8px; }
  .seat-box .nm { font-size: 10px; letter-spacing: -.2px; }
  .seat-box .st { font-size: 11px; }
  .seat-box .tag, .seat-box .win-tag, .seat-box .proj { font-size: 9px; }
  .seat-cards { min-height: 30px; gap: 2px; }
  .card { width: 30px; height: 42px; font-size: 13px; border-radius: 4px; }
  .card .suit { font-size: 10px; }
  .card.sm { width: 21px; height: 30px; font-size: 10px; }
  .card.sm .suit { font-size: 8px; }
  .bet-chip { font-size: 10px; padding: 1px 6px; }
  .dealer-btn { width: 17px; height: 17px; font-size: 9px; }
  .sit-btn { padding: 8px 4px; font-size: 10px; border-radius: 8px; }
  .pot-label { font-size: 13px; }
  .phase-label { font-size: 10px; }
  .board { gap: 3px; min-height: 44px; }

  /* action bar pinned to the bottom of the screen, thumb-reachable */
  .action-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    margin: 0; max-width: none;
    background: var(--bg2); border-top: 1px solid var(--border);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .action-bar:empty { display: none; }
  .action-bar .btn { flex: 1 1 auto; min-width: 84px; padding: 13px 8px; font-size: 15px; }
  .action-bar .amount-box { order: -1; width: 100%; justify-content: center; }
  .action-bar input[type=range] { flex: 1; width: auto; height: 34px; }
  .action-bar input[type=number] { width: 92px; }
  .action-bar .btn.sm { flex: 0 0 auto; min-width: 0; }
  .timer-bar { position: fixed; bottom: calc(100% - 100%); left: 0; right: 0; }
  .timer-bar { position: static; }

  .game-log { height: 88px; font-size: 11px; margin: 10px auto; }

  /* header row above the felt stays compact — one row of small controls */
  #view-table > div:first-child, #view-ofc > div:first-child { flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  #view-table h2, #view-ofc h2 { font-size: 17px; }
  #view-table > div:first-child .btn.sm,
  #view-ofc > div:first-child .btn.sm {
    font-size: 11px; padding: 8px 9px; white-space: nowrap; border-radius: 7px;
  }
  #view-table > div:first-child > div:last-child,
  #view-ofc > div:first-child > div:last-child { flex: 1 1 100%; }

  .god-view { padding: 8px 10px; gap: 5px; }
  .god-view .gv-label { font-size: 10px; letter-spacing: .5px; }

  /* --- OFC --- */
  .ofc-boards { gap: 10px; }
  .ofc-board { min-width: 0; width: 100%; padding: 11px; }
  .ofc-row { min-height: 32px; gap: 3px; }
  .ofc-slot { width: 21px; height: 30px; }
  .ofc-hand { gap: 6px; margin: 12px 0; }
  .ofc-hand .card { width: 42px; height: 58px; font-size: 17px; }
  #ofcMyTurn { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* very narrow phones */
@media (max-width: 380px) {
  .seat-spot { width: 72px; }
  .card { width: 26px; height: 37px; font-size: 12px; }
  .card.sm { width: 19px; height: 27px; font-size: 9px; }
  .action-bar .btn { min-width: 72px; font-size: 14px; padding: 12px 6px; }
  .hero .logo { font-size: 25px; }
}

/* landscape phones: keep the felt visible, shrink chrome */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topbar { padding: 5px 12px; }
  .tabs { display: none; }
  .felt { aspect-ratio: 16/9; border-radius: 44% / 58%; }
  .game-log { display: none; }
  #view-table { padding-top: 8px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
}
