:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.8);
  --border-color: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --board-light: #e8edf2;
  --board-dark: #6884ab;
  --board-frame: #2a3547;
  --highlight-selected: rgba(232, 176, 64, 0.42);
  --highlight-last: rgba(214, 177, 70, 0.48);
  --highlight-hover: rgba(255, 255, 255, 0.10);
  --highlight-hover-light: rgba(0, 0, 0, 0.06);
  --legal-dot: rgba(20, 20, 20, 0.28);
  --legal-capture: rgba(239, 68, 68, 0.42);
  --check-fill: rgba(239, 68, 68, 0.45);
  --checkmate-fill: rgba(185, 28, 28, 0.65);
  --clock-active: #d8eccf;
  --clock-low: #f3c4b8;
  --radius-lg: 12px;
  --radius-md: 8px;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

[data-board-theme="classic"] {
  --board-light: #e8edf2;
  --board-dark: #6884ab;
  --board-frame: #2a3547;
}

[data-board-theme="wood_green"] {
  --board-light: #ead7b2;
  --board-dark: #5f7a56;
  --board-frame: #3d4a42;
}

[data-board-theme="walnut_brown"] {
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-frame: #53382c;
}

[data-board-theme="dark_slate"] {
  --board-light: #cfd8dc;
  --board-dark: #455a64;
  --board-frame: #1c272c;
}

[data-board-theme="purple"] {
  --board-light: #e2d5f8;
  --board-dark: #705494;
  --board-frame: #3a2356;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: var(--accent-color);
}

.user-badge {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.role-pill {
  background: var(--accent-color);
  color: white;
  padding: 0.1rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 600;
}

.container {
  max-width: 1200px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
  flex: 1;
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--accent-color);
  color: white;
}
.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
}
.btn-danger:hover {
  opacity: 0.9;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.form-input, .form-select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent-color);
}

/* Chess Game Layout */
.game-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 900px) {
  .game-container {
    grid-template-columns: 1fr;
  }
}

.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  width: 100%;
}

.board-stage {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 100%;
}

