* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #0f0f12;
  color: #e7e5e4;
  font-size: 13px;
}

/* ============ layout: 2 columns ============ */
#layout {
  display: grid;
  grid-template-columns: minmax(440px, min(900px, 60vw)) minmax(380px, 1fr);
  grid-template-rows: 1fr;
  grid-template-areas: "board chat";
  height: 100vh;
  width: 100vw;
  gap: 20px;
  padding: 14px;
  overflow: hidden;
}

#board-col  { grid-area: board; min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
#chat-col   { grid-area: chat;  min-width: 0; min-height: 0; overflow: hidden; }

/* ============ board area ============ */
#board-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}
#board {
  /* size set imperatively by fitBoard() */
  background: #444;
  border-radius: 4px;
  overflow: hidden;
  flex: 0 0 auto;
}
#board cg-container { width: 100% !important; height: 100% !important; }

#board-footer {
  display: flex; gap: 10px; align-items: center;
  padding: 4px 2px;
  font-size: 12.5px;
}
#status-line { flex: 0 0 auto; opacity: 0.85; }
#think-meter {
  flex: 1;
  font-size: 12px;
  opacity: 0.75;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  letter-spacing: 0.01em;
}
.think-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #c0a060;
  animation: think-pulse 1.4s ease-in-out infinite;
  align-self: center;
  margin-right: 4px;
}
.think-who { color: #d8d4c8; font-weight: 600; }
.think-time {
  font-variant-numeric: tabular-nums;
  color: #f0d090;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@keyframes think-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

/* ============ eval bar ============ */
#eval-col {
  position: relative;
  width: 36px;
  flex: 0 0 36px;
  background: #2a2a30;                /* BLACK half on top */
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #3a3a40;
}
#eval-col::after {                    /* 50/50 reference line */
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px; background: rgba(255,255,255,0.12);
  pointer-events: none; z-index: 2;
}
#eval-fill {                          /* WHITE half from bottom */
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 50%;
  background: linear-gradient(180deg, #fafafa 0%, #e0ddd5 100%);
  transition: height 0.4s ease;
  z-index: 1;
}
#eval-text {
  position: absolute;
  left: 0; right: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none; z-index: 3;
  transition: color 0.2s, top 0.4s, bottom 0.4s;
  /* default — slight white or even: text near bottom on white half, dark */
  bottom: 4px; top: auto;
  color: #1a1a1a;
}
#eval-col.advantage-black #eval-text {
  bottom: auto; top: 4px;
  color: #e7e5e4;
}

/* ============ floating moves panel (below board) ============ */
#moves-floating {
  display: flex; align-items: flex-start; gap: 8px;
  background: #15151a;
  border: 1px solid #2a2a30;
  border-radius: 8px;
  padding: 6px 10px;
  max-height: 84px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.moves-label {
  font-size: 10px; opacity: 0.45; text-transform: uppercase;
  letter-spacing: 0.1em; padding-top: 2px; flex: 0 0 auto;
}
#history-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: 2px 8px;
  font-size: 12.5px; overflow-y: auto; flex: 1;
  font-variant-numeric: tabular-nums;
}
#history-list li { padding: 1px 4px; border-radius: 3px; cursor: pointer; }
#history-list li.ply-num { opacity: 0.4; cursor: default; padding-right: 2px; }
#history-list li:not(.ply-num):hover { background: #25252b; }
#history-list li.active { background: #3d342a; color: #f0d090; }

