* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  /* Профиль «Мастерская» — значения по умолчанию; другие: [data-board-profile] */
  --ch-frame-border: #2a3140;
  --ch-frame-bg: #0b0c10;
  --ch-board-bg: #14161c;
  --ch-board-inset: rgba(0, 0, 0, 0.35);
  --ch-cell-l: #3d4049;
  --ch-cell-l-fg: #b8b5c0;
  --ch-cell-d: #2a282e;
  --ch-cell-d-fg: #8f8a96;
  --ch-sel: rgba(200, 175, 130, 0.55);
  --ch-mv-dot: rgba(200, 195, 210, 0.35);
  --ch-mv-glow: rgba(150, 160, 200, 0.35);
  --ch-cap-b: rgba(180, 120, 110, 0.5);
  --ch-cap-bg: rgba(80, 50, 45, 0.15);
  --ch-w-fb: #bda898;
  --ch-w1: #f0e4d8;
  --ch-w2: #9d8a7a;
  --ch-w3: #d4c2b0;
  --ch-w-drop: rgba(0, 0, 0, 0.5);
  --ch-b1: #0c0f16;
  --ch-b2: #0a0d15;
  --ch-b-str: rgba(168, 188, 220, 0.85);
  --ch-b-sh1: rgba(120, 150, 200, 0.22);
  --ch-b-sh2: rgba(0, 0, 0, 0.55);
  --ch-last: rgba(120, 140, 180, 0.45);
  --ch-bota1: rgba(195, 165, 115, 0.65);
  --ch-bota2: rgba(170, 140, 95, 0.35);
  --ch-botb1: rgba(180, 150, 100, 0.55);
  --ch-botb2: rgba(160, 130, 90, 0.25);
  --ch-chk: #4a2a2e;
  --ch-chk-b: rgba(180, 100, 100, 0.35);
  --ch-botthink: rgba(8, 14, 32, 0.22);
  background:
    radial-gradient(circle at top left, rgba(74, 139, 255, 0.18), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(182, 120, 255, 0.16), transparent 26rem),
    #0f1220;
  color: #d9e1f4;
  font-family: Arial, sans-serif;
}

/* Сумерки над Невой — сине-лиловый холод */
body[data-board-profile="neva"] {
  --ch-frame-border: #2a3550;
  --ch-frame-bg: #060810;
  --ch-board-bg: #0e1018;
  --ch-board-inset: rgba(20, 30, 60, 0.5);
  --ch-cell-l: #38405a;
  --ch-cell-l-fg: #aeb4c8;
  --ch-cell-d: #202434;
  --ch-cell-d-fg: #8c90a5;
  --ch-sel: rgba(160, 175, 220, 0.5);
  --ch-mv-dot: rgba(180, 190, 230, 0.4);
  --ch-mv-glow: rgba(120, 140, 200, 0.4);
  --ch-cap-b: rgba(160, 130, 180, 0.45);
  --ch-cap-bg: rgba(40, 30, 60, 0.2);
  --ch-w-fb: #a8a0b0;
  --ch-w1: #e4e0ec;
  --ch-w2: #756a88;
  --ch-w3: #c8c0d4;
  --ch-w-drop: rgba(0, 0, 0, 0.55);
  --ch-b1: #0a0c14;
  --ch-b2: #080a12;
  --ch-b-str: rgba(190, 200, 235, 0.75);
  --ch-b-sh1: rgba(100, 130, 200, 0.25);
  --ch-b-sh2: rgba(0, 0, 0, 0.6);
  --ch-last: rgba(130, 150, 210, 0.5);
  --ch-bota1: rgba(150, 170, 230, 0.5);
  --ch-bota2: rgba(100, 120, 200, 0.35);
  --ch-botb1: rgba(130, 150, 210, 0.45);
  --ch-botb2: rgba(90, 110, 180, 0.3);
  --ch-chk: #3a2848;
  --ch-chk-b: rgba(160, 120, 200, 0.35);
  --ch-botthink: rgba(10, 14, 40, 0.25);
}

