:root {
    --bg-gradient: linear-gradient(135deg, #0d0d0d 0%, #161616 100%);
    --panel-bg: rgba(18, 18, 18, 0.96);
    --panel-border: rgba(255, 255, 255, 0.05);
    --text-main: #f5f5f5;
    --text-muted: #888888;
    --accent-yellow: #fc0;
    --accent-cyan: #00d2ff;
    /* Цвет ботов в списке столов (иконка-робот) */
    --accent-purple: #a78bfa;
    --error-red: #ff5252;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, sans-serif; }

body {
    background: var(--bg-gradient);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 40px 20px;
    overflow-x: hidden;
}

.container { position: relative; width: 100%; max-width: 1000px; z-index: 2; }

.brand-title {
    text-align: center;
    color: var(--accent-yellow);
    font-size: 28px;
    font-weight: 300;
    letter-spacing: 8px;
    margin-bottom: 40px;
    opacity: 0.9;
    text-transform: uppercase;
}

/* --- Interactive Eyes --- */
.eyes-follow {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
}

.eye-socket {
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 0 0 40px 40px;
    position: relative;
    overflow: hidden;
    border: 2px solid #000;
}

.pupil-iris {
    width: 12px;
    height: 12px;
    background: #111;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: calc(50% - 6px);
    transition: transform 0.1s ease-out;
}

.main-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0,0,0,0.8);
    backdrop-filter: blur(20px);
    position: relative;
    z-index: 2;
    /* Пропорции панели 4:3 относительно max-width контейнера (1000px) */
    min-height: 750px;
}

.main-content {
    position: relative;
    width: 100%;
}

/* --- Eyes Animation --- */
.eyes-container {
    display: flex;
    gap: 10px;
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.eye {
    width: 45px;
    height: 25px;
    background: white;
    border: 3px solid #f0c653;
    border-radius: 0 0 50px 50px;
    position: relative;
    box-sizing: border-box;
}

.pupil {
    width: 14px;
    height: 7px;
    background: #333;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0 0 14px 14px;
}

/* --- Auth Section --- */
#auth-section {
    flex: 1;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 60px;
    text-align: center;
}

.auth-card {
    max-width: 400px;
    width: 100%;
}

.auth-title {
    font-size: 28px;
    margin-bottom: 10px;
    color: #fff;
}

