:root {
    --bg-color: #262421;
    --panel-color: #302e2b;
    --light-sq: #eeeed2;
    --dark-sq: #769656;
    --red: #d93b3b;
    --blue: #3b7dd9;
    --yellow: #e0a82e;
    --green: #38a852;
    --sq: min(6.4vh, 5.2vw);
}

body {
    margin: 0;
    background-color: var(--bg-color);
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    gap: 24px;
}

#board-container {
    position: relative;
    background: #1e1c1a;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

#board {
    display: grid;
    grid-template-columns: repeat(14, var(--sq));
    grid-template-rows: repeat(14, var(--sq));
    user-select: none;
    position: relative;
}

.cell {
    width: var(--sq);
    height: var(--sq);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
}

    .cell.void {
        background: transparent;
        cursor: default;
    }

    .cell.light {
        background-color: var(--light-sq);
    }

    .cell.dark {
        background-color: var(--dark-sq);
    }

    .cell.selected {
        background-color: #f6f669 !important;
    }

    .cell.last-move {
        background-color: rgba(246, 246, 105, 0.45);
    }

    .cell.check {
        background-color: #e74c3c !important;
    }

.hint::after {
    content: "";
    width: calc(var(--sq) * 0.32);
    height: calc(var(--sq) * 0.32);
    background: rgba(0, 0, 0, 0.22);
    border-radius: 50%;
    position: absolute;
}

.hint-capture::after {
    content: "";
    width: calc(var(--sq) * 0.8);
    height: calc(var(--sq) * 0.8);
    border: calc(var(--sq) * 0.08) solid rgba(0, 0, 0, 0.25);
    border-radius: 50%;
    position: absolute;
    box-sizing: border-box;
}

.piece {
    width: calc(var(--sq) * 0.85);
    height: calc(var(--sq) * 0.85);
    object-fit: contain;
    z-index: 2;
    pointer-events: none;
    will-change: transform;
}

    .piece.R {
        filter: drop-shadow(0 2px 2px rgba(0,0,0,0.4));
    }

    .piece.B {
        filter: hue-rotate(215deg) saturate(1.2) brightness(1.15) drop-shadow(0 2px 2px rgba(0,0,0,0.4));
    }

    .piece.Y {
        filter: sepia(100%) hue-rotate(8deg) saturate(4.5) brightness(1.55) contrast(1.1) drop-shadow(0 2px 2px rgba(0,0,0,0.4));
    }

    .piece.G {
        filter: hue-rotate(125deg) saturate(1.1) brightness(1.25) drop-shadow(0 2px 2px rgba(0,0,0,0.4));
    }

    .piece.dead {
        filter: grayscale(100%) brightness(1.2) opacity(0.65) !important;
    }

#sidebar {
    width: 300px;
    background: var(--panel-color);
    padding: 20px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

h2 {
    margin: 0;
    font-size: 20px;
    text-align: center;
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-radius: 6px;
    background: #262421;
    border-left: 5px solid transparent;
    opacity: 0.6;
    transition: all 0.2s;
}

    .player-card.active {
        opacity: 1;
        background: #3a3834;
        transform: scale(1.02);
    }

    .player-card.eliminated {
        text-decoration: line-through;
        opacity: 0.35;
    }

.p-R {
    border-color: var(--red);
}

.p-B {
    border-color: var(--blue);
}

.p-Y {
    border-color: var(--yellow);
}

.p-G {
    border-color: var(--green);
}

.score {
    font-weight: bold;
    font-size: 18px;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

button, select {
    padding: 10px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    background: #81b64c;
    color: white;
}

    button:hover {
        background: #95cc5c;
    }

select {
    background: #262421;
    color: white;
    border: 1px solid #444;
}

#status {
    text-align: center;
    font-size: 14px;
    color: #ccc;
    min-height: 20px;
}

/* Угловые плашки в пустых зонах 3x3 (как на скриншоте Chess.com) */
.corner-hud {
    position: absolute;
    width: calc(var(--sq) * 3);
    height: calc(var(--sq) * 3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: calc(var(--sq) * 0.25);
    box-sizing: border-box;
    pointer-events: none;
}

.hud-Y {
    top: 0;
    left: 0;
    align-items: flex-end;
}

.hud-G {
    top: 0;
    right: 0;
    align-items: flex-start;
}

.hud-B {
    bottom: 0;
    left: 0;
    align-items: flex-end;
}

.hud-R {
    bottom: 0;
    right: 0;
    align-items: flex-start;
}

.hud-box {
    width: 100%;
    background: #262421;
    border-radius: 6px;
    padding: 6px 8px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0.65;
    transition: all 0.2s;
    border: 2px solid transparent;
}

    .hud-box.active {
        opacity: 1;
        transform: scale(1.03);
        box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    }

    .hud-box.eliminated {
        opacity: 0.3;
        text-decoration: line-through;
    }

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: calc(var(--sq) * 0.28);
    font-weight: bold;
}

.hud-timer {
    font-family: monospace;
    font-size: calc(var(--sq) * 0.42);
    font-weight: bold;
    text-align: center;
    padding: 3px 0;
    border-radius: 4px;
    color: #fff;
}

