/* ============ Tokens ============ */
:root {
  /* color */
  --felt: #0c3326;
  --felt-2: #13503a;
  --felt-dark: #082219;
  --surface: rgba(4, 22, 16, 0.6);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.14);
  --border-gold: rgba(217, 164, 65, 0.4);
  --gold: #d9a441;
  --gold-2: #f1c86a;
  --on-gold: #2a1d05;
  --cream: #fbf6ea;
  --ink: #1c1a17;
  --suit-red: #c0392b;
  --text: #eef3ee;
  --muted: #b3cabd;        /* 7:1 sobre el fieltro */
  --danger: #ef6b5f;
  --danger-bg: #6e2620;
  --success: #6fd39a;
  --focus: #ffe08a;

  /* tamaño */
  --card-w: 84px;
  --card-h: 120px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --tap: 44px;

  /* movimiento */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --t-fast: 120ms;
  --t-med: 220ms;
  --t-slow: 360ms;

  /* capas */
  --z-banner: 30; --z-modal: 40; --z-toast: 50;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 25%, var(--felt-2) 0%, var(--felt) 55%, var(--felt-dark) 100%) fixed;
  background-color: var(--felt);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.num { font-variant-numeric: tabular-nums; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.gold { color: var(--gold-2); }
.ic.fill { fill: currentColor; stroke: none; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }

/* ============ Botones ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast), filter var(--t-fast);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--on-gold); border-color: #b3832c; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.big { width: 100%; min-height: 52px; font-size: 1.0625rem; }
.btn.knock { background: var(--danger-bg); border-color: #a5463c; color: #ffe3de; }
.btn.knock:hover { background: #82302a; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.icon-btn {
  width: var(--tap); height: var(--tap);
  display: inline-grid; place-items: center;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="false"], .icon-btn[aria-expanded="true"] { color: var(--gold-2); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Pantallas de inicio y sala ============ */
.screen { min-height: 100vh; min-height: 100dvh; }
#home, #lobby { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: var(--space-5) var(--space-4); }
.panel {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  padding: var(--space-6) var(--space-5);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.logo { position: relative; height: 170px; margin-bottom: var(--space-2); }
/* Abanico de 3 cartas: dos volteadas a los lados y el 31 al frente, en medio */
.logo-card {
  position: absolute; left: 50%; top: 4px; width: 116px; height: 160px; margin-left: -58px;
  transform-origin: 50% 100%; perspective: 700px;
}
.logo-card.left { transform: translateX(-34px) rotate(-16deg); }
.logo-card.right { transform: translateX(34px) rotate(16deg); }
.logo-card.front { transform: translateY(-6px); z-index: 1; }
/* Giro 3D: la cara "lc-rank" está detrás y se ve al girar la carta 180° */
.lc-inner {
  position: relative; width: 100%; height: 100%; transform-style: preserve-3d;
  transition: transform 700ms cubic-bezier(.3, 1.35, .5, 1);
}
.logo-card.left .lc-inner { transition-delay: 0ms; }
.logo-card.front .lc-inner { transition-delay: 130ms; }
.logo-card.right .lc-inner { transition-delay: 260ms; }
.logo.flipped .lc-inner { transform: rotateY(180deg); }
.lc-face {
  position: absolute; inset: 0; border-radius: 14px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
}
.lc-back {
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.1) 0 6px, transparent 6px 12px), linear-gradient(135deg, #8e2a22, #5a1813);
  border: 4px solid var(--cream);
}
.lc-31 { background: var(--cream); color: var(--ink); display: grid; place-items: center; box-shadow: 0 18px 40px rgba(0,0,0,.4); }
.lc-31 span { font-family: 'Fraunces', serif; font-weight: 800; font-size: 5rem; line-height: 1; }
.lc-rank {
  transform: rotateY(180deg);
  background: var(--cream); color: var(--ink);
  font-family: 'Fraunces', serif; font-weight: 800;
}
.lc-rank.red { color: var(--suit-red); }
.lc-rank .c { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: .95; font-size: 1.375rem; }
.lc-rank .c small { font-size: 1.125rem; }
.lc-rank .tl { top: 8px; left: 9px; }
.lc-rank .br { bottom: 8px; right: 9px; transform: rotate(180deg); }
.lc-rank .mid { position: absolute; inset: 0; display: grid; place-items: center; font-size: 3.75rem; line-height: 1; }
.lc-rank .mid small { font-size: 2.25rem; margin-left: 2px; }
.tagline { text-align: center; color: var(--muted); margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .875rem; color: var(--muted); font-weight: 500; }
.field input, .join-row input, .field select {
  min-height: 48px;
  background: rgba(0,0,0,.28); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px;
  font-size: 1rem;
  transition: border-color var(--t-fast);
}
.field input:focus, .join-row input:focus, .field select:focus { border-color: var(--gold); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .875rem; margin: 0; min-height: 0; }
.field-error:empty { display: none; }
.help { color: var(--muted); font-size: .875rem; line-height: 1.45; margin: 0; }
.help:empty { display: none; }
.field-label { font-size: .875rem; color: var(--muted); font-weight: 500; }

/* Selector segmentado (vidas) */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: rgba(0,0,0,.28); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px;
}
.segmented button {
  min-height: 40px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-weight: 700; font-size: 1rem;
  font-variant-numeric: tabular-nums;
  transition: background var(--t-fast), color var(--t-fast);
}
.segmented button:hover { background: var(--surface-2); color: var(--text); }
.segmented button[aria-checked="true"] { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--on-gold); }
.segmented button:disabled { opacity: .35; cursor: not-allowed; background: transparent; }
.segmented button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Apuesta ficticia */
.settings .field { display: flex; flex-direction: column; gap: 6px; }
.money-input { position: relative; display: flex; align-items: center; }
.money-input span { position: absolute; left: 14px; color: var(--gold-2); font-weight: 700; pointer-events: none; }
.money-input input { width: 100%; padding-left: 30px; font-variant-numeric: tabular-nums; }
.bet-options { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border-gold); border-radius: var(--radius); background: rgba(217,164,65,.06); }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; font-size: .9375rem; }
.check input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; margin: 0; }
.bet-summary { display: flex; gap: 10px; align-items: flex-start; padding: var(--space-3); border-radius: var(--radius); background: rgba(217,164,65,.1); border: 1px solid var(--border-gold); font-size: .9375rem; line-height: 1.45; }
.bet-summary > .ic { color: var(--gold-2); width: 20px; height: 20px; flex: none; margin-top: 1px; }
.bet-summary b { color: var(--gold-2); }
.ledger { display: flex; flex-direction: column; gap: var(--space-2); }
.ledger-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.small-btn { min-height: 36px; padding: 4px 12px; font-size: .875rem; }
.ledger .section-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0; }
.ledger .section-title .ic { color: var(--gold-2); }
.small-title { font-size: .875rem; margin-top: var(--space-2) !important; color: var(--muted); }
.ledger-list, .transfers { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.ledger-list li, .transfers li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2); min-height: 40px; }
.ledger-list .pname { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-list .place { color: var(--muted); font-variant-numeric: tabular-nums; width: 2.2em; flex: none; }
.transfers li { flex-wrap: wrap; }
.transfers .ic { width: 16px; height: 16px; color: var(--muted); }
.amount { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.pos { color: var(--success); }
.amount.neg { color: var(--danger); }
#resultPayouts { margin-top: var(--space-3); text-align: left; }

/* Barajado verificable */
.fair-box { margin-top: var(--space-3); text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: var(--space-2); }
.fair-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.fair-head .section-title { display: flex; align-items: center; gap: 6px; margin: 0; }
.fair-head .section-title .ic { color: var(--gold-2); width: 18px; height: 18px; }
.fair-head p { margin: 2px 0 0; }
.fair-box code { font-family: ui-monospace, Consolas, monospace; font-size: .8125rem; word-break: break-all; color: var(--text); }
.fair-checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.fair-checks:empty { display: none; }
.fair-checks li { display: flex; gap: 8px; align-items: flex-start; font-size: .875rem; }
.fair-checks li .ic { width: 16px; height: 16px; margin-top: 2px; }
.fair-checks li.ok .ic { color: var(--success); }
.fair-checks li.fail { color: var(--danger); font-weight: 700; }
.fair-checks li.info { color: var(--muted); }
.fair-details summary { cursor: pointer; font-size: .875rem; color: var(--muted); }
.fair-details[open] { display: flex; flex-direction: column; gap: var(--space-2); }
.fair-details p, .fair-details div { margin: 0; }
.fair-order { display: flex; flex-wrap: wrap; gap: 4px; font-family: ui-monospace, Consolas, monospace; font-size: .8125rem; }
.fair-order span { background: var(--surface-3); border-radius: 4px; padding: 1px 5px; }
.fair-order span.red { color: #ff9c90; }

/* Selects nativos (por si se usan) con los tonos del juego */
select { color-scheme: dark; }
select option { background: #0d2f24; color: var(--text); }
.join-row { display: flex; gap: var(--space-2); }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .3em; font-weight: 700; min-width: 0; text-align: center; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .875rem; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.lobby-card { max-width: 460px; gap: var(--space-5); padding: var(--space-6); }
.invite-fallback { display: flex; flex-direction: column; gap: 6px; }
.invite-fallback.hidden { display: none; }
.invite-fallback input { text-transform: none; letter-spacing: 0; font-weight: 500; text-align: left; font-size: .9375rem; }
.lobby-main { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.lobby-main > section, .lobby-card .chat-box { display: flex; flex-direction: column; gap: var(--space-3); }
/* En pantallas anchas el chat va en una columna al lado, así las reglas pueden crecer sin empujarlo */
@media (min-width: 900px) {
  .lobby-card {
    max-width: 920px;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px);
    column-gap: var(--space-6); row-gap: var(--space-4);
  }
  .lobby-card .chat-box {
    grid-column: 2; grid-row: 1; align-self: start;
    /* Se queda fijo al bajar, con la caja para escribir siempre a la vista */
    position: sticky; top: var(--space-5);
    height: min(600px, calc(100dvh - 2 * var(--space-5)));
    min-height: 0; padding-left: var(--space-6); border-left: 1px solid var(--border);
  }
  .lobby-card .chat-box .chat-list { flex: 1 1 0; height: auto; min-height: 260px; }
  .lobby-foot { grid-column: 1 / -1; }
}
.lobby-card .section-title { margin: 0; }
.lobby-card #hostControls { gap: var(--space-4); }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3); padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.btn.primary:disabled { background: transparent; color: var(--muted); border: 1px dashed var(--border-gold); opacity: 1; }
.eyebrow { font-size: .8125rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.room-code { font-family: 'Fraunces', serif; font-size: 2.75rem; line-height: 1.1; letter-spacing: .14em; color: var(--gold-2); }
.section-title { font-size: 1rem; font-weight: 700; margin-bottom: var(--space-2); }
.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border-radius: var(--radius); padding: 6px 6px 6px 12px; min-height: 52px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: .875rem;
  background: var(--gold); color: var(--on-gold);
}
.avatar.bot { background: var(--surface-3); color: var(--text); }
.avatar .ic { width: 18px; height: 18px; }
.player-list .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-3); color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.tag .ic { width: 13px; height: 13px; }
.tag.host { background: rgba(217,164,65,.22); color: var(--gold-2); }
.tag.turn { background: var(--gold); color: var(--on-gold); }
.tag.knock { background: var(--danger-bg); color: #ffe3de; }
.tag.off { background: #3b3b3b; color: #ddd; }
.tag.good { background: rgba(111,211,154,.18); color: var(--success); }
.settings { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.settings legend { float: left; width: 100%; padding: 0; margin: 0 0 var(--space-3); }
.settings legend + * { clear: both; }
.settings .field { flex: 1; min-width: 150px; }
.waiting { display: flex; align-items: center; justify-content: center; gap: var(--space-2); color: var(--muted); margin: 0; }
.lobby-foot { display: flex; justify-content: space-between; margin: 0 -10px -10px; padding-top: var(--space-2); border-top: 1px solid var(--border); }

/* ============ Mesa ============ */
#game {
  max-width: 1320px; margin: 0 auto;
  padding: 0 var(--space-4) var(--space-4);
  display: grid; gap: var(--space-3);
  grid-template-columns: 1fr;
  grid-template-areas: "top" "table" "status" "me";
  align-content: start;
}
#game.hidden { display: none; }
.topbar { grid-area: top; display: flex; justify-content: space-between; align-items: center; padding-top: var(--space-2); }
.topbar-info { display: flex; align-items: baseline; gap: var(--space-2); white-space: nowrap; }
.topbar-info b { font-family: 'Fraunces', serif; font-size: 1.25rem; letter-spacing: .12em; color: var(--gold-2); }
.topbar-actions { display: flex; gap: 0; }

/* ---- Mesa de póker ovalada: crece con el número de jugadores ---- */
.table-wrap { grid-area: table; display: flex; justify-content: center; padding: 58px 64px 64px; }
.poker-table {
  --tw: 600px;
  position: relative;
  /* Crece con los jugadores y con la pantalla, pero sin pasarse del alto disponible
     (--reserve = espacio para barra superior, estado y tu mano). Nunca más chica que el tamaño base. */
  width: min(100%, calc(var(--tw) * var(--zoom, 1)), max(var(--tw), calc((100dvh - var(--reserve, 0px)) * 2)));
  aspect-ratio: 2 / 1;
  border-radius: 999px;
  padding: 14px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.18), transparent 60%),
    linear-gradient(180deg, #8a5a32 0%, #5e3a1e 55%, #3e2512 100%);
  box-shadow: 0 24px 60px rgba(0,0,0,.5), inset 0 2px 0 rgba(255,255,255,.18), inset 0 -3px 0 rgba(0,0,0,.35);
  transition: width var(--t-slow) var(--ease-out);
}
.felt {
  position: relative; width: 100%; height: 100%; border-radius: 999px;
  background: radial-gradient(ellipse at 50% 45%, #1c7a54 0%, #136043 45%, #0b3f2c 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.07), inset 0 0 0 10px rgba(0,0,0,.12), inset 0 12px 40px rgba(0,0,0,.45);
  display: grid; place-items: center;
}
.felt::after {
  content: ''; position: absolute; inset: 9%; border-radius: 999px;
  border: 2px solid rgba(241,200,106,.16); pointer-events: none;
}
.felt-logo {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Fraunces', serif; font-weight: 800; font-size: clamp(4rem, 14vw, 9rem);
  color: rgba(255,255,255,.05); pointer-events: none; user-select: none;
}
.seats { position: absolute; inset: 0; pointer-events: none; }
.seat {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: auto; width: 116px;
  transition: opacity var(--t-med), left var(--t-slow) var(--ease-out), top var(--t-slow) var(--ease-out);
}
.seat.out { opacity: .4; }
.seat .avatar-ring { position: relative; }
.seat .avatar {
  width: 50px; height: 50px; font-size: 1.25rem;
  border: 3px solid #2a1a0d; box-shadow: 0 6px 16px rgba(0,0,0,.45);
  transition: border-color var(--t-med), box-shadow var(--t-med);
}
.seat .avatar.bot .ic { width: 24px; height: 24px; }
.seat.turn .avatar { border-color: var(--gold-2); box-shadow: 0 0 0 4px rgba(241,200,106,.25), 0 0 24px rgba(241,200,106,.55); }
.seat.turn .avatar-ring::before {
  content: ''; position: absolute; inset: -7px; border-radius: 50%;
  border: 2px solid var(--gold-2); opacity: 0; animation: pulse 1.6s var(--ease-out) infinite;
}
@keyframes pulse { 0% { opacity: .8; transform: scale(.95); } 100% { opacity: 0; transform: scale(1.25); } }
.seat .plate {
  min-width: 96px; max-width: 116px; text-align: center;
  background: linear-gradient(180deg, #1b130c, #0e0a06); border: 1px solid rgba(241,200,106,.35);
  border-radius: 12px; padding: 3px 10px 4px; box-shadow: 0 6px 16px rgba(0,0,0,.45);
}
.seat.turn .plate { border-color: var(--gold-2); }

/* Rivales: solo avatar; la placa (nombre + vidas) aparece con hover o al tocar */
.avatar-btn { background: none; border: none; padding: 0; border-radius: 50%; display: block; cursor: pointer; }
.avatar-btn:focus-visible { outline-offset: 4px; border-radius: 50%; }
.seat-info {
  position: absolute; left: 50%; z-index: 20; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.seat.info-below .seat-info { top: calc(100% + 2px); transform: translate(-50%, -4px); }
.seat.info-above .seat-info { bottom: calc(100% + 2px); transform: translate(-50%, 4px); }
.seat:not(.seat-me):hover .seat-info,
.seat:not(.seat-me):focus-within .seat-info,
.seat.open .seat-info { opacity: 1; transform: translate(-50%, 0); }
.seat:not(.seat-me):hover, .seat.open, .seat:focus-within { z-index: 15; }
.seat:not(.seat-me) .badges { margin-top: 2px; }
.seat.seat-me .plate { border-color: var(--gold); background: linear-gradient(180deg, #3a2a0e, #1d1405); }
.seat .sname { display: block; font-weight: 700; font-size: .875rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .plate .lives { justify-content: center; }
.seat .plate .lives .ic { width: 13px; height: 13px; }
.seat .badges { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.seat .badges .tag { font-size: .625rem; padding: 1px 6px; }
.dealer-chip {
  position: absolute; right: -10px; bottom: -4px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff, #e8e1cf 60%, #bfb59c);
  color: #7a2a1d; font: 800 .75rem 'DM Sans', sans-serif;
  border: 2px dashed #7a2a1d; box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.seat-cards { position: absolute; transform: translate(-50%, -50%); display: flex; pointer-events: none; }
.seat-cards .card { --card-w: 26px; --card-h: 38px; border-radius: 4px; border-width: 2px; margin-left: -12px; box-shadow: 0 3px 8px rgba(0,0,0,.4); }
.seat-cards .card:first-child { margin-left: 0; }
.seat-cards .card:nth-child(1) { transform: rotate(-8deg); }
.seat-cards .card:nth-child(3) { transform: rotate(8deg); }
.seat-cards.out { opacity: .3; }
/* Rival de enfrente: cartas a la izquierda de su avatar, sobre el borde de la mesa */
.seat-cards.beside { left: calc(50% - var(--beside-off, 42px)); top: 0; transform: translate(-100%, -50%); }

/* Carta volando durante el reparto */
.fly-card { position: fixed; left: 0; top: 0; z-index: 25; pointer-events: none; --card-w: 40px; --card-h: 58px; border-radius: 6px; will-change: transform; }

.lives { display: inline-flex; gap: 2px; align-items: center; }
.lives .ic { width: 16px; height: 16px; fill: var(--danger); stroke: none; }
.lives .ic.lost { fill: rgba(255,255,255,.16); }

.table-center { position: relative; z-index: 1; display: flex; justify-content: center; gap: var(--space-5); --card-w: 62px; --card-h: 89px; }
.table-center .pile-label { font-size: .75rem; color: #cfe5d8; background: rgba(0,0,0,.35); padding: 1px 8px; border-radius: 99px; }
.pile {
  background: none; border: none; padding: 6px; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.pile:disabled { cursor: default; }
.pile .card { transition: transform var(--t-med) var(--ease-out), box-shadow var(--t-med); }
.pile.active .card { box-shadow: 0 0 0 3px var(--gold-2), 0 10px 24px rgba(0,0,0,.4); }
.pile.active:hover .card { transform: translateY(-5px); }
.pile.active:active .card { transform: translateY(-2px) scale(.98); }
.pile-label { font-size: .875rem; color: var(--muted); max-width: 130px; text-align: center; line-height: 1.3; }
.pile.active .pile-label { color: var(--gold-2); font-weight: 700; }
.deck-stack { position: relative; display: block; }
.deck-stack::before, .deck-stack::after {
  content: ''; position: absolute; inset: 0; border-radius: 10px; background: #5a1813; border: 3px solid var(--cream);
}
.deck-stack::before { transform: translate(4px, 4px); opacity: .5; }
.deck-stack::after { transform: translate(2px, 2px); opacity: .75; }
.deck-stack .card { position: relative; z-index: 1; }
.empty-slot { display: block; width: var(--card-w); height: var(--card-h); border: 2px dashed rgba(255,255,255,.22); border-radius: 10px; }

.status { grid-area: status; text-align: center; font-weight: 700; min-height: 1.6em; font-size: 1.0625rem; margin: 0; }
.status.mine { color: var(--gold-2); }

.me {
  grid-area: me;
  background: rgba(0,0,0,.26); border: 1px solid var(--border-gold); border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); align-items: center;
  justify-self: center; width: fit-content; min-width: min(100%, 380px); max-width: min(100%, 520px); /* se ajusta a las cartas */
  transition: border-color var(--t-med), box-shadow var(--t-med);
}
.me.turn { border-color: var(--gold); box-shadow: 0 0 32px rgba(217,164,65,.22); }
.me.out { opacity: .6; }
.me-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; justify-content: center; }
.me-name { font-weight: 700; }
.score-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--cream); color: var(--ink); border-radius: 99px; padding: 4px 14px; font-weight: 800;
}
.score-chip .big { font-family: 'Fraunces', serif; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.score-chip .red { color: var(--suit-red); }
.score-chip .ic { width: 16px; height: 16px; color: #2f6b4f; }
.hand {
  display: flex; gap: 10px; justify-content: center; align-items: flex-end; flex-wrap: wrap;
  min-height: calc(var(--card-h) + 26px); padding: 16px 0 10px;
}
.hand .card { cursor: default; transition: transform var(--t-med) var(--ease-out), box-shadow var(--t-med); }
.hand .card.enter { animation: deal var(--t-slow) var(--ease-out) both; }
.hand.choosing .card { cursor: pointer; }
.hand.choosing .card:hover { transform: translateY(-8px); }
.hand .card.selected { transform: translateY(-18px); box-shadow: 0 0 0 3px var(--danger), 0 16px 28px rgba(0,0,0,.45); }
.hand .card.locked { opacity: .7; }
.hand .card.counts::before {
  content: ''; position: absolute; left: 22%; right: 22%; bottom: -9px; height: 4px; border-radius: 4px; background: var(--gold-2);
}
.hand .card.fresh::after {
  content: 'nueva'; position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: var(--on-gold); font-family: 'DM Sans', sans-serif;
  font-size: .6875rem; font-weight: 800; padding: 1px 8px; border-radius: 99px; text-transform: uppercase;
}
.preview { margin: 0; color: var(--muted); font-size: .9375rem; text-align: center; }
.preview:empty { display: none; }
.preview b { color: var(--text); }
.actions { display: flex; gap: var(--space-3); flex-wrap: wrap; justify-content: center; }
.actions:not(:has(.btn:not(.hidden))) { display: none; } /* sin botones visibles, no ocupa espacio */
.actions .btn { min-width: 150px; }

@keyframes deal { from { opacity: 0; transform: translateY(24px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-18px) rotate(-6deg) scale(1.05); } to { opacity: 1; transform: none; } }
.drop { animation: drop var(--t-slow) var(--ease-out) both; }

/* ============ Cartas ============ */
.card {
  position: relative; display: block;
  width: var(--card-w); height: var(--card-h);
  background: var(--cream); color: var(--ink);
  border: none; padding: 0;
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
  font-family: 'Fraunces', serif;
  user-select: none; -webkit-user-select: none;
  flex: none;
}
.card.red { color: var(--suit-red); }
.card .corner { position: absolute; font-weight: 800; line-height: .95; font-size: calc(var(--card-w) * .21); text-align: center; }
.card .corner.tl { top: 6px; left: 7px; }
.card .corner.br { bottom: 6px; right: 7px; transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--card-w) * .5); }
.card .pip.face { font-size: calc(var(--card-w) * .4); font-weight: 800; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.09) 0 6px, transparent 6px 12px),
    linear-gradient(135deg, #8e2a22, #5a1813);
  border: 3px solid var(--cream);
}
.card.sm { --card-w: 44px; --card-h: 62px; border-radius: 6px; box-shadow: 0 3px 8px rgba(0,0,0,.3); }
.card.sm .corner { font-size: 13px; top: 3px; left: 4px; }
.card.sm .corner.br { display: none; }
.card.sm .pip { font-size: 20px; padding-top: 10px; }
.card.sm .pip.face { font-size: 15px; }

/* ============ Historial ============ */
/* ============ Panel lateral: chat + historial ============ */
.side { grid-area: side; display: none; flex-direction: column; min-height: 0; }
.side.open {
  display: flex;
  position: fixed; left: 0; right: 0; bottom: 0; height: 38vh; height: 38dvh; min-height: 230px; z-index: var(--z-modal);
  background: #0b2a20; border-top: 1px solid var(--border-gold); border-radius: 18px 18px 0 0;
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 50px rgba(0,0,0,.5);
  animation: sheet var(--t-med) var(--ease-out);
}
@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
/* Con el chat abierto en celular, deja espacio abajo para que tus cartas queden arriba del chat */
body.side-open #game { padding-bottom: calc(max(38dvh, 230px) + 12px); }
body.side-open .me { position: sticky; bottom: calc(max(38dvh, 230px) + 6px); z-index: 5; background: #0c2e22; }
.side.open .tabs { margin-bottom: var(--space-2); }
.side.open .tab { min-height: 40px; }
.side.open .pane { gap: var(--space-2); }
.tabs { display: flex; align-items: center; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 var(--space-3); background: none; border: none;
  border-bottom: 3px solid transparent; margin-bottom: -1px; color: var(--muted); font-weight: 700;
}
.tab[aria-selected="true"] { color: var(--gold-2); border-bottom-color: var(--gold); }
.side-close { margin-left: auto; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: .9375rem; overflow-y: auto; }
.log-list li { padding-left: 10px; border-left: 2px solid transparent; color: var(--muted); }
.log-list li:first-child { border-left-color: var(--gold); color: var(--text); }

.badge-wrap { position: relative; }
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: .6875rem; font-weight: 800; line-height: 1;
}
.badge-wrap .badge { position: absolute; top: 4px; right: 2px; }

.chat-list {
  list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain;
}
.chat-list:empty::before { content: 'Nadie ha escrito todavía. ¡Saluda!'; color: var(--muted); font-size: .9375rem; margin: auto; text-align: center; }
.msg {
  align-self: flex-start; max-width: 85%;
  background: var(--surface-2); border-radius: 4px 14px 14px 14px; padding: 6px 12px;
  overflow-wrap: anywhere; animation: rise var(--t-med) var(--ease-out);
}
.msg .who { display: block; font-size: .8125rem; font-weight: 700; color: var(--gold-2); }
.msg time { font-size: .75rem; color: var(--muted); margin-left: 6px; }
.msg.mine { align-self: flex-end; background: rgba(217,164,65,.2); border-radius: 14px 4px 14px 14px; }
.msg.mine .who { display: none; }
.chat-form { display: flex; gap: var(--space-2); }
.chat-form input {
  flex: 1; min-width: 0; min-height: var(--tap);
  background: rgba(0,0,0,.28); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; font-size: 1rem;
}
.chat-form input:focus { border-color: var(--gold); }
.chat-send { padding: 0; width: var(--tap); flex: none; }
.chat-box { display: flex; flex-direction: column; gap: var(--space-2); }
.chat-box .chat-list { height: 160px; flex: none; background: rgba(0,0,0,.18); border-radius: var(--radius); padding: var(--space-2); }

@media (min-width: 1024px) {
  #game {
    grid-template-columns: 1fr 300px;
    grid-template-areas: "top top" "table side" "status side" "me side";
  }
  .side, .side.open {
    display: flex; position: static; height: auto; max-height: 640px; animation: none;
    background: rgba(0,0,0,.2); border: 1px solid rgba(255,255,255,.06); border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-4) var(--space-4); box-shadow: none; align-self: stretch;
  }
  #chatBtn, #logBtn, .side-close { display: none; }
}

/* PC y laptop: todo más grande para aprovechar la pantalla (3 niveles según ancho y alto) */
@media (min-width: 1200px) and (min-height: 720px) {
  :root { --card-w: 92px; --card-h: 131px; }
  #game { max-width: 1560px; --zoom: 1.2; --reserve: 600px; grid-template-columns: 1fr 340px; }
  .table-wrap { padding: 64px 80px 72px; }
  .table-center { --card-w: 70px; --card-h: 100px; gap: var(--space-6); }
  .table-center .pile-label { font-size: .875rem; }
  .seat { width: 140px; }
  .seat .avatar { width: 62px; height: 62px; font-size: 1.5rem; }
  .seat .avatar.bot .ic { width: 30px; height: 30px; }
  .seat .plate { min-width: 110px; max-width: 140px; }
  .seat .sname { font-size: 1rem; }
  .seat .plate .lives .ic { width: 15px; height: 15px; }
  .dealer-chip { width: 28px; height: 28px; font-size: .875rem; }
  .seat-cards .card { --card-w: 34px; --card-h: 49px; margin-left: -15px; }
  .seat-cards.beside { --beside-off: 48px; }
  .fly-card { --card-w: 52px; --card-h: 75px; }
  .status { font-size: 1.25rem; }
  .me { max-width: min(100%, 640px); padding: var(--space-4) var(--space-6) var(--space-5); }
  .me-name { font-size: 1.125rem; }
  .score-chip .big { font-size: 1.5rem; }
  .hand { gap: 14px; }
  .me .actions .btn { min-height: 52px; font-size: 1.0625rem; padding-inline: 28px; }
  .topbar-info b { font-size: 1.5rem; }
}
@media (min-width: 1400px) and (min-height: 880px) {
  :root { --card-w: 108px; --card-h: 154px; }
  #game { --zoom: 1.45; --reserve: 650px; }
  .table-wrap { padding: 72px 84px 80px; }
  .table-center { --card-w: 82px; --card-h: 117px; }
}
@media (min-width: 1700px) and (min-height: 1000px) {
  :root { --card-w: 120px; --card-h: 171px; }
  #game { max-width: 1840px; --zoom: 1.7; --reserve: 690px; grid-template-columns: 1fr 380px; }
  .table-center { --card-w: 94px; --card-h: 134px; }
  .seat .avatar { width: 70px; height: 70px; font-size: 1.625rem; }
  .seat-cards .card { --card-w: 40px; --card-h: 57px; margin-left: -18px; }
  .seat-cards.beside { --beside-off: 52px; }
  .fly-card { --card-w: 60px; --card-h: 86px; }
}
@media (min-width: 2200px) and (min-height: 1300px) {
  :root { --card-w: 140px; --card-h: 200px; }
  #game { max-width: 2300px; --zoom: 2.1; --reserve: 780px; grid-template-columns: 1fr 440px; }
  .table-center { --card-w: 112px; --card-h: 160px; }
  .seat { width: 160px; }
  .seat .avatar { width: 84px; height: 84px; font-size: 2rem; }
  .seat-cards .card { --card-w: 48px; --card-h: 69px; margin-left: -22px; }
  .seat-cards.beside { --beside-off: 60px; }
  .fly-card { --card-w: 72px; --card-h: 103px; }
  .side, .side.open { max-height: 820px; }
}

/* ============ Desempate ============ */
.tie-players { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-4); }
.tie-row {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; min-height: 60px;
  border-left: 4px solid transparent;
}
.tie-row.win { border-left-color: var(--gold); background: rgba(217,164,65,.16); }
.tie-row.lose { border-left-color: var(--danger); background: rgba(239,107,95,.12); }
.tie-row .tname { flex: 1; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.tie-row .tpick { font-family: 'Fraunces', serif; font-size: 1.25rem; font-weight: 800; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.tie-row .tpick.waiting { font-family: inherit; font-size: .875rem; font-weight: 500; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.tie-row .card.sm { animation: drop var(--t-slow) var(--ease-out) both; }
.tie-pick { margin-top: var(--space-4); }
.num-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; max-height: 312px; overflow-y: auto; padding: 2px; }
.num-grid button {
  min-height: var(--tap); border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 700; font-variant-numeric: tabular-nums;
  transition: background var(--t-fast), transform var(--t-fast);
}
.num-grid button:hover:not(:disabled) { background: var(--gold); color: var(--on-gold); }
.num-grid button:active:not(:disabled) { transform: scale(.94); }
.num-grid button:disabled { opacity: .35; cursor: not-allowed; text-decoration: line-through; }
.tie-hands { margin-top: var(--space-4); }
.tie-hands summary { cursor: pointer; color: var(--muted); font-weight: 700; min-height: var(--tap); display: flex; align-items: center; }
.tiebreak-summary { margin-top: var(--space-3); display: flex; flex-direction: column; gap: 6px; }
.tiebreak-summary .tb-line { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: .9375rem; }
.tiebreak-summary .card.sm { --card-w: 34px; --card-h: 48px; }
.tiebreak-summary .card.sm .pip { font-size: 15px; padding-top: 8px; }
.tiebreak-summary .card.sm .corner { font-size: 11px; }

/* ============ Modales ============ */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(2, 12, 8, .72); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: var(--space-4);
  animation: fade var(--t-med) var(--ease-out);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  position: relative;
  background: #0d2f24; border: 1px solid var(--border-gold); border-radius: var(--radius-lg);
  width: 100%; max-width: 580px; max-height: 90vh; max-height: 90dvh; overflow-y: auto; padding: var(--space-5);
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
  animation: pop var(--t-slow) var(--ease-out);
}
.modal-box.small-box { max-width: 400px; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-box h2 { font-family: 'Fraunces', serif; font-size: 1.625rem; margin: 0 0 6px; color: var(--gold-2); }
.modal-box p { margin: 0; }
.modal-close { position: absolute; top: 10px; right: 10px; }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-3); margin-top: var(--space-5); flex-wrap: wrap; }
.modal-actions .muted { margin-right: auto; }
.result-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: rgba(217,164,65,.18); color: var(--gold-2); margin-bottom: var(--space-3); }
.result-icon .ic { width: 28px; height: 28px; }
.result-icon.bad { background: rgba(239,107,95,.18); color: var(--danger); }
.result-table { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-4); }
.rrow {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: var(--space-3);
  background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px;
  border-left: 4px solid transparent;
  animation: rise var(--t-med) var(--ease-out) both;
}
.rrow.lost { background: rgba(239,107,95,.12); border-left-color: var(--danger); }
.rrow.win { background: rgba(217,164,65,.16); border-left-color: var(--gold); }
.rrow .rname { font-weight: 700; min-width: 0; }
.rrow .rname > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrow .rtags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.rrow .rcards { display: flex; gap: 4px; }
.rrow .rscore { font-family: 'Fraunces', serif; font-size: 1.5rem; font-weight: 800; min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.countdown-bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: var(--space-4); }
.countdown-bar span { display: block; height: 100%; background: var(--gold); transform-origin: left; }
/* ============ Mini video "Cómo se juega" ============ */
.tut-box { max-width: 600px; padding: var(--space-4); }
.tut-stage {
  --card-w: 64px; --card-h: 92px;
  position: relative; height: 290px; overflow: hidden;
  border-radius: var(--radius-lg); border: 6px solid #6b4425;
  background: radial-gradient(ellipse at 50% 40%, #1c7a54 0%, #136043 50%, #0b3f2c 100%);
  box-shadow: inset 0 0 40px rgba(0,0,0,.45), 0 10px 30px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 14px;
}
.tut-row { display: flex; gap: 10px; justify-content: center; align-items: flex-end; }
.tut-hand { min-height: var(--card-h); }
.tut-hand .card, .tut-pile .card { transition: transform var(--t-med) var(--ease-out), opacity var(--t-med), filter var(--t-med), box-shadow var(--t-med); }
.tut-hand .card.lit { box-shadow: 0 0 0 3px var(--gold-2), 0 8px 20px rgba(0,0,0,.4); transform: translateY(-6px); }
.tut-hand .card.dim { background: #aab8af; }
.tut-hand .card.dim .corner, .tut-hand .card.dim .pip { opacity: .4; }
.tut-hand .card.selected { transform: translateY(-16px); box-shadow: 0 0 0 3px var(--danger), 0 14px 26px rgba(0,0,0,.45); }
.tut-tag { position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); white-space: nowrap; font-size: .75rem; font-weight: 700; color: #ffe3de; background: var(--danger-bg); border-radius: 99px; padding: 1px 8px; }
.tut-chip.win { background: var(--gold-2); box-shadow: 0 0 0 4px rgba(241,200,106,.3), 0 0 26px rgba(241,200,106,.6); }
.tut-values { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; transition: opacity var(--t-med); }
.tut-values span { font-size: .8125rem; font-weight: 700; color: #e6f3eb; background: rgba(0,0,0,.3); border-radius: 99px; padding: 2px 10px; }
.tut-piles { gap: 28px; }
.tut-pile { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tut-slot { position: relative; display: block; width: var(--card-w); height: var(--card-h); }
.tut-slot .card.glow { box-shadow: 0 0 0 3px var(--gold-2), 0 0 22px rgba(241,200,106,.6); }
.tut-slot .card.tut-over { position: absolute; inset: 0; }
.tut-pile .pile-label { font-size: .75rem; color: #cfe5d8; background: rgba(0,0,0,.35); padding: 1px 8px; border-radius: 99px; }
.tut-opps { gap: 40px; align-items: flex-start; }
.tut-opp { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 86px; }
.tut-opp .avatar { width: 44px; height: 44px; font-size: 1.125rem; }
.tut-name { font-weight: 700; font-size: .875rem; }
.tut-knock { pointer-events: none; }
.tut-knock.pressed { background: var(--gold); color: var(--on-gold); border-color: #b3832c; }
.tut-list { display: flex; flex-direction: column; gap: 6px; width: min(100%, 420px); }
.tut-prow {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  background: rgba(0,0,0,.28); border-radius: var(--radius); padding: 6px 10px; border-left: 4px solid transparent;
  transition: background var(--t-med), border-color var(--t-med);
}
.tut-prow .tut-name { display: flex; align-items: center; gap: 6px; }
.tut-prow .lives { grid-column: 1; grid-row: 2; }
.tut-prow .tut-mini { grid-column: 2; grid-row: 1 / span 2; }
.tut-prow .tut-chip { grid-column: 3; grid-row: 1 / span 2; }
.tut-prow .tag { justify-self: start; }
.tut-prow.lose { background: rgba(110,38,32,.55); border-left-color: var(--danger); }
.tut-mini { display: flex; gap: 3px; --card-w: 30px; --card-h: 43px; }
.tut-mini .card { border-radius: 4px; border-width: 2px; }
.tut-mini .card .corner.br { display: none; }
.tut-mini .card .corner { font-size: 10px; top: 2px; left: 3px; }
.tut-mini .card .pip { font-size: 15px; padding-top: 6px; }
.tut-mini .card .pip.face { font-size: 11px; }
.tut-specials { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.tut-special { display: flex; flex-direction: column; align-items: center; gap: 8px; background: rgba(0,0,0,.28); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.tut-special .tut-mini { --card-w: 36px; --card-h: 52px; }
.tut-special .tut-mini .card .pip { font-size: 18px; }
.tut-special .tut-mini .card .pip.face { font-size: 13px; }
.tut-special-label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .8125rem; line-height: 1.3; }
.tut-special-label .ic { width: 22px; height: 22px; }
.tut-caption { margin-top: var(--space-3); min-height: 4.4em; }
.tut-title { font-family: 'Fraunces', serif; font-size: 1.375rem; font-weight: 800; color: var(--gold-2); line-height: 1.2; }
.tut-text { margin: 4px 0 0 !important; color: var(--text); font-size: 1rem; }
.tut-progress { display: flex; gap: 4px; margin-top: var(--space-3); }
.tut-seg { flex: 1; height: 16px; padding: 6px 0; background: none; border: 0; cursor: pointer; display: block; }
.tut-seg span { display: block; height: 4px; border-radius: 99px; background: linear-gradient(var(--gold-2), var(--gold-2)) left / 0% 100% no-repeat, rgba(255,255,255,.18); }
.tut-seg.done span { background: var(--gold-2); }
.tut-controls { display: flex; align-items: center; gap: 4px; margin-top: var(--space-2); flex-wrap: wrap; }
.tut-controls .btn { white-space: nowrap; }
.tut-controls .icon-btn:disabled { opacity: .35; cursor: default; }
.tut-play { color: var(--gold-2); }
.tut-spacer { flex: 1; }
@media (max-width: 600px) {
  .tut-box { padding: var(--space-3); }
  .tut-stage { --card-w: 52px; --card-h: 75px; height: 250px; padding: 10px; }
  .tut-specials { gap: 6px; }
  .tut-special { padding: 8px 4px; }
  .tut-special .tut-mini { --card-w: 26px; --card-h: 38px; }
  .tut-special .tut-mini .card .pip { font-size: 13px; }
  .tut-special-label { font-size: .75rem; }
  .tut-opps { gap: 24px; }
  .tut-title { font-size: 1.1875rem; }
  .tut-text { font-size: .9375rem; }
  .tut-controls .tut-spacer { flex-basis: 100%; height: 0; }
  .tut-controls .btn { flex: 1; }
}

.rules h3 { margin-top: var(--space-4); }
.rule-steps { padding-left: 22px; margin: var(--space-3) 0; display: flex; flex-direction: column; gap: var(--space-2); }
.special-list { list-style: none; padding: 0; margin: 0 0 var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.special-list li { display: flex; gap: var(--space-3); align-items: flex-start; background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.special-list .ic { margin-top: 2px; }

/* ============ Avisos ============ */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--space-2);
  background: #2b0f0c; border: 1px solid var(--danger); color: #ffe3de;
  padding: 12px 18px; border-radius: var(--radius); z-index: var(--z-toast);
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: rise var(--t-med) var(--ease-out);
}
.toast.ok { background: #0f3324; border-color: var(--success); color: #dcf7e8; }
.toast .ic { width: 18px; height: 18px; }
/* Páginas legales */
#home { align-content: center; }
.legal-links { margin: var(--space-4) 0 0; font-size: .8125rem; color: var(--muted); text-align: center; max-width: 420px; }
.legal-links a, .rules a, .legal a { color: var(--gold-2); text-underline-offset: 3px; }
.legal {
  max-width: 720px; margin: 0 auto; padding: var(--space-6) var(--space-4) 64px;
  line-height: 1.65; font-size: 1rem;
}
.legal h1 { font-family: 'Fraunces', serif; color: var(--gold-2); font-size: clamp(1.75rem, 5vw, 2.25rem); line-height: 1.15; margin: var(--space-4) 0 var(--space-1); }
.legal h2 { font-size: 1.125rem; margin: var(--space-6) 0 var(--space-2); }
.legal p, .legal li { color: var(--text); max-width: 68ch; }
.legal ul { padding-left: 1.25rem; display: flex; flex-direction: column; gap: 6px; }
.legal-date { color: var(--muted); font-size: .875rem; margin: 0; }
.legal-lead { margin-top: var(--space-5); padding: var(--space-4); border-radius: var(--radius); border: 1px solid var(--border-gold); background: rgba(217,164,65,.08); }
.legal-back { display: inline-flex; align-items: center; min-height: var(--tap); font-weight: 700; text-decoration: none; }
.legal-foot { margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--border); color: var(--muted); }
mark.todo { background: #f1c86a; color: #2a1d05; padding: 0 4px; border-radius: 4px; font-weight: 700; }

/* Aviso de jugador desconectado (cuenta regresiva) */
.dc-banner {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 35; max-width: min(94vw, 560px);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; border-radius: 14px;
  background: var(--danger-bg); color: #ffe3de; border: 1px solid #a5463c;
  box-shadow: 0 12px 32px rgba(0,0,0,.45); font-weight: 600; line-height: 1.35;
  animation: rise var(--t-med) var(--ease-out);
}
.dc-banner.hidden { display: none; }
.dc-banner .spinner { flex: none; }
.dc-banner b { color: #fff; font-variant-numeric: tabular-nums; }

/* Aviso grande de "¡Tocó!" */
.knock-alert {
  position: fixed; inset: 0; z-index: 45; pointer-events: none;
  display: grid; place-items: center; padding: var(--space-4);
  background: radial-gradient(ellipse at center, rgba(110,38,32,.55), rgba(0,0,0,.35) 60%, transparent 85%);
  animation: knock-fade 2.6s var(--ease-out) both;
}
.knock-alert.hidden { display: none; }
.knock-burst {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center;
  padding: var(--space-5) var(--space-6); border-radius: 28px;
  background: linear-gradient(180deg, #8f2f26, #5a1813); border: 3px solid var(--gold-2);
  box-shadow: 0 0 0 8px rgba(241,200,106,.18), 0 30px 80px rgba(0,0,0,.6), 0 0 120px rgba(239,107,95,.45);
  animation: knock-pop 2.6s var(--ease-out) both;
  max-width: min(92vw, 620px);
}
.knock-icon {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  background: var(--cream); color: #7a2a1d; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: knock-knock .5s ease-in-out 2;
}
.knock-icon .ic { width: 48px; height: 48px; stroke-width: 2.2; }
.knock-name {
  font-family: 'Fraunces', serif; font-weight: 800; color: #fff; line-height: 1.05;
  font-size: clamp(2.25rem, 8vw, 4.5rem); text-shadow: 0 4px 18px rgba(0,0,0,.45);
  overflow-wrap: anywhere;
}
.knock-sub { color: var(--gold-2); font-weight: 800; font-size: clamp(1.125rem, 3.2vw, 1.625rem); letter-spacing: .04em; text-transform: uppercase; }
@keyframes knock-fade { 0% { opacity: 0; } 8% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes knock-pop {
  0% { transform: scale(.4); } 10% { transform: scale(1.08); } 16% { transform: scale(.97); } 22% { transform: scale(1); }
  75% { transform: scale(1); } 100% { transform: scale(1.06); }
}
@keyframes knock-knock { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-18deg) translateY(-4px); } 60% { transform: rotate(6deg); } }

/* Pantalla de carga / sin conexión */
.conn-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: var(--space-4);
  background: rgba(3, 16, 11, .78);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  /* Aparece con un pequeño retraso para no parpadear si la conexión es rápida */
  animation: conn-in var(--t-slow) var(--ease-out) 350ms both;
}
.conn-overlay.hidden { display: none; }
@keyframes conn-in { from { opacity: 0; } to { opacity: 1; } }
.conn-box { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); text-align: center; max-width: 320px; }
.loader {
  width: 56px; height: 56px; border-radius: 50%; position: relative;
  border: 4px solid rgba(241, 200, 106, .18); border-top-color: var(--gold-2);
  animation: spin .9s linear infinite; margin-bottom: var(--space-2);
}
.loader span {
  position: absolute; inset: 8px; border-radius: 50%;
  border: 3px solid transparent; border-bottom-color: var(--gold);
  animation: spin 1.4s linear infinite reverse;
}
.conn-title { font-family: 'Fraunces', serif; font-size: 1.375rem; color: var(--gold-2); margin: 0; }
.conn-sub { color: var(--muted); margin: 0; font-size: .9375rem; line-height: 1.45; }
#connRetry { margin-top: var(--space-2); }
@media (prefers-reduced-motion: reduce) {
  /* El loader debe seguir girando (indica que algo pasa), solo más lento */
  .loader { animation-duration: 2.4s !important; animation-iteration-count: infinite !important; }
  .loader span { animation: none !important; }
  .conn-overlay { animation: none !important; }
  /* El aviso de "Tocó" se muestra fijo (sin saltos) y lo quita el temporizador */
  .knock-alert, .knock-burst, .knock-icon { animation: none !important; }
}

/* ============ Celular ============ */
@media (max-width: 600px) {
  :root { --card-w: min(74px, calc((100vw - 82px) / 4)); --card-h: calc(var(--card-w) * 1.43); }
  .hand { gap: 6px; flex-wrap: nowrap; }
  .panel { padding: var(--space-5) var(--space-4); }
  #game { padding: 0 12px calc(12px + env(safe-area-inset-bottom)); gap: var(--space-2); }
  /* En celular la mesa es un óvalo vertical */
  .table-wrap { padding: 44px 34px 48px; }
  .poker-table { aspect-ratio: 3 / 4; padding: 10px; width: min(100%, 330px); }
  .table-center { gap: var(--space-2); --card-w: 46px; --card-h: 66px; }
  .table-center .pile-label { font-size: .6875rem; padding: 1px 6px; max-width: 84px; }
  .seat { width: 84px; }
  .seat .avatar { width: 40px; height: 40px; font-size: 1rem; border-width: 2px; }
  .seat .plate { min-width: 0; max-width: 84px; padding: 2px 6px 3px; }
  .seat .sname { font-size: .75rem; }
  .seat-cards .card { --card-w: 20px; --card-h: 29px; margin-left: -10px; }
  .dealer-chip { width: 20px; height: 20px; font-size: .625rem; right: -8px; }
  .room-code { font-size: 2.25rem; }
  .actions .btn { flex: 1; min-width: 0; }
  .rrow { grid-template-columns: 1fr auto; }
  .rrow .rcards { grid-column: 1 / -1; grid-row: 2; }
  .rrow .rscore { grid-column: 2; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .seat.turn::before { display: none; }
}
