/* Branchess web — dark theme, board + panel layout */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=JetBrains+Mono:wght@400&display=swap');

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

:root {
  --bg: #302e2b;
  --panel-bg: #27251e;
  --text: #dcdcdc;
  --text-dim: #969696;
  --btn: #505050;
  --btn-hover: #646464;
  --btn-text: #e6e6e6;
  --btn-active: #3c7850;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --body-bg: #1a3a2a;
}

html.theme-banglabs, html.theme-banglabs #app {
  --bg: #0a0a0f;
  --panel-bg: #0f0f19;
  --text: #e0e0e8;
  --text-dim: #9ca3b0;
  --btn: #1a1a2e;
  --btn-hover: #2a2a44;
  --btn-text: #c7d2fe;
  --btn-active: #6366f1;
  --sq-light: #363650;
  --sq-dark: #1a1a2e;
  --body-bg: #050510;
}

html, body {
  height: 100%;
  background: var(--body-bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  --board-size: min(calc(100vh - 40px), calc(min(100vw, 1600px) * 2 / 3 - 24px));
}

/* Board wrapper */
#board-wrap {
  display: flex;
  flex-direction: column;
  align-self: center;
  flex-shrink: 0;
}

.file-labels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 0;
  user-select: none;
  margin-left: 20px;
}

#board-row {
  display: flex;
  align-items: center;
}

.rank-labels {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--text-dim);
  user-select: none;
  width: 20px;
  height: min(calc(100vh - 40px), calc(min(100vw, 1600px) * 2 / 3 - 24px));
  text-align: center;
  align-items: center;
}

.rank-labels span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Board */
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  --board-size: min(calc(100vh - 40px), calc(min(100vw, 1600px) * 2 / 3 - 24px));
  width: var(--board-size);
  height: var(--board-size);
}

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

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

/* Pieces */
.piece {
  font-size: calc(var(--board-size) / 8 * 0.72);
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  font-variant-emoji: text;
}

.piece-white {
  color: #e8e0d0;
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000,
    -1px  1px 0 #000, 1px  1px 0 #000;
}

.piece-black {
  color: #000;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,0.7), 1px -1px 0 rgba(255,255,255,0.7),
    -1px  1px 0 rgba(255,255,255,0.7), 1px  1px 0 rgba(255,255,255,0.7);
}

.piece-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--board-size) / 8 * 0.72);
  line-height: 1;
}

/* Highlights */
.highlight-selected::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(130,151,105,0.7);
  pointer-events: none;
  z-index: 1;
}

.highlight-last::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(205,210,106,0.55);
  pointer-events: none;
  z-index: 1;
}

.highlight-check::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(235,64,52,0.63);
  pointer-events: none;
  z-index: 1;
}

.highlight-best::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(80,140,240,0.55);
  pointer-events: none;
  z-index: 1;
}

.highlight-legal::before {
  content: '';
  position: absolute;
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: rgba(20,85,30,0.47);
  pointer-events: none;
  z-index: 3;
}

.highlight-legal-capture::before {
  content: '';
  position: absolute;
  width: 85%;
  height: 85%;
  border-radius: 50%;
  border: 4px solid rgba(20,85,30,0.35);
  background: transparent;
  pointer-events: none;
  z-index: 3;
}

#board.hide-hints .highlight-legal::before,
#board.hide-hints .highlight-legal-capture::before {
  display: none;
}


/* Panel (right side) */
#panel, #setup-panel, #board-setup-panel {
  flex: 1;
  min-width: calc(min(100vw, 1600px) / 3);
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  padding: 8px;
  overflow-y: auto;
}

#setup-panel, #board-setup-panel {
  display: none;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  padding: 4px 6px;
  color: var(--text);
}

.panel-status {
  font-size: 13px;
  padding: 2px 6px 6px;
  font-weight: 600;
}

.tree-container {
  flex: 1;
  min-height: 120px;
  background: #1e1c1a;
  border-radius: 4px;
  margin: 4px 0;
  overflow: hidden;
  cursor: grab;
}

.tree-svg {
  display: block;
}

.branch-info {
  font-size: 15px;
  color: var(--text-dim);
  padding: 4px 6px;
  font-family: 'Inter', sans-serif;
}

