:root {
  --felt: #1f5c3c;
  --felt-dark: #123b26;
  --felt-light: #2b774d;
  --wood: #6b4426;
  --wood-dark: #3d2413;
  --wood-light: #8a5a33;
  --cream: #f7efdc;
  --gold: #e8b33a;
  --gold-dark: #b9851b;
  --red: #b8322a;
  --ink: #2b2118;
  --muted: #8d7f6a;
  --panel: #fffaf0;
  --panel-line: #e4d7bb;
  --bg: #f1e7d2;
  --shadow: 0 8px 24px rgba(0, 0, 0, .28);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --serif: Georgia, "Times New Roman", serif;

  /* los tamaños dependen del ancho y también del alto, para que la mesa entre en pantallas bajas */
  --hand-w: clamp(62px, min(8.4vw, 11vh), 118px);    /* mis cartas */
  --trick-w: clamp(42px, min(5.6vw, 6.8vh), 82px);   /* cartas en la mesa */
  --opp-w: clamp(34px, min(4.4vw, 5.4vh), 64px);     /* dorso del rival */
  --act-h: clamp(36px, 5.6vh, 46px);                 /* alto de los botones */
}
@media (prefers-color-scheme: dark) {
  :root {
    --panel: #2a221b;
    --panel-line: #463a2d;
    --ink: #f1e6cd;
    --muted: #b3a58c;
    --bg: #17110c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
body.in-game { color: #fff; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Botones ---------- */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 650;
  background: var(--cream);
  color: #2b2118;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .28);
  transition: transform .08s, filter .15s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .28); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: var(--gold); color: #2b1a05; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px currentColor; }
.btn.small { padding: 6px 12px; font-size: 14px; }

/* ---------- Paños y dorsos ---------- */
body[data-felt="verde"]    { --felt: #1f5c3c; --felt-dark: #123b26; --felt-light: #2b774d; }
body[data-felt="azul"]     { --felt: #1d3e66; --felt-dark: #0f2340; --felt-light: #2a5689; }
body[data-felt="bordo"]    { --felt: #5f1d2a; --felt-dark: #3a0f18; --felt-light: #7d2a3a; }
body[data-felt="petroleo"] { --felt: #145a5e; --felt-dark: #0b3739; --felt-light: #1e7479; }
body[data-felt="grafito"]  { --felt: #2b2f33; --felt-dark: #17191c; --felt-light: #3c4146; }
body[data-felt="marron"]   { --felt: #5b3a22; --felt-dark: #382313; --felt-light: #74502f; }
body[data-back="rojo"]  { --back-a: #8e2a22; --back-b: #a8362c; }
body[data-back="azul"]  { --back-a: #1f427a; --back-b: #2d5aa0; }
body[data-back="verde"] { --back-a: #215c35; --back-b: #2f7a46; }
body[data-back="negro"] { --back-a: #1e1c1a; --back-b: #3a3632; }

/* ---------- Menús ---------- */
body { background: radial-gradient(ellipse 90% 70% at 50% 0%, #563620 0%, #2a180c 55%, #150b05 100%) fixed; color: #f3e9d2; }
.menu-screen {
  --panel: rgba(25, 15, 8, .72);
  --panel-line: rgba(255, 235, 200, .12);
  --ink: #f3e9d2;
  --muted: #bba98a;
  color: var(--ink);
  max-width: 1120px; margin: 0 auto;
  padding: 16px 16px 40px;
  min-height: 100vh; min-height: 100dvh;
}
.btn.big { font-size: 19px; padding: 15px 22px; border-radius: 14px; letter-spacing: 2px; text-transform: uppercase; font-weight: 800; }
.btn.danger { background: #8e2a22; color: #fff; }

/* Inicio */
#home { display: grid; place-items: center; }
.home {
  width: min(460px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 26px;
  padding: 34px 22px 26px;
  border-radius: 36px;
  border: 12px solid var(--wood);
  box-shadow: inset 0 0 50px rgba(0, 0, 0, .45), 0 0 0 2px var(--wood-dark), 0 0 0 5px var(--wood-light), 0 24px 60px rgba(0, 0, 0, .6);
  background: radial-gradient(ellipse at 50% 35%, var(--felt-light), var(--felt) 60%, var(--felt-dark));
}
.home-logo { text-align: center; }
.home-logo h1 {
  font-family: var(--serif);
  font-size: clamp(64px, 16vw, 92px);
  margin: 10px 0 0; line-height: 1;
  color: var(--gold);
  letter-spacing: 3px;
  text-shadow: 0 3px 0 #7a5410, 0 8px 20px rgba(0, 0, 0, .5);
}
.home-logo .tag { margin: 6px 0 0; letter-spacing: 8px; text-transform: uppercase; font-size: 14px; opacity: .8; }
.brand-cards { display: flex; justify-content: center; height: 62px; }
.brand-cards span {
  width: 42px; height: 60px; border-radius: 6px;
  background: repeating-linear-gradient(45deg, var(--back-a) 0 4px, var(--back-b) 4px 8px);
  border: 3px solid #fffaf0;
  box-shadow: var(--shadow);
  margin: 0 -7px;
}
.brand-cards span:nth-child(1) { transform: rotate(-15deg) translateY(5px); }
.brand-cards span:nth-child(3) { transform: rotate(15deg) translateY(5px); }
.home-menu { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; }
.home-menu .btn.ghost { color: #f3e9d2; }
.home-foot { margin: 0; font-size: 13px; opacity: .7; text-align: center; }

/* Encabezado de los menús */
.menu-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin: 4px 0 18px; }
.menu-head h2 { font-family: var(--serif); font-size: 28px; margin: 0; color: var(--gold); }
.menu-head .btn { justify-self: start; color: var(--ink); }
.head-meta { justify-self: end; font-weight: 700; color: var(--gold); }

/* Modos */
.modes { display: grid; gap: 14px; max-width: 640px; margin: 0 auto; }
.mode {
  display: flex; gap: 16px; align-items: center; text-align: left;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--panel-line);
  border-radius: 18px; padding: 18px 20px;
  transition: transform .12s, border-color .12s, background .12s;
}
.mode:not(.disabled):hover { transform: translateY(-2px); border-color: var(--gold); background: rgba(40, 24, 12, .85); }
.mode.disabled { opacity: .5; cursor: not-allowed; }
.mode-icon { font-size: 34px; width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; background: rgba(255, 255, 255, .07); flex: none; }
.mode-text { display: flex; flex-direction: column; gap: 4px; }
.mode-title { font-size: 20px; font-weight: 800; letter-spacing: .5px; }
.mode-desc { font-size: 14.5px; color: var(--muted); line-height: 1.4; }
.mode-meta { font-size: 13px; color: var(--gold); font-weight: 700; }
.soon { font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; background: var(--gold); color: #2b1a05; border-radius: 6px; padding: 2px 7px; margin-left: 8px; vertical-align: middle; }

/* Carrera */
.career-bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .1); max-width: 720px; margin: 0 auto 18px; overflow: hidden; }
#career-fill { height: 100%; background: linear-gradient(90deg, var(--gold-dark), var(--gold)); border-radius: 99px; transition: width .4s; }
.ladder { list-style: none; margin: 0 auto; padding: 0; max-width: 720px; display: flex; flex-direction: column; gap: 8px; }
.tier-head { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); opacity: .8; margin: 12px 4px 2px; }
.rung {
  display: grid; grid-template-columns: 30px 48px 1fr auto; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-left: 4px solid var(--accent);
  border-radius: 14px; padding: 10px 14px;
}
.rung.next { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232, 179, 58, .35); }
.rung.locked { opacity: .5; border-left-color: rgba(255, 255, 255, .2); }
.rung-num { font-family: var(--serif); font-size: 20px; font-weight: 700; color: var(--muted); text-align: center; }
.rung-avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; background: rgba(255, 255, 255, .07); font-weight: 800; color: var(--muted); }
.rung-info { display: flex; flex-direction: column; min-width: 0; }
.rung-name { font-weight: 750; }
.rung-desc { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rung-right { display: flex; gap: 8px; align-items: center; }
.rung-state { font-size: 13px; color: var(--muted); }
.rung.done .rung-state { color: #7fd48b; font-weight: 700; }
.rung .btn.ghost { color: var(--ink); }

/* Partida libre */
.tier-filter { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; }
.tier-filter button {
  border: 1px solid var(--panel-line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font-weight: 650; font-size: 14px;
}
.tier-filter button[aria-selected="true"] { background: var(--gold); color: #2b1a05; border-color: var(--gold); }
.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.persona {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  text-align: left; color: inherit;
  position: relative; overflow: hidden;
  transition: transform .12s, border-color .12s;
}
.persona::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--accent); }
.persona:hover { transform: translateY(-3px); border-color: var(--accent); }
.persona-head { display: flex; gap: 12px; align-items: center; }
.persona-avatar {
  width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px;
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  border: 2px solid var(--accent); flex: none;
}
.persona-name { font-weight: 750; font-size: 17px; }
.persona-level { font-size: 13px; color: var(--muted); }
.pips { display: flex; gap: 2px; margin-top: 5px; }
.pips i { width: 8px; height: 5px; border-radius: 2px; background: rgba(255, 255, 255, .12); }
.pips i.on { background: var(--accent); }
.persona-desc { margin: 0; font-size: 14px; line-height: 1.45; flex: 1; color: #e6dac2; }
.persona-foot { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.persona-foot .play { background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 9px; font-weight: 700; font-size: 14px; }
.badge { font-size: 12px; background: var(--gold); color: #2b1a05; border-radius: 6px; padding: 1px 6px; font-weight: 700; margin-left: 6px; }

/* Opciones */
.options { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.opt-preview { display: grid; place-items: center; }
.mini-table {
  width: 100%; height: 150px; border-radius: 24px;
  border: 10px solid var(--wood);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .45), 0 0 0 2px var(--wood-dark), var(--shadow);
  background: radial-gradient(ellipse at center, var(--felt-light), var(--felt) 65%, var(--felt-dark));
  display: flex; justify-content: center; align-items: center; gap: 10px;
}
.mini-card { width: 62px; aspect-ratio: 2 / 3; border-radius: 7px; box-shadow: 0 4px 10px rgba(0, 0, 0, .4); }
.mini-card:nth-child(1) { transform: rotate(-8deg); }
.mini-card:nth-child(3) { transform: rotate(8deg) translateY(-6px); }
.opt-group { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px; padding: 6px 18px; }
.opt-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); margin: 12px 0 4px; }
.opt-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--panel-line); }
.opt-group h3 + .opt-row { border-top: 0; }
.opt-row.col { flex-direction: column; align-items: stretch; }
.opt-label { font-weight: 600; }
.seg { display: flex; gap: 4px; background: rgba(0, 0, 0, .3); padding: 4px; border-radius: 11px; }
.seg button { border: 0; background: transparent; color: var(--ink); border-radius: 8px; padding: 7px 13px; font-weight: 700; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--gold); color: #2b1a05; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 2px; font-size: 11px; }
.swatch span { width: 38px; height: 38px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 70%, #fff), var(--c)); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .3); }
.swatch[aria-pressed="true"] span { box-shadow: 0 0 0 3px var(--gold); }
.swatch[aria-pressed="true"] em { color: var(--gold); }
.swatch em { font-style: normal; }
.skins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.skin { border: 1px solid var(--panel-line); background: rgba(0, 0, 0, .25); color: var(--ink); border-radius: 14px; padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.skin-card { width: 54px; aspect-ratio: 2 / 3; display: block; box-shadow: 0 3px 8px rgba(0, 0, 0, .4); border-radius: 6px; }
.skin em { font-style: normal; font-size: 13px; font-weight: 650; }
.skin[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232, 179, 58, .4); }

/* Reglas */
#rules .rules-body { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px; padding: 8px 22px; }
#rules .rules-body p { line-height: 1.6; font-size: 15.5px; }
#rules .rules-body b { color: var(--gold); }

@media (max-width: 600px) {
  .menu-head h2 { font-size: 23px; }
  .mode { padding: 14px; gap: 12px; }
  .mode-icon { width: 46px; height: 46px; font-size: 26px; }
  .rung { grid-template-columns: 22px 40px 1fr auto; gap: 8px; padding: 8px 10px; }
  .rung-avatar { width: 40px; height: 40px; font-size: 22px; }
  .skins { grid-template-columns: repeat(2, 1fr); }
  .opt-row { padding: 10px 0; }
}

/* ---------- Mesa ---------- */
#game { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  height: 58px;
}
.top-title { font-family: var(--serif); font-size: 24px; font-weight: 700; color: var(--gold); letter-spacing: 1px; text-shadow: 0 2px 6px rgba(0, 0, 0, .5); }
.top-score { justify-self: end; display: flex; gap: 8px; align-items: center; font-weight: 600; background: rgba(0, 0, 0, .35); padding: 6px 14px; border-radius: 999px; font-size: 14.5px; }
.top-score b { color: var(--gold); font-size: 18px; }
.top-score .sep { opacity: .4; }
#btn-back { justify-self: start; color: #f3e6c8; }

.layout {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: minmax(0, 1fr);
  gap: 20px;
  padding: 4px 20px 20px;
  max-width: 1320px; width: 100%;
  margin: 0 auto;
  min-height: calc(100dvh - 58px);
}
.table {
  position: relative;
  border-radius: 34px;
  border: 14px solid var(--wood);
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(255, 255, 255, .07), transparent 70%),
    radial-gradient(ellipse at center, var(--felt-light), var(--felt) 60%, var(--felt-dark));
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, .5),
    0 0 0 2px var(--wood-dark),
    0 0 0 5px var(--wood-light),
    0 0 0 7px var(--wood-dark),
    0 20px 50px rgba(0, 0, 0, .55);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(8px, 1.6vh, 14px) 18px;
  min-height: calc(100dvh - 58px - 24px);
}

/* Rival */
.opp-zone { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.opp-id { display: flex; gap: 10px; align-items: center; position: relative; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px;
  background: rgba(0, 0, 0, .25);
  border: 3px solid var(--accent, var(--gold));
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .25);
}
.opp-name { font-weight: 750; font-size: 16px; }
.opp-level { font-size: 12.5px; opacity: .75; }

.hand { display: flex; justify-content: center; }
.hand .card { transform: translateY(var(--lift, 0)) rotate(var(--rot, 0)); }
.opp-hand { --w: var(--opp-w); min-height: calc(var(--opp-w) * 1.5 + 8px); }
.opp-hand .card { margin: 0 -6px; transform-origin: 50% -30%; transform: translateY(calc(var(--lift, 0) * -1)) rotate(var(--rot, 0)); }

.card {
  width: var(--w, var(--hand-w));
  aspect-ratio: 2 / 3;
  padding: 0; border: 0; background: none;
  border-radius: 9px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .4);
  flex: none;
  display: block;
}
.card-svg { width: 100%; height: 100%; display: block; }

/* Mis cartas */
.my-hand { --w: var(--hand-w); min-height: calc(var(--hand-w) * 1.5 + 14px); padding-top: 10px; }
.my-hand .card { margin: 0 -4px; transform-origin: 50% 130%; transition: transform .16s ease, box-shadow .16s, filter .16s; }
.my-hand .card.playable { cursor: pointer; }
.my-hand .card.playable:hover, .my-hand .card.playable:focus-visible {
  transform: translateY(calc(var(--lift, 0) - 20px)) rotate(var(--rot, 0)) scale(1.03);
  box-shadow: 0 16px 26px rgba(0, 0, 0, .45), 0 0 0 3px var(--gold);
  outline: none;
  z-index: 2;
}
.my-hand.waiting .card { filter: brightness(.82) saturate(.85); cursor: default; }

/* Centro: las tres bazas */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(6px, 1.6vh, 14px); padding: 6px 0; }
.tricks { display: flex; gap: clamp(14px, 3vw, 40px); justify-content: center; --w: var(--trick-w); }
.trick { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.trick-label { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .55; }
.trick.current .trick-label { opacity: 1; color: var(--gold); }
.pair { position: relative; width: calc(var(--trick-w) + 10px); height: calc(var(--trick-w) * 1.5 * 1.62); }
.slot { position: absolute; width: var(--trick-w); aspect-ratio: 2 / 3; border-radius: 9px; }
.slot.theirs { top: 0; left: 0; }
.slot.mine { bottom: 0; left: 10px; }
.trick.current .slot:empty { border: 2px dashed rgba(255, 255, 255, .18); }
.slot .card { position: absolute; inset: 0; width: 100%; }
.slot.theirs .card { transform: rotate(-3deg); }
.slot.mine .card { transform: rotate(3deg); }
.slot .card.fresh { animation: drop .3s ease-out; }
.slot.win .card { box-shadow: 0 0 0 3px var(--gold), 0 8px 18px rgba(0, 0, 0, .5); z-index: 1; }
.slot.lose .card { filter: brightness(.6) saturate(.7); }
.slot.parda .card { box-shadow: 0 0 0 3px #9fb8dc; }
.trick-res { font-size: 12px; font-weight: 700; min-height: 20px; padding: 2px 10px; border-radius: 999px; }
.trick.r-me .trick-res { background: var(--gold); color: #2b1a05; }
.trick.r-opp .trick-res { background: rgba(0, 0, 0, .4); }
.trick.r-parda .trick-res { background: #9fb8dc; color: #142a4a; }
@keyframes drop { from { translate: 0 -24px; scale: 1.08; opacity: 0; } to { translate: 0 0; scale: 1; opacity: 1; } }

.status {
  min-height: 34px;
  font-weight: 650; text-align: center;
  padding: 6px 16px; border-radius: 999px;
  background: rgba(0, 0, 0, .28);
  max-width: 92%;
}
.status.mine { background: rgba(232, 179, 58, .18); box-shadow: inset 0 0 0 1.5px var(--gold); }
.status.empty { visibility: hidden; }

/* Yo */
.me-zone { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.4vh, 12px); position: relative; }
.actions {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  min-height: 52px; padding: 8px 10px; border-radius: 16px;
  background: rgba(0, 0, 0, .25);
  transition: opacity .2s;
}
.actions.idle { opacity: .0; pointer-events: none; }
.act-group { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.act-group:empty, .act-group:not(:has(.btn:not(.hidden))) { display: none; }
.btn.act {
  width: clamp(98px, 9.4vw, 132px); height: var(--act-h); padding: 0 8px;
  font-size: 14.5px; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn.env { background: #efe2bf; }
.btn.flor { background: #f0c9e0; color: #4a1030; }
.btn.truco { background: var(--red); color: #fff; }
.btn.yes { background: #4fa95e; color: #fff; }
.btn.no { background: #6b5b4a; color: #fff; }
.btn.mazo { background: transparent; color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .55); }

/* Globos */
.bubble {
  position: absolute;
  background: #fffaf0; color: #2b2118;
  border-radius: 14px;
  padding: 9px 14px;
  font-weight: 650; font-size: 15px;
  width: max-content; max-width: 300px;
  box-shadow: var(--shadow);
  opacity: 0; transform: scale(.9);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
  z-index: 6;
}
.bubble.show { opacity: 1; transform: none; }
.bubble.opp { left: calc(100% + 14px); top: 50%; translate: 0 -50%; transform-origin: left center; }
.bubble.opp::before { content: ""; position: absolute; left: -8px; top: 50%; translate: 0 -50%; border: 8px solid transparent; border-left: 0; border-right-color: #fffaf0; }
.bubble.me { bottom: calc(100% - 4px); right: 8%; background: var(--gold); }
.bubble.me::after { content: ""; position: absolute; right: 26px; bottom: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: var(--gold); }

/* Fin de mano */
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(8, 24, 14, .45);
  backdrop-filter: blur(1.5px);
  border-radius: 20px;
  z-index: 8;
}
.overlay-card {
  background: var(--panel); color: var(--ink);
  border-radius: 18px; padding: 20px 26px;
  text-align: center; box-shadow: var(--shadow);
  min-width: 260px; max-width: min(92%, 420px);
}
.overlay-title { font-family: var(--serif); font-size: 23px; font-weight: 700; }
.overlay-detail { margin: 8px 0 16px; color: var(--muted); font-size: 14.5px; line-height: 1.55; }

/* ---------- Costado ---------- */
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; max-height: calc(100dvh - 82px); position: sticky; top: 8px; overflow: auto; }
.board {
  background: radial-gradient(ellipse at 30% 20%, #2f3d34, #1c2620);
  border: 10px solid var(--wood);
  box-shadow: 0 0 0 2px var(--wood-dark), var(--shadow);
  border-radius: 12px;
  padding: 12px 10px 14px;
  color: #f1ecdf;
}
.board-title { text-align: center; font-family: var(--serif); font-size: 14px; opacity: .7; margin-bottom: 8px; letter-spacing: .5px; }
.board-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sb-col { text-align: center; min-width: 0; }
.sb-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-num { font-family: var(--serif); font-size: 34px; font-weight: 700; color: var(--gold); line-height: 1.1; }
.sb-sub { font-size: 11px; opacity: .6; margin-bottom: 6px; }
.sb-col svg { width: 100%; max-width: 120px; display: block; margin: 0 auto; }
.sb-col.bump .sb-num { animation: bump .55s; }
@keyframes bump { 40% { transform: scale(1.4); color: #fff; } }

.info { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip { background: rgba(0, 0, 0, .3); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip span { font-size: 11px; opacity: .65; text-transform: uppercase; letter-spacing: .6px; }
.chip b { color: var(--gold); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.log-wrap { background: rgba(0, 0, 0, .3); border-radius: 14px; padding: 10px 12px; flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.log-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .6; margin-bottom: 6px; }
.log { list-style: none; margin: 0; padding: 0; font-size: 13.5px; overflow-y: auto; flex: 1; min-height: 0; }
.log li { padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, .07); line-height: 1.35; }
.log li.me { color: #f5d98c; }
.log li.play { opacity: .8; }
.log li.pts { color: var(--gold); font-weight: 650; }
.log li.sep { opacity: .55; font-size: 12px; text-align: center; border: 0; padding-top: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, .6); padding: 16px; }
.modal-card { background: var(--panel); color: var(--ink); border-radius: 22px; padding: 28px 24px; max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.modal-avatar { font-size: 62px; }
.modal-card h2 { font-family: var(--serif); margin: 6px 0; font-size: 28px; }
.modal-quote { font-style: italic; color: var(--muted); }
.modal-score { font-weight: 700; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* ---------- Pantallas medianas y celulares ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; padding: 0 10px 14px; gap: 12px; }
  .table { min-height: calc(100dvh - 58px - 8px); }
  .side { overflow: visible; max-height: none; position: static; }
  .side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .side .log-wrap { grid-column: 1 / -1; }
  .log { max-height: 240px; flex: none; }
}
@media (max-width: 600px) {
  :root { --hand-w: 82px; --trick-w: 54px; --opp-w: 40px; }
  .topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); height: 52px; }
  .top-title { display: none; }
  .topbar { grid-template-columns: auto 1fr; }
  .top-score { font-size: 13px; padding: 5px 10px; }
  .table { border-width: 8px; border-radius: 22px; padding: 10px 8px 12px; min-height: calc(100dvh - 52px - 6px); }
  .avatar { width: 42px; height: 42px; font-size: 24px; }
  .opp-zone { flex-direction: row; justify-content: space-between; align-items: flex-start; }
  .bubble.opp { left: 0; top: calc(100% + 10px); translate: none; transform-origin: top left; max-width: 240px; font-size: 14px; }
  .bubble.opp::before { left: 18px; top: -8px; translate: none; border: 8px solid transparent; border-top: 0; border-bottom-color: #fffaf0; }
  .btn.act { width: 104px; height: 42px; padding: 0 6px; font-size: 13px; }
  .actions { padding: 6px; gap: 6px; }
  .side { grid-template-columns: 1fr; }
  .info { grid-template-columns: 1fr 1fr 1fr; }
  .status { font-size: 14px; }
}

/* ---------- Carrera por provincias y partida libre ---------- */
.tier-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.tier-head span { font-family: var(--serif); font-size: 17px; letter-spacing: .5px; text-transform: none; color: var(--gold); }
.tier-head em { font-style: normal; font-size: 11px; color: var(--muted); }
.crown { font-size: 14px; }
.diff { height: 5px; width: 130px; background: rgba(255, 255, 255, .12); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.diff i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- Armado de equipos ---------- */
.teams { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.team-cols { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 16px; width: 100%; align-items: start; }
.team-col h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); margin: 0 0 10px; }
.team-col.them h3 { color: #e7a39b; }
.team-slot {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--panel-line); border-left: 4px solid var(--accent, var(--gold));
  border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; min-height: 58px;
}
.slot-avatar { font-size: 24px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .08); flex: none; }
.slot-name { font-weight: 700; }
select.pick {
  flex: 1; min-width: 0; width: 100%;
  background: rgba(0, 0, 0, .35); color: var(--ink);
  border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 8px; font: inherit; font-size: 14px;
}
select.pick option, select.pick optgroup { background: #2a1a0e; color: #f3e9d2; }
.team-vs { font-family: var(--serif); font-size: 30px; color: var(--gold); align-self: center; padding-top: 24px; }
.team-meta { margin: 0; color: var(--muted); font-size: 14px; }
.team-actions { display: flex; gap: 12px; align-items: center; }
.team-actions .btn.ghost { color: var(--ink); }

/* ---------- Mesa por equipos ---------- */
.table.team-mode { padding-top: 96px; }
.ring { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.seat { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.seat-id { display: flex; gap: 8px; align-items: center; background: rgba(0, 0, 0, .38); padding: 4px 12px 4px 4px; border-radius: 999px; border: 2px solid transparent; transition: box-shadow .2s; }
.seat.us .seat-id { border-color: rgba(232, 179, 58, .55); }
.seat.them .seat-id { border-color: rgba(231, 163, 155, .45); }
.seat.acting .seat-id { box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(232, 179, 58, .55); }
.seat-avatar { font-size: 22px; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .1); border: 2px solid var(--accent); flex: none; }
.seat-text { display: flex; flex-direction: column; line-height: 1.15; }
.seat-text b { font-size: 13px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-text em { font-style: normal; font-size: 11px; opacity: .75; }
.seat.mano .seat-text em::after { content: " · mano"; color: var(--gold); }
.seat-cards { display: flex; --w: 30px; min-height: 45px; }
.seat-cards .card { margin: 0 -5px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, .4); }
.pos-top { top: 10px; left: 50%; translate: -50% 0; }
.pos-left { left: 12px; top: 40%; translate: 0 -50%; }
.pos-right { right: 12px; top: 40%; translate: 0 -50%; }
.pos-tl { left: 12px; top: 14px; }
.pos-tr { right: 12px; top: 14px; }
.pos-bl { left: 12px; top: 50%; }
.pos-br { right: 12px; top: 50%; }
.seat-bubble { top: calc(100% + 8px); left: 50%; translate: -50% 0; transform-origin: top center; }
.seat-bubble::before { content: ""; position: absolute; left: 50%; top: -8px; translate: -50% 0; border: 8px solid transparent; border-top: 0; border-bottom-color: #fffaf0; }
.pos-left .seat-bubble, .pos-tl .seat-bubble, .pos-bl .seat-bubble { left: 0; translate: none; }
.pos-left .seat-bubble::before, .pos-tl .seat-bubble::before, .pos-bl .seat-bubble::before { left: 24px; }
.pos-right .seat-bubble, .pos-tr .seat-bubble, .pos-br .seat-bubble { left: auto; right: 0; translate: none; }
.pos-right .seat-bubble::before, .pos-tr .seat-bubble::before, .pos-br .seat-bubble::before { left: auto; right: 24px; translate: none; }

.team-center { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.tsum { display: flex; gap: 8px; }
.tchip { font-size: 12.5px; font-weight: 700; padding: 4px 12px; border-radius: 999px; background: rgba(0, 0, 0, .3); display: flex; gap: 6px; }
.tchip em { font-style: normal; opacity: .6; font-weight: 600; }
.tchip.r-me { background: var(--gold); color: #2b1a05; }
.tchip.r-opp { background: rgba(140, 40, 30, .7); }
.tchip.r-parda { background: #9fb8dc; color: #142a4a; }
.tring { position: relative; width: min(380px, 56%); height: calc(var(--trick-w) * 1.5 * 2.25); --w: var(--trick-w); }
.tcard { position: absolute; }
.tcard .card.fresh { animation: drop .3s ease-out; }
.tcard.win .card { box-shadow: 0 0 0 3px var(--gold), 0 8px 18px rgba(0, 0, 0, .5); }
.tcard.parda .card { box-shadow: 0 0 0 3px #9fb8dc; }
.at-bottom { left: 50%; bottom: 0; translate: -50% 0; }
.at-top { left: 50%; top: 0; translate: -50% 0; }
.at-left { left: 0; top: 50%; translate: 0 -50%; }
.at-right { right: 0; top: 50%; translate: 0 -50%; }
.at-tl { left: 14%; top: 0; }
.at-tr { right: 14%; top: 0; }
.at-bl { left: 14%; bottom: 0; }
.at-br { right: 14%; bottom: 0; }
.table.six .at-tl, .table.six .at-bl { left: 2%; }
.table.six .at-tr, .table.six .at-br { right: 2%; }

@media (max-width: 600px) {
  .team-cols { grid-template-columns: minmax(0, 1fr); }
  .team-vs { padding: 0; text-align: center; }
  .table.team-mode { padding-top: 118px; }
  .pos-bl, .pos-br { top: 37%; }
  .table.team-mode .status { max-width: 54%; font-size: 13px; }
  .seat-id { flex-direction: column; gap: 2px; padding: 4px 6px; border-radius: 14px; }
  .seat-text { align-items: center; }
  .seat-text b { font-size: 11px; max-width: 74px; }
  .seat-text em { display: none; }
  .seat.mano .seat-avatar { box-shadow: 0 0 0 2px var(--gold); }
  .seat-cards { --w: 20px; min-height: 30px; }
  .seat-cards .card { margin: 0 -4px; }
  .pos-left, .pos-right { top: 40%; }
  .pos-left, .pos-tl, .pos-bl { left: 4px; }
  .pos-right, .pos-tr, .pos-br { right: 4px; }
  .seat-bubble { max-width: 170px; font-size: 13px; }
  .tring { width: calc(100% - 180px); min-width: 150px; height: calc(var(--trick-w) * 1.5 * 2.3); }
  .tchip { font-size: 11.5px; padding: 3px 8px; }
}

/* ---------- Señas al compañero y ver sus cartas ---------- */
.talk { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; max-width: 720px; }
.talk-label { font-size: 12px; opacity: .7; margin-right: 2px; }
.btn.talk-btn { padding: 5px 11px; font-size: 13px; border-radius: 999px; background: rgba(0, 0, 0, .35); color: #f5e6c4; box-shadow: inset 0 0 0 1.5px rgba(232, 179, 58, .55); }
.btn.talk-btn:hover { background: rgba(232, 179, 58, .25); }
button.seat-id { font: inherit; color: inherit; cursor: pointer; pointer-events: auto; }
button.seat-id:hover { box-shadow: 0 0 0 2px rgba(232, 179, 58, .7); }
.seat.peek .seat-cards { --w: 46px; min-height: 70px; }
.seat.peek .seat-cards .card { margin: 0 -2px; }
.seat.peek.pos-top, .seat.peek.pos-tl, .seat.peek.pos-tr { flex-direction: row; align-items: center; gap: 10px; }
.seat.peek.pos-tr { flex-direction: row-reverse; }
.log li.mate { color: #a9e0b2; }
@media (max-width: 600px) {
  .talk-label { display: none; }
  .btn.talk-btn { padding: 4px 8px; font-size: 12px; }
  .seat.peek .seat-cards { --w: 32px; min-height: 48px; }
}
.talk.asking .talk-btn[data-talk="pone"], .talk.asking .talk-btn[data-talk="veni"] {
  background: var(--gold); color: #2b1a05; box-shadow: 0 0 0 3px rgba(232, 179, 58, .4); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.08); } }
/* truco fuera de turno: sólo aparece ese botón, más discreto */
.actions.out-turn { background: rgba(0, 0, 0, .15); }
.actions.out-turn .btn.truco { opacity: .92; }
