/* Naipe de truco: una placa de carbón con trazo grueso y sombra dura, como una carta impresa.
   Marcador, bazas, cantos y acciones viven en la misma placa. Mobile first, una mano. */

:root {
  --wall: #0b0c0f;
  --enamel: #16181d;
  --enamel-hi: #2d3038;
  --enamel-deep: #1b1d23;
  --enamel-edge: #0b0c0f;
  --porcelain: #f7f1e3;
  --porcelain-dim: #b9bcc6;
  --ink: #16181d;
  --signal: #e6b83c;
  --signal-deep: #a37a12;
  --lacre: #c8261f;
  --lacre-deep: #7d1511;
  --ok: #17794a;
  --line: rgba(247, 244, 234, 0.24);
  --focus: var(--signal);
  --font: 'DM Sans', system-ui, sans-serif;
  --display: 'Alfa Slab One', Georgia, serif;
  --r: 12px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-snap: cubic-bezier(0.165, 0.84, 0.44, 1);
  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --cw-hand: clamp(68px, 21.5vw, 116px);
  --cw-table: clamp(52px, 15.5vw, 92px);
  --cw-bot: clamp(36px, 10vw, 62px);
  --card-glow: 0 0 0.75px rgba(11, 12, 15, 0.9);
  accent-color: var(--signal);
  caret-color: var(--signal);
  scrollbar-color: var(--enamel-hi) var(--wall);
  scrollbar-width: thin;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--wall); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--wall);
  color: var(--porcelain);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
  padding-inline: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px));
  padding-block: 10px calc(18px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; background: var(--noise); opacity: 0.06; }
::selection { background: var(--signal); color: var(--ink); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--enamel-hi); border-radius: 99px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a { text-underline-offset: 0.2em; text-decoration-thickness: 1px; }

.wall { position: relative; z-index: 1; max-width: 1120px; margin-inline: auto; display: grid; gap: 14px; align-items: start; }

/* ---------- la chapa ---------- */
.plate {
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  min-height: calc(100dvh - 24px);
  padding: 24px 20px 28px;
  border-radius: 18px;
  color: var(--porcelain);
  overflow: clip;
  background: var(--enamel-deep);
  border: 3px solid var(--porcelain);
  box-shadow: 6px 8px 0 var(--lacre), 6px 8px 0 3px var(--wall);
}

.plate > * { position: relative; z-index: 1; }
.chips, .rivet { display: none; }

/* ---------- cabecera de la chapa ---------- */
.plate-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-inline: 4px; }
.plate-head h1 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: 36px; line-height: 0.95; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--porcelain); text-shadow: 3px 3px 0 var(--lacre);
}
/* Los cuatro palos de la baraja como filete bajo el titulo. */
.plate-head h1::after {
  content: ""; display: block; height: 6px; margin-top: 9px; border-radius: 3px;
  background: linear-gradient(to right, #e6b83c 0 25%, #c8261f 25% 50%, #2f5fa8 50% 75%, #2f7a45 75%);
}
.tools { display: flex; align-items: center; gap: 8px; }
.sound-toggle {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%;
  background: var(--porcelain); color: var(--ink);
  box-shadow: 3px 3px 0 var(--wall);
  transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}
.sound-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle .spk { fill: currentColor; }
.sound-toggle .cross { display: none; }
.sound-toggle[aria-pressed="false"] { background: transparent; color: var(--porcelain-dim); box-shadow: inset 0 0 0 2px var(--line); }
.sound-toggle[aria-pressed="false"] .wave { display: none; }
.sound-toggle[aria-pressed="false"] .cross { display: inline; }
.sound-toggle:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--wall); }
.deck-link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 99px;
  border: 2px solid rgba(247, 244, 234, 0.55); color: var(--porcelain); text-decoration: none;
  font-weight: 800; font-size: 16px; letter-spacing: 0.08em; text-transform: uppercase;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .deck-link:hover { background: rgba(247, 244, 234, 0.12); border-color: var(--porcelain); }
  .sound-toggle:hover { transform: translateY(-1px); }
}

