root { --cell-size: 48px; }

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #1a2a0e;
  color: #e0e0e0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen { width: 100%; }
.hidden { display: none !important; }

/* ─── Кнопки ─── */
.btn-primary {
  background: #4f8ef7;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: #3a7ae0; }
.btn-primary:disabled { background: #555; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: #e07c7c;
  border: 2px solid #e07c7c;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: #e07c7c; color: #fff; }

/* ─── СТАРТОВЫЙ ЭКРАН (новый трехколоночный макет) ─── */
#screen-start {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Фоновое изображение */
.start-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('image/backgroud.png') center/cover no-repeat;
  z-index: -1;
}

/* Фоновое изображение для экрана игры */
.game-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('image/backgroud.png') center/cover no-repeat;
  z-index: -1;
}

/* Логотип игры */
.start-logo {
  text-align: center;
  padding: 30px 20px 20px;
}

.start-logo img {
  max-width: 400px;
  width: 100%;
  height: auto;
}

/* Основной контейнер с тремя колонками */
.start-content {
  display: flex;
  padding: 20px 40px 40px;
  gap: 30px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  align-items: stretch;
}

/* Общие стили для колонок */
.start-column {
  background: rgba(22, 33, 62, 0.9);
  border-radius: 16px;
  padding: 24px;
  border: 2px solid #2a4a7a;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

/* ЛЕВАЯ КОЛОНКА - Приветствие */
.start-column-left {
  flex: 0 0 300px;
}

.player-welcome-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.welcome-title {
  font-size: 1.5rem;
  color: #4f8ef7;
  margin-bottom: 20px;
  text-align: center;
}

.welcome-name {
  font-size: 1.3rem;
  color: #a8d5a2;
  margin-bottom: 24px;
  text-align: center;
  font-weight: 600;
}

.player-stats {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(15, 52, 96, 0.5);
  border-radius: 8px;
}

.stat-label {
  color: #9aa;
  font-size: 0.95rem;
}

.stat-value {
  color: #e0e0e0;
  font-size: 1.1rem;
  font-weight: 700;
}

.welcome-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 0.9rem;
  color: #9aa;
  margin-bottom: 8px;
}

.input-group input {
  width: 100%;
  background: rgba(15, 52, 96, 0.8);
  border: 2px solid #2a4a7a;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.2s;
}

.input-group input:focus {
  border-color: #4f8ef7;
}

/* ЦЕНТРАЛЬНАЯ КОЛОНКА - Выбор уровня */
.start-column-center {
  flex: 1 1 500px;
  min-width: 300px;
}

.level-selection-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.level-title {
  font-size: 1.5rem;
  color: #4f8ef7;
  margin-bottom: 8px;
  text-align: center;
}

.level-subtitle {
  font-size: 0.95rem;
  color: #9aa;
  margin-bottom: 24px;
  text-align: center;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  flex: 1;
}

.btn-level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: rgba(15, 52, 96, 0.5);
  border: 2px solid #2a4a7a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-level-card:hover {
  border-color: #4f8ef7;
  background: rgba(15, 52, 96, 0.8);
}

.btn-level-card.active {
  background: #4f8ef7;
  border-color: #4f8ef7;
}

/* Таблица уровней (строки) */
.level-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-level-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: rgba(15, 52, 96, 0.5);
  border: 2px solid #2a4a7a;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.btn-level-row:hover {
  border-color: #4f8ef7;
  background: rgba(15, 52, 96, 0.8);
}

.btn-level-row.active {
  background: #4f8ef7;
  border-color: #4f8ef7;
}

.level-num {
  font-size: 1.4rem;
  font-weight: 700;
  color: #4f8ef7;
  min-width: 30px;
  text-align: center;
}

.btn-level-row.active .level-num,
.btn-level-row.active .level-name-text {
  color: #fff;
}

.level-name-text {
  font-size: 1rem;
  color: #e0e0e0;
  flex: 1;
}

/* ПРАВАЯ КОЛОНКА - Рейтинг */
.start-column-right {
  flex: 0 0 320px;
}

.rating-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.rating-title {
  font-size: 1.5rem;
  color: #4f8ef7;
  margin-bottom: 20px;
  text-align: center;
}

