:root {
  --bg: #0f1215;
  --surface: #171b20;
  --surface-2: #1f242b;
  --line: #2b313a;
  --text: #e7e9ec;
  --muted: #8b949f;
  --accent: #eef0f2;
  --accent-ink: #111418;
  --felt: #13181d;
  --red: #d8443a;
  --card: #f2f4f6;
  --card-ink: #15181c;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.invisible { visibility: hidden; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0 14px;
  min-height: 44px;
  font-weight: 600;
  white-space: nowrap;
}
a.btn { display: inline-grid; place-items: center; text-decoration: none; color: var(--text); }
a.btn.primary { color: var(--accent-ink); }
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
input[type="text"], input[type="number"], input[inputmode] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  min-height: 44px;
  width: 100%;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; min-height: 40px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; margin: 0; }

/* ---------- home ---------- */
.home { max-width: 440px; margin: 0 auto; padding: 28px 16px 40px; }
.home h1 { font-size: 22px; margin: 0 0 4px; }
.home p { margin: 0 0 20px; }
.form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; min-height: 36px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface-2); color: var(--text); }
.seg button:disabled { cursor: not-allowed; opacity: 0.6; line-height: 1.15; padding: 4px 0; }
.seg button small { display: block; font-size: 11px; font-weight: 500; }
.err { color: #ff8a80; font-size: 13px; min-height: 18px; }

/* ---------- game layout ---------- */
.game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  min-height: 48px;
}
.topbar .title { font-weight: 700; }
/* Wordmark: heavy, slanted, tight, in plain white. */
.logo {
  display: inline-block;
  font-family: "Arial Black", "Helvetica Neue", system-ui, sans-serif;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: -0.045em;
  line-height: 1;
  color: #fff;
  transform: skewX(-9deg);
  white-space: nowrap;
  text-decoration: none;
  padding-right: 2px;
}
.topbar .logo { margin-right: 6px; }
/* Phones: a smaller wordmark and tighter icons so the top bar fits on one line. */
@media (max-width: 759px) {
  .topbar { gap: 6px; padding-left: 10px; }
  .topbar .logo { font-size: 16px; margin-right: 2px; }
  .topbar .kind, .topbar .handno { display: none; }
  .topbar .iconbtn { width: 36px; }
}
/* Landing page: a big centred wordmark with the tagline under it. */
.home .hero { display: grid; justify-items: center; text-align: center; margin: 16px 0 26px; }
.home .hero .logo { font-size: 46px; margin: 0 0 10px; justify-self: center; }
.home .hero p { margin: 0; font-size: 15px; }
.home .logo, .final .logo { font-size: 30px; margin: 4px 0 22px; justify-self: start; }
.topbar .spacer { flex: 1; }
.topbar .conn { color: #ffb74d; font-size: 13px; }
.iconbtn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 10px;
  font-size: 22px; line-height: 1;
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn { color: var(--muted); position: relative; }
.iconbtn.on { color: var(--accent); }
.badge {
  position: absolute; top: 6px; right: 4px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 800; display: grid; place-items: center;
}
.small { font-size: 13px; }

.table-wrap { flex: 1; min-height: 0; position: relative; padding: 8px 14px 4px; }
.table {
  position: absolute;
  inset: 40px 34px 50px;
  border: 2px solid var(--line);
  background: var(--felt);
  border-radius: 999px;
}
.center {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 6px;
  width: max-content;
}
.pot { font-size: 14px; color: var(--muted); }
.pot b { color: var(--text); font-weight: 700; }
/* Room for five cards, filled from the left, so the flop stays put as the turn and river land. */
.board { display: flex; gap: 3px; min-height: 52px; align-items: center; width: calc(5 * 35px + 4 * 3px); }
.status-line { font-size: 13px; color: var(--muted); text-align: center; min-height: 18px; }

/* ---------- cards ---------- */
/* Four-colour deck: the whole card takes the suit colour. */
.card {
  width: 35px; height: 50px;
  border-radius: 6px;
  color: #fff;
  display: inline-grid;
  grid-template-rows: 1fr 1fr;
  justify-items: center;
  align-items: center;
  font-weight: 800;
  font-size: 19px;
  line-height: 1;
  padding: 4px 0 5px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.card i { font-style: normal; font-size: 17px; }
.card.ss { background: #3a3f48; }
.card.sh { background: #c8353b; }
.card.sd { background: #2368c9; }
.card.sc { background: #2b8a46; }
.card.back { background: #262b33; border: 2px solid #4a515c; }
/* Hole cards are never bigger than the board: yours match it, others are smaller. */
.card.sm { width: 28px; height: 40px; font-size: 14px; border-radius: 5px; padding: 3px 0 4px; }
.card.sm i { font-size: 12px; }
.card.lg { width: 35px; height: 50px; }
.card { position: relative; transition: transform 0.15s ease-out, opacity 0.15s; }
.card.dim { opacity: 0.45; }
/* Your cards that are (or will be) shown to everyone: raised, with an eye. */
.card.open, .card.queued { transform: translateY(-9px); opacity: 1; }
.card .eye {
  position: absolute; top: -9px; right: -9px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.card .eye svg { width: 14px; height: 14px; }
.card.queued .eye { background: var(--surface-2); color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card.deal { animation: deal 0.32s ease-out backwards; }
@keyframes deal {
  from { opacity: 0; transform: translateY(-10px) rotateY(80deg) scale(0.9); }
  to { opacity: 1; transform: none; }
}
.cards { display: flex; gap: 3px; position: relative; }
/* Your hand's strength: plain text off the table, bottom corner. */
.table-wrap > .strength {
  position: absolute; left: 16px; bottom: 6px; z-index: 3;
  font-size: 13px; font-weight: 600; color: #fff; pointer-events: none;
}
.cards .gap { width: 10px; }
.cardbtn { border: 0; padding: 0; background: none; border-radius: 7px; display: inline-flex; }
.cardbtn:hover .card:not(.queued) { transform: translateY(-4px); opacity: 0.85; }

/* ---------- seats ---------- */
.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 84px;
  display: grid;
  justify-items: center;
  gap: 2px;
  z-index: 2;
}
.seat .box {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 6px 5px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.seat .name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .stack { font-size: 14px; font-weight: 700; }
.seat .tag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); min-height: 13px; }
.seat .tag.clock { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0; }
.seat .tag.clock .countdown { color: inherit; }
.seat .tag.clock.bank { color: #e5735a; }
.seat.turn .box { border-color: var(--accent); }
.seat.folded .box, .seat.out .box { opacity: 0.45; }
.seat.me .box { background: var(--surface-2); }
.seat.offline .name::after { content: " ·"; color: #ffb74d; }
.seat .won { color: var(--accent); font-weight: 700; font-size: 13px; }
.seat .won.pop { animation: pop 0.5s ease-out; }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.2); opacity: 1; } 100% { transform: none; } }
.seat.winner .box { border-color: var(--accent); }
.bubble {
  position: absolute; transform: translate(-50%, -50%);
  max-width: 140px; width: max-content;
  background: var(--text); color: var(--bg);
  font-size: 12px; line-height: 1.3; padding: 4px 8px; border-radius: 10px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  z-index: 5;
}
.bubble.in { animation: fadein 0.2s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translate(-50%, calc(-50% + 4px)); } }
.seat .label { font-size: 11px; color: var(--accent); white-space: nowrap; }
.seat .cards { min-height: 42px; }
.seat.empty button {
  width: 64px; height: 40px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.timer { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.timer.bank { background: #e5735a; }
.bet {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 4;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.layer { position: absolute; inset: 0; }
.dealer {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #f4f1e8;
  color: #15181c;
  border: 2px solid #c9c2ad;
  font-size: 12px; font-weight: 800;
  display: grid; place-items: center;
  z-index: 3;
  transition: left 0.7s ease-in-out, top 0.7s ease-in-out;
}

/* ---------- action panel ---------- */
/* Fixed height whether or not it's your turn, so the table never jumps. */
.panel {
  padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  align-content: end;
  height: calc(150px + env(safe-area-inset-bottom));
  flex: none;
  position: relative;
  z-index: 5;
}
.panel .msg { text-align: center; color: var(--muted); min-height: 24px; display: grid; place-items: center; }
.panel .msg.small { min-height: 16px; font-size: 13px; }
/* Action grid: sizes, slider, amount, then Fold / Call / Raise. On phones the slider stands
   upright right above the Raise button. */
.actgrid {
  display: grid; gap: 8px;
  grid-template-columns: 1fr 1.2fr 1.3fr;
  grid-template-areas: "f c r";
}
.actgrid.raise { grid-template-areas: "q q q" "s s i"; grid-template-columns: 1fr 1.2fr 1.3fr; }
.actgrid.raise > .btn { grid-row: 3; }
.actgrid.raise > input { min-height: 32px; }
/* Phones: sizes on the left, an upright slider above the Raise button that reaches up over the
   table edge, and no typed amount (the Raise button shows it). */
.actgrid.raise.vert { grid-template-columns: 1fr 1.15fr 1fr; grid-template-areas: "q q s"; }
.actgrid.raise.vert > .btn { grid-row: 2; }
.actgrid.raise.vert > .slider { margin-top: -78px; }
.actgrid > .quick { grid-area: q; }
.actgrid > .slider { grid-area: s; }
.actgrid > .btn:nth-last-child(3) { grid-column: 1; }
.actgrid > .btn:nth-last-child(2) { grid-column: 2; }
.actgrid > .btn:nth-last-child(1) { grid-column: 3; }
.actgrid > input { grid-area: i; text-align: right; font-weight: 700; min-height: 40px; }
.actgrid > .btn { min-height: 52px; font-size: 16px; }
.actgrid > .btn small { display: block; font-size: 12px; font-weight: 600; opacity: 0.85; }
.quick { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 5px; }
.vert .quick { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
.quick .btn { padding: 0 4px; }
.slider { position: relative; height: 32px; touch-action: none; cursor: pointer; outline: none; }
.slider .track {
  position: absolute; inset: 0; border-radius: 16px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
}
.slider .fill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255, 255, 255, 0.16); }
.slider .thumb {
  position: absolute; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.slider .thumb::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--accent-ink); opacity: 0.35; }
.slider:focus-visible .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.slider.vert { height: auto; width: 46px; justify-self: center; }
.slider.vert .track { border-radius: 23px; }
.slider.vert .fill { top: auto; right: 0; width: auto; }
.slider.vert .thumb { top: auto; left: 50%; width: 36px; height: 36px; margin: 0 0 -18px -18px; }
.slider.vert .thumb::after { inset: 13px; }
.acts { display: grid; grid-template-columns: 1fr 1.2fr 1.3fr; gap: 8px; }
.acts .btn { min-height: 52px; font-size: 16px; }
.pre { display: flex; gap: 8px; justify-content: center; }
.pre label {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; min-height: 38px;
}
.pre label.on { border-color: var(--accent); }
.bar { display: flex; gap: 8px; justify-content: center; }
.bar .btn { flex: 1; max-width: 220px; }
.countdown { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- sheets ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 20;
}
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet header { display: flex; align-items: center; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line); }
.sheet header h2 { font-size: 16px; margin: 0; flex: 1; }
.sheet .body { overflow-y: auto; padding: 14px 16px 18px; display: grid; gap: 12px; align-content: start; }
.menu { display: grid; }
.menu button {
  text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line);
  min-height: 52px; padding: 0 4px; font-size: 16px;
}
.menu button:last-child { border-bottom: 0; }
.menu button.danger { color: #ff8a80; }
/* Chat on phones: see the table through it. */
.overlay.see-through { background: rgba(0, 0, 0, 0.12); }
.overlay.see-through .sheet { background: rgba(23, 27, 32, 0.78); max-height: 58dvh; }
.overlay.see-through .sheet .chat { height: min(44dvh, 420px); }
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; border-bottom: 1px solid var(--line); }
}

/* ---------- chat ---------- */
.shell { height: 100dvh; }
.side { display: none; }
.chat { display: grid; grid-template-rows: 1fr auto; gap: 10px; min-height: 0; height: 100%; }
.sheet .chat { height: min(60dvh, 520px); }
.chat-list { overflow-y: auto; display: grid; gap: 6px; align-content: start; min-height: 0; }
.chat-msg { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.chat-msg b { color: var(--muted); font-weight: 600; margin-right: 6px; }
.chat-msg.mine b { color: var(--accent); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.chat-form .send { color: var(--accent); font-weight: 600; }
/* Wide screens: a compact chat box in the bottom-right corner, beside the action bar, so the
   table keeps the full width. */
@media (min-width: 1280px) {
  .side {
    display: grid; grid-template-rows: auto 1fr;
    position: fixed; left: 16px; bottom: 0; width: 290px; height: 160px;
    padding: 0 0 10px; z-index: 6;
  }
  /* No box: the chat sits straight on the background. */
  .side-head { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); min-height: 24px; display: flex; align-items: center; }
  .side .chat-msg { font-size: 13px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
  .side .chat-form input, .side .chat-form .btn { min-height: 34px; }
  .side .chat-form input { background: rgba(255, 255, 255, 0.04); border-color: transparent; }
  .side .chat-form input:focus { border-color: var(--line); }
}

/* ---------- ledger ---------- */
table.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
table.ledger th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 4px 6px; }
table.ledger th:first-child, table.ledger td:first-child { text-align: left; }
table.ledger td { text-align: right; padding: 7px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.pos { color: var(--accent); }
.neg { color: #ff8a80; }
.settle { display: grid; gap: 6px; }
.settle div { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.note { font-size: 13px; color: var(--muted); }
h3 { margin: 6px 0 0; font-size: 14px; }

/* ---------- history ---------- */
.hands { display: grid; gap: 6px; }
.hands button {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center;
  text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.replay-board { display: grid; gap: 6px; justify-items: center; background: var(--felt); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.replay-players { display: grid; gap: 4px; }
.replay-players div { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.log { display: grid; gap: 2px; font-size: 14px; }
.log div { padding: 3px 6px; border-radius: 6px; color: var(--muted); }
.log div.past { color: var(--text); }
.log div.cur { background: var(--surface-2); color: var(--text); font-weight: 600; }
.stepper { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; position: sticky; bottom: 0; background: var(--surface); padding-top: 6px; }

/* ---------- final ---------- */
.final { max-width: 560px; margin: 0 auto; padding: 24px 16px 40px; display: grid; gap: 14px; }
.final h1 { margin: 0; font-size: 22px; }

.toast {
  position: fixed; left: 50%; top: calc(56px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px;
  z-index: 30; font-size: 14px; max-width: 90vw;
}

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  .table { inset: 50px 70px 60px; }
  .seat { width: 116px; }
  .seat .name { font-size: 13px; }
  .seat .stack { font-size: 15px; }
  .card { width: 58px; height: 82px; font-size: 28px; border-radius: 8px; }
  .card i { font-size: 25px; }
  .card.sm { width: 40px; height: 56px; font-size: 20px; border-radius: 6px; }
  .card.sm i { font-size: 17px; }
  .card.lg { width: 50px; height: 70px; font-size: 25px; border-radius: 8px; }
  .card.lg i { font-size: 22px; }
  .seat .cards { min-height: 56px; }
  .board { min-height: 84px; gap: 6px; width: calc(5 * 58px + 4 * 6px); }
  .table-wrap > .strength { left: auto; right: 28px; bottom: 16px; font-size: 15px; }
  .panel { max-width: 640px; width: 100%; margin: 0 auto; }
  /* Keep the felt in natural proportions however wide the window is. */
  .table-wrap { container-type: size; }
  .table {
    inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%);
    height: calc(100cqh - 110px);
    width: min(100cqw - 140px, (100cqh - 110px) * 1.85);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card.deal, .seat .won.pop, .bubble { animation: none; }
  .dealer { transition: none; }
}
.final .logo { justify-self: center; }
