/* Chess Board Styles - EL3AB Pro */

:root {
  /* Chess Layout */
  --chess-board-max: 580px;
  --chess-board-radius: 4px;
  --chess-board-shadow: 0 2px 10px rgba(0,0,0,0.4);
  --chess-board-border: none;
  /* Chess Pieces */
  --chess-piece-size: min(11vw, 62px);
  --chess-piece-white: #fff;
  --chess-piece-white-stroke: 1px #555;
  --chess-piece-black: #222;
  --chess-piece-black-stroke: 0.5px #000;
  --chess-piece-shadow: 0 1px 2px rgba(0,0,0,0.3);
  --chess-piece-hover-scale: 1.05;
  --chess-piece-drag-scale: 1.15;
  /* Chess Legal Moves */
  --chess-legal-dot-size: 28%;
  --chess-legal-capture-size: 88%;
  --chess-legal-capture-border: 4px;
  /* Chess Clock */
  --chess-clock-bg: var(--bg-3);
  --chess-clock-text: var(--text-1);
  --chess-clock-active-bg: var(--gold);
  --chess-clock-active-text: var(--text-inverse);
  --chess-clock-radius: 8px;
  --chess-clock-font-size: 20px;
  --chess-clock-padding: 8px 14px;
  /* Chess Coords */
  --chess-coords-size: 11px;
  --chess-coords-weight: 700;
  /* Chess Panel */
  --chess-panel-width: 260px;
  --chess-panel-bg: var(--bg-2);
  --chess-panel-radius: var(--radius-md);
  --chess-move-font-size: 13px;
  --chess-move-active-bg: var(--cyan);
  /* Chess Eval Bar */
  --chess-eval-width: 18px;
  --chess-eval-radius: 4px;
  /* Chess Game Header */
  --chess-header-padding: 10px 14px;
  --chess-header-radius: 12px;
  --chess-header-bg: var(--bg-2);
  --chess-player-font-size: 14px;
  --chess-rating-font-size: 11px;
}

/* ============================================
   GAME LAYOUT
   ============================================ */

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 100%;
  direction: ltr;
}

.game-board-column {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: center;
}

/* Player info + clock rows */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 560px;
  direction: rtl;
}

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

.game-player-name {
  font-size: var(--chess-player-font-size);
  font-weight: 600;
}

.game-player-rating {
  font-size: var(--chess-rating-font-size);
  color: var(--text-3);
  font-family: var(--font-en);
}

.game-clock {
  font-family: var(--font-en);
  font-size: 20px;
  font-weight: 700;
  padding: 8px 14px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  min-width: 80px;
  text-align: center;
  direction: ltr;
}

.game-clock.active {
  background: var(--gold);
  color: var(--text-inverse);
}

.game-clock.low {
  background: var(--error);
  color: var(--eval-label-light);
  animation: clock-pulse 1s ease infinite;
}

@keyframes clock-pulse {
  50% { opacity: 0.7; }
}

/* ============================================
   BOARD
   ============================================ */

.game-board-section {
  display: flex;
  gap: 4px;
  align-items: stretch;
  width: 100%;
  max-width: 580px;
  margin: 4px auto;
}

.board-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
  direction: ltr;
}

.board-wrapper::before {
  content: '';
  display: block;
  padding-top: 100%;
}

.board-wrapper > .board {
  position: absolute;
  inset: 0;
}

/* Standalone board (puzzles page etc) */
.puzzle-board-area .board-wrapper {
  max-width: 480px;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--chess-board-radius);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  direction: ltr;
  box-shadow: var(--chess-board-shadow);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
}

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

.square.selected { background: var(--board-selected) !important; }
.square.legal-move::after {
  content: '';
  position: absolute;
  width: var(--chess-legal-dot-size);
  height: var(--chess-legal-dot-size);
  border-radius: 50%;
  background: var(--board-legal);
}
.square.legal-capture::after {
  content: '';
  position: absolute;
  width: var(--chess-legal-capture-size);
  height: var(--chess-legal-capture-size);
  border-radius: 50%;
  border: var(--chess-legal-capture-border) solid var(--board-legal);
  background: transparent;
}

