:root {
  --bg: #fff;
  --panel: #fff;
  --text: #111;
  --muted: #6b6b6b;
  --dark-square: #e2e2e2;
  --light-square: #fff;
  --highlight: #111;
  --selected: #111;
  --accent: #111;
  --accent-soft: #ececec;
  --border: #111;
  --danger: #111;
  --piece-white: #fff;
  --piece-black: #111;
  --stroke: #111;
  --stroke-soft: #cfcfcf;
}

body[data-theme="dark"] {
  --bg: #111;
  --panel: #111;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --dark-square: #3c3c3c;
  --light-square: #111;
  --highlight: #f5f5f5;
  --selected: #f5f5f5;
  --accent: #f5f5f5;
  --accent-soft: #2c2c2c;
  --border: #f5f5f5;
  --danger: #f5f5f5;
  --piece-white: #f5f5f5;
  --piece-black: #111;
  --stroke: #f5f5f5;
  --stroke-soft: #4a4a4a;
  --turn-glow: 0 0 9px 1px var(--highlight);
}

/* «Дерево» — палитра по референсу: крем, тёплые коричневые */
body[data-theme="wood"] {
  --bg: #fef7ef;
  --panel: #fef7ef;
  --text: #3f2d1e;
  --muted: #8b6d53;
  --dark-square: #b98a60;
  --light-square: #fce2c3;
  --highlight: #7a4a26;
  --selected: #7a4a26;
  --accent: #7a4a26;
  --accent-soft: #f0dcc2;
  --border: #7a4a26;
  --danger: #a04326;
  --piece-white: #fdf3e3;
  --piece-black: #4a3222;
  --stroke: #7a4a26;
  --stroke-soft: #dcc3a4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app { width: 100%; max-width: 480px; padding: 16px; position: relative; }

h1 { font-size: 1.6rem; margin: 24px 0 8px; font-weight: 800; }
.sub { color: var(--muted); margin-bottom: 24px; }

body[data-in-telegram] #home-title,
body[data-in-telegram] #home-sub { display: none; }
/* без заголовка кнопка упирается в скины — отступаем от них с запасом */
body[data-in-telegram] #home:not([hidden]) { padding-top: 52px; }

#side-pick { display: flex; gap: 8px; margin-bottom: 12px; }
/* позвали по имени — под кнопками сторон уже ничего нет */
#invite-box.named #side-pick { margin-bottom: 0; }
#side-pick button {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}
#side-pick button.selected {
  background: var(--accent);
  border-color: var(--stroke);
  color: var(--bg);
}

#rival-box { margin-top: 14px; }
.pick-label { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
#rival-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.rival-option {
  padding: 10px 14px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}
.rival-option .rival-score {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

button.primary {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--stroke);
  border-radius: 12px;
  background: var(--accent);
  color: var(--bg);
  font-size: 1.05rem;
  font-weight: 700;
}
button:active { opacity: 0.85; }

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  color: var(--muted);
}
.player-bar.turn .who { color: var(--text); font-weight: 700; }
.player-bar.turn .who::after { content: attr(data-turn-suffix); color: var(--text); }
.pieces { letter-spacing: 2px; font-size: 0.9rem; }
.player-bar .score {
  margin-left: 8px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
}
.player-bar .score:empty { display: none; }
.player-bar .who, .player-bar .score { white-space: nowrap; flex-shrink: 0; }
.player-bar .seen {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-bar .seen {
  margin: 0 auto 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border: 2px solid var(--stroke);
  border-radius: 12px;
  overflow: hidden;
  touch-action: manipulation;
}
.cell { position: relative; }
.cell.dark { background: var(--dark-square); }
.cell.light { background: var(--light-square); }
.cell.target::after {
  content: "";
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: var(--highlight);
  opacity: 0.55;
}
.cell.target.far::after { opacity: 0.25; }
.cell.selected { outline: 3px solid var(--selected); outline-offset: -3px; }
.cell.last { box-shadow: inset 0 0 0 1px var(--stroke-soft); }
@supports (color: color-mix(in srgb, red 50%, transparent)) {
  .cell.last {
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--muted) 28%, transparent);
  }
}
.cell.movable { outline: 2px solid var(--highlight); outline-offset: -2px; }

.piece {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.2vw;
}
@media (min-width: 480px) { .piece { font-size: 20px; } }
.piece.w { background: var(--piece-white); border: 2px solid var(--stroke); }
.piece.b { background: var(--piece-black); border: 2px solid var(--stroke); }
.piece.king::after { content: "♛"; }
.piece.w.king::after { color: var(--piece-black); }
.piece.b.king::after { color: var(--piece-white); }
.piece.captured { opacity: 0.35; }
.piece.glow { box-shadow: var(--turn-glow, none); }

#status-line { margin: 14px 4px; color: var(--muted); }

