:root {
  --bg: #0e1116;
  --bg-2: #12151c;
  --panel: #161a23;
  --panel-2: #1b2029;
  --line: #242a36;
  --line-2: #2f3746;
  --text: #e7ebf3;
  --muted: #8d97a9;
  --muted-2: #6c768a;
  --accent: #5b8def;
  --accent-strong: #3f74dd;
  --danger: #e2564f;
  --ok: #45b378;
  --sq-light: #c8d0dc;
  --sq-dark: #5a6579;
  --sq-hl: #d8b64a;
  --sq-last: #8ec7a3;
  --sq-check: #e2564f;
  --board-max: 620px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-size: 18px;
  line-height: 1;
}

.brand-name {
  letter-spacing: 0.2px;
}

.brand-tld {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.main {
  flex: 1 0 auto;
  padding: 24px 20px 32px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 24px;
  justify-items: center;
  align-items: start;
}

.stage {
  display: flex;
  gap: 10px;
  align-items: stretch;
  width: 100%;
  justify-content: center;
}

.board-host {
  width: 100%;
  max-width: var(--board-max);
}

.evalbar {
  position: relative;
  width: 16px;
  flex: 0 0 16px;
  background: #22262f;
  border: 1px solid var(--line-2);
  overflow: hidden;
}

.evalbar-white {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #eef1f6;
  transition: height 180ms linear;
}

.evalbar-score {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  writing-mode: vertical-rl;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  padding: 4px 1px;
  line-height: 1;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line-2);
  background: var(--sq-dark);
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
}

.squares {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

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

.sq::before {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}

.sq.is-last::before {
  background: rgba(142, 199, 163, 0.42);
}

.sq.is-selected::before {
  background: rgba(216, 182, 74, 0.55);
}

.sq.is-check::before {
  background: rgba(226, 86, 79, 0.6);
}

.sq.is-target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 24, 32, 0.32);
  pointer-events: none;
}

.sq.is-target.has-piece::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 4px solid rgba(20, 24, 32, 0.3);
  box-sizing: border-box;
}

.sq.is-dragging .piece {
  opacity: 0;
}

.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
}

.coord-file {
  right: 3px;
  bottom: 2px;
}

.coord-rank {
  left: 3px;
  top: 2px;
}

.sq.is-light .coord {
  color: var(--sq-dark);
}

.sq.is-dark .coord {
  color: var(--sq-light);
}

.piece {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  pointer-events: none;
}

