/*
 * УНИ «Шахматы» — оформление.
 *
 * Тёмная палитра раздела «Игры» (как у лобби UNO) плюс классические
 * «деревянные» цвета доски: так фигуры читаются и на светлой, и на тёмной
 * клетке. Раскладка — CSS Grid и Flexbox, на узких экранах колонки
 * складываются в одну.
 */

:root {
    --bg: #0b1019;
    --panel: #131a26;
    --panel-2: #182233;
    --line: #24303f;
    --ink: #eef2ff;
    --muted: #8a97ab;
    --gold: #f5af42;
    --green: #20a05c;
    --blue: #2f8bff;
    --red: #ff6b6b;

    --light-sq: #ead9b0;
    --dark-sq: #997148;
    --board-edge: #6f4f2c;

    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(120% 90% at 20% 0%, #16233a 0%, var(--bg) 55%, #070d16 100%);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 1240px;
    margin: 0 auto;
    padding: 14px 16px 28px;
}

/* ------------------------------------------------------------------ шапка */

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 12px;
}

.brand { display: flex; align-items: baseline; gap: 8px; }

.brand-mark {
    font-weight: 900;
    font-size: 20px;
    letter-spacing: .5px;
    color: var(--green);
}

.brand-name { font-size: 17px; font-weight: 700; }

.topbar-status {
    margin-left: auto;
    font-size: 13px;
    color: var(--muted);
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(19, 26, 38, .7);
}

/* ---------------------------------------------------------------- каркас */

.layout {
    display: grid;
    /* minmax(0, …) — чтобы доска могла сужаться: иначе широкий элемент
       растягивает колонку и страница уезжает вправо на телефоне */
    grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
    gap: 18px;
    align-items: start;
}

.board-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
}

/* ---------------------------------------------------------------- часы */

.clockbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.clockbar.is-active { border-color: var(--green); box-shadow: 0 0 0 1px rgba(32, 160, 92, .35) inset; }

.clockbar.is-low .clock { color: var(--red); }

.player { display: flex; align-items: center; gap: 8px; min-width: 0; }

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #56637a;
    flex: 0 0 auto;
}

.player-dot.is-white { background: #f2f5fa; border: 1px solid #9aa7bb; }
.player-dot.is-black { background: #1b2534; border: 1px solid #4a5a72; }

.player-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clock {
    margin-left: auto;
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: .5px;
}

.clock.is-hidden { display: none; }

/* ---------------------------------------------------------------- доска */

.board {
    width: 100%;
    display: flex;
    justify-content: center;
}

/*
 * Доска — квадрат: с одной стороны её ограничивает ширина колонки, с другой —
 * высота окна (иначе на ноутбуке нижние часы уезжают за экран).
 */
.board-wrap {
    display: grid;
    grid-template-columns: 18px 1fr;
    grid-template-rows: 1fr 18px;
    gap: 4px;
    width: 100%;
    max-width: calc(100vh - 250px);
    margin: 0 auto;
    padding: 10px;
    border-radius: 18px;
    background: linear-gradient(160deg, #2a2116, #171008);
    border: 1px solid #3b2f1f;
    box-shadow: 0 20px 45px rgba(0, 0, 0, .5);
}

.board-ranks,
.board-files {
    display: flex;
    color: #a98b62;
    font-size: 10px;
    font-weight: 700;
    user-select: none;
}

.board-ranks { flex-direction: column; justify-content: space-around; align-items: center; }
.board-files { grid-column: 2; flex-direction: row; justify-content: space-around; align-items: center; }

.board-main {
    position: relative;
    grid-column: 2;
    grid-row: 1;
    aspect-ratio: 1 / 1;
    width: 100%;
    touch-action: none;
    user-select: none;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px var(--board-edge);
}

.board-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

.board-defs { position: absolute; width: 0; height: 0; }

.sq { position: relative; }

.sq--light { background: var(--light-sq); }
.sq--dark { background: var(--dark-sq); }

/* Последний ход подсвечиваем мягко, чтобы не мешать чтению позиции */
.sq--last { box-shadow: inset 0 0 0 100px rgba(245, 175, 66, .22); }

.sq--selected { box-shadow: inset 0 0 0 3px var(--gold); }

/* Возможные ходы: точка в центре, взятие — кольцо */
.sq--target::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 26%;
    height: 26%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(20, 30, 45, .32);
}

.sq--capture::after {
    content: '';
    position: absolute;
    inset: 6%;
    border-radius: 50%;
    border: 3px solid rgba(180, 40, 40, .55);
}

.sq--hover { box-shadow: inset 0 0 0 3px rgba(47, 139, 255, .85); }

/* Шах: красное свечение вокруг короля */
.sq--check { box-shadow: inset 0 0 0 100px rgba(200, 40, 40, .35); }

.board-pieces {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Фигура занимает 1/8 доски; позиция задаётся transform — так работает анимация */
.piece-holder {
    position: absolute;
    left: 0;
    top: 0;
    width: 12.5%;
    height: 12.5%;
    transition: transform .22s cubic-bezier(.22, .61, .36, 1), opacity .18s ease;
    will-change: transform;
}

.piece-holder--instant { transition: none; }
.piece-holder--dragging { transition: none; z-index: 5; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .55)); }
.piece-holder--captured { opacity: 0; transform: scale(.6) !important; }

.piece-box {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5%;
}

.piece { width: 100%; height: 100%; display: block; }

.board-overlay { position: absolute; inset: 0; pointer-events: none; }

.board-state { display: none; }

/* ---------------------------------------------------------------- кнопки */

.board-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 11px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--ink);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .08s ease;
}

