:root {
  --wood: #2a1b12;
  --wood2: #3b2618;
  --felt: #1f6b43;
  --felt-dark: #154a2f;
  --cream: #fbf5e6;
  --ink: #23170f;
  --gold: #e9b949;
  --us: #5fb4ff;
  --them: #ff7a6b;
  --text: #f6efe0;
  --muted: #c8bba3;
  --card-w: 74px;
  --card-h: 112px;
  --mini-w: 46px;
  --mini-h: 70px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--wood2), var(--wood) 70%) fixed;
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Botones ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 800;
  background: #f3e7cc; color: var(--ink); box-shadow: 0 3px 0 #b9a47a;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b9a47a; }
.btn.primary { background: var(--gold); box-shadow: 0 3px 0 #a37a1d; }
.btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); }
.btn.sm { padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn.call { background: #ffe08a; box-shadow: 0 3px 0 #b48a1f; }
.btn.envido { background: #bde3ff; box-shadow: 0 3px 0 #5f93b8; }
.btn.yes { background: #9de6a8; box-shadow: 0 3px 0 #4f9a5b; }
.btn.no { background: #ffb3a8; box-shadow: 0 3px 0 #b8655a; }
.btn.mazo { background: #d9cfc0; box-shadow: 0 3px 0 #8f8473; }
.btn.flor { background: #f6b8e0; box-shadow: 0 3px 0 #a7618e; }

/* ---------- Inicio y sala ---------- */
.screen { min-height: 100vh; min-height: 100dvh; }
#home, #lobby { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.home-card {
  width: 100%; max-width: 440px; background: rgba(0,0,0,.28);
  border: 1px solid rgba(255,255,255,.08); border-radius: 22px; padding: 26px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo { font-family: 'Alfa Slab One', serif; font-weight: 400; font-size: 52px; margin: 0 0 18px; text-align: center; color: var(--gold); line-height: .95; text-shadow: 0 4px 0 #6b4a12; }
.logo span { display: block; font-size: 20px; letter-spacing: 6px; text-transform: uppercase; color: var(--text); text-shadow: none; margin-top: 6px; }
.logo.small { font-size: 30px; }
.logo .code { display: inline; font-size: 30px; letter-spacing: 4px; color: var(--text); }
.field { display: block; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.field input, .join-row input, .chat-form input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,.12); background: rgba(0,0,0,.3); color: var(--text); outline: none;
}
.field input:focus, .join-row input:focus { border-color: var(--gold); }
.box { background: rgba(255,255,255,.05); border-radius: 16px; padding: 14px; margin-top: 14px; }
.box h2 { margin: 0 0 10px; font-size: 16px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--gold); }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.opt-row > span { color: var(--muted); font-weight: 600; }
.seg { display: flex; background: rgba(0,0,0,.3); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 10px; border-radius: 8px; font-weight: 800; font-size: 14px; }
.seg button.on { background: var(--cream); color: var(--ink); }
.join-row { display: flex; gap: 8px; }
.join-row input { margin: 0; text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 800; }
.muted { color: var(--muted); }
.tiny { font-size: 13px; }
.center { text-align: center; }
#lobby .btn { margin-top: 10px; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.team-col h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.team-col.t0 h3 { color: var(--us); } .team-col.t1 h3 { color: var(--them); }
.seat {
  background: rgba(0,0,0,.25); border-radius: 12px; padding: 10px; margin-bottom: 8px; min-height: 64px;
  display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent;
}
.seat.me { border-color: var(--gold); }
.seat .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .nm small { color: var(--muted); font-weight: 600; }
.seat .row { display: flex; gap: 6px; flex-wrap: wrap; }
.seat .btn { margin: 0 !important; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #6c6; margin-right: 6px; vertical-align: middle; }
.dot.off { background: #c66; }

/* ---------- Mesa ---------- */
#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; gap: 10px; background: rgba(0,0,0,.25); }
.score { display: flex; gap: 18px; align-items: center; }
.sc { display: flex; align-items: center; gap: 8px; }
.sc .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; font-weight: 800; }
.sc.us .lbl { color: var(--us); } .sc.them .lbl { color: var(--them); }
.sc .num { font-family: 'Alfa Slab One', serif; font-size: 26px; line-height: 1; }
.sc .sub { font-size: 11px; color: var(--muted); }
.fos-wrap { display: flex; gap: 2px; flex-wrap: wrap; max-width: 130px; }
.fos { width: 18px; height: 18px; stroke: #f2d38a; stroke-width: 3; stroke-linecap: round; }
.top-right { display: flex; gap: 8px; align-items: center; }
.pill { background: rgba(255,255,255,.08); padding: 5px 10px; border-radius: 999px; font-size: 13px; color: var(--muted); white-space: nowrap; }

.main { flex: 1; display: flex; min-height: 0; position: relative; }
.table-wrap { flex: 1; position: relative; min-height: 0; padding: 14px; }
.felt {
  position: absolute; inset: 14px; border-radius: 48% / 42%;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 85%);
  border: 12px solid #5a3a22; box-shadow: inset 0 0 50px rgba(0,0,0,.5), 0 10px 30px rgba(0,0,0,.5);
}
.bubbles { position: absolute; inset: 14px; pointer-events: none; }
.spot { position: absolute; transform: translate(-50%, -50%); text-align: center; width: 128px; z-index: 2; }
.plate {
  display: inline-flex; flex-direction: column; align-items: center; padding: 5px 10px; border-radius: 12px;
  background: rgba(0,0,0,.45); border: 2px solid transparent; max-width: 128px; transition: box-shadow .2s;
}
.plate.t-us { border-color: var(--us); } .plate.t-them { border-color: var(--them); }
.plate.active { box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); }
.plate .pn { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 108px; }
.plate .tags { display: flex; gap: 4px; margin-top: 2px; }
.tag { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: rgba(255,255,255,.15); text-transform: uppercase; }
.tag.mano { background: var(--gold); color: var(--ink); }
.backs { display: flex; justify-content: center; margin-top: 4px; height: 30px; }
.back-mini { width: 20px; height: 30px; border-radius: 4px; margin: 0 -3px; border: 1.5px solid #fff;
  background: repeating-linear-gradient(45deg, #a3262e 0 4px, #861c23 4px 8px); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.played { position: absolute; transform: translate(-50%, -50%); display: flex; gap: 4px; z-index: 1; }
.played .card { width: var(--mini-w); height: var(--mini-h); }
.played .card.old { opacity: .5; transform: scale(.9); }
.played .card.won { box-shadow: 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,.4); opacity: 1; }
.played .slot { width: var(--mini-w); height: var(--mini-h); }

.center-info { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; z-index: 3; }
.ci-chip { display: inline-block; background: rgba(0,0,0,.5); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; margin: 2px; }
.ci-chip.truco { color: #ffe08a; }

.bubble {
  position: absolute; transform: translate(-50%, -130%); background: var(--cream); color: var(--ink);
  font-weight: 800; padding: 8px 14px; border-radius: 16px; white-space: nowrap; font-size: 17px;
  box-shadow: 0 6px 18px rgba(0,0,0,.4); animation: pop .25s ease-out; z-index: 10;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: var(--cream); }
@keyframes pop { from { transform: translate(-50%, -110%) scale(.6); opacity: 0; } }

/* ---------- Cartas ---------- */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 9px; background: var(--cream);
  position: relative; box-shadow: 0 3px 8px rgba(0,0,0,.4); color: var(--ink); flex: none;
  border: 1px solid #d8ccb0; overflow: hidden;
}
.card .cn { position: absolute; top: 4px; left: 6px; font-family: 'Alfa Slab One', serif; font-size: 18px; line-height: 1; }
.card .cn.b { top: auto; left: auto; bottom: 4px; right: 6px; transform: rotate(180deg); }
.card .cs { position: absolute; inset: 22% 14%; display: flex; align-items: center; justify-content: center; }
.card .cs svg { width: 100%; height: 100%; }
.card .fig { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: #8a7a5d; font-weight: 800; }
.card.espada .cn { color: #2b4a66; } .card.basto .cn { color: #3d5a12; }
.card.oro .cn { color: #a06d00; } .card.copa .cn { color: #a0222b; }
.played .card .cn { font-size: 13px; top: 3px; left: 4px; }
.played .card .cn.b { display: none; }
.played .card .fig { display: none; }

/* ---------- Abajo ---------- */
.bottom { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.3); }
.status { text-align: center; font-weight: 800; min-height: 22px; margin-bottom: 6px; }
.status.mine { color: var(--gold); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 44px; margin-bottom: 8px; }
.hand-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.mine-info { font-size: 13px; color: var(--muted); text-align: right; min-width: 70px; }
.mine-info b { color: var(--text); font-size: 18px; display: block; }
.hand { display: flex; gap: 10px; justify-content: center; min-height: var(--card-h); }
.hand .card { transition: transform .12s; }
.hand.can .card { cursor: pointer; }
.hand.can .card:hover { transform: translateY(-10px); }
.hand:not(.can) .card { filter: brightness(.85); }

/* ---------- Historial ---------- */
.side { width: 290px; display: flex; flex-direction: column; background: rgba(0,0,0,.3); border-left: 1px solid rgba(255,255,255,.06); }
.side-head { padding: 10px 12px; font-weight: 800; display: flex; justify-content: space-between; }
.side-head .x { display: none; background: none; border: 0; color: var(--text); font-size: 18px; }
.log { flex: 1; overflow-y: auto; padding: 0 12px; font-size: 13px; }
.log div { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log .k-hand { color: var(--gold); font-weight: 800; margin-top: 8px; }
.log .k-points { color: #9de6a8; font-weight: 800; }
.log .k-over { color: var(--gold); font-weight: 800; font-size: 15px; }
.log .k-call { font-weight: 800; }
.log .k-play { color: var(--muted); }
.chat { max-height: 26%; overflow-y: auto; padding: 6px 12px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.08); }
.chat b { color: var(--gold); }
.chat-form { display: flex; gap: 6px; padding: 8px 10px; }
.chat-form input { margin: 0; padding: 8px 10px; }
.top-right #btnLog { display: none; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.ov-card { background: var(--wood2); border-radius: 20px; padding: 26px; text-align: center; max-width: 360px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.ov-card h2 { font-family: 'Alfa Slab One', serif; font-weight: 400; color: var(--gold); font-size: 32px; margin: 0 0 8px; }
.ov-card .btn { margin-top: 12px; }

.toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: var(--cream); color: var(--ink); padding: 10px 16px; border-radius: 12px; font-weight: 800; z-index: 100; box-shadow: 0 8px 20px rgba(0,0,0,.4); max-width: calc(100% - 32px); text-align: center; }
.result-banner { display: inline-block; background: var(--cream); color: var(--ink); padding: 8px 16px; border-radius: 14px; font-weight: 800; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.conn { position: fixed; bottom: 12px; left: 12px; background: #b33; padding: 6px 12px; border-radius: 10px; font-weight: 800; z-index: 99; font-size: 13px; }

@media (max-width: 900px) {
  .side { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; width: min(320px, 88vw); background: var(--wood); transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; }
  .side-head .x { display: block; }
  .top-right #btnLog { display: inline-block; }
}
@media (max-width: 600px) {
  :root { --card-w: 64px; --card-h: 97px; --mini-w: 34px; --mini-h: 52px; }
  .table-wrap { padding: 8px; }
  .felt, .bubbles { inset: 8px; }
  .felt { border-width: 8px; }
  .spot { width: 96px; }
  .plate { padding: 3px 7px; }
  .plate .pn { font-size: 12px; max-width: 84px; }
  .back-mini { width: 15px; height: 23px; }
  .backs { height: 23px; }
  .sc .num { font-size: 22px; }
  .fos-wrap { display: none; }
  .pill { display: none; }
  .topbar { padding: 8px 10px; }
  .score { gap: 12px; }
  .btn { padding: 9px 12px; font-size: 14px; }
  .bubble { font-size: 14px; padding: 6px 10px; }
  .mine-info { min-width: 50px; font-size: 11px; }
  .logo { font-size: 44px; }
}
