:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-sunken: #010409;
  --border: #30363d;
  --border-soft: #21262d;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --fg-dimmer: #6e7681;
  --accent: #d4af37;
  --accent-fg: #1c1206;
  --red: #ff7b72;
  --green: #6fce7a;
  --mono: "Menlo", "Monaco", "Cascadia Code", "Consolas", "Liberation Mono", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --sq-light: #eeeed2;
  --sq-dark: #6f9152;
  --sq-select: rgba(255, 214, 51, 0.55);
  --sq-last: rgba(255, 214, 51, 0.3);
  --sq-check: rgba(255, 70, 70, 0.55);
}

* , *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.premise-banner {
  text-align: center;
  background: var(--bg-sunken);
  color: var(--fg-dimmer);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
}

.top {
  text-align: center;
  padding: 22px 16px 8px;
}
.top h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.02em;
}
.top h1 .version {
  color: var(--accent);
  font-weight: 400;
}
.top .tagline {
  margin: 6px 0 0;
  color: var(--fg-dim);
  font-size: 13px;
}

.layout {
  flex: 1;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 16px 32px;
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

.board-wrap {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.eval-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 26px;
}
.eval-bar {
  position: relative;
  width: 18px;
  flex: 1;
  min-height: 200px;
  background: #1b1b1b;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.eval-fill {
  width: 100%;
  background: #eef1f5;
  height: 50%;
  transition: height 0.5s ease;
}
.eval-mid {
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(255,255,255,0.15);
}
.eval-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  white-space: nowrap;
}

.board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.board {
  width: min(78vw, 520px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--bg-sunken);
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

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

.square .coord {
  position: absolute;
  font-size: 9px;
  font-family: var(--mono);
  opacity: 0.55;
  bottom: 1px;
  right: 3px;
  pointer-events: none;
}
.square.light .coord { color: var(--sq-dark); }
.square.dark .coord { color: var(--sq-light); }

.square.last-move::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sq-last);
}
.square.selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sq-select);
}
.square.in-check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, var(--sq-check) 0%, transparent 70%);
}

.square .legal-dot {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(0,0,0,0.22);
  pointer-events: none;
}
.square .legal-ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 4px solid rgba(0,0,0,0.22);
  pointer-events: none;
}

.piece {
  font-size: min(9.5vw, 62px);
  line-height: 1;
  cursor: grab;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
.piece.white { color: #fbfbf9; -webkit-text-stroke: 1px #2b2b2b; }
.piece.black { color: #1c1c1c; }
.piece.dragging { opacity: 0.35; }
.piece.just-moved { animation: pop 0.22s ease; }
@keyframes pop {
  0% { transform: scale(0.7); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  font-size: min(9.5vw, 62px);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
  transform: translate(-50%, -50%);
}
.drag-ghost.white { color: #fbfbf9; -webkit-text-stroke: 1px #2b2b2b; }
.drag-ghost.black { color: #1c1c1c; }

.status-line {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-dim);
  min-height: 18px;
}

.side {
  width: 320px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.card-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dimmer);
  margin-bottom: 6px;
}

.engine-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-dimmer);
  flex-shrink: 0;
}
.dot.thinking {
  background: var(--accent);
  animation: blink 0.9s infinite ease-in-out;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.engine-state {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--fg);
}
.badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}
.badge.book { background: #30363d; color: var(--fg-dim); }
.badge.best { background: #1f6feb33; color: #79c0ff; }
.badge.great { background: #23863633; color: var(--green); }
.badge.good { background: #23863622; color: var(--green); }
.badge.inaccuracy { background: #d2992233; color: #e3b341; }
.badge.mistake { background: #ff7b7233; color: var(--red); }
.badge.blunder { background: #ff383333; color: #ffb3ae; }
.badge.brilliant { background: #39c5cf33; color: #56d4de; }

.engine-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-dimmer);
  margin-top: 6px;
  min-height: 13px;
}
.commentary {
  font-size: 12.5px;
  color: var(--fg);
  margin: 8px 0 0;
  font-style: italic;
  min-height: 34px;
}
.system-line {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
  margin: 4px 0 0;
}
.elo-row {
  font-size: 11.5px;
  color: var(--fg-dim);
  margin-top: 8px;
  border-top: 1px solid var(--border-soft);
  padding-top: 8px;
}
.elo-row strong { color: var(--accent); }

.opening-name {
  font-size: 13px;
}
.opening-name .eco {
  color: var(--fg-dimmer);
  font-family: var(--mono);
  font-size: 11px;
  margin-left: 6px;
}

.movelist-card {
  max-height: 220px;
  display: flex;
  flex-direction: column;
}
.movelist {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12.5px;
}
.movelist li {
  display: grid;
  grid-template-columns: 26px 1fr 1fr;
  gap: 6px;
  padding: 2px 3px;
  border-radius: 4px;
}
.movelist li .num { color: var(--fg-dimmer); }
.movelist .mv {
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
}
.movelist .mv:hover { background: var(--bg-sunken); }
.movelist .mv.active { background: var(--accent); color: var(--accent-fg); }

.trivia-text {
  font-size: 12px;
  color: var(--fg-dim);
  min-height: 48px;
}

.memory-card {
  max-height: 200px;
  display: flex;
  flex-direction: column;
}
.memory-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.memory-row {
  padding: 6px 8px;
  border-radius: 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-soft);
  transition: border-color 0.3s ease, background 0.3s ease;
}
.memory-row.in-play { border-color: var(--border); }
.memory-row.locked-in {
  border-color: var(--accent);
  background: rgba(212, 175, 55, 0.08);
}
.memory-name {
  font-size: 12px;
  font-weight: 600;
}
.memory-claim {
  font-size: 10.5px;
  color: var(--fg-dim);
  margin-top: 1px;
}
.memory-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-dimmer);
  margin-top: 3px;
}
.memory-row.locked-in .memory-count { color: var(--accent); }

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.control-row label {
  font-size: 12px;
  color: var(--fg-dim);
}
.control-row select {
  background: var(--bg-sunken);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 12.5px;
}
.control-row.buttons { gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

button {
  font-family: var(--ui);
  font-size: 12.5px;
  background: var(--bg-sunken);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, select:focus-visible, .square:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button:active { transform: translateY(1px); }

.hint {
  font-size: 11px;
  color: var(--fg-dimmer);
  margin: 4px 0 0;
}
.hint kbd {
  font-family: var(--mono);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
}
.promo-choices { display: flex; gap: 10px; margin-top: 10px; }
.promo-choices button {
  font-size: 32px;
  padding: 6px 10px;
  color: var(--fg);
}

.footer {
  text-align: center;
  padding: 18px;
  font-size: 12px;
  color: var(--fg-dimmer);
}
.footer a { color: var(--fg-dim); }

@media (max-width: 860px) {
  .layout { flex-direction: column; align-items: center; }
  .side { width: min(94vw, 520px); }
}
