/* ============================================================
   modules/chess/chess.css – онлайн-шахматы с другом
   ============================================================ */

.chess-app {
    width: 100%;
    box-sizing: border-box;
}

/* ---------- Стартовый экран ---------- */
.chess-start-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    text-align: center;
    padding: 20px;
}
.chess-start-inner {
    /* ширина под две кнопки в ряд; на узком экране они переносятся */
    max-width: 720px;
}
.chess-start-icon {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 10px;
}
.chess-start-title {
    font-weight: 700;
    margin-bottom: 10px;
}
.chess-start-text {
    color: #666;
    margin-bottom: 20px;
}
.chess-guest-name-wrap {
    max-width: 320px;
    margin: 0 auto 14px;
}
.chess-play-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}
.chess-play-btn {
    padding: 12px 28px;
    font-size: 1.1rem;
    border-radius: 30px;
}

/* ---------- Поиск соперника ---------- */
.chess-search-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    text-align: center;
    padding: 20px;
}
.chess-search-inner {
    max-width: 420px;
}
.chess-search-radar {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Расходящиеся круги — «идёт поиск» */
.chess-search-radar::before,
.chess-search-radar::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(13, 110, 253, 0.55);
    animation: chess-radar 2s ease-out infinite;
}
.chess-search-radar::after {
    animation-delay: 1s;
}
@keyframes chess-radar {
    0%   { transform: scale(0.35); opacity: 1; }
    100% { transform: scale(1);    opacity: 0; }
}
.chess-search-piece {
    position: relative;
    font-size: 3.2rem;
    line-height: 1;
    animation: chess-search-bob 1.6s ease-in-out infinite;
}
@keyframes chess-search-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
.chess-search-title {
    font-weight: 700;
    margin-bottom: 6px;
}
.chess-search-timer {
    font-family: 'Courier New', monospace;
    font-size: 1.3rem;
    color: #888;
    margin-bottom: 20px;
}
.chess-search-found {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 4px 0 20px;
}
.chess-search-error {
    color: #888;
    margin: 4px 0 20px;
}
/* Соперник найден / ошибка — круги останавливаются */
.chess-search-done .chess-search-radar::before,
.chess-search-done .chess-search-radar::after,
.chess-search-failed .chess-search-radar::before,
.chess-search-failed .chess-search-radar::after {
    animation: none;
    opacity: 0;
}
.chess-search-done .chess-search-radar::before {
    opacity: 1;
    transform: none;
    border-color: #28a745;
}
.chess-search-done .chess-search-piece,
.chess-search-failed .chess-search-piece {
    animation: none;
}

/* ---------- Настройки (подсказки / способ хода) ---------- */
.chess-settings {
    margin-top: 18px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    text-align: left;
}
.chess-settings-ingame {
    margin-top: 0;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e5e5e5;
}
.chess-setting-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 160px;
    min-width: 0;
}
.chess-setting-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.chess-setting-select {
    font-size: 0.9rem;
    padding: 6px 10px;
}
.chess-setting-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #eee;
}

/* ---------- Приглашение / ожидание ---------- */
.chess-invite-box {
    max-width: 100%;
    margin: 30px 0;
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-sizing: border-box;
    text-align: center;
}
.chess-invite-label {
    font-weight: 600;
    margin-bottom: 10px;
}
.chess-invite-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}
.chess-invite-input {
    font-family: monospace;
    font-size: 0.85rem;
    height: 40px;
    box-sizing: border-box;
}
.chess-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}
/* Кнопка копирования ссылки должна быть строго по высоте инпута рядом с ней
   (у сохранённой в общем .chess-icon-btn кнопки звука своя высота от btn-sm —
   поэтому фиксируем высоту точечно, только в паре с полем ссылки). */
.chess-invite-row .chess-icon-btn {
    height: 40px;
    box-sizing: border-box;
}
.chess-icon-btn.chess-copied {
    color: #fff;
    background-color: #28a745;
    border-color: #28a745;
}
.chess-invite-waiting {
    margin-top: 14px;
    color: #888;
    font-style: italic;
    animation: chess-waiting-pulse 1.8s ease-in-out infinite;
}
.chess-invite-waiting::after {
    content: '';
    display: inline-block;
    width: 10px;
    text-align: left;
    animation: chess-dots 1.4s steps(4, end) infinite;
}
@keyframes chess-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}
@keyframes chess-waiting-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.chess-join-box {
    max-width: 420px;
    margin: 40px auto;
    padding: 24px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    text-align: center;
}
.chess-join-text {
    font-weight: 600;
    margin-bottom: 14px;
}

/* ---------- Основной layout партии ---------- */
.chess-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    padding: 10px 0 30px;
}

.chess-board-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(90vw, 520px);
}

.chess-player {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 480px;
    padding: 6px 4px;
    font-weight: 600;
}
.chess-player-name::before {
    content: '●';
    margin-right: 6px;
    color: #ccc;
    font-size: 0.7em;
}
.chess-player.chess-turn .chess-player-name::before {
    color: #28a745;
}

.chess-board-wrap {
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1 / 1;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border: 3px solid #4a3728;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(0,0,0,0.18);
    user-select: none;
}

