/* chesscnn web — "engine lab" theme.
   Warm near-black canvas, a single amber accent, walnut board, monospace for the
   numbers the engine actually cares about. Everything sized on an 8px rhythm. */

:root {
  --bg: #14110e;
  --bg-grad: radial-gradient(1200px 800px at 78% -10%, #201a14 0%, #14110e 55%);
  --panel: #1b1712;
  --panel-2: #221d17;
  --line: #322a22;
  --line-soft: #29231c;
  --ink: #ece5d7;
  --ink-dim: #c3b7a3;
  --muted: #8f8371;
  --muted-2: #6b6153;
  --accent: #e3a13c;
  --accent-ink: #1a1410;
  --accent-soft: rgba(227, 161, 60, 0.14);
  --win: #d9cfbb;   /* white side */
  --loss: #241f19;  /* black side */
  --sq-light: #d7c19c;
  --sq-dark: #8a6746;
  --sq-light-lastmove: #d8bb6e;
  --sq-dark-lastmove: #b08a3f;
  --check: #d5563f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.75);
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-grad), var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, select { font-family: inherit; }
h1 { margin: 0; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 30px) 30px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #2a2119, #1a1510);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.brand-mark .glyph { font-size: 26px; color: var(--accent); line-height: 1; margin-top: -2px; }
.brand-text h1 {
  font-size: 21px; font-weight: 750; letter-spacing: -0.02em;
}
.brand-text p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); letter-spacing: 0.01em; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted-2); padding-left: 2px; }
select, .btn {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
}
select { padding-right: 26px; }
.btn:hover, select:hover { border-color: #4a3e31; }
.btn:active { transform: translateY(1px); }
.btn-accent {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 650;
}
.btn-accent:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; }
.seg-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 13px; font-size: 13px; border-radius: 6px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- stage ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 26px;
  padding-top: 22px;
  align-items: start;
  flex: 1;
}

/* ---------- board ---------- */
.board-col { min-width: 0; }
.board-wrap {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}
.evalbar {
  position: relative;
  border-radius: 6px;
  background: var(--loss);
  overflow: hidden;
  border: 1px solid var(--line);
  min-height: 200px;
}
.evalbar-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 50%;
  background: linear-gradient(180deg, #efe7d4, var(--win));
  transition: height .5s cubic-bezier(.4, 0, .1, 1);
}
.evalbar-num {
  position: absolute; left: 50%; top: 6px; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 8.5px; color: var(--accent-ink);
  writing-mode: vertical-rl; letter-spacing: .04em; opacity: .0;
}