.move-list {
  font-size: 15px;
  color: var(--text-dim);
  padding: 2px 6px 8px;
  font-family: 'JetBrains Mono', monospace;
  white-space: pre-wrap;
  line-height: 1.5;
  min-height: 28px;
  max-height: 120px;
  overflow-y: auto;
  cursor: text;
}

.move-list-empty {
  color: #555;
  font-style: italic;
}

.move-input {
  width: calc(100% - 12px);
  margin: 0 6px 4px;
  padding: 4px 6px;
  font-size: 15px;
  font-family: 'JetBrains Mono', monospace;
  background: #1a1a1a;
  color: var(--text);
  border: 1px solid #555;
  border-radius: 4px;
  outline: none;
}

.move-input:focus {
  border-color: var(--btn-active);
}

.move-input-invalid {
  border-color: #c44 !important;
  color: #e66;
}

/* Buttons */
.btn-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

.btn-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
  border-top: 1px solid #3a3a3a;
}

.btn-section:first-child {
  border-top: none;
}

.btn-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 2px 2px 0;
}

.btn-row {
  display: flex;
  gap: 6px;
}

.panel-btn {
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}

.panel-btn:hover { background: var(--btn-hover); }
.panel-btn:disabled { opacity: 0.35; cursor: default; }
.panel-btn:disabled:hover { background: var(--btn); }

.btn-half { flex: 1; }
.btn-full { width: 100%; }

.btn-active {
  background: var(--btn-active);
}
.btn-active:hover {
  background: #508c64;
}

/* Strength slider */
.slider-area {
  padding: 6px;
}

.slider-label {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
}

.strength-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #3c3a37;
  outline: none;
}

.strength-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #dcdcdc;
  border: 2px solid #3c3c3c;
  cursor: pointer;
  margin-top: -6px;
}

.strength-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #dcdcdc;
  border: 2px solid #3c3c3c;
  cursor: pointer;
}

.strength-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right,
    var(--slider-color, #64b450) 0%,
    var(--slider-color, #64b450) var(--val, 70%),
    #3c3a37 var(--val, 70%),
    #3c3a37 100%
  );
}

/* Hints bar */
.hints {
  font-size: 10px;
  color: #505050;
  padding: 4px 6px 2px;
  text-align: center;
}

/* Board setup panel — piece grid matching board piece size */
.board-setup-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px 8px;
}

.board-setup-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--btn);
  border-radius: 6px;
  font-size: calc(var(--board-size) / 8 * 0.72);
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}
.board-setup-cell:hover { background: var(--btn-hover); }
.board-setup-cell.palette-selected { background: var(--btn-active); }

/* Overlay for dialogs */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* Fullscreen tree mode */
.tree-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 500;
  background: #1e1c1a;
  width: 100vw !important;
  height: 100vh !important;
  min-height: 100vh !important;
  max-height: none !important;
  flex: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  overflow: visible !important;
}

.board-floating {
  position: fixed !important;
  z-index: 600;
  flex-shrink: 0;
  cursor: move;
  border: 2px solid #555;
  border-radius: 6px;
  background: var(--bg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.board-floating #board {
  --board-size: min(25vh, 25vw);
  width: var(--board-size);
  height: var(--board-size);
}

.board-floating .file-labels {
  font-size: 10px;
}

.board-floating .rank-labels {
  height: min(25vh, 25vw);
  font-size: 10px;
}

.board-floating .piece {
  font-size: calc(min(25vh, 25vw) / 8 * 0.72) !important;
}

.board-floating .piece-ghost {
  font-size: calc(min(25vh, 25vw) / 8 * 0.72) !important;
}

.board-floating .btn-area {
  max-height: 40vh;
  overflow-y: auto;
  padding: 4px;
  background: var(--panel-bg);
  border-radius: 0 0 6px 6px;
}

/* When tree is fullscreen, hide panel but tree escapes via position:fixed */
.panel-hidden {
  visibility: hidden !important;
  pointer-events: none !important;
}
.panel-hidden .tree-fullscreen {
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Responsive: stack on narrow screens */
@media (max-width: 700px) {
  #app { flex-direction: column; }
  #board {
    --board-size: min(100vw, 50vh);
    width: var(--board-size);
    height: var(--board-size);
  }
  #panel, #setup-panel, #board-setup-panel {
    max-width: none;
    height: 50vh;
    min-width: auto;
  }
}
