/* style.css — Ajedrez por turnos · UI mobile-first
   Layout vertical que entra en una pantalla de celular sin scroll:
   [ad] [rival · tablero · vos] [acciones] [ad] */

:root {
  --bg: #161a23;
  --bg-2: #1f2430;
  --panel: #262d3b;
  --panel-2: #2f3749;
  --line: #39415680;
  --text: #eef1f7;
  --muted: #97a0b5;
  --accent: #5b8cff;
  --accent-2: #4f7ff0;
  --good: #46c97e;
  --danger: #ff6b6b;

  --light-sq: #ebd9b6;
  --dark-sq: #9c6a43;
  --sel: #f7d154;
  --target: rgba(70, 201, 126, 0.85);
  --capture: rgba(255, 107, 107, 0.85);
  --last: rgba(247, 209, 84, 0.38);
  --check: rgba(255, 80, 80, 0.55);

  --radius: 14px;
  --radius-sm: 10px;
  --max: 460px;
  --gap: 10px;
}

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

/* El atributo [hidden] debe ocultar siempre, aunque una regla .btn/.sheet
   defina display. (Los estilos de autor le ganan al [hidden] del navegador.) */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(120% 60% at 50% -10%, #20283a 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* App ocupa el alto real del viewport del celular (dvh evita saltos por la
   barra del navegador) y reparte el espacio verticalmente. */
