/* Шахматы «Малахитовой Тайги» — пасхалка на бренде.
   UX-вдохновение: lichess — темы доски через CSS-переменные, подсветки,
   drag&drop с ghost-фигурой, панель настроек, навигация по партии. */
@font-face {
  font-family: "Russo One";
  src: url("/assets/fonts/RussoOne-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Golos Text";
  src: url("/assets/fonts/GolosText-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
:root {
  --c-deep: #06251f;
  --c-forest: #073f35;
  --c-pine: #0a2f27;
  --c-paper: #f4f6ed;
  --c-mint: #b8f3cd;
  --c-malachite: #3fbf8f;
  --c-malachite-deep: #176857;
  --c-line: #ccd6ca;
  --c-ink: #103e34;
  --c-muted: #546b60;
}
body.chess-page {
  margin: 0;
  background: var(--c-paper);
  color: var(--c-ink);
  font: 16px/1.6 "Golos Text", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
.chess-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 5vw, 64px);
  border-bottom: 1px solid var(--c-line);
  background: #fbfcf7;
}
.chess-brand { display: flex; align-items: center; gap: 12px; color: var(--c-ink); text-decoration: none; font-size: 12px; font-weight: 800; line-height: 1.35; letter-spacing: .04em; }
.chess-brand img { width: 56px; height: auto; }
.chess-header nav { display: flex; gap: 22px; font-size: 13px; }
.chess-header nav a { color: var(--c-ink); text-decoration: none; border-bottom: 1px solid transparent; }
.chess-header nav a:hover { border-color: currentColor; }

.chess-main { flex: 1; width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 46px 0 64px; }
.chess-eyebrow { margin: 0 0 14px; font-size: 11px; font-weight: 700; letter-spacing: .18em; color: var(--c-malachite-deep); }
.chess-intro h1 {
  font-family: "Russo One", Arial, sans-serif;
  font-size: clamp(34px, 4.6vw, 62px);
  line-height: 1.06;
  margin: 0 0 18px;
  letter-spacing: -.01em;
}
.chess-intro h1 em { color: var(--c-malachite-deep); font-style: oblique; display: inline-block; transform: skewX(-12deg); }
.chess-lead { max-width: 640px; color: var(--c-muted); margin: 0 0 34px; }

.chess-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
.chess-board-wrap { min-width: 0; position: relative; }

/* ── доска ─────────────────────────────────────────────────────── */

.chess-board {
  --sq-light: #e9eee1;
  --sq-dark: #2f7f66;
  --board-line: #0b4a3c;
  --coord-ink-dark: #073f35aa;
  --coord-ink-light: #f4f6edcc;
  --last-move: #b8f3cd70;
  --selected: #b8f3cd;
  --target: #073f3599;
  --target-ring: #073f35aa;
  --check: #e03131;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--board-line);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 26px 60px #103e341f;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  font-size: clamp(24px, 6.8vw, 56px);
  background: var(--sq-light);
}
.chess-board[data-theme="brown"] {
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --board-line: #7a5230;
  --coord-ink-dark: #8a6a45;
  --coord-ink-light: #fdf3e3;
  --last-move: #f7ec4e75;
  --selected: #f7ec4e;
  --target: #6b4a2f99;
  --target-ring: #6b4a2faa;
}
.chess-board[data-theme="blue"] {
  --sq-light: #dee3e6;
  --sq-dark: #8ca2ad;
  --board-line: #546b78;
  --coord-ink-dark: #5d7987;
  --coord-ink-light: #f2f7f9;
  --last-move: #99d1e07a;
  --selected: #9ad4e5;
  --target: #2f485899;
  --target-ring: #2f4858aa;
}
.chess-board[data-theme="grey"] {
  --sq-light: #e6e6e6;
  --sq-dark: #9c9c9c;
  --board-line: #6f6f6f;
  --coord-ink-dark: #6c6c6c;
  --coord-ink-light: #fafafa;
  --last-move: #f2d64b7a;
  --selected: #f2d64b;
  --target: #40404099;
  --target-ring: #404040aa;
}
.chess-row { display: contents; }
.chess-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  font-size: 1em;
  line-height: 1;
  color: inherit;
  background: var(--sq-light);
  transition: background-color .12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  outline: none;
}
.chess-square.light { background: var(--sq-light); }
.chess-square.dark { background: var(--sq-dark); }
.chess-square.movable { cursor: grab; }
.chess-square.movable:active { cursor: grabbing; }
.chess-square.viewing { cursor: default; }
@media (hover: hover) {
  .chess-square:hover:not(.selected) { box-shadow: inset 0 0 0 2px #b8f3cd88; }
  .chess-square.dark:hover:not(.selected) { box-shadow: inset 0 0 0 2px #b8f3cd77; }
}
.chess-square:focus-visible { outline: 3px solid var(--c-forest); outline-offset: -3px; z-index: 2; }
.chess-square.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last-move);
  pointer-events: none;
}
.chess-square.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, #e03131e0 0%, #e0313180 42%, transparent 72%);
  pointer-events: none;
}
.chess-square.selected { box-shadow: inset 0 0 0 4px var(--selected); }
.chess-square.dragging .piece { opacity: .28; }
.chess-square.drag-over { box-shadow: inset 0 0 0 4px var(--selected); }
.chess-square.target::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--target);
  pointer-events: none;
  z-index: 0;
}
.chess-square.target.capture::after {
  width: 76%;
  height: 76%;
  background: transparent;
  border: 3px solid var(--target-ring);
}
.chess-board.hide-legal .chess-square.target::after { display: none; }
.chess-square .piece {
  position: relative;
  z-index: 1;
  pointer-events: none;
  font-size: 1em;
  line-height: 1;
  will-change: opacity;
}
.chess-square .piece.w { color: #f9fcf3; text-shadow: 0 1px 0 #06251f, 0 0 2px #06251f; }
.chess-square .piece.b { color: #06251f; text-shadow: 0 1px 0 #f4f6edaa; }
.chess-square .coord {
  position: absolute;
  font-family: "Golos Text", Arial, sans-serif;
  font-size: clamp(8px, 1.05vw, 11px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  opacity: .85;
}
.chess-square.light .coord { color: var(--coord-ink-dark); }
.chess-square.dark .coord { color: var(--coord-ink-light); }
.chess-square .coord.file { right: 4px; bottom: 3px; }
.chess-square .coord.rank { left: 4px; top: 3px; }
.chess-board:not(.show-coords) .coord { display: none; }

/* контейнерные единицы — глиф ровно по размеру клетки */
@supports (container-type: inline-size) {
  .chess-board-wrap { container-type: inline-size; }
  .chess-board .chess-square { font-size: 9.2cqw; }
  .chess-square .coord { font-size: 1.45cqw; }
}

/* ghost под курсором и FLIP-подобная анимация */
.chess-drag-ghost {
  position: fixed;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  filter: drop-shadow(0 10px 14px rgba(6, 37, 31, .35));
  line-height: 1;
  will-change: left, top;
}
.chess-drag-ghost.w { color: #f9fcf3; text-shadow: 0 1px 0 #06251f, 0 0 2px #06251f; }
.chess-drag-ghost.b { color: #06251f; text-shadow: 0 1px 0 #f4f6edaa; }
.chess-anim-piece {
  position: fixed;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
  transition: transform .17s cubic-bezier(.2, .7, .25, 1);
  will-change: transform;
}
.chess-anim-piece.w { color: #f9fcf3; text-shadow: 0 1px 0 #06251f, 0 0 2px #06251f; }
.chess-anim-piece.b { color: #06251f; text-shadow: 0 1px 0 #f4f6edaa; }

.chess-board-help { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: #7b8f84; max-width: 720px; }

/* ── диалог превращения ────────────────────────────────────────── */

.chess-promo {
  position: absolute;
  z-index: 40;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px;
  background: #fbfcf7;
  border: 1px solid var(--c-line);
  border-radius: 12px;
  box-shadow: 0 24px 54px #06251f33;
}
.chess-promo[hidden] { display: none !important; }
.chess-promo.up { transform: translate(-50%, -100%); }
.chess-promo.down { transform: translateX(-50%); }
.chess-promo-title {
  margin: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c-muted);
}
.chess-promo-options { display: grid; gap: 4px; }
.chess-promo-btn {
  width: var(--promo-size, 54px);
  height: var(--promo-size, 54px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid #b7cfc2;
  border-radius: 8px;
  background: #fff;
  color: var(--c-ink);
  font-size: calc(var(--promo-size, 54px) * .58);
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.chess-promo-btn:hover { background: #eef4e9; border-color: var(--c-malachite-deep); }
.chess-promo-btn:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 1px; }
.chess-promo-btn span {
  font: 700 8px "Golos Text", Arial, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-muted);
}
.chess-promo-cancel {
  border: 0;
  background: transparent;
  color: var(--c-muted);
  font: 600 11px "Golos Text", Arial, sans-serif;
  padding: 4px;
  cursor: pointer;
  text-decoration: underline;
}
.chess-promo-cancel:focus-visible { outline: 2px solid var(--c-forest); outline-offset: 2px; }

.chess-captured { min-height: 28px; margin-top: 12px; font-size: 22px; color: #6d8a7d; letter-spacing: 2px; }

/* ── панель управления ─────────────────────────────────────────── */

.chess-panel { background: #fbfcf7; border: 1px solid var(--c-line); border-radius: 14px; padding: 22px; position: sticky; top: 18px; }
.chess-panel-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.chess-status { flex: 1; font-family: "Russo One", Arial, sans-serif; font-size: 15px; line-height: 1.45; min-height: 44px; }
.chess-status strong { color: var(--c-malachite-deep); }
.chess-view-tag {
  display: inline-block;
  margin: 0 8px 4px 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: #e4efe6;
  color: var(--c-malachite-deep);
  font: 700 10px "Golos Text", Arial, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.chess-icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #b7cfc2;
  border-radius: 8px;
  background: #eef4e9;
  color: var(--c-malachite-deep);
  font-size: 19px;
  cursor: pointer;
  transition: background .15s ease;
}
.chess-icon-btn:hover { background: #e2ecdc; }
.chess-icon-btn:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }
.chess-icon-btn[aria-expanded="true"] { background: var(--c-malachite-deep); color: #fff; }

.chess-settings {
  position: absolute;
  top: 58px;
  right: 16px;
  z-index: 30;
  width: 300px;
  display: grid;
  gap: 16px;
  padding: 16px;
  background: #fbfcf7;
  border: 1px solid var(--c-line);
  border-radius: 12px;
  box-shadow: 0 24px 54px #06251f26;
}
.chess-settings[hidden] { display: none !important; }
.chess-settings-group { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.chess-settings-label { font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: var(--c-muted); }
.chess-themes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chess-theme {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-ink);
  font: 600 12px "Golos Text", Arial, sans-serif;
  cursor: pointer;
  text-align: left;
}
.chess-theme:hover { border-color: #9cbcab; }
.chess-theme[aria-checked="true"] { border-color: var(--c-malachite-deep); box-shadow: inset 0 0 0 1px var(--c-malachite-deep); }
.chess-theme:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }
.chess-theme-swatch {
  width: 38px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 5px;
  border: 1px solid #00000022;
  background-image: conic-gradient(var(--sw-d) 25%, var(--sw-l) 0 50%, var(--sw-d) 0 75%, var(--sw-l) 0);
  background-size: 13px 13px;
}
.chess-theme-swatch.green { --sw-l: #e9eee1; --sw-d: #2f7f66; }
.chess-theme-swatch.brown { --sw-l: #f0d9b5; --sw-d: #b58863; }
.chess-theme-swatch.blue { --sw-l: #dee3e6; --sw-d: #8ca2ad; }
.chess-theme-swatch.grey { --sw-l: #e6e6e6; --sw-d: #9c9c9c; }
.chess-toggles { display: grid; gap: 2px; }
.chess-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
}
.chess-switch:hover { background: #f1f6ee; }
.chess-switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: #cfdacd;
  position: relative;
  cursor: pointer;
  transition: background .15s ease;
}
.chess-switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px #06251f33;
  transition: transform .15s ease;
}
.chess-switch input:checked { background: var(--c-malachite-deep); }
.chess-switch input:checked::after { transform: translateX(16px); }
.chess-switch input:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }

.chess-controls { display: grid; gap: 10px; }
.chess-select { display: grid; gap: 6px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--c-muted); }
.chess-select select { height: 44px; border: 1px solid var(--c-line); border-radius: 8px; padding: 0 12px; font: 15px "Golos Text", Arial, sans-serif; color: var(--c-ink); background: #fff; }
.chess-btn {
  min-height: 44px; border: 0; border-radius: 8px; padding: 0 16px;
  background: var(--c-malachite-deep); color: #fff;
  font: 600 14px "Golos Text", Arial, sans-serif; cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.chess-btn:hover { background: #0d4f41; }
.chess-btn:active { transform: translateY(1px); }
.chess-btn:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }
.chess-btn-ghost { background: transparent; color: var(--c-malachite-deep); border: 1px solid #b7cfc2; }
.chess-btn-ghost:hover { background: #eef4e9; }
.chess-btn:disabled { opacity: .45; cursor: default; transform: none; }

/* ── список ходов и навигация ───────────────────────────────────── */

.chess-moves-block { margin-top: 22px; border-top: 1px solid var(--c-line); padding-top: 16px; }
.chess-moves-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chess-moves-head h2 { font-family: "Russo One", Arial, sans-serif; font-size: 13px; letter-spacing: .08em; margin: 0; color: var(--c-muted); font-weight: 400; }
.chess-nav { display: flex; gap: 4px; }
.chess-nav-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-line);
  border-radius: 7px;
  background: #fff;
  color: var(--c-ink);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease;
}
.chess-nav-btn:hover:not(:disabled) { background: #eef4e9; }
.chess-nav-btn:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }
.chess-nav-btn:disabled { opacity: .35; cursor: default; }
.chess-moves {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  align-content: start;
  gap: 2px 4px;
  max-height: 244px;
  overflow: auto;
  font-size: 14px;
  padding-right: 2px;
  scrollbar-width: thin;
}
.chess-move-row { display: contents; }
.chess-move-num { padding: 5px 2px; color: var(--c-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chess-move-spacer { display: block; }
.chess-move {
  border: 0;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 6px;
  background: transparent;
  color: #2e4a40;
  font: 600 14px "Golos Text", Arial, sans-serif;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.chess-move:hover { background: #eef4e9; }
.chess-move:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 1px; }
.chess-move.is-current { background: var(--c-malachite-deep); color: #fff; }
.chess-move.is-current:hover { background: #0d4f41; }
.chess-moves-empty { margin: 0; padding: 6px 2px; font-size: 13px; color: #7b8f84; grid-column: 1 / -1; }
.chess-jump-live {
  width: 100%;
  margin-top: 10px;
  min-height: 38px;
  border: 1px dashed #9cbcab;
  border-radius: 8px;
  background: #eef4e9;
  color: var(--c-malachite-deep);
  font: 600 13px "Golos Text", Arial, sans-serif;
  cursor: pointer;
}
.chess-jump-live:hover { background: #e2ecdc; }
.chess-jump-live:focus-visible { outline: 3px solid var(--c-forest); outline-offset: 2px; }
.chess-jump-live[hidden] { display: none !important; }

.chess-export { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.chess-export .chess-btn { min-height: 40px; font-size: 12px; padding: 0 8px; }
.chess-hint { margin: 16px 0 0; font-size: 12px; line-height: 1.55; color: #7b8f84; }
.chess-hint kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid #c6d4c9;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  color: var(--c-ink);
  font: 600 11px "Golos Text", Arial, sans-serif;
}

.chess-footer { border-top: 1px solid var(--c-line); padding: 18px clamp(18px, 5vw, 64px); display: flex; justify-content: space-between; gap: 18px; font-size: 12px; color: var(--c-muted); }
.chess-footer a { color: var(--c-ink); text-decoration: none; border-bottom: 1px solid currentColor; }
.chess-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--c-forest); color: var(--c-paper); padding: 10px 18px; border-radius: 999px; font-size: 13px; box-shadow: 0 12px 30px #06251f44; z-index: 10; max-width: calc(100% - 32px); text-align: center; }
.chess-toast[hidden] { display: none !important; }

.chess-board.thinking { opacity: .82; pointer-events: none; }
.chess-gameover { text-align: center; }
.chess-gameover strong { display: block; font-family: "Russo One", Arial, sans-serif; font-size: 18px; color: var(--c-ink); margin-bottom: 4px; }

body.chess-dragging { cursor: grabbing; }
body.chess-dragging .chess-square { cursor: grabbing; }

@media (max-width: 900px) {
  .chess-layout { grid-template-columns: 1fr; }
  .chess-panel { position: static; }
  .chess-settings { position: static; width: auto; margin: 0 0 14px; box-shadow: none; border-radius: 10px; }
  .chess-moves { max-height: 190px; }
  .chess-header nav a:first-child { display: none; }
}
@media (max-width: 520px) {
  .chess-main { padding-top: 28px; }
  .chess-panel { padding: 18px; }
  .chess-header { gap: 12px; }
  .chess-brand span { font-size: 11px; }
  .chess-export { grid-template-columns: 1fr; }
  .chess-board-help { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .chess-square, .chess-btn, .chess-switch input, .chess-switch input::after,
  .chess-anim-piece, .chess-nav-btn, .chess-move { transition: none !important; }
}
/* Пасхалка: главная страница — маленькая пешка в футере */