.square.last-move { background: var(--board-last-move) !important; }
.square.in-check {
  background: var(--board-check) !important;
  box-shadow: inset 0 0 12px rgba(255,0,0,0.6);
}
.square.premove-from { background: var(--board-premove) !important; }
.square.premove-to { background: var(--board-premove) !important; }
.square.highlight-green { background: var(--board-highlight-green) !important; }
.square.highlight-red { background: var(--board-highlight-red) !important; }
.square.highlight-yellow { background: var(--board-highlight-yellow) !important; }

/* Pieces */
.piece {
  width: 100%;
  height: 100%;
  font-size: var(--chess-piece-size);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  z-index: 1;
  user-select: none;
  transition: transform 0.1s ease;
}

.piece[data-color="w"] {
  color: var(--chess-piece-white);
  -webkit-text-stroke: var(--chess-piece-white-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(var(--chess-piece-shadow));
}

.piece[data-color="b"] {
  color: var(--chess-piece-black);
  -webkit-text-stroke: var(--chess-piece-black-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(var(--chess-piece-shadow));
}

.piece:hover {
  transform: scale(var(--chess-piece-hover-scale));
}

.piece:active { cursor: grabbing; }
.piece.dragging {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  transform: scale(1.15);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

/* Coordinate labels - inside squares like Chess.com */
.board-coords-file, .board-coords-rank {
  position: absolute;
  display: flex;
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  z-index: 6;
}

.board-coords-file {
  bottom: 2px;
  left: 0;
  right: 0;
}

.board-coords-file span {
  flex: 1;
  text-align: right;
  padding-right: 3px;
}

.board-coords-file span:nth-child(odd) {
  color: var(--board-dark);
}
.board-coords-file span:nth-child(even) {
  color: var(--board-light);
}

.board-coords-rank {
  top: 0;
  bottom: 0;
  left: 2px;
  flex-direction: column;
}

.board-coords-rank span {
  flex: 1;
  display: flex;
  align-items: flex-start;
  padding-top: 2px;
}

.board-coords-rank span:nth-child(odd) {
  color: var(--board-light);
}
.board-coords-rank span:nth-child(even) {
  color: var(--board-dark);
}

/* Arrow Canvas */
.arrow-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* Eval Bar */
.eval-bar {
  width: 18px;
  min-width: 18px;
  background: var(--eval-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.eval-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--eval-white);
  transition: height 0.5s ease;
  height: 50%;
}

.eval-bar-label {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-en);
  font-size: 8px;
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
}

.eval-bar-label-top { top: 3px; color: var(--eval-label-light); }
.eval-bar-label-bottom { bottom: 3px; color: var(--eval-label-dark); }

/* ============================================
   SIDE PANEL
   ============================================ */

.game-side-panel {
  display: none;
  flex-direction: column;
  width: 260px;
  min-width: 240px;
}

.analysis-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

/* Opening Display */
.opening-display {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  direction: ltr;
}

.opening-eco {
  font-family: var(--font-en);
  font-weight: 700;
  color: var(--cyan);
  font-size: 11px;
}

.opening-name {
  font-weight: 500;
  font-family: var(--font-en);
}

/* Pro Move List */
.move-list-pro {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-en);
  font-size: 13px;
  direction: ltr;
  text-align: left;
  padding: 6px 0;
  min-height: 80px;
  max-height: 300px;
}

.move-list-pro .move-pair {
  display: flex;
  align-items: center;
  padding: 4px 12px;
  gap: 4px;
}

.move-list-pro .move-pair:nth-child(odd) {
  background: rgba(255,255,255,0.03);
}

.move-list-pro .move-number {
  color: var(--text-3);
  min-width: 28px;
  font-size: 12px;
}

.move-list-pro .move {
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 50px;
  text-align: center;
  font-weight: 500;
}

.move-list-pro .move:hover {
  background: rgba(255,255,255,0.08);
}

.move-list-pro .move.current {
  background: var(--cyan);
  color: var(--text-inverse);
}

/* Game Status */
.panel-status {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  text-align: center;
  color: var(--text-2);
  direction: rtl;
}

/* Panel Controls Row */
.panel-controls {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  direction: rtl;
}

.panel-controls .btn {
  flex: 1;
  font-size: 12px;
  padding: 8px 6px;
  min-width: 0;
}

/* Draw offer banner */
.draw-offer-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: rgba(255, 199, 40, 0.1);
  direction: rtl;
  font-size: 13px;
  font-weight: 600;
}