.auth-subtitle {
    color: var(--text-muted);
    margin-bottom: 40px;
    font-size: 16px;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.auth-divider span {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    opacity: 0.7;
}

.auth-hint {
    margin-top: 24px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.8;
    line-height: 1.4;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.btn-google,
.btn-telegram,
.btn-email,
.btn-password {
    border: none;
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    transition: 0.3s;
    text-decoration: none;
}

.btn-google {
    background: white;
    color: #333;
}

.btn-google:hover {
    background: #f8f8f8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-telegram {
    background: #24A1DE;
    color: white;
}

.btn-telegram:hover {
    background: #28b1f5;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(36, 161, 222, 0.3);
}

.btn-telegram:disabled {
    background: #444;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-email {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-email:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-password {
    background: rgba(84, 160, 255, 0.15);
    color: white;
    border: 1px solid rgba(84, 160, 255, 0.3);
}

.btn-password:hover {
    background: rgba(84, 160, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(84, 160, 255, 0.2);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-message {
    color: var(--error-red);
    margin-top: 20px;
    font-size: 14px;
    background: rgba(255, 82, 82, 0.1);
    padding: 10px;
    border-radius: 8px;
    display: none;
}

/* --- Lobby Section --- */
#lobby-section {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.header, .tabs, .table-header, .table-footer { border-bottom: 1px solid var(--panel-border); }

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: rgba(255, 255, 255, 0.01);
}

.user-info { display: flex; align-items: center; gap: 10px; }

.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 16px; font-weight: 600; color: var(--accent-cyan); }

.user-balance {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-muted);
    margin-top: 3px;
}

.coin-icon { width: 8px; height: 8px; background: var(--accent-yellow); border-radius: 50%; }

.btn-logout {
    background: none; border: none; padding: 8px 0; cursor: pointer;
    font-size: 12px; color: var(--text-muted); opacity: 0.6; transition: 0.3s;
}

.btn-logout:hover { color: var(--error-red); opacity: 1; }

.tabs { padding: 0 30px; background: rgba(0, 0, 0, 0.1); display: flex; gap: 30px; }

.tab {
    display: inline-block; padding: 20px 0;
    color: var(--text-muted); font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 1.5px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: 0.3s;
}

.tab.active {
    color: var(--accent-yellow);
    border-bottom: 2px solid var(--accent-yellow);
}

.tab:hover:not(.active) {
    color: #fff;
}

.table-area {
    flex: 1;
    min-height: 0;
    background: radial-gradient(circle at 50% -20%, rgba(255,204,0,0.02) 0%, transparent 50%);
    display: flex;
    flex-direction: column;
}

.table-header {
    display: grid; grid-template-columns: 2fr 1fr 1fr 40px;
    padding: 18px 30px; color: var(--accent-cyan);
    font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    align-items: center;
}

.refresh-btn {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    display: flex; align-items: center; justify-content: center; transition: 0.4s;
}

.refresh-btn:hover { color: #fff; transform: rotate(180deg); }
.refresh-btn svg { fill: currentColor; width: 16px; height: 16px; }

.table-body {
    /* Фиксированная высота под PAGE_SIZE=10 строк, чтобы высота панели
       не менялась при переключении вкладок (столы/рейтинг/матчи). */
    flex: 0 0 auto;
    height: 450px; /* 10 строк * (44px + 1px border) — влезает вся страница без скролла */
    overflow-y: auto;
    display: flex; flex-direction: column; justify-content: safe center;
    align-items: stretch; text-align: left;
    color: var(--text-muted); font-size: 14px;
    padding: 0; opacity: 0.4;
}

/* Центрируем только текст пустого состояния, строки таблицы — по левому краю */
.table-body:not(:has(.table-row)) { text-align: center; }

/* Скроллбар в стиле панели — на случай, если контент всё же переполнится */
.table-body {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 204, 0, 0.25) transparent;
}

.table-body::-webkit-scrollbar { width: 8px; }
.table-body::-webkit-scrollbar-track { background: transparent; }

.table-body::-webkit-scrollbar-thumb {
    background: rgba(255, 204, 0, 0.25);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.table-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 204, 0, 0.45);
    background-clip: padding-box;
}

.table-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 40px;
    /* Единая высота строки во всех вкладках => одинаковая высота панели */
    height: 44px;
    padding: 0 30px;
    border-bottom: 1px solid var(--panel-border);
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.table-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.table-footer {
    padding: 30px; display: flex; justify-content: space-between; align-items: center;
    min-height: 105px; /* стабильная высота, когда кнопка "Создать стол" скрыта */
    background: rgba(0,0,0,0.05); border-bottom: none; border-top: 1px solid var(--panel-border);
}

.btn-create, .btn-play {
    background: transparent; color: var(--accent-yellow);
    border: 1px solid rgba(255, 204, 0, 0.3);
    padding: 12px 30px; border-radius: 12px; cursor: pointer;
    font-size: 13px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 1px; transition: 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-play {
    background: var(--accent-yellow);
    color: #000;
    border-color: var(--accent-yellow);
}

.btn-create:hover, .btn-play:hover {
    background: var(--accent-yellow); color: #000;
    box-shadow: 0 0 30px rgba(255, 204, 0, 0.2); transform: translateY(-2px);
}

.sidebar {
    position: absolute;
    left: 100%;
    top: 60px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1;
}

.social-link, .social-group {
    display: flex;
    width: 190px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-left: none;
    color: var(--text-main);
    text-decoration: none;
    border-radius: 0 12px 12px 0;
    transition: 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    overflow: hidden;
    box-shadow: 5px 0 20px rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
}

.social-link {
    align-items: center;
    height: 48px;
    padding-left: 16px;
}

.social-group {
    flex-direction: column;
    padding: 14px 16px;
}

.social-group-title {
    display: flex;
    align-items: center;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-yellow);
    margin-bottom: 12px;
    opacity: 0.9;
}