/* ---------- marcador: panel de porcelana pintado dentro de la chapa ---------- */
.board {
  display: grid; gap: 2px; padding: 8px 12px 6px; border-radius: 10px;
  background: var(--porcelain); color: var(--ink);
  border: 2px solid var(--wall); box-shadow: 4px 4px 0 var(--wall);
}
.score-row { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) 36px; align-items: center; gap: 8px; }
.score-name { font-family: var(--display); font-weight: 400; font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--enamel); }
.score-row.bot .score-name { color: var(--lacre); }
.score-num { display: inline-block; text-align: right; font-family: var(--display); font-weight: 400; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--enamel); }
.score-row.bot .score-num { color: var(--lacre); }
.score-num.bump { animation: bump 420ms var(--ease-snap); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* Fosforos en cuadritos de cinco: 15 malas y 15 buenas, entintados sobre la porcelana. */
.tally { position: relative; }
.tally::after { content: ""; position: absolute; top: 2px; bottom: 2px; left: 50%; border-left: 1px dashed rgba(22, 24, 29, 0.4); pointer-events: none; }
.tally svg { display: block; width: 100%; height: auto; max-height: 26px; }
.tally .stick { stroke: rgba(22, 24, 29, 0.14); stroke-width: 2.8; stroke-linecap: round; }
.tally .stick.on { stroke: var(--enamel); }
.score-row.bot .tally .stick.on { stroke: var(--lacre); }
.tally .stick.fresh { animation: strike 380ms var(--ease-out); }
@keyframes strike { from { stroke-width: 7; opacity: 0.2; } to { stroke-width: 2.8; opacity: 1; } }
.score-legend { display: grid; grid-template-columns: 44px minmax(0, 1fr) 36px; gap: 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: #4a4d58; }
.score-legend .halves { grid-column: 2; display: flex; justify-content: space-between; }

/* ---------- asientos ---------- */
.seat { position: relative; display: grid; gap: 6px; align-items: center; }
.seat-head {
  display: flex; align-items: center; gap: 8px; border-bottom: 3px solid transparent; padding-bottom: 2px;
  font-family: var(--display); font-weight: 400; font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--porcelain);
  transition: color 200ms var(--ease-out), border-color 200ms var(--ease-out), transform 240ms var(--ease-out);
}
.chip {
  font-weight: 800; font-size: 11px; letter-spacing: 0.1em; padding: 2px 9px; border-radius: 99px;
  background: var(--signal); color: var(--ink); animation: bump 420ms var(--ease-snap);
}
.hint { color: var(--porcelain-dim); font-size: 15px; font-weight: 600; }
.hand { display: flex; justify-content: center; gap: 8px; min-height: calc(var(--cw) * 1.5); perspective: 800px; }

/* Bot: nombre a la izquierda y sus cartas en la misma linea. */
.seat-bot { grid-template-columns: auto 1fr; gap: 12px; }
.seat-bot .hand { --cw: var(--cw-bot); gap: 0; }
.seat-bot .hand .card + .card { margin-left: calc(var(--cw) * -0.3); }

/* Vos: nombre y pista de envido en una linea, la mano debajo. */
.seat-you { grid-template-columns: auto 1fr; grid-template-areas: "head hint" "hand hand"; column-gap: 12px; }
.seat-you .seat-head { grid-area: head; justify-self: start; }
.seat-you .hint { grid-area: hint; justify-self: end; text-align: right; }
.seat-you .hand { grid-area: hand; --cw: var(--cw-hand); }

/* El turno se ve por forma y por color: tu nombre sube, se subraya y se pinta de señal. */
.seat-you::before {
  content: ""; position: absolute; inset: 10px -12px -8px; border-radius: 22px; pointer-events: none; opacity: 0;
  background: rgba(247, 241, 227, 0.07);
  transition: opacity 400ms var(--ease-out);
}
.seat-you.turn::before { opacity: 1; animation: breathe 2.4s ease-in-out infinite; }
.seat-you.turn .seat-head { transform: translateY(-2px); color: var(--signal); border-color: var(--signal); }
@keyframes breathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.seat > * { position: relative; }

/* ---------- cantos: cartel pintado ---------- */
.bubble {
  position: absolute; top: -6px; right: 0; z-index: 6; max-width: 68%;
  background: var(--porcelain); color: var(--ink);
  border-radius: var(--r);
  border: 2px solid var(--wall); box-shadow: 4px 4px 0 var(--wall);
  padding: 6px 14px 8px;
  font-family: var(--display); font-weight: 400; font-size: clamp(20px, 6.2vw, 28px); line-height: 1.1; letter-spacing: 0.02em; text-transform: uppercase;
  opacity: 0; transform: scale(0.92) translateY(6px); pointer-events: none;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.bubble.show { opacity: 1; animation: pop 320ms var(--ease-snap) forwards; }
.seat-you .bubble { top: auto; bottom: calc(100% + 6px); right: auto; left: 0; }
@keyframes pop { 0% { transform: scale(0.6) translateY(10px) rotate(-6deg); } 100% { transform: scale(1) translateY(0) rotate(-2deg); } }
.bubble::after { content: ""; position: absolute; inset: -1px; border-radius: inherit; border: 2px solid var(--signal); opacity: 0; pointer-events: none; }
.bubble.show::after { animation: ring 520ms var(--ease-out) both; }
@keyframes ring { from { opacity: 0.9; transform: scale(1); } to { opacity: 0; transform: scale(1.3, 1.55); } }
.bubble.shout-truco { color: var(--lacre); }
.bubble.shout-truco.show { animation: stamp 340ms var(--ease-out) forwards; }
@keyframes stamp {
  0% { transform: scale(1.7) translateY(-8px) rotate(-9deg); opacity: 0; }
  55% { transform: scale(0.94) translateY(0) rotate(-2deg); opacity: 1; }
  100% { transform: scale(1) translateY(0) rotate(-2deg); opacity: 1; }
}
.bubble.shout-envido { color: var(--ink); }
.bubble.shout-envido.show { animation: chime 520ms var(--ease-out) forwards; }
@keyframes chime {
  0% { transform: scale(0.7) translateY(10px) rotate(-7deg); opacity: 0; }
  35% { transform: scale(1.08) translateY(-2px) rotate(3deg); opacity: 1; }
  65% { transform: scale(0.98) rotate(-3deg); }
  100% { transform: scale(1) translateY(0) rotate(-2deg); opacity: 1; }
}

/* El bot piensa: sus cartas se mecen. */
.seat-bot.thinking .hand .card:not(.deal) { animation: sway 1.8s ease-in-out infinite; animation-delay: calc(var(--i, 0) * 140ms); transform-origin: 50% 110%; }
@keyframes sway { 0%, 100% { rotate: -1.5deg; translate: 0 0; } 50% { rotate: 1.5deg; translate: 0 -3px; } }

/* ---------- centro: bazas en parejas superpuestas, numeradas con plantilla ---------- */
.center { flex: 1; display: grid; align-content: center; justify-items: center; gap: 4px; background: var(--wall); border: 2px solid var(--enamel-hi); border-radius: 14px; padding-block: 8px; }
.tricks { display: flex; gap: clamp(6px, 3vw, 28px); justify-content: center; counter-reset: baza; }
.trick {
  --cw: var(--cw-table);
  position: relative; counter-increment: baza;
  display: grid; grid-template-areas: "pair" "label"; justify-items: center; gap: 4px;
  padding: calc(var(--cw) * 0.22) calc(var(--cw) * 0.24) 0;
}
/* Numero pintado con plantilla sobre el esmalte, donde caen las cartas. */
.trick::before {
  content: counter(baza); position: absolute; inset: 0 0 20px; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-weight: 400; font-size: calc(var(--cw) * 1.45); line-height: 1; color: rgba(247, 244, 234, 0.1);
}
.slot { grid-area: pair; position: relative; z-index: 1; width: var(--cw); height: calc(var(--cw) * 1.5); display: grid; place-items: center; }
.slot.won { z-index: 2; }
.slot:nth-child(1) { transform: translate(-24%, -20%); }
.slot:nth-child(2) { transform: translate(24%, 18%); }
.slot .card { margin: -2px; transform: rotate(var(--tilt, 0deg)); transition: opacity 300ms var(--ease-out), filter 300ms var(--ease-out); }
.slot .card.celebrate { animation: win 700ms var(--ease-out) 1; }
.slot.won .card::after {
  content: ""; position: absolute; inset: -3px; border: 3px solid var(--signal); border-radius: calc(var(--cw) * 0.08); pointer-events: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35); animation: winglow 1.4s ease-in-out 2;
}
@keyframes winglow { 50% { box-shadow: 0 4px 0 var(--signal-deep); } }
/* La baza perdida se anula, no desaparece. */
.slot.lost .card { opacity: 0.5; filter: saturate(0.4) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)); }
@keyframes win { 0% { transform: rotate(var(--tilt, 0deg)) scale(1); } 35% { transform: rotate(0deg) scale(1.16); } 100% { transform: rotate(var(--tilt, 0deg)) scale(1); } }
.slot .card.drop { will-change: transform; }
.trick-label { grid-area: label; margin-top: calc(var(--cw) * 0.3); font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--porcelain-dim); }

