/* Ajedrez: tablero (chess-board.js), partida contra la máquina, partida online y sala de retos. */

/* Los bloques con display propio deben seguir ocultándose con el atributo hidden. */
.chess-wrap [hidden] { display: none !important; }

/* ------------------------------------------------------------ tablero */
.cb-board {
  --cb-light: #e9dcb8;
  --cb-dark: #8a6a45;
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 3px var(--wood-dark), 0 10px 30px rgba(0, 0, 0, .45);
  container-type: inline-size;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cb-sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cb-light { background: var(--cb-light); }
.cb-dark { background: var(--cb-dark); }
.cb-last.cb-light { background: #e3c878; }
.cb-last.cb-dark { background: #b4914a; }
.cb-sel { box-shadow: inset 0 0 0 100px rgba(111, 174, 74, .55); }
.cb-check { background-image: radial-gradient(circle, rgba(230, 40, 20, .95) 0%, rgba(230, 40, 20, .55) 35%, rgba(230, 40, 20, 0) 72%); }
.cb-target::after {
  content: '';
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(30, 50, 20, .35);
  pointer-events: none;
}
.cb-capture::after {
  content: '';
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 0.9cqw solid rgba(30, 50, 20, .4);
  pointer-events: none;
}
.cb-mine { cursor: grab; }
.cb-piece {
  position: relative;
  z-index: 1;
  font-size: 10.4cqw;
  line-height: 1;
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', 'DejaVu Sans', 'Arial Unicode MS', serif;
  pointer-events: none;
}
.cb-w {
  color: #fbf8ef;
  text-shadow: 0 0 1px #2a1d10, 0 0 1px #2a1d10, 1px 1px 0 #2a1d10, -1px -1px 0 #2a1d10, 1px -1px 0 #2a1d10, -1px 1px 0 #2a1d10, 0 2px 3px rgba(0, 0, 0, .35);
}
.cb-b {
  color: #1c1712;
  text-shadow: 0 0 1px rgba(255, 255, 255, .5), 0 2px 3px rgba(0, 0, 0, .35);
}
.cb-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transform-origin: center;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .4));
}
.cb-coord {
  position: absolute;
  font-size: 2.3cqw;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.cb-rank { top: 3%; left: 4%; }
.cb-file { bottom: 3%; right: 5%; }
.cb-light .cb-coord { color: var(--cb-dark); }
.cb-dark .cb-coord { color: var(--cb-light); }

.cb-promo {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2%;
  background: rgba(10, 14, 8, .7);
  backdrop-filter: blur(2px);
}
.cb-promo button {
  width: 18%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--cb-light);
  cursor: pointer;
}
.cb-promo button:hover,
.cb-promo button:focus-visible { border-color: var(--accent); outline: none; transform: translateY(-2px); }
.cb-promo .cb-piece { font-size: 12cqw; }
.cb-promo .cb-promo-cancel {
  position: absolute;
  top: 3%;
  right: 3%;
  width: 9%;
  background: var(--bg-card);
  color: var(--text);
  font-size: 4cqw;
}

/* ------------------------------------------------------------ disposición de una partida */
.chess-wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.chess-game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
.chess-main { max-width: min(640px, calc(100vh - 210px)); width: 100%; margin: 0 auto; }
.chess-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
@media (max-width: 860px) {
  .chess-game { grid-template-columns: 1fr; }
  .chess-main { max-width: 560px; }
}

