:root {
    --cell-size: 60px;
    --light-color: #f0d9b5;
    --dark-color: #b58863;
}

body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f0f0f0;
}

#chess-game {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    margin-top: 20px;
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 60px);
    grid-template-rows: repeat(8, 60px);
    border: 2px solid #333;
}

.square {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5em;
    cursor: pointer;
    margin: 0;
    padding: 0;
}
.square span {
    font-size: calc(var(--cell-size) * 0.8); /* Размер фигур относительно размера клетки */
    line-height: 1; /* ОЧЕНЬ ВАЖНО: Устанавливаем line-height в 1 */
    text-align: center; /* На всякий случай */

    /* Попробуйте указать конкретный шрифт для шахматных символов, если он у вас есть. Иначе - просто системный. */
    /* font-family: "Segoe UI Symbol", "Noto Color Emoji", sans-serif;  */
    /* font-family: tru */
    
    user-select: none; /* Чтобы фигуры не выделялись мышкой */
    -webkit-user-select: none; /* Для старых версий Safari */
}
.square.light {
    background-color: var(--light-color);
}

.square.dark {
    background-color: var(--dark-color);
}

.selected {
    background-color: #8c7b4c !important;
}

.highlight {
    background-color: #a3c48a !important;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.check {
    background-color: #ff4d4d !important;
}

.piece {
    cursor: pointer;
    user-select: none;
}

.white {
    color: #fff;
    text-shadow: 1px 1px 2px #000;
}

.black {
    color: #000;
    /* color: #333; */
    /* color: #fff; */
    /* text-shadow: 0 0 1px #fff; */

    text-shadow: 1px 1px 2px #000;
    /* font-weight: bold; */
}

#controls {
    margin-bottom: 10px;

    display: flex;
    flex-direction: row;
    justify-content: center;
    /* grid-template: auto; */
    /* grid-template-columns: repeat(8, 60px); */
    /* grid-template-rows: repeat(8, 60px); */
    /* border: 2px solid #333; */

}

#status-bar,
#game-status {
    margin: 10px 0;
    margin-top: 2em;
    font-weight: bold;
    text-align: center;
}

#sync-status {
    margin-left: 15px; font-size: 0.8em; color: gray;
}


/* Контейнер для всей доски с разметкой */
.board-wrapper {
    display: inline-block;
    background: #333; /* Цвет рамки */
    padding: 5px;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.main-row {
    display: flex;
    flex-direction: row;
}

/* Общие стили для блоков координат */
.coords {
    display: flex;
    color: #ddd;
    font-weight: bold;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    text-transform: uppercase;
}

/* Горизонтальные (буквы) */
.letters {
    flex-direction: row;
    padding-left: 25px; /* Отступ под ширину колонки с цифрами */
    height: 25px;
    align-items: center;
}
.letters div {
    width: 60px; /* Должно совпадать с шириной клетки */
    text-align: center;
}

/* Вертикальные (цифры) */
.numbers {
    flex-direction: column;
    width: 25px;
}
.numbers div {
    height: 60px; /* Должно совпадать с высотой клетки */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Чтобы доска не съезжала */
#chessboard {
    border: none; /* Рамку теперь берет на себя wrapper */
}

.coords {
    font-family: "Courier New", Courier, monospace;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}


/* Стильная кнопка */
.chess-button {
    background-color: #4a4a4a;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    font-family: sans-serif;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 0 #2c2c2c;
}

.chess-button:hover {
    background-color: #555;
    transform: translateY(-1px);
}

.chess-button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #2c2c2c;
}

.chess-button .icon {
    font-size: 1.2em;
}

#reset-btn {
    /* padding: 10px 20px;
    font-size: 1.1em; */
    background-color: #174436;
    color: white;
    margin-left: 47px;
    /* border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease; */
}

#reset-btn:hover {
    background-color: #227259;
}


/* --- ЛОГИКА ПЕРЕВОРОТА --- */