.rating-table-wrapper {
  flex: 1;
  overflow-y: auto;
  background: rgba(15, 52, 96, 0.3);
  border-radius: 8px;
  padding: 8px;
}

.rating-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.rating-table th,
.rating-table td {
  padding: 10px 8px;
  text-align: left;
}

.rating-table th {
  color: #7aad7a;
  font-weight: 600;
  background: rgba(26, 42, 26, 0.5);
  position: sticky;
  top: 0;
}

.rating-table td {
  color: #e0e0e0;
  border-bottom: 1px solid rgba(42, 74, 122, 0.3);
}

.rating-table tr:last-child td {
  border-bottom: none;
}

.rating-table tr:hover td {
  background: rgba(26, 42, 26, 0.3);
}

/* Стили для колонок рейтинга: имя | счет | дата */
.rating-table td:nth-child(1) {
  font-weight: 600;
  color: #e0e0e0;
}

.rating-table td:nth-child(2) {
  color: #4f8ef7;
  font-weight: 700;
}

.rating-table td:nth-child(3) {
  color: #9aa;
  font-size: 0.85rem;
  text-align: right;
}

.rating-table td:nth-child(4) {
  color: #9aa;
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
}

/* ─── Игра ─── */
#screen-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #16213e;
  padding: 12px 24px;
  border-bottom: 1px solid #2a4a7a;
  gap: 16px;
}

.header-left  { display: flex; align-items: center; }
.header-right { justify-self: end; position: relative; display: flex; align-items: center; }

