:root {
  --bg: #0d1f17;
  --panel: #14291f;
  --panel-2: #1b3528;
  --line: #2a4a3a;
  --text: #eef5f0;
  --muted: #9bb5a6;
  --felt: #1f6b45;
  --felt-dark: #154d31;
  --rail: #3b2616;
  --gold: #f2c14e;
  --red: #e5484d;
  --green: #3ecf8e;
  --blue: #4f8cff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #16352a, var(--bg) 70%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow-x: hidden;
}
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; color: inherit; }
button:disabled { opacity: .4; cursor: default; }
input, select { font: inherit; }
.hidden { display: none !important; }
.invisible { visibility: hidden !important; }

/* ---------- telas iniciais ---------- */
.screen { min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: 28px 16px 40px; }
.stack { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; }
.card-panel {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 24px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.logo { text-align: center; font-size: 38px; letter-spacing: 4px; margin: 10px 0 2px; }
.logo span:nth-child(2), .logo span:nth-child(3) { color: var(--red); }
h1 { text-align: center; margin: 0 0 4px; font-size: 24px; }
h2 { margin: 0 0 12px; font-size: 19px; }
h3 { margin: 18px 0 8px; font-size: 15px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 8px; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.field {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px; outline: none;
}
.field:focus { border-color: var(--gold); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { padding: 13px 14px; font-weight: 700; font-size: 15px; background: var(--panel-2); border: 1px solid var(--line); }
.btn-primary { width: 100%; margin-top: 18px; padding: 14px; font-weight: 800; font-size: 16px; background: var(--gold); color: #2a1d00; }
.btn-primary:active, .btn:active { transform: translateY(1px); }
.btn-ghost { width: 100%; margin-top: 10px; padding: 12px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; }
.btn-danger { background: #3a1e20; color: #ffb3b5; border: 1px solid #5a2a2d; }
.link-btn { background: none; color: var(--muted); text-decoration: underline; width: 100%; margin-top: 12px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; text-align: center; line-height: 1.5; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; margin: 14px 0 4px; }
.tabs button { padding: 10px; background: none; color: var(--muted); font-weight: 700; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; }
.row .field { flex: 1; }

.me-bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.me-bar .who { flex: 1; min-width: 0; }
.me-bar .who b { display: block; font-size: 17px; }
.me-bar .who small { color: var(--muted); }
.table-list .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.table-list .item:last-child { border-bottom: 0; }
.table-list .item div { flex: 1; }
.table-list .item small { color: var(--muted); display: block; }
.tournament-only { display: none; }
.is-tournament .tournament-only { display: block; }

/* avatar */
.av {
  width: 40px; height: 40px; border-radius: 50%; background: #26433a; border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; overflow: hidden; flex-shrink: 0;
}
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.big { width: 84px; height: 84px; font-size: 46px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-grid button { font-size: 22px; padding: 6px 0; background: var(--bg); border: 2px solid transparent; }
.emoji-grid button.on { border-color: var(--gold); }

/* ---------- jogo ---------- */
#game { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
}
.table-code { font-weight: 800; letter-spacing: 2px; margin-right: 4px; }
.table-code small { display: block; font-size: 11px; letter-spacing: 0; color: var(--muted); font-weight: 600; }
.topbar .spacer { flex: 1; }
.chip-btn { position: relative; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 11px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.chip-btn.gold { background: var(--gold); color: #2a1d00; border-color: var(--gold); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: flex; align-items: center; justify-content: center; }
.hud {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted);
  padding: 0 10px 4px;
}
.hud b { color: var(--text); }
.hud .clock { color: var(--gold); font-weight: 800; }

.table-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px 18px; min-height: 0; }
.table { position: relative; width: 100%; max-width: 980px; aspect-ratio: 16 / 9; max-height: 100%; }
.felt {
  position: absolute; inset: 9% 7%; border-radius: 999px;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 80%);
  border: 12px solid var(--rail);
  box-shadow: inset 0 0 40px rgba(0,0,0,.45), 0 12px 40px rgba(0,0,0,.5);
}
.center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: 60%;
}
.pot { background: rgba(0,0,0,.35); padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.board { display: flex; gap: 5px; min-height: 64px; }
.results {
  background: rgba(0,0,0,.6); border: 1px solid var(--gold); border-radius: 10px;
  padding: 6px 12px; font-size: 13px; text-align: center; line-height: 1.45;
}
.results b { color: var(--gold); }
.waiting-msg { color: #d6ebdf; font-size: 14px; text-align: center; opacity: .9; }

/* cartas */
.c {
  width: 44px; height: 62px; border-radius: 6px; background: #fff; color: #111;
  display: inline-flex; flex-direction: column; justify-content: space-between;
  padding: 3px 4px; font-weight: 800; box-shadow: 0 2px 6px rgba(0,0,0,.4); position: relative;
  animation: deal .25s ease-out;
}
.c .r { font-size: 17px; line-height: 1; }
.c .s { font-size: 22px; line-height: 1; align-self: flex-end; }
.c.red { color: #d42a2f; }
.c.back { background: repeating-linear-gradient(45deg, #b42b30 0 5px, #8f1f24 5px 10px); border: 3px solid #fff; }
.c.win { outline: 3px solid var(--gold); outline-offset: -1px; }
.c.dim { opacity: .45; }
.c.small { width: 34px; height: 48px; }
.c.small .r { font-size: 14px; }
.c.small .s { font-size: 16px; }
@keyframes deal { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* assentos */
.seat {
  position: absolute; transform: translate(-50%, -50%); width: 118px;
  display: flex; flex-direction: column; align-items: center; z-index: 2;
}
.seat .cards { display: flex; gap: 2px; height: 50px; margin-bottom: -5px; z-index: 1; align-items: flex-end; }
.seat.me .cards { height: 64px; }
.seat.me .c.small { width: 44px; height: 62px; }
.seat.me .c.small .r { font-size: 17px; }
.seat.me .c.small .s { font-size: 22px; }
.plate {
  position: relative; width: 100%; background: rgba(10, 20, 15, .92); border: 2px solid var(--line);
  border-radius: 12px; padding: 5px 6px 6px 16px; text-align: center; z-index: 2;
}
.plate .av { position: absolute; left: -14px; top: -12px; width: 32px; height: 32px; font-size: 18px; }
.seat.turn .plate { border-color: var(--gold); box-shadow: 0 0 18px rgba(242,193,78,.55); }
.seat.me .plate { background: rgba(28, 52, 40, .96); }
.seat.folded .cards, .seat.folded .plate { opacity: .5; }
.seat.away .plate { opacity: .6; }
.seat.out .plate { opacity: .45; filter: grayscale(1); }
.plate .name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .chips { color: var(--gold); font-weight: 800; font-size: 14px; }
.plate .status { font-size: 11px; color: var(--muted); min-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .status.hl { color: var(--green); font-weight: 700; }
.timer { height: 4px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; margin-top: 4px; }
.timer i { display: block; height: 100%; background: var(--gold); width: 100%; }
.dealer {
  position: absolute; right: -8px; top: -8px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #111; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.bet {
  position: absolute; transform: translate(-50%, -50%); z-index: 1;
  background: rgba(0,0,0,.45); border-radius: 999px; padding: 2px 8px 2px 4px; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.bet::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px dashed #fff; }
.empty-seat { position: absolute; transform: translate(-50%, -50%); width: 54px; height: 54px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.12); }

.bubble {
  position: absolute; transform: translate(-50%, -100%); z-index: 20; max-width: 170px;
  background: #fff; color: #111; font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4); pointer-events: none; animation: pop .2s ease-out;
  overflow-wrap: anywhere;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble.emoji { background: none; box-shadow: none; font-size: 38px; padding: 0; animation: floatUp 2.6s ease-out forwards; }
.bubble.emoji::after { display: none; }
@keyframes pop { from { transform: translate(-50%, -80%) scale(.8); opacity: 0; } to { transform: translate(-50%, -100%); opacity: 1; } }
@keyframes floatUp { 0% { transform: translate(-50%, -60%) scale(.6); opacity: 0; } 15% { transform: translate(-50%, -100%) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -220%) scale(1); opacity: 0; } }

/* barra inferior com altura fixa: nada pula quando chega a sua vez */
.bottom { padding: 8px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: rgba(8,16,12,.75); border-top: 1px solid var(--line); }
.stage { display: grid; max-width: 640px; margin: 0 auto; height: 152px; }
.stage > * { grid-area: 1 / 1; min-width: 0; }
.actions { display: flex; flex-direction: column; gap: 8px; justify-content: flex-end; }
.quick { display: flex; gap: 6px; }
.quick button { flex: 1; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 4px; font-size: 13px; font-weight: 600; }
.raise-row { display: flex; align-items: center; gap: 6px; }
.raise-row input[type=range] { flex: 1; accent-color: var(--gold); }
.raise-row .field { width: 100px; padding: 8px; font-size: 15px; text-align: center; }
.main-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.main-btns button { padding: 14px 6px; font-weight: 800; font-size: 15px; }
.b-fold { background: #3a1e20; color: #ffb3b5; }
.b-call { background: var(--blue); color: #fff; }
.b-raise { background: var(--gold); color: #2a1d00; }
.idle { display: flex; flex-direction: column; gap: 8px; justify-content: flex-end; }
.info-line { text-align: center; color: var(--muted); font-size: 14px; min-height: 20px; }
.info-line b { color: var(--text); }
.pre { display: flex; gap: 8px; justify-content: center; }
.pre button { flex: 1; max-width: 200px; padding: 11px 6px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-size: 14px; color: var(--muted); }
.pre button.on { border-color: var(--gold); color: var(--gold); background: rgba(242,193,78,.1); }
.extra { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; min-height: 0; }
.log { font-size: 12px; color: var(--muted); height: 32px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; text-align: center; cursor: pointer; }

/* modais */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal .card-panel { max-width: 460px; max-height: 88vh; overflow: auto; padding: 22px 18px; }
table.score { width: 100%; border-collapse: collapse; font-size: 14px; }
table.score th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.score th:first-child, table.score td:first-child { text-align: left; }
table.score td { text-align: right; padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,.05); }
table.score td .av { width: 24px; height: 24px; font-size: 13px; vertical-align: middle; margin-right: 6px; border-width: 1px; }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }
.loglist { font-size: 13px; line-height: 1.6; color: var(--muted); }
.loglist div:nth-last-child(-n+5) { color: var(--text); }
.menu-list button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 12px; background: var(--panel-2); border: 1px solid var(--line); margin-bottom: 8px; font-weight: 600; }
.host-player { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.host-player .who { flex: 1; min-width: 0; }
.host-player .who b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host-player .who small { color: var(--gold); }
.host-player button { padding: 7px 9px; font-size: 12px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--line); }
.prev-player { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.prev-player .who { flex: 1; }
.prev-player .who small { display: block; color: var(--muted); }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 10px 0 16px; }
.podium div { text-align: center; }
.podium .medal { font-size: 30px; }
.podium b { display: block; font-size: 14px; margin-top: 4px; }

/* chat */
.chat-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 360px; max-width: 100%; z-index: 55;
  background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(0,0,0,.4);
}
.chat-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head b { flex: 1; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.chat-msg .av { width: 30px; height: 30px; font-size: 16px; }
.chat-msg .txt { background: var(--panel-2); border-radius: 12px; padding: 7px 10px; font-size: 14px; overflow-wrap: anywhere; }
.chat-msg .txt small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.chat-msg.emoji .txt { background: none; font-size: 30px; padding: 0; }
.reactions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 8px 12px 0; }
.reactions button { font-size: 22px; padding: 4px 0; background: var(--bg); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: #3a1e20; color: #fff;
  border: 1px solid var(--red); padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 14px; max-width: 90%;
}
.toast.ok { background: #16352a; border-color: var(--green); }
.conn { position: fixed; bottom: 8px; left: 8px; font-size: 11px; color: var(--red); z-index: 60; }

@media (max-width: 520px) {
  .hide-sm { display: none; }
  .topbar { gap: 5px; }
  .chip-btn { padding: 8px 9px; }
}

/* celular em pé: mesa vertical */
@media (max-width: 700px) and (orientation: portrait) {
  .table { aspect-ratio: 3 / 4.3; max-width: 520px; }
  .felt { inset: 10% 12%; border-width: 9px; }
  .center { width: 72%; }
  .seat { width: 88px; }
  .plate { padding-left: 12px; }
  .plate .av { width: 26px; height: 26px; font-size: 15px; left: -11px; top: -10px; }
  .plate .name { font-size: 12px; }
  .plate .chips { font-size: 13px; }
  .c { width: 36px; height: 51px; }
  .c .r { font-size: 14px; }
  .c .s { font-size: 17px; }
  .c.small { width: 28px; height: 40px; }
  .c.small .r { font-size: 12px; }
  .c.small .s { font-size: 13px; }
  .seat .cards { height: 40px; }
  .seat.me .cards { height: 53px; }
  .seat.me .c.small { width: 38px; height: 53px; }
  .seat.me .c.small .r { font-size: 15px; }
  .seat.me .c.small .s { font-size: 18px; }
  .board { gap: 3px; min-height: 51px; }
  .results { font-size: 12px; }
  .chat-panel { top: auto; height: 72dvh; width: 100%; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; }
}
