* {
  box-sizing: border-box;
}

:root {
  --header-height: 70px;
  --padding: 20px;
  --gap: 30px;
  --info-panel-width: 220px;
  --move-list-height: 60px;
  /* Board size: min of available height or available width */
  --board-size: min(
    calc(100vh - var(--header-height) - var(--padding) * 2 - var(--move-list-height)),
    calc(100vw - var(--info-panel-width) - var(--gap) - var(--padding) * 2),
    800px
  );
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: var(--padding);
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
}

#loading {
  text-align: center;
  padding: 50px;
  font-size: 1.2em;
  color: #888;
}

.container {
  max-width: calc(var(--board-size) + var(--info-panel-width) + var(--gap));
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 20px;
  height: calc(var(--header-height) - 20px);
}

header h1 {
  margin: 0;
  color: #fff;
  font-size: 2em;
}

header p {
  margin: 0;
  color: #888;
}

.game-area {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
  justify-content: center;
}

.board-column {
  display: flex;
  flex-direction: column;
  width: var(--board-size);
}

.board {
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.move-list {
  min-height: 1.5em;
  padding: 10px 0;
  font-family: monospace;
  font-size: 0.95em;
  color: #ccc;
  line-height: 1.8;
}

.move-list .move-number {
  color: #888;
}

.move-list .move {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.15s;
}

.move-list .move:hover {
  background: #3d3d54;
}

.move-list .move.current {
  background: #4a4a6a;
  color: #fff;
}

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: var(--info-panel-width);
  flex-shrink: 0;
}

.eval-panel {
  background: #2d2d44;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
}

.eval-score {
  font-size: 2.5em;
  font-weight: bold;
  color: #4CAF50;
  font-family: monospace;
}

.eval-score.mate {
  color: #64b5f6;
}

.eval-panel.out-of-book .eval-score,
.out-of-book-msg {
  color: #ff9800;
  font-size: 1.2em;
}

.eval-depth {
  color: #888;
  margin-top: 5px;
  font-size: 0.9em;
}

.game-over {
  font-size: 1.5em;
  color: #ff5722;
}

.candidates-panel {
  background: #2d2d44;
  padding: 12px;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4a4a6a #2d2d44;
}

.candidates-panel::-webkit-scrollbar {
  width: 8px;
}

.candidates-panel::-webkit-scrollbar-track {
  background: #2d2d44;
  border-radius: 4px;
}

.candidates-panel::-webkit-scrollbar-thumb {
  background: #4a4a6a;
  border-radius: 4px;
}

.candidates-panel::-webkit-scrollbar-thumb:hover {
  background: #5a5a7a;
}

.candidate-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
  cursor: pointer;
}

.candidate-row:hover {
  background: #3d3d54;
}

.candidate-move {
  color: #fff;
}

.candidate-score {
  color: #4CAF50;
}

.candidate-score.mate {
  color: #64b5f6;
}

.candidate-score.no-eval {
  color: #ff9800;
}

.stats-panel {
  background: #2d2d44;
  padding: 20px;
  border-radius: 8px;
}

.stats-panel h3 {
  margin: 0 0 15px 0;
  font-size: 1em;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #3d3d54;
}

.stat:last-child {
  border-bottom: none;
}

.stat .label {
  color: #888;
}

.stat span:last-child {
  color: #fff;
  font-weight: 500;
  font-family: monospace;
}

.controls {
  display: flex;
  gap: 10px;
}

.controls button {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 6px;
  background: #4a4a6a;
  color: #fff;
  cursor: pointer;
  font-size: 1em;
  transition: background 0.2s;
}

.controls button:hover {
  background: #5a5a7a;
}

.message {
  background: #ff9800;
  color: #000;
  padding: 12px;
  border-radius: 6px;
  text-align: center;
  display: none;
  font-weight: 500;
}

.message.visible {
  display: block;
}

@media (max-width: 700px) {
  :root {
    --board-size: min(calc(100vw - var(--padding) * 2), calc(100vh - 300px));
  }

  .game-area {
    flex-direction: column;
    align-items: center;
  }

  .info-panel {
    width: var(--board-size);
  }
}