.social-group-title .social-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    fill: var(--accent-yellow);
}

.social-sublinks {
    display: flex;
    flex-direction: column;
    position: relative;
    padding-left: 6px;
}

/* Vertical line for the tree */
.social-sublinks::before {
    content: '';
    position: absolute;
    left: 13px;
    top: -5px;
    bottom: 15px;
    width: 1px;
    background: rgba(255, 255, 255, 0.15);
}

.social-sublink {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-main);
    font-size: 13px;
    height: 28px;
    opacity: 0.6;
    transition: all 0.2s ease;
    position: relative;
}

.tree-branch {
    width: 12px;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin-right: 10px;
    position: relative;
    margin-left: 8px;
}

.social-sublink:hover {
    opacity: 1;
    color: var(--accent-cyan);
    transform: translateX(3px);
}

.social-sublink:hover .tree-branch {
    background: var(--accent-cyan);
    width: 16px;
}

.social-link span {
    margin-left: 15px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0.9;
    transition: 0.2s;
}

.social-link:hover {
    background: #222;
    transform: translateX(5px);
}

.social-link:hover span { opacity: 1; }

.social-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    fill: var(--accent-cyan);
    opacity: 0.8;
    transition: 0.3s;
}

.social-link:hover .social-icon {
    opacity: 1;
    transform: scale(1.1);
}

@media (max-width: 1400px) {
    .sidebar {
        position: relative;
        left: 0;
        top: 0;
        flex-direction: row;
        justify-content: center;
        margin-top: 40px;
        gap: 15px;
    }

    .social-link, .social-group {
        width: auto;
        padding-right: 20px;
        border-left: 1px solid var(--panel-border);
        border-radius: 12px;
        transform: none !important;
    }
}

@media (max-width: 600px) {
    body { padding: 20px 10px; }
    .brand-title { font-size: 20px; letter-spacing: 4px; margin-bottom: 20px; }

    .eye { width: 35px; height: 18px; border-width: 2px; }
    .pupil { width: 10px; height: 5px; border-radius: 0 0 10px 10px; }

    .sidebar {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        margin-top: 30px;
    }

    .social-link, .social-group {
        width: 100%;
        max-width: 280px;
        justify-content: center;
        border-left: 1px solid var(--panel-border);
        border-radius: 12px;
    }

    .social-group {
        align-items: flex-start;
        padding-right: 16px;
    }

    .social-sublinks {
        align-items: flex-start;
    }

    .social-sublink {
        padding-left: 0;
    }

    .main-panel {
        min-height: auto;
        border-radius: 16px;
    }

    #auth-section { padding: 30px 20px; }
    .auth-title { font-size: 22px; }
    .auth-subtitle { margin-bottom: 20px; }

    .header { padding: 15px 20px; }
    .tabs { padding: 0 20px; gap: 20px; }
    .tab { padding: 15px 0; font-size: 11px; }

    .table-header { padding: 12px 20px; grid-template-columns: 2fr 1fr 40px; }
    .table-header div:nth-child(2) { display: none; } /* Hide Stakes label */

    .table-row { padding: 0 20px; grid-template-columns: 2fr 1fr 40px; }
    .table-row div:nth-child(2) { display: none; } /* Hide Stakes value */
    .table-body { padding: 0; height: 450px; }

    .table-footer { padding: 20px; flex-direction: column; gap: 20px; min-height: auto; }
    .btn-create { width: 100%; text-align: center; }

    .modal-content { padding: 25px; border-radius: 16px; width: 90%; }
}

@media (max-width: 400px) {
    .table-header, .table-row { grid-template-columns: 1fr 1fr 40px; }
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 450px;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
}

