:root {
  --bg: #07130e;
  --panel: #fbf8f1;
  --panel-ink: #1d2420;
  --ink: #f3efe4;
  --muted: #a9bdb2;
  --gold: #e8b94e;
  --gold-2: #ffd76a;
  --gold-ink: #2b2104;
  --danger: #d9534f;
  --win: #3fb37f;
  --line: rgba(255, 255, 255, 0.12);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-family: Georgia, "Times New Roman", serif; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(#0b1d15, #06110c); border-bottom: 1px solid rgba(232, 185, 78, 0.25);
  position: sticky; top: 0; z-index: 30;
}
.brand { font-family: Georgia, serif; font-weight: 700; letter-spacing: 0.25em; color: var(--gold); font-size: 1.15rem; text-shadow: 0 0 12px rgba(232, 185, 78, 0.35); }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-av { width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: radial-gradient(#2f5a47, #10261c); border: 2px solid var(--gold); flex: none; cursor: pointer; padding: 0; }
.me-av .av-wrap { width: 100%; height: 100%; transform: scale(1.5) translateY(14%); }
#me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
.chip-pill {
  background: linear-gradient(#ffe08a, #d9a628); color: var(--gold-ink); font-weight: 800;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 10px; width: 38px; height: 38px; font-size: 18px; cursor: pointer; flex: none; }

/* ---------- botones y campos ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #17402f; color: var(--ink);
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 10px; cursor: pointer;
  min-height: 44px; touch-action: manipulation; transition: transform 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(#ffd76a, #d9a628); color: var(--gold-ink); border-color: transparent; box-shadow: 0 3px 0 #8c6611, 0 6px 14px rgba(0, 0, 0, 0.35); }
.btn.danger { background: linear-gradient(#e2625d, #b83a35); border-color: transparent; color: #fff; box-shadow: 0 3px 0 #7a1f1b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; box-shadow: none; }
input {
  font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid #c9c2b3;
  background: #fff; color: var(--panel-ink); min-height: 44px; width: 100%; min-width: 0;
}
.action-dock input { border-color: rgba(232, 185, 78, 0.4); background: #0a2219; color: var(--ink); }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1 1 140px; }

/* ---------- paneles ---------- */
.screen { padding: 16px; max-width: 1200px; margin: 0 auto; }
.card-panel {
  background: var(--panel); color: var(--panel-ink); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.card-panel .muted { color: #6b7069; }
.narrow { max-width: 560px; margin: 4vh auto 0; display: grid; gap: 12px; }
.lobby { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .lobby { grid-template-columns: 1fr 1fr; } .lobby > :last-child { grid-column: 1 / -1; } }
.table-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.table-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid #e3ddd0; border-radius: 10px; }
.table-list .code-sm { font-weight: 800; letter-spacing: 0.1em; }

/* Selector de personaje */
.avatar-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.avatar-option {
  appearance: none; border: 2px solid transparent; border-radius: 12px; padding: 4px 2px 6px; cursor: pointer;
  background: radial-gradient(ellipse at 50% 30%, #2f6b52, #0f2a1f); color: #fff; font: inherit; font-size: 0.72rem;
  display: grid; justify-items: center; gap: 2px; transition: transform 0.15s, border-color 0.15s;
}
.avatar-option .av-wrap { width: 100%; aspect-ratio: 160 / 182; }
.avatar-option[aria-pressed="true"] { border-color: var(--gold-2); transform: translateY(-3px); box-shadow: 0 6px 16px rgba(232, 185, 78, 0.35); }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-back .card-panel { width: min(560px, 100%); }

/* ---------- layout de la mesa ---------- */
#screen-table { padding: 0; max-width: none; }
.table-layout {
  display: grid; gap: 12px; padding: 8px 0;
  grid-template-columns: 1fr;
  grid-template-areas: "head" "stage" "side";
  padding-bottom: calc(var(--dock-h, 220px) + 16px);
}
.table-head { grid-area: head; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 16px; }
.code { font-weight: 800; letter-spacing: 0.15em; font-size: 1.05rem; color: var(--gold); }
.phase { text-align: center; font-weight: 600; flex: 1; font-size: 0.92rem; }
.side { grid-area: side; display: grid; gap: 16px; align-content: start; padding: 0 16px; }

/* ---------- escena 3D ---------- */
.stage-wrap {
  grid-area: stage; position: relative; width: 100%; overflow: hidden;
  background:
    radial-gradient(ellipse 60% 50% at 50% 30%, rgba(255, 226, 150, 0.16), transparent 70%),
    radial-gradient(ellipse at 50% 40%, #1c3a2d 0%, #0b1913 55%, #050c09 100%);
}
.stage { position: absolute; left: 0; top: 0; width: 1480px; height: 910px; transform-origin: 0 0; }
.scene { position: absolute; inset: 0; perspective: 1500px; perspective-origin: 50% 10%; transform-style: preserve-3d; }
.plane {
  position: absolute; left: 160px; top: 175px;
  transform: rotateX(var(--tilt, 40deg)) rotateZ(var(--rz, 0deg)); transform-origin: 50% 40%; transform-style: preserve-3d;
  transition: transform 0.9s ease;
}
.plane > * { position: absolute; }
.table-svg { left: 0; top: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 30px 30px rgba(0, 0, 0, 0.6)); }

.billboard { transform: translate(-50%, -100%) rotateZ(calc(-1 * var(--rz, 0deg))) rotateX(calc(-1 * var(--tilt, 40deg))); transform-origin: 50% 100%; transform-style: preserve-3d; transition: transform 0.9s ease; }

/* Cartas */
.cards-row { width: 0; height: 0; transform-style: preserve-3d; }
.card-slot { position: absolute; width: 86px; height: 129px; margin: -64.5px 0 0 -43px; transform-style: preserve-3d; transition: left 0.35s ease; }
.card3d { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.65s cubic-bezier(0.3, 1.3, 0.5, 1); }
.card3d.no-anim { transition: none; }
.card3d.faceup { transform: rotateY(180deg); }
.cface { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 0 #d8ccb0, 0 2px 0 #c2b493, 0 6px 10px rgba(0, 0, 0, 0.45); }
.cfront { transform: rotateY(180deg); }
.card-svg { display: block; width: 100%; height: 100%; }
.shoe { width: 66px; height: 99px; transform-style: preserve-3d; }
.shoe::before { content: ""; position: absolute; inset: -8px -8px -8px -8px; border-radius: 10px; background: linear-gradient(#3b1f0c, #1d0e04); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6); transform: translateZ(-1px); }
.shoe .card3d { position: absolute; inset: 0; }
.discard-pile { width: 66px; height: 99px; }
.rack { width: 260px; height: 64px; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.5)); }
.dir-label { font: 600 18px Georgia, serif; color: rgba(244, 214, 140, 0.55); white-space: nowrap; letter-spacing: 0.06em; }

/* Anillo de turno sobre el paño */
.turn-ring { width: 100px; height: 100px; border-radius: 50%; border: 4px solid var(--gold-2); opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.turn-ring.on { opacity: 1; animation: ring-pulse 1.3s ease-in-out infinite; }
@keyframes ring-pulse { 0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 215, 106, 0.5), inset 0 0 10px rgba(255, 215, 106, 0.4); } 50% { box-shadow: 0 0 34px 10px rgba(255, 215, 106, 0.8), inset 0 0 20px rgba(255, 215, 106, 0.6); } }

/* Fichas (vistas de costado, paradas sobre el paño) */
.chipstack { width: 160px; height: 130px; pointer-events: none; }
.chipstack-inner { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); display: flex; gap: 3px; align-items: flex-end; }
.chip-col { display: flex; flex-direction: column-reverse; }
.chip {
  width: 38px; height: 12px; border-radius: 50%; margin-top: -6px;
  background: repeating-linear-gradient(90deg, var(--c) 0 6px, rgba(255, 255, 255, 0.92) 6px 9px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 1px 1px rgba(0, 0, 0, 0.5);
}
.chip-col .chip:last-child { background: radial-gradient(ellipse at 50% 45%, var(--c) 0 38%, rgba(255, 255, 255, 0.9) 39% 44%, var(--c) 45%); height: 14px; }
.chip-label {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); white-space: nowrap;
  font: 800 17px system-ui, sans-serif; color: var(--gold-2); background: rgba(0, 0, 0, 0.65);
  padding: 2px 8px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.pot .chip { width: 44px; height: 14px; margin-top: -7px; }

/* Jugadores */
.player { width: 190px; display: flex; flex-direction: column; align-items: center; pointer-events: none; transition: opacity 0.3s; }
.player .av-holder { width: 132px; height: 150px; position: relative; transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.5, 1); }
.player.turn .av-holder { transform: scale(1.1) translateY(-6px); }
.player.empty { opacity: 0.55; }
.player.at-bank { display: none; }
.player.offline .av-holder { filter: grayscale(0.9) brightness(0.7); }
.glow { position: absolute; left: 50%; top: 10px; width: 210px; height: 210px; margin-left: -105px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 215, 106, 0.55), transparent 65%); opacity: 0; transition: opacity 0.3s; }
.player.turn .glow, .dealer.turn .glow { opacity: 1; animation: glow-pulse 1.3s ease-in-out infinite; }
@keyframes glow-pulse { 50% { transform: scale(1.12); opacity: 0.75; } }
.empty-chair { position: absolute; left: 35px; right: 35px; top: 40px; bottom: 6px; border-radius: 26px 26px 10px 10px; background: linear-gradient(#5a2d14, #2b1407); box-shadow: inset 0 0 0 6px #6e3a1b, 0 8px 16px rgba(0, 0, 0, 0.5); }

.plate {
  margin-top: -8px; min-width: 130px; max-width: 190px; text-align: center; padding: 5px 12px 6px; border-radius: 12px;
  background: linear-gradient(rgba(16, 30, 24, 0.95), rgba(5, 12, 9, 0.95)); border: 2px solid rgba(232, 185, 78, 0.55);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.55); position: relative; z-index: 2;
}
.pname { font: 700 21px system-ui, sans-serif; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbal { font: 800 18px system-ui, sans-serif; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.pstatus { font: italic 600 15px system-ui, sans-serif; color: #9fe0bf; min-height: 0; }
.pstatus:empty { display: none; }
.player.me .plate, .dealer.me .plate { border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(255, 215, 106, 0.35), 0 8px 18px rgba(0, 0, 0, 0.55); }
.player.turn .plate { background: linear-gradient(#5b4310, #2a1e06); }

.dealer { width: 260px; display: flex; flex-direction: column; align-items: center; }
.dealer .av-holder { width: 196px; height: 223px; position: relative; }
.dealer.empty .av-holder { height: 60px; }
.dealer .glow { width: 260px; height: 260px; margin-left: -130px; }
.dealer-plate { min-width: 210px; border-color: var(--gold-2); }
.dealer-plate .pname { font-size: 22px; }
.dealer-plate .pbal { font-size: 24px; }
.wheel { width: 260px; display: flex; flex-direction: column; align-items: center; }
.wheel svg { width: 180px; height: 207px; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.6)); }
.wheel-rot { transform-box: view-box; transform-origin: 100px 100px; }
.wheel.spinning .wheel-rot { animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.wheel-plate .pname, .wheel-plate { font: 700 19px system-ui, sans-serif; color: var(--gold-2); }

/* ---------- personajes ---------- */
.av-wrap { width: 100%; height: 100%; transform-origin: 50% 100%; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 2px rgba(255, 240, 200, 0.45)); }
.av { width: 100%; height: 100%; display: block; overflow: visible; }
.av .body { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 4.2s ease-in-out infinite; animation-delay: var(--breathe-delay, 0s); }
.av .head { transform-box: fill-box; transform-origin: 50% 100%; animation: bob 4.2s ease-in-out infinite; animation-delay: var(--breathe-delay, 0s); }
.av .lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); animation: blink 5.2s infinite; animation-delay: var(--blink-delay, 0s); }
.av .brows { transition: transform 0.3s; }
@keyframes breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.02); } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-1.5px) rotate(-0.8deg); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(0); } 95% { transform: scaleY(1); } }
.av .m-happy, .av .m-sad { display: none; }
.av-wrap.happy .m-happy, .av-wrap.sad .m-sad { display: inline; }
.av-wrap.happy .m-neutral, .av-wrap.sad .m-neutral { display: none; }
.av-wrap.happy .brows { transform: translateY(-3px); }
.av-wrap.sad .brows { transform: translateY(2px); }
.av-wrap.win { animation: jump 1.1s cubic-bezier(0.3, 1.5, 0.5, 1) 2; }
.av-wrap.lose { animation: slump 1.2s ease-in-out forwards; }
@keyframes jump { 0%, 100% { transform: translateY(0) scale(1); } 30% { transform: translateY(-22px) scale(1.06) rotate(-2deg); } 55% { transform: translateY(0) scale(0.98); } 75% { transform: translateY(-8px) rotate(2deg); } }
@keyframes slump { 0% { transform: none; } 25% { transform: rotate(-4deg); } 50% { transform: rotate(3deg); } 100% { transform: translateY(6px) scale(0.97); } }
.player.turn .av-wrap:not(.win):not(.lose), .dealer.turn .av-wrap:not(.win):not(.lose) { animation: think 2.4s ease-in-out infinite; }
@keyframes think { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-2.5deg); } 70% { transform: rotate(2.5deg); } }