.piece svg {
  width: 92%;
  height: 92%;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.board-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.drag-ghost {
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  z-index: 5;
}

.drag-ghost svg {
  width: 96%;
  height: 96%;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
}

.block {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.block:last-child {
  border-bottom: none;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 3px;
}

.btn:hover:not(:disabled) {
  background: #232936;
  border-color: #3a4356;
}

.btn:active:not(:disabled) {
  background: #1d222d;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
}

.btn-accent {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #ffffff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: #ef6a63;
  border-color: #ef6a63;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 13px;
}

.btn-icon {
  padding: 6px 9px;
  font-size: 13px;
  line-height: 1;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.seg {
  display: flex;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  appearance: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--line-2);
  color: var(--muted);
  padding: 8px 6px;
  font-size: 13px;
  cursor: pointer;
}

.seg-btn:last-child {
  border-right: none;
}

.seg-btn:hover {
  color: var(--text);
  background: #1f2430;
}

.seg-btn.is-active {
  background: var(--accent-strong);
  color: #ffffff;
}

.field {
  display: block;
  margin-top: 12px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.output {
  font-family: var(--mono);
  color: var(--text);
}

.input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.textarea {
  font-family: var(--mono);
  font-size: 12px;
  resize: vertical;
  min-height: 76px;
}

.input-sm {
  width: auto;
  padding: 7px 8px;
  font-size: 13px;
}

.inline {
  display: flex;
  gap: 8px;
}

.inline .input {
  flex: 1;
  min-width: 0;
}

.range {
  width: 100%;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.check-inline {
  margin-top: 0;
}

.check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.ai-settings {
  margin-top: 12px;
}

.status {
  font-size: 15px;
  font-weight: 600;
  min-height: 22px;
}

.status .sub {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.chip {
  font-size: 12px;
  font-family: var(--mono);
  padding: 2px 7px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.nav-label {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted-2);
}

.moves {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: var(--bg-2);
}

.moves:empty {
  display: none;
}

.mvrow {
  display: grid;
  grid-template-columns: 3.2em 1fr 1fr;
  gap: 4px;
  padding: 3px 6px;
  border-bottom: 1px solid rgba(36, 42, 54, 0.7);
}

.mvrow:last-child {
  border-bottom: none;
}

.mvrow.is-active {
  background: #1f2531;
}

.mvnum {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted-2);
  padding-top: 3px;
}

.san {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  text-align: left;
  padding: 3px 5px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.san:hover {
  background: #242b38;
}

.san.is-current {
  background: var(--accent-strong);
  color: #ffffff;
}

.san:disabled {
  cursor: default;
}

.cls {
  display: inline-block;
  margin-left: 4px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}

.cls-best {
  color: #45b378;
}

.cls-excellent {
  color: #7ec9a0;
}

.cls-good {
  color: #9aa6bb;
}

.cls-inaccuracy {
  color: #e0b34a;
}

.cls-mistake {
  color: #e08a3c;
}

.cls-blunder {
  color: #e2564f;
}

.progress {
  margin-top: 12px;
}

.progress-track {
  height: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-track i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms linear;
}

.progress-text {
  display: block;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted-2);
}

.acc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.acc-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 8px;
}

.acc-name {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.acc-value {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  margin-top: 2px;
}

.tally {
  display: block;
  margin-top: 10px;
}

.tally-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}

.tally-row:last-child {
  border-bottom: none;
}

.tally-head {
  min-width: 4.2em;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted-2);
}

.tally-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tally-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
}

.engine-meta {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted-2);
}

.lines {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.line {
  display: grid;
  grid-template-columns: 4.6em 3.4em 1fr;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.line-score {
  color: var(--text);
  text-align: right;
}

.line-depth {
  color: var(--muted-2);
  text-align: right;
}

.line-pv {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line.is-best .line-score {
  color: var(--accent);
}

.error {
  margin: 10px 0 0;
  padding: 8px 10px;
  background: rgba(226, 86, 79, 0.12);
  border: 1px solid rgba(226, 86, 79, 0.5);
  color: #f0a9a4;
  font-size: 13px;
}

.game-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.game-id {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.game-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.players {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  padding: 7px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.player-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pc {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border: 1px solid var(--line-2);
}

.pc-white {
  background: #eef1f6;
}

.pc-black {
  background: #14181f;
}

.player-rating {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.game-links {
  margin-top: 10px;
  font-size: 13px;
}

.foot {
  padding: 20px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted-2);
  font-size: 12px;
  text-align: center;
}

.foot p {
  margin: 4px 0;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.busy {
  position: fixed;
  left: 50%;
  top: 74px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-size: 13px;
  z-index: 40;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-size: 13px;
  z-index: 50;
  max-width: min(92vw, 560px);
  text-align: center;
}

.promo {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.promo-box {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line-2);
}

.promo-btn {
  width: 64px;
  height: 64px;
  background: var(--sq-light);
  border: 1px solid var(--line-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.promo-btn:hover {
  background: #ffffff;
}

.promo-btn svg {
  width: 90%;
  height: 90%;
}

.noscript {
  margin: 40px auto;
  max-width: 520px;
  padding: 16px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage {
    justify-content: center;
    width: 100%;
  }

  .board-host {
    width: min(100%, 560px);
  }

  .moves {
    max-height: 200px;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 14px;
  }

  .main {
    padding: 14px 10px 24px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .topbar-actions .btn {
    padding: 6px 8px;
    font-size: 13px;
  }

  .block {
    padding: 13px;
  }

  .evalbar {
    width: 12px;
    flex-basis: 12px;
  }
}
