:root {
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-selected: rgba(20, 85, 30, 0.5);
  --sq-last: rgba(155, 199, 0, 0.41);
  --sq-hint: rgba(255, 170, 0, 0.75);
  --sq-check: rgba(220, 30, 30, 0.85);
  --sq-target: rgba(20, 85, 30, 0.45);
}

html, body {
  min-height: 100%;
}

body {
  background: var(--bs-tertiary-bg);
  overscroll-behavior-y: none;
}

.board-wrap {
  width: 100%;
  max-width: min(100%, calc(100vh - 146px - 3.2rem), calc(100dvh - 146px - 3.2rem));
  min-width: min(100%, 280px);
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 3px solid #6d4c33;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overflow: hidden;
}

.sq {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
}

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

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

.sq.last::before { background: var(--sq-last); }
.sq.selected::before { background: var(--sq-selected); }
.sq.hint::before { background: var(--sq-hint); }
.sq.check::before { background: radial-gradient(circle, var(--sq-check) 0%, rgba(220, 30, 30, 0.35) 55%, transparent 75%); }

.sq.target::after {
  content: '';
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: var(--sq-target);
  pointer-events: none;
}

.sq.target-capture::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 5px var(--sq-target);
  pointer-events: none;
}

.board.interactive .sq { cursor: pointer; }

.piece {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.piece:not([src]) { display: none; }
.piece.dragging { opacity: 0.3; }

.piece-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
}

.piece-ghost.visible { opacity: 1; }

.coord {
  position: absolute;
  font-size: clamp(8px, 1.6vmin, 13px);
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.coord-rank { top: 3px; left: 3px; }
.coord-file { bottom: 2px; right: 3px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.moves {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  max-height: 30vh;
  overflow-y: auto;
}

.move-no {
  color: var(--bs-secondary-color);
  font-size: 0.85rem;
  margin-left: 4px;
}

.move.btn {
  --bs-btn-padding-y: 0.1rem;
  --bs-btn-padding-x: 0.35rem;
  font-family: var(--bs-font-monospace);
}

.move.btn:disabled {
  opacity: 1;
  color: var(--bs-body-color);
}

.move.active {
  background: var(--bs-primary);
  color: #fff !important;
}

.comment {
  max-height: 35vh;
  overflow-y: auto;
}

.note {
  padding: 4px 6px;
  border-left: 3px solid transparent;
  margin-bottom: 4px;
}

.note.current {
  border-left-color: var(--bs-primary);
  background: var(--bs-primary-bg-subtle);
}

.note-title {
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--bs-font-monospace);
}

.note-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.promo-piece {
  width: 52px;
  height: 52px;
}

/* Фиксированное поле подсказок над доской: высота не меняется, доска не сдвигается. */
.message-bar {
  height: 3.2rem;
  margin-bottom: 6px;
  overflow: hidden;
}

.message-bar .message {
  height: 100%;
  margin: 0;
  padding: 0.25rem 0.6rem;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  line-height: 1.25;
  overflow: hidden;
}

@media (max-width: 575.98px) {
  .btn-label { display: none; }
  .navbar-brand { font-size: 1.1rem; }
}

.tree {
  padding-left: 0;
}

.tree .tree {
  padding-left: 1.1rem;
  border-left: 1px solid var(--bs-border-color);
  margin-left: 0.4rem;
}

.tree-node {
  padding: 0.3rem 0.25rem;
  font-weight: 600;
  cursor: pointer;
}

.tree-leaf.btn {
  display: block;
  width: 100%;
  padding: 0.3rem 0.25rem;
  text-decoration: none;
  white-space: normal;
}