/* La carta toca el esmalte: una onda se abre desde la casilla. */
.impact {
  position: absolute; inset: -6px; z-index: -1; border-radius: 50%; pointer-events: none;
  border: 3px solid rgba(247, 244, 234, 0.6); animation: impact 520ms var(--ease-out) both;
}
@keyframes impact { from { transform: scale(0.5); opacity: 0.9; border-width: 4px; } to { transform: scale(1.75); opacity: 0; border-width: 1px; } }

/* Cantar truco es golpear la chapa: vibra un golpe por cada nivel. */
.plate.knock { animation: knock 150ms var(--ease-out) var(--n, 1); }
@keyframes knock {
  0% { translate: 0 0; rotate: 0deg; }
  30% { translate: 0 3px; rotate: -0.25deg; }
  65% { translate: 0 -1px; rotate: 0.2deg; }
  100% { translate: 0 0; rotate: 0deg; }
}

.status { min-height: 40px; display: grid; gap: 8px; justify-items: center; align-content: center; text-align: center; font-size: 17px; font-weight: 600; }
.status > span { animation: fade-up 260ms var(--ease-out) both; }
.status .hint { font-size: 16px; }
.hint.thinking::after { content: ""; display: inline-block; width: 1.4em; text-align: left; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- cartas (el arte no se toca; solo su sombra y su filete) ---------- */
.card {
  position: relative; display: block; flex: none; padding: 0; background: none;
  width: var(--cw); height: calc(var(--cw) * 1.5);
  border-radius: calc(var(--cw) * 0.07);
  filter: drop-shadow(var(--card-glow)) drop-shadow(0 5px 8px rgba(0, 0, 0, 0.5));
  transition: filter 220ms var(--ease-out);
}
.card::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 248, 224, 0.16) 0%, transparent 42%, rgba(0, 0, 0, 0.12) 100%);
}
.card img { display: block; width: 100%; height: 100%; border-radius: inherit; -webkit-user-drag: none; user-select: none; }