.modal-title {
    font-size: 24px;
    margin-bottom: 30px;
    color: var(--accent-yellow);
    text-align: center;
}

.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.input-group input, .input-group select {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 14px 18px;
    color: #fff;
    font-size: 15px;
    outline: none;
    transition: 0.3s;
}

.input-group select {
    color-scheme: dark;
    background: #1a1a1a !important;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--accent-yellow);
    background: rgba(255, 255, 255, 0.06);
}

/* Чекбокс в модалке (галочка «сообщить в Telegram»): подпись в строку с
   квадратиком, а не блочный uppercase-label как у обычных полей. */
.input-group-check .check-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
}

.input-group-check .check-line input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    padding: 0;
    accent-color: var(--accent-yellow);
    cursor: pointer;
}

.input-group select option {
    background: #1a1a1a;
    color: #fff;
    padding: 10px;
}

.modal-actions {
    display: flex;
    gap: 15px;
    margin-top: 40px;
}

.modal-actions button {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
}

.btn-primary {
    background: var(--accent-yellow);
    color: #000;
    border: none;
}

.btn-primary:hover {
    background: #ffdb4d;
    transform: translateY(-2px);
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

/* Edit Nickname Button */
.btn-edit-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-edit-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-edit-icon svg {
    transition: fill 0.2s;
}

.btn-edit-icon:hover svg {
    fill: var(--accent-cyan);
}

.input-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.link-inline {
    color: var(--accent-cyan);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
    cursor: pointer;
}

.link-inline:hover {
    color: var(--accent-yellow);
}

/* Развёрнутая инструкция «как подписаться на бота» под галочкой уведомлений. */
.tg-subscribe-info {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-muted);
}

.tg-subscribe-info code {
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--accent-yellow);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.page-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: 0.3s;
}

.page-btn:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.2);
}

.page-btn.active {
    background: var(--accent-yellow);
    color: #000;
    border-color: var(--accent-yellow);
}

.page-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-container {
    display: flex;
    justify-content: center;
    padding: 0;
}

/* --- Music Player Iframe --- */
.music-player-container {
    position: relative;
    width: 300px;
    height: 38px;
    margin: 0 0 12px 24px; /* Left aligned above the panel */
    z-index: 100;
    display: none;
}

.music-player-container.visible {
    display: block;
}

.music-player-iframe {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 38px; /* Default height to match container */
    border: none;
    background: transparent;
    pointer-events: all;
    transition: height 0.2s ease;
}

/* Expand height only on hover to show volume slider and not block the title */
.music-player-iframe:hover {
    height: 250px;
}

@media (max-width: 800px) {
    /* Music player is horizontal and centered on mobile */
    .music-player-container {
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        margin: 0 auto 20px auto;
        width: 100%;
        max-width: 300px;
        height: 38px;
        z-index: 100;
        display: none;
    }
    .music-player-container.visible {
        display: block;
    }
    .music-player-iframe {
        width: 100%;
        height: 38px;
        border-radius: 12px;
        background: rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(4px);
    }
    .music-player-iframe:hover {
        height: 38px;
    }
}

/* --- Global Chat -----------------------------------------------------------
   Панель, пристыкованная снизу под окном лобби на десктопе, bottom sheet на
   мобиле. Визуально повторяет игровой ChatPanel.vue (services/bomber-game):
   та же плашка, шапка, анатомия сообщения, пикер и ввод.
   Шрифт остаётся лоббийным ('Inter') — это осознанное отличие.

   #global-chat лежит внутри .container (сразу за .main-content), но НЕ внутри
   .main-panel: у той есть backdrop-filter, который сломал бы position: fixed
   у мобильной шторки.
   -------------------------------------------------------------------------- */