/* 1. Поворачиваем основной контейнер */
.board-wrapper.flipped {
    display: flex;
    flex-direction: column-reverse; /* Меняем верхние и нижние буквы местами */
}

/* 2. Поворачиваем ряды (цифры и доску) */
.board-wrapper.flipped .main-row {
    flex-direction: row-reverse; /* Меняем левые и правые цифры местами */
}

/* 3. Поворачиваем саму доску на 180 градусов */
.board-wrapper.flipped #chessboard {
    transform: rotate(180deg);
}

/* 4. ВАЖНО: Поворачиваем клетки обратно на 180 градусов, 
      чтобы фигуры и цвета не были вверх ногами! */
.board-wrapper.flipped .square {
    transform: rotate(180deg);
}

/* 5. Инвертируем порядок букв и цифр */
.board-wrapper.flipped .letters {
    flex-direction: row-reverse;
    padding-right: 25px; /* Отступ под ширину колонки с цифрами */
}
.board-wrapper.flipped .numbers {
    flex-direction: column-reverse;
}




    /* #captured-pieces {
        margin-top: 20px;
        font-size: 24px;
        text-align: center;
    } */

    /* .piece {
        width: 50px;
        height: 50px;
        display: inline-block;
        background-size: cover;
        border-radius: 8px;
    } */


    #captured-pieces {
        margin-top: 20px;
        padding: 10px;
    }

    /* #captured-pieces .white {
        color: #fff;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    }

    #captured-pieces .black {
        color: #000;
        text-shadow: 0 0 1px rgba(255, 255, 255, 0.8);
    } */


#captured-white,
#captured-black {
    background: linear-gradient(135deg, #F0F1EE, #E8E8E1);
    border: 2px solid #ccc;
    border-radius: 7px;
    padding: 7px;
    padding-bottom: 2px;
    margin-bottom: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 120px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: left;
    text-align: left;
    transition: box-shadow 0.3s ease;
}

#captured-white:hover,
#captured-black:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

#captured-white {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    /* border-color: #adb5bd; */
}

/* #captured-black {
    background: linear-gradient(135deg, #2C3D30, #344944);
    border-color: #4a5568;
} */

#captured-white #captured-white > span:first-child,
#captured-black #captured-black > span:first-child {
    display: block;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

#captured-pieces .piece {
    margin: 0;
    padding: 2px;
    cursor: default;
    user-select: none;
    font-size: 32px;
    transition: transform 0.2s ease;
}

#captured-pieces .piece:hover {
    transform: scale(1.2);
}

#captured-white .white {
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

#captured-black .black {
    color: #000;
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.8);
}

#captured-pieces > div {
    display: block;
}


/* --- Move History Panel Styles --- */

#move-history {
    margin-bottom: 15px;
    background: #fff;
    border: 2px solid #333;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: scroll;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    height: 61px; /* Ограничиваем высоту под 3 строки */
    max-height: 61px; /* Ограничиваем высоту под 3 строки */
    transition: max-height 0.3s ease;
}

#move-history.history-expanded {
    max-height: 600px;
    overflow: visible;
}

.history-content {
    padding: 6px;
    max-height: 80px; /* Около 3 строк по 27px (14px шрифт + отступы) */
    min-height: 70px;
    flex: 1;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.3;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 2px; /* Небольшой отступ между строками */
}

.history-content::-webkit-scrollbar {
    width: 8px;
}

.history-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.history-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.history-content::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* --- Каждая запись на новой строке --- */
.history-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 2px 6px;
    border-radius: 4px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0; /* Не сжимать строки */
    transition: background 0.2s ease;
}

.history-row:last-child {
    border-bottom: none;
}

.history-row:hover {
    background: #f5f5f5;
}

.history-white {
    color: #333;
    font-weight: 600;
    flex-shrink: 0;
}

.history-black {
    color: #000;
    font-weight: 600;
    flex-shrink: 0;
}

.history-move {
    padding: 2px 4px;
    border-radius: 3px;
    display: inline-block;
    font-size: 14px;
    flex: 0 0 auto;
    white-space: nowrap;
}