/* ---------- efectos ---------- */
.fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center;
  padding: 14px 28px; border-radius: 18px; background: rgba(5, 12, 9, 0.82); border: 2px solid var(--gold-2);
  box-shadow: 0 0 40px rgba(255, 215, 106, 0.45); animation: banner 2.6s cubic-bezier(0.3, 1.4, 0.5, 1) forwards;
  max-width: 90%;
}
.banner.lose { border-color: #e2625d; box-shadow: 0 0 40px rgba(226, 98, 93, 0.4); }
.banner-title { font: 800 clamp(22px, 5vw, 44px) Georgia, serif; color: var(--gold-2); text-shadow: 0 2px 0 #6b4c0b, 0 0 18px rgba(255, 215, 106, 0.6); }
.banner.lose .banner-title { color: #ffb3ae; text-shadow: 0 2px 0 #5e1512; }
.banner-sub { font-weight: 600; color: #fff; margin-top: 2px; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 20% { transform: translate(-50%, -50%) scale(1); } 85% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); } }
.confetti { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); opacity: 0.9; } }

/* ---------- dock de acciones (abajo en celular) ---------- */
.action-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: linear-gradient(#0d241a, #06110c); border-top: 1px solid rgba(232, 185, 78, 0.35);
  padding: 10px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: grid; gap: 10px; max-height: 62dvh; overflow-y: auto;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}
.my-hand { display: flex; align-items: center; gap: 14px; perspective: 800px; }
.my-hand:empty { display: none; }
.my-cards { display: flex; gap: 6px; }
.my-cards .card3d { width: 70px; height: 105px; }
.my-cards .mine-slot { animation: mine-in 0.45s cubic-bezier(0.3, 1.3, 0.5, 1) backwards; transform-style: preserve-3d; transition: transform 0.2s; }
.my-cards .mine-slot:hover { transform: translateY(-6px) rotateX(8deg); }
@keyframes mine-in { from { transform: translateY(-60px) rotate(-8deg); opacity: 0; } }
.my-hand .value { font-size: 1.05rem; font-weight: 700; }
.my-hand .value b { color: var(--gold-2); font-size: 1.4rem; display: block; }
.my-hand .value small { display: block; color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.actions { display: grid; gap: 10px; }
.actions .prompt { font-weight: 700; font-size: 1.02rem; }
.actions .hint { color: var(--muted); font-size: 0.92rem; }

/* ---------- resultados e historial ---------- */
.showdown-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid #e7e1d4; }
.showdown-row:last-child { border-bottom: 0; }
.showdown-row .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.showdown-row .res { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.showdown-row .res.win { color: #1e8a5a; }
.showdown-row .res.lose { color: #b33a36; }
.mini-cards { grid-column: 1 / -1; display: flex; gap: 4px; }
.mini-cards .card-svg { width: 34px; height: 51px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3)); }
.log-panel summary { cursor: pointer; font-weight: 700; }
.log { margin: 8px 0 0; padding-left: 18px; max-height: 240px; overflow-y: auto; font-size: 0.88rem; display: grid; gap: 4px; }

.announce {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 65;
  width: min(640px, calc(100vw - 32px)); display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 14px; border-radius: 12px; font-weight: 600;
  background: linear-gradient(#ffe08a, #e0b13a); color: var(--gold-ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: announce-in 0.4s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.announce #announce-text { flex: 1; }
.announce .icon-btn { color: var(--gold-ink); border-color: rgba(0, 0, 0, 0.2); }
@keyframes announce-in { from { transform: translate(-50%, -30px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%) translateY(-20px);
  background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 70;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- celular: textos de la mesa más grandes (la escena se achica) ---------- */
@media (max-width: 640px) {
  .pname { font-size: 28px; }
  .pbal { font-size: 25px; }
  .pstatus { font-size: 22px; }
  .plate { min-width: 170px; max-width: 230px; }
  .chip-label { font-size: 24px; }
  .dealer-plate .pname { font-size: 28px; }
  .dealer-plate .pbal { font-size: 30px; }
  .dir-label { font-size: 24px; }
}

/* ---------- computadora ---------- */
@media (min-width: 980px) {
  .table-layout {
    max-width: 1500px; margin: 0 auto; padding: 12px 20px 20px;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "head side" "stage side" "dock side";
    grid-template-rows: auto auto 1fr;
    align-items: start;
  }
  .table-head { padding: 0; }
  .side { grid-row: 1 / span 3; padding: 0; }
  .stage-wrap { border-radius: 22px; border: 1px solid rgba(232, 185, 78, 0.2); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
  .action-dock {
    grid-area: dock; position: static; max-height: none; border-radius: var(--radius);
    border: 1px solid rgba(232, 185, 78, 0.3); box-shadow: none;
    grid-template-columns: auto 1fr; align-items: center; gap: 20px;
  }
  .actions > .btn { justify-self: start; min-width: 240px; }
  .my-cards .card3d { width: 86px; height: 129px; }
  .log { max-height: 380px; }
}

/* =====================================================================
   Cuentas, asientos, temporizador, chat y voz
   ===================================================================== */

.stack { display: grid; gap: 8px; }
.tabs { display: flex; gap: 4px; background: #efe8d8; padding: 4px; border-radius: 12px; margin-bottom: 4px; }
.tabs button { flex: 1; appearance: none; border: 0; background: transparent; font: inherit; font-weight: 700; padding: 10px; border-radius: 9px; cursor: pointer; color: #6b7069; }
.tabs button[aria-selected="true"] { background: #fff; color: var(--panel-ink); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); }
.card-panel label { font-weight: 600; font-size: 0.9rem; }

/* Boca que se mueve al hablar (personajes) y pulso en el marco (fotos). */
.av-wrap.talking .m-neutral, .av-wrap.talking .m-sad { display: none; }
.av-wrap.talking .m-happy { display: inline; transform-box: fill-box; transform-origin: 50% 20%; animation: talk-mouth 0.24s ease-in-out infinite alternate; }
@keyframes talk-mouth { from { transform: scaleY(0.25); } to { transform: scaleY(1.05); } }
.av-wrap.talking .head { animation: talk-head 0.5s ease-in-out infinite alternate; }
@keyframes talk-head { from { transform: rotate(-1deg) translateY(0); } to { transform: rotate(1deg) translateY(-1px); } }

/* Retrato con foto */
.av-wrap.portrait { position: relative; }
.photo-frame {
  position: absolute; left: 50%; top: 2%; width: 66%; aspect-ratio: 1; transform: translateX(-50%);
  border-radius: 50%; overflow: hidden; border: 5px solid #e8b94e; background: #10261c;
  box-shadow: 0 0 0 2px #6e4c08, 0 8px 16px rgba(0, 0, 0, 0.5);
}
.photo-frame.dealer { border-color: #2e9b54; }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av-wrap.portrait.talking .photo-frame { animation: speak-pulse 0.32s ease-in-out infinite alternate; }
@keyframes speak-pulse { from { box-shadow: 0 0 0 2px #6e4c08, 0 0 0 0 rgba(63, 179, 127, 0.8); } to { box-shadow: 0 0 0 2px #6e4c08, 0 0 0 12px rgba(63, 179, 127, 0); } }
.me-av .portrait .photo-frame, .avatar-option .portrait .photo-frame { border-width: 2px; }

/* Quién está hablando */
.player.speaking .plate, .dealer.speaking .plate { border-color: #3fb37f; box-shadow: 0 0 0 4px rgba(63, 179, 127, 0.45), 0 8px 18px rgba(0, 0, 0, 0.55); }

/* Globos de diálogo (chat y lo que canta la banca) */
.bubble {
  position: absolute; left: 50%; bottom: calc(100% - 6px); transform: translateX(-50%); z-index: 5;
  max-width: 280px; width: max-content; padding: 10px 14px; border-radius: 16px;
  background: #fffdf6; color: #1d2420; font: 600 20px system-ui, sans-serif; line-height: 1.25; text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45); overflow-wrap: anywhere;
}
.bubble::after { content: ""; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 10px solid transparent; border-top-color: #fffdf6; }
.bubble.call { background: linear-gradient(#ffe08a, #e0b13a); color: var(--gold-ink); font: 800 30px Georgia, serif; padding: 12px 22px; max-width: 360px; }
.bubble.call::after { border-top-color: #e0b13a; }
@media (max-width: 640px) { .bubble { font-size: 28px; max-width: 340px; } .bubble.call { font-size: 38px; } }

/* Barra de tiempo bajo el cartel del jugador */
.tbar { width: 150px; height: 10px; margin-top: 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.55); overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.25); }
.tbar-fill { width: 100%; height: 100%; background: #3fb37f; transform-origin: 0 50%; }
.dealer .tbar { width: 200px; }
@media (max-width: 640px) { .tbar { height: 16px; width: 180px; } }

/* Asientos libres clickeables para cambiarse */
.player.selectable { pointer-events: auto; cursor: pointer; opacity: 0.85; }
.player.selectable:hover .plate { border-color: var(--gold-2); background: linear-gradient(#2a4a3a, #10261c); }
.player.selectable .empty-chair { box-shadow: inset 0 0 0 6px #e8b94e, 0 8px 16px rgba(0, 0, 0, 0.5); }

/* Temporizador propio en el panel inferior */
.dock-timer { position: relative; height: 26px; border-radius: 8px; background: rgba(0, 0, 0, 0.5); overflow: hidden; grid-column: 1 / -1; }
.dock-timer-fill { position: absolute; inset: 0; background: linear-gradient(90deg, #2e9b54, #3fb37f); transform-origin: 0 50%; transition: transform 0.15s linear; }
.dock-timer.urgent .dock-timer-fill { background: linear-gradient(90deg, #b83a35, #e2625d); }
.dock-timer span { position: relative; display: block; text-align: center; font-weight: 800; line-height: 26px; font-size: 0.9rem; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

/* Elegir asiento */
.seat-picker-card { width: min(640px, 100%); }
.seat-picker { position: relative; width: 100%; aspect-ratio: 16 / 10; border-radius: 0 0 50% 50% / 0 0 70% 70%; background: radial-gradient(ellipse at 50% 10%, #1f8a5a, #0b4027); border: 8px solid #5b2f17; margin-top: 8px; }
.sp-dealer { position: absolute; left: 50%; top: 4%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.35); color: var(--gold-2); font-weight: 800; padding: 4px 12px; border-radius: 999px; }
.sp-seat {
  position: absolute; transform: translate(-50%, -50%); width: 64px; min-height: 64px; border-radius: 14px;
  border: 2px solid var(--gold-2); background: rgba(5, 12, 9, 0.85); color: #fff; font: inherit; font-size: 0.7rem;
  display: grid; justify-items: center; align-content: center; gap: 2px; cursor: pointer; padding: 4px;
}
.sp-seat b { font-size: 1.2rem; color: var(--gold-2); }
.sp-seat:hover:not(:disabled) { background: #2e6b4f; transform: translate(-50%, -50%) scale(1.08); }
.sp-seat.taken { border-color: rgba(255, 255, 255, 0.2); cursor: default; opacity: 0.85; }
.sp-seat span { max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-av { width: 40px; height: 44px; }
@media (max-width: 480px) { .sp-seat { width: 52px; min-height: 52px; } .sp-av { width: 32px; height: 36px; } }

/* Perfil */
.profile-photo { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.photo-preview { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; border: 4px solid var(--gold); background: #0f2a1f; display: grid; place-items: center; flex: none; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
#profile-modal .card-panel { max-height: calc(100dvh - 32px); overflow-y: auto; }

/* Cabecera de la mesa: voz */
.head-actions { display: flex; align-items: center; gap: 8px; }
.voice-ctrl { display: flex; gap: 6px; }
.ptt { user-select: none; -webkit-user-select: none; touch-action: none; background: #17402f; border-color: rgba(63, 179, 127, 0.6); }
.ptt.talking { background: linear-gradient(#e2625d, #b83a35); border-color: transparent; color: #fff; box-shadow: 0 0 0 4px rgba(226, 98, 93, 0.35); }

/* Chat */
.chat-panel { display: flex; flex-direction: column; gap: 8px; }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-head h3 { margin: 0; }
.chat-close { display: none; color: var(--panel-ink); border-color: #d8d0bf; }
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; align-content: start; max-height: 300px; min-height: 120px; overflow-y: auto; }
.chat-list li { background: #f1ebdc; border-radius: 12px 12px 12px 4px; padding: 6px 10px; justify-self: start; max-width: 90%; overflow-wrap: anywhere; }
.chat-list li.mine { background: #d9f0e2; border-radius: 12px 12px 4px 12px; justify-self: end; }
.chat-name { display: block; font-size: 0.75rem; font-weight: 800; color: #7a5a10; }
.chat-list li.mine .chat-name { color: #1e6b45; }
.chat-form input { background: #fff; }
.chat-fab {
  position: fixed; right: 16px; bottom: calc(var(--dock-h, 200px) + 16px); z-index: 25;
  width: 54px; height: 54px; border-radius: 50%; border: 0; font-size: 24px; cursor: pointer;
  background: linear-gradient(#ffd76a, #d9a628); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}
.badge-count { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font: 800 12px/22px system-ui, sans-serif; }

/* Celular: el chat es un cajón que se abre con el botón flotante. */
@media (max-width: 979px) {
  .chat-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-radius: 18px 18px 0 0; max-height: 70dvh; transform: translateY(105%); transition: transform 0.3s ease; }
  .chat-panel.open { transform: none; }
  .chat-panel .chat-list { max-height: 50dvh; }
  .chat-close { display: inline-block; }
  .table-head { flex-wrap: wrap; }
  .phase { order: 3; flex-basis: 100%; }
}
@media (min-width: 980px) {
  .chat-fab { display: none; }
  .chat-list { max-height: 260px; }
}

/* El globo de la banca va al costado: arriba de su cabeza queda fuera de la escena. */
.dealer .bubble { bottom: auto; top: 18%; left: calc(100% - 30px); transform: none; }
.dealer .bubble::after { left: auto; right: 100%; top: 50%; transform: translateY(-50%); border-top-color: transparent; border-right-color: #fffdf6; }
.dealer .bubble.call::after { border-top-color: transparent; border-right-color: #ffe08a; }
.dealer .photo-frame { top: 16%; width: 58%; }
.player .photo-frame { top: 6%; }

/* Nombre del sitio en la barra superior */
.brand span { font-family: Georgia, serif; letter-spacing: 0.08em; font-size: 0.8em; color: #f3e2b0; margin-left: 4px; white-space: nowrap; }
@media (max-width: 400px) { .brand { font-size: 0.95rem; letter-spacing: 0.15em; } .brand span { display: block; margin-left: 0; font-size: 0.7em; letter-spacing: 0.05em; } }

/* =====================================================================
   Pantalla de mesa a medida: sin scroll en la PC y sin huecos en el celular
   (estas reglas van al final a propósito: reemplazan las de más arriba)
   ===================================================================== */

#screen-table { padding: 0; }
.stage-wrap.fill { min-height: 0; }
.voice-ctrl .lbl { margin-left: 4px; }

/* ---------- celular y tablet ---------- */
@media (max-width: 979px) {
  .table-layout {
    display: flex; flex-direction: column; gap: 6px;
    height: calc(100dvh - var(--top-h, 56px));
    padding: 6px 0 calc(var(--dock-h, 180px) + 4px);
  }
  .table-head { flex: none; padding: 0 12px; gap: 6px; }
  .table-head .muted.small { display: none; }
  .code { font-size: 0.95rem; }
  .phase { font-size: 0.82rem; line-height: 1.25; }
  .head-actions { gap: 6px; }
  .stage-wrap.fill { flex: 1 1 auto; height: auto; }
  /* El resultado ya se ve en la mesa: el resumen queda para la PC. */
  #showdown-panel { display: none; }
  .side { padding: 0; }

  .action-dock { padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); gap: 8px; max-height: 55dvh; }
  .my-hand { gap: 10px; }
  .my-cards .card3d { width: 50px; height: 75px; }
  .my-hand .value { font-size: 0.9rem; }
  .my-hand .value b { font-size: 1.15rem; }
  .actions { gap: 8px; }
  .actions .prompt { font-size: 0.95rem; }
  .actions .hint { font-size: 0.85rem; }
  .action-dock .btn { min-height: 40px; padding: 8px 12px; }
  .action-dock .btn.small { min-height: 34px; padding: 4px 8px; }
  .action-dock input { min-height: 40px; padding: 8px 10px; }
  .dock-timer { height: 22px; }
  .dock-timer span { line-height: 22px; font-size: 0.8rem; }
  .chat-fab { width: 46px; height: 46px; font-size: 20px; right: 12px; bottom: calc(var(--dock-h, 180px) + 10px); }
}

/* Teléfonos: barra superior y botones de voz más compactos. */
@media (max-width: 560px) {
  .topbar { padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); gap: 8px; }
  #me-name { display: none; }
  .me { gap: 6px; }
  .me-av, .icon-btn { width: 34px; height: 34px; }
  .chip-pill { padding: 2px 8px; font-size: 0.9rem; }
  .voice-ctrl .lbl { display: none; }
  .voice-ctrl .btn, .head-actions .btn { min-height: 34px; padding: 4px 10px; }
  .ptt.talking .lbl { display: inline; }
}

/* Celular acostado: la mesa a la izquierda y las acciones a la derecha. */
@media (max-width: 979px) and (orientation: landscape) and (max-height: 520px) {
  .table-layout { padding-bottom: 6px; padding-right: min(42vw, 340px); }
  .action-dock { left: auto; top: var(--top-h, 48px); width: min(42vw, 340px); max-height: none; border-top: 0; border-left: 1px solid rgba(232, 185, 78, 0.35); overflow-y: auto; }
  .chat-fab { bottom: 12px; right: calc(min(42vw, 340px) + 12px); }
}

/* ---------- computadora: todo entra en la ventana ---------- */
@media (min-width: 980px) {
  body:has(#screen-table:not([hidden])) { overflow: hidden; }
  .table-layout {
    height: calc(100dvh - var(--top-h, 56px));
    max-width: none; margin: 0; padding: 10px 16px 12px;
    grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 360px);
    grid-template-areas: "head side" "stage side" "dock side";
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-items: stretch; gap: 10px 16px;
  }
  .stage-wrap.fill { height: 100%; }
  .side { grid-row: 1 / span 3; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 0; overflow: hidden; }
  .chat-panel { flex: 1 1 auto; min-height: 180px; }
  .chat-list { flex: 1 1 auto; min-height: 0; max-height: none; }
  #showdown-panel { flex: 0 1 auto; max-height: 45%; overflow-y: auto; }

  .action-dock { padding: 10px 14px; gap: 6px 18px; grid-template-columns: auto 1fr; }
  .action-dock .dock-timer { grid-column: 1 / -1; }
  .my-cards .card3d { width: 62px; height: 93px; }
  .actions { gap: 8px; }
  .action-dock .btn { min-height: 40px; padding: 8px 14px; }
  .action-dock input { min-height: 40px; }
  .actions > .btn { min-width: 220px; }
}

/* Pantallas de PC bajitas (notebooks): todavía más compacto. */
@media (min-width: 980px) and (max-height: 760px) {
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .table-layout { padding-top: 6px; padding-bottom: 8px; gap: 6px 14px; }
  .my-cards .card3d { width: 50px; height: 75px; }
  .actions .prompt { font-size: 0.95rem; }
}

/* Celular: montos rápidos de apuesta en una sola fila. */
@media (max-width: 979px) {
  .actions .btn-row .btn.small { flex: 1 1 0; min-width: 0; padding: 4px 2px; font-size: 0.82rem; }
  .actions .btn-row:has(.btn.small) { flex-wrap: nowrap; gap: 6px; }
}

/* Pantallas bajitas (celular acostado): barra superior compacta. */
@media (max-height: 520px) and (max-width: 979px) {
  .topbar { padding: 4px 12px; }
  #me-name { display: none; }
  .me-av, .icon-btn { width: 32px; height: 32px; }
  .brand { font-size: 0.95rem; }
  .voice-ctrl .lbl { display: none; }
}

/* =====================================================================
   Rendimiento: la escena 3D se redibuja entera si algo adentro cambia
   en cada cuadro. Se evitan animaciones de sombras y, en el celular,
   las animaciones constantes de los personajes y los filtros caros.
   ===================================================================== */

/* Anillo de turno: titila con opacidad (barato) en vez de animar la sombra. */
.turn-ring.on { animation: ring-fade 1.3s ease-in-out infinite; box-shadow: 0 0 22px 6px rgba(255, 215, 106, 0.6), inset 0 0 14px rgba(255, 215, 106, 0.5); }
@keyframes ring-fade { 50% { opacity: 0.45; } }

/* Las cartas que vuelan se componen aparte. */
.card-slot { will-change: transform; }

@media (max-width: 979px), (prefers-reduced-motion: reduce) {
  /* Sin filtros de sombra sobre elementos grandes. */
  .table-svg, .rack, .wheel svg, .av-wrap { filter: none !important; }
  .shoe::before { box-shadow: none; }
  .cface { box-shadow: 0 1px 0 #c2b493, 0 2px 3px rgba(0, 0, 0, 0.35); }
  .plate { box-shadow: none; }

  /* Personajes quietos (sin respirar, parpadear ni balancearse todo el tiempo). */
  .av .body, .av .head, .av .lid { animation: none !important; }
  .player.turn .av-wrap:not(.win):not(.lose), .dealer.turn .av-wrap:not(.win):not(.lose) { animation: none; }
  .player.turn .av-holder { transform: none; }
  .glow { display: none; }
  .player.turn .plate, .dealer.turn .plate { border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(255, 215, 106, 0.5); }

  /* Al hablar se sigue moviendo la boca (es breve). */
  .av-wrap.talking .m-happy { animation: talk-mouth 0.24s ease-in-out infinite alternate !important; }
}

/* Mesa vertical (celular parado): personajes y carteles un poco más chicos para que entren 10. */
.geom-tall .player .av-holder { width: 116px; height: 132px; }
.geom-tall .plate { min-width: 150px; max-width: 200px; padding: 3px 10px 4px; }
.geom-tall .pname { font-size: 24px; }
.geom-tall .pbal { font-size: 21px; }
.geom-tall .pstatus { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.geom-tall .dealer .av-holder { width: 170px; height: 194px; }

/* Valor de cada mano al mostrar resultados (sobre la mesa, bien grande). */
.hand-badge { pointer-events: none; z-index: 3; }
.hand-badge span {
  display: inline-block; white-space: nowrap; padding: 4px 16px; border-radius: 14px;
  font: 800 36px Georgia, serif; color: var(--gold-2); background: rgba(5, 12, 9, 0.88);
  border: 3px solid var(--gold); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5);
  animation: badge-in 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.hand-badge.win span { color: #9ff0c6; border-color: #3fb37f; }
.hand-badge.lose span { color: #ffb3ae; border-color: #e2625d; }
@keyframes badge-in { from { opacity: 0; scale: 0.6; } }
@media (max-width: 979px) { .hand-badge span { font-size: 46px; padding: 4px 18px; } }

/* Puntos de referencia para encuadrar la mesa (invisibles). */
.rim-pt { position: absolute; width: 1px; height: 1px; pointer-events: none; }

/* Primera persona: tu propio personaje es semitransparente para no taparte la mesa. */
.player.me .av-holder, .dealer.me .av-holder { opacity: 0.3; }
.player.me .glow, .dealer.me .glow { display: none; }
/* Textos del paño (FICO, números de asiento): siempre derechos aunque la mesa gire. */
.table-svg .felt-text { transform-box: fill-box; transform-origin: center; transform: rotate(calc(-1 * var(--rz, 0deg))); transition: transform 0.9s ease; }
.dir-label { transition: transform 0.9s ease; }