:root {
    /* 8 name colors, derived from the brand accents:
       cyan / yellow / red base, their lighter+warmer tints, and one neutral. */
    --chat-c0: #00d2ff; /* --accent-cyan */
    --chat-c1: #ffcc00; /* --accent-yellow */
    --chat-c2: #ff5252; /* --error-red */
    --chat-c3: #6ee7ff; /* cyan, lightened */
    --chat-c4: #ffe066; /* yellow, lightened */
    --chat-c5: #ff8a80; /* red, lightened */
    --chat-c6: #7cf2c8; /* cyan shifted to green */
    --chat-c7: #ffa94d; /* yellow shifted to orange */

    /* Высота нижнего дока: панель под лобби, а не полноэкранный столбец.
       Запаса хватает, чтобы поповер эмодзи (max 240px) не обрезался. */
    --gchat-height: 360px;
    /* Общая для чата линия «стекла» — как в игровой панели. */
    --gchat-line: rgba(255, 255, 255, 0.1);
    --gchat-line-soft: rgba(255, 255, 255, 0.15);
    --gchat-fill: rgba(255, 255, 255, 0.06);
}

.gchat {
    position: relative;
    z-index: 2;
    margin-top: 20px;
    width: 100%;
    /* Как ширина .container — раньше .gchat случайно наследовал её,
       будучи (по ошибке) вложен внутрь .container в DOM. */
    max-width: 1000px;
    height: var(--gchat-height);
    display: none;
    flex-direction: column;
    box-sizing: border-box;
    background: var(--panel-bg);
    border: 1px solid var(--gchat-line);
    border-radius: 16px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    overflow: hidden;
    color: var(--text-main);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.gchat-enabled .gchat { display: flex; }

/* Свёрнутый десктоп: от панели остаётся только горизонтальная шапка. */
body.gchat-enabled .gchat.collapsed { height: auto; }
body.gchat-enabled .gchat.collapsed .gchat-body { display: none; }
body.gchat-enabled .gchat.collapsed .gchat-header { border-bottom: none; }
.gchat.collapsed #gchat-collapse { transform: rotate(180deg); }

/* --- Header --- */
.gchat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    padding: 10px 12px 10px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--gchat-line);
    user-select: none;
}

.gchat-stripe {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    background-color: var(--accent-yellow);
    background-image: repeating-linear-gradient(
        45deg,
        #1a1a1a,
        #1a1a1a 8px,
        var(--accent-yellow) 8px,
        var(--accent-yellow) 16px
    );
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}

.gchat-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-yellow);
    white-space: nowrap;
}

.gchat-status { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.gchat-header-spacer { flex: 1; }

.gchat-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--gchat-line-soft);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.gchat-icon-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.gchat-icon-btn:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; }
.gchat-icon-btn.muted { opacity: 0.4; }
.gchat-only-mobile { display: none; }

.gchat-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* --- Messages --- */
.gchat-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.gchat-scroll::-webkit-scrollbar { width: 6px; }
.gchat-scroll::-webkit-scrollbar-track { background: transparent; }
.gchat-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.gchat-msg { display: flex; flex-direction: column; gap: 2px; }

.gchat-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
    line-height: 1.2;
}

.gchat-name {
    font-weight: 700;
    font-size: 12px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Ник — недоверенная строка: изолируем bidi, чтобы RTL-override
       не переупорядочивал мета-строку (чип роли / время). */
    unicode-bidi: isolate;
}

/* Ник в таблице рейтинга — тот же недоверенный источник. */
.rank-player-name {
    unicode-bidi: isolate;
}

.match-players {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    unicode-bidi: isolate;
}

.gchat-badge-role {
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}

.gchat-badge-role.is-player {
    color: var(--accent-yellow);
    background: rgba(255, 204, 0, 0.12);
    border-color: rgba(255, 204, 0, 0.35);
}

.gchat-badge-role.is-spectator {
    color: var(--text-muted);
    background: var(--gchat-fill);
    border-color: var(--gchat-line-soft);
}

.gchat-time {
    margin-left: auto;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.gchat-text {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-main);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    /* defense in depth: bidi-изоляция текста сообщения */
    unicode-bidi: isolate;
}