/* Tus cartas en abanico. La carta (el boton) no se mueve al tocarla: solo sube su imagen,
   asi la zona sensible al mouse queda fija y el borde no parpadea entre hover y no-hover. */
.seat-you .hand .card { transform: translateY(var(--lift, 0)) rotate(var(--rot, 0deg)); transform-origin: 50% 120%; }
.seat-you .hand .card:nth-child(1):not(:last-child) { --rot: -6deg; --lift: 6px; }
.seat-you .hand .card:nth-child(3) { --rot: 6deg; --lift: 6px; }
.seat-you .hand .card:nth-child(2):not(:last-child) { --lift: -3px; }
.seat-you .hand .card img, .seat-you .hand .card::before {
  transform: var(--pop, none); transform-origin: 50% 100%;
  transition: transform 240ms var(--ease-out);
}
.seat-you .hand .card:not(:disabled):not(.selected) img,
.seat-you .hand .card:not(:disabled):not(.selected)::before { animation: ready 2.6s ease-in-out infinite; animation-delay: calc(var(--i, 0) * 180ms); }
@keyframes ready { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
@media (hover: hover) and (pointer: fine) {
  button.card:hover:not(:disabled) { --pop: translateY(-18px) rotate(calc(var(--rot, 0deg) * -1)) scale(1.06); z-index: 2; filter: drop-shadow(var(--card-glow)) drop-shadow(0 12px 14px rgba(0, 0, 0, 0.5)); }
  .seat-you .hand button.card:hover:not(:disabled) img, .seat-you .hand button.card:hover:not(:disabled)::before { animation: none; }
}
button.card:active:not(:disabled) { --pop: translateY(-8px) rotate(calc(var(--rot, 0deg) * -1)) scale(0.97); }
button.card:disabled { cursor: default; }
.seat-you .hand .card.selected {
  --pop: translateY(-26px) rotate(calc(var(--rot, 0deg) * -1)) scale(1.1); z-index: 3;
  filter: drop-shadow(var(--card-glow)) drop-shadow(0 14px 16px rgba(0, 0, 0, 0.5));
}
.seat-you .hand .card.selected img { outline: 3px solid var(--signal); outline-offset: 3px; }

/* Reparto: las cartas vuelan desde el mazo, una tras otra. */
.hand .card.deal { animation: deal 560ms var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 120ms); }
@keyframes deal {
  0% { transform: translate(40vw, -46vh) rotate(40deg) scale(0.5); opacity: 0; }
  30% { opacity: 1; }
}

