:root {
  --bg: #0b1d14;
  --felt: #13603b;
  --felt-dark: #0b4127;
  --rail: #4a2a17;
  --rail-light: #6b3d22;
  --text: #f4f6f4;
  --muted: #a8c4b3;
  --accent: #ffd54f;
  --danger: #ef5350;
  --panel: #13261c;
  --panel-2: #1b3427;
  --line: rgba(255, 255, 255, .12);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
input, select { -webkit-user-select: text; user-select: text; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #2a2000; border-color: transparent; font-weight: 700; }
button.warn { color: #ffcdd2; border-color: rgba(239, 83, 80, .5); }
button.big { width: 100%; padding: 12px; font-size: 16px; margin-top: 8px; }

input, select {
  font: inherit;
  color: var(--text);
  background: #0d1c14;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
label { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }
label input, label select { margin-top: 4px; }
.field { margin: 10px 0; color: var(--muted); font-size: 14px; }
.error { color: #ff8a80; min-height: 1.2em; }
.note { color: var(--muted); font-size: 13px; }
small { color: var(--muted); }

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

#lobby {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at top, #1d5a3b, var(--bg) 70%);
}
.lobby-card {
  width: 100%;
  max-width: 420px;
  background: rgba(10, 25, 18, .85);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
}
.lobby-card h1 { margin: 0; font-size: 28px; }
.sub { margin: 4px 0 10px; color: var(--muted); }
.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 6px; }
.avatar-grid button { font-size: 22px; padding: 4px 0; background: transparent; border-color: transparent; }
.avatar-grid button.on { background: var(--panel-2); border-color: var(--accent); }
.color-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.color-row button { width: 30px; height: 30px; border-radius: 50%; padding: 0; background: var(--pc); border: 3px solid transparent; }
.color-row button.on { border-color: #fff; }
details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; color: var(--accent); }

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

#game {
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

#topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 4px;
}
#topbar button { padding: 6px 9px; }
#topbar .code { font-size: 14px; white-space: nowrap; }
#topbar .code b { color: var(--accent); letter-spacing: 2px; }
.spacer { flex: 1; }

#tableWrap { flex: 1 1 auto; min-height: 300px; position: relative; }
#table { position: absolute; inset: 2px 6px; }

.felt {
  position: absolute;
  inset: 9% 15% 3%;
  border-radius: 999px;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 10px solid var(--rail);
  box-shadow: 0 0 0 2px var(--rail-light), inset 0 0 40px rgba(0, 0, 0, .55), 0 10px 30px rgba(0, 0, 0, .5);
}

/* seats around the table */
.seat {
  position: absolute;
  width: 27%;
  max-width: 170px;
  padding: 5px;
  border-radius: 12px;
  background: rgba(8, 20, 14, .82);
  border: 1px solid var(--line);
  z-index: 2;
}
.seat.offline { opacity: .55; }
.seat.target, .mehead.target, .community.target, .pot.target, .side.target, .pilebox.target { cursor: pointer; }
.seat.target { border-color: rgba(255, 213, 79, .45); }
.slot-1 { left: 0; bottom: 4%; }
.slot-2 { left: 0; top: 10%; }
.slot-3 { left: 50%; top: 0; transform: translateX(-50%); }
.slot-4 { right: 0; top: 10%; }
.slot-5 { right: 0; bottom: 4%; }

.who { display: flex; align-items: center; gap: 6px; }
.av {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: rgba(0, 0, 0, .35);
  box-shadow: 0 0 0 3px var(--pc);
}
.av.sm { width: 28px; height: 28px; font-size: 16px; }
.badge {
  position: absolute;
  font-size: 10px;
  line-height: 1;
}
.badge.dealer {
  right: -6px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 2px #000;
}
.badge.host { left: -6px; top: -8px; font-size: 13px; }
.plist .badge { position: static; display: inline-grid; margin-left: 4px; }
.info { min-width: 0; }
.nm { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 6px; font-size: 12px; color: var(--muted); }
.ch { color: var(--accent); font-weight: 600; }
.seatrow { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px; margin-top: 4px; }
.minicards { display: flex; flex-wrap: wrap; padding-left: 7px; }
.minicards .card { margin-left: -7px; }
.ministacks { display: flex; flex-wrap: wrap; gap: 3px; }

/* center of the table */
.center {
  position: absolute;
  inset: max(17%, 84px) 28% 4%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  z-index: 1;
}
.ticker {
  font-size: 12px;
  color: #d9eadf;
  background: rgba(0, 0, 0, .3);
  border-radius: 8px;
  padding: 2px 8px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.piles { display: flex; gap: 14px; }
.pilebox { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pilebox .lbl { font-size: 11px; color: var(--muted); }
.deckcard { box-shadow: 1px 1px 0 #ddd, 2px 2px 0 #aaa, 3px 3px 0 #888, 0 4px 8px rgba(0, 0, 0, .5); }
.community {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  min-height: 56px;
  width: 100%;
  padding: 4px;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, .18);
  align-items: center;
}
.pot {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 70px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, .14);
}
.pot.target, .side.target { border-color: var(--accent); background: rgba(255, 213, 79, .06); }
.potlbl { position: absolute; left: 8px; top: 4px; font-size: 12px; color: var(--accent); font-weight: 600; pointer-events: none; }
.hint { color: rgba(255, 255, 255, .5); font-size: 12px; text-align: center; padding: 4px; pointer-events: none; }

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

.card {
  position: relative;
  flex: none;
  border-radius: 6px;
  background: #fff;
  color: #111;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .45);
  overflow: hidden;
}
.card.xs { width: 20px; height: 28px; border-radius: 3px; }
.card.sm { width: 36px; height: 51px; }
.card.lg { width: 56px; height: 80px; border-radius: 8px; }
.card.red { color: #c62828; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .14) 0 3px, transparent 3px 7px),
    linear-gradient(135deg, #b71c1c, #7f0000);
  border: 2px solid #fff;
}
.card.slot { background: transparent; border: 1px dashed rgba(255, 255, 255, .3); box-shadow: none; }
.card .corner { position: absolute; left: 3px; top: 2px; font-weight: 800; line-height: 1; text-align: center; }
.card .mid { position: absolute; inset: 0; display: grid; place-items: center; }
.card.xs .corner { display: none; }
.card.xs .mid { font-size: 9px; font-weight: 800; line-height: 1; text-align: center; }
.card.sm .corner { font-size: 11px; }
.card.sm .mid { font-size: 20px; padding-top: 6px; }
.card.lg .corner { font-size: 14px; }
.card.lg .mid { font-size: 30px; padding-top: 8px; }
.card .tag { position: absolute; right: 2px; bottom: 1px; font-size: 11px; }
.card.private { background: #e9eef7; box-shadow: 0 0 0 2px #5c6bc0 inset, 0 2px 5px rgba(0, 0, 0, .45); }
.card.sel { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--accent), 0 6px 12px rgba(0, 0, 0, .6); }
.card[data-card] { cursor: pointer; transition: transform .12s; }
.card.arrive { animation: arrive .35s ease-out; }
@keyframes arrive {
  from { transform: translateY(-30px) scale(.6) rotate(-8deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- chips ---------- */

.stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 4px 2px;
  border-radius: 10px;
  --d: 24px;
}
.stack.xs { --d: 12px; padding: 1px 2px; background: rgba(0, 0, 0, .25); }
.stack.md { --d: 32px; }
.stack[data-drag] { position: absolute; transform: translate(-50%, -50%); touch-action: none; cursor: grab; background: rgba(0, 0, 0, .18); }
.stack.drag-src { opacity: .3; }
.stack.drop-hover, .seat.drop-hover, .mehead.drop-hover { box-shadow: 0 0 0 3px var(--accent); }
.pot.drop-hover, .side.drop-hover, .community.drop-hover { background: rgba(255, 213, 79, .12); }
.ghost-drag {
  position: fixed !important;
  z-index: 100;
  transform: translate(-50%, -50%) scale(1.08);
  pointer-events: none;
  background: rgba(0, 0, 0, .35);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6));
}
.cols { display: flex; gap: 3px; align-items: flex-end; }
.col { display: flex; flex-direction: column; align-items: center; }
.col[data-chip] { cursor: pointer; }
.col.none { opacity: .35; }
.pile { position: relative; width: var(--d); height: calc(var(--d) * .62 + (var(--n) - 1) * var(--d) * .14); }
.disc {
  position: absolute;
  left: 0;
  bottom: calc(var(--k) * var(--d) * .14);
  width: var(--d);
  height: calc(var(--d) * .62);
  border-radius: 50%;
  background: var(--c);
  color: var(--t);
  border: calc(var(--d) * .1) dashed color-mix(in srgb, var(--t) 55%, transparent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .25);
  font-size: calc(var(--d) * .3);
  font-weight: 800;
  display: grid;
  place-items: center;
  line-height: 1;
}
.disc.ghost { opacity: .5; }
.disc.solo {
  position: static;
  --d: 34px;
  height: 34px;
  font-size: 12px;
  flex: none;
}
.cnt { font-size: 11px; color: var(--muted); line-height: 1.1; }
.total { font-size: 11px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stack.xs .total { font-size: 10px; }
.empty { color: var(--muted); font-size: 11px; }

/* ---------- dealer controls ---------- */

#dealerBar {
  flex: none;
  padding: 4px 8px;
  background: linear-gradient(#2a1a0f, #1c120a);
  border-top: 1px solid var(--rail-light);
}
#dealerBar .row { display: flex; gap: 6px; align-items: center; padding: 2px 0; }
#dealerBar .row.scroll { overflow-x: auto; scrollbar-width: none; }
#dealerBar .row.scroll button { flex: none; padding: 6px 10px; font-size: 14px; }
#dealerBar .tip { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; border-radius: 0; padding: 6px 10px; font-size: 14px; background: transparent; }
.seg button.on { background: var(--accent); color: #2a2000; font-weight: 700; }

/* ---------- my area ---------- */

#mine {
  flex: none;
  background: linear-gradient(#10261b, #0b1a12);
  border-top: 1px solid var(--line);
  padding: 6px 8px 8px;
}
.mehead { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 10px; }
.mehead.target { background: rgba(255, 213, 79, .07); }
.mehead .nm { font-size: 15px; }
.mehead .cc, .mehead .in { font-size: 13px; color: var(--muted); }
.mehead .ch { font-size: 14px; }
.hand { display: flex; gap: 6px; padding: 14px 4px 6px; overflow-x: auto; min-height: 100px; align-items: flex-end; scrollbar-width: thin; }
.hand .hint { align-self: center; }
.rail {
  display: flex;
  gap: 8px;
  height: 116px;
  padding: 6px;
  border-radius: 14px;
  background: linear-gradient(#5a341c, #3f2413);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .6);
}
.mainwrap { flex: none; display: flex; align-items: center; padding: 0 4px; border-right: 1px solid rgba(255, 255, 255, .15); }
.stack.main { background: rgba(0, 0, 0, .2); padding: 4px 6px; }
.side { position: relative; flex: 1; border-radius: 10px; border: 1px dashed transparent; display: flex; align-items: center; justify-content: center; }
.buttons { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.buttons button { flex: 1; padding: 8px 6px; font-size: 14px; white-space: nowrap; }

/* ---------- floating action bar ---------- */

#bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  width: min(96vw, 620px);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border-radius: 14px;
  background: rgba(18, 32, 25, .97);
  border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
}
#bar .msg { flex: 1 1 200px; font-size: 14px; }
#bar button { flex: 1 0 auto; padding: 9px 10px; }

/* ---------- sheets ---------- */

#sheet { position: fixed; inset: 0; z-index: 80; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100vw, 520px);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
}
.ph { display: flex; align-items: center; justify-content: space-between; }
.ph h2 { margin: 0; font-size: 19px; }
.panel h3 { margin: 12px 0 4px; font-size: 15px; color: var(--muted); }
.ledger { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.ledger th, .ledger td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.ledger th { color: var(--muted); font-weight: 600; font-size: 12px; }
.ledger tr.gone { opacity: .6; }
.pos { color: #81c784; font-weight: 700; }
.neg { color: #e57373; font-weight: 700; }
.plist { list-style: none; padding: 0; margin: 10px 0; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.plist .pn { flex: 1; font-weight: 600; }
.plist .pb { display: flex; gap: 4px; flex-wrap: wrap; }
.plist .pb button { padding: 5px 8px; font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #666; margin-left: 4px; }
.dot.on { background: #66bb6a; }
.log { list-style: none; padding: 0; margin: 10px 0; font-size: 14px; }
.log li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.counter { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.counter button { width: 42px; height: 42px; font-size: 20px; padding: 0; flex: none; }
.counter input { text-align: center; }
.two { display: flex; gap: 8px; }
.two label { flex: 1; }
.denrow { display: flex; gap: 8px; align-items: flex-end; }
.denrow input[type="color"] { width: 46px; height: 44px; padding: 2px; flex: none; margin-bottom: 10px; }
.denrow label { flex: 1; margin: 6px 0 10px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input { width: auto; margin: 0; }

#toast {
  position: fixed;
  left: 50%;
  top: calc(56px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 90;
  background: #3b1f1f;
  border: 1px solid var(--danger);
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 90vw;
  font-size: 14px;
}
#conn {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 95;
  text-align: center;
  background: #8d6e00;
  color: #fff;
  font-size: 13px;
  padding: 3px;
}

/* ---------- bigger screens ---------- */

@media (min-width: 720px) {
  .seat { padding: 8px; }
  .av { width: 42px; height: 42px; font-size: 24px; }
  .nm { font-size: 15px; }
  .card.xs { width: 30px; height: 42px; border-radius: 4px; }
  .card.xs .mid { font-size: 14px; }
  .minicards { padding-left: 10px; }
  .minicards .card { margin-left: -10px; }
  .card.sm { width: 52px; height: 74px; }
  .card.sm .corner { font-size: 14px; }
  .card.sm .mid { font-size: 28px; }
  .card.lg { width: 76px; height: 108px; }
  .card.lg .corner { font-size: 17px; }
  .card.lg .mid { font-size: 40px; }
  .hand { min-height: 130px; }
  .community { min-height: 82px; }
  .stack { --d: 30px; }
  .stack.xs { --d: 16px; }
  .stack.md { --d: 38px; }
  .rail { height: 136px; }
  .center { inset: max(18%, 104px) 27% 5%; }
}

/* ---------- small-screen tightening ---------- */

.potbtn { position: absolute; right: 6px; top: 3px; padding: 2px 8px; font-size: 12px; z-index: 3; }
@media (max-width: 719px) {
  #topbar { gap: 4px; padding-left: 6px; padding-right: 6px; }
  #topbar button { padding: 6px 7px; }
  #topbar .code { font-size: 13px; }
  .pot .stack { --d: 20px; }
}

/* Laptops / landscape tablets: table on the left, your seat on the right */
@media (min-width: 900px) and (orientation: landscape) {
  #game {
    max-width: 1500px;
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto auto 1fr;
  }
  #topbar { grid-column: 1 / -1; }
  #tableWrap { grid-column: 1; grid-row: 2 / 4; }
  #dealerBar { grid-column: 2; grid-row: 2; border: 1px solid var(--rail-light); border-radius: 14px; margin: 0 8px 8px 0; }
  #dealerBar .row.scroll { flex-wrap: wrap; overflow: visible; }
  #dealerBar .row:first-child { flex-wrap: wrap; }
  #mine { grid-column: 2; grid-row: 3; overflow-y: auto; border: 1px solid var(--line); border-radius: 14px; margin: 0 8px 8px 0; }
  #dealerBar[hidden] + #mine { grid-row: 2 / 4; }
  .hand { flex-wrap: wrap; overflow: visible; }
  .rail { height: auto; min-height: 220px; flex-direction: column; }
  .mainwrap { border-right: 0; border-bottom: 1px solid rgba(255, 255, 255, .15); padding: 0 0 6px; justify-content: center; }
  .side { min-height: 150px; }
  .felt { inset: 9% 12% 4%; }
  .center { inset: max(18%, 110px) 25% 6%; }
}