.gchat-msg.system {
    display: block;
    text-align: center;
    font-style: italic;
    font-size: 12px;
    color: var(--text-muted);
    padding: 2px 8px;
}

.gchat-newpill {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 62px;
    display: none;
    background: var(--accent-yellow);
    color: #000;
    border: none;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    z-index: 2;
}

.gchat-newpill.visible { display: block; }

/* --- Input row --- */
.gchat-input-row {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--gchat-line);
    background: rgba(0, 0, 0, 0.25);
}

.gchat-input {
    flex: 1;
    min-width: 0;
    background: var(--gchat-fill);
    border: 1px solid var(--gchat-line-soft);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-main);
    font-size: 13px;
    outline: none;
    touch-action: manipulation;
    transition: border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.gchat-input::placeholder { color: var(--text-muted); }
.gchat-input:focus { border-color: rgba(255, 204, 0, 0.6); }
.gchat-input:disabled { color: var(--text-muted); opacity: 0.6; cursor: not-allowed; }

.gchat-counter {
    position: absolute;
    right: 56px;
    bottom: 2px;
    font-size: 9px;
    color: var(--text-muted);
    pointer-events: none;
    display: none;
}

.gchat-counter.visible { display: block; }
.gchat-counter.limit { color: var(--error-red); }

.gchat-send {
    flex: 0 0 auto;
    width: 36px;
    height: 34px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    background: var(--accent-yellow);
    color: #000;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.gchat-send:hover:not(:disabled) { filter: brightness(1.1); }
.gchat-send:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; }
.gchat-send:disabled {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    cursor: not-allowed;
}

/* --- Emoji picker --- */
.gchat-emoji-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 34px;
    padding: 0;
    background: var(--gchat-fill);
    border: 1px solid var(--gchat-line-soft);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.gchat-emoji-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 204, 0, 0.6);
}

.gchat-emoji-btn.active { border-color: var(--accent-yellow); background: rgba(255, 204, 0, 0.12); }
.gchat-emoji-btn:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; }
.gchat-emoji-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.gchat-emoji-popover {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(100% + 6px);
    width: auto;
    max-height: min(240px, 40vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 20;
    box-sizing: border-box;
    padding: 8px;
    background: var(--panel-bg);
    border: 1px solid var(--gchat-line);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    transform-origin: bottom center;
    animation: gchat-emoji-in 0.15s ease-out;
}

.gchat-emoji-popover[hidden] { display: none; }

@keyframes gchat-emoji-in {
    from { opacity: 0; transform: translateY(6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.gchat-emoji-popover::-webkit-scrollbar { width: 6px; }
.gchat-emoji-popover::-webkit-scrollbar-track { background: transparent; }
.gchat-emoji-popover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; }

.gchat-emoji-group + .gchat-emoji-group { margin-top: 8px; }
.gchat-emoji-group[hidden] { display: none; }

.gchat-emoji-group-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 0 0 4px 2px;
}

.gchat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 2px;
}

.gchat-emoji-item {
    aspect-ratio: 1 / 1;
    min-height: 30px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-main);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s ease;
}

.gchat-emoji-item:hover { background: rgba(255, 204, 0, 0.18); }
.gchat-emoji-item:focus-visible { outline: none; border-color: var(--accent-yellow); }

.gchat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 890;
    display: none;
}

/* --- Мобильный FAB + бейдж непрочитанных --- */
.gchat-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid var(--gchat-line);
    background: var(--panel-bg);
    color: var(--accent-yellow);
    cursor: pointer;
    touch-action: manipulation;
    z-index: 880;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
}

.gchat-fab-glyph { font-size: 20px; line-height: 1; }

.gchat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    display: none;
}

.gchat-badge.visible { display: block; }

/* Нижний док на узких десктопах/планшетах — просто ниже, ширина всегда 100%. */
@media (max-width: 1000px) {
    :root { --gchat-height: 320px; }
    .gchat-name { max-width: 140px; }
}