/* Окно в заливе — тёплый янтарь, сиена */
body[data-board-profile="window"] {
  --ch-frame-border: #4a3f32;
  --ch-frame-bg: #0f0c08;
  --ch-board-bg: #1a1510;
  --ch-board-inset: rgba(40, 25, 10, 0.45);
  --ch-cell-l: #4a4036;
  --ch-cell-l-fg: #c4b8a8;
  --ch-cell-d: #2e2820;
  --ch-cell-d-fg: #9a9084;
  --ch-sel: rgba(220, 175, 110, 0.5);
  --ch-mv-dot: rgba(230, 200, 150, 0.35);
  --ch-mv-glow: rgba(200, 150, 90, 0.3);
  --ch-cap-b: rgba(200, 120, 80, 0.55);
  --ch-cap-bg: rgba(60, 35, 20, 0.2);
  --ch-w-fb: #c4a888;
  --ch-w1: #f8ecd8;
  --ch-w2: #8f6e58;
  --ch-w3: #e0c8a8;
  --ch-w-drop: rgba(40, 20, 10, 0.45);
  --ch-b1: #120e0a;
  --ch-b2: #0f0c08;
  --ch-b-str: rgba(210, 175, 140, 0.8);
  --ch-b-sh1: rgba(180, 140, 100, 0.3);
  --ch-b-sh2: rgba(0, 0, 0, 0.55);
  --ch-last: rgba(200, 160, 100, 0.5);
  --ch-bota1: rgba(230, 190, 120, 0.55);
  --ch-bota2: rgba(200, 150, 80, 0.35);
  --ch-botb1: rgba(210, 170, 110, 0.5);
  --ch-botb2: rgba(180, 130, 70, 0.3);
  --ch-chk: #4a2820;
  --ch-chk-b: rgba(200, 100, 80, 0.4);
  --ch-botthink: rgba(30, 20, 10, 0.2);
}

/* Ночной этюд — глубокий контраст */
body[data-board-profile="nocturne"] {
  --ch-frame-border: #1e1e24;
  --ch-frame-bg: #050508;
  --ch-board-bg: #0c0c10;
  --ch-board-inset: rgba(0, 0, 0, 0.55);
  --ch-cell-l: #2e3038;
  --ch-cell-l-fg: #a0a0a8;
  --ch-cell-d: #16161a;
  --ch-cell-d-fg: #707078;
  --ch-sel: rgba(230, 210, 140, 0.45);
  --ch-mv-dot: rgba(255, 255, 255, 0.22);
  --ch-mv-glow: rgba(200, 200, 220, 0.2);
  --ch-cap-b: rgba(240, 120, 100, 0.5);
  --ch-cap-bg: rgba(40, 15, 15, 0.25);
  --ch-w-fb: #a89888;
  --ch-w1: #e8dcc8;
  --ch-w2: #6a5848;
  --ch-w3: #c8b498;
  --ch-w-drop: rgba(0, 0, 0, 0.65);
  --ch-b1: #08080a;
  --ch-b2: #050508;
  --ch-b-str: rgba(200, 200, 225, 0.9);
  --ch-b-sh1: rgba(80, 100, 140, 0.3);
  --ch-b-sh2: rgba(0, 0, 0, 0.65);
  --ch-last: rgba(180, 190, 220, 0.5);
  --ch-bota1: rgba(255, 220, 140, 0.5);
  --ch-bota2: rgba(200, 170, 100, 0.35);
  --ch-botb1: rgba(230, 200, 130, 0.45);
  --ch-botb2: rgba(180, 150, 90, 0.25);
  --ch-chk: #3a2024;
  --ch-chk-b: rgba(220, 100, 100, 0.4);
  --ch-botthink: rgba(0, 0, 0, 0.35);
}

/* Северный сад — зелёно-дымчатый */
body[data-board-profile="north"] {
  --ch-frame-border: #2d3834;
  --ch-frame-bg: #080a09;
  --ch-board-bg: #101412;
  --ch-board-inset: rgba(20, 40, 30, 0.4);
  --ch-cell-l: #3a4540;
  --ch-cell-l-fg: #b0b8b4;
  --ch-cell-d: #262e2a;
  --ch-cell-d-fg: #8a928e;
  --ch-sel: rgba(160, 200, 170, 0.45);
  --ch-mv-dot: rgba(180, 210, 190, 0.3);
  --ch-mv-glow: rgba(120, 160, 140, 0.3);
  --ch-cap-b: rgba(140, 180, 150, 0.45);
  --ch-cap-bg: rgba(20, 40, 30, 0.2);
  --ch-w-fb: #a8b0a4;
  --ch-w1: #eef2e8;
  --ch-w2: #5a6860;
  --ch-w3: #c8d0c8;
  --ch-w-drop: rgba(10, 25, 15, 0.5);
  --ch-b1: #0c100e;
  --ch-b2: #0a0e0c;
  --ch-b-str: rgba(170, 200, 185, 0.8);
  --ch-b-sh1: rgba(100, 140, 120, 0.25);
  --ch-b-sh2: rgba(0, 0, 0, 0.55);
  --ch-last: rgba(140, 170, 155, 0.5);
  --ch-bota1: rgba(180, 210, 185, 0.45);
  --ch-bota2: rgba(120, 160, 140, 0.3);
  --ch-botb1: rgba(160, 195, 175, 0.4);
  --ch-botb2: rgba(110, 150, 130, 0.25);
  --ch-chk: #2a352e;
  --ch-chk-b: rgba(100, 160, 130, 0.4);
  --ch-botthink: rgba(8, 20, 14, 0.22);
}

.layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  padding: 24px 24px 8px;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-area {
  display: flex;
  flex-direction: column;
  width: 280px;
}

.clock-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: min(82vw, 560px);
}

.clock-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #2e3557;
  border-radius: 10px;
  background: rgba(22, 29, 56, 0.92);
  color: #c4ccee;
  padding: 10px 12px;
}

.clock-card.active {
  border-color: rgba(255, 212, 71, 0.78);
  box-shadow: 0 0 18px rgba(255, 212, 71, 0.18);
}

body.bot-thinking .clock-card.active {
  border-color: rgba(120, 190, 255, 0.85);
  box-shadow: 0 0 22px rgba(100, 170, 255, 0.28);
  animation: bot-clock-pulse 0.9s ease-in-out infinite;
}

@keyframes bot-clock-pulse {
  0%,
  100% {
    box-shadow: 0 0 16px rgba(100, 170, 255, 0.22);
  }
  50% {
    box-shadow: 0 0 26px rgba(130, 200, 255, 0.38);
  }
}

body.bot-thinking .board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: var(--ch-botthink);
  pointer-events: none;
  z-index: 2;
}

.clock-card strong {
  color: #edf2ff;
  font-size: 20px;
  letter-spacing: 0.5px;
}

.captured-bar {
  width: min(82vw, 560px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 4px 0;
  font-size: 13px;
  color: #a8b0c8;
}

.captured-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  line-height: 1.35;
}

.captured-label {
  flex: 0 0 auto;
  min-width: 7.5rem;
  color: #8a94b0;
}

.captured-glyphs {
  flex: 1 1 auto;
  font-size: clamp(16px, 3.5vw, 26px);
  line-height: 1;
  letter-spacing: 0.06em;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols2", "Apple Symbols", "Arial Unicode MS", sans-serif;
  color: #d0d6e8;
  min-height: 1.2em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.02em 0.12em;
}

.captured-glyphs .piece.captured-taken {
  position: static;
  display: inline-block;
  pointer-events: none;
  font-size: 1em;
  font-weight: 500;
  line-height: 1;
  vertical-align: middle;
}

.board-wrap {
  position: relative;
  border: 2px solid var(--ch-frame-border);
  background: var(--ch-frame-bg);
  padding: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(82vw, 560px);
  height: min(82vw, 560px);
  max-width: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  background: var(--ch-board-bg);
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px var(--ch-board-inset);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: none;
  margin: 0;
  padding: 0;
  color: #edf2ff;
  font-size: clamp(36px, 10.5vw, 76px);
  line-height: 0.92;
  cursor: pointer;
}

.cell.light {
  background: var(--ch-cell-l);
  color: var(--ch-cell-l-fg);
}

.cell.dark {
  background: var(--ch-cell-d);
  color: var(--ch-cell-d-fg);
}

.cell.selected {
  box-shadow: inset 0 0 0 2px var(--ch-sel);
  border-radius: 1px;
}

.cell.move-target::after,
.cell.capture-target::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 999px;
  background: var(--ch-mv-dot);
  box-shadow: 0 0 10px var(--ch-mv-glow);
}

.cell.capture-target::after {
  width: 74%;
  height: 74%;
  border: 2px solid var(--ch-cap-b);
  background: var(--ch-cap-bg);
  box-shadow: none;
}

.piece {
  position: relative;
  z-index: 1;
  pointer-events: none;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols2", "Apple Symbols", "Arial Unicode MS", sans-serif;
  text-rendering: optimizeLegibility;
  paint-order: stroke fill;
}

/* Старые движки: плоский тёплый / тёмный тон */
.piece.white-piece {
  color: var(--ch-w-fb);
  text-shadow: 0.04em 0.1em 0.12em rgba(0, 0, 0, 0.45);
}