.level-name   { font-size: 1rem; font-weight: 600; color: #9aa; letter-spacing: 0.5px; }
.player-name  { font-size: 1rem; font-weight: 700; color: #4f8ef7; }

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}
.score-label       { color: #9aa; font-size: 0.95rem; }
.score-value       { font-size: 1.4rem; font-weight: 700; }
.score-value-inline { font-size: 1.3rem; font-weight: 700; }
.score-sep         { color: #556; margin: 0 4px; }

/* ─── Меню ─── */
.menu-wrap { position: relative; }

.game-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #16213e;
  border: 1px solid #2a4a7a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 220px;
  z-index: 50;
  animation: menu-drop 0.2s ease;
}

@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-menu button {
  display: block;
  width: 100%;
  padding: 13px 20px;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.game-menu button:hover { background: #1e3a6e; }
.game-menu button + button { border-top: 1px solid #2a4a7a; }

/* ─── Декоративные рыцари по краям ─── */
@keyframes knight-deco-idle {
  from { background-position: 0 0; }
  to   { background-position: calc(30vmin * -19) 0; }
}

.knight-deco {
  position: absolute;
  top: 0;
  width: 30vmin;
  height: 30vmin;
  pointer-events: none;
  z-index: 20;
}

/* Облако ЗА рыцарем (z-index:1, рыцарь z-index:2 — выше) */
.knight-deco::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(
    ellipse 45% 45% at 50% 60%,
    rgba(255, 255, 255, 0.92) 0%,
    rgba(255, 255, 255, 0.65) 30%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0)    70%
  );
  z-index: 1;
}

/* Спрайт рыцаря — поверх облака */
.knight-deco::after {
  content: '';
  position: absolute;
  inset: 0;
  background-size: calc(30vmin * 19) 30vmin;
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: knight-deco-idle 1.9s steps(19) alternate infinite;
  z-index: 2;
}

.knight-deco-blue {
  right: 100%;
  transform: translateX(15%) translateY(-25%);
}
.knight-deco-blue::after {
  background-image: url('knight-blue.png');
  animation-delay: -0.6s;
}

.knight-deco-red {
  left: 100%;
  transform: translateX(-15%) translateY(-25%) scaleX(-1);   /* смотрит влево (к центру поля) */
}
.knight-deco-red::after {
  background-image: url('knight-red.png');
  animation-delay: -1.5s;
}

/* ─── Поле ─── */
#board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: visible;
}

#board-area {
  position: relative;
  display: inline-block;  /* сжимается до размера board-container */
}

#board-container {
  display: grid;
  border: 2px solid #7a6530;
  transform: perspective(1500px) rotateX(8deg);
  transform-origin: 50% 50%;   /* вращение вокруг центра — низ не уходит */
  /* grid-template-columns задаётся из JS */
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #8a7d4a;   /* fallback если изображение не загрузилось */
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border: 1px solid rgba(70, 50, 8, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.1s;
  user-select: none;
  position: relative;
}

.cell:hover.empty {
  box-shadow: inset 0 0 0 2px #ffd700;
}

/* ─── Рыцари поверх клетки, 20% больше ─── */
/*
  Рыцарь на 20% больше клетки: inset = -10% с каждой стороны.
  background-size и keyframe-конец пересчитываются JS при изменении --cell-size.
  Базовые значения ниже соответствуют --cell-size: 48px.
*/
@keyframes knight-idle {
  from { background-position: 0px 0px; }
  to   { background-position: -1094px 0px; } /* 19 × ceil(48×1.2)=58 */
}

.cell.player,
.cell.ai {
  cursor: default;
}

.cell.player::after,
.cell.ai::after {
  content: '';
  position: absolute;
  /* 20% больше клетки, сдвинут вверх: ноги точно у нижнего края клетки */
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-size: calc(var(--cell-size) * 22.8) calc(var(--cell-size) * 1.2);
  background-repeat: no-repeat;
  background-position: 0px 0px;
  /* ping-pong: 1→19→1, delay задаётся inline CSS-переменной */
  animation: knight-idle 1.9s steps(19) alternate infinite;
  animation-delay: var(--knight-delay, 0s);
  z-index: 2;
}

.cell.player::after { background-image: url('knight-blue.png'); }
.cell.ai::after     { background-image: url('knight-red.png'); }

/* ─── Цветовые оверлеи поверх травы (::before) ─── */
/* Трава остаётся фоном, поверх неё — полупрозрачный цвет */
.cell.fire-place::before,
.cell.player-place::before,
.cell.ai-place::before,
.cell.wall::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.cell.fire-place   { cursor: default; }
.cell.player-place { cursor: default; }
.cell.ai-place     { cursor: default; }
.cell.wall         { cursor: default; }

.cell.fire-place::before   { background: rgba(90,  40,  0,  0.50); }

.cell.fire-place::after {
  content: '';
  position: absolute;
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-image: url('image/fire.png');
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: fire-idle 1.65s steps(33) infinite;
  animation-delay: var(--fire-delay, 0s);
  z-index: 3;
}
.cell.player-place::before { background: rgba(10,  26,  74, 0.82); }
.cell.ai-place::before     { background: rgba(74,  10,  10, 0.82); }
.cell.wall::before         { background: rgba(30,  30,  30, 0.50); }

.cell.wall::after {
  content: '';
  position: absolute;
  top:   calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:  calc(var(--cell-size) * -0.1);
  right: calc(var(--cell-size) * -0.1);
  background-image: var(--rock-url);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  z-index: 2;
}


/* ─── Оверлей победителя ─── */
@keyframes overlay-fade {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.75); }
}