.player-bar {
  width: min(560px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 600;
  min-width: 0;
}

.player-color-mark {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
}

.player-color-mark.white {
  background: #f4efe3;
}

.player-color-mark.black {
  background: #2a2b30;
}

.player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timer {
  background: #0b1220;
  border: 1px solid var(--border-color);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  min-width: 5.2rem;
  text-align: center;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.timer.active {
  background: var(--clock-active);
  border-color: #7ea57a;
  color: #163018;
}

.timer.low {
  background: var(--clock-low);
  border-color: #c97868;
  color: #5a1d14;
}

.chessboard {
  --board-size: min(560px, calc(100vw - 2rem));
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  border: 8px solid var(--board-frame);
  user-select: none;
  background: var(--board-frame);
}

@media (max-width: 900px) {
  .chessboard {
    --board-size: min(560px, calc(100vw - 2rem));
  }
}

.square {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
}

.square.light {
  background-color: var(--board-light);
}

.square.dark {
  background-color: var(--board-dark);
}

.square.last-move::before,
.square.selected::before,
.square.in-check::before,
.square.in-checkmate::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.square.last-move::before {
  background: var(--highlight-last);
}

.square.selected::before {
  background: var(--highlight-selected);
  box-shadow: inset 0 0 0 2px rgba(120, 84, 24, 0.35);
}

.square.in-check::before {
  background: radial-gradient(circle at center, var(--check-fill) 0%, transparent 72%);
}

.square.in-checkmate::before {
  background: radial-gradient(circle at center, var(--checkmate-fill) 0%, rgba(120, 20, 20, 0.28) 70%, transparent 100%);
  box-shadow: inset 0 0 0 3px rgba(120, 24, 24, 0.45);
}

@media (hover: hover) and (pointer: fine) {
  .square.light:hover {
    box-shadow: inset 0 0 0 999px var(--highlight-hover-light);
  }
  .square.dark:hover {
    box-shadow: inset 0 0 0 999px var(--highlight-hover);
  }
}

.square.legal-move::after {
  content: '';
  width: 28%;
  height: 28%;
  max-width: 18px;
  max-height: 18px;
  background-color: var(--legal-dot);
  border-radius: 50%;
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.square.legal-capture::after {
  content: '';
  position: absolute;
  inset: 8%;
  border: 3.5px solid var(--legal-capture);
  border-radius: 50%;
  z-index: 5;
  pointer-events: none;
  background: transparent;
}

.piece {
  width: 86%;
  height: 86%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.piece.piece-animating {
  transition: transform 0.16s ease-out;
  z-index: 6;
  will-change: transform;
}

.piece-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}

.coord {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.78;
  z-index: 3;
  pointer-events: none;
  line-height: 1;
}

.coord-file {
  bottom: 3px;
  right: 5px;
}

.coord-rank {
  top: 3px;
  left: 5px;
}

.square.light .coord { color: #4d6246; }
.square.dark .coord { color: #f0e2c6; }

/* Game Sidebar */
.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

.game-meta-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.connection-status {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
  font-weight: 600;
}

.connection-status.online {
  background: rgba(16, 185, 129, 0.18);
  color: var(--success-color);
}

.connection-status.offline {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

.turn-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.turn-value {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-top: 0.15rem;
}

.check-alert {
  display: none;
  background: rgba(190, 58, 48, 0.16);
  color: #f3b4ae;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  text-align: center;
  margin-bottom: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid rgba(190, 58, 48, 0.35);
}

.check-alert.visible {
  display: block;
}

.draw-offer-banner {
  display: none;
  background: rgba(245, 158, 11, 0.14);
  color: #f5c56b;
  padding: 0.75rem;
  border-radius: 8px;
  text-align: center;
  margin-bottom: 1rem;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.game-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.move-history {
  height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  background: var(--bg-primary);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

.move-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr 1fr;
  gap: 0.25rem;
  padding: 0.32rem 0.5rem;
  border-radius: 6px;
  align-items: center;
}

.move-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.move-row.current,
.move-row:last-child {
  background: rgba(59, 130, 246, 0.12);
}

.move-num {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.move-san {
  color: var(--text-primary);
}

.move-san.is-last {
  font-weight: 700;
  color: #f2e2b6;
}

.status-badge {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
}

.status-in_progress { background: rgba(59, 130, 246, 0.2); color: var(--accent-color); border: 1px solid var(--accent-color); }
.status-finished { background: rgba(16, 185, 129, 0.2); color: var(--success-color); border: 1px solid var(--success-color); }

.eval-bar {
  width: 18px;
  flex-shrink: 0;
  align-self: stretch;
  min-height: 0;
  background: #1a2233;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
}

.eval-bar-white,
.eval-bar-black {
  width: 100%;
  transition: height 0.25s ease;
}

.eval-bar-white { background: #f4efe3; }
.eval-bar-black { background: #1a1b20; }

.piece-palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 1rem;
  width: min(560px, 100%);
}

.palette-piece {
  min-height: 52px;
  padding: 0.25rem;
}

.palette-piece .piece {
  width: 100%;
  height: 36px;
}

.palette-piece.is-active {
  outline: 2px solid var(--accent-color);
  outline-offset: 1px;
}

/* Promotion Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.promotion-choices {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.promotion-choice {
  width: 68px;
  height: 68px;
  background: var(--board-light);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.promotion-choice .piece {
  width: 88%;
  height: 88%;
}

.promotion-choice:hover,
.promotion-choice:focus-visible {
  border-color: var(--accent-color);
  transform: translateY(-1px);
}

.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible,
.promotion-choice:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* ============================================
   PWA - Configuración y Menú
   ============================================ */

.settings-container {
  position: relative;
  display: inline-block;
}

.settings-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.6rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.2s ease;
  line-height: 1;
}

.settings-btn:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.settings-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 200;
}

.settings-menu.open {
  display: flex;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background-color 0.15s ease;
}

.settings-item:hover {
  background: rgba(59, 130, 246, 0.12);
}

.settings-item-danger {
  color: var(--danger-color);
}

.settings-item-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* Botón Instalar Aplicación */
#install-app-btn {
  white-space: nowrap;
}

/* Modal de desinstalación */
#uninstall-modal .modal-content {
  max-width: 480px;
  text-align: left;
}

#uninstall-modal .modal-content h3 {
  text-align: center;
}

#uninstall-modal .modal-content p {
  margin-bottom: 0.75rem;
}

#uninstall-modal .modal-content #uninstall-instructions p {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  border-left: 3px solid var(--accent-color);
}

#uninstall-modal .modal-content #uninstall-instructions p strong {
  color: var(--text-primary);
}

#uninstall-modal .modal-content .btn {
  width: 100%;
}

@media (max-width: 600px) {
  .container {
    margin: 1rem auto;
  }
  .navbar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .nav-links {
    gap: 0.75rem;
    flex-wrap: wrap;
  }
  .chessboard {
    --board-size: min(560px, calc(100vw - 1.5rem));
    border-width: 6px;
  }
  .timer {
    font-size: 1.05rem;
    min-width: 4.6rem;
    padding: 0.25rem 0.5rem;
  }
  .coord {
    font-size: 0.55rem;
  }
  .settings-menu {
    position: fixed;
    top: auto;
    right: 1rem;
    bottom: 1rem;
    left: 1rem;
    min-width: auto;
  }
}

