/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-dark:       #0d0d0d;
    --bg-panel:      #141414;
    --bg-card:       #1c1c1c;
    --border:        #2e2e2e;
    --border-bright: #4a4a4a;
    --gold:          #c9a84c;
    --gold-light:    #e8c97a;
    --gold-dim:      #6b5428;
    --red:           #c0392b;
    --blue:          #2980b9;
    --yellow:        #d4ac0d;
    --green:         #27ae60;
    --text-primary:  #e8dcc8;
    --text-muted:    #7a6f60;
    --shadow:        0 8px 32px rgba(0,0,0,0.6);
}

body {
    background: var(--bg-dark);
    min-height: 100vh;
    font-family: 'Crimson Text', Georgia, serif;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* ─── Background Texture ────────────────────────────────────── */
.bg-texture {
    position: fixed; inset: 0; pointer-events: none; z-index: 0;
    background:
            radial-gradient(ellipse at 20% 50%, rgba(201,168,76,0.04) 0%, transparent 60%),
            radial-gradient(ellipse at 80% 20%, rgba(192,57,43,0.04) 0%, transparent 60%),
            repeating-linear-gradient(
                    45deg,
                    transparent,
                    transparent 40px,
                    rgba(255,255,255,0.005) 40px,
                    rgba(255,255,255,0.005) 41px
            );
}

/* ─── Turn Notification Overlay ─────────────────────────────── */
#uved {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cinzel', serif;
    font-size: clamp(3rem, 10vw, 8rem);
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 0 60px rgba(201,168,76,0.6), 0 0 120px rgba(201,168,76,0.2);
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    letter-spacing: 0.15em;
    transition: opacity 0.5s ease;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
}

/* ─── Layout ─────────────────────────────────────────────────── */
.game-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
    gap: 24px;
}

.game-header { text-align: center; }

.game-title {
    font-family: 'Cinzel', serif;
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.25em;
    text-shadow: 0 0 20px rgba(201,168,76,0.3);
}

.game-subtitle {
    font-style: italic;
    color: var(--text-muted);
    font-size: 1rem;
    letter-spacing: 0.15em;
    margin-top: 4px;
}

.game-container {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    width: 100%;
    max-width: 900px;
    justify-content: center;
}

/* ─── Side Panels ────────────────────────────────────────────── */
.side-panel {
    width: 170px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 14px;
    box-shadow: var(--shadow);
}

.panel-title {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    color: var(--gold-dim);
    text-transform: uppercase;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ─── Player Cards ───────────────────────────────────────────── */
#player-panel { display: flex; flex-direction: column; gap: 8px; }

.player-card {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: border-color 0.25s, background 0.25s;
    font-size: 0.9rem;
}
.player-card.active {
    border-color: var(--gold-dim);
    background: #1f1a0e;
}
.player-card.me { color: var(--gold-light); }

.player-dot {
    width: 13px; height: 13px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

.player-name { flex: 1; font-size: 0.85rem; line-height: 1.2; }
.me-badge {
    font-size: 0.65rem;
    color: var(--gold-dim);
    font-style: italic;
    display: block;
}

.turn-badge {
    font-size: 0.65rem;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(201,168,76,0.15);
    color: var(--gold);
    border: 1px solid var(--gold-dim);
    white-space: nowrap;
}

/* ─── Board ──────────────────────────────────────────────────── */
.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.board-frame {
    padding: 10px;
    background: #111;
    border: 2px solid var(--gold-dim);
    border-radius: 14px;
    box-shadow:
            var(--shadow),
            inset 0 0 30px rgba(0,0,0,0.5),
            0 0 0 4px #0d0d0d,
            0 0 0 5px #2a2014;
}

#grid {
    display: grid;
    grid-template-columns: repeat(3, 160px);
    grid-template-rows:    repeat(3, 160px);
    gap: 6px;
}

/* ─── Tiles ──────────────────────────────────────────────────── */
.item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}
.item:hover { transform: scale(1.04); }

