:root {
  --bg0: #070b16;
  --bg1: #111827;
  --panel: rgba(255,255,255,.10);
  --panel2: rgba(255,255,255,.15);
  --line: rgba(255,255,255,.18);
  --text: #f8fafc;
  --muted: #a7b0c0;
  --gold: #f8c45c;
  --red: #ef4444;
  --blue: #3b82f6;
  --yellow: #facc15;
  --green: #22c55e;
  --shadow: 0 26px 70px rgba(0,0,0,.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg0); color: var(--text); }
body {
  background:
    radial-gradient(circle at 10% 0%, rgba(59,130,246,.35), transparent 28rem),
    radial-gradient(circle at 90% 12%, rgba(239,68,68,.30), transparent 28rem),
    radial-gradient(circle at 65% 90%, rgba(34,197,94,.25), transparent 26rem),
    linear-gradient(160deg, #070b16, #101827 48%, #070b16);
  overflow-x: hidden;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { width: min(1480px, 100%); margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)); }
.glass {
  background: linear-gradient(145deg, rgba(255,255,255,.14), rgba(255,255,255,.07));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border-radius: 26px; padding: 14px; margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-dice {
  width: 54px; height: 54px; display: grid; place-items: center; border-radius: 18px;
  background: linear-gradient(135deg, #fff2c2, #f8c45c 42%, #b45309);
  font-size: 30px; box-shadow: inset 0 2px 10px rgba(255,255,255,.45), 0 12px 26px rgba(0,0,0,.28);
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(22px, 3vw, 34px); letter-spacing: -.04em; }
h2 { font-size: clamp(20px, 2vw, 28px); letter-spacing: -.03em; }
p { color: var(--muted); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 18px; background: rgba(0,0,0,.18); min-width: 190px; }
.user-card b, .user-card span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.user-card span { color: var(--muted); font-size: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center; font-weight: 900;
  background: linear-gradient(135deg, #64748b, #1f2937); border: 2px solid rgba(255,255,255,.28); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.skeleton .avatar, .skeleton b, .skeleton span { background: rgba(255,255,255,.12); color: transparent; border-radius: 8px; }

.layout { display: grid; gap: 14px; }
.panel { border-radius: 28px; padding: 18px; }
.section-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 16px; }
.create-form { display: flex; gap: 10px; margin-bottom: 18px; }
input {
  width: 100%; border: 1px solid rgba(255,255,255,.16); color: var(--text); outline: none;
  background: rgba(0,0,0,.24); border-radius: 16px; padding: 13px 14px;
}
input:focus { border-color: rgba(248,196,92,.75); box-shadow: 0 0 0 4px rgba(248,196,92,.12); }
.primary, .ghost, .icon-btn {
  border: 0; color: var(--text); border-radius: 16px; padding: 12px 15px; font-weight: 800;
  transition: transform .15s ease, opacity .15s ease, filter .15s ease;
}
.primary {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #1f1300; box-shadow: 0 12px 24px rgba(249,115,22,.25), inset 0 1px 0 rgba(255,255,255,.55);
}
.ghost, .icon-btn { background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.12); }
.icon-btn { width: 45px; height: 45px; padding: 0; font-size: 22px; }
.primary:hover, .ghost:hover, .icon-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.primary:disabled, .ghost:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.room-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.room-card {
  position: relative; overflow: hidden; border-radius: 24px; padding: 16px; background: rgba(0,0,0,.23);
  border: 1px solid rgba(255,255,255,.14); min-height: 162px;
}
.room-card::before {
  content: ""; position: absolute; inset: -55% auto auto -20%; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(248,196,92,.38), transparent 70%); pointer-events: none;
}
.room-card h3 { margin: 0 0 7px; font-size: 20px; position: relative; }
.room-card .meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; position: relative; }
.pill {
  border-radius: 999px; padding: 7px 10px; background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.12);
  color: var(--muted); font-size: 13px;
}
.room-actions { display: flex; gap: 8px; align-items: center; position: relative; }
.empty { text-align: center; border: 1px dashed rgba(255,255,255,.22); border-radius: 22px; padding: 30px 16px; color: var(--muted); }

