/* =========================================================================
   Chess Board Styles — Sleek Modern Theme with Blue Outlines
   Vector SVG Pieces (45x45 viewBox, 100% square scaling)
   Chess.com-Style Board Layout, Scaling Controls & Eval Bar
   ========================================================================= */

.board-layout {
  display: flex;
  gap: 20px;
  max-width: 1440px;
  width: 100%;
  align-items: flex-start;
  justify-content: center;
  animation: fadeIn 300ms ease;
  margin: 0 auto;
}

/* --- Chess.com Style Eval Bar --- */
.eval-bar-container {
  width: 28px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  align-self: stretch;
}

.eval-bar-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  color: var(--cyan);
  text-align: center;
  padding: 3px 6px;
  background: #111726;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 6px;
  min-width: 38px;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

.eval-bar {
  width: 24px;
  flex: 1;
  min-height: 380px;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: #1e293b; /* Black side */
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.15), inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

.eval-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #e2e8f0; /* White side */
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.45);
  transition: height 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  height: 50%;
}

/* --- Chess Board Wrapper & Grid --- */
.board-wrapper {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chess-board-outer {
  position: relative;
  display: inline-block;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 1 / 1;
  background: #0f172a;
  border: 2px solid rgba(56, 189, 248, 0.4);
  box-shadow: 
    0 0 0 1px rgba(56, 189, 248, 0.15),
    0 0 24px -2px rgba(56, 189, 248, 0.28),
    0 24px 64px -12px rgba(0, 0, 0, 0.85);
  user-select: none;
  -webkit-user-select: none;
  width: var(--board-custom-size, min(700px, calc(100vw - 360px), 78vh));
  height: var(--board-custom-size, min(700px, calc(100vw - 360px), 78vh));
  max-width: min(920px, calc(100vw - 32px), 86vh);
  max-height: min(920px, calc(100vw - 32px), 86vh);
  min-width: 320px;
  min-height: 320px;
}

/* Blue Chess.com Theme & Board Mechanics */
:root {
  --bg-main: #0f172a;
  --bg-panel: #1e293b;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --board-light: #eae9d2;
  --board-dark: #4b7399;
}

/* Hide original piece on square ONLY while an active dragging clone is in motion */
body.dragging-active .square .chess-piece.is-dragging,
body.dragging-active .square .piece.is-dragging,
body:has(.piece.dragging) .square .chess-piece.is-dragging,
body:has(.piece.dragging) .square .piece.is-dragging {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Fallback: when not actively dragging, pieces on squares must always remain visible */
body:not(.dragging-active) .square .chess-piece,
body:not(.dragging-active) .square .piece {
  opacity: 1 !important;
  visibility: visible !important;
}

/* King in Check Highlight */
.square.in-check {
  background: radial-gradient(ellipse at center, rgba(255, 0, 0, 0.85) 0%, rgba(231, 0, 0, 0.5) 45%, rgba(169, 0, 0, 0) 89%) !important;
}

/* Analysis & Premove Square Highlights */
.square.highlight-analysis {
  background-color: rgba(59, 130, 246, 0.45) !important;
}
.square.highlight-premove {
  background-color: rgba(239, 68, 68, 0.45) !important;
}

/* Corner Resize Handle Only */
.bottom-resize-bar { display: none !important; }
.board-controls-toolbar { display: none !important; }
.board-resize-handle {
  position: absolute;
  bottom: 2px;
  right: 2px;
  cursor: nwse-resize;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: transparent;
  border: none;
  box-shadow: none;
  transition: transform var(--transition-fast);
}

.board-resize-handle:hover,
.board-resize-handle.active {
  transform: scale(1.2);
}

.board-resize-handle svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}


.board-scale-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.board-scale-slider-wrap label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.board-scale-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 5px;
  background: #1e293b;
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

.board-scale-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.7);
  cursor: pointer;
  transition: transform 120ms ease;
}

.board-scale-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* --- Square Styling --- */
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: background-color var(--transition-fast);
}

.square-light {
  background: var(--board-light, #eae9d2);
}

.square-dark {
  background: var(--board-dark, #4b7399);
}

/* In-Square Chess.com Coordinates */
.coord-in-square {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 2;
  opacity: 0.85;
}

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

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

.square-light .coord-in-square {
  color: var(--board-dark, #4b7399);
}

.square-dark .coord-in-square {
  color: var(--board-light, #eae9d2);
}

/* Last move highlight - Chess.com soft warm amber */
.square.last-move-from::before,
.square.last-move-to::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(245, 158, 11, 0.32);
  pointer-events: none;
  z-index: 1;
}

/* Selected square - Glowing Cyan outline */
.square.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(56, 189, 248, 0.28);
  box-shadow: inset 0 0 0 3px rgba(56, 189, 248, 0.85);
  pointer-events: none;
  z-index: 1;
}

/* Legal move dots - Chess.com disk */
.square.legal-move::after {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.38);
  pointer-events: none;
  z-index: 2;
}

/* Legal capture ring - Chess.com ring */
.square.legal-capture::after {
  content: '';
  position: absolute;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  border: 4px solid rgba(15, 23, 42, 0.38);
  background: transparent;
  pointer-events: none;
  z-index: 2;
}

/* King in Check Highlight */
.square.in-check {
  background: radial-gradient(ellipse at center, rgba(255, 0, 0, 0.85) 0%, rgba(231, 0, 0, 0.5) 45%, rgba(169, 0, 0, 0) 89%) !important;
}

/* Analysis & Premove Square Highlights */
.square.highlight-analysis,
.square.analysis-from,
.square.analysis-to {
  background-color: rgba(59, 130, 246, 0.45) !important;
}

.square.highlight-premove,
.square.premove-from::before,
.square.premove-to::before {
  background-color: rgba(239, 68, 68, 0.45) !important;
}

/* Evaluation Classification Badges on Squares & Move List */
.square-eval-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  z-index: 15;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
  animation: badgePop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.eval-icon {
  width: 24px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
}

@keyframes badgePop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Right-click annotations */
.square.highlight-green::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(34, 197, 94, 0.32);
  pointer-events: none;
  z-index: 2;
}

