/* ==========================================================================
   Ajedrez Sparky — estilos del tablero móvil (WhatsApp WebView)
   ========================================================================== */
:root {
  --bg: #0e1a14;
  --bg-2: #14251d;
  --panel: #1a2f25;
  --panel-2: #21392d;
  --text: #eaf3ec;
  --muted: #9db6a8;
  --accent: #57b894;
  --accent-2: #7fd4b1;
  --danger: #e0695f;
  --warn: #e2b25a;
  --light-sq: #eeeed2;
  --dark-sq: #6d9a58;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d3a2c 0%, transparent 60%),
    var(--bg);
}

.app {
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
}

/* ── Barra superior ─────────────────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; }
.brand-mark { font-size: 22px; color: var(--accent-2); }
.brand-text em { color: var(--accent-2); font-style: normal; font-weight: 800; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(226, 178, 90, .15);
  transition: background .2s, box-shadow .2s;
}
.dot.online { background: var(--accent); box-shadow: 0 0 0 3px rgba(87, 184, 148, .18); }
.dot.offline { background: var(--danger); box-shadow: 0 0 0 3px rgba(224, 105, 95, .18); }

.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  font-size: 20px; line-height: 1; padding: 6px 8px; border-radius: 10px;
}
.icon-btn:active { background: rgba(255,255,255,.07); }

/* ── Contenido ──────────────────────────────────────────────────────────── */
.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 0 12px 10px;
  overflow: hidden;
}

.players {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px;
}
.player { display: flex; align-items: center; gap: 7px; min-width: 0; }
.player-name {
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw;
}
.player.active .player-name { color: var(--text); }
.player.active .piece-dot { transform: scale(1.25); box-shadow: 0 0 0 3px rgba(127, 212, 177, .25); }
.piece-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid #0c1712; transition: transform .15s;
}
.piece-dot.white { background: #f4f4ec; }
.piece-dot.black { background: #1b1b1b; }
.vs { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px; }

/* ── Tablero ────────────────────────────────────────────────────────────── */
.board-wrap {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board {
  /* Cuadrado: el ancho disponible, limitado para que quepan la barra, los
     controles y el historial en pantallas pequeñas. */
  width: min(100%, calc(100dvh - 350px));
  max-width: 620px;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.06) inset;
  touch-action: none;
}

.board .cm-chessboard .board .square { transition: filter .12s; }
.board .cm-chessboard .board .square:hover { filter: brightness(1.06); }

/* El tablero de cm-chessboard trae su propio fondo; forzamos los colores. */
.board .cm-chessboard .board .square.white { fill: var(--light-sq); }
.board .cm-chessboard .board .square.black { fill: var(--dark-sq); }

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 16, 12, .72);
  backdrop-filter: blur(3px);
  border-radius: 12px;
  padding: 18px;
  z-index: 20;
}
.overlay-card {
  width: 100%; max-width: 340px;
  background: var(--panel);
  border: 1px solid rgba(127, 212, 177, .18);
  border-radius: 18px;
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.overlay-card h2 { margin: 0 0 6px; font-size: 19px; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; }

/* ── Estado y controles ─────────────────────────────────────────────────── */
.statusbar { flex: 0 0 auto; display: flex; gap: 8px; justify-content: center; }
.pill {
  font-size: 12.5px; font-weight: 650;
  padding: 6px 12px; border-radius: 999px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid rgba(255,255,255,.06);
}
.pill.subtle { color: var(--muted); font-weight: 550; }
.pill.turn-mine { background: rgba(87,184,148,.18); color: var(--accent-2); border-color: rgba(87,184,148,.35); }
.pill.turn-theirs { background: rgba(226,178,90,.12); color: var(--warn); border-color: rgba(226,178,90,.25); }
.pill.finished { background: rgba(224,105,95,.15); color: #f2a49d; border-color: rgba(224,105,95,.3); }

.controls { flex: 0 0 auto; display: flex; gap: 8px; justify-content: center; }

/* Barra de jugadas: aparece sólo cuando hay alguna. */
.log:empty { display: none; }

.btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,.09);
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-weight: 600;
  padding: 11px 16px;
  border-radius: 12px;
  transition: transform .06s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.small { padding: 9px 12px; font-size: 13px; border-radius: 11px; }
.btn.primary { background: var(--accent); color: #06130d; border-color: transparent; }
.btn.danger { color: #f2a49d; }
.btn.wide { width: 100%; }

/* ── Registro de jugadas ────────────────────────────────────────────────── */
.log {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 26vh;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 5px;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: normal;
  padding: 6px 8px;
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(255, 255, 255, .05);
  border-radius: 12px;
  scrollbar-width: thin;
}
.log::-webkit-scrollbar { width: 5px; }
.log::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }
.log .mv { padding: 3px 7px; border-radius: 7px; background: rgba(255,255,255,.05); }
.log .mv.last { background: rgba(87,184,148,.2); color: var(--accent-2); font-weight: 700; }
.log .num { color: #6d8a7b; font-variant-numeric: tabular-nums; align-self: center; }

/* ── Hoja de menú ───────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  background: var(--panel);
  border-top: 1px solid rgba(255,255,255,.08);
  border-radius: 20px 20px 0 0;
  padding: 16px 18px calc(20px + var(--safe-bottom));
  box-shadow: 0 -20px 50px rgba(0,0,0,.5);
  animation: slideUp .2s ease-out;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h3 { margin: 0; font-size: 16px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 10px 0 16px; font-size: 13.5px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; text-align: right; font-weight: 650; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 12px 0 0; }
.credits { font-size: 10.5px; color: #5f7a6b; margin: 14px 0 0; text-align: center; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(20, 37, 29, .96);
  border: 1px solid rgba(127,212,177,.22);
  color: var(--text);
  padding: 10px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 600;
  z-index: 60;
  max-width: 86vw; text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
  transition: opacity .2s, transform .2s;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, 8px); }

.hidden { display: none !important; }

/* Ajustes para pantallas bajas (móvil en horizontal) */
@media (max-height: 560px) {
  .players, .log { display: none; }
  .board { width: min(100%, calc(100dvh - 150px)); }
  .topbar { padding-top: 4px; }
}