@media (max-width: 800px) {
    /* Mobile: скрыт по умолчанию, открывается bottom sheet'ом по FAB. */
    body.gchat-enabled { padding-bottom: 90px; }

    body.gchat-enabled .gchat-fab { display: flex; }

    body.gchat-enabled .gchat,
    body.gchat-enabled .gchat.collapsed {
        display: flex;
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        margin-top: 0;
        width: auto;
        max-width: none;
        height: 72vh;
        max-height: 72vh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        transform: translateY(105%);
        z-index: 900;
    }

    /* На мобиле «свёрнутость» не действует — шторка всегда полная. */
    body.gchat-enabled .gchat.collapsed .gchat-body { display: flex; }

    body.gchat-enabled .gchat.mobile-open { transform: translateY(0); }

    body.gchat-mobile-open .gchat-backdrop { display: block; }
    body.gchat-mobile-open .gchat-fab { display: none; }

    .gchat-only-mobile { display: inline-flex; }
    .gchat-only-desktop { display: none; }

    /* Шторка выше нижнего дока — имени можно дать больше места. */
    .gchat-status { display: inline; }
    .gchat-name { max-width: 150px; }

    /* Ручка шторки над шапкой (как в игровом bottom sheet). */
    .gchat-header { padding: 18px 12px 12px 20px; cursor: default; }
    .gchat-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.15);
    }

    .gchat-scroll { padding: 12px 14px; }
    .gchat-input-row { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
    .gchat-emoji-btn { width: 38px; height: 40px; font-size: 20px; }
    .gchat-send { width: 42px; height: 40px; font-size: 16px; }
    .gchat-counter { right: 62px; }

    .gchat-emoji-popover {
        left: 14px;
        right: 14px;
        max-height: min(240px, 34vh);
    }
    .gchat-emoji-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
    .gchat-emoji-item { min-height: 38px; font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    .gchat { transition: none; }
    .gchat-emoji-popover { animation: none; }
    .gchat-emoji-item,
    .gchat-emoji-btn,
    .gchat-icon-btn,
    .gchat-send,
    .gchat-input { transition: none; }
}


.replays-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.replay-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12px;
               background: rgba(255,255,255,0.05); }
.replay-item:hover { background: rgba(255,255,255,0.12); }
.replays-pagination { display: flex; gap: 4px; margin-top: 6px; justify-content: center; }

/* --- Avatar block in nickname modal (prefix lav-) --- */
.lav-block {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.lav-preview {
    position: relative;
    flex: 0 0 auto;
    width: 72px;
    height: 72px;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.lav-preview-busy { opacity: 0.5; }

.lav-placeholder {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-muted);
}

.lav-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.lav-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.lav-file { display: none; }

.lav-btn {
    padding: 6px 14px;
    font-size: 13px;
    min-width: 0;
}

.lav-btn-danger { color: var(--error-red); }
.lav-btn-danger:hover { color: var(--error-red); }

.lav-btn[disabled] { opacity: 0.5; cursor: default; }

.lav-hint {
    flex-basis: 100%;
    font-size: 12px;
    color: var(--text-muted);
}

.lav-error {
    flex-basis: 100%;
    font-size: 12px;
    color: var(--error-red);
}

/* --- Interactive avatar cropper (layer above .modal-overlay, prefix lav-) --- */
.lav-crop-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1100; /* выше .modal-overlay (1000) */
}

.lav-crop-overlay.active { display: flex; }

.lav-crop-box {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 300px;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
    text-align: center;
}

.lav-crop-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.lav-crop-stage {
    position: relative;
    width: 220px;
    height: 220px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--panel-border);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.lav-crop-stage:active { cursor: grabbing; }

.lav-crop-canvas {
    display: block;
    width: 220px;
    height: 220px;
}

/* Квадрат-подсказка: показывает, как аватар обрежется в интерфейсе
   (в карточке игрока аватарка квадратная, со скруглением 6px). */