.board {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid #43331f;
  user-select: none;
  touch-action: manipulation;
}
.sq { position: relative; display: grid; place-items: center; container-type: size; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.lastmove.light { background: var(--sq-light-lastmove); }
.sq.lastmove.dark { background: var(--sq-dark-lastmove); }
.sq.check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(213,86,63,.85) 0%, rgba(213,86,63,.25) 55%, transparent 72%);
}
.sq .coord {
  position: absolute; font-size: 9.5px; font-weight: 650; opacity: .55;
  font-family: var(--font-mono);
}
.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq.light .coord { color: #7a5a37; }
.sq.dark .coord { color: #e6d3b3; }

.piece {
  font-family: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols 2', 'Arial Unicode MS', sans-serif;
  font-size: 78cqmin; /* scale to the square, not the root font */
  line-height: 1;
  cursor: grab;
  z-index: 2;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.45));
  transition: transform .08s;
}
.piece.w { color: #f7f2e9; -webkit-text-stroke: 2px #23190f; }
.piece.b { color: #201914; -webkit-text-stroke: 2px #0c0906; }
.sq.selectable .piece { cursor: pointer; }
.sq.dragging .piece { opacity: .35; }

.hintdot {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(40, 28, 16, 0.28); z-index: 1; pointer-events: none;
}
.sq.capture .hintdot {
  width: 86%; height: 86%; background: transparent;
  border: 4px solid rgba(40, 28, 16, 0.28); box-sizing: border-box;
}
.sq.selected::before {
  content: ""; position: absolute; inset: 0; background: rgba(227,161,60,.32); z-index: 0;
}
.policy-heat {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: var(--accent); opacity: 0;
  transition: opacity .3s;
}

.statusline {
  display: flex; align-items: center; gap: 9px;
  margin: 14px 0 0 28px;
  font-size: 13.5px; color: var(--ink-dim);
  min-height: 20px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; }
.dot.thinking { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.dot.ready { background: #6fae7f; }
.dot.gameover { background: var(--check); }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------- panel ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel-card {
  background: linear-gradient(180deg, var(--panel), #17130f);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px 15px;
}
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 11px;
}
.card-title .hint { font-family: var(--font-mono); letter-spacing: 0; text-transform: none; color: var(--muted-2); }

.readout-head { display: flex; align-items: baseline; justify-content: space-between; }
.tag {
  font-size: 10px; letter-spacing: .14em; color: var(--accent);
  border: 1px solid rgba(227,161,60,.35); border-radius: 5px; padding: 2px 6px;
  background: var(--accent-soft);
}
.readout-eval { font-family: var(--font-mono); font-size: 30px; font-weight: 650; letter-spacing: -0.01em; }
.readout-sub { margin-top: 5px; font-size: 13px; color: var(--ink-dim); min-height: 18px; }
.wdl { display: flex; height: 7px; margin-top: 12px; border-radius: 4px; overflow: hidden; background: var(--line); }
.wdl-seg { height: 100%; transition: width .5s ease; }
.wdl-w { background: #e7ddc7; }
.wdl-d { background: #574c3d; }
.wdl-b { background: #100d0a; }

.cands { display: flex; flex-direction: column; gap: 2px; }
.cand {
  position: relative; display: grid; grid-template-columns: 1.6em 1fr auto;
  align-items: center; gap: 9px; padding: 7px 8px; border-radius: 7px;
  cursor: default; overflow: hidden;
}
.cand .cand-bar {
  position: absolute; left: 0; top: 0; bottom: 0; z-index: 0;
  background: var(--accent-soft); border-radius: 7px;
}
.cand.best .cand-bar { background: rgba(227,161,60,.22); }
.cand > * { position: relative; z-index: 1; }
.cand-rank { font-family: var(--font-mono); font-size: 11px; color: var(--muted-2); }
.cand-san { font-weight: 600; font-size: 14px; }
.cand.best .cand-san { color: var(--accent); }
.cand-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); text-align: right; }
.cands .empty, .empty { color: var(--muted-2); font-size: 13px; padding: 4px 2px; }

.mini-toggle {
  font-size: 11px; letter-spacing: .04em; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; cursor: pointer; text-transform: none;
}
.mini-toggle[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

.pv { font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim); line-height: 1.7; word-spacing: .1em; min-height: 20px; }
.pv .pv-move { color: var(--ink); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 15px; }
.stat { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--line-soft); padding-bottom: 6px; }
.stat-k { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); }
.stat-v { font-family: var(--font-mono); font-size: 14px; color: var(--ink); }

.moves-card { max-height: 220px; display: flex; flex-direction: column; }
.movelist {
  overflow-y: auto; font-family: var(--font-mono); font-size: 13px;
  display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 2px 8px; align-content: start;
}
.movelist .mv-no { color: var(--muted-2); }
.movelist .mv { padding: 2px 5px; border-radius: 4px; color: var(--ink-dim); cursor: default; }
.movelist .mv.last { background: var(--accent-soft); color: var(--ink); }

/* ---------- footer ---------- */
.footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line-soft);
  font-size: 12px; color: var(--muted-2);
}
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--accent); }

/* ---------- promotion picker ---------- */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(8, 6, 4, .6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 40;
}
.modal-scrim[hidden] { display: none; }
.promo { display: flex; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.promo button {
  width: 62px; height: 62px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); cursor: pointer; font-size: 40px; line-height: 1;
  display: grid; place-items: center; transition: border-color .15s, transform .05s;
}
.promo button:hover { border-color: var(--accent); }
.promo button .piece { font-size: 44px; -webkit-text-stroke: 1.8px #23190f; color: #f7f2e9; filter: none; }

/* ---------- loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: var(--bg-grad), var(--bg);
  transition: opacity .5s;
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; width: min(320px, 80vw); }
.loader-board {
  width: 74px; height: 74px; margin: 0 auto 20px; border-radius: 12px;
  background:
    conic-gradient(from 0deg, var(--sq-dark) 0 25%, var(--sq-light) 0 50%, var(--sq-dark) 0 75%, var(--sq-light) 0);
  background-size: 50% 50%;
  animation: spin 3.5s linear infinite; box-shadow: var(--shadow);
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 14px; color: var(--ink-dim); margin-bottom: 14px; }
.loader-bar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
.loader-bar-fill { height: 100%; width: 8%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  .panel { order: 2; }
  .board-col { order: 1; max-width: 560px; margin: 0 auto; width: 100%; }
  .panel { max-width: 560px; margin: 0 auto; width: 100%; }
}
@media (max-width: 560px) {
  .controls { gap: 8px; }
  .field > span { display: none; }
  .brand-text p { display: none; }
  .readout-eval { font-size: 26px; }
}