/* перемотка партии (#154): ‹ «ход K из N» › под доской */
#board-wrap { position: relative; }
#board { transition: filter 0.2s ease; }
#replay:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 2px;
}
#replay button {
  flex: 0 0 52px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}
#replay button:disabled { opacity: 0.4; }
#replay-label {
  flex: 1;
  text-align: center;
  font-size: 15px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
#replay-label b { font-weight: 700; }
/* живая партия: только ‹, подпись и › невидимы, но держат высоту строки */
#replay.mini #replay-label,
#replay.mini #replay-next { visibility: hidden; }

#review-tag { display: none; }
/* плашка лежит на верхней кромке доски — доска не сдвигается */
.reviewing #review-tag {
  display: block;
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.3px;
  white-space: nowrap;
  pointer-events: none;
}
.reviewing #board { filter: saturate(0.55) brightness(0.92); }
.reviewing #action-bar,
.reviewing #btn-nudge,
.reviewing #offer-box { display: none !important; }

#invite-box {
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  padding: 14px;
  margin-top: 8px;
}
#invite-box p { color: var(--muted); font-size: 0.9rem; margin-bottom: 10px; }
.invite-row:not([hidden]) { display: flex; gap: 8px; }
#invite-link {
  flex: 1;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
#copy-invite {
  padding: 10px 14px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

#lobby { margin-top: 28px; }
#lobby h2 { font-size: 1.1rem; margin-bottom: 10px; font-weight: 800; }
#game-list { list-style: none; }
.game-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.row-delete {
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--stroke-soft);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1;
}
.game-row.cat-0 .row-badge { color: var(--text); font-weight: 700; }
.game-row.cat-3 { opacity: 0.5; border-color: var(--muted); }
.row-opponent { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-score { color: var(--text); font-size: 0.85rem; font-weight: 700; }
.row-badge { color: var(--muted); font-size: 0.85rem; }
.row-time { color: var(--muted); font-size: 0.85rem; }

.error { color: var(--danger); margin-top: 12px; font-weight: 700; }

#action-bar:not([hidden]) {
  display: flex;
  gap: 6px;
  margin-top: 14px;
}
#action-bar button {
  /* равные трети, а кегль подбираем так, чтобы «Вернуть ход» влезал в строку */
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  padding: 10px 4px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: clamp(0.7rem, 3.2vw, 0.85rem);
}
#action-bar button:disabled { opacity: 0.35; }

/* глифы системный шрифт рисует мельче букв — поднимаем до веса надписи */
#action-bar button[data-icon]::before,
#btn-nudge::before {
  content: attr(data-icon);
  margin-right: 6px;
  font-size: 1.3em;
  line-height: 0;
  vertical-align: -0.09em;
}
/* руку тот же шрифт рисует мельче остальных — догоняем отдельно */
#btn-nudge::before { font-size: 1.85em; vertical-align: 0.02em; }
/* глиф ↺ система рисует крохотным в любом кегле — стрелку рисуем сами */
#btn-takeback { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#offer-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
}
#offer-box p { margin-bottom: 10px; }
.offer-row { display: flex; gap: 8px; }
.offer-row button {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.offer-row button.primary {
  background: var(--accent);
  border-color: var(--stroke);
  color: var(--bg);
}

#finish-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}
#finish-overlay:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}
#confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#finish-card {
  width: min(320px, 84vw);
  padding: 24px 20px;
  border: 1px solid var(--stroke-soft);
  border-radius: 16px;
  background: var(--panel);
  text-align: center;
}
#finish-card p {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 18px;
}
#finish-card button { margin-top: 8px; }
#finish-card #finish-score {
  margin: -10px 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
#finish-lobby {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.95rem;
}

#lang-toggle {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 6px 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
}

#tg-invite { width: 100%; margin-top: 10px; }

#btn-rematch { margin-top: 14px; }

#btn-nudge {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}
#btn-nudge:disabled { color: var(--muted); opacity: 0.6; }

/* чат партии: текст и голос одной лентой, прокручивается внутри панели */
#voice-panel:not([hidden]) {
  display: block;
  margin-top: 14px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
}
#voice-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
}
#voice-title { flex: 1; font-weight: 600; }
.voice-count:not([hidden]) {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}
#voice-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 10px;
  max-height: 45vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#voice-list:empty { display: none; }
