* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #e23b2e;
  --red-dark: #a31f14;
  --blue: #2f7de1;
  --blue-dark: #1a4f9c;
  --gold: #ffd24a;
  --gold-deep: #f5a623;
  --gold-edge: #c47d0e;
  --ink: #10314d;
  --ink-soft: #2a5d88;
  --ink-faint: #4a7ba3;
  --paper: #eaf6ff;
  --paper-2: #cfe8fa;
  --line: #7fb8e0;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --shadow-1: 0 2px 8px rgba(4, 26, 45, .25);
  --shadow-2: 0 8px 24px rgba(4, 26, 45, .35);
  --shadow-3: 0 16px 48px rgba(4, 26, 45, .45);
  /* el tablero crece con la ventana (alto Y ancho) hasta 54px por casilla:
     el alto descuenta publicidad y márgenes; el ancho, la columna lateral */
  --tile-size: clamp(26px, min(calc((100dvh - 266px) / 16), calc((100vw - 310px) / 16)), 54px);
}

body {
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255,255,255,.10), transparent 55%),
    linear-gradient(160deg, #0b3457 0%, #17629b 48%, #0a2e4e 100%);
  background-attachment: fixed;
  /* dvh: en iOS el body no debe medir más que la pantalla visible, o el
     fondo asoma como un hueco azul scrolleable bajo la portada */
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.column { flex-direction: column; gap: 16px; }
.hidden { display: none !important; }

/* huecos publicitarios: el <ins> de AdSense rellena el contenedor; mientras
   no haya anuncio se ve un hueco discreto con la etiqueta de ::before */
.ad-slot {
  position: relative;
  width: min(728px, 94vw);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(255,255,255,.18);
  border-radius: var(--radius-s);
  background: rgba(255,255,255,.04);
}
.ad-slot::before {
  content: 'Publicidad';
  position: absolute;
  color: rgba(255,255,255,.30);
  font-size: 10px;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.ad-slot ins { width: 100%; position: relative; z-index: 1; }
/* con anuncio servido, fuera el marco y la etiqueta del hueco */
.ad-slot:has(ins[data-ad-status="filled"]) { border-color: transparent; background: none; }
.ad-slot:has(ins[data-ad-status="filled"])::before { display: none; }

/* rascacielos junto al tablero: solo aparece en pantallas muy anchas */
.ad-rail { display: none; }
.ad-slot--tall { width: 300px; min-height: 600px; }

.credits { margin-top: 12px; font-size: 10px; color: #6d94b5; }
.credits a { color: #8db8d9; }

/* ===== Menú ===== */

/* menú y espera: la mesa del capitán con la carta del duelo de fondo,
   bajo un velo oscuro para que la caja y el banner destaquen */
#menu-screen, #wait-screen {
  background-image:
    linear-gradient(180deg, rgba(6, 26, 44, .50) 0%, rgba(6, 26, 44, .30) 40%, rgba(6, 26, 44, .55) 100%),
    image-set(url("assets/menu-bg-1536.webp") type("image/webp"),
              url("assets/menu-bg-1536.jpg") type("image/jpeg"));
  background-size: cover;
  background-position: center;
}
@media (max-width: 768px) {
  #menu-screen, #wait-screen {
    background-image:
      linear-gradient(180deg, rgba(6, 26, 44, .50) 0%, rgba(6, 26, 44, .30) 40%, rgba(6, 26, 44, .55) 100%),
      image-set(url("assets/menu-bg-768.webp") type("image/webp"),
                url("assets/menu-bg-768.jpg") type("image/jpeg"));
  }
}

/* el banner queda clavado arriba (con el padding de la pantalla como margen)
   y la caja se centra en el hueco que queda debajo */
#menu-screen .menu-box, #wait-screen .menu-box { margin-top: auto; margin-bottom: auto; }

/* los dos marineros asoman tras la caja del menú, como piezas del juego;
   el margen bajo el banner reserva su hueco para que nunca lo pisen */
#menu-screen .menu-box { position: relative; }
#menu-screen .ad-slot { margin-bottom: 40px; }
#menu-screen .menu-box::before,
#menu-screen .menu-box::after {
  content: '';
  position: absolute;
  top: -44px;
  width: 62px;
  height: 62px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom;
  filter: drop-shadow(0 4px 6px rgba(4, 20, 36, .55));
  pointer-events: none;
}
#menu-screen .menu-box::before {
  left: 6px;
  background-image: url("assets/avatar-red.png");
  transform: rotate(-7deg);
}
#menu-screen .menu-box::after {
  right: 6px;
  background-image: url("assets/avatar-blue.png");
  transform: rotate(7deg) scaleX(-1);
}