.btn:hover { border-color: #3a4a62; }
.btn:active { transform: translateY(1px); }

.btn--primary {
    background: linear-gradient(180deg, #24b268, var(--green));
    border-color: #1c8b4f;
    color: #04120a;
    font-weight: 800;
}

.btn--small { font-size: 12px; padding: 7px 11px; }

.btn[disabled] { opacity: .45; cursor: not-allowed; }

.btn--ghost { background: transparent; }

/* ---------------------------------------------------------------- панель */

.side {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    min-height: 320px;
}

.side-head { display: flex; flex-direction: column; gap: 4px; }

.status { font-size: 15px; font-weight: 700; }
.status--check { color: var(--red); }
.status--over { color: var(--gold); }

.opening { font-size: 12px; color: var(--muted); min-height: 16px; }

.tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
}

.tab {
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}

.tab.is-active {
    background: rgba(32, 160, 92, .16);
    border-color: #2b6b43;
    color: #74e2a6;
}

.panel { display: none; flex-direction: column; gap: 12px; }
.panel.is-active { display: flex; }

.panel-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-2);
}

.panel-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
}

.panel-hint { font-size: 11px; font-weight: 500; color: var(--muted); }

.muted { font-size: 12px; line-height: 1.45; color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- ходы */

.moves {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-variant-numeric: tabular-nums;
    max-height: 220px;
    overflow-y: auto;
}

.moves li {
    display: flex;
    gap: 6px;
    font-size: 13px;
    padding: 3px 6px;
    border-radius: 7px;
}

.moves li:nth-child(4n + 1),
.moves li:nth-child(4n + 2) { background: rgba(255, 255, 255, .03); }

.moves .num { color: var(--muted); min-width: 22px; }
.moves .san { font-weight: 600; }

.moves .tag {
    font-size: 11px;
    font-weight: 800;
    padding: 0 4px;
    border-radius: 5px;
}

.tag--best { color: #74e2a6; background: rgba(32, 160, 92, .18); }
.tag--good { color: #9fd3ff; background: rgba(47, 139, 255, .16); }
.tag--inaccuracy { color: #ffd479; background: rgba(245, 175, 66, .18); }
.tag--mistake { color: #ffa07a; background: rgba(255, 132, 82, .18); }
.tag--blunder { color: #ff8a8a; background: rgba(255, 107, 107, .2); }

/* ---------------------------------------------------------------- формы */

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row--center { justify-content: center; }

.textarea,
.select {
    font: inherit;
    font-size: 12px;
    width: 100%;
    padding: 9px 10px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #0f1724;
    color: var(--ink);
    resize: vertical;
}

.textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field--check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }

.field--check input { width: 16px; height: 16px; accent-color: var(--green); }

.keys { margin: 0; padding-left: 18px; font-size: 12px; color: var(--muted); line-height: 1.7; }
.keys b { color: var(--ink); }

/* ---------------------------------------------------------------- разбор */

.progress {
    height: 6px;
    border-radius: 999px;
    background: #0f1724;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--green), #7fd4ff);
    transition: width .15s linear;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #0f1724;
}

.chart {
    width: 100%;
    height: 90px;
    border-radius: 10px;
    background: #0f1724;
    border: 1px solid var(--line);
}

.patterns { margin: 0; padding-left: 16px; font-size: 12px; color: var(--muted); line-height: 1.6; }

.review-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 260px;
    overflow-y: auto;
}

.review-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 7px;
    background: rgba(255, 255, 255, .03);
}

.review-list .num { color: var(--muted); min-width: 24px; font-variant-numeric: tabular-nums; }
.review-list .loss { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.review-list .best { color: #74e2a6; }

/* ---------------------------------------------------------------- турнир */

.standings {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.standings th,
.standings td {
    padding: 5px 6px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.standings th { color: var(--muted); font-weight: 600; }
.standings td:last-child,
.standings th:last-child { text-align: right; }

.rounds { display: flex; flex-direction: column; gap: 10px; max-height: 300px; overflow-y: auto; }

.round-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.pairing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 9px;
    background: #0f1724;
    font-size: 12px;
}

.pairing .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pairing .result {
    font-weight: 800;
    color: var(--gold);
    min-width: 42px;
    text-align: center;
}

.pairing .btn { padding: 4px 8px; font-size: 11px; }

.online-status {
    font-size: 12px;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #0f1724;
    color: var(--muted);
}

.online-status.is-ok { color: #74e2a6; border-color: #2b6b43; }
.online-status.is-error { color: #ff8a8a; border-color: #6b2b2b; }

/* ---------------------------------------------------------------- модалки */

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 12, 21, .82);
    padding: 20px;
    z-index: 30;
}

.modal[hidden] { display: none; }

.modal-box {
    width: min(360px, 92vw);
    padding: 20px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .65);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-title { font-size: 17px; font-weight: 800; text-align: center; }

.promotion { display: flex; gap: 8px; justify-content: center; }

.promotion button {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    cursor: pointer;
    padding: 6px;
}

.promotion button:hover { border-color: var(--gold); }
.promotion svg { width: 100%; height: 100%; }

/* ---------------------------------------------------------------- адаптив */

@media (max-width: 900px) {
    .app { padding: 10px 10px 22px; }

    .layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    /* На телефоне доску ограничивает ширина, а не высота окна */
    .board-wrap { max-width: 100%; }

    .topbar-status { display: none; }

    .clock { font-size: 19px; }

    .board-wrap { padding: 8px; }

    .moves { max-height: 150px; }

    .side { min-height: 0; }
}

@media (max-width: 420px) {
    .player-name { font-size: 13px; }
    .board-actions .btn { flex: 1 1 calc(50% - 8px); }
}