.voice-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(78%, 300px);
  padding: 6px 10px 6px 6px;
  border: 1px solid transparent;
  border-radius: 16px;
}
.voice-msg.mine {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--accent-soft);
}
.voice-msg.theirs {
  align-self: flex-start;
  border-color: var(--stroke-soft);
  border-bottom-left-radius: 4px;
  background: var(--panel);
}
.voice-play {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.8rem;
}
.voice-body {
  flex: 1;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.voice-track {
  height: 4px;
  border-radius: 2px;
  background: var(--stroke-soft);
  overflow: hidden;
}
.voice-fill { width: 0; height: 100%; background: var(--accent); }
.voice-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.voice-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.voice-msg:not(.unheard) .voice-dot { display: none; }
/* корзина на своём пузыре: тихая, но с пальцевой зоной касания */
.voice-delete {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: -4px -6px -4px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.55;
}
.voice-delete:active { opacity: 1; background: var(--stroke-soft); }
@media (max-width: 380px) {
  .voice-msg { width: min(88%, 300px); }
  .voice-body { min-width: 96px; }
}
#voice-empty,
#voice-hint {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

/* текстовый пузырь: переносы строк сохраняем, длинные слова рубим */
.text-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: min(80%, 320px);
  padding: 6px 10px 4px;
  border: 1px solid transparent;
  border-radius: 16px;
  color: var(--text);
}
.text-msg.mine {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--accent-soft);
}
.text-msg.theirs {
  align-self: flex-start;
  border-color: var(--stroke-soft);
  border-bottom-left-radius: 4px;
  background: var(--panel);
}
.text-body {
  font-size: 0.93rem;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.text-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-height: 18px;
  color: var(--muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}
.text-msg .voice-dot { width: 7px; height: 7px; }
.text-msg:not(.unheard) .voice-dot { display: none; }
.text-msg .voice-delete {
  width: 24px;
  height: 24px;
  margin: -4px -6px -4px -2px;
  font-size: 0.8rem;
}

/* строка ввода: поле растёт до четырёх строк, справа микрофон или стрелка */
#composer:not([hidden]) {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--stroke-soft);
}
#composer-field { flex: 1; min-width: 0; }
#chat-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--stroke-soft);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* меньше — и iOS приближает страницу при фокусе */
  line-height: 20px;
  resize: none;
  overflow-y: hidden;
}
#chat-input::placeholder { color: var(--muted); }
#chat-input:focus { outline: none; border-color: var(--stroke); }
#chat-input[hidden], #talk-status[hidden] { display: none; }
#talk-status {
  padding: 10px 4px;
  color: #d93838;
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#btn-talk {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--stroke-soft);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#btn-talk svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#btn-talk.send {
  border-color: var(--stroke);
  background: var(--accent);
  color: var(--bg);
}
#btn-talk:disabled { opacity: 0.55; }
/* запись идёт: красная пульсирующая кнопка, тап — стоп */
#btn-talk.recording {
  background: #d93838;
  border-color: #d93838;
  color: #fff;
  animation: talk-pulse 1.2s ease-in-out infinite;
}
#btn-talk.recording svg { fill: currentColor; stroke: none; }
@keyframes talk-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 56, 56, 0.55); }
  50% { box-shadow: 0 0 0 7px rgba(217, 56, 56, 0); }
}
@media (prefers-reduced-motion: reduce) {
  #btn-talk.recording { animation: none; }
}

/* черновик записи: прослушать, затем отправить или удалить */
#voice-draft:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 8px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background: var(--panel);
}
#voice-draft .voice-msg { flex: 1 1 180px; width: auto; }
.draft-actions { display: flex; gap: 8px; margin-left: auto; }
.draft-actions button {
  padding: 9px 14px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
}
.draft-actions button.primary {
  background: var(--accent);
  border-color: var(--stroke);
  color: var(--bg);
  font-weight: 600;
}
.draft-actions button:disabled { opacity: 0.6; }

#back-link {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 6px 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

#game:not([hidden]) { padding-top: 34px; }

#theme-toggle {
  position: absolute;
  top: 10px;
  right: 62px;
  padding: 6px 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
}

#skin-menu {
  position: absolute;
  top: 44px;
  right: 62px;
}
#skin-menu:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--panel);
  z-index: 10;
}
#skin-menu button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
}
#skin-menu button.active {
  background: var(--accent);
  color: var(--bg);
}

/* ---------- шахматы (#158) ---------- */

/* выбор игры на главной — как выбор стороны */
#type-pick { display: flex; gap: 8px; margin-bottom: 12px; }
#type-pick button {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
#type-pick button.selected {
  background: var(--accent);
  border-color: var(--stroke);
  color: var(--bg);
  font-weight: 700;
}

#credits-line { margin-top: 28px; text-align: center; font-size: 0.75rem; }
#credits { color: var(--muted); text-decoration: none; }

/* значок игры в строке лобби */
.row-game {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.row-game svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}
.row-game .knight {
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: url(vendor/pieces/cburnett/bN.svg) center / contain no-repeat;
  mask: url(vendor/pieces/cburnett/bN.svg) center / contain no-repeat;
}