.draw-offer-actions {
  display: flex;
  gap: 6px;
}

/* Post-game Controls */
.postgame-controls {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.postgame-controls .btn {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 8px 6px;
}

/* ============================================
   THINKING INDICATOR
   ============================================ */

.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-2);
  direction: rtl;
  max-width: 560px;
  width: 100%;
}

.thinking-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  animation: thinking-bounce 1.4s infinite;
  margin: 0 2px;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Pre-move indicator */
.premove-indicator {
  font-size: 11px;
  color: var(--cyan);
  padding: 4px 14px;
  max-width: 560px;
  width: 100%;
  direction: rtl;
}

/* ============================================
   GAME RESULT OVERLAY
   ============================================ */

.game-result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--overlay-result);
  z-index: 10;
  border-radius: var(--radius-sm);
  gap: 12px;
  direction: ltr;
}

.game-result-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
}

.game-result-subtitle {
  font-size: 13px;
  color: var(--text-2);
}

.game-result-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  font-family: var(--font-en);
  font-size: 13px;
  width: 180px;
}

.game-result-stats .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  color: var(--text-2);
}

.game-result-stats .stat-row span:last-child {
  font-weight: 600;
  color: var(--text-1);
}

/* ============================================
   PROMOTION MODAL
   ============================================ */

.promotion-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  gap: 8px;
  z-index: 20;
  box-shadow: var(--shadow-lg);
}

.promotion-piece {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.promotion-piece:hover { background: var(--cyan); }

/* ============================================
   MOVE BADGES (Analysis)
   ============================================ */

.move-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-en);
  margin-inline-start: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

.move-brilliant { background: var(--move-brilliant); color: var(--eval-label-light); }
.move-great { background: var(--move-great); color: var(--eval-label-light); }
.move-good { background: var(--move-good); color: var(--eval-label-light); }
.move-inaccuracy { background: var(--move-inaccuracy); color: var(--eval-label-dark); }
.move-mistake { background: var(--move-mistake); color: var(--eval-label-light); }
.move-blunder { background: var(--move-blunder); color: var(--eval-label-light); }

/* ============================================
   ANALYSIS PAGE
   ============================================ */

.analysis-panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-eval-graph {
  width: 100%;
  height: 80px;
  min-height: 60px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.analysis-eval-graph canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.eval-graph-container {
  position: relative;
  width: 100%;
  height: 80px;
  background: var(--bg-3);
}

.eval-graph-container canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ============================================
   PUZZLE UI
   ============================================ */

.puzzle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  direction: rtl;
}

.puzzle-streak {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-en);
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
}

.puzzle-timer {
  font-family: var(--font-en);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-2);
  padding: 4px 10px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
}

/* Pre-move Ghost Piece */
.piece-ghost {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.3);
}

/* ============================================
   RESPONSIVE - Desktop
   ============================================ */

@media (min-width: 768px) {
  .game-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
    justify-content: center;
    padding: 8px 0;
  }

  .game-board-column {
    flex: 0 0 auto;
    width: min(560px, calc(100vh - 180px));
  }

  .game-board-section {
    max-width: 100%;
  }

  .game-side-panel {
    display: flex;
    flex: 0 1 280px;
    max-height: min(560px, calc(100vh - 180px));
  }

  .game-mobile-panel {
    display: none;
  }

  .game-header {
    max-width: 100%;
  }
}

/* ============================================
   RESPONSIVE - Mobile
   ============================================ */

@media (max-width: 767px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
    padding: 0;
  }

  .game-board-column {
    width: 100%;
  }

  .game-side-panel {
    display: none;
  }

  .game-mobile-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .game-mobile-panel .analysis-panel {
    max-height: 240px;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
  }

  .game-mobile-panel .move-list-pro {
    max-height: 140px;
  }

  .game-board-section {
    max-width: 100%;
  }

  .game-header {
    border-radius: var(--radius-sm);
    max-width: 100%;
  }

  .eval-bar {
    display: none;
  }
}