.game-view { display: grid; gap: 12px; }
.game-header { border-radius: 24px; padding: 12px; display: flex; align-items: center; gap: 12px; }
.game-title { flex: 1; min-width: 0; }
.game-title h2, .game-title p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.players-strip { border-radius: 24px; padding: 10px; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.player-chip {
  display: flex; align-items: center; gap: 8px; padding: 9px; border-radius: 18px; background: rgba(0,0,0,.20);
  border: 1px solid rgba(255,255,255,.12); min-width: 0;
}
.player-chip.active { box-shadow: 0 0 0 2px var(--gold), 0 0 30px rgba(248,196,92,.22); }
.player-chip .color-dot { width: 13px; height: 13px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(255,255,255,.14); }
.player-chip b, .player-chip span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-chip span { font-size: 12px; color: var(--muted); }
.color-red { background: var(--red); }
.color-blue { background: var(--blue); }
.color-yellow { background: var(--yellow); }
.color-green { background: var(--green); }

.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
.board-card { border-radius: 30px; padding: 12px; position: relative; overflow: hidden; }
.board-card::after {
  content: ""; position: absolute; pointer-events: none; inset: 0;
  background: radial-gradient(circle at 50% 45%, transparent 42%, rgba(255,255,255,.10));
}
#board { width: 100%; aspect-ratio: 1 / 1; display: block; border-radius: 24px; background: #111827; box-shadow: inset 0 2px 24px rgba(0,0,0,.45); touch-action: manipulation; }
.game-controls {
  position: absolute; left: 22px; right: 22px; bottom: 22px; z-index: 3; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px; border-radius: 22px; background: rgba(7,11,22,.72); border: 1px solid rgba(255,255,255,.16); backdrop-filter: blur(14px);
}
.dice {
  width: 60px; height: 60px; border-radius: 18px; background: linear-gradient(135deg, #fff, #f3f4f6); color: #111827;
  display: grid; place-items: center; font-size: 34px; font-weight: 900; box-shadow: 0 12px 30px rgba(0,0,0,.32), inset 0 2px 0 rgba(255,255,255,.75);
}
.dice.roll { animation: dice-pop .7s ease; }
@keyframes dice-pop { 0% { transform: rotate(-8deg) scale(.9); } 35% { transform: rotate(8deg) scale(1.12); } 100% { transform: rotate(0) scale(1); } }
.move-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.move-buttons button { background: rgba(255,255,255,.12); color: var(--text); border: 1px solid rgba(255,255,255,.16); border-radius: 14px; padding: 10px 12px; font-weight: 750; }

.side-card { border-radius: 30px; padding: 14px; display: grid; gap: 12px; max-height: calc(100dvh - 190px); position: sticky; top: 10px; }
.status-box { border-radius: 20px; background: rgba(0,0,0,.20); border: 1px solid rgba(255,255,255,.12); padding: 12px; }
.status-box b { display: block; margin-bottom: 6px; }
.quick-emojis { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-emojis button { width: 44px; height: 42px; border-radius: 15px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.10); font-size: 22px; }
.chat { min-height: 180px; max-height: 250px; overflow: auto; display: grid; gap: 8px; padding-right: 4px; }
.chat-msg { background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.10); padding: 9px 10px; border-radius: 16px; }
.chat-msg .by { display: flex; gap: 6px; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.chat-msg.emoji { display: inline-flex; font-size: 30px; width: max-content; }
.chat-form { display: flex; gap: 8px; }
.events { max-height: 210px; overflow: auto; display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.event { padding: 8px 10px; border-radius: 13px; background: rgba(255,255,255,.07); }
.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: white; border: 1px solid rgba(255,255,255,.18); border-radius: 999px;
  box-shadow: 0 20px 45px rgba(0,0,0,.35); padding: 12px 18px; max-width: min(92vw, 620px); text-align: center;
}

@media (max-width: 980px) {
  .game-grid { grid-template-columns: 1fr; }
  .side-card { position: static; max-height: none; }
  .players-strip { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 640px) {
  .app-shell { padding-left: 8px; padding-right: 8px; }
  .topbar { align-items: stretch; flex-direction: column; border-radius: 22px; }
  .user-card { width: 100%; }
  .create-form, .chat-form { flex-direction: column; }
  .room-list { grid-template-columns: 1fr; }
  .game-header { flex-wrap: wrap; }
  .game-title { order: -1; flex-basis: 100%; }
  .players-strip { grid-template-columns: 1fr; }
  .board-card { padding: 6px; border-radius: 22px; }
  #board { border-radius: 18px; }
  .game-controls { position: static; margin-top: 8px; }
}

/* Mejoras móviles y tablero interactivo */
.control-text { min-width: 120px; }
.control-text b, .control-text p { display: block; }
.control-text p { font-size: 12px; }
.board-card { min-height: 0; }
.side-card { overflow: hidden; }
#board { cursor: pointer; }
body.playing-mode { overscroll-behavior: none; }

@media (max-width: 760px) {
  html, body { height: 100%; }
  body { overflow-x: hidden; }
  .app-shell {
    width: 100%;
    padding: max(6px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom));
  }
  .topbar {
    margin-bottom: 8px;
    padding: 8px 9px;
    border-radius: 18px;
    flex-direction: row;
    align-items: center;
  }
  .brand { gap: 8px; }
  .brand-dice { width: 42px; height: 42px; border-radius: 14px; font-size: 24px; }
  h1 { font-size: 21px; }
  .brand p { display: none; }
  .user-card { min-width: 0; padding: 6px; border-radius: 15px; width: auto; max-width: 48vw; }
  .avatar { width: 34px; height: 34px; font-size: 12px; }
  .user-card b { max-width: 120px; font-size: 13px; }
  .user-card span { display: none; }
  .panel { padding: 12px; border-radius: 20px; }
  .section-head { margin-bottom: 10px; align-items: center; }
  .section-head p { font-size: 13px; }
  .create-form { gap: 8px; }
  input { padding: 12px; border-radius: 14px; }
  .primary, .ghost, .icon-btn { min-height: 44px; border-radius: 14px; padding: 11px 13px; }
  .room-card { min-height: 132px; border-radius: 19px; padding: 14px; }

  .game-view { gap: 8px; }
  .game-header {
    position: sticky;
    top: max(4px, env(safe-area-inset-top));
    z-index: 20;
    padding: 8px;
    border-radius: 18px;
    gap: 7px;
  }
  .game-title h2 { font-size: 17px; }
  .game-title p { font-size: 12px; }
  .players-strip {
    padding: 6px;
    border-radius: 18px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
  }
  .player-chip {
    flex: 0 0 47%;
    scroll-snap-align: start;
    padding: 7px;
    border-radius: 15px;
  }
  .player-chip .avatar { width: 30px; height: 30px; }
  .player-chip b { font-size: 13px; }
  .player-chip span { font-size: 11px; }

  .game-grid { grid-template-columns: 1fr; gap: 8px; }
  .board-card {
    border-radius: 20px;
    padding: 5px;
    position: relative;
  }
  #board {
    width: 100%;
    height: auto;
    max-height: min(72dvh, calc(100dvh - 185px));
    border-radius: 16px;
  }
  .game-controls {
    position: static;
    margin-top: 6px;
    padding: 8px;
    gap: 7px;
    border-radius: 17px;
  }
  .dice { width: 52px; height: 52px; border-radius: 15px; font-size: 30px; }
  .control-text { flex: 1; min-width: 90px; }
  .control-text b { font-size: 13px; }
  .control-text p { font-size: 11px; }
  .move-buttons { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .move-buttons button { flex: 0 0 auto; min-height: 42px; padding: 9px 11px; }

  .side-card {
    border-radius: 20px;
    padding: 10px;
    gap: 9px;
    max-height: none;
    position: static;
  }
  .status-box { display: none; }
  .quick-emojis { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .quick-emojis button { flex: 0 0 42px; width: 42px; height: 40px; }
  .chat { min-height: 96px; max-height: 24dvh; }
  .events { max-height: 110px; font-size: 12px; }
  .chat-form { flex-direction: row; }
  .chat-form input { min-width: 0; }
  .chat-form .primary { flex: 0 0 auto; }
}

@media (max-width: 380px) {
  .game-header .ghost, .game-header .primary { padding-inline: 9px; font-size: 13px; }
  .player-chip { flex-basis: 72%; }
  .brand h1 { font-size: 18px; }
  .user-card b { max-width: 92px; }
}

/* v2.3 - UI móvil real: dado/HUD superpuestos al tablero para que no dependan solo del canvas */
.board-stage {
  position: relative;
  width: 100%;
  border-radius: 24px;
  overflow: hidden;
  isolation: isolate;
}
.board-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, transparent 30%, rgba(0,0,0,.10) 66%, rgba(0,0,0,.22)),
    linear-gradient(to bottom, rgba(255,255,255,.08), transparent 20%, transparent 80%, rgba(0,0,0,.14));
  z-index: 2;
}
.board-live-hud {
  position: absolute;
  z-index: 8;
  top: max(8px, 1.4vw);
  left: 50%;
  transform: translateX(-50%);
  width: min(78%, 560px);
  padding: 9px 13px;
  border-radius: 999px;
  text-align: center;
  background: rgba(15,23,42,.78);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 12px 34px rgba(0,0,0,.28);
  backdrop-filter: blur(12px);
  pointer-events: none;
}
.board-live-hud .hud-turn {
  font-weight: 950;
  color: #fff;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(12px, 2.6vw, 18px);
}
.board-live-hud .hud-sub {
  color: rgba(255,255,255,.72);
  font-weight: 700;
  font-size: clamp(10px, 2.1vw, 13px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-dice-overlay {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 50%;
  width: clamp(78px, 19vw, 138px);
  height: clamp(78px, 19vw, 138px);
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  gap: 0;
  padding: 6px;
  border: 0;
  border-radius: 28%;
  color: #111827;
  background: linear-gradient(145deg, #ffffff, #f3f4f6 60%, #d1d5db);
  box-shadow:
    0 20px 46px rgba(0,0,0,.36),
    inset 0 4px 0 rgba(255,255,255,.9),
    inset 0 -5px 12px rgba(17,24,39,.12);
  outline: 4px solid rgba(255,255,255,.24);
  transition: transform .15s ease, filter .15s ease, opacity .15s ease;
  touch-action: manipulation;
}
.board-dice-overlay .dice-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  filter: drop-shadow(0 2px 0 rgba(255,255,255,.8));
}
.board-dice-overlay .dice-placeholder {
  display: grid;
  place-items: center;
  font-size: clamp(34px, 8vw, 68px);
  line-height: 1;
}
.board-dice-overlay .dice-number {
  display: grid;
  place-items: center;
  width: 72%;
  height: 72%;
  margin: auto;
  border-radius: 22%;
  font-size: clamp(42px, 10vw, 86px);
  font-weight: 1000;
  line-height: 1;
  color: #111827;
  background: radial-gradient(circle at 35% 25%, rgba(255,255,255,.88), rgba(255,255,255,0) 38%), rgba(255,255,255,.28);
  box-shadow: inset 0 0 0 2px rgba(17,24,39,.10);
}
.board-dice-overlay small {
  display: block;
  margin-top: -2px;
  font-size: clamp(10px, 2.2vw, 14px);
  font-weight: 950;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.board-dice-overlay.can-roll {
  animation: dicePulse 1s infinite ease-in-out;
  outline-color: rgba(250,204,21,.82);
}
.board-dice-overlay.rolling {
  animation: diceShake .52s ease-in-out infinite;
}
.board-dice-overlay:disabled {
  opacity: .76;
  filter: saturate(.7);
  cursor: default;
}
.board-dice-overlay:not(:disabled):active {
  transform: translate(-50%, -50%) scale(.95) rotate(-3deg);
}
@keyframes dicePulse {
  0%, 100% { box-shadow: 0 20px 46px rgba(0,0,0,.36), 0 0 0 0 rgba(250,204,21,.45), inset 0 4px 0 rgba(255,255,255,.9), inset 0 -5px 12px rgba(17,24,39,.12); }
  50% { box-shadow: 0 20px 46px rgba(0,0,0,.36), 0 0 0 12px rgba(250,204,21,0), inset 0 4px 0 rgba(255,255,255,.9), inset 0 -5px 12px rgba(17,24,39,.12); }
}
@keyframes diceShake {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
  25% { transform: translate(-50%, -50%) rotate(-8deg) scale(1.04); }
  50% { transform: translate(-50%, -50%) rotate(7deg) scale(1.01); }
  75% { transform: translate(-50%, -50%) rotate(-4deg) scale(1.04); }
}
.board-player-cards {
  position: absolute;
  z-index: 7;
  inset: 8px;
  pointer-events: none;
}
.board-player-mini {
  position: absolute;
  min-width: 0;
  width: clamp(72px, 16vw, 110px);
  display: grid;
  grid-template-columns: 12px 1fr;
  grid-template-areas: "dot name" "dot meta";
  align-items: center;
  column-gap: 6px;
  row-gap: 1px;
  padding: 5px 7px;
  border-radius: 14px;
  background: rgba(15,23,42,.68);
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  backdrop-filter: blur(8px);
}
.board-player-mini.player-pos-0 { left: 0; top: 44px; }
.board-player-mini.player-pos-1 { right: 0; top: 44px; }
.board-player-mini.player-pos-2 { right: 0; bottom: 0; }
.board-player-mini.player-pos-3 { left: 0; bottom: 0; }
.board-player-mini.active {
  background: rgba(250,204,21,.88);
  color: #2a1700;
  transform: scale(1.04);
  box-shadow: 0 0 0 2px rgba(255,255,255,.35), 0 10px 28px rgba(0,0,0,.22);
}
.board-player-mini .mini-dot {
  grid-area: dot;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255,255,255,.22);
}
.board-player-mini b {
  grid-area: name;
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(12px, 2.4vw, 15px);
  line-height: 1;
}
.board-player-mini span {
  grid-area: meta;
  display: block;
  color: inherit;
  opacity: .76;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}
.board-bubbles {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: clamp(76px, 16vw, 118px);
  transform: translateX(-50%);
  width: min(74%, 520px);
  display: grid;
  gap: 5px;
  pointer-events: none;
}
.board-bubble {
  justify-self: center;
  max-width: 100%;
  padding: 7px 11px;
  border-radius: 999px;
  color: #fff;
  font-weight: 850;
  font-size: clamp(11px, 2.35vw, 14px);
  background: rgba(15,23,42,.74);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 10px 28px rgba(0,0,0,.26);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: bubbleIn .22s ease-out both;
}
.board-bubble.emoji {
  font-size: clamp(22px, 6vw, 38px);
  padding: 5px 12px;
  background: rgba(15,23,42,.62);
}
@keyframes bubbleIn { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Controles duplicados debajo: siguen existiendo, pero más compactos para móvil. */
.game-controls .dice { display: none; }
.game-controls {
  z-index: 12;
}

@media (max-width: 760px) {
  html, body { min-height: 100dvh; }
  .app-shell {
    padding: max(6px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom));
  }
  .topbar {
    padding: 8px;
    border-radius: 18px;
    margin-bottom: 8px;
  }
  body.playing-mode .topbar { display: none; }
  body.playing-mode .app-shell { padding-top: max(4px, env(safe-area-inset-top)); }
  .brand-dice { width: 42px; height: 42px; font-size: 24px; border-radius: 14px; }
  .brand p { display: none; }
  .user-card { min-width: 0; padding: 6px 8px; }
  .user-card .avatar { width: 34px; height: 34px; }
  .user-card b, .user-card span { max-width: 120px; }
  .panel { padding: 12px; border-radius: 20px; }
  .room-list { grid-template-columns: 1fr; }
  .game-header { box-shadow: 0 12px 35px rgba(0,0,0,.28); }
  .game-header .ghost { padding-inline: 10px; }
  .game-header .primary { padding-inline: 11px; }
  .players-strip { display: none; }
  .board-card { padding: 4px; border-radius: 18px; }
  .board-stage { border-radius: 16px; }
  #board { border-radius: 16px; max-height: none; }
  .board-live-hud {
    top: 7px;
    width: calc(100% - 18px);
    padding: 7px 10px;
  }
  .board-player-cards { inset: 6px; }
  .board-player-mini {
    width: clamp(56px, 18vw, 78px);
    padding: 4px 5px;
    border-radius: 12px;
    grid-template-columns: 9px 1fr;
    column-gap: 4px;
  }
  .board-player-mini.player-pos-0 { left: 0; top: 38px; }
  .board-player-mini.player-pos-1 { right: 0; top: 38px; }
  .board-player-mini .mini-dot { width: 9px; height: 9px; box-shadow: 0 0 0 2px rgba(255,255,255,.20); }
  .board-player-mini b { font-size: 11px; }
  .board-player-mini span { font-size: 8px; }
  .board-bubbles { bottom: clamp(61px, 14vw, 88px); width: calc(100% - 58px); }
  .side-card {
    max-height: none;
    border-radius: 18px;
    padding: 8px;
  }
  .status-box, .events { display: none; }
  .quick-emojis {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
  }
  .quick-emojis button {
    flex: 0 0 42px;
    height: 42px;
  }
  .chat {
    max-height: 118px;
    min-height: 80px;
  }
  .chat-form {
    gap: 6px;
  }
  .chat-form input { padding: 10px 12px; }
  .chat-form button { padding-inline: 12px; }
}

@media (max-width: 380px) {
  .board-dice-overlay { width: 76px; height: 76px; }
  .board-player-mini { width: 54px; }
  .board-player-mini span { display: none; }
  .board-bubbles { bottom: 58px; }
}

/* v2.4 — rediseño móvil tipo app de parchís Android */
:root { --board-shadow: 0 24px 60px rgba(0,0,0,.35); }
.board-card {
  padding: 8px;
  background:
    radial-gradient(circle at 50% 45%, rgba(250,204,21,.18), transparent 34%),
    rgba(255,255,255,.10);
}
.board-stage {
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: var(--board-shadow);
  background: #d8a95e;
}
#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.24), inset 0 18px 45px rgba(0,0,0,.16);
}
.chat-toggle {
  display: none;
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255,255,255,.10);
  font-weight: 950;
}
.chat-toggle span {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 99px;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
}
.events-details {
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.16);
  overflow: hidden;
}
.events-details summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 900;
  color: rgba(255,255,255,.78);
}
.events-details summary::-webkit-details-marker { display: none; }
.events-details .events { padding: 0 10px 10px; }
.game-controls .dice .dice-number {
  display: grid;
  place-items: center;
  width: 74%;
  height: 74%;
  border-radius: 22%;
  font-size: 34px;
  font-weight: 1000;
}
.game-controls .dice .dice-placeholder { font-size: 32px; line-height: 1; }