.menu-box {
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 1px solid rgba(255,255,255,.55);
  outline: 2px solid rgba(127,184,224,.55);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-3), inset 0 1px 0 rgba(255,255,255,.8);
  padding: 28px 32px;
  width: min(440px, 94vw);
  text-align: center;
  animation: overlay-in .35s cubic-bezier(.2, 1.4, .4, 1);
}
.menu-box h1 { color: #114d7c; margin-bottom: 4px; font-size: 26px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.logo-flag { width: 34px; height: 34px; }
.logo-flag.flip { transform: scaleX(-1); }
.subtitle { color: var(--ink-faint); font-size: 13px; margin-bottom: 18px; }

.menu-section { margin-bottom: 14px; text-align: left; }
.menu-section label { font-size: 12px; font-weight: bold; color: var(--ink-soft); display: block; margin-bottom: 4px; }

input[type=text] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #a9cfe9;
  border-radius: var(--radius-s);
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47,125,225,.18);
}

.menu-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 3px 0 var(--gold-edge), 0 6px 12px rgba(4,26,45,.25);
  color: #5b3a00;
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: transform .06s, filter .15s, box-shadow .06s;
}
.menu-btn:hover { filter: brightness(1.07); }
.menu-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 1px 0 var(--gold-edge), 0 3px 8px rgba(4,26,45,.25);
}
.menu-btn:focus-visible { outline: 3px solid rgba(47,125,225,.6); outline-offset: 2px; }
.menu-btn.small { font-size: 13px; padding: 9px 12px; width: auto; display: inline-block; }
.menu-btn.danger {
  background: linear-gradient(180deg, #f4796b, #d8402f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 3px 0 #9a2417, 0 6px 12px rgba(4,26,45,.25);
  color: #fff;
}
.menu-btn.danger:active { box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 1px 0 #9a2417, 0 3px 8px rgba(4,26,45,.25); }
.menu-btn:disabled { filter: grayscale(.7); cursor: not-allowed; }

.join-row { display: flex; gap: 8px; margin-top: 4px; align-items: stretch; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; font-weight: bold; text-align: center; flex: 1; }
.join-row .menu-btn { margin: 0; flex-shrink: 0; }

.status-msg { min-height: 18px; margin-top: 10px; font-size: 13px; color: #b03020; font-weight: bold; }

.rules { text-align: left; margin-top: 18px; background: rgba(255,255,255,.55); border: 1px solid rgba(127,184,224,.35); border-radius: var(--radius-m); padding: 12px 14px; }
.rules h3 { font-size: 13px; color: #114d7c; margin-bottom: 6px; }
.rules ul { padding-left: 18px; }
.rules li { font-size: 12px; color: #29506f; margin: 3px 0; }

/* modo invitación (enlace con #CÓDIGO) */
.invite-text { color: var(--ink-soft); font-size: 14px; font-weight: bold; margin-bottom: 6px; }
.invite-code {
  font-size: 26px;
  letter-spacing: 7px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  color: #114d7c;
  background: #fff;
  border: 2px dashed var(--line);
  border-radius: var(--radius-m);
  padding: 7px;
  margin-bottom: 14px;
}
.linklike {
  background: none;
  border: none;
  color: var(--ink-faint);
  text-decoration: underline;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
}

.room-code {
  font-size: 40px;
  letter-spacing: 10px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  color: #114d7c;
  background: #fff;
  border: 2px dashed var(--line);
  border-radius: var(--radius-m);
  padding: 12px;
  margin: 14px 0;
  user-select: all;
}

/* ===== Layout de juego =====
   Rejilla: columna lateral a la izquierda y, a la derecha, el tablero con
   su banner justo debajo (mismo ancho); el chat estira hasta esa altura */
.game-layout {
  display: grid;
  grid-template-columns: auto auto;
  /* la 2ª fila absorbe el alto sobrante para que el banner quede pegado
     al tablero (a la derecha del chat) aunque la columna lateral sea más alta */
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar board"
    "sidebar ad";
  gap: 16px;
  align-items: stretch;
}

.sidebar {
  grid-area: sidebar;
  width: 188px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.board-wrap { grid-area: board; }

.game-layout .ad-slot--game-bottom {
  grid-area: ad;
  align-self: start;
  width: auto;
  min-height: 90px;
}

.ad-rail { grid-area: rail; }

.player-panel {
  border-radius: var(--radius-m);
  padding: 10px;
  text-align: center;
  color: #fff;
  box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255,255,255,.25);
  border: 1px solid rgba(255,255,255,.3);
  opacity: .55;
  transform: scale(.98);
  transition: opacity .25s, box-shadow .25s, transform .25s;
}
.player-panel.red  { background: linear-gradient(180deg, var(--red), var(--red-dark)); }
.player-panel.blue { background: linear-gradient(180deg, var(--blue), var(--blue-dark)); }
.player-panel.active {
  opacity: 1;
  transform: scale(1);
  box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(255,210,74,.35), var(--shadow-2);
}

.panel-title { font-weight: bold; font-size: 13px; letter-spacing: 3px; text-shadow: 0 1px 2px rgba(0,0,0,.4); opacity: .9; }
.avatar { margin: 4px 0; }
.avatar img { width: 56px; height: 56px; object-fit: contain; filter: drop-shadow(0 3px 5px rgba(0,0,0,.35)); }
.pname { font-size: 13px; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pmsg { font-size: 11px; min-height: 15px; opacity: .9; font-style: italic; }

.counters { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 6px; }
.flag-counter {
  position: relative;
  background: rgba(255,255,255,.95);
  color: var(--ink);
  border-radius: var(--radius-s);
  padding: 4px 10px;
  font-size: 15px;
  box-shadow: inset 0 -2px 0 rgba(4,26,45,.12);
}
.flag-counter b {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
.flag-ico-img { width: 18px; height: 18px; vertical-align: -3px; }

/* marcador: bote al cambiar + chip flotante «+n» */
.bump { animation: bump .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes bump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.55); }
  100% { transform: scale(1); }
}
.score-pop {
  position: absolute;
  left: 50%;
  top: -4px;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  background: var(--gold-deep);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 999px;
  padding: 1px 7px;
  pointer-events: none;
  animation: score-pop 1s ease-out forwards;
  z-index: 6;
}
@keyframes score-pop {
  0%   { opacity: 0; transform: translate(-50%, 4px) scale(.6); }
  20%  { opacity: 1; transform: translate(-50%, -10px) scale(1.1); }
  75%  { opacity: 1; transform: translate(-50%, -22px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(.9); }
}

.bomb-btn {
  font-size: 17px;
  padding: 3px 9px;
  border-radius: var(--radius-s);
  border: 2px solid rgba(0,0,0,.25);
  background: #f7f7f7;
  cursor: pointer;
  transition: transform .1s;
}
.bomb-btn:hover:not(:disabled) { transform: scale(1.12); }
.bomb-btn:disabled { opacity: .35; cursor: not-allowed; }
.bomb-btn.armed { background: var(--gold); box-shadow: 0 0 10px var(--gold); animation: pulse .7s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }

.side-actions { display: flex; gap: 8px; justify-content: center; }
.side-actions .danger { flex: 1; }

.mid-info { text-align: center; display: flex; gap: 10px; justify-content: center; align-items: center; }

/* contador central de minas restantes, como el del original */
.mines-left { display: flex; align-items: center; gap: 5px; }
.mines-left .star {
  color: #b9c6d1;
  font-size: 17px;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.mines-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #4a5058, #17191c 75%);
  border: 2px solid #e6edf3;
  box-shadow: var(--shadow-1), inset 0 2px 4px rgba(255,255,255,.15);
  color: #fff;
  font-size: 17px;
}
.mines-circle b { font-variant-numeric: tabular-nums; display: inline-block; }

/* píldora del turno con barra de progreso (JS fija --frac de 1 a 0) */
.turn-timer {
  position: relative;
  display: inline-block;
  background: rgba(255,255,255,.9);
  border-radius: var(--radius-s);
  padding: 4px 10px 6px;
  font-size: 12px;
  color: #114d7c;
  overflow: hidden;
  box-shadow: inset 0 -2px 0 rgba(4,26,45,.1);
}
.turn-timer b { font-variant-numeric: tabular-nums; }
.turn-timer::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: calc(var(--frac, 1) * 100%);
  background: linear-gradient(90deg, var(--blue), var(--gold-deep));
  transition: width .25s linear;
}
.turn-timer.low { animation: timer-low .6s infinite alternate; }
.turn-timer.low b { color: #d81f1f; }
.turn-timer.low::after { background: #d81f1f; }
@keyframes timer-low {
  from { box-shadow: inset 0 -2px 0 rgba(4,26,45,.1); }
  to   { box-shadow: inset 0 -2px 0 rgba(4,26,45,.1), 0 0 10px rgba(216,31,31,.6); }
}

/* ===== Tablero ===== */
.board-wrap { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(16, var(--tile-size));
  grid-auto-rows: var(--tile-size);
  gap: 2px;
  background: linear-gradient(180deg, #0c3a60, #092c4a);
  padding: 8px;
  border-radius: var(--radius-m);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: var(--shadow-3), inset 0 1px 0 rgba(255,255,255,.08);
}

.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 4px;
  user-select: none;
  cursor: pointer;
  /* sprites del cliente MIT de Zomis (minesweeper-flags-client) */
  background-image: url("assets/tiles/classic_unknown.png");
  background-size: 100% 100%;
  transition: filter .08s, transform .08s;
}
.cell:not(.revealed):not(.mine-red):not(.mine-blue):hover { filter: brightness(1.12); }
.cell:not(.revealed):not(.mine-red):not(.mine-blue):active { transform: scale(.92); }
.cell.bomb-target { outline: 3px solid var(--gold); outline-offset: -3px; }

.cell.revealed, .cell.mine-red, .cell.mine-blue { cursor: default; }
.cell.revealed.n0 { background-image: url("assets/tiles/classic_0.png"); }
.cell.revealed.n1 { background-image: url("assets/tiles/classic_1.png"); }
.cell.revealed.n2 { background-image: url("assets/tiles/classic_2.png"); }
.cell.revealed.n3 { background-image: url("assets/tiles/classic_3.png"); }
.cell.revealed.n4 { background-image: url("assets/tiles/classic_4.png"); }
.cell.revealed.n5 { background-image: url("assets/tiles/classic_5.png"); }
.cell.revealed.n6 { background-image: url("assets/tiles/classic_6.png"); }
.cell.revealed.n7 { background-image: url("assets/tiles/classic_7.png"); }
.cell.revealed.n8 { background-image: url("assets/tiles/classic_8.png"); }
.cell.mine-red  { background-image: url("assets/tiles/classic_m2.png"); }
.cell.mine-blue { background-image: url("assets/tiles/classic_m1.png"); }

.cell.last-move { box-shadow: inset 0 0 0 3px rgba(255,255,255,.9); }

/* jugada del rival: anillo dorado pulsante para localizarla de un vistazo */
.cell.opp-move {
  z-index: 3;
  animation: opp-ping 1.2s ease-out 2;
}
@keyframes opp-ping {
  0%   { box-shadow: 0 0 0 0 rgba(255,210,74,.85), inset 0 0 0 3px var(--gold); }
  100% { box-shadow: 0 0 0 20px rgba(255,210,74,0), inset 0 0 0 3px var(--gold); }
}

/* minimapa flotante: solo tiene sentido cuando el tablero se desplaza (móvil) */
.minimap { display: none; }

/* animación al clavar la bandera */
.cell.planted {
  animation: plant .5s cubic-bezier(.2, 1.8, .4, 1);
  transform-origin: center 80%;
  z-index: 2;
}
@keyframes plant {
  0%   { transform: scale(2); opacity: 0; }
  55%  { transform: scale(.88); opacity: 1; }
  75%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ===== Chat ===== */
.chat {
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 1px solid rgba(255,255,255,.55);
  outline: 2px solid rgba(127,184,224,.55);
  border-radius: var(--radius-m);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-2);
  flex: 1;
  min-height: 140px;
}
.chat-head {
  display: none; /* solo se muestra en móvil (hoja inferior) */
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: bold;
  color: #114d7c;
}
.chat-close {
  background: none;
  border: none;
  font-size: 15px;
  color: #114d7c;
  cursor: pointer;
  padding: 2px 6px;
}
.chat-log {
  flex: 1;
  min-height: 100px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  background: #fff;
}
.chat-msg { overflow-wrap: anywhere; line-height: 1.35; color: var(--ink); }
.chat-msg.red b  { color: var(--red-dark); }
.chat-msg.blue b { color: var(--blue-dark); }
.chat-form { display: flex; gap: 6px; padding: 6px; }
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  font-size: 13px;
  border-radius: 7px;
}
.chat-send {
  border: none;
  border-radius: 7px;
  padding: 0 12px;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 2px 0 var(--gold-edge);
  color: #5b3a00;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
}
.chat-send:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 1px 0 var(--gold-edge); }
.chat-toggle { display: none; }
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  line-height: 19px;
  padding: 0 4px;
  border-radius: 10px;
  background: #d81f1f;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  text-align: center;
}

/* ===== Avisos a pantalla completa: cambio de turno y capturas ===== */
.turn-banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 44%;
  display: flex;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
}
.turn-banner span {
  padding: 10px 28px;
  border-radius: 999px;
  font-size: clamp(24px, 7vw, 42px);
  font-weight: bold;
  color: #fff;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0,0,0,.35);
  border: 2px solid rgba(255,255,255,.65);
  box-shadow: var(--shadow-2);
  opacity: 0;
}
.turn-banner.red  span { background: linear-gradient(180deg, var(--red), var(--red-dark)); }
.turn-banner.blue span { background: linear-gradient(180deg, var(--blue), var(--blue-dark)); }
.turn-banner.show span { animation: turn-banner 1.5s ease forwards; }
@keyframes turn-banner {
  0%   { opacity: 0; transform: scale(.6); }
  12%  { opacity: 1; transform: scale(1.08); }
  22%  { transform: scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; transform: scale(.98) translateY(-10px); }
}

/* «+n» gigante en mitad de la pantalla al capturar una mina */
.big-pop {
  position: fixed;
  left: 50%;
  top: 24%;
  transform: translateX(-50%);
  z-index: 41;
  pointer-events: none;
  text-align: center;
  opacity: 0;
  animation: big-pop 1.4s ease-out forwards;
}
.big-pop-num {
  display: block;
  font-size: clamp(44px, 13vw, 76px);
  font-weight: bold;
  line-height: 1;
  text-shadow: 0 0 4px rgba(255,255,255,.85), 0 3px 10px rgba(0,0,0,.45);
}
.big-pop.red  .big-pop-num { color: var(--red); }
.big-pop.blue .big-pop-num { color: var(--blue); }
.big-pop-name {
  display: inline-block;
  margin-top: 4px;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  background: rgba(8, 40, 68, .75);
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  padding: 2px 12px;
}
@keyframes big-pop {
  0%   { opacity: 0; transform: translateX(-50%) scale(.5); }
  15%  { opacity: 1; transform: translateX(-50%) scale(1.15); }
  28%  { transform: translateX(-50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(.95); }
}

/* ===== Overlay fin de partida ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 40, 68, .72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-m);
  z-index: 5;
}
.overlay-box {
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 1px solid rgba(255,255,255,.55);
  border-radius: var(--radius-l);
  padding: 26px 34px;
  text-align: center;
  box-shadow: var(--shadow-3);
  animation: overlay-in .3s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes overlay-in {
  from { transform: scale(.8) translateY(12px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.overlay-box h2 { color: #114d7c; margin-bottom: 8px; }
.overlay-box p { color: var(--ink-soft); margin-bottom: 14px; font-size: 14px; }

/* ===== Responsive / móvil ===== */
@media (max-width: 760px) {
  /* casillas grandes y cómodas: el tablero se navega con el dedo */
  :root { --tile-size: 42px; }

  body { overscroll-behavior: none; }
  .screen { padding: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .screen.column { gap: 8px; }

  /* la pantalla de juego queda clavada a la ventana: la página no puede
     desplazarse y el HUD con los marcadores nunca se pierde de vista;
     el tablero absorbe todo el alto sobrante */
  #game-screen {
    position: fixed;
    inset: 0;
    height: auto;
    min-height: 0;
    justify-content: flex-start;
    overflow: hidden;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  /* banner compacto bajo el tablero durante la partida (formato móvil) */
  #game-screen .ad-slot--game-bottom {
    width: 100%;
    min-height: 56px;
    flex-shrink: 0;
  }

  .game-layout { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; flex: 1; min-height: 0; }

  /* HUD en una sola fila: rojo | contadores | azul | acciones */
  .sidebar {
    width: 100%;
    max-width: 560px;
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    gap: 6px;
    align-items: stretch;
    flex-shrink: 0;
  }
  .player-panel {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 5px;
    padding: 5px 8px;
    border-radius: 10px;
    min-width: 0;
  }
  .player-panel.active { transform: none; }
  .panel-title, .pmsg, .avatar { display: none; }
  .pname { font-size: 11px; flex: 1; min-width: 0; text-align: left; }
  .counters { margin-top: 0; gap: 4px; flex-shrink: 0; }
  .flag-counter { font-size: 11px; padding: 2px 7px; border-radius: 6px; }
  .flag-counter b { font-size: 13px; }
  .flag-ico-img { width: 12px; height: 12px; vertical-align: -2px; }
  .bomb-btn { font-size: 12px; padding: 1px 5px; border-radius: 6px; }
  .score-pop { font-size: 12px; padding: 0 6px; }

  .mid-info { flex-direction: column; justify-content: center; gap: 2px; }
  .mines-circle { width: 30px; height: 30px; font-size: 12px; }
  .mines-left .star { display: none; }
  .turn-timer { font-size: 10px; padding: 2px 6px 4px; }

  /* sonido y retirarse: botoncitos apilados a la derecha del HUD */
  .side-actions { flex-direction: column; gap: 4px; justify-content: center; }
  .side-actions .menu-btn { margin: 0; padding: 4px 9px; font-size: 13px; line-height: 1.2; }
  #btn-leave { font-size: 0; } /* icono en vez de texto: cabe en la fila */
  #btn-leave::before { content: '🏳️'; font-size: 14px; line-height: 1.2; }

  /* tablero desplazable en ambos ejes; llena el alto restante exacto */
  .board-wrap {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-m);
  }
  .board { width: max-content; margin: 0 auto; padding: 6px; }

  /* el aviso de fin de partida no debe desplazarse con el tablero */
  .overlay { position: fixed; border-radius: 0; }

  .menu-box { padding: 20px 16px; }
  .overlay-box { padding: 18px 20px; width: min(340px, 92vw); }

  /* chat como hoja inferior deslizante (fija: no reserva hueco en el HUD) */
  .chat {
    flex: none;
    min-height: 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(105%);
    transition: transform .25s ease;
    box-shadow: 0 -8px 30px rgba(0,0,0,.45);
  }
  .chat.open { transform: none; }
  .chat-head { display: flex; }
  .chat-log { height: 32dvh; flex: none; min-height: 0; }
  .chat-form input { font-size: 16px; } /* evita el zoom automático de iOS al enfocar */

  /* minimapa: aparece al moverse el tablero o jugar el rival y se desvanece */
  .minimap {
    display: block;
    position: fixed;
    left: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 96px;
    height: 96px;
    z-index: 28;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,.75);
    background: #0b3457;
    box-shadow: 0 6px 18px rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  .minimap.show { opacity: 1; }

  .chat-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 12px;
    /* por encima del banner inferior de la partida */
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
    /* arrastrable: sin este touch-action el dedo desplazaría la página,
       y sin user-select el pulsado largo seleccionaría el emoji */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    border-radius: 50%;
    border: none;
    z-index: 29;
    font-size: 24px;
    background: linear-gradient(180deg, var(--gold), var(--gold-deep));
    box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 3px 0 var(--gold-edge), 0 6px 18px rgba(0,0,0,.45);
    cursor: pointer;
  }
  .chat-toggle:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 1px 0 var(--gold-edge), 0 4px 12px rgba(0,0,0,.45); }
}

/* pantallas anchas: más aire entre paneles */
@media (min-width: 1200px) {
  .game-layout { gap: 22px; }
  .sidebar { width: 210px; }
}

/* muy anchas: rascacielos extra a la derecha, donde sobra espacio */
@media (min-width: 1500px) {
  :root { --tile-size: clamp(26px, min(calc((100dvh - 266px) / 16), calc((100vw - 700px) / 16)), 54px); }
  .ad-rail { display: block; }
  .game-layout {
    grid-template-columns: auto auto 300px;
    grid-template-areas:
      "sidebar board rail"
      "sidebar ad rail";
  }
}

/* táctil: objetivos cómodos y sin gestos accidentales */
@media (pointer: coarse) {
  .cell, .menu-btn, .bomb-btn { touch-action: manipulation; }
  .menu-btn { padding: 13px 16px; }
  .cell:not(.revealed):hover { filter: none; }
}

/* accesibilidad: sin animaciones para quien las desactiva en el sistema */
@media (prefers-reduced-motion: reduce) {
  .bump, .score-pop, .cell.planted, .overlay-box, .menu-box,
  .bomb-btn.armed, .turn-timer.low, .cell.opp-move,
  .turn-banner.show span, .big-pop { animation: none; }
  /* sin animación siguen visibles: el JS los retira pasado un momento */
  .turn-banner.show span, .big-pop { opacity: 1; }
  .player-panel, .chat { transition: none; }
  .cell.opp-move { box-shadow: 0 0 0 4px var(--gold), inset 0 0 0 3px var(--gold); }
}

/* ============================================================
   PORTADA (landing): escena a pantalla completa con la imagen
   del duelo en el mar y la llamada a jugar
   ============================================================ */
#landing-screen {
  position: relative;
  overflow: hidden;
  padding: max(24px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}
.landing-bg, .landing-bg img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* velo sutil arriba y abajo para que el texto se lea sobre la foto */
#landing-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 26, 44, .55) 0%, transparent 26%),
    linear-gradient(0deg, rgba(6, 26, 44, .78) 0%, rgba(6, 26, 44, .35) 26%, transparent 48%);
  pointer-events: none;
}
.landing-content {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  /* ocupa todo el alto que deja el padding de la pantalla: así nunca suma
     más de 100dvh (con min-height fijo el padding + safe-area desbordaba) */
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  text-align: center;
  color: #f2f9ff;
}
.landing-title {
  font-size: clamp(34px, 7vw, 64px);
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 3px 0 rgba(9, 34, 56, .8), 0 10px 30px rgba(4, 20, 36, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  animation: landing-drop .7s cubic-bezier(.2, 1.4, .4, 1) both;
}
.landing-title .logo-flag { width: clamp(34px, 6vw, 58px); height: auto; filter: drop-shadow(0 4px 8px rgba(4,20,36,.6)); }
.landing-title .logo-flag.flip { transform: scaleX(-1); }
.landing-tagline {
  margin-top: 8px;
  font-size: clamp(14px, 2.4vw, 19px);
  font-weight: 600;
  color: #ffe9b8;
  text-shadow: 0 2px 6px rgba(4, 20, 36, .9);
  animation: landing-drop .7s .12s cubic-bezier(.2, 1.4, .4, 1) both;
}
.landing-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: landing-rise .8s .2s ease-out both;
}
.landing-story {
  max-width: 56ch;
  font-size: clamp(15px, 2.6vw, 19px);
  line-height: 1.55;
  text-shadow: 0 2px 8px rgba(4, 20, 36, .95), 0 0 24px rgba(4, 20, 36, .7);
}
.landing-story b { color: var(--gold); }
.landing-cta {
  font: inherit;
  font-size: clamp(19px, 3.4vw, 24px);
  font-weight: 700;
  color: #4a2c02;
  padding: 16px 44px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(180deg, #ffe27a 0%, var(--gold) 38%, var(--gold-deep) 100%);
  box-shadow: 0 4px 0 var(--gold-edge), var(--shadow-2), 0 0 34px rgba(255, 210, 74, .45);
  animation: landing-pulse 2.2s 1.2s ease-in-out infinite;
  transition: transform .12s, box-shadow .12s;
}
.landing-cta:hover { transform: translateY(-2px) scale(1.03); }
.landing-cta:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-edge), var(--shadow-1); }
.landing-feats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 10px;
  font-size: clamp(12px, 2vw, 14px);
}
.landing-feats span {
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(6, 26, 44, .55);
  border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

@keyframes landing-drop {
  from { opacity: 0; transform: translateY(-26px); }
  to   { opacity: 1; transform: none; }
}
@keyframes landing-rise {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}
@keyframes landing-pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--gold-edge), var(--shadow-2), 0 0 24px rgba(255, 210, 74, .35); }
  50%      { box-shadow: 0 4px 0 var(--gold-edge), var(--shadow-2), 0 0 46px rgba(255, 210, 74, .75); }
}

