/* ===== Chess board + side panel ===== */

.chess-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chess-table {
  flex: 1;
  display: flex;
  gap: clamp(16px, 3vw, 36px);
  align-items: flex-start;
  justify-content: center;
  padding: clamp(12px, 3vw, 28px);
  flex-wrap: wrap;
}

.chess-board-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 600px);
}

/* trays show captured pieces + material edge */
.tray {
  min-height: 26px;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 2px 6px;
  color: var(--muted);
  font-size: 14px;
}
.tray .cap-pieces { display: inline-flex; flex-wrap: wrap; line-height: 1; }
.tray .cp.small { font-size: 20px; filter: none; }
.tray .mat-edge {
  margin-left: 8px;
  color: var(--gold);
  font-weight: 700;
  font-size: 13px;
}

/* ----- the board ----- */
.chess-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #2a1c10;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* Each square is intrinsically square (width comes from the 1fr column).
     This keeps the board from collapsing its empty ranks if a browser doesn't
     resolve the board's container aspect-ratio. */
  aspect-ratio: 1 / 1;
  min-width: 0;
}
.chess-board.locked .sq { cursor: default; }

.sq.light { background: #e7d6b0; }
.sq.dark  { background: #4e7d4e; }

/* highlight tints (drawn above the base colour, below the piece) */
.sq.lastmove { box-shadow: inset 0 0 0 9999px rgba(212, 175, 55, 0.30); }
.sq.selected { box-shadow: inset 0 0 0 9999px rgba(212, 175, 55, 0.55); }
.sq.incheck  { box-shadow: inset 0 0 0 9999px rgba(216, 48, 48, 0.55); }

/* piece glyphs */
.cp {
  font-size: clamp(28px, 8.5vw, 54px);
  line-height: 1;
  pointer-events: none;
  position: relative;
  z-index: 2;
}
.cp-w {
  color: #f8f4e8;
  text-shadow:
    0 0 1px #000, 1px 0 1px #000, -1px 0 1px #000, 0 1px 1px #000, 0 -1px 1px #000,
    0 2px 3px rgba(0, 0, 0, 0.6);
}
.cp-b {
  color: #1a1a1a;
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.35),
    0 2px 3px rgba(0, 0, 0, 0.55);
}

/* legal-move markers */
.target {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 30%;
  height: 30%;
  background: rgba(0, 0, 0, 0.32);
  border-radius: 50%;
  z-index: 1;
}
.target.capture {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 5px solid rgba(0, 0, 0, 0.32);
  box-sizing: border-box;
}

/* edge coordinates */
.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.65;
  z-index: 3;
  pointer-events: none;
}
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }
.sq.light .coord { color: #4e7d4e; }
.sq.dark  .coord { color: #e7d6b0; }

/* ----- side panel ----- */
.chess-side {
  width: min(92vw, 300px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chess-status {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  min-height: 20px;
}

.chess-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chess-controls button { flex: 1 1 auto; }

.chess-ai-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
}
.chess-ai-controls label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  gap: 10px;
}
.chess-ai-controls select {
  background: #1a1410;
  color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
}

.chess-moves-wrap {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  overflow: hidden;
  flex: 1;
}
.moves-label {
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.chess-moves {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: 320px;
  overflow-y: auto;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}
.chess-moves li {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 6px;
  padding: 2px 12px;
}
.chess-moves li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.chess-moves .mv-no { color: var(--muted); }
.chess-moves .mv-w, .chess-moves .mv-b { color: var(--text); }

/* ----- promotion picker ----- */
.chess-promo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
}
.chess-promo.hidden { display: none; }
.promo-card {
  background: #16110c;
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 20px 24px;
  text-align: center;
}
.promo-card p { margin: 0 0 12px; color: var(--muted); }
.promo-options { display: flex; gap: 8px; margin-bottom: 12px; }
.promo-options button {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #4e7d4e;
  border-radius: 8px;
}
.promo-options button:hover { background: #5e9460; }
.promo-options .cp { font-size: 42px; }

/* ----- responsive ----- */
@media (max-width: 760px) {
  .chess-table { flex-direction: column; align-items: center; }
  .chess-side { width: min(92vw, 600px); }
  .chess-moves { max-height: 160px; }
}
