/* === Reset y base === */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: #312e2b;
  color: #e8e6e3;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.header { text-align: center; margin-bottom: 20px; }
.header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.header h1 .muted { color: #999693; font-weight: 400; }
.status {
  margin: 0;
  color: #b8b6b4;
  font-size: 14px;
  min-height: 21px;
}
.status strong { color: #f5f5f4; font-weight: 600; }
.status .check { color: #ff8a80; }

/* === Controles === */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 16px;
  align-items: center;
}
.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #b8b6b4;
}
select, .btn {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid #4a4744;
  background: #3d3a37;
  color: #e8e6e3;
  cursor: pointer;
  transition: all 0.15s ease;
}
select:hover, .btn:hover:not(:disabled) {
  background: #4a4744;
  border-color: #5a5754;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary {
  background: #769656;
  border-color: #769656;
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover:not(:disabled) {
  background: #82a767;
  border-color: #82a767;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Tablero === */
.board-wrap {
  position: relative;
  margin: 0 auto;
  max-width: 560px;
}
.board {
  display: grid;
  grid-template-columns: 22px repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr) 22px;
  aspect-ratio: 9 / 9;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: clamp(28px, 7vw, 44px);
  line-height: 1;
  transition: background 0.1s;
}
.sq.light { background: #f0d9b5; }
.sq.dark { background: #b58863; }
.sq.selected { background: #f7ec74 !important; }
.sq.last-move { background: #cdd26a !important; }
.sq.in-check {
  background: radial-gradient(circle, #ff5252 0%, #b58863 75%) !important;
}
.sq.light.in-check {
  background: radial-gradient(circle, #ff5252 0%, #f0d9b5 75%) !important;
}
.sq .piece {
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}
.sq .piece.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 2px #000; }
.sq .piece.b { color: #1a1a1a; }
.sq .move-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.sq .capture-ring {
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}
.coord {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #b8b6b4;
  background: #312e2b;
}

/* Tablero volteado: invertir el orden visual */
.board.flipped .sq,
.board.flipped .coord {
  transform: rotate(180deg);
}
.board.flipped {
  transform: rotate(180deg);
}

/* === Modal === */
.modal-host { position: absolute; inset: 0; pointer-events: none; }
.modal-host.active { pointer-events: auto; }
.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  animation: fade-in 0.2s ease;
}
.modal {
  background: #3d3a37;
  border: 1px solid #4a4744;
  border-radius: 8px;
  padding: 24px 28px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
.modal h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
}
.modal p {
  margin: 0 0 16px;
  color: #b8b6b4;
  font-size: 14px;
}
.promo {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.promo button {
  font-size: 36px;
  padding: 8px 14px;
  background: #4a4744;
  border: 1px solid #5a5754;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
}
.promo button:hover { background: #5a5754; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* === Información === */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.panel {
  background: #3d3a37;
  border: 1px solid #4a4744;
  border-radius: 8px;
  padding: 10px 14px;
}
.panel-label {
  font-size: 12px;
  color: #b8b6b4;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.captured {
  font-size: 22px;
  line-height: 1.3;
  word-break: break-all;
  min-height: 28px;
}
.history-panel { margin-top: 10px; }
.history {
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.6;
  color: #d4d2d0;
}

/* === Indicador "pensando" === */
.thinking-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #769656;
  margin-left: 6px;
  vertical-align: middle;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* === Footer === */
.footer {
  text-align: center;
  margin-top: 32px;
  font-size: 12px;
  color: #777472;
}
.footer p { margin: 0; }

/* === Móvil === */
@media (max-width: 480px) {
  .app { padding: 16px 10px 32px; }
  .header h1 { font-size: 22px; }
  .controls { gap: 6px; }
  select, .btn { padding: 7px 10px; font-size: 13px; }
  .board { grid-template-columns: 18px repeat(8, 1fr); grid-template-rows: repeat(8, 1fr) 18px; }
  .modal { padding: 18px 20px; max-width: 280px; }
  .promo button { font-size: 30px; padding: 6px 10px; }
}
