/* Мини-шахматы (app/mini_chess, страница views/mini_chess/game.ejs). Статический
   файл, а не импорт в бандл: css-loader пытается разрешить адреса /cg/... как
   модули. Доска — из chessround (mini-chess.css), фигуры — набор cburnett сайта
   (/cg/assets), цвета страницы — переменные темы сайта (common.css:
   --surface-1, --border, --text-1, --text-2), тёмная тема — html[data-theme="dark"]. */

.mc-page {
  --mc-primary: #0d6efd;
  --mc-primary-soft: rgba(13, 110, 253, 0.12);
  display: grid;
  justify-items: center;
  padding: 0.5rem 0 1rem;
  color: var(--text-1, #212529);
}
html[data-theme='dark'] .mc-page {
  --mc-primary: #60a5fa;
  --mc-primary-soft: rgba(96, 165, 250, 0.16);
}

.mc-card {
  width: 100%;
  max-width: 760px;
  padding: 1rem 1.25rem 1.25rem;
  background: var(--surface-1, #fff);
  border: 1px solid var(--border, #dee2e6);
  border-radius: 12px;
}
html[data-theme='dark'] .mc-card {
  background: var(--surface-2, #1e293b);
}
@media (max-width: 600px) {
  .mc-card {
    padding: 0.75rem;
  }
}

.mc-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 0 0.75rem;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.mc-crumbs li + li::before {
  content: '/';
  margin-right: 0.25rem;
  color: var(--text-2, #6c757d);
}
.mc-crumbs a {
  color: inherit;
}
.mc-crumbs li[aria-current] {
  font-weight: 800;
}

/* колонка — не шире контейнера: иначе длинный статус («Бот думает…») на узком
   экране расширял сетку, текст правил переливался, и доска прыгала */
.mc-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 640px;
  margin: 0 auto;
}
.mc-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.mc-title {
  margin: 0 0 0.15rem;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 800;
}
.mc-muted {
  color: var(--text-2, #6c757d);
  font-size: 0.9rem;
}
.mc-shrink {
  flex-shrink: 0;
}
.mc-grow {
  flex: 1 1 auto;
  min-width: 0;
}
.mc-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.6rem;
}
.mc-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.mc-wrap {
  flex-wrap: wrap;
}
/* Строка статуса — постоянной высоты и в одну строку: «Бот думает…» длиннее
   «Ваш ход», и на телефоне перенос на вторую строку сдвигал доску. */
.mc-status-row {
  height: 48px;
}
.mc-status,
.mc-result-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mc-status {
  font-size: 1.1rem;
  font-weight: 800;
}
@media (max-width: 420px) {
  .mc-status {
    font-size: 1rem;
  }
  .mc-action {
    padding: 4px;
  }
  .mc-action .mc-emoji {
    width: 26px;
    height: 26px;
  }
}
@media (max-width: 380px) {
  .mc-status {
    font-size: 0.92rem;
  }
  .mc-status-row {
    gap: 0.35rem;
  }
  .mc-actions {
    gap: 0;
  }
  .mc-action {
    padding: 3px;
  }
  .mc-action .mc-emoji {
    width: 24px;
    height: 24px;
  }
}
.mc-result {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.6rem;
}
.mc-result-text {
  min-width: 0;
}
.mc-result-title {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.2;
}
.mc-result-title.won {
  color: #15803d;
}
.mc-result-title.lost {
  color: #c2410c;
}
html[data-theme='dark'] .mc-result-title.won {
  color: #4ade80;
}
html[data-theme='dark'] .mc-result-title.lost {
  color: #fb923c;
}
.mc-emoji {
  display: block;
  flex-shrink: 0;
}

/* Итог партии — карточкой по центру доски. Появляется с задержкой: сначала
   виден последний ход (ответ бота и так приходит не раньше 0,45 с). */
.mc-board-wrap {
  position: relative;
}
.mc-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 8%;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.42);
  animation: mc-fade 0.3s ease 0.5s both;
}
.mc-overlay-card {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  width: 100%;
  max-width: 340px;
  padding: 1.1rem 1.25rem 0.9rem;
  border-radius: 16px;
  background: var(--surface-1, #fff);
  color: var(--text-1, #212529);
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  animation: mc-pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) 0.5s both;
}
html[data-theme='dark'] .mc-overlay-card {
  background: var(--surface-2, #1e293b);
}
.mc-overlay-icon {
  margin-bottom: 0.15rem;
}
.mc-overlay-title {
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}
.mc-overlay-title.won {
  color: #15803d;
}
.mc-overlay-title.lost {
  color: #c2410c;
}
html[data-theme='dark'] .mc-overlay-title.won {
  color: #4ade80;
}
html[data-theme='dark'] .mc-overlay-title.lost {
  color: #fb923c;
}
.mc-overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0.5rem;
  margin-top: 0.5rem;
}
@media (max-width: 420px) {
  .mc-overlay {
    padding: 4%;
  }
  .mc-overlay-card {
    padding: 0.8rem 0.9rem 0.6rem;
  }
  .mc-overlay-title {
    font-size: 1.2rem;
  }
}
@keyframes mc-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes mc-pop {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Значки действий: новая игра, отмена, переворот, поделиться. */
.mc-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.15rem;
}
.mc-action {
  display: grid;
  place-items: center;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.mc-action:hover:not(:disabled) {
  background: var(--mc-primary-soft);
}
.mc-action:disabled {
  opacity: 0.35;
  cursor: default;
}
.mc-action.highlight {
  background: var(--mc-primary-soft);
  box-shadow: 0 0 0 2px var(--mc-primary);
}

/* Строка настроек значками. */
.mc-settings {
  display: grid;
  grid-template-columns: repeat(var(--mc-settings-n, 5), minmax(0, 1fr));
  gap: 0.5rem;
}
@media (max-width: 600px) {
  .mc-settings {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.mc-setting {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.25rem;
  min-width: 0;
  padding: 0.4rem 0.25rem 0.5rem;
  border: 1px solid var(--border, #dee2e6);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.mc-setting:hover,
.mc-setting.open {
  border-color: var(--mc-primary);
  background: var(--mc-primary-soft);
}
.mc-setting-label {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-2, #6c757d);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mc-setting-icon {
  display: grid;
  place-items: center;
  height: 32px;
}
.mc-setting-value {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Меню вариантов под значком. */
.mc-pop {
  position: fixed;
  z-index: 1060;
  display: grid;
  gap: 0.5rem;
  width: 340px;
  max-width: calc(100vw - 24px);
  padding: 0.5rem;
  border: 1px solid var(--border, #dee2e6);
  border-radius: 12px;
  background: var(--surface-1, #fff);
  color: var(--text-1, #212529);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.mc-pop.tiles {
  width: auto;
}
html[data-theme='dark'] .mc-pop {
  background: var(--surface-2, #1e293b);
}
.mc-pop-title {
  padding: 0.25rem 0.5rem 0;
  font-size: 0.9rem;
  font-weight: 800;
}
.mc-pop-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.35rem;
}
.mc-pop-divider {
  height: 1px;
  background: var(--border, #dee2e6);
}
.mc-pop-note {
  padding: 0 0.5rem 0.25rem;
  color: var(--text-2, #6c757d);
  font-size: 0.8rem;
}
.mc-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.5rem;
  border: 2px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.mc-option.tile {
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem;
  text-align: center;
}
.mc-option:hover {
  background: var(--mc-primary-soft);
}
.mc-option.selected {
  border-color: var(--mc-primary);
  background: var(--mc-primary-soft);
}
.mc-option-icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
}
.mc-option-text {
  display: grid;
  min-width: 0;
}
.mc-option-title {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.25;
}
.mc-option-hint {
  color: var(--text-2, #6c757d);
  font-size: 0.85rem;
  line-height: 1.35;
}

/* Фигура-значок (цвет в настройках, первыми ходят). */
.mc-piece-icon {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

/* Редактор: «первыми ходят» — две кнопки. */
.mc-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border, #dee2e6);
  border-radius: 8px;
}
.mc-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
}
.mc-toggle button + button {
  border-left: 1px solid var(--border, #dee2e6);
}
.mc-toggle button.on {
  background: var(--mc-primary-soft);
  color: var(--mc-primary);
}

/* Подсказка внизу: ссылка скопирована / скопируйте вручную. */
.mc-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 1070;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  max-width: calc(100vw - 32px);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  background: #0b5394;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  word-break: break-all;
  transform: translateX(-50%);
}
.mc-toast.ok {
  background: #15803d;
}
.mc-toast .close {
  color: #fff;
  opacity: 0.8;
  text-shadow: none;
}

/* --- Доска N×N ------------------------------------------------------------ */

.mc-board,
.mc-size-icon {
  --mc-light: #f0d9b5;
  --mc-dark: #b58863;
  --mc-coord-light: #b58863;
  --mc-coord-dark: #f0d9b5;
}

.mc-board {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

/* Значок размера доски в настройках. */
.mc-size-icon {
  display: block;
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.mc-size-icon .l {
  fill: var(--mc-light);
}
.mc-size-icon .d {
  fill: var(--mc-dark);
}

.mc-square {
  position: relative;
  background: var(--mc-light);
}
.mc-square.dark {
  background: var(--mc-dark);
}
.mc-square.last::before,
.mc-square.selected::before,
.mc-square.check::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
}
.mc-square.last::before {
  background: rgba(155, 199, 0, 0.41);
}
.mc-square.selected::before {
  background: rgba(20, 85, 30, 0.5);
}
.mc-square.check::before {
  background: 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%);
}
.mc-square.editable {
  cursor: pointer;
}
.mc-square.editable:hover::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

.mc-dest {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  background: radial-gradient(rgba(20, 85, 30, 0.5) 19%, rgba(0, 0, 0, 0) 20%);
}
.mc-dest.capture {
  background: radial-gradient(transparent 0%, transparent 79%, rgba(20, 85, 0, 0.3) 80%);
}

.mc-piece {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
}
.mc-piece.dragging-origin {
  opacity: 0.3;
}

.mc-ghost {
  position: fixed;
  z-index: 1500;
  pointer-events: none;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transform: translate(-50%, -50%);
}

.mc-coord {
  position: absolute;
  font-size: clamp(9px, 1.6vw, 13px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  color: var(--mc-coord-light);
}
.mc-square.dark .mc-coord {
  color: var(--mc-coord-dark);
}
.mc-coord.rank {
  top: 3px;
  left: 3px;
}
.mc-coord.file {
  right: 3px;
  bottom: 3px;
}

/* Палитра редактора: 6 белых фигур, ластик, 6 чёрных. */
.mc-palette {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.mc-palette-item {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(127, 127, 127, 0.15);
  color: inherit;
  font-size: 1.4rem;
  cursor: pointer;
}
.mc-palette-item.active {
  border-color: var(--mc-primary);
  background: var(--mc-primary-soft);
}
.mc-palette-item .mc-piece {
  top: 8%;
  right: 8%;
  bottom: 8%;
  left: 8%;
}

/* Фигуры — набор cburnett сайта. */
.mc-piece.mc-wp { background-image: url('/cg/assets/images/pieces/cburnett/wP.svg'); }
.mc-piece.mc-wn { background-image: url('/cg/assets/images/pieces/cburnett/wN.svg'); }
.mc-piece.mc-wb { background-image: url('/cg/assets/images/pieces/cburnett/wB.svg'); }
.mc-piece.mc-wr { background-image: url('/cg/assets/images/pieces/cburnett/wR.svg'); }
.mc-piece.mc-wq { background-image: url('/cg/assets/images/pieces/cburnett/wQ.svg'); }
.mc-piece.mc-wk { background-image: url('/cg/assets/images/pieces/cburnett/wK.svg'); }
.mc-piece.mc-bp { background-image: url('/cg/assets/images/pieces/cburnett/bP.svg'); }
.mc-piece.mc-bn { background-image: url('/cg/assets/images/pieces/cburnett/bN.svg'); }
.mc-piece.mc-bb { background-image: url('/cg/assets/images/pieces/cburnett/bB.svg'); }
.mc-piece.mc-br { background-image: url('/cg/assets/images/pieces/cburnett/bR.svg'); }
.mc-piece.mc-bq { background-image: url('/cg/assets/images/pieces/cburnett/bQ.svg'); }
.mc-piece.mc-bk { background-image: url('/cg/assets/images/pieces/cburnett/bK.svg'); }
