:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --border: rgba(255, 255, 255, 0.1);
  --border-light: rgba(255, 255, 255, 0.05);
  
  --board-light: #e2e8f0;
  --board-dark: #475569;
  --board-border: #1e293b;
  
  --accent-gold: #f59e0b;
  --accent-green: #10b981;
  --accent-blue: #3b82f6;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --square-size: 72px;
}

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

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2.5rem;
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* Main Layout */
.main-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 2.5rem;
  padding: 2.5rem 2rem;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
}

/* Left / Board Section */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.player-bar {
  width: calc(var(--square-size) * 8 + 32px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.graveyard {
  display: flex;
  gap: 4px;
  font-size: 1.2rem;
  min-height: 24px;
}

/* The Chessboard Container */
.board-frame {
  position: relative;
  padding: 16px;
  background: var(--board-border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border);
}

.chessboard {
  display: grid;
  grid-template-columns: repeat(8, var(--square-size));
  grid-template-rows: repeat(8, var(--square-size));
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: var(--square-size);
  height: var(--square-size);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

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

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

.square.selected {
  background-color: var(--accent-gold) !important;
}

.square.last-move {
  background-color: rgba(245, 158, 11, 0.4) !important;
}

/* Coordinate Labels */
.square-coord-file, .square-coord-rank {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
  opacity: 0.7;
}

.square-coord-file {
  bottom: 2px;
  right: 4px;
}

.square-coord-rank {
  top: 2px;
  left: 4px;
}

.square.light .square-coord-file, .square.light .square-coord-rank {
  color: var(--board-dark);
}

.square.dark .square-coord-file, .square.dark .square-coord-rank {
  color: var(--board-light);
}

/* Valid Move Indicator Dot */
.valid-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.75);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  pointer-events: none;
}

.valid-dot.capture {
  width: 58px;
  height: 58px;
  background: transparent;
  border: 4px solid rgba(239, 68, 68, 0.85);
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.6);
  border-radius: 50%;
  animation: pulse-capture 1.2s infinite ease-in-out;
}

@keyframes pulse-capture {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(0.92); opacity: 0.6; }
}

/* King in Check Red Glow Highlight */
.square.check {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.9) 0%, rgba(220, 38, 38, 0.5) 65%, transparent 100%) !important;
  animation: check-pulse 1s infinite alternate;
}

@keyframes check-pulse {
  0% { box-shadow: inset 0 0 12px #ef4444; }
  100% { box-shadow: inset 0 0 32px #b91c1c; }
}

/* Chess Piece Icons */
.piece {
  font-size: 46px;
  line-height: 1;
  transition: transform 0.1s ease;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

.piece:hover {
  transform: scale(1.1);
}

.piece.white {
  color: #ffffff;
  text-shadow: 0 0 2px #000, 0 1px 3px rgba(0,0,0,0.8);
}

.piece.black {
  color: #1a1a1a;
  text-shadow: 0 0 2px #fff, 0 1px 3px rgba(0,0,0,0.8);
}

/* Right / Sidebar Section */
.sidebar {
  flex: 1;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  backdrop-filter: blur(10px);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Action Controls */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.btn-primary:hover {
  background: #2563eb;
  border-color: #2563eb;
}

/* Move History Table */
.move-history-container {
  height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
}

.move-table {
  width: 100%;
  border-collapse: collapse;
}

.move-table th {
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.move-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-light);
}

.move-table tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Log / Console Messages */
.engine-toast {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
  display: none;
}

.engine-toast.active {
  display: block;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Tech Spec Badges */
.tech-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tech-pill {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Modal Overlays (Promotion & Game Over) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  padding: 2rem;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

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

.promo-btn {
  width: 68px;
  height: 68px;
  font-size: 40px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.promo-btn:hover {
  background: var(--accent-blue);
  border-color: #60a5fa;
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.4);
}

/* Status Indicator States */
.status-badge.check-alert {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #ef4444 !important;
  border-color: rgba(239, 68, 68, 0.4) !important;
}

.status-badge.check-alert .status-dot {
  background: #ef4444 !important;
  box-shadow: 0 0 12px #ef4444 !important;
}

.status-badge.mate-alert {
  background: rgba(245, 158, 11, 0.18) !important;
  color: #f59e0b !important;
  border-color: rgba(245, 158, 11, 0.5) !important;
}

.status-badge.mate-alert .status-dot {
  background: #f59e0b !important;
  box-shadow: 0 0 12px #f59e0b !important;
}