@media (min-width: 981px) {
  .game-grid { grid-template-columns: minmax(560px, 1fr) 360px; }
  .board-card { max-width: min(78vh, 900px); justify-self: center; width: 100%; }
}

@media (max-width: 760px) {
  body.playing-mode {
    background: radial-gradient(circle at top, #233557 0, #0b1020 48%, #060914 100%);
    height: 100dvh;
    overflow: hidden;
  }
  body.playing-mode .layout,
  body.playing-mode #game-view {
    height: 100%;
    min-height: 0;
  }
  body.playing-mode .game-view {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 6px;
  }
  .game-header {
    min-height: 42px;
    padding: 6px;
    border-radius: 16px;
    gap: 6px;
  }
  .game-title h2 { font-size: 15px; }
  .game-title p { font-size: 11px; }
  .game-header .ghost,
  .game-header .primary {
    min-height: 36px;
    padding: 8px 9px;
    border-radius: 12px;
    font-size: 13px;
  }
  .game-grid {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 6px;
  }
  .board-card {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    align-content: start;
    padding: 3px;
    border-radius: 18px;
  }
  .board-stage {
    width: min(100%, calc(100dvh - 214px));
    max-width: 100%;
    justify-self: center;
    align-self: start;
    border-radius: 18px;
  }
  #board {
    border-radius: 18px;
    max-height: calc(100dvh - 214px);
  }
  .board-live-hud {
    top: 6px;
    left: 50%;
    width: calc(100% - 96px);
    padding: 6px 8px;
    border-radius: 14px;
  }
  .board-live-hud .hud-turn { font-size: clamp(11px, 3.2vw, 14px); }
  .board-live-hud .hud-sub { font-size: clamp(9px, 2.7vw, 11px); }
  .board-dice-overlay {
    width: clamp(68px, 18vw, 88px);
    height: clamp(68px, 18vw, 88px);
    border-radius: 22%;
    outline-width: 3px;
  }
  .board-dice-overlay .dice-number { font-size: clamp(40px, 12vw, 58px); }
  .board-dice-overlay .dice-placeholder { font-size: clamp(30px, 9vw, 42px); }
  .board-dice-overlay small { font-size: 10px; }
  .board-player-cards { inset: 4px; }
  .board-player-mini {
    width: 46px;
    height: 46px;
    min-width: 46px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas: "name";
    place-items: center;
    padding: 0;
    border-radius: 50%;
    background: rgba(15,23,42,.62);
    border: 2px solid rgba(255,255,255,.30);
  }
  .board-player-mini.player-pos-0 { left: 6px; top: 46px; }
  .board-player-mini.player-pos-1 { right: 6px; top: 46px; }
  .board-player-mini.player-pos-2 { right: 6px; bottom: 6px; }
  .board-player-mini.player-pos-3 { left: 6px; bottom: 6px; }
  .board-player-mini .mini-dot {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 100%; height: 100%;
    border-radius: 50%;
    opacity: .92;
    box-shadow: inset 0 3px 10px rgba(255,255,255,.25), 0 6px 18px rgba(0,0,0,.25);
  }
  .board-player-mini b {
    position: relative;
    z-index: 2;
    font-size: 13px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,.55);
  }
  .board-player-mini span { display: none; }
  .board-player-mini.active {
    transform: scale(1.09);
    box-shadow: 0 0 0 3px rgba(250,204,21,.75), 0 12px 30px rgba(0,0,0,.30);
  }
  .board-bubbles {
    bottom: 58px;
    width: calc(100% - 92px);
  }

  .game-controls {
    position: static;
    margin-top: 5px;
    padding: 6px;
    min-height: 44px;
    border-radius: 15px;
    gap: 6px;
    background: rgba(8,13,28,.78);
  }
  .game-controls .control-text {
    min-width: 0;
    flex: 1 1 115px;
  }
  .game-controls .control-text b { font-size: 13px; }
  .game-controls .control-text p { font-size: 11px; }
  .game-controls #roll-btn {
    min-height: 38px;
    padding: 8px 12px;
  }
  .move-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .move-buttons:empty { display: none; }
  .move-buttons button {
    min-height: 36px;
    padding: 8px 6px;
    font-size: 12px;
    border-radius: 12px;
  }

  .side-card {
    position: static;
    display: grid;
    grid-template-rows: auto auto auto;
    gap: 6px;
    padding: 7px;
    border-radius: 18px 18px 0 0;
    max-height: 182px;
    overflow: hidden;
    box-shadow: 0 -14px 38px rgba(0,0,0,.28);
  }
  .chat-toggle { display: block; }
  .status-box { display: none !important; }
  .quick-emojis {
    order: 2;
    display: flex !important;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 1px;
    scrollbar-width: none;
  }
  .quick-emojis::-webkit-scrollbar { display: none; }
  .quick-emojis button {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 13px;
    font-size: 20px;
  }
  .chat-form {
    order: 3;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
  }
  .chat-form input { padding: 10px 12px; border-radius: 14px; }
  .chat-form button { min-height: 40px; padding: 8px 12px; border-radius: 14px; }
  .chat {
    order: 4;
    min-height: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    transition: max-height .18s ease, opacity .18s ease;
  }
  .side-card.chat-open {
    max-height: 320px;
  }
  .side-card.chat-open .chat {
    max-height: 142px;
    min-height: 88px;
    opacity: 1;
    overflow: auto;
  }
  .events-details {
    display: none;
    order: 5;
  }
  .side-card.chat-open .events-details {
    display: block;
  }
  .side-card.chat-open .events-details:not([open]) .events { display: none; }
}