/* --- demo animada «así se juega»: mini-tablero con los sprites reales
       donde un cursor pisa la mina, planta bandera y pasa turno --- */
.landing-demo {
  --demo-tile: clamp(28px, 8.4vw, 40px);
  width: min(400px, 94vw);
  padding: 10px 12px 12px;
  border-radius: var(--radius-l);
  background: rgba(6, 26, 44, .60);
  border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  box-shadow: var(--shadow-2);
  animation: landing-rise .8s .3s ease-out both;
}
.demo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.demo-title {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}
.demo-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .25);
  opacity: .45;
  transition: opacity .3s, box-shadow .3s;
}
.demo-chip img { width: 14px; height: 14px; }
.demo-chip b { font-variant-numeric: tabular-nums; }
.demo-chip.red  { background: linear-gradient(180deg, var(--red), var(--red-dark)); }
.demo-chip.blue { background: linear-gradient(180deg, var(--blue), var(--blue-dark)); }
.demo-chip.active { opacity: 1; box-shadow: 0 0 0 2px var(--gold), 0 0 10px rgba(255, 210, 74, .5); }

.demo-stage { position: relative; display: flex; justify-content: center; }
.demo-board {
  display: grid;
  grid-template-columns: repeat(6, var(--demo-tile));
  grid-auto-rows: var(--demo-tile);
  gap: 2px;
  padding: 5px;
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, #0c3a60, #092c4a);
  border: 1px solid rgba(255, 255, 255, .12);
}
.demo-board .cell {
  width: var(--demo-tile);
  height: var(--demo-tile);
  cursor: default;
  pointer-events: none;
}
.demo-board.demo-reset { animation: demo-fade .55s ease; }
@keyframes demo-fade { from { opacity: .15; } to { opacity: 1; } }