.lav-crop-mask {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 6px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.lav-crop-zoom {
    width: 220px;
    margin: 16px auto 0;
    display: block;
}

.lav-crop-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.lav-crop-error {
    margin-top: 8px;
    font-size: 12px;
    color: var(--error-red);
}

.lav-crop-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
}

/* --- Desktop: лобби вписывается в экран, страница не скроллится -------------
   Это игровое лобби, а не лендинг: прокручиваться должен только список
   (.table-body) и лента чата, но не сам документ. Раньше контент перерастал
   вьюпорт на ~15px, и страница «слегка ездила».
   Высоту отдаёт только список столов (450px -> сколько не хватает, но не
   меньше 300px) и чат: на типовом экране это единицы процентов.
   Мобильная вёрстка (<= 800px) не трогается — там скролл уместен.
   -------------------------------------------------------------------------- */
@media (min-width: 801px) {
    html {
        height: 100%;
    }

    body {
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
        overscroll-behavior: none;
        flex-direction: column;
    }

    .container {
        display: flex;
        flex-direction: column;
        max-height: 100%;
        min-height: 0;
    }

    .main-content {
        display: flex;
        flex: 0 1 auto;
        min-height: 0;
    }

    .main-panel {
        flex: 1 1 auto;
        /* базовые 750px иначе стали бы порогом переполнения */
        min-height: 0;
    }

    /* Экран логина не растягивается контентом, поэтому держим ему пропорции
       4:3 от max-width контейнера (1000px), но не выше вьюпорта. */
    body:has(#auth-section[style*="flex"]) .main-panel {
        min-height: min(750px, calc(100vh - 160px));
    }

    /* Без этого сжимается сама панель, и .table-footer уезжает под
       её overflow: hidden вместо того, чтобы ужался список. */
    #lobby-section {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
    }

    .table-area {
        min-height: 0;
        /* .table-body держит собственный min-height и может не влезть в
           ужатую .table-area — без clip он наезжает на .table-footer
           вместо того, чтобы просто обрезаться (список и так скроллится). */
        overflow: hidden;
    }

    .table-body {
        /* 450px — желаемая высота; отдаётся только недостающее, дальше
           список скроллится внутри себя. */
        flex: 0 1 450px;
        height: auto;
        min-height: 300px;
    }

    /* Кнопка «Создать стол» никогда не должна ужиматься/обрезаться. */
    .table-footer {
        flex-shrink: 0;
    }

    .gchat {
        flex: 0 1 auto;
        min-height: 260px;
    }

    /* Свёрнутый чат не должен держать базовые 260px — от него остаётся шапка. */
    body.gchat-enabled .gchat.collapsed {
        flex: 0 0 auto;
        min-height: 0;
    }

    /* Невысокий экран + развёрнутый чат: сумма min-height (список 300 + чат 260
       + шапки/футер) перерастает вьюпорт — отдаём высоту списка, он и так
       скроллится внутри себя. С 6cf6fa30 (закрытие .container, body:
       flex-direction: column) .gchat больше не вложен в .container и не
       делит с .table-footer одну область обрезки, так что здесь остаётся
       только честная нехватка места, а не наезд чата на кнопку. */
    @media (max-height: 900px) {
        .table-body { min-height: 160px; }
    }

    @media (max-height: 760px) {
        .table-body { min-height: 90px; }
        .gchat { min-height: 200px; }
    }

    @media (max-height: 640px) {
        .gchat { min-height: 150px; }
    }
}

/* Подсветка недопустимых символов логина: пользователь видит, какой именно
   символ мешает, а не абстрактное «only letters and numbers». */
.input-group input.input-invalid {
    border-color: var(--error-red);
    background: rgba(255, 82, 82, 0.08);
}

.charmap {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 8px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 15px;
    line-height: 1;
}

.charmap span {
    padding: 4px 3px;
    border-radius: 4px;
    color: var(--text-muted);
}

.charmap span.bad {
    color: #fff;
    background: var(--error-red);
    font-weight: 700;
    box-shadow: 0 0 0 2px rgba(255, 82, 82, 0.35);
}