.chess-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 2px;
}
.chess-player .cp-av {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 18px;
}
.chess-player .cp-name { font-weight: 700; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chess-player .cp-name:hover { text-decoration: underline; }
.chess-player .cp-mat { color: var(--text-dim); font-size: 15px; letter-spacing: -2px; white-space: nowrap; overflow: hidden; }
.chess-player .cp-mat small { letter-spacing: 0; margin-left: 4px; font-size: 12px; }
.chess-player .cp-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cp-clock {
  margin-left: auto;
  min-width: 92px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font: 700 22px/1.1 ui-monospace, 'Cascadia Mono', Consolas, monospace;
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.cp-clock.running { background: #e9dcb8; color: #1d160e; border-color: var(--accent); }
.cp-clock.low { background: #a8462f; color: #fff; border-color: #e0715a; }
.cp-thinking { font-size: 12px; color: var(--accent); }

.chess-status {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-weight: 600;
  text-align: center;
}
.chess-status.over { border-color: var(--accent); color: var(--accent); }
.chess-status.alert { border-color: #a8462f; color: #f0a08f; }

.chess-moves {
  max-height: 260px;
  min-height: 90px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.cm-row { display: grid; grid-template-columns: 42px 1fr 1fr; align-items: center; }
.cm-row:nth-child(odd) { background: rgba(255, 255, 255, .025); }
.cm-n { color: var(--text-dim); font-size: 13px; padding-left: 10px; }
.cm-move {
  border: 0;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 4px 8px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
}
.cm-move:hover:not(:disabled) { background: rgba(255, 255, 255, .06); }
.cm-move.cm-cur { background: var(--wood); color: #fff; }
.cm-empty { color: var(--text-dim); padding: 10px 12px; font-size: 14px; }

.chess-nav { display: flex; gap: 6px; }
.chess-nav button { flex: 1; }
.chess-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chess-actions > * { flex: 1 1 auto; }

.chess-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.chess-btn:hover:not(:disabled) { border-color: var(--accent-2); }
.chess-btn:disabled { opacity: .45; cursor: default; }
.chess-btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #0f150b; }
.chess-btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.chess-btn.danger:hover:not(:disabled) { border-color: #c1503a; color: #f0a08f; }
.chess-btn.small { padding: 5px 10px; font-size: 13px; }

.chess-offer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: rgba(201, 154, 63, .1);
}
.chess-offer p { margin: 0; flex: 1 1 100%; }

.chess-field { display: flex; flex-direction: column; gap: 6px; }
.chess-field > span { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.chess-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.chess-seg label { flex: 1 1 auto; }
.chess-seg input { position: absolute; opacity: 0; pointer-events: none; }
.chess-seg label span {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.chess-seg input:checked + span { border-color: var(--accent-2); background: rgba(111, 174, 74, .18); color: var(--text); }
.chess-seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chess-field input[type="text"] {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
}

.chess-invite { display: flex; gap: 6px; }
.chess-invite input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; }

/* ------------------------------------------------------------ sala de retos (lobby) */
.chess-hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 20px; }
.chess-hero h1 { margin: 0; font-size: 30px; }
.chess-hero p { margin: 4px 0 0; color: var(--text-dim); }
.chess-stats { color: var(--text-dim); font-size: 14px; }
.chess-stats strong { color: var(--text); }

.chess-lobby { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .chess-lobby { grid-template-columns: 1fr; } }
.chess-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chess-panel h2 { margin: 0; font-size: 18px; }
.chess-panel h3 { margin: 4px 0 0; font-size: 15px; color: var(--text-dim); }
.chess-tabs { display: flex; gap: 6px; }
.chess-tabs button { flex: 1; }
.chess-tabs button[aria-selected="true"] { border-color: var(--accent-2); background: rgba(111, 174, 74, .18); }

.chess-list { display: flex; flex-direction: column; gap: 8px; }
.chess-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.chess-row .cr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chess-row .cr-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chess-row .cr-main small { color: var(--text-dim); }
.chess-row .cr-time { font: 700 16px/1 ui-monospace, Consolas, monospace; color: var(--accent); min-width: 48px; }
.chess-row a.cr-link { color: inherit; text-decoration: none; display: contents; }
.chess-empty { color: var(--text-dim); margin: 0; font-size: 14px; }
.chess-note { color: var(--text-dim); font-size: 13px; margin: 0; }
.chess-error { color: #f0a08f; font-size: 14px; margin: 0; }

.chess-ai-card { display: grid; gap: 14px; }

/* Portada de juegos */
.games-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.game-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border);
}
.game-card .gc-icon { font-size: 44px; line-height: 1; }
.game-card h2 { margin: 0; font-size: 20px; }
.game-card p { margin: 0; color: var(--text-dim); }
.game-card .gc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

@media (prefers-reduced-motion: reduce) {
  .cb-promo button:hover { transform: none; }
}
