/* Three-Player Chess Arena — Base Styles */
:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface2: #0f3460;
    --accent: #e94560;
    --text: #eee;
    --text-muted: #999;
    --light-cell: #F0D9B5;
    --dark-cell: #B58863;
    --highlight: rgba(255, 255, 80, 0.45);
    --check-color: rgba(255, 0, 0, 0.4);
    --white-piece: #fff;
    --black-piece: #222;
    --red-piece: #d32f2f;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
    background: var(--surface);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

header h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

header nav a {
    margin-left: 20px;
    color: var(--text-muted);
    font-size: .9rem;
}

header nav a:hover { color: var(--text); }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Lobby ─────────────────────────────────────── */
.lobby-title {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.game-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    border: 1px solid rgba(255,255,255,.06);
}

.game-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

.game-card .status {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 8px;
}

.status-waiting { background: #f59e0b; color: #000; }
.status-playing { background: #10b981; color: #000; }
.status-finished { background: var(--text-muted); color: #000; }

.game-card .meta {
    font-size: .85rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.players-list {
    list-style: none;
    margin-top: 8px;
}

.players-list li {
    font-size: .85rem;
    padding: 2px 0;
}

.player-color {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.player-color-white { background: #fff; border: 1px solid #ccc; }
.player-color-black { background: #333; }
.player-color-red { background: #d32f2f; }

.no-games {
    color: var(--text-muted);
    font-style: italic;
    padding: 32px 0;
    text-align: center;
}

/* ── Game Page ─────────────────────────────────── */
.game-container {
    max-width: none;
    padding: 16px 24px;
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    align-items: start;
}

.board-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Квадрат, занимающий доступную высоту вьюпорта */
    width: min(calc(100vw - 360px), calc(100vh - 80px));
    height: min(calc(100vw - 360px), calc(100vh - 80px));
    position: sticky;
    top: 16px;
}

.board-container svg {
    width: 100%;
    height: 100%;
    display: block;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid rgba(255,255,255,.06);
}

.panel h3 {
    font-size: .95rem;
    margin-bottom: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: .85rem;
}

.info-label { color: var(--text-muted); }

/* ── Move Log ──────────────────────────────────── */
.move-log {
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: .8rem;
    line-height: 1.6;
}

.move-log-entry { padding: 2px 0; }
.move-log-entry .move-num { color: var(--text-muted); margin-right: 8px; }

/* ── Connection status ─────────────────────────── */
.ws-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.ws-connected { background: #10b981; }
.ws-disconnected { background: var(--accent); }

/* ── Docs / Rules Pages ───────────────────────── */
.docs-page h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.docs-page .panel { margin-bottom: 16px; }
.docs-page .panel p { font-size: .9rem; line-height: 1.6; margin-bottom: 8px; }
.docs-page .panel ul, .docs-page .panel ol { font-size: .9rem; line-height: 1.6; padding-left: 20px; margin-bottom: 8px; }
.docs-page .panel li { margin-bottom: 4px; }

.rules-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin: 8px 0; }
.rules-table th, .rules-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.08); }
.rules-table th { color: var(--text-muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .05em; }

.docs-page pre { background: var(--bg); border-radius: 4px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.docs-page code { font-family: 'Consolas', 'Courier New', monospace; font-size: .82rem; color: var(--text); }

.method-badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 4px; margin-right: 8px; vertical-align: middle; }
.method-get { background: #10b981; color: #000; }
.method-post { background: #3b82f6; color: #fff; }

header nav a.active, header nav a[href]:where(:target) { color: var(--text); }

/* ── Buttons ──────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-join {
    background: #10b981;
    color: #000;
}

.btn-join:hover { background: #059669; }

.btn-skip {
    background: #f59e0b;
    color: #000;
    width: 100%;
    margin-top: 16px;
}

.btn-skip:hover { background: #d97706; }

.btn-resign {
    background: var(--accent);
    color: #fff;
    width: 100%;
}

.btn-resign:hover { background: #c73650; }

/* ── Lobby header ────────────────────────────── */
.lobby-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.join-status {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: .9rem;
}

.join-error {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
    border: 1px solid rgba(233, 69, 96, 0.3);
}

/* ── Waiting overlay ─────────────────────────── */
.waiting-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(26, 26, 46, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
}

.waiting-card {
    background: var(--surface);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 16px;
    padding: 40px 48px;
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.waiting-card h2 {
    font-size: 1.4rem;
    margin-bottom: 16px;
}

.waiting-info {
    font-size: 1rem;
    margin-bottom: 12px;
}

.player-color-badge {
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 4px;
}

.color-white { background: #fff; color: #000; }
.color-black { background: #333; color: #fff; }
.color-red { background: #d32f2f; color: #fff; }

.waiting-players {
    margin: 12px 0;
    font-size: .9rem;
    color: var(--text-muted);
}

.waiting-timer {
    font-size: 1.1rem;
    margin-top: 12px;
    color: var(--text-muted);
}

.waiting-timer span {
    font-weight: 700;
    color: #f59e0b;
    font-size: 1.3rem;
}

/* ── Turn banner ─────────────────────────────── */
.turn-banner {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-weight: 700;
    text-align: center;
    font-size: .95rem;
}

.turn-banner-active {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.turn-banner-waiting {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.turn-banner-win {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.4);
    font-size: 1.1rem;
}

.turn-banner-loss {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
    border: 1px solid rgba(233, 69, 96, 0.3);
}

.turn-banner-draw {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ── Board highlights (SVG) ──────────────────── */
.cell-selected {
    fill: rgba(100, 200, 255, 0.35);
    stroke: rgba(100, 200, 255, 0.7);
    stroke-width: 2;
}

.cell-target {
    fill: rgba(100, 255, 100, 0.3);
    stroke: rgba(100, 255, 100, 0.6);
    stroke-width: 2;
    cursor: pointer;
}

.cell-highlight {
    fill: rgba(255, 255, 80, 0.3);
    stroke: rgba(255, 255, 80, 0.6);
    stroke-width: 1.5;
}

/* ── Piece Style & Labels Panel ───────────────── */
.piece-style-panel .style-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    gap: 8px;
}

.style-label {
    font-size: .8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.style-select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: .8rem;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.style-select:focus {
    outline: none;
    border-color: var(--accent);
}

.style-range {
    flex: 1;
    min-width: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Toggle switch */
.style-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.style-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.style-toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.15);
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.style-toggle-slider::before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.style-toggle input:checked + .style-toggle-slider {
    background: var(--accent);
}

.style-toggle input:checked + .style-toggle-slider::before {
    transform: translateX(16px);
    background: #fff;
}

/* ── Label mode buttons ────────────────────────── */
.style-divider {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: 6px 0;
}

.style-label-btns {
    display: flex;
    gap: 4px;
    margin-top: 2px;
}

.label-btn {
    flex: 1;
    padding: 4px 2px;
    font-size: .72rem;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.label-btn:hover {
    background: rgba(255,255,255,.07);
    color: var(--text);
}

.label-btn-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 900px) {
    .game-layout {
        grid-template-columns: 1fr;
    }
    .board-container {
        width: min(calc(100vw - 48px), calc(100vh - 200px));
        height: min(calc(100vw - 48px), calc(100vh - 200px));
        position: static;
        margin: 0 auto;
    }
    .lobby-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
}
