* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  background: #1a1a1a;
  color: #eee;
  font-family: 'Segoe UI', Arial, sans-serif;
  padding: 6px;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
h1 {
  text-align: center;
  font-size: clamp(14px, 2.2vh, 30px);
  margin: 4px 0 6px;
  flex-shrink: 0;
}

.screen {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#gameScreen.screen {
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
#gameScreen.screen > h1 {
  flex: 0 0 auto;
}

.menu, .menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}
.menu { flex-direction: column; align-items: center; }
.menu.form { align-items: stretch; max-width: 420px; margin: 20px auto; }
.menu.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #ccc; }

.menu-btn {
  padding: 14px 24px;
  font-size: 16px;
  cursor: pointer;
  background: #2a2a2a;
  border: 2px solid #444;
  border-radius: 10px;
  color: #eee;
  min-width: 220px;
}
.menu-btn:hover:not(:disabled) { background: #3a3a3a; border-color: #66ff99; }
.menu-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.back-btn { border-color: #666; color: #aaa; }

.conn-status { text-align: center; margin-top: 10px; font-size: 13px; color: #888; }

.auth-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 4px;
  font-size: 14px;
}
.auth-user { color: #66ff99; font-weight: bold; }
.auth-link {
  background: transparent;
  border: 1px solid #555;
  color: #ccc;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.auth-link:hover { border-color: #66ff99; color: #66ff99; }
.auth-form { max-width: 360px; margin: 20px auto; }
.auth-form input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #111;
  color: #eee;
  font-size: 15px;
}
.auth-error {
  color: #ff6666;
  min-height: 20px;
  text-align: center;
  font-size: 14px;
}

.code-input {
  padding: 12px; font-size: 22px; text-align: center; letter-spacing: 6px;
  border-radius: 8px; border: 2px solid #444; background: #111; color: #66ff99;
}

select, input[type=text], input[type=password] {
  padding: 8px; border-radius: 6px; border: 1px solid #444; background: #222; color: #eee;
}

.lobby-list { display: flex; flex-direction: column; gap: 10px; margin-top: 15px; }
.empty-note { text-align: center; color: #777; padding: 20px; }
.lobby-item {
  background: #242424; border: 1px solid #3a3a3a; border-radius: 10px; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.lobby-item .badge-private { background: #661111; color: #ff8888; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.lobby-item .lobby-info { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.lobby-item .slots-preview { font-size: 13px; color: #aaa; }

.slot-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; background: #222; border-radius: 8px; margin-bottom: 6px;
}
.lobby-slots { margin-top: 15px; }
.lobby-slots .kick-btn { background: #661111; border: none; color: #ff8888; padding: 4px 10px; border-radius: 6px; cursor: pointer; }

.lobby-code {
  text-align: center; font-size: 36px; letter-spacing: 8px; color: #66ff99;
  background: #111; border-radius: 10px; padding: 10px; margin: 15px 0;
}

.lobby-settings {
  background: #1a1a22;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 12px 0;
}
.lobby-settings-title { font-weight: bold; margin-bottom: 8px; color: #9cf; }
.lobby-setting-row {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  color: #ccc;
}
.lobby-setting-row select,
.lobby-setting-row input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 4px;
}
.lobby-settings-hint { font-size: 12px; color: #888; margin-top: 4px; }

.chat-box { margin-top: 15px; background: #202020; border-radius: 8px; padding: 8px; }
.chat-box.small { max-height: 220px; }
.chat-messages { max-height: 180px; overflow-y: auto; font-size: clamp(12px, 1.05vw, 16px); padding: 4px; }
.chat-messages .chat-line { margin-bottom: 4px; word-break: break-word; }
.chat-messages .chat-name { color: #66ccff; font-weight: bold; }
.chat-input-row { display: flex; gap: 6px; margin-top: 6px; }
.chat-input-row input { flex: 1; }
.chat-input-row button { background: #333; border: 1px solid #555; color: #eee; border-radius: 6px; padding: 6px 12px; cursor: pointer; }

/* Игровой чат справа */
.game-chat-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; flex-shrink: 0;
}
.chat-tab {
  position: relative;
  padding: 5px 8px;
  font-size: clamp(11px, 0.95vw, 15px);
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #ccc;
  cursor: pointer;
  white-space: nowrap;
}
.chat-tab:hover { background: #333; border-color: #666; }
.chat-tab.active { background: #1a3a2a; border-color: #66ff99; color: #66ff99; }
.chat-tab .unread-dot {
  position: absolute;
  top: -3px; right: -3px;
  width: 10px; height: 10px;
  background: #ff4444;
  border-radius: 50%;
  border: 2px solid #1a1a1a;
  display: none;
}
.chat-tab.has-unread .unread-dot { display: block; }
.game-chat-box {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.game-chat-box .chat-messages {
  flex: 1;
  max-height: none;
  min-height: 60px;
  overflow-y: auto;
}
.side-panel-right { min-width: 0; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr) minmax(160px, 260px);
  gap: 10px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
  width: 100%;
  max-width: none;
  margin: 0 auto;
}
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}
.hand { background: #202020; border-radius: 10px; padding: 10px; flex-shrink: 0; }
.hand-title { font-weight: bold; margin-bottom: 6px; font-size: clamp(13px, 1.15vw, 18px); }
.hand-tabs { margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.hand-tabs .chat-tab,
.hand-tabs .hand-tab { font-size: 13px; padding: 5px 10px; min-width: 2.2em; }
.hand-tabs .hand-tab.elim { opacity: 0.55; }
.hand-view-note { font-size: 12px; color: #888; margin-bottom: 6px; }
.piece-btn {
  display: block; width: 100%; margin-bottom: 4px; padding: 6px 8px;
  background: #333; border: 1px solid #555; border-radius: 8px; color: #eee; cursor: pointer; text-align: left;
  font-size: clamp(12px, 1.05vw, 17px);
}
.piece-btn:hover { background: #444; }
.piece-btn.selected-deploy {
  background: #2a4a6a;
  border-color: #6ab0ff;
  box-shadow: 0 0 0 2px rgba(106, 176, 255, 0.55);
  color: #fff;
}
.piece-btn.hand-view-only { cursor: default; opacity: 0.9; }
.piece-btn.hand-view-only:hover { background: #333; }
.piece-btn.hand-locked { opacity: 0.35; cursor: not-allowed; }
.piece-btn.hand-locked:hover { background: #333; }
.cancel-btn { width: 100%; padding: 8px; background: #552222; border: 1px solid #773333; border-radius: 8px; color: #ffaaaa; cursor: pointer; margin-top: 4px; }
.captured-info { font-size: 12px; color: #999; margin-top: 6px; }

.board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.board-with-coords {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  grid-template-rows: 16px minmax(0, 1fr) 16px;
  width: min(100%, calc(100vh - 80px), calc(100dvh - 80px));
  height: min(100%, calc(100vh - 80px), calc(100dvh - 80px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  min-height: 0;
  min-width: 0;
  box-sizing: border-box;
}
.coord-corner { /* spacer */ }
.coord-files {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  font-size: clamp(10px, 1.1vw, 16px);
  color: #aaa;
  text-align: center;
  align-items: center;
  user-select: none;
}
.coord-ranks {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  font-size: clamp(10px, 1.1vw, 16px);
  color: #aaa;
  text-align: center;
  align-items: center;
  justify-items: center;
  user-select: none;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 3px solid #555;
  container-type: size;
  container-name: chessboard;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* размер фигуры от клетки доски, не от окна */
  font-size: clamp(16px, 11cqmin, 88px);
}

/* Зоны 1v1 — синяя территория (Игрок 1, верх) и красная (Игрок 2, низ) */
.zone-top { background: #34567a; }
.zone-bottom { background: #7a3434; }
/* Зоны 4p — зелёный/красный/синий/жёлтый игроки */
.zone1 { background: #2f6b45; } /* зелёный игрок */
.zone2 { background: #6b2f2f; } /* красный игрок */
.zone3 { background: #2f4a6b; } /* синий игрок */
.zone4 { background: #6b632f; } /* жёлтый игрок */
.diagonal { outline: 2px dashed rgba(255,255,255,0.4); outline-offset: -2px; }

/* Шахматный узор внутри цветных территорий — иначе доска выглядит сплошным пятном */
.sq-light { filter: brightness(1.28); }
.sq-dark { filter: brightness(0.78); }

.piece { user-select: none; z-index: 2; font-size: 1em; line-height: 1; }
/* Цвета фигур в режиме 1 на 1: синие для верхней территории, красные для нижней */
.piece-1v1-0 { color: #6ec3ff; text-shadow: 0 0 3px #000, 0 0 1px #000; }
.piece-1v1-1 { color: #ff6a6a; text-shadow: 0 0 3px #000, 0 0 1px #000; }
/* Цвета фигур в режиме 4 игрока: зелёный/красный/синий/жёлтый */
.piece-4p-0 { color: #6cea6c; text-shadow: 0 0 3px #000, 0 0 1px #000; }
.piece-4p-1 { color: #ff6a6a; text-shadow: 0 0 3px #000, 0 0 1px #000; }
.piece-4p-2 { color: #6ec3ff; text-shadow: 0 0 3px #000, 0 0 1px #000; }
.piece-4p-3 { color: #f5ea6c; text-shadow: 0 0 3px #000, 0 0 1px #000; }

/* Треугольные стрелки направления пешки (режим 4p) — масштаб от клетки */
.pawn-arrow {
  position: absolute;
  width: 0; height: 0;
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 0 1.5px #000);
  --aw: clamp(3px, 1.3cqmin, 8px);
  --ah: clamp(4px, 1.8cqmin, 11px);
}
.pawn-arrow.dir-U {
  top: 2px; left: 50%; transform: translateX(-50%);
  border-left: var(--aw) solid transparent;
  border-right: var(--aw) solid transparent;
  border-bottom: var(--ah) solid #fff;
}
.pawn-arrow.dir-D {
  bottom: 2px; left: 50%; transform: translateX(-50%);
  border-left: var(--aw) solid transparent;
  border-right: var(--aw) solid transparent;
  border-top: var(--ah) solid #fff;
}
.pawn-arrow.dir-L {
  left: 2px; top: 50%; transform: translateY(-50%);
  border-top: var(--aw) solid transparent;
  border-bottom: var(--aw) solid transparent;
  border-right: var(--ah) solid #fff;
}
.pawn-arrow.dir-R {
  right: 2px; top: 50%; transform: translateY(-50%);
  border-top: var(--aw) solid transparent;
  border-bottom: var(--aw) solid transparent;
  border-left: var(--ah) solid #fff;
}
.selected { outline: 3px solid #ffcc00; outline-offset: -3px; }
.hint::after { content:''; position:absolute; width:24%; height:24%; border-radius:50%; background: rgba(80,220,120,0.6); }
.hint-capture::after { content:''; position:absolute; width:80%; height:80%; border-radius:50%; border: 4px solid rgba(220,60,60,0.7); }
.hint-deploy { outline: 2px solid #4499ff; outline-offset: -2px; }
.hint-deploy-light { outline: 2px solid #ffffff; outline-offset: -2px; }
.hint-deploy-dark { outline: 2px solid #333333; outline-offset: -2px; }
.check-highlight { outline: 3px solid #ff3333; outline-offset: -3px; }
.last-move-from { box-shadow: inset 0 0 0 3px rgba(255,165,0,0.6); }
.last-move-to { box-shadow: inset 0 0 0 3px rgba(80,220,120,0.7); }
.last-deploy-to { box-shadow: inset 0 0 0 3px rgba(80,180,255,0.7); }
.promoting { outline: 3px solid #66ff41; }

#status { font-weight: bold; padding: 6px; background: #222; border-radius: 8px; text-align:center; font-size: clamp(13px, 1.15vw, 18px); flex-shrink: 0; }
#message { min-height: 18px; padding: 4px; text-align:center; font-size: clamp(12px, 1.1vw, 17px); flex-shrink: 0; }
.diplomacy-panel { background: #202020; border-radius: 8px; padding: 8px; font-size: clamp(12px, 1.05vw, 16px); line-height: 1.5; flex-shrink: 0; }
.game-controls { flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; }
.game-controls button {
  width: 100%; padding: 8px; background: #333; border: 1px solid #555; border-radius: 8px; color: #eee; cursor: pointer;
}
.game-controls .spectate-btn {
  background: #1a3a4a;
  border-color: #4a9ccc;
  color: #bdf;
  font-weight: bold;
}
.game-controls .spectate-btn:hover { border-color: #6cf; background: #245060; }
.spectator-badge {
  text-align: center;
  padding: 6px 8px;
  background: #1a2a3a;
  border: 1px solid #3a6a8a;
  border-radius: 8px;
  color: #9cf;
  font-size: 13px;
}
.board-frozen-mate {
  outline: 2px solid rgba(255, 120, 80, 0.55);
  outline-offset: 2px;
}
.timer-display { text-align:center; font-size: clamp(18px, 1.6vw, 28px); font-weight:bold; color:#ffcc00; flex-shrink: 0; }

/* Планшет / узкий экран */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; max-height: none; }
  #gameScreen.screen { height: auto; max-height: none; overflow: visible; }
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    overflow: visible;
  }
  .board-container {
    width: 100%;
    height: min(92vw, 70vh, 70dvh);
    min-height: min(92vw, 70vh, 70dvh);
  }
  .side-panel { overflow-y: visible; max-height: none; height: auto; }
  /* На мобильных: дипломатия над рукой */
  .side-panel > .diplomacy-panel { order: -1; }
  .game-chat-box { min-height: 140px; max-height: 220px; }
}

/* Очень узкий телефон */
@media (max-width: 480px) {
  body { padding: 4px; }
  h1 { font-size: 14px; margin: 2px 0; }
  .chat-tab { font-size: 10px; padding: 4px 6px; }
  .piece-btn { font-size: 12px; padding: 5px 6px; }
}

/* Широкий экран */
@media (min-width: 1200px) {
  .game-layout {
    grid-template-columns: minmax(180px, 260px) minmax(0, 1fr) minmax(200px, 300px);
    gap: 14px;
  }
  h1 { font-size: clamp(16px, 2.2vh, 28px); }
}

/* Full HD+ / большие мониторы */
@media (min-width: 1600px) {
  body { font-size: 16px; }
  .game-layout {
    grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) minmax(240px, 340px);
    gap: 16px;
  }
  h1 { font-size: clamp(18px, 2.4vh, 32px); }
  .menu-btn { font-size: 17px; padding: 16px 28px; min-width: 240px; }
  .auth-bar { font-size: 15px; }
  .auth-link { font-size: 14px; padding: 5px 14px; }
  .hand { padding: 12px; }
  .hand-title { font-size: 16px; }
  .piece-btn { font-size: 15px; padding: 8px 10px; }
  #status { font-size: 16px; padding: 8px; }
  #message { font-size: 15px; }
  .diplomacy-panel { font-size: 14px; padding: 10px; }
  .timer-display { font-size: 26px; }
  .chat-tab { font-size: 13px; padding: 6px 10px; }
  .chat-messages { font-size: 14px; }
  .captured-info { font-size: 13px; }
  .leaderboard-panel { max-width: none; }
  .leader-row { font-size: 1rem; }
}

/* 2K / 2560×1440 и выше */
@media (min-width: 2200px) {
  body { font-size: 18px; padding: 10px; }
  .game-layout {
    grid-template-columns: minmax(260px, 360px) minmax(0, 1fr) minmax(280px, 400px);
    gap: 18px;
  }
  h1 { font-size: clamp(20px, 2.6vh, 36px); margin: 6px 0 10px; }
  .menu-btn { font-size: 18px; padding: 18px 32px; min-width: 260px; }
  .auth-bar { font-size: 16px; gap: 16px; }
  .auth-link { font-size: 15px; padding: 6px 16px; }
  .hand { padding: 14px; }
  .hand-title { font-size: 18px; }
  .piece-btn { font-size: 16px; padding: 10px 12px; }
  #status { font-size: 18px; padding: 10px; }
  #message { font-size: 16px; min-height: 22px; }
  .diplomacy-panel { font-size: 15px; padding: 12px; }
  .timer-display { font-size: 30px; }
  .chat-tab { font-size: 14px; padding: 7px 12px; }
  .chat-messages { font-size: 15px; max-height: 240px; }
  .game-chat-box .chat-messages { max-height: none; }
  .captured-info { font-size: 14px; }
  .coord-files, .coord-ranks { font-size: clamp(12px, 1.1vw, 18px); }
  .leaderboard-panel { max-width: none; padding: 1rem 1.2rem; }
  .leaderboard-title { font-size: 1.25rem; }
  .leader-row { font-size: 1.05rem; }
}


/* ----- Рейтинг ----- */
.leaderboard-panel {
  margin: 0;
  max-width: none;
  width: 100%;
  text-align: left;
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  border: 1px solid #333;
  box-sizing: border-box;
}
.leaderboard-title { margin: 0 0 0.3rem; font-size: 1.1rem; }
.leaderboard-hint { margin: 0 0 0.6rem; font-size: 0.8rem; color: #aaa; }
.leaderboard-list { max-height: min(40vh, 320px); overflow-y: auto; }
.leader-row {
  display: flex; gap: 0.5rem; align-items: baseline;
  padding: 0.25rem 0; border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.9rem;
}
.leader-place { color: #ffcc00; min-width: 1.6em; }
.leader-name { flex: 1; }
.leader-rating { color: #66ff99; font-weight: 600; }
.leader-stats { color: #888; font-size: 0.8rem; }
.slot-rating { color: #66ff99; font-size: 0.85em; margin-left: 0.3em; }
.guest-badge { color: #ffaa66; font-size: 0.75em; margin-left: 0.3em; }


/* Онлайн-меню: мировой чат и счётчик */
.online-presence {
  text-align: center;
  font-size: clamp(14px, 1.2vw, 18px);
  color: #8f8;
  margin: 0 0 10px;
}
.ranked-panel {
  background: #1a2230;
  border: 1px solid #3a5a7a;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 12px;
  text-align: center;
}
.ranked-title { font-weight: bold; font-size: clamp(15px, 1.3vw, 18px); color: #9cf; margin-bottom: 4px; }
.ranked-hint { font-size: 12px; color: #889; margin: 0 0 10px; }
.ranked-btns { justify-content: center; flex-wrap: wrap; }
.ranked-btn { min-width: 160px; background: #243a55; border-color: #4a7aaa; }
.ranked-btn:hover { border-color: #6cf; }
.matchmaking-status {
  margin-top: 10px;
  padding: 8px 12px;
  background: #111;
  border-radius: 8px;
  color: #ffc;
  font-size: 14px;
}
.matchmaking-status .mm-cancel {
  margin-top: 8px;
  display: inline-block;
  padding: 6px 14px;
  background: #552222;
  border: 1px solid #a44;
  border-radius: 6px;
  color: #fcc;
  cursor: pointer;
}
/* Онлайн-меню: лобби → рейтинг → чат, на всю ширину */
.online-menu-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  box-sizing: border-box;
}
.online-block {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.online-block-title {
  margin: 0 0 8px;
  font-size: clamp(14px, 1.2vw, 18px);
}
.online-block-lobbies {
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 12px;
}
.online-block-lobbies .lobby-list {
  margin-top: 0;
  max-height: min(36vh, 280px);
  overflow-y: auto;
}
.online-block-lobbies .menu-row {
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: flex-start;
}
.world-chat-panel {
  display: flex;
  flex-direction: column;
  background: #202020;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 12px;
  min-height: 200px;
  max-height: min(42vh, 360px);
  width: 100%;
  box-sizing: border-box;
}
.world-chat-title {
  margin: 0 0 8px;
  font-size: clamp(14px, 1.2vw, 18px);
}
.world-chat-messages {
  flex: 1;
  min-height: 100px;
  max-height: none;
  overflow-y: auto;
  margin-bottom: 8px;
  background: #181818;
  border-radius: 8px;
  padding: 8px;
}
.world-chat-messages .chat-line { font-size: clamp(12px, 1.05vw, 15px); }

/* убрать старые ограничения ширины рейтинга на широких экранах */
@media (min-width: 1200px) {
  .leaderboard-panel { max-width: none; }
}
@media (min-width: 1600px) {
  .leaderboard-panel { max-width: none; }
}

/* Плавное исчезновение фигур при поражении */
.piece-fading {
  animation: pieceFadeOut 0.75s ease-out forwards;
  pointer-events: none;
  z-index: 4;
}
@keyframes pieceFadeOut {
  0%   { opacity: 1; transform: scale(1); filter: brightness(1); }
  40%  { opacity: 0.85; transform: scale(1.05); filter: brightness(1.3); }
  100% { opacity: 0; transform: scale(0.55); filter: brightness(0.6); }
}


/* ===== Обучение ===== */
#tutorialScreen.screen {
  overflow: auto;
  max-height: 100%;
}
.tutorial-layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.1fr);
  gap: 16px;
  flex: 1;
  min-height: 0;
  align-items: start;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 0 8px 16px;
}
.tutorial-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tutorial-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(100%, 42vh, 420px);
  aspect-ratio: 1;
  border: 3px solid #555;
  border-radius: 6px;
  overflow: hidden;
}
.tutorial-board .tsq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 3.5vh, 28px);
}
/* Стрелки пешек в обучении — компактнее, чем в партии */
.tutorial-board .pawn-arrow {
  --aw: 3px;
  --ah: 4px;
}
.tutorial-board .pawn-arrow.dir-U,
.tutorial-board .pawn-arrow.dir-D {
  border-left-width: var(--aw);
  border-right-width: var(--aw);
}
.tutorial-board .pawn-arrow.dir-U { border-bottom-width: var(--ah); top: 2px; }
.tutorial-board .pawn-arrow.dir-D { border-top-width: var(--ah); bottom: 2px; }
.tutorial-board .pawn-arrow.dir-L,
.tutorial-board .pawn-arrow.dir-R {
  border-top-width: var(--aw);
  border-bottom-width: var(--aw);
}
.tutorial-board .pawn-arrow.dir-L { border-right-width: var(--ah); left: 2px; }
.tutorial-board .pawn-arrow.dir-R { border-left-width: var(--ah); right: 2px; }

.tutorial-board .tsq.hl {
  outline: 2px solid #ffcc00;
  outline-offset: -2px;
  z-index: 2;
}
.tutorial-board .tsq.hl-soft {
  box-shadow: inset 0 0 0 3px rgba(100, 200, 255, 0.55);
}
.tutorial-board .tsq.hl-path {
  box-shadow: inset 0 0 0 3px rgba(80, 220, 120, 0.55);
}
.tutorial-board-caption {
  font-size: clamp(12px, 1.1vw, 15px);
  color: #aaa;
  text-align: center;
  min-height: 1.2em;
}
.tutorial-text-panel {
  background: #202020;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.tutorial-progress {
  font-size: 13px;
  color: #888;
}
.tutorial-slide-title {
  margin: 0;
  font-size: clamp(16px, 1.6vw, 22px);
  color: #66ff99;
}
.tutorial-slide-body {
  font-size: clamp(13px, 1.15vw, 16px);
  line-height: 1.55;
  color: #ddd;
  flex: 1;
}
.tutorial-slide-body ul {
  margin: 8px 0;
  padding-left: 1.2em;
}
.tutorial-slide-body li { margin-bottom: 6px; }
.tutorial-slide-body strong { color: #ffcc00; }
.tutorial-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.tutorial-nav .menu-btn {
  min-width: 0;
  padding: 10px 16px;
  font-size: 14px;
}
@media (max-width: 800px) {
  .tutorial-layout {
    grid-template-columns: 1fr;
  }
  .tutorial-board {
    width: min(92vw, 360px);
  }
}

.tutorial-demo {
  width: min(100%, 42vh, 420px);
  min-height: min(100%, 42vh, 280px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tutorial-demo .tutorial-board {
  width: 100%;
}
.tutorial-ui-card {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;
  font-size: clamp(12px, 1.1vw, 15px);
  color: #ddd;
}
.tutorial-ui-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: #66ff99;
}
.tutorial-hand-list .piece-btn {
  pointer-events: none;
  opacity: 0.95;
}
.tutorial-hand-list .piece-btn.locked {
  opacity: 0.35;
  border-style: dashed;
}
.tutorial-chat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.tutorial-chat-tabs span {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #2a2a2a;
  font-size: 12px;
}
.tutorial-chat-tabs span.active {
  border-color: #66ff99;
  color: #66ff99;
  background: #1a3a2a;
}
.tutorial-chat-tabs span .dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: #ff4444;
  border-radius: 50%;
  margin-left: 4px;
}
.tutorial-status-demo {
  text-align: center;
  padding: 10px;
  background: #222;
  border-radius: 8px;
  font-weight: bold;
  margin-bottom: 8px;
}
.tutorial-dip-row { margin-bottom: 6px; line-height: 1.45; }

.tutorial-dip-panel .tutorial-dip-row {
  background: #181818;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.45;
}
.tutorial-ui-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: #999;
}
.tutorial-chat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.tutorial-chat-tabs span {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #ccc;
  position: relative;
}
.tutorial-chat-tabs span.active {
  border-color: #66ff99;
  color: #66ff99;
  background: #1a3a2a;
}
.tutorial-chat-tabs .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #ff4444;
  border-radius: 50%;
  margin-left: 4px;
  vertical-align: middle;
}
.piece-btn.locked {
  opacity: 0.45;
  cursor: default;
}

.sound-toggle-row { text-align: center; margin-top: 10px; }
.sound-toggle { font-size: 14px; color: #bbb; cursor: pointer; user-select: none; }
.history-hint { text-align: center; color: #888; font-size: 13px; margin: 0 0 12px; }
.history-list {
  max-width: 560px;
  margin: 0 auto 16px;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 8px 12px;
}
.history-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: clamp(12px, 1.05vw, 15px);
}
.history-row:last-child { border-bottom: none; }
.history-result-win { color: #66ff99; font-weight: 600; }
.history-result-loss { color: #ff8888; font-weight: 600; }
.history-result-draw { color: #ffcc00; font-weight: 600; }
.history-meta { color: #aaa; font-size: 0.9em; }
.history-delta-pos { color: #66ff99; }
.history-delta-neg { color: #ff8888; }