@keyframes card-pop {
  from { transform: scale(0.04); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-fade 0.35s ease forwards;
}

.overlay-card {
  background: #16213e;
  border-radius: 20px;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.7);
  animation: card-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.overlay-text {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}
.overlay-text.win  { color: #4f8ef7; }
.overlay-text.lose { color: #e07c7c; }

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-next-level {
  background: transparent;
  color: #7aad7a;
  border: 2px solid #7aad7a;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-next-level:hover    { background: #7aad7a; color: #fff; }
.btn-next-level:disabled { opacity: 0.35; cursor: default; border-color: #555; color: #555; }

/* ─── Стартовый экран: приветствие и кнопки (старые стили - удалить) ─── */
.start-card {
  display: none;
}

/* ─── Игра ─── */
#screen-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #16213e;
  padding: 12px 24px;
  border-bottom: 1px solid #2a4a7a;
  gap: 16px;
}

.header-left  { display: flex; align-items: center; }
.header-right { justify-self: end; position: relative; }

.level-name   { font-size: 1rem; font-weight: 600; color: #9aa; letter-spacing: 0.5px; }
.player-name  { font-size: 1rem; font-weight: 700; color: #4f8ef7; }

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}
.score-label       { color: #9aa; font-size: 0.95rem; }
.score-value       { font-size: 1.4rem; font-weight: 700; }
.score-value-inline { font-size: 1.3rem; font-weight: 700; }
.score-sep         { color: #556; margin: 0 4px; }

/* ─── Меню ─── */
.menu-wrap { position: relative; }

.game-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #16213e;
  border: 1px solid #2a4a7a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 220px;
  z-index: 50;
  animation: menu-drop 0.2s ease;
}

@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-menu button {
  display: block;
  width: 100%;
  padding: 13px 20px;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.game-menu button:hover { background: #1e3a6e; }
.game-menu button + button { border-top: 1px solid #2a4a7a; }

/* ─── Декоративные рыцари по краям ─── */
@keyframes knight-deco-idle {
  from { background-position: 0 0; }
  to   { background-position: calc(30vmin * -19) 0; }
}

.knight-deco {
  position: absolute;
  top: 0;
  width: 30vmin;
  height: 30vmin;
  pointer-events: none;
  z-index: 20;
}

/* Облако ЗА рыцарем (z-index:1, рыцарь z-index:2 — выше) */
.knight-deco::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(
    ellipse 45% 45% at 50% 60%,
    rgba(255, 255, 255, 0.92) 0%,
    rgba(255, 255, 255, 0.65) 30%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0)    70%
  );
  z-index: 1;
}

/* Спрайт рыцаря — поверх облака */
.knight-deco::after {
  content: '';
  position: absolute;
  inset: 0;
  background-size: calc(30vmin * 19) 30vmin;
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: knight-deco-idle 1.9s steps(19) alternate infinite;
  z-index: 2;
}

.knight-deco-blue {
  right: 100%;
  transform: translateX(15%) translateY(-25%);
}
.knight-deco-blue::after {
  background-image: url('knight-blue.png');
  animation-delay: -0.6s;
}

.knight-deco-red {
  left: 100%;
  transform: translateX(-15%) translateY(-25%) scaleX(-1);   /* смотрит влево (к центру поля) */
}
.knight-deco-red::after {
  background-image: url('knight-red.png');
  animation-delay: -1.5s;
}

/* ─── Поле ─── */
#board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: visible;
}

#board-area {
  position: relative;
  display: inline-block;  /* сжимается до размера board-container */
}

#board-container {
  display: grid;
  border: 2px solid #7a6530;
  transform: perspective(1500px) rotateX(8deg);
  transform-origin: 50% 50%;   /* вращение вокруг центра — низ не уходит */
  /* grid-template-columns задаётся из JS */
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #8a7d4a;   /* fallback если изображение не загрузилось */
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border: 1px solid rgba(70, 50, 8, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.1s;
  user-select: none;
  position: relative;
}

.cell:hover.empty {
  box-shadow: inset 0 0 0 2px #ffd700;
}

/* ─── Рыцари поверх клетки, 20% больше ─── */
/*
  Рыцарь на 20% больше клетки: inset = -10% с каждой стороны.
  background-size и keyframe-конец пересчитываются JS при изменении --cell-size.
  Базовые значения ниже соответствуют --cell-size: 48px.
*/
@keyframes knight-idle {
  from { background-position: 0px 0px; }
  to   { background-position: -1094px 0px; } /* 19 × ceil(48×1.2)=58 */
}

.cell.player,
.cell.ai {
  cursor: default;
}

.cell.player::after,
.cell.ai::after {
  content: '';
  position: absolute;
  /* 20% больше клетки, сдвинут вверх: ноги точно у нижнего края клетки */
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-size: calc(var(--cell-size) * 22.8) calc(var(--cell-size) * 1.2);
  background-repeat: no-repeat;
  background-position: 0px 0px;
  /* ping-pong: 1→19→1, delay задаётся inline CSS-переменной */
  animation: knight-idle 1.9s steps(19) alternate infinite;
  animation-delay: var(--knight-delay, 0s);
  z-index: 2;
}

.cell.player::after { background-image: url('knight-blue.png'); }
.cell.ai::after     { background-image: url('knight-red.png'); }

/* ─── Цветовые оверлеи поверх травы (::before) ─── */
/* Трава остаётся фоном, поверх неё — полупрозрачный цвет */
.cell.fire-place::before,
.cell.player-place::before,
.cell.ai-place::before,
.cell.wall::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.cell.fire-place   { cursor: default; }
.cell.player-place { cursor: default; }
.cell.ai-place     { cursor: default; }
.cell.wall         { cursor: default; }

.cell.fire-place::before   { background: rgba(90,  40,  0,  0.50); }

.cell.fire-place::after {
  content: '';
  position: absolute;
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-image: url('image/fire.png');
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: fire-idle 1.65s steps(33) infinite;
  animation-delay: var(--fire-delay, 0s);
  z-index: 3;
}
.cell.player-place::before { background: rgba(10,  26,  74, 0.82); }
.cell.ai-place::before     { background: rgba(74,  10,  10, 0.82); }
.cell.wall::before         { background: rgba(30,  30,  30, 0.50); }

.cell.wall::after {
  content: '';
  position: absolute;
  top:   calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:  calc(var(--cell-size) * -0.1);
  right: calc(var(--cell-size) * -0.1);
  background-image: var(--rock-url);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  z-index: 2;
}


/* ─── Оверлей победителя ─── */
@keyframes overlay-fade {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.75); }
}

@keyframes card-pop {
  from { transform: scale(0.04); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-fade 0.35s ease forwards;
}

.overlay-card {
  background: #16213e;
  border-radius: 20px;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.7);
  animation: card-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.overlay-text {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}
.overlay-text.win  { color: #4f8ef7; }
.overlay-text.lose { color: #e07c7c; }

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-next-level {
  background: transparent;
  color: #7aad7a;
  border: 2px solid #7aad7a;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-next-level:hover    { background: #7aad7a; color: #fff; }
.btn-next-level:disabled { opacity: 0.35; cursor: default; border-color: #555; color: #555; }

/* ─── Стартовый экран: приветствие и кнопки ─── */
.welcome-text-old {
  font-size: 1.4rem;
  font-weight: 700;
  color: #a8d5a2;
  margin-bottom: 8px;
}

.player-stats-row-old {
  display: flex;
  gap: 24px;
  font-size: 1rem;
  color: #b0c8b0;
  margin-bottom: 16px;
}

.player-stats-row-old strong {
  color: #e0e0e0;
}

.btn-row-old {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

/* ─── Таблица статистики (старая) ─── */
.stats-block-old {
  margin-top: 28px;
  width: 100%;
}

.stats-title-old {
  font-size: 1rem;
  color: #7aad7a;
  margin-bottom: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stats-table-old {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stats-table-old th,
.stats-table-old td {
  padding: 7px 12px;
  text-align: left;
  border-bottom: 1px solid #2a3a2a;
}

.stats-table-old th {
  color: #7aad7a;
  font-weight: 600;
  background: #1a2a1a;
}

.stats-table-old tr:hover td {
  background: #1e2e1e;
}

/* ─── Игра ─── */
#screen-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #16213e;
  padding: 12px 24px;
  border-bottom: 1px solid #2a4a7a;
  gap: 16px;
}

.header-left  { display: flex; align-items: center; }
.header-right { justify-self: end; position: relative; }

.level-name   { font-size: 1rem; font-weight: 600; color: #9aa; letter-spacing: 0.5px; }
.player-name  { font-size: 1rem; font-weight: 700; color: #4f8ef7; }

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}
.score-label       { color: #9aa; font-size: 0.95rem; }
.score-value       { font-size: 1.4rem; font-weight: 700; }
.score-value-inline { font-size: 1.3rem; font-weight: 700; }
.score-sep         { color: #556; margin: 0 4px; }

/* ─── Меню ─── */
.menu-wrap { position: relative; }

.game-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #16213e;
  border: 1px solid #2a4a7a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 220px;
  z-index: 50;
  animation: menu-drop 0.2s ease;
}

@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-menu button {
  display: block;
  width: 100%;
  padding: 13px 20px;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.game-menu button:hover { background: #1e3a6e; }
.game-menu button + button { border-top: 1px solid #2a4a7a; }

/* ─── Декоративные рыцари по краям ─── */
@keyframes knight-deco-idle {
  from { background-position: 0 0; }
  to   { background-position: calc(30vmin * -19) 0; }
}

.knight-deco {
  position: absolute;
  top: 0;
  width: 30vmin;
  height: 30vmin;
  pointer-events: none;
  z-index: 20;
}

/* Облако ЗА рыцарем (z-index:1, рыцарь z-index:2 — выше) */
.knight-deco::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(
    ellipse 45% 45% at 50% 60%,
    rgba(255, 255, 255, 0.92) 0%,
    rgba(255, 255, 255, 0.65) 30%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0)    70%
  );
  z-index: 1;
}

/* Спрайт рыцаря — поверх облака */
.knight-deco::after {
  content: '';
  position: absolute;
  inset: 0;
  background-size: calc(30vmin * 19) 30vmin;
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: knight-deco-idle 1.9s steps(19) alternate infinite;
  z-index: 2;
}

.knight-deco-blue {
  right: 100%;
  transform: translateX(15%) translateY(-25%);
}
.knight-deco-blue::after {
  background-image: url('knight-blue.png');
  animation-delay: -0.6s;
}

.knight-deco-red {
  left: 100%;
  transform: translateX(-15%) translateY(-25%) scaleX(-1);   /* смотрит влево (к центру поля) */
}
.knight-deco-red::after {
  background-image: url('knight-red.png');
  animation-delay: -1.5s;
}

/* ─── Поле ─── */
#board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: visible;
}

#board-area {
  position: relative;
  display: inline-block;  /* сжимается до размера board-container */
}

#board-container {
  display: grid;
  border: 2px solid #7a6530;
  transform: perspective(1500px) rotateX(8deg);
  transform-origin: 50% 50%;   /* вращение вокруг центра — низ не уходит */
  /* grid-template-columns задаётся из JS */
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #8a7d4a;   /* fallback если изображение не загрузилось */
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border: 1px solid rgba(70, 50, 8, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.1s;
  user-select: none;
  position: relative;
}

.cell:hover.empty {
  box-shadow: inset 0 0 0 2px #ffd700;
}

/* ─── Рыцари поверх клетки, 20% больше ─── */
/*
  Рыцарь на 20% больше клетки: inset = -10% с каждой стороны.
  background-size и keyframe-конец пересчитываются JS при изменении --cell-size.
  Базовые значения ниже соответствуют --cell-size: 48px.
*/
@keyframes knight-idle {
  from { background-position: 0px 0px; }
  to   { background-position: -1094px 0px; } /* 19 × ceil(48×1.2)=58 */
}

.cell.player,
.cell.ai {
  cursor: default;
}

.cell.player::after,
.cell.ai::after {
  content: '';
  position: absolute;
  /* 20% больше клетки, сдвинут вверх: ноги точно у нижнего края клетки */
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-size: calc(var(--cell-size) * 22.8) calc(var(--cell-size) * 1.2);
  background-repeat: no-repeat;
  background-position: 0px 0px;
  /* ping-pong: 1→19→1, delay задаётся inline CSS-переменной */
  animation: knight-idle 1.9s steps(19) alternate infinite;
  animation-delay: var(--knight-delay, 0s);
  z-index: 2;
}

.cell.player::after { background-image: url('knight-blue.png'); }
.cell.ai::after     { background-image: url('knight-red.png'); }

/* ─── Цветовые оверлеи поверх травы (::before) ─── */
/* Трава остаётся фоном, поверх неё — полупрозрачный цвет */
.cell.fire-place::before,
.cell.player-place::before,
.cell.ai-place::before,
.cell.wall::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.cell.fire-place   { cursor: default; }
.cell.player-place { cursor: default; }
.cell.ai-place     { cursor: default; }
.cell.wall         { cursor: default; }

.cell.fire-place::before   { background: rgba(90,  40,  0,  0.50); }

.cell.fire-place::after {
  content: '';
  position: absolute;
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-image: url('image/fire.png');
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: fire-idle 1.65s steps(33) infinite;
  animation-delay: var(--fire-delay, 0s);
  z-index: 3;
}
.cell.player-place::before { background: rgba(10,  26,  74, 0.82); }
.cell.ai-place::before     { background: rgba(74,  10,  10, 0.82); }
.cell.wall::before         { background: rgba(30,  30,  30, 0.50); }

.cell.wall::after {
  content: '';
  position: absolute;
  top:   calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:  calc(var(--cell-size) * -0.1);
  right: calc(var(--cell-size) * -0.1);
  background-image: var(--rock-url);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  z-index: 2;
}


/* ─── Оверлей победителя ─── */
@keyframes overlay-fade {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.75); }
}

@keyframes card-pop {
  from { transform: scale(0.04); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-fade 0.35s ease forwards;
}

.overlay-card {
  background: #16213e;
  border-radius: 20px;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.7);
  animation: card-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.overlay-text {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}
.overlay-text.win  { color: #4f8ef7; }
.overlay-text.lose { color: #e07c7c; }

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-next-level {
  background: transparent;
  color: #7aad7a;
  border: 2px solid #7aad7a;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-next-level:hover    { background: #7aad7a; color: #fff; }
.btn-next-level:disabled { opacity: 0.35; cursor: default; border-color: #555; color: #555; }

/* ─── Стартовый экран: приветствие и кнопки (старые стили - удалить) ─── */
.start-card {
  display: none;
}

/* ─── Игра ─── */
#screen-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #16213e;
  padding: 12px 24px;
  border-bottom: 1px solid #2a4a7a;
  gap: 16px;
}

.header-left  { display: flex; align-items: center; }
.header-right { justify-self: end; position: relative; }

.level-name   { font-size: 1rem; font-weight: 600; color: #9aa; letter-spacing: 0.5px; }
.player-name  { font-size: 1rem; font-weight: 700; color: #4f8ef7; }

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}
.score-label       { color: #9aa; font-size: 0.95rem; }
.score-value       { font-size: 1.4rem; font-weight: 700; }
.score-value-inline { font-size: 1.3rem; font-weight: 700; }
.score-sep         { color: #556; margin: 0 4px; }

/* ─── Меню ─── */
.menu-wrap { position: relative; }

.game-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #16213e;
  border: 1px solid #2a4a7a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 220px;
  z-index: 50;
  animation: menu-drop 0.2s ease;
}

@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-menu button {
  display: block;
  width: 100%;
  padding: 13px 20px;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.game-menu button:hover { background: #1e3a6e; }
.game-menu button + button { border-top: 1px solid #2a4a7a; }

/* ─── Декоративные рыцари по краям ─── */
@keyframes knight-deco-idle {
  from { background-position: 0 0; }
  to   { background-position: calc(30vmin * -19) 0; }
}

.knight-deco {
  position: absolute;
  top: 0;
  width: 30vmin;
  height: 30vmin;
  pointer-events: none;
  z-index: 20;
}

/* Облако ЗА рыцарем (z-index:1, рыцарь z-index:2 — выше) */
.knight-deco::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(
    ellipse 45% 45% at 50% 60%,
    rgba(255, 255, 255, 0.92) 0%,
    rgba(255, 255, 255, 0.65) 30%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0)    70%
  );
  z-index: 1;
}

/* Спрайт рыцаря — поверх облака */
.knight-deco::after {
  content: '';
  position: absolute;
  inset: 0;
  background-size: calc(30vmin * 19) 30vmin;
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: knight-deco-idle 1.9s steps(19) alternate infinite;
  z-index: 2;
}

.knight-deco-blue {
  right: 100%;
  transform: translateX(15%) translateY(-25%);
}
.knight-deco-blue::after {
  background-image: url('knight-blue.png');
  animation-delay: -0.6s;
}

.knight-deco-red {
  left: 100%;
  transform: translateX(-15%) translateY(-25%) scaleX(-1);   /* смотрит влево (к центру поля) */
}
.knight-deco-red::after {
  background-image: url('knight-red.png');
  animation-delay: -1.5s;
}

/* ─── Поле ─── */
#board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: visible;
}

#board-area {
  position: relative;
  display: inline-block;  /* сжимается до размера board-container */
}

#board-container {
  display: grid;
  border: 2px solid #7a6530;
  transform: perspective(1500px) rotateX(8deg);
  transform-origin: 50% 50%;   /* вращение вокруг центра — низ не уходит */
  /* grid-template-columns задаётся из JS */
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #8a7d4a;   /* fallback если изображение не загрузилось */
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border: 1px solid rgba(70, 50, 8, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.1s;
  user-select: none;
  position: relative;
}

.cell:hover.empty {
  box-shadow: inset 0 0 0 2px #ffd700;
}

/* ─── Рыцари поверх клетки, 20% больше ─── */
/*
  Рыцарь на 20% больше клетки: inset = -10% с каждой стороны.
  background-size и keyframe-конец пересчитываются JS при изменении --cell-size.
  Базовые значения ниже соответствуют --cell-size: 48px.
*/
@keyframes knight-idle {
  from { background-position: 0px 0px; }
  to   { background-position: -1094px 0px; } /* 19 × ceil(48×1.2)=58 */
}

.cell.player,
.cell.ai {
  cursor: default;
}

.cell.player::after,
.cell.ai::after {
  content: '';
  position: absolute;
  /* 20% больше клетки, сдвинут вверх: ноги точно у нижнего края клетки */
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-size: calc(var(--cell-size) * 22.8) calc(var(--cell-size) * 1.2);
  background-repeat: no-repeat;
  background-position: 0px 0px;
  /* ping-pong: 1→19→1, delay задаётся inline CSS-переменной */
  animation: knight-idle 1.9s steps(19) alternate infinite;
  animation-delay: var(--knight-delay, 0s);
  z-index: 2;
}

.cell.player::after { background-image: url('knight-blue.png'); }
.cell.ai::after     { background-image: url('knight-red.png'); }

/* ─── Цветовые оверлеи поверх травы (::before) ─── */
/* Трава остаётся фоном, поверх неё — полупрозрачный цвет */
.cell.fire-place::before,
.cell.player-place::before,
.cell.ai-place::before,
.cell.wall::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.cell.fire-place   { cursor: default; }
.cell.player-place { cursor: default; }
.cell.ai-place     { cursor: default; }
.cell.wall         { cursor: default; }

.cell.fire-place::before   { background: rgba(90,  40,  0,  0.50); }

.cell.fire-place::after {
  content: '';
  position: absolute;
  top:    calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:   calc(var(--cell-size) * -0.1);
  right:  calc(var(--cell-size) * -0.1);
  background-image: url('image/fire.png');
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: fire-idle 1.65s steps(33) infinite;
  animation-delay: var(--fire-delay, 0s);
  z-index: 3;
}
.cell.player-place::before { background: rgba(10,  26,  74, 0.82); }
.cell.ai-place::before     { background: rgba(74,  10,  10, 0.82); }
.cell.wall::before         { background: rgba(30,  30,  30, 0.50); }

.cell.wall::after {
  content: '';
  position: absolute;
  top:   calc(var(--cell-size) * -0.2);
  bottom: 0;
  left:  calc(var(--cell-size) * -0.1);
  right: calc(var(--cell-size) * -0.1);
  background-image: var(--rock-url);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  z-index: 2;
}


/* ─── Оверлей победителя ─── */
@keyframes overlay-fade {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.75); }
}

@keyframes card-pop {
  from { transform: scale(0.04); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-fade 0.35s ease forwards;
}

.overlay-card {
  background: #16213e;
  border-radius: 20px;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.7);
  animation: card-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.overlay-text {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}
.overlay-text.win  { color: #4f8ef7; }
.overlay-text.lose { color: #e07c7c; }

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-next-level {
  background: transparent;
  color: #7aad7a;
  border: 2px solid #7aad7a;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-next-level:hover    { background: #7aad7a; color: #fff; }
.btn-next-level:disabled { opacity: 0.35; cursor: default; border-color: #555; color: #555; }

/* ─── Кнопка музыки (динамик) ─── */
.music-btn {
  background: transparent;
  border: none;
  color: #aaccee;
  width: 40px;
  height: 40px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.music-btn:hover {
  color: #fff;
}
.music-btn svg {
  width: 28px;
  height: 28px;
}
.music-btn.muted {
  color: #556;
}
.music-btn.muted:hover {
  color: #778;
}

#screen-start .music-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 50;
  background: rgba(26, 44, 81, 0.85);
  border: 1px solid #3a5a8a;
  border-radius: 8px;
}
#screen-start .music-btn:hover {
  background: #1e3a6e;
  border-color: #5b9cf7;
}
#screen-start .music-btn.muted {
  background: rgba(30, 30, 40, 0.7);
  border-color: #333;
}

#screen-game .header-right .music-btn {
  margin-right: 8px;
}