/* casilla-pista: el número que delata a la mina vecina */
.demo-board .cell.demo-hint { animation: demo-hint .8s ease-in-out infinite alternate; }
@keyframes demo-hint {
  from { box-shadow: inset 0 0 0 2px var(--gold); }
  to   { box-shadow: inset 0 0 0 3px var(--gold), 0 0 14px rgba(255, 210, 74, .9); }
}

/* mina «fantasma»: marca dónde se esconde la mina que hay que pisar */
.demo-ghost {
  position: absolute;
  font-size: calc(var(--demo-tile) * .62);
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  animation: demo-ghost 1s ease-in-out infinite alternate;
}
@keyframes demo-ghost {
  from { opacity: .35; transform: translate(-50%, -50%) scale(.9); }
  to   { opacity: .9;  transform: translate(-50%, -50%) scale(1.08); }
}

/* cursor que «juega» la demo; en el turno rival brilla en azul */
.demo-cursor {
  position: absolute;
  left: 0;
  top: 0;
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1;
  transform: translate(-50%, -10%);
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .55));
  transition: left .6s cubic-bezier(.3, .9, .35, 1), top .6s cubic-bezier(.3, .9, .35, 1), transform .12s;
  pointer-events: none;
  z-index: 4;
}
.demo-cursor.tap { transform: translate(-50%, -10%) scale(.76); }
.demo-cursor.rival { filter: drop-shadow(0 0 7px var(--blue)) drop-shadow(0 3px 5px rgba(0, 0, 0, .55)); }