/* ---------- acciones: chapitas pintadas, dentro de la placa, no una barra aparte ---------- */
.dock { margin-top: 2px; padding-top: 12px; border-top: 2px solid var(--line); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: stretch; min-height: 50px; }

.btn {
  --face: var(--enamel-hi); --rim: var(--wall); --drop: var(--wall); --fg: var(--porcelain);
  position: relative; isolation: isolate; overflow: hidden;
  flex: 1 1 calc(33% - 8px); min-height: 50px; padding: 6px 10px;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  background: var(--face);
  color: var(--fg);
  border: 2px solid var(--rim); border-radius: var(--r);
  box-shadow: 3px 3px 0 var(--drop);
  font-family: var(--display); font-weight: 400; font-size: 16px; letter-spacing: 0.05em; line-height: 1; text-transform: uppercase;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out), border-color 160ms var(--ease-out);
  animation: btn-in 380ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes btn-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--drop); }
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--drop); transition-duration: 60ms; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Un color por funcion. Quiero: señal. Truco: lacre. Envido: porcelana. Mazo: aparte, chico y sin relleno. */
.btn.primary { --face: var(--signal); --rim: var(--wall); --drop: var(--wall); --fg: var(--ink); }
.btn.danger { --face: var(--enamel-hi); --rim: var(--porcelain-dim); --drop: var(--wall); }
.btn.hot { --face: var(--lacre); --rim: var(--wall); --drop: var(--wall); --fg: #fff; min-height: 56px; font-size: 18px; }
.btn.cool, .menu-wrap > .btn.cool { --face: var(--porcelain); --rim: var(--wall); --drop: var(--wall); --fg: var(--ink); min-height: 56px; font-size: 18px; }
.btn.ghost { --face: transparent; --rim: rgba(247, 241, 227, 0.4); --drop: transparent; --fg: var(--porcelain-dim); min-height: 44px; padding-inline: 14px; font-size: 16px; font-weight: 700; background: none; }
/* Orden en la botonera: Quiero, No quiero, Mazo (chico y aparte), Truco, Envido. */
.actions > .btn.primary { order: -3; flex-basis: calc(50% - 8px); }
.actions > .btn.danger { order: -2; flex-basis: calc(50% - 8px); }
.actions > .btn.ghost { order: -1; flex: 0 0 auto; align-self: center; margin-right: 8px; }
.actions > .btn.hot { flex-grow: 1.4; }
.actions > .menu-wrap { order: 1; }
.status .btn { flex: 0 0 auto; min-width: 200px; }

/* Menu del envido: se abre hacia arriba, sobre el boton. */
.menu-wrap { position: relative; flex: 1 1 calc(33% - 8px); display: flex; }
.menu-wrap > .btn { flex: 1; gap: 8px; }
.caret { width: 8px; height: 8px; border-right: 3px solid currentColor; border-top: 3px solid currentColor; transform: translateY(2px) rotate(-45deg); transition: transform 220ms var(--ease-out); flex: none; }
.menu-wrap.open .caret { transform: translateY(-1px) rotate(135deg); }
.menu {
  --focus: var(--lacre);
  position: absolute; bottom: calc(100% + 12px); left: 50%; z-index: 20;
  width: max-content; min-width: 230px; max-width: calc(100vw - 20px);
  display: grid; gap: 4px; padding: 8px;
  background: var(--porcelain); color: var(--ink); border-radius: 14px;
  border: 2px solid var(--wall); box-shadow: 4px 4px 0 var(--wall), 0 16px 32px rgba(0, 0, 0, 0.5);
  transform: translateX(calc(-50% + var(--shift, 0px))) translateY(10px) scale(0.94); transform-origin: 50% 100%;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 160ms var(--ease-out), transform 220ms var(--ease-out), visibility 0s 220ms;
}
.menu::after {
  content: ""; position: absolute; top: 100%; left: calc(50% - var(--shift, 0px)); width: 14px; height: 14px; margin: -8px 0 0 -7px;
  background: var(--porcelain); border-right: 2px solid var(--wall); border-bottom: 2px solid var(--wall); transform: rotate(45deg);
}
.menu-wrap.open .menu { opacity: 1; visibility: visible; pointer-events: auto; transform: translateX(calc(-50% + var(--shift, 0px))) translateY(0) scale(1); transition-delay: 0s; }
.menu-item {
  display: grid; gap: 1px; justify-items: start; text-align: left; width: 100%; min-height: 56px; padding: 8px 14px;
  background: transparent; color: var(--ink); border-radius: 10px; border: 1px solid transparent;
  opacity: 0; transform: translateY(8px);
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 120ms var(--ease-out), opacity 200ms var(--ease-out);
}
.menu-wrap.open .menu-item { opacity: 1; transform: none; transition-delay: calc(var(--k, 0) * 45ms), calc(var(--k, 0) * 45ms), 0s, calc(var(--k, 0) * 45ms); }
.menu-name { font-family: var(--display); font-weight: 400; font-size: 18px; line-height: 1.1; letter-spacing: 0.03em; text-transform: uppercase; }
.menu-hint { font-size: 13px; font-weight: 600; color: #4a4d58; }
.menu-item:active { transform: scale(0.97) !important; background: rgba(22, 24, 29, 0.14); }
@media (hover: hover) and (pointer: fine) {
  .menu-item:hover { background: rgba(22, 24, 29, 0.08); border-color: rgba(22, 24, 29, 0.4); }
}
.menu-item:last-child .menu-name { color: var(--lacre); }

/* ---------- carteles secundarios: lo que el bot sabe, reglas, historial ---------- */
.side { display: grid; gap: 12px; min-width: 0; }
.panel {
  --focus: var(--enamel);
  padding: 14px 16px; border-radius: 14px; background: var(--porcelain); color: var(--ink);
  border: 2px solid var(--wall); box-shadow: 4px 4px 0 var(--wall);
}
.panel > summary, .panel h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 17px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--enamel); }
.panel > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px; list-style: none; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: "+"; font-size: 26px; font-weight: 700; color: var(--enamel); transition: transform 200ms var(--ease-out); }
.panel[open] > summary::after { transform: rotate(45deg); }
.panel[open] > .panel-body, .panel[open] > ul { animation: fade-up 260ms var(--ease-out) both; }
.panel-body { display: grid; gap: 12px; margin-top: 8px; }
.panel-sub, .insight-note { margin: 0; color: #3a3d47; font-size: 15px; }
.insight { display: grid; gap: 5px; padding-top: 12px; border-top: 1px solid rgba(22, 24, 29, 0.18); }
.insight:first-of-type { border-top: 0; padding-top: 0; }
.insight-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.insight-title { font-weight: 800; }
.insight-val { font-family: var(--display); font-weight: 400; font-size: 20px; color: var(--enamel); white-space: nowrap; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 99px; background: rgba(22, 24, 29, 0.12); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--enamel); transition: width 600ms var(--ease-out); }
.insight-n { font-size: 14px; color: #3a3d47; font-variant-numeric: tabular-nums; }
.insight.nodata .insight-val { color: #4a4d58; font-weight: 600; font-size: 16px; }
.insight.changed .insight-val { color: var(--ok); }
.insight.changed .meter > i { background: var(--ok); }
.panel ul { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 8px; }
.panel li { font-size: 15px; }
.log { list-style: none; padding: 0 !important; max-height: 220px; overflow: auto; }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(22, 24, 29, 0.15); }
.panel .btn { --face: var(--porcelain); --rim: var(--wall); --drop: var(--wall); --fg: var(--ink); flex: none; width: 100%; font-size: 17px; }

/* ---------- fin de partida: otra chapa ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11, 12, 15, 0.8); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 30; animation: fade-in 240ms var(--ease-out) both; }
.overlay[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }
.dialog {
  width: min(100%, 380px); display: grid; gap: 14px; text-align: center; padding: 30px 22px 24px;
  background: var(--enamel-deep); border: 3px solid var(--porcelain);
  color: var(--porcelain); border-radius: 18px;
  box-shadow: 6px 8px 0 var(--lacre), 6px 8px 0 3px var(--wall);
  animation: dialog-in 420ms var(--ease-snap) both;
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(30px) scale(0.85) rotate(-3deg); } }
.dialog h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 34px; line-height: 1.05; letter-spacing: 0.04em; text-transform: uppercase; color: var(--signal); }
.dialog p { margin: 0; font-size: 18px; }
.dialog .btn { flex: 0 0 auto; }

/* Puntos: el numero sale flotando y el renglon del marcador se enciende. */
.score-pop {
  position: absolute; right: 0; top: -6px; z-index: 2; pointer-events: none;
  font-family: var(--display); font-weight: 400; font-size: 20px; color: var(--enamel); text-shadow: none;
  animation: score-pop 1100ms var(--ease-out) both;
}
.score-row.bot .score-pop { color: var(--lacre); }
@keyframes score-pop {
  0% { transform: translateY(6px) scale(0.6); opacity: 0; }
  20% { transform: translateY(-6px) scale(1.2); opacity: 1; }
  100% { transform: translateY(-28px) scale(1); opacity: 0; }
}
.score-row.scored::before {
  content: ""; position: absolute; inset: -2px -6px; border-radius: 8px; pointer-events: none;
  background: rgba(255, 194, 26, 0.45); animation: flash 900ms var(--ease-out) both;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* Victoria: lluvia de confeti en los colores de la chapa. */
.confetti { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -5vh; left: calc(var(--x) * 1%); width: 9px; height: 14px; border-radius: 2px; background: var(--c);
  animation: confetti-fall calc(var(--t) * 1s) cubic-bezier(0.3, 0.1, 0.6, 1) calc(var(--d) * 1s) both;
}
@keyframes confetti-fall {
  from { transform: translate3d(0, 0, 0) rotate(0turn); opacity: 1; }
  to { transform: translate3d(calc(var(--dx) * 1vw), 108vh, 0) rotate(calc(var(--r) * 1turn)); opacity: 0.9; }
}

/* ---------- pantallas medianas y escritorio ---------- */
@media (min-width: 600px) {
  body { font-size: 17px; padding-block: 22px 40px; }
  .plate { padding: 26px 26px 30px; min-height: 0; gap: 8px; }
  .plate-head h1 { font-size: 40px; }
  :root { --cw-hand: 108px; --cw-table: 80px; --cw-bot: 58px; }
  .btn { flex: 0 1 auto; padding-inline: 22px; }
  .btn.primary, .btn.danger { flex-basis: auto; }
}
@media (min-width: 960px) {
  .wall { grid-template-columns: minmax(0, 620px) minmax(0, 340px); justify-content: center; gap: 24px; }
  .btn { flex: 1 1 0; }
  :root { --cw-hand: 118px; --cw-table: 88px; --cw-bot: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-property: opacity, background-color !important; }
  .bubble.show { opacity: 1; transform: none; }
  .impact, .confetti, .score-row.scored::before { display: none; }
}

@media (max-width: 420px) {
  .plate-head h1 { font-size: 30px; }
  .deck-link { padding: 0 12px; font-size: 14px; }
  .tools { gap: 6px; }
}