/* ============ chat panel (right, full height) ============ */
#chat-col { display: flex; flex-direction: column; background: #15151a; border-radius: 8px; overflow: hidden; border: 1px solid #2a2a30; }
.col-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; opacity: 0.6; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.1em; border-bottom: 1px solid #2a2a30;
}
#chat-list {
  flex: 1; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  padding: 7px 10px 9px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.4;
  word-wrap: break-word;
  transition: outline-color 0.1s ease;
  outline: 1px solid transparent;
  outline-offset: 2px;
}
.bubble:hover { outline-color: #555; }
.bubble.active { outline-color: #c0a060; }
.bubble-white { background: #f0eee6; color: #16161a; align-self: flex-start; max-width: 92%; }
.bubble-black { background: #1f1e22; color: #e7e5e4; align-self: flex-end;   max-width: 92%; border-color: #2a2a30; }
.bubble-meta {
  font-size: 10px; opacity: 0.65; margin-bottom: 3px;
  display: flex; justify-content: space-between; gap: 6px; align-items: center;
}
.bubble-san { font-weight: 700; opacity: 0.95; }
.bubble-body { font-size: 13px; }
.bubble-empty { font-style: italic; opacity: 0.5; }

/* ============ buttons + dialog ============ */
button {
  background: #25252b; color: #e7e5e4; border: 1px solid #34343a;
  padding: 4px 10px; cursor: pointer; border-radius: 4px; font-size: 12px;
}
button:hover { background: #2e2e36; }
#live-btn { background: #3d342a; color: #f0d090; }
#abort-game { background: #3a2222; color: #e09080; border-color: #5a3030; }
#abort-game:hover { background: #4a2a2a; }

dialog {
  background: #15151a; color: #e7e5e4; border: 1px solid #2a2a30;
  padding: 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog form { display: flex; flex-direction: column; gap: 12px; min-width: 320px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 0; }
dialog h3 { margin: 0; font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
dialog select, dialog input[type="number"], dialog input[type="text"] {
  background: #1f1f25; color: #e7e5e4; border: 1px solid #34343a;
  border-radius: 4px; padding: 4px 6px; font-size: 12px;
}

/* setup dialog */
#setup-dialog { min-width: 580px; }
.setup-header { display: flex; justify-content: space-between; align-items: center; }
.setup-actions { display: flex; gap: 8px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.setup-side {
  border: 1px solid #34343a; border-radius: 6px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  background: #1a1a20;
}
.setup-side legend { padding: 0 6px; font-size: 11px; letter-spacing: 0.1em; opacity: 0.8; }
.setup-white legend { color: #e7e5e4; }
.setup-black legend { color: #c0a060; }
.setup-side label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 10px; opacity: 0.55; text-transform: uppercase; letter-spacing: 0.08em;
}
.setup-side select { font-size: 13px; opacity: 1; text-transform: none; letter-spacing: 0; }
.setup-promptdesc {
  margin: 4px 0 0; font-size: 11px; opacity: 0.55; line-height: 1.4;
  min-height: 2.4em;
}
#setup-warning { background: #3a2a1a; border: 1px solid #5a4020; color: #f0c080; padding: 8px 10px; border-radius: 4px; font-size: 12px; margin: 0; }
#setup-start { background: #3d342a; color: #f0d090; }
#games-link { font-size: 12px; color: #c0a060; text-decoration: none; margin-right: 4px; }
#games-link:hover { text-decoration: underline; }
#games-link.disabled { color: #555; cursor: not-allowed; }
#games-link.disabled:hover { text-decoration: none; }

/* ============ /games page ============ */
#games-page {
  max-width: 1500px; margin: 0 auto; padding: 24px;
  display: flex; flex-direction: column; gap: 18px;
}
#games-page-header {
  display: flex; align-items: baseline; gap: 16px;
  border-bottom: 1px solid #2a2a30; padding-bottom: 12px;
}
#games-page-header h1 { margin: 0; font-size: 18px; letter-spacing: 0.05em; }
#games-count { opacity: 0.55; font-size: 12px; }
#back-link { color: #c0a060; text-decoration: none; }
#back-link:hover { text-decoration: underline; }

#blocked-banner {
  background: #3a2a1a; border: 1px solid #5a4020; color: #f0c080;
  padding: 12px 14px; border-radius: 6px;
}
#blocked-banner a { color: #f0d090; }

#page-grid {
  display: grid; grid-template-columns: 420px 1fr; gap: 18px;
}
#stats-pane, #games-pane {
  background: #15151a; border: 1px solid #2a2a30; border-radius: 8px;
  overflow: hidden;
}
#stats-pane table, #games-pane table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}
#stats-pane th, #stats-pane td, #games-pane th, #games-pane td {
  padding: 6px 10px; text-align: left; border-bottom: 1px solid #1f1f24;
}
#stats-pane th, #games-pane th {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  opacity: 0.55; font-weight: 600;
}
#stats-pane td:nth-child(n+2), #games-pane td:nth-child(n+4) { font-variant-numeric: tabular-nums; }
.persona { font-size: 10px; opacity: 0.5; }
.result-1-0  { color: #f0eee6; font-weight: 700; }
.result-0-1  { color: #c0a060; font-weight: 700; }
.result-1_2-1_2 { color: #88c0a0; font-weight: 700; }
.result-_ { opacity: 0.4; }

/* replay */
#replay-wrap { border-top: 1px solid #2a2a30; padding: 14px; }
#replay-layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; }
#replay-board { width: 360px; aspect-ratio: 1/1; }
#replay-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#replay-controls { display: flex; gap: 6px; align-items: center; font-size: 12px; }
#replay-controls button { padding: 2px 8px; }
#replay-ply { opacity: 0.6; margin-left: 8px; }
#replay-eval { margin-left: auto; font-weight: 700; color: #f0d090; }
#replay-history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 540px; overflow-y: auto; }
.replay-row { font-size: 12px; }
#replay-close { background: #25252b; }