/* Тип 1 — Облака/Вода */
.tile-1 { border-color: #1e3a5f; }
.tile-1 .cards { filter: brightness(0.8) saturate(1.2); }

/* Тип 2 — Трава */
.tile-2 { border-color: #1a3a1a; }
.tile-2 .cards { filter: brightness(0.85) saturate(1.3); }

/* Тип 3 — Клад */
.tile-3 { border-color: #3a2a0a; }
.tile-3 .cards { filter: brightness(0.9) sepia(0.2) saturate(1.4); }

/* Подсветка доступных ходов */
.item.can-move {
    border-color: var(--gold) !important;
    box-shadow: 0 0 14px rgba(201,168,76,0.55), inset 0 0 10px rgba(201,168,76,0.1);
    cursor: crosshair;
}
.item.can-move::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(201,168,76,0.08);
    animation: pulse-tile 1.2s ease-in-out infinite;
    pointer-events: none;
    border-radius: 6px;
}
@keyframes pulse-tile {
    0%, 100% { opacity: 0; }
    50%       { opacity: 1; }
}

.item .cards {
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    border-radius: 6px;
}

/* Метка типа тайла */
.tile-label {
    position: absolute;
    top: 5px; left: 6px;
    font-size: 10px;
    font-family: 'Cinzel', serif;
    color: rgba(255,255,255,0.55);
    letter-spacing: 0.05em;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* ─── Pieces Layer ───────────────────────────────────────────── */
.pieces-layer {
    position: absolute;
    inset: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 6px;
    gap: 4px;
    pointer-events: none;
    border-radius: 6px;
}

.piece {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 2.5px solid rgba(255,255,255,0.5);
    box-shadow: 0 2px 8px rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: transform 0.3s;
    position: relative;
}
.piece.my-piece {
    border-color: rgba(255,255,255,0.9);
    box-shadow: 0 0 10px rgba(255,255,255,0.4), 0 2px 8px rgba(0,0,0,0.6);
}
.piece::after {
    content: "";
    position: absolute;
    top: 3px; left: 50%;
    transform: translateX(-50%);
    width: 6px; height: 6px;
    background: rgba(255,255,255,0.4);
    border-radius: 50%;
}

/* ─── Event Log ──────────────────────────────────────────────── */
#event-log {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 360px;
    overflow-y: auto;
}

.log-entry {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}
.log-entry b { color: var(--text-primary); }
.log-entry.log-move b { color: var(--gold-light); }
.log-entry.log-turn b { color: var(--gold); }

/* ─── Board Hint ─────────────────────────────────────────────── */
.board-hint {
    font-size: 0.85rem;
    font-style: italic;
    color: var(--text-muted);
    text-align: center;
    letter-spacing: 0.05em;
    min-height: 1.2em;
    transition: color 0.3s;
}
.board-hint.my-turn { color: var(--gold); }

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

/* ─── Выбранная фишка ────────────────────────────────────────── */
.piece.selected {
    border-color: #ffffff !important;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.6), 0 2px 8px rgba(0,0,0,0.6) !important;
    transform: scale(1.2);
    z-index: 2;
}

/* Фишки кликабельны */
.pieces-layer { pointer-events: none; }
.piece.my-piece { pointer-events: all; cursor: pointer; }
.ship.my-ship   { pointer-events: all; cursor: pointer; }

/* ─── Счётчик фишек в панели игрока ────────────────────────────*/
.piece-count {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Flip-анимация тайла ────────────────────────────────────── */
.tile-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-origin: center;
    transform-style: preserve-3d;
}

@keyframes card-flip {
    0%   { transform: perspective(600px) rotateY(0deg);   }
    45%  { transform: perspective(600px) rotateY(90deg);  opacity: 0.4; }
    55%  { transform: perspective(600px) rotateY(-90deg); opacity: 0.4; }
    100% { transform: perspective(600px) rotateY(0deg);   opacity: 1; }
}

.tile-inner.flipping {
    animation: card-flip 0.62s ease-in-out forwards;
}

/* Карточка "закрытая" — затемнение поверх */
.tile-1 .tile-inner::after {
    content: "?";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: rgba(255,255,255,0.25);
    font-family: 'Cinzel', serif;
    background: rgba(0,0,0,0.35);
    border-radius: 6px;
}

/* Лог: открытие тайла */
.log-entry.log-flip b { color: #c9a84c; }

/* ─── Экраны ─────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Лобби ──────────────────────────────────────────────────── */
.lobby-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 24px;
}

.lobby-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.lobby-title {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    letter-spacing: 0.2em;
    color: var(--gold-dim);
    text-transform: uppercase;
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.field-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field-label {
    font-size: 0.9rem;
    color: var(--text-primary);
    flex: 1;
}

.field-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 60px;
}

/* Степпер */
.stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.step-btn {
    background: var(--bg-card);
    border: none;
    color: var(--gold);
    font-size: 1.1rem;
    width: 32px;
    height: 32px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.step-btn:hover { background: #2a2a2a; }

.step-val {
    width: 36px;
    text-align: center;
    font-family: var(--font-mono, monospace);
    font-size: 0.95rem;
    color: var(--text-primary);
    background: #111;
    padding: 0 4px;
    line-height: 32px;
    display: block;
}

/* Кнопки */
.btn-primary {
    background: linear-gradient(135deg, #c9a84c, #e8c97a);
    color: #1a1200;
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    font-weight: 700;
    transition: opacity 0.2s, transform 0.15s;
    margin-top: 8px;
}
.btn-primary:hover   { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-leave {
    margin-top: auto;
    background: transparent;
    border: 1px solid #5a2020;
    color: #c0392b;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s;
    font-family: 'Crimson Text', serif;
}
.btn-leave:hover { background: rgba(192,57,43,0.1); }

.lobby-error {
    font-size: 0.8rem;
    color: #c0392b;
    text-align: center;
    min-height: 1em;
}

/* Левая панель — flex для кнопки снизу */
.left-panel { display: flex; flex-direction: column; min-height: 300px; }
#player-panel { flex: 1; }

/* ─── Лобби layout ───────────────────────────────────────────── */
.lobby-layout {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 24px;
    padding: 60px 24px;
    flex-wrap: wrap;
}

.lobby-online { min-width: 240px; flex: 1; max-width: 320px; }

/* ─── Онлайн-игроки ─────────────────────────────────────────── */
.online-badge {
    background: #27ae60;
    color: #fff;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 999px;
    font-family: monospace;
    margin-left: 6px;
    vertical-align: middle;
}

.online-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.online-item:last-child { border-bottom: none; }

.online-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #27ae60;
    box-shadow: 0 0 6px #27ae60;
    flex-shrink: 0;
}

.online-name { flex: 1; }
.online-status { font-size: 0.7rem; color: var(--text-muted); }
.online-empty { font-size: 0.85rem; color: var(--text-muted); font-style: italic; }

.btn-invite {
    background: transparent;
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn-invite:hover { background: rgba(201,168,76,0.12); }
.btn-invite:disabled { opacity: 0.5; cursor: default; }

/* ─── Toast-уведомления о приглашениях ─────────────────────── */
#invite-notifications {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.invite-toast {
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    pointer-events: all;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 240px;
    animation: toast-in 0.3s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}

.invite-text { font-size: 0.9rem; color: var(--text-primary); }
.invite-actions { display: flex; gap: 8px; }

.btn-accept {
    flex: 1;
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    border: none;
    border-radius: 7px;
    color: #fff;
    font-size: 0.8rem;
    padding: 6px 12px;
    cursor: pointer;
    font-weight: 600;
}
.btn-decline {
    flex: 1;
    background: transparent;
    border: 1px solid #5a2020;
    border-radius: 7px;
    color: #c0392b;
    font-size: 0.8rem;
    padding: 6px 12px;
    cursor: pointer;
}

/* ─── Кнопка завершить ход ──────────────────────────────────── */
.btn-end-turn {
    width: 100%;
    background: linear-gradient(135deg, #c9a84c, #e8c97a);
    color: #1a1200;
    border: none;
    border-radius: 10px;
    padding: 10px;
    font-family: 'Cinzel', serif;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 8px;
    transition: opacity 0.2s;
}
.btn-end-turn:hover    { opacity: 0.88; }
.btn-end-turn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Лог: открытие тайла */
.log-entry.log-flip b { color: #c9a84c; }

/* ─── Зал ожидания ───────────────────────────────────────────── */
.lobby-waiting { min-width: 200px; max-width: 260px; }

.wr-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.wr-gameid {
    font-family: monospace;
    color: var(--gold);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    user-select: all; /* можно выделить и скопировать */
}

.wr-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.wr-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.wr-player:last-child { border-bottom: none; }

.wr-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Toast: заголовок "Приглашение" */
.invite-from {
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gold-dim);
    font-family: 'Cinzel', serif;
    margin-bottom: 2px;
}

/* Кнопка "Пригласить" без активной игры */
.btn-invite--disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--border);
    color: var(--text-muted);
}
.btn-invite--disabled:hover { background: transparent; }

/* Уже приглашённый игрок */
.btn-invite--sent {
    opacity: 0.5;
    cursor: default;
    border-color: var(--border);
    color: var(--text-muted);
}

/* ─── Водяные тайлы ─────────────────────────────────────────── */
.tile-water { border-color: #1a3a5f !important; }
.tile-closed { border-color: #2a2a2a !important; }
.tile-grass  { border-color: #1a3a1a !important; }
.tile-keys   { border-color: #3a2a0a !important; }

/* ─── Корабль ───────────────────────────────────────────────── */
.ship {
    width: 36px; height: 36px;
    border-radius: 6px;
    background: #555;
    border: 3px solid #aaa;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    cursor: default;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
}
.ship::after { content: "⛵"; font-size: 18px; }

.ship.my-ship {
    cursor: pointer;
    border-color: #fff;
}
.ship.my-ship:hover { transform: scale(1.15); }

.ship.selected {
    box-shadow: 0 0 0 3px rgba(255,255,255,0.7), 0 2px 8px rgba(0,0,0,0.5) !important;
    transform: scale(1.2);
}

/* Поле теперь чуть меньше клеток для большой карты */
#grid .item { min-width: 0; min-height: 0; }

/* ─── Телепорт-тайл ─────────────────────────────────────────── */
.tile-teleport { border-color: #6a0dad !important; }
.tile-teleport .cards { filter: hue-rotate(270deg) brightness(0.9); }

/* ─── Модал телепорта ───────────────────────────────────────── */
.teleport-modal {
    position: fixed; inset: 0; z-index: 300;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
}

.teleport-card {
    background: var(--bg-panel);
    border: 1px solid #6a0dad;
    border-radius: 16px;
    padding: 28px 36px;
    text-align: center;
    box-shadow: 0 0 40px rgba(106,13,173,0.4), var(--shadow);
    min-width: 200px;
}

.teleport-title {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    color: #c77dff;
    letter-spacing: 0.15em;
    margin-bottom: 8px;
}

.teleport-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.teleport-dirs {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    gap: 8px;
    justify-content: center;
}

.teleport-dir-btn {
    width: 52px; height: 52px;
    background: #1a0a2e;
    border: 1px solid #6a0dad;
    border-radius: 10px;
    color: #c77dff;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.teleport-dir-btn:hover {
    background: #2d0f52;
    transform: scale(1.1);
}