.piece.black-piece {
  font-weight: 700;
  text-rendering: geometricPrecision;
  color: var(--ch-b1);
  -webkit-text-fill-color: var(--ch-b2);
  -webkit-text-stroke: 0.035em var(--ch-b-str);
  text-shadow: 0 0.06em 0.1em var(--ch-b-sh1), 0 0.11em 0.18em var(--ch-b-sh2);
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .piece.white-piece {
    color: transparent;
    background: linear-gradient(158deg, var(--ch-w1) 0%, var(--ch-w2) 42%, var(--ch-w3) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter: drop-shadow(0.05em 0.1em 0.12em var(--ch-w-drop));
  }
}

.last-move {
  box-shadow: inset 0 0 0 2px var(--ch-last);
}

.bot-last-move {
  animation: bot-move-pulse 1.8s ease-out;
  box-shadow: inset 0 0 0 2px var(--ch-botb1), 0 0 14px var(--ch-botb2);
}

@keyframes bot-move-pulse {
  0% {
    box-shadow: inset 0 0 0 2px var(--ch-bota1), 0 0 16px var(--ch-bota2);
  }
  100% {
    box-shadow: inset 0 0 0 2px var(--ch-botb1), 0 0 14px var(--ch-botb2);
  }
}

.check {
  background: var(--ch-chk) !important;
  box-shadow: inset 0 0 0 1px var(--ch-chk-b);
}

.panel {
  width: 280px;
  background: rgba(22, 29, 56, 0.92);
  border: 1px solid #2e3557;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
  font-size: 14px;
  line-height: 1.35;
}

h1,
h2 {
  margin: 0 0 12px;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
  margin-top: 16px;
}

.stat {
  margin-bottom: 6px;
  line-height: 1.35;
}

.stat span {
  color: #e6ecfb;
  font-weight: 700;
}

.controls ul {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.35;
}

.controls li {
  margin-bottom: 4px;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  font-size: 13px;
}

select {
  width: 100%;
  border: 1px solid #45568f;
  border-radius: 8px;
  background: #10162b;
  color: #d9e1f4;
  padding: 10px 12px;
  font-size: 14px;
}

button {
  margin-top: 16px;
  width: 100%;
  border: none;
  border-radius: 8px;
  background: #4a8bff;
  color: #edf2ff;
  padding: 10px 12px;
  font-size: 15px;
  cursor: pointer;
}

button:hover {
  background: #6ca2ff;
}

.mobile-stats,
.mobile-info-toggle,
.mobile-info-panel {
  display: none;
}

.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 0;
  color: #7f8bb7;
  font-size: 13px;
}

.app-footer .footer-sep,
.mobile-app-footer .footer-sep {
  opacity: 0.45;
  user-select: none;
}

.app-footer .footer-game,
.mobile-app-footer .footer-game {
  color: #b4c0e0;
  font-weight: 600;
}

.mobile-app-footer {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
}

.overlay-content {
  width: min(90vw, 360px);
  border: 1px solid #3d4772;
  border-radius: 10px;
  background: #1b2442;
  padding: 20px;
  text-align: center;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    padding: 28px 14px 12px;
    gap: 10px;
  }

  .board-wrap {
    padding: 6px;
  }

  .clock-panel {
    width: min(94vw, 520px);
  }

  .clock-card {
    padding: 8px 10px;
    font-size: 13px;
  }

  .clock-card strong {
    font-size: 18px;
  }

  .board {
    width: min(94vw, 520px);
    height: min(94vw, 520px);
    max-width: none;
    max-height: none;
  }

  .captured-bar {
    width: min(94vw, 520px);
  }

  .captured-label {
    min-width: 6.5rem;
  }

  .side-area {
    display: none;
  }

  .panel {
    display: none;
  }

  .mobile-stats {
    display: flex;
    justify-content: space-between;
    width: min(100%, 520px);
    border: 1px solid #2e3557;
    border-radius: 8px;
    background: rgba(22, 29, 56, 0.92);
    padding: 8px 10px;
    font-size: 14px;
  }

  .mobile-info-toggle {
    display: block;
    width: min(100%, 520px);
    margin-top: 0;
    background: #2f3b64;
    padding: 4px 12px 7px;
    font-size: 18px;
    line-height: 1;
  }

  .mobile-info-panel {
    width: min(100%, 520px);
    border: 1px solid #2e3557;
    border-radius: 8px;
    background: rgba(22, 29, 56, 0.92);
    padding: 10px;
  }

  .mobile-info-panel.hidden {
    display: none;
  }

  .mobile-info-panel:not(.hidden) {
    display: block;
  }

  .mobile-app-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    color: #7f8bb7;
    font-size: 12px;
  }

}