@media (max-width: 390px) {
  .board-stage { width: min(100%, calc(100dvh - 200px)); }
  #board { max-height: calc(100dvh - 200px); }
  .board-player-mini { width: 40px; height: 40px; min-width: 40px; }
  .board-live-hud { width: calc(100% - 84px); }
  .side-card { max-height: 170px; }
}

/* v2.5 — móvil limpio: tablero sin globos encima, header compacto y chat útil */
.emoji-menu-btn {
  border: 1px solid rgba(255,255,255,.16);
  color: var(--text);
  background: rgba(255,255,255,.10);
  border-radius: 15px;
  min-width: 48px;
  min-height: 44px;
  padding: 0;
  font-size: 22px;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
}
.send-btn { white-space: nowrap; }
.chat-dock { position: relative; }
.emoji-popover {
  position: absolute;
  z-index: 40;
  right: 10px;
  bottom: calc(100% + 10px);
  width: min(320px, calc(100vw - 30px));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  border-radius: 22px;
  background: rgba(15,23,42,.96);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 24px 60px rgba(0,0,0,.42);
  backdrop-filter: blur(16px);
}
.emoji-popover button {
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  background: rgba(255,255,255,.10);
}
.game-controls.empty-controls { display: none; }

@media (max-width: 760px) {
  body.playing-mode {
    height: 100dvh;
    overflow: hidden;
  }
  body.playing-mode .app-shell {
    height: 100dvh;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    padding: max(3px, env(safe-area-inset-top)) 5px max(4px, env(safe-area-inset-bottom));
  }
  body.playing-mode .layout,
  body.playing-mode #game-view,
  body.playing-mode .game-view {
    height: 100%;
    min-height: 0;
  }
  body.playing-mode .game-view {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 5px;
  }

  /* Header de partida: una sola línea, sin tarjeta gigante. */
  .game-header {
    position: static;
    min-height: 38px;
    padding: 4px 5px;
    border-radius: 13px;
    gap: 5px;
    box-shadow: 0 8px 22px rgba(0,0,0,.22);
    background: rgba(15,23,42,.82);
  }
  .game-header .ghost {
    width: 36px;
    min-width: 36px;
    min-height: 34px;
    padding: 0;
    border-radius: 11px;
    font-size: 0;
  }
  .game-header .ghost::before {
    content: '←';
    font-size: 20px;
    line-height: 1;
  }
  .game-header .primary {
    min-height: 34px;
    padding: 7px 9px;
    border-radius: 11px;
    font-size: 12px;
  }
  .game-title h2 {
    font-size: 14px;
    letter-spacing: -.02em;
  }
  .game-title p {
    font-size: 10px;
    line-height: 1.05;
  }

  .game-grid {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 5px;
  }
  .board-card {
    min-height: 0;
    padding: 2px;
    border-radius: 15px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: visible;
  }
  .board-stage {
    width: min(100%, calc(100dvh - 150px));
    justify-self: center;
    align-self: start;
    border-radius: 15px;
  }
  #board {
    border-radius: 15px;
    max-height: calc(100dvh - 150px);
  }

  /* En móvil dejamos el tablero limpio: solo dado central y fichas. */
  .board-live-hud,
  .board-player-cards,
  .board-bubbles {
    display: none !important;
  }
  .board-stage::before {
    background:
      radial-gradient(circle at 50% 50%, transparent 45%, rgba(0,0,0,.12)),
      linear-gradient(to bottom, rgba(255,255,255,.08), transparent 24%, transparent 80%, rgba(0,0,0,.12));
  }
  .board-dice-overlay {
    width: clamp(56px, 14.5vw, 74px);
    height: clamp(56px, 14.5vw, 74px);
    padding: 4px;
    border-radius: 20%;
    outline-width: 2px;
    box-shadow:
      0 12px 28px rgba(0,0,0,.32),
      inset 0 3px 0 rgba(255,255,255,.85),
      inset 0 -4px 9px rgba(17,24,39,.12);
  }
  .board-dice-overlay small { display: none; }
  .board-dice-overlay .dice-number {
    width: 78%;
    height: 78%;
    font-size: clamp(34px, 9vw, 50px);
  }
  .board-dice-overlay .dice-placeholder {
    font-size: clamp(26px, 7vw, 36px);
  }

  /* El control inferior solo aparece cuando hay que elegir ficha. No duplica el dado. */
  .game-controls {
    position: static;
    margin-top: 3px;
    padding: 5px;
    min-height: 0;
    border-radius: 13px;
    background: rgba(8,13,28,.78);
    border-color: rgba(255,255,255,.12);
  }
  .game-controls.empty-controls { display: none !important; }
  .move-hint { display: none; }
  .move-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    overflow: visible;
    padding: 0;
  }
  .move-buttons button {
    min-height: 34px;
    padding: 6px 4px;
    border-radius: 11px;
    font-size: 11px;
  }

  /* Chat fijo y pequeño: visible sin scroll largo. */
  .side-card.chat-dock {
    position: relative;
    display: grid;
    grid-template-rows: minmax(34px, 60px) auto;
    gap: 5px;
    padding: 6px;
    border-radius: 14px;
    max-height: none;
    overflow: visible;
    box-shadow: 0 -10px 28px rgba(0,0,0,.25);
    background: rgba(15,23,42,.88);
  }
  .side-card .status-box,
  .side-card .events-details,
  .chat-toggle {
    display: none !important;
  }
  .chat {
    order: 1;
    min-height: 34px !important;
    max-height: 60px !important;
    opacity: 1 !important;
    overflow: auto !important;
    padding: 0 2px 0 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: none;
  }
  .chat::-webkit-scrollbar { display: none; }
  .chat:empty::before {
    content: 'Chat de la partida';
    color: rgba(255,255,255,.46);
    font-weight: 800;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(0,0,0,.15);
  }
  .chat-msg {
    padding: 6px 8px;
    border-radius: 12px;
    font-size: 12px;
    line-height: 1.15;
  }
  .chat-msg .by {
    margin-bottom: 2px;
    font-size: 10px;
  }
  .chat-msg.emoji {
    font-size: 23px;
    padding: 3px 8px;
  }
  .chat-form {
    order: 2;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 5px;
    align-items: center;
  }
  .emoji-menu-btn {
    min-width: 38px;
    min-height: 38px;
    border-radius: 12px;
    font-size: 20px;
  }
  .chat-form input {
    min-width: 0;
    height: 38px;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 14px;
  }
  .chat-form .send-btn {
    min-height: 38px;
    padding: 7px 11px;
    border-radius: 12px;
    font-size: 13px;
  }
  .quick-emojis.emoji-popover {
    order: 3;
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    right: 6px;
    bottom: calc(100% + 6px);
    width: min(260px, calc(100vw - 18px));
    padding: 8px;
    border-radius: 18px;
    overflow: visible;
  }
  .quick-emojis.emoji-popover.hidden { display: none !important; }
  .quick-emojis.emoji-popover button {
    width: 100%;
    height: 42px;
    min-height: 42px;
    flex: initial;
    font-size: 22px;
    border-radius: 13px;
  }
}

@media (max-width: 390px) {
  .board-stage { width: min(100%, calc(100dvh - 142px)); }
  #board { max-height: calc(100dvh - 142px); }
  .side-card.chat-dock { grid-template-rows: minmax(30px, 50px) auto; }
  .chat { max-height: 50px !important; }
  .chat-form .send-btn { padding-inline: 9px; }
}