.cp-wK { background-image: url(vendor/pieces/cburnett/wK.svg); }
.cp-wQ { background-image: url(vendor/pieces/cburnett/wQ.svg); }
.cp-wR { background-image: url(vendor/pieces/cburnett/wR.svg); }
.cp-wB { background-image: url(vendor/pieces/cburnett/wB.svg); }
.cp-wN { background-image: url(vendor/pieces/cburnett/wN.svg); }
.cp-wP { background-image: url(vendor/pieces/cburnett/wP.svg); }
.cp-bK { background-image: url(vendor/pieces/cburnett/bK.svg); }
.cp-bQ { background-image: url(vendor/pieces/cburnett/bQ.svg); }
.cp-bR { background-image: url(vendor/pieces/cburnett/bR.svg); }
.cp-bB { background-image: url(vendor/pieces/cburnett/bB.svg); }
.cp-bN { background-image: url(vendor/pieces/cburnett/bN.svg); }
.cp-bP { background-image: url(vendor/pieces/cburnett/bP.svg); }

.piece.chess {
  inset: 3%;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  z-index: 1;
}

/* последний ход — тонированная клетка: в шахматах ходят издалека, рамки мало */
.cell.last-move { box-shadow: inset 0 0 0 100px rgba(155, 199, 0, 0.32); }
body[data-theme="wood"] .cell.last-move { box-shadow: inset 0 0 0 100px rgba(205, 210, 106, 0.5); }
body[data-theme="dark"] .cell.last-move { box-shadow: inset 0 0 0 100px rgba(170, 162, 58, 0.45); }
.cell.check {
  background-image: radial-gradient(
    ellipse at center,
    rgba(255, 0, 0, 1) 0%,
    rgba(231, 0, 0, 1) 25%,
    rgba(169, 0, 0, 0) 89%,
    rgba(158, 0, 0, 0) 100%
  );
}
#game.chess .cell.target::after { z-index: 2; inset: 37%; opacity: 0.4; }
#game.chess .cell.target.capture::after {
  inset: 2%;
  background: transparent;
  border: 4px solid var(--highlight);
  opacity: 0.4;
}

.coord {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  opacity: 0.75;
}
.coord.rank { top: 2px; left: 2px; }
.coord.file { bottom: 2px; right: 3px; }
.coord { color: var(--muted); }
body[data-theme="wood"] .cell.dark .coord { color: var(--light-square); }
body[data-theme="wood"] .cell.light .coord { color: var(--dark-square); }
body[data-theme="dark"] #game.chess .cell.dark .coord { color: #a9a9a9; }
body[data-theme="dark"] #game.chess .cell.light .coord { color: #5c5c5c; }

/* графитовая тема: на почти чёрных клетках чёрные фигуры пропадают —
   шахматам доска светлее, в тех же серых тонах */
body[data-theme="dark"] #game.chess .cell.dark { background: #5f5f5f; }
body[data-theme="dark"] #game.chess .cell.light { background: #9c9c9c; }

/* взятые фигуры и перевес в плашках игроков */
#game.chess .pieces { letter-spacing: 0; display: inline-flex; align-items: center; }
.cap {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: -2px;
  background-size: contain;
  background-repeat: no-repeat;
}
.cap-plus { margin-left: 9px; font-size: 0.85rem; color: var(--muted); }

/* превращение пешки: выбор фигуры поверх доски */
#promo:not([hidden]) {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
}
.promo-card {
  background: var(--panel);
  border: 2px solid var(--stroke);
  border-radius: 14px;
  padding: 12px 14px 14px;
  text-align: center;
}
.promo-card p { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.promo-row { display: flex; gap: 8px; }
.promo-piece {
  width: 62px;
  height: 62px;
  border: 1px solid var(--stroke-soft);
  border-radius: 12px;
  background-color: var(--dark-square);
  background-size: 82%;
  background-position: center;
  background-repeat: no-repeat;
}

.replay-san { font-weight: 700; }

/* сообщение соперника поверх экрана (#162): выезжает сверху, 2 с, гаснет */
#msg-toast {
  position: fixed;
  top: calc(
    max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) +
      var(--tg-content-safe-area-inset-top, 0px) + 10px
  );
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: max-content;
  min-width: 160px;
  max-width: min(360px, calc(100vw - 24px));
  padding: 9px 14px 10px;
  border: 1px solid var(--stroke-soft);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16), 0 1px 4px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transform: translate(-50%, -14px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 400ms ease, transform 400ms ease, visibility 0s linear 400ms;
}
#msg-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
  pointer-events: auto;
  transition: opacity 200ms ease-out, transform 200ms ease-out, visibility 0s;
}
#msg-toast .toast-from {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  text-overflow: ellipsis;
}
#msg-toast .toast-text {
  display: -webkit-box;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
@media (prefers-reduced-motion: reduce) {
  #msg-toast,
  #msg-toast.show { transform: translate(-50%, 0); }
}