.app {
  max-width: var(--max);
  margin: 0 auto;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding:
    calc(8px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
}

/* ===== Publicidad ===== */
.ad { flex: 0 0 auto; }
.ad__slot {
  display: flex; align-items: center; justify-content: center;
  min-height: 50px;
  background: var(--bg-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}
.ad--top .ad__slot { min-height: 56px; }
.ad__label { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }

/* ===== Zona de juego ===== */
.game {
  flex: 1 1 auto;
  min-height: 0;                /* permite que el tablero se achique */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

/* ===== Barras de jugador ===== */
.player {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.player--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 18px -8px var(--accent);
}
.player__dot {
  width: 18px; height: 18px; border-radius: 50%;
  flex: 0 0 auto; border: 2px solid #00000040;
}
.player--white .player__dot { background: #f4f4f4; }
.player--black .player__dot { background: #2b2b2b; border-color: #ffffff30; }
.player__name { font-weight: 700; font-size: 14px; flex: 0 0 auto; }
.player__captures {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center;
  white-space: nowrap; overflow: hidden;
}
.cap { width: 20px; height: 20px; margin-right: -6px; flex: 0 0 auto; }
.player__adv { font-size: 12px; font-weight: 700; color: var(--muted); flex: 0 0 auto; }
.player__badge {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  color: #fff; background: var(--accent);
  padding: 3px 8px; border-radius: 999px;
  display: none;
}
.player--active .player__badge { display: inline-block; }

/* ===== Tablero ===== */
.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
/* Tablero cuadrado. En vertical (celular) lo limita el ancho; en horizontal,
   el alto disponible. Todo por CSS, sin depender de timing de JS. */
.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 8px;
  overflow: hidden;
  /* Marco de madera + relieve interior y sombra exterior. */
  border: clamp(7px, 2.4vmin, 14px) solid;
  border-image: linear-gradient(150deg, #6b4427, #4d3019) 1;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, .35),
    inset 0 2px 6px rgba(0, 0, 0, .35),
    0 16px 44px -14px rgba(0, 0, 0, .75);
  user-select: none;
  touch-action: manipulation;
}
@media (min-aspect-ratio: 1 / 1) {
  .board { width: auto; height: 100%; }
}
.board--locked { pointer-events: none; }

.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
/* Casillas con textura de madera (gradientes superpuestos simulando veta). */
.cell--light {
  background:
    repeating-linear-gradient(96deg, #00000000 0 6px, #0000000a 6px 7px),
    linear-gradient(150deg, #f3e2c0 0%, #e6d0a7 55%, #ddc498 100%);
}
.cell--dark {
  background:
    repeating-linear-gradient(96deg, #00000000 0 6px, #ffffff08 6px 7px),
    linear-gradient(150deg, #a9794d 0%, #99683f 55%, #8a5d39 100%);
}

/* Pieza: imagen SVG con sombra suave para dar volumen. */
.pc {
  width: 92%; height: 92%;
  object-fit: contain;
  will-change: transform;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35));
}
.pc--anim { transition: transform .2s cubic-bezier(.2,.7,.3,1); }

/* Etiquetas de coordenadas */
.cell::after {
  content: attr(data-file-label);
  position: absolute; right: 3px; bottom: 1px;
  font-size: 9px; font-weight: 700; opacity: .55;
}
.cell::before {
  content: attr(data-rank-label);
  position: absolute; left: 3px; top: 1px;
  font-size: 9px; font-weight: 700; opacity: .55;
}
.cell--light::after, .cell--light::before { color: #6b4a2a; }
.cell--dark::after,  .cell--dark::before  { color: #f0e0c8; }

/* Resaltados */
.cell--last::before { content: ""; position: absolute; inset: 0; background: var(--last); }
.cell--selected { box-shadow: inset 0 0 0 3px var(--sel); }
.cell--check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, var(--check) 0%, transparent 72%);
}
.cell--target > .dot {
  position: absolute; left: 50%; top: 50%;
  width: 30%; height: 30%; transform: translate(-50%, -50%);
  background: var(--target); border-radius: 50%; opacity: .9;
}
.cell--capture > .dot {
  position: absolute; inset: 8%;
  border: 5px solid var(--capture); border-radius: 50%;
  background: transparent;
}

/* ===== Acciones ===== */
/* Barra de acciones: botones con ícono SVG + etiqueta (estilo tab-bar). */
.actbar { display: flex; gap: 8px; flex: 0 0 auto; }
.act {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px;
  min-height: 60px; padding: 8px 4px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  cursor: pointer;
  transition: transform .05s ease, background .15s, border-color .15s, box-shadow .15s;
}
.act:active { transform: scale(.95); }
.act svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.act__label { font-size: 11px; font-weight: 700; letter-spacing: .01em; }
.act--primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent);
}
.act--primary:active { background: var(--accent-2); }
.act:disabled { opacity: .45; pointer-events: none; }

/* ===== Control de reproducción ===== */
.playbar { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.playbar__head { display: flex; justify-content: center; }
.playbar__info {
  font-size: 13px; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.playbar__range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 999px;
  background: var(--panel-2); outline: none; cursor: pointer; margin: 2px 0;
}
.playbar__range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: pointer;
}
.playbar__range::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: pointer;
}
.playbar__row { display: flex; gap: 8px; align-items: stretch; }
.pbtn {
  flex: 1 1 0;
  display: flex; align-items: center; justify-content: center;
  min-height: 52px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; font-weight: 800; cursor: pointer;
  transition: transform .05s ease, background .15s;
}
.pbtn:active { transform: scale(.95); }
.pbtn--primary { flex: 1.5 1 0; background: var(--accent); border-color: var(--accent); color: #fff; }
.pbtn--primary:active { background: var(--accent-2); }
.pbtn--speed { letter-spacing: .02em; }
.pbtn svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
/* play/pausa: rellenos para que se lean mejor en el botón principal */
.pbtn--primary svg path { fill: currentColor; stroke: none; }
.btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn--primary { flex: 1 1 auto; background: var(--accent); border-color: var(--accent); }
.btn--ghost { background: transparent; }
.btn:disabled { opacity: .65; cursor: default; }

/* ===== Bottom sheets ===== */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fade .2s ease; }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: var(--max); margin: 0 auto;
  background: var(--bg-2);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: sheet-up .24s cubic-bezier(.2,.8,.3,1);
  max-height: 92dvh;
  overflow-y: auto;
}
.sheet__grip { width: 40px; height: 4px; border-radius: 999px; background: #ffffff30; margin: 6px auto 12px; }
.sheet__title { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.sheet__hint { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.sheet__close { width: 100%; margin-top: 14px; }

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Compartir */
.share__url { display: flex; gap: 8px; }
.share__input {
  flex: 1 1 auto; min-width: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 12px; min-height: 48px; font-size: 13px;
}
.share__buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.sbtn {
  text-align: center; text-decoration: none;
  min-height: 48px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 0;
  font-size: 15px; font-weight: 700; color: #fff; cursor: pointer;
}
.sbtn--native { grid-column: 1 / -1; background: var(--accent); }
.sbtn--ig {
  grid-column: 1 / -1;
  background: linear-gradient(95deg, #f9ce34 0%, #ee2a7b 50%, #6228d7 100%);
}
.sbtn--dl { grid-column: 1 / -1; background: var(--panel-2); border: 1px solid var(--line); }
.sbtn--wa { background: #25d366; }
.sbtn--tg { background: #2aabee; }
.sbtn--x  { background: #111; border: 1px solid #333; }
.sbtn--fb { background: #1877f2; }

/* Vista previa de la imagen del tablero */
.share__img {
  display: block;
  width: 160px; max-width: 50%;
  margin: 0 auto 14px;
  border-radius: 12px;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .6);
}

/* Historial */
.history__list {
  margin: 0; padding-left: 28px;
  font-variant-numeric: tabular-nums; font-size: 15px; line-height: 1.7;
  max-height: 50vh; overflow-y: auto;
}
.history__list li { white-space: pre; }

/* ===== Aviso de jaque ===== */
.check-alert {
  position: fixed; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45);
  animation: fade .15s ease;
}
.check-alert__box {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 24px 40px;
  background: linear-gradient(160deg, #e74c3c 0%, #c0392b 100%);
  border: 1px solid #ff7b6b;
  border-radius: 18px;
  box-shadow: 0 18px 50px -10px rgba(192, 57, 43, .7);
  animation: check-pop .4s cubic-bezier(.2, 1.3, .4, 1);
}
.check-alert__icon {
  width: 56px; height: 56px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .4));
}
.check-alert__text {
  font-size: 28px; font-weight: 800; color: #fff;
  letter-spacing: .02em; text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
@keyframes check-pop {
  0%   { transform: scale(.5) rotate(-6deg); opacity: 0; }
  60%  { transform: scale(1.08) rotate(2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ===== Modal de promoción ===== */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6);
}
.modal[hidden] { display: none; }
.modal__box {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  text-align: center; max-width: 320px; width: 86%;
  animation: pop .18s ease;
}
.modal__title { margin: 0 0 14px; font-weight: 800; }
.modal__choices { display: flex; justify-content: center; gap: 10px; }
.modal__piece {
  width: 64px; height: 64px; padding: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer;
}
.modal__piece img { width: 100%; height: 100%; object-fit: contain; }
.modal__piece:active { transform: scale(.95); }

/* ===== Cartel de fin de partida =====
   Panel anclado abajo (no tapa el tablero: se ve el mate y la última jugada). */
.result {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: var(--max); margin: 0 auto;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  pointer-events: none;   /* sólo la tarjeta recibe toques */
}
.result[hidden] { display: none; }
.result__card {
  position: relative;
  pointer-events: auto;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px 18px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .55);
  animation: sheet-up .26s cubic-bezier(.2, .8, .3, 1);
}
.result__close {
  position: absolute; top: 8px; right: 8px;
  width: 34px; height: 34px; padding: 6px;
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
}
.result__close svg {
  width: 100%; height: 100%;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}
.result__head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.result__icon { flex: 0 0 auto; line-height: 1; font-size: 40px; }
.result__icon img { width: 46px; height: 46px; display: block; }
.result__texts { text-align: left; }
.result__title { margin: 0; font-size: 20px; font-weight: 800; }
.result__sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.result__actions { display: flex; gap: 8px; }
.result__actions .btn { flex: 1 1 0; }

/* En pantallas muy bajas, ocultamos los ads para priorizar el tablero. */
@media (max-height: 620px) {
  .ad { display: none; }
}