/* onda al hacer clic */
.demo-ripple {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  pointer-events: none;
  z-index: 3;
  animation: demo-ripple .45s ease-out forwards;
}
@keyframes demo-ripple {
  from { opacity: .95; transform: translate(-50%, -50%) scale(.5); }
  to   { opacity: 0;   transform: translate(-50%, -50%) scale(2.6); }
}

/* «+1» al capturar una mina en la demo */
.demo-pop {
  position: absolute;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 999px;
  padding: 1px 8px;
  pointer-events: none;
  z-index: 5;
  animation: demo-pop 1.1s ease-out forwards;
}
.demo-pop.red  { background: linear-gradient(180deg, var(--red), var(--red-dark)); }
.demo-pop.blue { background: linear-gradient(180deg, var(--blue), var(--blue-dark)); }
@keyframes demo-pop {
  0%   { opacity: 0; transform: translate(-50%, -40%) scale(.6); }
  18%  { opacity: 1; transform: translate(-50%, -95%) scale(1.15); }
  80%  { opacity: 1; transform: translate(-50%, -150%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(.95); }
}

/* subtítulo: alto fijo para que el texto cambie sin mover el resto */
.demo-caption {
  margin-top: 9px;
  min-height: 2.8em;
  font-size: clamp(12px, 2.3vw, 14px);
  line-height: 1.35;
  color: #eaf6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.demo-caption span { transition: opacity .2s; text-shadow: 0 1px 4px rgba(4, 20, 36, .9); }

/* pantallas bajas: la demo se compacta y, si no cabe (móvil apaisado), fuera */
@media (min-height: 641px) and (max-height: 780px) {
  .landing-demo { --demo-tile: clamp(24px, 6.5vw, 32px); }
  .demo-caption { min-height: 2.6em; font-size: 12px; }
}
@media (max-height: 640px) {
  .landing-demo { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .landing-title, .landing-tagline, .landing-bottom, .landing-cta,
  .landing-demo, .demo-board .cell.demo-hint, .demo-ghost { animation: none; }
}
