:root {
  --frame: #2c2117; --frame-2: #3b2d20; --chrome: #cfc6b4; --chrome-2: #b9ae98;
  --panel: #e4dfd6; --panel-line: #b5a993; --ink: #1d1a16; --muted: #6b6151;
  --felt: #1f7a24; --felt-dark: #155a19; --rail: #262626; --gold: #e9c46a;
  --btn-top: #efe9de; --btn-bot: #c8bfae; --red: #b3261e; --bg: #6b5a43;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at center, #7a6a50 0%, #4f4231 100%) fixed;
  font: 13px/1.35 Tahoma, Verdana, "Segoe UI", sans-serif; color: var(--ink);
  display: flex; justify-content: center; align-items: flex-start; padding: 18px 8px;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- window chrome ---------- */
.win {
  width: 100%; max-width: 720px; background: var(--frame); border: 1px solid #120d08;
  border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.45); overflow: hidden;
}
.table-win { max-width: 1000px; }
.titlebar {
  background: linear-gradient(#3a2d21, #241a11); color: #f1e6d2; font-weight: bold;
  padding: 5px 10px; font-size: 13px;
}
.menubar { display: flex; gap: 0; background: linear-gradient(#d8d0c0, #bfb49e); border-bottom: 1px solid #8f826b; }
.menubar button { background: none; border: 0; padding: 4px 26px; color: var(--ink); }
.menubar button:hover { background: rgba(255,255,255,.35); }
.win-body { background: var(--panel); padding: 8px; }
.site-title { text-align: center; font-size: 16px; margin: 2px 0 10px; color: #2a221a; }

.btn {
  background: linear-gradient(var(--btn-top), var(--btn-bot)); border: 1px solid #7d715e;
  border-radius: 3px; padding: 8px 14px; color: var(--ink); min-width: 100px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { filter: brightness(.94); }
.btn:disabled { color: #8a8170; cursor: default; }
.btn-row { display: flex; gap: 12px; padding: 12px; background: var(--frame); }
.btn-row .btn { flex: 1; padding: 12px 8px; }
.btn-row .btn.wide { flex: 1.5; }

/* ---------- lobby ---------- */
.lobby-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 8px; min-height: 340px; }
.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; border: 0; border-radius: 12px 12px 0 0; padding: 7px 4px; color: #e8dcc8;
  background: linear-gradient(#4a3a2b, #2a1f15);
}
.tab.active { background: linear-gradient(#2b2017, #1b140d); color: #fff; font-weight: bold; }
.grid-panel { background: #e7e3dc; border: 3px solid var(--frame); height: 330px; overflow: auto; }
.list { width: 100%; border-collapse: collapse; }
.list th {
  background: linear-gradient(#d7cfbf, #bdb29c); font-weight: normal; padding: 4px 6px;
  border-right: 1px solid #9f937c; text-align: left; position: sticky; top: 0;
}
.list td { padding: 2px 6px; border-right: 1px solid #c9bfae; white-space: nowrap; }
.list tr.me td { font-weight: bold; }
.list tbody tr { cursor: default; }
.list tbody tr.sel td { background: #3d6db5; color: #fff; }
.swatch { display: inline-block; width: 40px; height: 11px; border: 1px solid #333; vertical-align: middle; }
.hint { color: var(--muted); font-size: 12px; margin: 6px; }
.chat-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.chat-box {
  flex: 1; background: #e7e3dc; border: 3px solid var(--frame); overflow-y: auto; padding: 4px 6px;
  min-height: 120px; font-size: 12px; word-wrap: break-word;
}
.lobby-grid .chat-box { height: 330px; flex: none; margin-top: 30px; }
.chat-box .who { font-weight: bold; }
.chat-box .sys { color: var(--muted); }
.chat-input input {
  width: 100%; padding: 6px; border: 1px solid #7d715e; background: #f6f3ee; font: inherit;
}

/* ---------- table ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px;
  background: linear-gradient(#d8d0c0, #bfb49e); border-bottom: 1px solid #8f826b;
}
.toolbar .icon { background: none; border: 1px solid transparent; padding: 3px 8px; border-radius: 3px; }
.toolbar .icon:hover { border-color: #8f826b; background: rgba(255,255,255,.3); }
.hand-no { flex: 1; text-align: center; }
.felt-area {
  position: relative; background: radial-gradient(ellipse at center, #6f5d42 0%, #4c3f2c 100%);
  padding: 34px 18px 12px;
}
.stakes { position: absolute; top: 6px; right: 12px; color: #ddd2bd; font-weight: bold; text-align: right; font-size: 14px; }
.shoe-info { position: absolute; top: 6px; left: 12px; color: #ddd2bd; font-size: 12px; }
.felt {
  position: relative; margin: 0 auto; width: 100%; aspect-ratio: 1.75 / 1; max-height: 560px;
  background: radial-gradient(ellipse at 50% 25%, #2a9a31 0%, var(--felt) 45%, var(--felt-dark) 100%);
  border: 14px solid var(--rail); border-radius: 0 0 50% 50% / 0 0 72% 72%;
  border-top-width: 10px; box-shadow: 0 10px 22px rgba(0,0,0,.45), inset 0 0 40px rgba(0,0,0,.35);
}
.watermark {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none;
  font: italic 44px Georgia, serif; color: rgba(0,0,0,.13);
}
.rules-arc {
  position: absolute; left: 0; right: 0; top: 41%; text-align: center; pointer-events: none;
  color: rgba(255,240,180,.55); font: bold 12px Georgia, serif; letter-spacing: .12em; text-transform: uppercase;
}
.dealer { position: absolute; left: 50%; top: 6%; transform: translateX(-50%); text-align: center; }
.dealer .label { color: #eef5e8; font-weight: bold; text-shadow: 0 1px 2px #000; margin-top: 4px; }
.center-msg {
  position: absolute; left: 50%; top: 26%; transform: translateX(-50%); color: #fff; font-size: 18px; z-index: 1;
  font-weight: bold; text-shadow: 0 1px 3px #000; white-space: nowrap; pointer-events: none;
}
.seats { position: absolute; inset: 0; pointer-events: none; }
.seat { position: absolute; width: 120px; transform: translate(-50%, -50%); text-align: center; pointer-events: auto; }
.seat .hands { display: flex; gap: 6px; justify-content: center; min-height: 66px; align-items: flex-end; }
.seat .hand { display: flex; flex-direction: column; align-items: center; padding: 2px; border-radius: 6px; }
.seat .hand.active { box-shadow: 0 0 0 2px var(--gold), 0 0 12px var(--gold); }
.seat .hand .tot { color: #fff; font-size: 11px; font-weight: bold; text-shadow: 0 1px 2px #000; }
.seat .hand .res { font-size: 11px; font-weight: bold; padding: 0 5px; border-radius: 8px; color: #111; background: #ddd; }
.res.r-win, .res.r-blackjack { background: #ffe27a; } .res.r-lose, .res.r-bust { background: #e8a39d; } .res.r-push, .res.r-surrender { background: #cfd8dc; }
.plate {
  margin-top: 4px; background: rgba(20,20,20,.75); border: 2px solid rgba(255,255,255,.18); border-radius: 18px;
  color: #fff; padding: 3px 6px; line-height: 1.2; min-height: 38px;
}
.plate .nm { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate .bal { color: #ffe27a; font-size: 12px; }
.plate.me { border-color: var(--gold); }
.plate.turn { border-color: #7fd37f; box-shadow: 0 0 10px #7fd37f; }
.plate.away { opacity: .6; }
.plate .tag { font-size: 10px; color: #ddd; }
.seat.empty .plate { background: rgba(0,0,0,.18); border: 2px solid rgba(255,255,255,.25); color: rgba(255,255,255,.7); cursor: pointer; padding-top: 10px; }
.seat.empty.nosit .plate { cursor: default; }
.betspot {
  margin: 4px auto 0; width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center; flex-direction: column; color: #fff; font-size: 11px; font-weight: bold;
}
.chip {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0 46%, var(--c, #c0392b) 47% 100%); border: 3px dashed rgba(255,255,255,.85);
  color: #111; font-size: 9px; font-weight: bold; letter-spacing: -.3px; box-shadow: 0 2px 3px rgba(0,0,0,.5);
}
.sidebets { display: flex; gap: 3px; justify-content: center; margin-top: 2px; }
.sidebets span { font-size: 10px; background: rgba(0,0,0,.45); color: #fff; padding: 0 4px; border-radius: 6px; }
.sidebets span.won { background: #ffe27a; color: #111; }

/* cards */
.cards { display: flex; }
.card {
  width: 38px; height: 54px; background: #fff; border-radius: 4px; border: 1px solid #999; margin-left: -18px;
  box-shadow: 1px 1px 3px rgba(0,0,0,.45); position: relative; font: bold 15px Georgia, serif; color: #111;
}
.card:first-child { margin-left: 0; }
.card.red { color: var(--red); }
.card .r { position: absolute; top: 3px; left: 3px; line-height: .95; text-align: center; width: 14px; }
.card .r i { display: block; font-style: normal; font-size: 13px; }
.card .s { position: absolute; bottom: 3px; right: 4px; font-size: 20px; line-height: 1; }
.card.back { background: repeating-linear-gradient(45deg, #7b1d1d 0 4px, #9b2a2a 4px 8px); border: 2px solid #fff; }
.dealer .card { width: 46px; height: 66px; margin-left: -14px; font-size: 18px; }
.dealer .card .s { font-size: 26px; }
.dealer .card .r { width: 16px; } .dealer .card .r i { font-size: 15px; }

/* bottom area */
.table-bottom { display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; background: var(--bg); padding: 8px; }
.table-bottom .chat-box { min-height: 110px; max-height: 150px; }
.chat-tabs { display: flex; gap: 2px; }
.ctab { border: 0; border-radius: 6px 6px 0 0; padding: 3px 12px; background: #4a3a2b; color: #e8dcc8; }
.ctab.active { background: var(--frame); color: #fff; }
.controls { display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; color: #fff; }
.controls .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.controls .btn { min-width: 0; flex: 1; padding: 10px 6px; }
.controls .btn.go { background: linear-gradient(#bfe6a8, #79b85a); }
.controls .note { color: #f3ead8; text-align: center; }
.controls .timer { color: var(--gold); font-weight: bold; }
.chip-btn { border: 0; background: none; padding: 0; }
.chip-btn .chip { width: 46px; height: 46px; font-size: 12px; }
.chip-btn:disabled { opacity: .4; }
.bet-amount { font-size: 15px; font-weight: bold; color: var(--gold); min-width: 70px; text-align: center; }
.side-input { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.side-input input { width: 64px; padding: 4px; }

/* dialogs */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 10px; }
.dialog { width: 100%; max-width: 540px; background: #e7e3dc; border: 4px solid var(--frame); border-radius: 4px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.dialog.small { max-width: 380px; }
.dlg-title { display: flex; justify-content: space-between; align-items: center; background: linear-gradient(#3a2d21, #241a11); color: #f1e6d2; padding: 6px 10px; }
.x { background: none; border: 0; color: #f1e6d2; font-size: 15px; }
.dlg-body { padding: 18px; display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: auto 160px; gap: 8px 10px; align-items: center; }
.form-grid input:not([type=checkbox]) { padding: 3px 5px; border: 1px solid #555; background: #f6f3ee; font: inherit; }
.form-grid .check { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.err { color: var(--red); width: 100%; margin: 0; min-height: 1em; }
.dlg-buttons { display: flex; justify-content: center; gap: 20px; padding: 10px 0 16px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #2b2117; color: #fff;
  padding: 8px 14px; border-radius: 6px; border: 1px solid #c9a96a; z-index: 60; max-width: 90vw;
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  body { padding: 0; }
  .win { border-radius: 0; max-width: none; min-height: 100vh; }
  .lobby-grid { grid-template-columns: 1fr; }
  .lobby-grid .chat-box { height: 160px; margin-top: 0; }
  .grid-panel { height: 240px; }
  .table-bottom { grid-template-columns: 1fr; }
  .table-bottom .chat-col { order: 2; }
  .felt-area { padding: 30px 4px 8px; }
  .felt { aspect-ratio: 1 / 1.05; border-radius: 0 0 46% 46% / 0 0 40% 40%; border-width: 8px; }
  .seat { width: 84px; }
  .plate { font-size: 11px; min-height: 32px; }
  .card { width: 28px; height: 40px; font-size: 12px; margin-left: -12px; }
  .card .s { font-size: 14px; }
  .dealer .card { width: 36px; height: 52px; font-size: 14px; }
  .betspot { width: 34px; height: 34px; }
  .watermark { font-size: 28px; }
  .rules-arc { font-size: 8px; top: 47%; padding: 0 30px; letter-spacing: .05em; }
  .card .r i { font-size: 10px; } .card .r { width: 11px; }
  .menubar button { padding: 4px 12px; }
  .btn-row .btn { padding: 10px 4px; font-size: 12px; }
}

/* ===================== phase 3 polish ===================== */
.toolbar #tb-help { padding: 3px 9px; font-weight: bold; }
.opt { display: flex; gap: 8px; align-items: center; width: 100%; }
.conn {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); background: #b3261e; color: #fff;
  padding: 4px 14px; border-radius: 0 0 6px 6px; z-index: 70; font-weight: bold;
}

/* shoe + discard tray */
.shoe {
  position: absolute; right: 7%; top: 5%; width: 46px; height: 64px; border-radius: 4px 4px 8px 8px;
  background: linear-gradient(#3a3a3a, #161616); border: 2px solid #555; box-shadow: 2px 3px 6px rgba(0,0,0,.5);
  transform: rotate(-12deg); overflow: hidden; display: flex; align-items: flex-end;
}
.shoe-fill { width: 100%; background: repeating-linear-gradient(0deg, #f4efe6 0 2px, #cfc6b4 2px 3px); transition: height .6s; }
.tray {
  position: absolute; left: 7%; top: 5%; width: 46px; height: 64px; border-radius: 4px;
  border: 2px solid rgba(0,0,0,.35); background: rgba(0,0,0,.15); transform: rotate(12deg);
}

/* card animations: fly in from the shoe, flip the hole card */
@keyframes deal {
  from { opacity: 0; transform: translate(var(--from-x, 260px), var(--from-y, -260px)) rotate(-25deg) scale(.6); }
  60% { opacity: 1; }
  to { opacity: 1; transform: none; }
}
@keyframes flip {
  0% { transform: rotateY(90deg); filter: brightness(.7); }
  100% { transform: rotateY(0); filter: none; }
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, 8px); } 15% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -16px); } }
.card.deal { animation: deal .38s cubic-bezier(.2,.7,.3,1) both; }
.card.flip { animation: flip .32s ease-out both; }
.dealer .card.deal { --from-x: 160px; --from-y: -10px; }
.fadein { animation: fadein .25s ease-out both; }
@media (prefers-reduced-motion: reduce) { .card.deal, .card.flip, .fadein, .net { animation-duration: .01s !important; } }

.net {
  position: absolute; left: 50%; top: -14px; transform: translateX(-50%); z-index: 3; pointer-events: none;
  font: bold 16px Tahoma, sans-serif; color: #fff; text-shadow: 0 1px 3px #000; animation: rise 3.2s ease-out both;
}
.net.up { color: #ffe27a; } .net.down { color: #ffb0a8; }
.betspot.draft { border-style: dashed; opacity: .85; }
.chip.doubled { box-shadow: 0 2px 3px rgba(0,0,0,.5), 0 -4px 0 -1px var(--c), 0 -4px 0 1px rgba(255,255,255,.7); }
.seat.mine { z-index: 2; }
.seat .hand .chip { margin-top: 2px; }
.timer.low { color: #ff7b6e; }
.btn .hk { display: none; }
@media (hover: hover) and (min-width: 761px) {
  .btn .hk { display: inline-block; text-decoration: none; font-size: 10px; margin-left: 6px; padding: 0 4px; border: 1px solid #7d715e; border-radius: 3px; opacity: .7; }
}
.chips-row { justify-content: center; }
.chip-btn:not(:disabled):hover .chip { transform: translateY(-3px); }
.chip-btn .chip { transition: transform .1s; }

/* four-color deck */
.card.suit-h { color: #c62828; } .card.suit-d { color: #c62828; } .card.suit-s, .card.suit-c { color: #111; }
body.four-color .card.suit-d { color: #1565c0; } body.four-color .card.suit-c { color: #2e7d32; }

/* phones: tall felt with seats in a U */
@media (max-width: 760px) {
  .felt { aspect-ratio: .7 / 1; max-height: none; border-radius: 0 0 44% 44% / 0 0 22% 22%; }
  .dealer { top: 3%; }
  .center-msg { top: 27%; font-size: 15px; }
  .watermark { top: 40%; font-size: 17px; }
  .rules-arc { display: none; }
  .shoe, .tray { width: 30px; height: 42px; top: 3%; }
  .shoe { right: 5%; } .tray { left: 5%; }
  .seat { width: 92px; }
  .seat .hands { min-height: 46px; gap: 2px; }
  .seat .hand .chip { width: 24px; height: 24px; font-size: 7px; border-width: 2px; }
  .plate { min-height: 30px; padding: 2px 4px; border-radius: 12px; }
  .plate .bal { font-size: 10px; }
  .betspot { width: 30px; height: 30px; margin-top: 2px; }
  .betspot .chip { width: 26px; height: 26px; font-size: 8px; border-width: 2px; }
  .card { width: 26px; height: 37px; margin-left: -13px; border-radius: 3px; }
  .card .s { font-size: 13px; bottom: 1px; right: 2px; }
  .card .r { top: 1px; left: 2px; font-size: 11px; width: 10px; }
  .card .r i { font-size: 9px; }
  .dealer .card { width: 34px; height: 48px; margin-left: -12px; font-size: 14px; }
  .dealer .card .s { font-size: 18px; }
  .seat .hand .tot, .seat .hand .res { font-size: 10px; }
  .net { font-size: 13px; top: -6px; }
  .card.deal { --from-x: 120px; --from-y: -200px; }
  .controls .btn { padding: 12px 4px; }
  .chip-btn .chip { width: 50px; height: 50px; }
  .toolbar .icon { padding: 3px 5px; }
  .toolbar .lbl { display: none; }
}