.square.highlight-cyan::before,
.square.highlight-blue::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(59, 130, 246, 0.35);
  pointer-events: none;
  z-index: 2;
}

.square.highlight-red::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(239, 68, 68, 0.32);
  pointer-events: none;
  z-index: 2;
}

/* --- SVG Piece Styling (exact user requested class & rules) --- */
.chess-piece {
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none; /* Drag and drop on parent square */
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
  display: block;
}

.piece {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform var(--transition-fast);
}

.piece svg {
  width: 100%;
  height: 100%;
}

.square:hover .piece {
  transform: scale(1.03);
}

/* Dragging piece clone */
.piece.dragging {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transform: translate(-50%, -50%) scale(1.14);
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.75));
  cursor: grabbing;
}

.piece.dragging svg {
  width: 100%;
  height: 100%;
}

/* --- SVG Arrow Overlay --- */
.board-arrows-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* Edge Coordinates (fallback if enabled) */
.board-coords-rank,
.board-coords-file {
  display: none;
}

/* --- Player Bars (Chess.com layout) --- */
.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: var(--p-card);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  gap: 12px;
}

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

.player-avatar-wrap {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  background: #0b0f19;
  border: 1px solid rgba(56, 189, 248, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-avatar-svg {
  width: 28px;
  height: 28px;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.player-rating {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

/* Digital Chess Clock (Chess.com style) */
.player-clock {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 6px;
  background: #090d16;
  color: var(--text-primary);
  border: 1px solid rgba(148, 163, 184, 0.2);
  letter-spacing: 0.04em;
  transition: all var(--transition-fast);
}

.player-clock.active-turn {
  background: #0e1e36;
  color: var(--cyan);
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
}

.player-clock.low-time {
  background: rgba(239, 68, 68, 0.18);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.6);
  animation: clockUrgent 1s infinite alternate;
}

@keyframes clockUrgent {
  0% { transform: scale(1); }
  100% { transform: scale(1.03); }
}

/* Captured Pieces Display */
.captured-pieces {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 32px;
}

.captured-group {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 3px 6px;
  gap: 4px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.captured-group:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.captured-piece-svg {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.captured-piece-svg svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.captured-count {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.material-diff-badge {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.18);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

/* Promotion Modal */
.promotion-pieces {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 14px;
}

.promotion-piece {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  background: #141c2b;
  border: 1px solid rgba(56, 189, 248, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: all var(--transition-fast);
}

.promotion-piece:hover {
  background: #1c2b46;
  border-color: var(--cyan);
  transform: translateY(-2px);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.4);
}

/* =========================================================================
   Developer Spec Additions: Eval Bar, Top 3 Lines & Post-Game Right Panel
   ========================================================================= */

/* Ensure board arrows layer never has conflicting CSS transform */
#board-arrows,
.board-arrows-layer {
  transform: none !important;
}

/* Evaluation Bar */
.eval-bar {
  width: 26px;
  height: 100%;
  background: #1e293b; /* Black advantage side */
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin-right: 10px;
  border: 1px solid rgba(255,255,255,0.1);
}
.eval-fill {
  width: 100%;
  background: #f8fafc; /* White advantage fill */
  transition: height 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.eval-score {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: #3b82f6;
  mix-blend-mode: difference;
}

/* Engine Top 3 Lines */
.engine-lines { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.engine-line {
  display: flex; align-items: center; gap: 10px;
  background: rgba(15, 23, 42, 0.6);
  padding: 7px 10px; border-radius: 6px;
  font-size: 0.84rem; font-family: monospace;
  cursor: pointer;
  transition: background 0.15s ease;
}
.engine-line:hover {
  background: rgba(30, 41, 59, 0.85);
}
.line-eval {
  background: #334155; color: #f8fafc;
  padding: 2px 6px; border-radius: 4px;
  font-weight: 700; min-width: 48px; text-align: center;
}
.line-eval.blue-eval { background: #3b82f6; color: #fff; }
.line-moves { color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Post-Game Right Panel */
.game-over-header { text-align: center; margin-bottom: 16px; }
.game-over-header h2 { font-size: 1.5rem; color: #f8fafc; }
.game-over-header p { font-size: 0.85rem; color: #94a3b8; }
.accuracy-box {
  display: flex; justify-content: space-around;
  background: rgba(15, 23, 42, 0.55);
  padding: 14px; border-radius: 8px; margin-bottom: 16px;
}
.acc-player { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.acc-label { font-size: 0.75rem; color: #94a3b8; }
.acc-val { font-size: 1.1rem; padding: 4px 10px; border-radius: 6px; background: #334155; }
.acc-val.blue-badge { background: #3b82f6; color: #fff; }
.review-cta { text-align: center; margin-bottom: 12px; display: flex; flex-direction: column; align-items: center; text-decoration: none; padding: 10px 16px; border-radius: 8px; }
.review-cta span { font-size: 0.75rem; opacity: 0.85; }
.post-game-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.post-game-actions button { border: none; cursor: pointer; text-align: center; font-weight: 700; padding: 9px 12px; border-radius: 6px; }