.chess-square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(7.5vw, 40px);
    line-height: 1;
    cursor: default;
}
.chess-square.chess-light { background: #f0d9b5; }
.chess-square.chess-dark  { background: #b58863; }
.chess-square.chess-interactive { cursor: pointer; }

.chess-square.chess-selected {
    box-shadow: inset 0 0 0 3px rgba(13, 110, 253, 0.85);
}
.chess-square.chess-last-move {
    background-color: rgba(255, 235, 59, 0.55) !important;
}
.chess-square.chess-check {
    background-color: rgba(220, 53, 69, 0.55) !important;
}

.chess-square .chess-move-dot {
    position: absolute;
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background: rgba(13, 110, 253, 0.55);
    pointer-events: none;
}
.chess-square .chess-move-dot.chess-capture-dot {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: transparent;
    box-shadow: inset 0 0 0 5px rgba(13, 110, 253, 0.55);
}

.chess-piece {
    pointer-events: none;
}
.chess-piece.chess-piece-white { color: #fff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,0.5); }
.chess-piece.chess-piece-black { color: #111; text-shadow: 0 1px 1px rgba(255,255,255,0.15); }

/* ---------- Перетаскивание фигур ---------- */
.chess-square.chess-draggable { cursor: grab; }
.chess-board.chess-drag-mode { touch-action: none; }
.chess-square.chess-drop-hover {
    box-shadow: inset 0 0 0 3px rgba(40, 167, 69, 0.85);
}
.chess-piece-ghost {
    position: fixed;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 9999;
    opacity: 0.92;
}

.chess-coord {
    position: absolute;
    font-size: 0.6rem;
    font-weight: 700;
    opacity: 0.55;
    pointer-events: none;
}
.chess-coord.chess-coord-file { bottom: 2px; right: 3px; }
.chess-coord.chess-coord-rank { top: 2px; left: 3px; }
.chess-square.chess-light .chess-coord { color: #b58863; }
.chess-square.chess-dark  .chess-coord { color: #f0d9b5; }

.chess-status {
    margin-top: 12px;
    min-height: 1.4em;
    font-weight: 600;
    text-align: center;
}
.chess-status.chess-status-your-turn { color: #28a745; }
.chess-status.chess-status-check { color: #dc3545; }
.chess-status.chess-status-over { color: #0d6efd; }
.chess-status.chess-status-left { color: #b8860b; }

.chess-controls {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chess-guest-note {
    margin-top: 8px;
    max-width: 320px;
    font-size: 0.78rem;
    line-height: 1.35;
    color: #888;
    text-align: center;
}

/* ---------- Боковая панель (роль + история ходов) ---------- */
.chess-side-col {
    width: 220px;
    max-width: 90vw;
    /* сдвигаем панель вниз, чтобы её верх был на одном уровне с началом
       доски, а не с именем игрока над доской; высоту (чтобы нижняя граница
       совпадала с нижним краем доски) выставляет JS — syncSideColHeight() */
    margin-top: 34px;
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 14px;
    max-height: 560px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}
.chess-side-title {
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #555;
}
.chess-moves-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}
.chess-moves-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    flex: 1;
}
.chess-moves-list li {
    padding: 2px 0;
    display: flex;
    gap: 6px;
}
.chess-moves-list .chess-move-num {
    color: #999;
    min-width: 24px;
}
/* Последний ход в списке: клик показывает на доске последний ход соперника (replayMove в chess.js) */
.chess-moves-list .chess-move-replay {
    cursor: pointer;
    text-decoration: underline dashed;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}
.chess-moves-list .chess-move-replay:hover,
.chess-moves-list .chess-move-replay:focus-visible {
    color: #0d6efd;
    outline: none;
}

/* ---------- Показ хода анимацией ---------- */
.chess-board.chess-replaying {
    pointer-events: none;
}
/* 0.45s — то же, что REPLAY_SLIDE_MS в chess.js */
.chess-board.chess-replaying .chess-piece {
    transition: transform 0.45s ease-in-out, opacity 0.45s ease-in-out;
}
.chess-board.chess-replaying .chess-piece-sliding {
    position: relative;
    z-index: 3;
}
.chess-board.chess-replaying .chess-piece-captured {
    opacity: 0;
}

/* ---------- Модалка выбора фигуры при превращении ---------- */
.chess-promo-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chess-promo-inner {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.chess-promo-title {
    font-weight: 600;
    margin-bottom: 12px;
}
.chess-promo-pieces {
    display: flex;
    gap: 10px;
}
.chess-promo-pieces button {
    width: 56px;
    height: 56px;
    font-size: 2rem;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #f8f9fa;
    cursor: pointer;
    transition: background 0.15s;
}
.chess-promo-pieces button:hover {
    background: #e9ecef;
}

/* ---------- Тёмная тема ---------- */
body.theme-dark .chess-start-text { color: #aaa; }
body.theme-dark .chess-search-timer,
body.theme-dark .chess-search-error { color: #aaa; }
body.theme-dark .chess-invite-box,
body.theme-dark .chess-join-box,
body.theme-dark .chess-side-col {
    background: #2a2a2a;
    border-color: #3a3a3a;
    color: #eee;
}
body.theme-dark .chess-side-title { color: #bbb; }
body.theme-dark .chess-moves-list .chess-move-replay:hover,
body.theme-dark .chess-moves-list .chess-move-replay:focus-visible { color: #6ea8fe; }
body.theme-dark .chess-guest-note { color: #999; }
body.theme-dark .chess-settings-ingame { border-bottom-color: #3a3a3a; }
body.theme-dark .chess-setting-label { color: #999; }
body.theme-dark .chess-promo-inner { background: #2a2a2a; color: #eee; }
body.theme-dark .chess-promo-pieces button { background: #333; border-color: #444; color: #eee; }

@media (max-width: 560px) {
    /* кнопки старта — во всю ширину, чтобы длинная надпись не ломалась в две строки */
    .chess-play-btn { width: 100%; padding: 12px 16px; font-size: 1rem; }
    .chess-side-col { width: 100%; height: auto !important; max-height: 340px; margin-top: 0; }
    .chess-layout { padding: 4px 0 20px; }
}