/* Цвета плашек таймера как на скриншоте */
.timer-R {
    background: var(--red);
}

.timer-B {
    background: var(--blue);
}

.timer-Y {
    background: var(--yellow);
    color: #1e1c1a;
}

.timer-G {
    background: var(--green);
}

.hud-box.low-time .hud-timer {
    animation: pulse-red 0.8s infinite alternate;
}

@keyframes pulse-red {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.4;
    }
}

/* Всплывающее окно победителя */
#victory-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

    #victory-modal.show {
        display: flex;
        animation: fadeIn 0.3s ease-out;
    }

.modal-card {
    background: #262421;
    border: 2px solid #81b64c;
    border-radius: 12px;
    padding: 28px 36px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
    max-width: 340px;
    width: 90%;
    position: relative;
    z-index: 1002;
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.trophy {
    font-size: 56px;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 10px rgba(255, 215, 0, 0.4));
}

.modal-title {
    font-size: 24px;
    font-weight: 800;
    margin: 0 0 6px 0;
    color: #fff;
}

.modal-subtitle {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 18px;
}

.podium {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 22px;
}

.podium-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #302e2b;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 15px;
}

    .podium-row.first {
        background: rgba(129, 182, 76, 0.25);
        border: 1px solid #81b64c;
        font-size: 17px;
    }

/* Холст для салютов */
#fireworks-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1001;
}

@keyframes popIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Оверлей со стрелками направления перед стартом игры */
#start-arrows {
    position: absolute;
    /* Центрируем ровно по центру доски 14x14 (занимает центральные 6x6 клеток) */
    top: calc(var(--sq) * 4 + 10px);
    left: calc(var(--sq) * 4 + 10px);
    width: calc(var(--sq) * 6);
    height: calc(var(--sq) * 6);
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.3s ease;
}

    #start-arrows.hidden {
        opacity: 0;
    }

/* Координаты на клетках в стиле Chess.com */
.coord-rank, .coord-file {
    position: absolute;
    font-size: calc(var(--sq) * 0.22);
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}

/* Цифры — в левом верхнем углу клетки */
.coord-rank {
    top: 2px;
    left: 3px;
}

/* Буквы — в правом нижнем углу клетки */
.coord-file {
    bottom: 2px;
    right: 3px;
}

/* Инверсия цвета шрифта как на Chess.com: темный текст на светлой клетке и наоборот */
.cell.light .coord-rank,
.cell.light .coord-file {
    color: var(--dark-sq);
}

.cell.dark .coord-rank,
.cell.dark .coord-file {
    color: var(--light-sq);
}

/* Кнопка закрытия (крестик) в модальном окне */
.modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    color: #999;
    font-size: 26px;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
}

    .modal-close:hover {
        background: transparent;
        color: #fff;
        transform: scale(1.15);
    }

/* Убираем синюю подсветку при тапе на мобильных экранах */
* {
    -webkit-tap-highlight-color: transparent;
}

/* --- АДАПТИВНОСТЬ ДЛЯ СМАРТФОНОВ И ПЛАНШЕТОВ (ПОРТРЕТ) --- */
@media (max-width: 900px) and (orientation: portrait) {
    body {
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        padding: 0 0 24px 0;
        gap: 10px;
        overflow-x: hidden;
    }

    :root {
        --sq: calc(100vw / 14);
    }

    #board-container {
        padding: 0;
        border-radius: 0;
        width: 100vw;
        box-sizing: border-box;
    }

    .piece {
        width: calc(var(--sq) * 0.94);
        height: calc(var(--sq) * 0.94);
    }

    .hint::after {
        width: calc(var(--sq) * 0.38);
        height: calc(var(--sq) * 0.38);
    }

    .hint-capture::after {
        width: calc(var(--sq) * 0.9);
        height: calc(var(--sq) * 0.9);
    }

    #sidebar {
        width: calc(100vw - 16px);
        max-width: 100%;
        padding: 14px;
        box-sizing: border-box;
        gap: 12px;
    }

    h2 {
        font-size: 18px;
    }

    button, select {
        padding: 12px;
        font-size: 15px;
    }

    .corner-hud {
        padding: 2px;
    }

    .hud-box {
        padding: 3px 4px;
        gap: 2px;
        border-radius: 4px;
    }

    .hud-top {
        font-size: calc(var(--sq) * 0.34);
    }

    .hud-timer {
        font-size: calc(var(--sq) * 0.46);
        padding: 1px 0;
    }

    .coord-rank, .coord-file {
        display: none;
    }
}

/* --- АДАПТИВНОСТЬ ДЛЯ ТЕЛЕФОНОВ/ПЛАНШЕТОВ (ГОРИЗОНТАЛЬНО) --- */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 4px;
        gap: 10px;
    }

    :root {
        --sq: min(6.8vh, 5.2vw);
    }

    #board-container {
        width: auto;
        padding: 4px;
        border-radius: 6px;
    }

    #sidebar {
        width: 240px;
        max-height: 94vh;
        overflow-y: auto;
    }
}