/* ── Reset & variables ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1c1c1e;
  --panel:     #2c2c2e;
  --border:    #3a3a3c;
  --text:      #e5e5e7;
  --muted:     #8e8e93;
  --accent:    #f5a623;
  --light-sq:  #f0d9b5;
  --dark-sq:   #b58863;
  --hl-sq:     rgba(255, 215, 0, 0.48);
  --sq:        80px;   /* square size → 640px board */
}

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

.hidden { display: none !important; }

/* ── Loader / drop zone ─────────────────────────────────────────────────── */
#loader {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

#drop-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 56px 80px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  max-width: 440px;
}
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(245, 166, 35, 0.06);
}

.drop-icon { font-size: 64px; display: block; margin-bottom: 16px; }
#drop-zone h2 { font-size: 22px; margin-bottom: 12px; }
#drop-zone p  { color: var(--muted); margin-bottom: 6px; font-size: 14px; }
#drop-zone code { color: var(--text); background: var(--panel); padding: 1px 5px; border-radius: 4px; }
.or { font-size: 11px; margin: 16px 0 !important; }

#file-input { display: none; }

.browse-btn {
  display: inline-block;
  margin-top: 4px;
  padding: 10px 32px;
  background: var(--accent);
  color: #000;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.browse-btn:hover { opacity: 0.85; }

/* ── Header ─────────────────────────────────────────────────────────────── */
#game-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.player-block {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ph-piece { font-size: 24px; }
.wp { color: #fff; text-shadow: 0 1px 4px #000a; }
.bp { color: #888; }

.ph-names { display: flex; flex-direction: column; line-height: 1.2; }
.ph-name  { font-weight: 700; font-size: 15px; }
.ph-style { font-size: 11px; color: var(--muted); font-style: italic; }

#result-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
#game-result { font-weight: 700; font-size: 16px; color: var(--accent); }
#game-reason { font-size: 11px; color: var(--muted); }

#header-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
#game-date { font-size: 12px; color: var(--muted); }

#btn-load-new {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s;
}
#btn-load-new:hover { border-color: var(--accent); }

/* ── Main layout — centered ─────────────────────────────────────────────── */
main {
  display: flex;
  gap: 20px;
  padding: 24px;
  align-items: flex-start;
  justify-content: center;   /* center board on page */
  flex-wrap: wrap;
}

/* ── Board area (eval bar + board column) ───────────────────────────────── */
#board-area {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* ── Eval bar ───────────────────────────────────────────────────────────── */
#eval-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  /* vertically align bar with the board itself (skip player row + cap row above) */
  margin-top: calc(26px + 26px + 6px * 2);  /* player-row + cap-row + gaps */
}

#eval-bar {
  width: 14px;
  height: calc(var(--sq) * 8 + 4px);   /* 4px = board border */
  background: #1a1a1a;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}

#eval-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;            /* default = equal position */
  background: #e8e8e8;
  transition: height 0.3s ease;
}

#eval-score {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  min-height: 16px;
  text-align: center;
}

/* ── Board column ───────────────────────────────────────────────────────── */
#board-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Player rows (above/below board) */
.player-row {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 26px;
}
.pr-piece { font-size: 20px; }
.pr-name  { font-weight: 600; font-size: 14px; }
.pr-style { font-size: 11px; color: var(--muted); font-style: italic; }

/* Captured pieces */
.cap-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1px;
  min-height: 26px;
  font-size: 20px;
}
.cap-w   { color: #fff; text-shadow: 0 1px 3px #000a; }
.cap-b   { color: #555; }
.cap-adv {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-left: 6px;
  align-self: center;
}

/* Board grid */
#board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows:    repeat(8, var(--sq));
  border: 2px solid #111;
  border-radius: 3px;
  overflow: hidden;
}

.square {
  width:  var(--sq);
  height: var(--sq);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.light { background: var(--light-sq); }
.dark  { background: var(--dark-sq);  }
.hl    { background: var(--hl-sq);    }

/* Pieces */
.piece {
  font-size: 62px;
  line-height: 1;
  cursor: default;
  position: relative;
  z-index: 1;
}
.piece.wp {
  color: #fff;
  text-shadow: 0 1px 2px #000c, 0 0 6px #0007;
}
.piece.bp {
  color: #111;
  text-shadow: 0 1px 2px #fffa, 0 0 4px #fff6;
}

/* Board coordinates */
.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}
.light .coord { color: var(--dark-sq);  }
.dark  .coord { color: var(--light-sq); }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 2px; right: 3px; }

/* ── Side panel ─────────────────────────────────────────────────────────── */
#side-panel {
  display: flex;
  flex-direction: column;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  /* align top with board (same offset as eval-wrap margin-top) */
  margin-top: calc(26px + 26px + 6px * 2);
  /* height = board + border */
  max-height: calc(var(--sq) * 8 + 4px);
}

#move-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  font-family: 'Menlo', 'Consolas', 'SF Mono', monospace;
  font-size: 13px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#move-list::-webkit-scrollbar       { width: 4px; }
#move-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.move-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
}

.move-num {
  padding: 4px 4px 4px 8px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  align-self: center;
}

.move-san {
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 3px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  transition: background 0.1s;
}
.move-san:hover         { background: rgba(255,255,255,0.07); }
.move-san.active        { background: var(--accent); color: #000; font-weight: 700; }
.move-san.active .meval { color: #0007; }
.move-san.empty         { pointer-events: none; }

/* Eval score inside each move cell */
.meval {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
  font-weight: 500;
}
.meval.pos { color: #7eb8f7; }   /* white ahead — blue tint */
.meval.neg { color: #e08080; }   /* black ahead — red tint */

/* ── Controls ───────────────────────────────────────────────────────────── */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#controls button {
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 6px;
  color: var(--text);
  padding: 5px 9px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
#controls button:hover    { background: rgba(255,255,255,0.12); }
#controls button:disabled { opacity: 0.25; cursor: default; }

/* Play/pause button — accent color so it's visually distinct from step buttons */
#controls .play-btn {
  background: var(--accent) !important;
  color: #000 !important;
  font-weight: 700;
  min-width: 34px;
}
#move-counter {
  font-size: 11px;
  color: var(--muted);
  min-width: 46px;
  text-align: center;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 780px) {
  :root { --sq: 44px; }
  .piece { font-size: 34px; }
  #side-panel  { width: 100%; max-height: 240px; margin-top: 0; }
  #eval-wrap   { margin-top: calc(26px + 26px + 6px * 2); }
  main         { padding: 12px; gap: 12px; }
  #game-header { gap: 10px; padding: 8px 12px; }
  #board-area  { gap: 6px; }
}
