:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #252525;
  --bg-tertiary: #2f2f2f;
  --bg-card: #363636;
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-muted: #888;
  --accent-green: #81b64c;
  --accent-blue: #4a90d9;
  --accent-red: #ca3a3a;
  --accent-orange: #e58f2a;
  --accent-yellow: #f0c14b;
  --accent-cyan: #1baca6;
  --board-light: #ebecd0;
  --board-dark: #779556;
  --board-highlight: rgba(255, 255, 0, 0.45);
  --board-best: rgba(0, 150, 255, 0.35);
  --border-color: #444;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* Header */
.site-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.logo-icon {
  font-size: 2rem;
  color: var(--accent-green);
}

.coach-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.coach-selector label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

#coachSelect {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  outline: none;
}

.coach-info-mini {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.coach-info-mini img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

/* Main Layout */
.main-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

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

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

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1;
}

.chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 3px solid var(--bg-tertiary);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 5vw, 3rem);
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.square.light { background: var(--board-light); color: #333; }
.square.dark { background: var(--board-dark); color: #222; }

.square.highlight-last { background: var(--board-highlight) !important; }
.square.highlight-best { background: var(--board-best) !important; }

.square .piece {
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  pointer-events: none;
}

.square .piece.white { color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.square .piece.black { color: #111; }

/* Classification Badge Overlay */
.classification-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  z-index: 10;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  background-size: cover;
  background-position: center;
  pointer-events: none;
}

/* Move overlay for best move arrow (optional visual) */
.move-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
}

/* Board Controls */
.board-controls {
  display: flex;
  gap: 8px;
}

.board-controls button {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
}

.board-controls button:hover {
  background: var(--bg-card);
  border-color: var(--accent-blue);
}

.board-controls button:active {
  transform: translateY(1px);
}

/* Eval Display */
.eval-display {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  background: var(--bg-secondary);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.eval-bar-track {
  flex: 1;
  height: 24px;
  background: #444;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.eval-bar-white {
  height: 100%;
  background: linear-gradient(90deg, #ddd, #fff);
  width: 50%;
  transition: width 0.4s ease;
  border-right: 2px solid var(--accent-green);
}

.eval-text {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 60px;
  text-align: right;
  color: var(--text-primary);
}

/* Side Panel */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h2 {
  font-size: 1.1rem;
  color: var(--text-primary);
}

.status-badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.ready { background: #2d4a1e; color: var(--accent-green); }
.status-badge.analyzing { background: #4a3a1e; color: var(--accent-yellow); }
.status-badge.done { background: #1e3a4a; color: var(--accent-blue); }

/* Move List */
.move-list {
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  gap: 4px 8px;
  font-size: 0.92rem;
}

.move-list::-webkit-scrollbar { width: 6px; }
.move-list::-webkit-scrollbar-track { background: var(--bg-tertiary); }
.move-list::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.move-number {
  color: var(--text-muted);
  text-align: right;
  padding-right: 4px;
  font-weight: 600;
}

.move-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.move-item:hover { background: var(--bg-tertiary); }
.move-item.active { background: rgba(74, 144, 217, 0.2); border: 1px solid var(--accent-blue); }

.move-item .move-text {
  flex: 1;
  font-weight: 500;
}

.move-item .move-eval {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
}

.move-item .move-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  background-size: cover;
}

/* Coach Section */
.coach-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.coach-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.coach-avatar-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-color);
}

.coach-details h3 {
  font-size: 1.1rem;
  color: var(--text-primary);
}

.coach-style {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.coach-speech {
  background: var(--bg-tertiary);
  padding: 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--accent-blue);
}

.signature {
  display: block;
  color: var(--accent-blue);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.explanation {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Best Move Section */
.best-move-section h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.best-move-display {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-green);
  font-family: monospace;
  margin-bottom: 4px;
}

.depth-display {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* PGN Section */
.pgn-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px 20px;
}

.pgn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.pgn-header h3 {
  font-size: 1.1rem;
  color: var(--text-primary);
}

#pgnInput {
  width: 100%;
  min-height: 120px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
  font-family: monospace;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
}

#pgnInput:focus {
  border-color: var(--accent-blue);
}

.pgn-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

/* Buttons */
.btn-primary {
  background: var(--accent-green);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover { background: #6a9a3e; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover { background: var(--bg-card); color: var(--text-primary); }

/* Ad Section */
.ad-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px 24px;
}

.ad-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.ad-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.ad-card {
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.ad-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
}

.ad-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: #555;
  color: #ccc;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.ad-card h4 {
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.ad-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.ad-btn {
  background: transparent;
  color: var(--accent-blue);
  border: 1px solid var(--accent-blue);
  padding: 6px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

/* Footer */
.site-footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Tooltip */
.tooltip {
  position: absolute;
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 240px;
}

.tooltip.show { opacity: 1; }

/* Classification colors for text */
.class-brilliant { color: var(--accent-cyan); }
.class-best { color: var(--accent-green); }
.class-good { color: #95bb4a; }
.class-inaccuracy { color: var(--accent-yellow); }
.class-mistake { color: var(--accent-orange); }
.class-blunder { color: var(--accent-red); }

/* Responsive */
@media (max-width: 600px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .board-wrapper {
    max-width: 100%;
  }

  .move-list {
    max-height: 240px;
  }

  .ad-banner {
    grid-template-columns: 1fr;
  }
}


/* Custom Piece Images */
.piece-img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
  pointer-events: none;
}
