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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text-dim: #aaa;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --blocked-sq: #555;
  --highlight: rgba(255, 255, 0, 0.4);
  --move-dot: rgba(0, 0, 0, 0.25);
  --last-move: rgba(155, 199, 0, 0.41);
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-header {
  background: var(--surface);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--surface2);
}

.app-header h1 {
  font-size: 1.2rem;
  color: var(--accent);
}

.app-header nav { display: flex; gap: 16px; }
.app-header nav a { color: var(--text-dim); font-size: 0.9rem; }
.app-header nav a:hover, .app-header nav a.active { color: var(--text); }

.app-main {
  display: flex;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.board-container {
  flex-shrink: 0;
}

.side-panel {
  flex: 1;
  min-width: 280px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Board SVG */
.chess-board-svg {
  cursor: pointer;
  user-select: none;
}

.chess-board-svg .square-light { fill: var(--light-sq); }
.chess-board-svg .square-dark { fill: var(--dark-sq); }
.chess-board-svg .square-blocked { fill: var(--blocked-sq); }
.chess-board-svg .square-highlight { fill: var(--highlight); }
.chess-board-svg .square-last-move { fill: var(--last-move); }
.chess-board-svg .move-dot { fill: var(--move-dot); pointer-events: none; }
.chess-board-svg .capture-ring { stroke: var(--move-dot); fill: none; stroke-width: 3; pointer-events: none; }
.chess-board-svg .piece { cursor: grab; }
.chess-board-svg .piece.dragging { cursor: grabbing; opacity: 0.7; }
.chess-board-svg .label { fill: var(--text-dim); font-size: 11px; font-family: sans-serif; pointer-events: none; }
.chess-board-svg .arrow { stroke: rgba(0,150,50,0.7); stroke-width: 8; fill: none; stroke-linecap: round; pointer-events: none; }
.chess-board-svg .arrow-head { fill: rgba(0,150,50,0.7); pointer-events: none; }

/* Panels & Cards */
.card {
  background: var(--surface);
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--surface2);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Form Controls */
label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
}

input[type="number"] { width: 70px; }

textarea { resize: vertical; min-height: 60px; }

.row { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.row label { margin-bottom: 0; white-space: nowrap; }

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #d13550; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: #1a4a8a; }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Piece Palette */
.piece-palette {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.piece-palette .piece-btn {
  width: 40px;
  height: 40px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: border-color 0.15s;
}

.piece-palette .piece-btn:hover { border-color: var(--text-dim); }
.piece-palette .piece-btn.active { border-color: var(--accent); background: var(--surface2); }

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
}

.mode-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--surface2);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: all 0.15s;
}

.mode-tab:first-child { border-radius: 4px 0 0 4px; }
.mode-tab:last-child { border-radius: 0 4px 4px 0; }
.mode-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Move History */
.move-history {
  max-height: 300px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

.move-history .move-number { color: var(--text-dim); margin-right: 4px; }
.move-history .move {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 2px;
}
.move-history .move:hover { background: var(--surface2); }
.move-history .move.active { background: var(--accent); color: #fff; }

/* Turn Indicator */
.turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.turn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
}

.turn-dot.white { background: #fff; }
.turn-dot.black { background: #333; }

/* Status Message */
.game-status {
  padding: 10px;
  border-radius: 4px;
  text-align: center;
  font-weight: 600;
  display: none;
}

.game-status.active { display: block; }
.game-status.checkmate { background: var(--accent); color: #fff; }
.game-status.stalemate { background: var(--accent2); color: #fff; }
.game-status.draw { background: var(--surface2); }

/* Eval Bar */
.eval-bar-container {
  width: 30px;
  height: 100%;
  min-height: 400px;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.eval-bar-white {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: #fff;
  transition: height 0.3s ease;
}

.eval-bar-label {
  position: absolute;
  width: 100%;
  text-align: center;
  font-size: 0.7rem;
  font-weight: bold;
  z-index: 1;
}

.eval-bar-label.top { top: 4px; color: #fff; }
.eval-bar-label.bottom { bottom: 4px; color: #333; }

/* Analysis Info */
.analysis-info { font-family: monospace; font-size: 0.85rem; }
.analysis-info dt { color: var(--text-dim); }
.analysis-info dd { margin-bottom: 6px; }

.pv-line {
  font-family: monospace;
  font-size: 0.85rem;
  word-break: break-all;
  color: var(--text-dim);
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  min-height: 1.5em;
}

/* Progress Bar */
.progress-bar {
  height: 20px;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
  border-radius: 10px;
}

/* Results Bar */
.results-bar {
  display: flex;
  height: 30px;
  border-radius: 4px;
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: bold;
}

.results-bar .white-wins { background: #fff; color: #333; display: flex; align-items: center; justify-content: center; }
.results-bar .draws { background: #888; color: #fff; display: flex; align-items: center; justify-content: center; }
.results-bar .black-wins { background: #333; color: #fff; display: flex; align-items: center; justify-content: center; }

/* Variant List */
.variant-list { list-style: none; }
.variant-list li {
  padding: 10px;
  border-bottom: 1px solid var(--surface2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.variant-list li:last-child { border-bottom: none; }
.variant-list .variant-name { font-weight: 500; }
.variant-list .variant-meta { font-size: 0.8rem; color: var(--text-dim); }
.variant-list .variant-actions { display: flex; gap: 6px; }

/* Checkbox group for promotion pieces */
.checkbox-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

/* Responsive */
@media (max-width: 768px) {
  .app-main { flex-direction: column; padding: 12px; }
  .side-panel { max-width: none; }
}

/* Promotion picker */
.promotion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.promotion-picker {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 160px;
}

.promotion-choice {
  text-align: left;
}

/* Static-site additions */
.page-banner {
  margin: 12px 24px 0;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--surface2);
  font-size: 0.9rem;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.page-banner.page-error { background: #5a1f2a; }
.status-text { margin-top: 8px; font-size: 0.85rem; color: var(--text-dim); min-height: 1em; }
.btn-group .status-text { margin-top: 0; align-self: center; }
.hint { font-size: 0.8rem; color: var(--text-dim); margin-top: 6px; }
.mono-input { width: 100%; font-family: monospace; font-size: 0.8rem; }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: normal;
  vertical-align: middle;
  text-transform: none;
}
.variant-list li.empty { color: var(--text-dim); font-size: 0.85rem; }
