/**
 * Основные стили для игры "Battle of Ships"
 * Стили для мобильных устройств с адаптивным дизайном
 */

/* Сброс стилей по умолчанию */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Основные настройки страницы */
html {
    touch-action: manipulation; /* Предотвращает зум при двойном тапе */
    -ms-touch-action: manipulation;
    -webkit-text-size-adjust: 100%; /* Предотвращает автоматическое изменение размера текста */
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    
    /* CSS переменные для viewport (устанавливаются через ViewportManager) */
    --vw: 100vw;
    --vh: 100vh;
    --real-vh: 100vh;
    --available-height: 100vh;
    --available-width: 100vw;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --screen-width: 100vw;
    --screen-height: 100vh;
    --is-standalone: 0;
    --min-size: 100vw;
    --max-size: 100vh;
    
    /* CSS переменные для Aspect Ratio Lock */
    --aspect-lock-scale: 1;
    --aspect-lock-width: 375px;
    --aspect-lock-height: 667px;
    --aspect-lock-base-width: 375px;
    --aspect-lock-base-height: 667px;
    --aspect-lock-offset-x: 0px;
    --aspect-lock-offset-y: 0px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #000; /* Черный фон для letterboxing */
    background: radial-gradient(ellipse at center, #1a1a3e 0%, #0c0c2e 40%, #050510 100%);
    min-height: 100vh;
    min-height: var(--real-vh, 100vh);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
    position: fixed;
    width: 100%;
    height: 100%;
    height: var(--real-vh, 100vh);
    /* Дополнительная защита от зума */
    -ms-content-zooming: none;
    -ms-touch-action: manipulation;
    position: relative;
}

/* Главный контейнер приложения - Aspect Ratio Lock */
#app {
    width: var(--aspect-lock-width, 375px);
    height: var(--aspect-lock-height, 667px);
    max-width: var(--aspect-lock-width, 375px);
    max-height: var(--aspect-lock-height, 667px);
    position: relative;
    background: radial-gradient(ellipse at center, #1a1a3e 0%, #0c0c2e 40%, #050510 100%);
    overflow: hidden;
    /* Центрирование с учетом отступов и safe areas */
    margin: var(--aspect-lock-offset-y, 0px) var(--aspect-lock-offset-x, 0px);
    margin-bottom: calc(var(--aspect-lock-offset-y, 0px) + var(--aspect-lock-safe-bottom, 0px));
    box-sizing: border-box;
    /* Убеждаемся, что контент масштабируется правильно */
    transform-origin: center center;
}

/* Контейнер для звездного неба */
#app::before {
    content: '';
    position: absolute;
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
    background: radial-gradient(ellipse at 30% 40%, rgba(102, 126, 234, 0.15) 0%, transparent 70%);
    animation: nebulaPulse 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

#app::after {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    top: 30%;
    right: 10%;
    background: radial-gradient(ellipse at 70% 60%, rgba(118, 75, 162, 0.12) 0%, transparent 70%);
    animation: nebulaPulse 25s ease-in-out infinite reverse;
    pointer-events: none;
    z-index: 0;
}

@keyframes nebulaPulse {
    0%, 100% {
        opacity: 0.5;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

/* Контейнер для звезд - должен быть поверх туманности, но под контентом */
.stars-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

/* Маленькие звезды */
.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    animation: twinkle 2s infinite ease-in-out;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
}

/* Средние звезды */
.star.medium {
    width: 3px;
    height: 3px;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.9);
    animation: twinkle 3s infinite ease-in-out;
}

/* Большие яркие звезды */
.star.bright {
    width: 4px;
    height: 4px;
    background: #fff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 1),
                0 0 12px rgba(255, 255, 255, 0.6),
                0 0 20px rgba(255, 255, 255, 0.3);
    animation: twinkleBright 4s infinite ease-in-out;
}

/* Очень яркие звезды с цветным свечением */
.star.super-bright {
    width: 5px;
    height: 5px;
    background: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 1),
                0 0 20px rgba(102, 126, 234, 0.8),
                0 0 30px rgba(118, 75, 162, 0.5);
    animation: twinkleSuperBright 5s infinite ease-in-out;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

@keyframes twinkleBright {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }
    25% {
        opacity: 1;
        transform: scale(1.3);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
    75% {
        opacity: 1;
        transform: scale(1.4);
    }
}

@keyframes twinkleSuperBright {
    0%, 100% {
        opacity: 0.7;
        transform: scale(1);
    }
    20% {
        opacity: 1;
        transform: scale(1.5);
    }
    40% {
        opacity: 0.9;
        transform: scale(1.2);
    }
    60% {
        opacity: 1;
        transform: scale(1.6);
    }
    80% {
        opacity: 0.8;
        transform: scale(1.3);
    }
}

/* Кометы */
.comet {
    position: absolute;
    width: 3px;
    height: 3px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.8),
                0 0 20px rgba(255, 255, 255, 0.4);
    animation: cometFly 15s infinite linear;
    pointer-events: none;
}

.comet::before {
    content: '';
    position: absolute;
    width: 100px;
    height: 2px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.6));
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    border-radius: 2px;
}

@keyframes cometFly {
    0% {
        left: -10px;
        top: 10%;
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    95% {
        opacity: 1;
    }
    100% {
        left: 110%;
        top: 90%;
        opacity: 0;
    }
}

/* Базовый класс для экранов - используем фиксированные размеры */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    min-height: var(--aspect-lock-height, 667px);
    max-height: var(--aspect-lock-height, 667px);
    padding: 20px;
    padding-top: calc(20px + var(--safe-area-top, 0px));
    padding-bottom: calc(20px + var(--safe-area-bottom, 0px));
    padding-left: calc(20px + var(--safe-area-left, 0px));
    padding-right: calc(20px + var(--safe-area-right, 0px));
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    z-index: 10; /* Поверх звездного неба */
}

.screen.active {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Специальная обработка для экрана авторизации при открытии клавиатуры */
#auth-screen.screen.active {
    /* Разрешаем прокрутку на экране авторизации */
    overflow-y: auto;
    overflow-x: hidden;
    /* Плавная прокрутка */
    -webkit-overflow-scrolling: touch;
    /* Выравнивание по верху при открытии клавиатуры */
    justify-content: flex-start;
    padding-top: 20px;
    padding-bottom: 20px;
}

/* Когда клавиатура открыта */
#auth-screen.screen.active.keyboard-open {
    /* Убираем центрирование, выравниваем по верху */
    justify-content: flex-start;
    padding-top: 10px;
    /* Увеличиваем нижний отступ для клавиатуры */
    padding-bottom: 20px;
}

.auth-container.keyboard-open {
    /* Уменьшаем максимальную высоту при открытой клавиатуре */
    max-height: calc(var(--available-height, 100vh) - 100px);
    /* Убираем центрирование */
    margin-top: 0;
    margin-bottom: auto;
}

/* Экран расстановки - полный экран без padding */
#manual-placement-screen.screen.active {
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;
}

/* Игровой экран - БЕЗ прокрутки, все должно помещаться */
#game-screen.screen.active {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Начинаем с верха, а не центрируем */
    overflow: hidden; /* БЕЗ прокрутки - все должно помещаться */
    padding: 8px;
    padding-top: calc(8px + var(--safe-area-top, 0px));
    padding-bottom: calc(8px + var(--safe-area-bottom, 0px));
    padding-left: calc(8px + var(--safe-area-left, 0px));
    padding-right: calc(8px + var(--safe-area-right, 0px));
    height: 100%;
    max-height: 100%;
    width: 100%;
    box-sizing: border-box;
    min-height: 0; /* Позволяет flex-контейнеру сжиматься */
    position: relative; /* Для позиционирования чата */
}

/* Стили для меню */
.menu-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.game-title {
    font-size: 48px;
    color: #1976D2;
    margin-bottom: 40px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap; /* Вариант 1: Запретить перенос текста */
    overflow: hidden; /* Скрыть переполнение */
    text-overflow: ellipsis; /* Показать многоточие при переполнении (опционально) */
    /* Альтернативные варианты (раскомментируйте нужный): */
    /* Вариант 2: Уменьшить размер шрифта на маленьких экранах */
    /* font-size: clamp(28px, 8vw, 48px); */
    /* Вариант 3: Использовать адаптивный размер */
    /* font-size: min(48px, 12vw); */
}

/* Стили для кнопок */
.btn {
    width: 100%;
    padding: 15px 30px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 10px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background: #ffffff;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:active {
    transform: scale(0.95);
    background: #f5f5f5;
}

/* Стили для игрового экрана */
.game-info {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 10px 14px; /* Немного увеличен padding */
    margin-bottom: 8px;
    margin-top: 0;
    width: 100%;
    max-width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Не сжимается */
    box-sizing: border-box;
}

.game-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 10px;
}

.game-info-header .user-info-top {
    flex: 1;
    margin-bottom: 0;
}

/* Индикатор соединения */
.connection-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 12px;
    font-size: 12px;
    color: #4CAF50;
    border: 1px solid rgba(76, 175, 80, 0.3);
    white-space: nowrap;
}

.connection-indicator.disconnected {
    background: rgba(244, 67, 54, 0.1);
    color: #F44336;
    border-color: rgba(244, 67, 54, 0.3);
}

.connection-indicator.connecting {
    background: rgba(255, 152, 0, 0.1);
    color: #FF9800;
    border-color: rgba(255, 152, 0, 0.3);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    animation: pulse 2s ease-in-out infinite;
}

.connection-indicator.disconnected .connection-dot {
    background: #F44336;
    animation: none;
}

.connection-indicator.connecting .connection-dot {
    background: #FF9800;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.9);
    }
}

.connection-text {
    font-weight: 600;
    font-size: 11px;
}

/* Имя соперника */
.opponent-name {
    text-align: center;
    font-size: 14px;
    color: #1976D2;
    font-weight: 600;
    margin-bottom: 6px;
    padding: 4px 8px;
    background: rgba(25, 118, 210, 0.1);
    border-radius: 8px;
}

.opponent-name span {
    color: #1565C0;
    font-weight: 700;
}

/* Счетчик оставшихся кораблей */
.ships-remaining {
    text-align: center;
    font-size: 13px;
    color: #666;
    font-weight: 600;
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(255, 152, 0, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(255, 152, 0, 0.2);
}

.ships-remaining span {
    color: #FF9800;
    font-weight: 700;
}

.ships-remaining.low {
    background: rgba(244, 67, 54, 0.1);
    border-color: rgba(244, 67, 54, 0.2);
}

.ships-remaining.low span {
    color: #F44336;
}

.player-info h2 {
    font-size: 18px; /* Уменьшено для компактности */
    color: #1976D2;
    margin-bottom: 6px; /* Уменьшено */
    text-align: center;
    line-height: 1.2;
}

.stats {
    display: flex;
    justify-content: space-around;
    font-size: 12px; /* Уменьшено для компактности */
    color: #666;
    gap: 8px;
    flex-wrap: wrap;
}

.stats span {
    font-weight: 600;
}

/* Контейнер для игровых полей */
.boards-container {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px; /* Увеличен gap */
    margin-bottom: 8px;
    flex: 1 1 auto; /* Занимает доступное пространство */
    min-height: 0; /* Позволяет сжиматься */
    box-sizing: border-box;
    overflow: hidden; /* Предотвращаем переполнение */
}

.board-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 8px; /* Увеличен padding */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    flex: 1 1 0; /* Равномерно распределяем пространство */
    min-height: 0; /* Позволяет сжиматься */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.board-title {
    font-size: 14px; /* Уменьшено для компактности */
    color: #1976D2;
    margin-bottom: 4px; /* Уменьшено */
    text-align: center;
    font-weight: 600;
    line-height: 1.2;
    flex-shrink: 0;
}

/* Стили для экрана поиска соперника */
.matchmaking-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.matchmaking-title {
    font-size: 28px;
    margin-bottom: 30px;
    color: #1976D2;
}

.matchmaking-status {
    margin-bottom: 30px;
}

.search-spinner {
    margin-bottom: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(25, 118, 210, 0.2);
    border-top-color: #1976D2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

#matchmaking-message {
    font-size: 18px;
    color: #666;
    margin-bottom: 10px;
}

.matchmaking-time {
    font-size: 24px;
    font-weight: bold;
    color: #1976D2;
    margin-bottom: 10px;
}

.matchmaking-queue {
    font-size: 14px;
    color: #999;
    margin-top: 10px;
}

.matchmaking-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

/* Стили для экрана результатов */
.result-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

#result-title {
    font-size: 36px;
    margin-bottom: 20px;
    color: #1976D2;
}

#result-message {
    font-size: 18px;
    color: #666;
    margin-bottom: 30px;
    line-height: 1.6;
}

/* Адаптивность для очень маленьких экранов - отключено при Aspect Ratio Lock */
/* Медиа-запросы не нужны, так как все масштабируется автоматически */
/*
@media (max-width: 360px) {
    .game-title {
        font-size: 36px;
    }
    
    .btn {
        font-size: 16px;
        padding: 12px 25px;
    }
    
    .board-section {
        padding: 4px;
    }
    
    .game-info {
        padding: 6px 10px;
        margin-bottom: 6px;
    }
    
    .player-info h2 {
        font-size: 16px;
        margin-bottom: 4px;
    }
    
    .stats {
        font-size: 11px;
    }
    
    .boards-container {
        gap: 6px;
        margin-bottom: 6px;
    }
    
    .board-title {
        font-size: 12px;
        margin-bottom: 2px;
    }
    
    #game-screen.screen.active {
        padding: 6px;
        padding-top: calc(6px + var(--safe-area-top, 0px));
        padding-bottom: calc(6px + var(--safe-area-bottom, 0px));
    }
    
    /* Кнопка выхода должна быть видна */
    #exit-game-btn {
        margin-top: 6px;
        margin-bottom: calc(6px + var(--safe-area-bottom, 0px));
        padding: 10px 16px;
        font-size: 14px;
        flex-shrink: 0;
    }
}
*/

/* Адаптивность для игрового экрана на маленьких экранах - отключено при Aspect Ratio Lock */
/*
@media (max-height: 700px) {
    #game-screen.screen.active {
        padding: 6px;
        padding-top: calc(6px + var(--safe-area-top, 0px));
        padding-bottom: calc(6px + var(--safe-area-bottom, 0px));
    }
    
    .game-info {
        padding: 6px 10px;
        margin-bottom: 6px;
    }
    
    .player-info h2 {
        font-size: 16px;
        margin-bottom: 4px;
    }
    
    .stats {
        font-size: 11px;
    }
    
    .boards-container {
        gap: 6px;
        margin-bottom: 6px;
    }
    
    .board-section {
        padding: 4px;
    }
    
    .board-title {
        font-size: 12px;
        margin-bottom: 2px;
    }
    
    /* Кнопка выхода должна быть видна */
    #exit-game-btn {
        margin-top: 6px;
        margin-bottom: calc(6px + var(--safe-area-bottom, 0px));
        padding: 10px 16px;
        font-size: 14px;
        flex-shrink: 0;
    }
}
*/

/* Адаптивность для очень маленьких экранов по высоте (iPhone SE) - отключено при Aspect Ratio Lock */
/*
@media (max-height: 670px) {
    #game-screen.screen.active {
        padding: 4px;
        padding-top: calc(4px + var(--safe-area-top, 0px));
        padding-bottom: calc(4px + var(--safe-area-bottom, 0px));
    }
    
    .game-info {
        padding: 5px 8px;
        margin-bottom: 4px;
    }
    
    .player-info h2 {
        font-size: 14px;
        margin-bottom: 3px;
    }
    
    .stats {
        font-size: 10px;
        gap: 4px;
    }
    
    .boards-container {
        gap: 4px;
        margin-bottom: 4px;
    }
    
    .board-section {
        padding: 3px;
    }
    
    .board-title {
        font-size: 11px;
        margin-bottom: 2px;
    }
    
    #exit-game-btn {
        margin-top: 4px;
        margin-bottom: calc(4px + var(--safe-area-bottom, 0px));
        padding: 8px 14px;
        font-size: 13px;
    }
}
*/

/* Стили для кнопки выхода в игровом экране */
#exit-game-btn {
    flex-shrink: 0; /* Не сжимается */
    margin-top: 8px; /* Уменьшено */
    margin-bottom: calc(8px + var(--safe-area-bottom, 0px));
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 20px; /* Уменьшено для компактности */
    font-size: 16px; /* Уменьшено */
}

/* Предотвращение выделения текста при касании */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Стили для экрана аутентификации */
.auth-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    max-height: calc(var(--available-height, 100vh) - 40px);
    overflow-y: auto;
    overflow-x: hidden;
    /* Плавная прокрутка */
    -webkit-overflow-scrolling: touch;
    /* Предотвращаем изменение размера при открытии клавиатуры */
    position: relative;
    /* Убеждаемся, что контейнер не выходит за границы */
    box-sizing: border-box;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-form h2 {
    color: #1976D2;
    margin-bottom: 20px;
    font-size: 28px;
}

.auth-input {
    width: 100%;
    padding: 12px 15px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    color: #333;
    transition: border-color 0.3s;
    /* Предотвращаем зум при фокусе на iOS */
    font-size: 16px;
    /* Улучшаем отображение на мобильных */
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
}

.auth-input:focus {
    outline: none;
    border-color: #1976D2;
}

.auth-error {
    color: #f44336;
    background: #ffebee;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 10px;
}

.auth-success {
    color: #4caf50;
    background: #e8f5e9;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 10px;
}

.btn-link {
    background: transparent;
    color: #1976D2;
    box-shadow: none;
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    padding: 8px;
    margin: 5px 0;
}

.btn-link:active {
    transform: none;
    opacity: 0.7;
}

.btn-oauth {
    background: white;
    color: #333;
    border: 2px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-oauth:active {
    background: #f5f5f5;
}

.auth-divider {
    position: relative;
    text-align: center;
    margin: 20px 0;
    color: #999;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #e0e0e0;
}

.auth-divider::before {
    left: 0;
}

.auth-divider::after {
    right: 0;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 20px;
    color: white;
}

.user-info #user-name {
    font-weight: 600;
}

/* Стиль для меню - имя пользователя с кнопкой выхода */
.user-info-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.25), rgba(25, 118, 210, 0.2));
    border-radius: 10px;
    margin-bottom: 20px;
    color: white;
    font-size: 16px;
    border: 2px solid rgba(33, 150, 243, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.3s ease-in;
}

.user-info-top .btn-small {
    margin-left: 15px;
    padding: 6px 12px;
    font-size: 13px;
    background: rgba(244, 67, 54, 0.2);
    border: 1px solid rgba(244, 67, 54, 0.4);
    color: white;
    transition: all 0.2s;
}

.user-info-top .btn-small:hover {
    background: rgba(244, 67, 54, 0.3);
    border-color: rgba(244, 67, 54, 0.6);
}

/* Информация о пользователе на всех экранах */
.user-info-top {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.25), rgba(25, 118, 210, 0.2));
    border-radius: 10px;
    margin-bottom: 15px;
    color: white;
    font-size: 16px;
    border: 2px solid rgba(33, 150, 243, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-name-display {
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
}

.user-name-display span {
    color: #64B5F6;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(100, 181, 246, 0.6), 0 1px 2px rgba(0, 0, 0, 0.3);
    margin-left: 5px;
}

.btn-small {
    padding: 5px 15px;
    font-size: 12px;
    margin: 0;
    width: auto;
}

/* ============================================
   НОВЫЙ ДИЗАЙН - ОДНО ПОЛЕ С ПЕРЕКЛЮЧЕНИЕМ
   ============================================ */

/* Верхняя карточка */
.top-card {
    margin: 8px;
    padding: 10px 12px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    box-sizing: border-box;
}

/* Игроки VS */
.players-vs {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.player-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex: 1;
    padding: 4px 6px;
    position: relative;
    transition: all 0.3s ease;
}

.player-item.inactive {
    opacity: 0.5;
}

.player-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 11px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.player-item.active .player-avatar {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.4);
}

.player-name {
    font-size: 11px;
    font-weight: 600;
    color: #333;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-item.active .player-name {
    color: #4CAF50;
    font-weight: 700;
}

.player-item.inactive .player-name {
    color: #999;
}

.turn-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    padding: 1px 6px;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    border-radius: 8px;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(76, 175, 80, 0.4);
}

.player-item.active .turn-badge {
    opacity: 1;
    transform: scale(1);
}

.vs-divider {
    font-size: 12px;
    font-weight: 700;
    color: #ccc;
    padding: 0 8px;
    flex-shrink: 0;
}

/* Нативный индикатор подключения */
.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 9px;
    font-weight: 600;
    margin-bottom: 6px;
    padding: 2px 6px;
    border-radius: 8px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: center;
}

.connection-status.connected {
    color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
}

.connection-status.disconnected {
    color: #F44336;
    background: rgba(244, 67, 54, 0.1);
}

.connection-status .connection-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Сообщение о статусе соединения (для переподключения) */
.connection-status-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    z-index: 10000;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    max-width: 90%;
    word-wrap: break-word;
}

.connection-status-message.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.connection-status-message.connection-status-success {
    background: #4CAF50;
    color: white;
}

.connection-status-message.connection-status-warning {
    background: #FF9800;
    color: white;
}

.connection-status-message.connection-status-error {
    background: #F44336;
    color: white;
}

/* Статистика с визуализацией кораблей */
.stats-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: rgba(25, 118, 210, 0.05);
    border-radius: 8px;
    white-space: nowrap;
    overflow: hidden;
}

.stat-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}

.stat-player-name {
    font-size: 11px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    min-width: 52px;
    flex-shrink: 0;
}

.ships-visual {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    flex-wrap: nowrap;
    justify-content: flex-start;
    min-width: 0;
    overflow: hidden;
}

.ship-type {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(25, 118, 210, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(25, 118, 210, 0.2);
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(25, 118, 210, 0.1);
    flex-shrink: 0;
    white-space: nowrap;
}

.ship-type:hover {
    background: rgba(25, 118, 210, 0.18);
    border-color: rgba(25, 118, 210, 0.35);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(25, 118, 210, 0.25);
}

.ship-visual {
    display: inline-block;
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    border-radius: 4px;
    vertical-align: middle;
    box-shadow: 0 2px 4px rgba(25, 118, 210, 0.4);
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.ship-visual.size-1 {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.ship-visual.size-2 {
    width: 20px;
    height: 12px;
}

.ship-visual.size-3 {
    width: 28px;
    height: 12px;
}

.ship-visual.size-4 {
    width: 36px;
    height: 12px;
}

.ship-count {
    font-size: 10px;
    font-weight: 700;
    color: #1976D2;
    min-width: 20px;
    text-align: center;
    letter-spacing: 0.3px;
}

.stat-total {
    font-size: 16px;
    font-weight: 700;
    color: #1976D2;
    margin-left: 10px;
    padding-left: 10px;
    border-left: 2px solid rgba(25, 118, 210, 0.25);
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
    white-space: nowrap;
}

/* Адаптивные размеры для статистики в зависимости от экрана */
/* Очень маленькие экраны (до 360px) */
@media (max-width: 360px) {
    .stat-item {
        padding: 6px 6px;
    }
    
    .stat-item-left {
        gap: 6px;
    }
    
    .stat-player-name {
        font-size: 9px;
        min-width: 40px;
    }
    
    .ships-visual {
        gap: 4px;
    }
    
    .ship-type {
        padding: 2px 6px;
        gap: 3px;
        border-radius: 6px;
    }
    
    .ship-visual.size-1 {
        width: 8px;
        height: 8px;
    }
    
    .ship-visual.size-2 {
        width: 14px;
        height: 8px;
    }
    
    .ship-visual.size-3 {
        width: 20px;
        height: 8px;
    }
    
    .ship-visual.size-4 {
        width: 26px;
        height: 8px;
    }
    
    .ship-count {
        font-size: 8px;
        min-width: 16px;
    }
    
    .stat-total {
        font-size: 12px;
        margin-left: 6px;
        padding-left: 6px;
        min-width: 20px;
    }
}

/* Маленькие экраны (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
    .stat-item {
        padding: 6px 8px;
    }
    
    .stat-item-left {
        gap: 8px;
    }
    
    .stat-player-name {
        font-size: 10px;
        min-width: 45px;
    }
    
    .ships-visual {
        gap: 5px;
    }
    
    .ship-type {
        padding: 3px 8px;
        gap: 4px;
        border-radius: 8px;
    }
    
    .ship-visual.size-1 {
        width: 10px;
        height: 10px;
    }
    
    .ship-visual.size-2 {
        width: 16px;
        height: 10px;
    }
    
    .ship-visual.size-3 {
        width: 24px;
        height: 10px;
    }
    
    .ship-visual.size-4 {
        width: 30px;
        height: 10px;
    }
    
    .ship-count {
        font-size: 9px;
        min-width: 18px;
    }
    
    .stat-total {
        font-size: 14px;
        margin-left: 8px;
        padding-left: 8px;
        min-width: 22px;
    }
}

/* Средние экраны (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .stat-item {
        padding: 7px 9px;
    }
    
    .stat-item-left {
        gap: 10px;
    }
    
    .stat-player-name {
        font-size: 10.5px;
        min-width: 48px;
    }
    
    .ships-visual {
        gap: 6px;
    }
    
    .ship-type {
        padding: 3px 9px;
        gap: 5px;
        border-radius: 9px;
    }
    
    .ship-visual.size-1 {
        width: 11px;
        height: 11px;
    }
    
    .ship-visual.size-2 {
        width: 18px;
        height: 11px;
    }
    
    .ship-visual.size-3 {
        width: 26px;
        height: 11px;
    }
    
    .ship-visual.size-4 {
        width: 33px;
        height: 11px;
    }
    
    .ship-count {
        font-size: 9.5px;
        min-width: 19px;
    }
    
    .stat-total {
        font-size: 15px;
        margin-left: 9px;
        padding-left: 9px;
        min-width: 23px;
    }
}

/* Большие экраны (769px и выше) - базовые размеры уже установлены */

/* Обновленный board-section для одного поля */
.board-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.board-card {
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    margin: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: white;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

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

/* Скрываем кнопку "Сдаться" в board-header, она теперь в bottom-bar */
.board-header .surrender-btn {
    display: none;
}

.board-title {
    font-size: 16px;
    font-weight: 700;
    color: #1976D2;
}

.board-title.my-turn {
    color: #4CAF50;
}

.board-title.opponent-turn {
    color: #FF9800;
}

.surrender-btn {
    background: linear-gradient(135deg, #F44336 0%, #D32F2F 100%);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
    transition: all 0.2s;
}

.surrender-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

.surrender-btn:active {
    transform: translateY(0);
}

.game-board-container {
    width: 100%;
    position: relative;
}

.game-board-container .game-board {
    width: 100%;
}

/* Плавающая кнопка чата */
.chat-button {
    position: fixed; /* Изменено с absolute на fixed для надежного позиционирования */
    bottom: 80px; /* Выше bottom-bar */
    right: 8px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000; /* Увеличен для надежности */
    transition: all 0.3s ease;
    pointer-events: auto; /* Убеждаемся, что кнопка кликабельна */
    touch-action: manipulation; /* Для мобильных устройств */
}

.chat-button:hover {
    transform: scale(1.1);
}

.chat-button.hidden {
    display: none !important;
}

.chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #F44336;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Контейнер чата */
.chat-container {
    position: fixed;
    bottom: 80px; /* Выше bottom-bar */
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 160px); /* Высота экрана минус bottom-bar и отступы */
    background: white;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000; /* Выше всех элементов */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0) scale(1);
    opacity: 1;
    margin: 0;
    padding: 0;
}

.chat-container.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    border-radius: 12px 12px 0 0;
    color: white;
    font-size: 13px;
    font-weight: 600;
    user-select: none; /* Запрещаем выделение текста */
}

.chat-toggle {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #1976D2;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s;
    font-weight: 600;
    min-width: 70px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-toggle:hover {
    background: white;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chat-toggle:active {
    transform: scale(0.95);
}

.chat-toggle-icon {
    font-size: 18px;
    line-height: 1;
    font-weight: bold;
}

.chat-toggle-text {
    font-size: 11px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    max-height: 120px;
    font-size: 11px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(25, 118, 210, 0.3);
    border-radius: 2px;
}

.chat-message {
    margin-bottom: 6px;
    padding: 4px 6px;
    border-radius: 6px;
    background: rgba(25, 118, 210, 0.05);
    animation: messageAppear 0.3s ease;
}

.chat-message.own {
    background: rgba(76, 175, 80, 0.1);
    text-align: right;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-input-area {
    display: flex;
    gap: 4px;
    padding: 6px;
    border-top: 1px solid #e0e0e0;
}

.chat-input-area .emoji-picker {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
}

.chat-input-area .emoji-btn {
    background: rgba(25, 118, 210, 0.1);
    border: none;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.chat-input-area .emoji-btn:hover {
    background: rgba(25, 118, 210, 0.2);
    transform: scale(1.1);
}

.chat-input-area .emoji-btn:active {
    transform: scale(0.95);
}

.chat-input-area .chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    transition: border-color 0.2s;
}

.chat-input-area .chat-input:focus {
    outline: none;
    border-color: #1976D2;
}

.chat-input-area .chat-send {
    background: #1976D2;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.chat-input-area .chat-send:hover {
    background: #1565C0;
}

.chat-input-area .chat-send:active {
    transform: scale(0.95);
}

/* Анимация переключения поля */
.board-card.switching {
    animation: cardSwitch 0.4s ease;
}

@keyframes cardSwitch {
    0% { 
        opacity: 0.7;
        transform: scale(0.97) rotateY(5deg);
    }
    100% { 
        opacity: 1;
        transform: scale(1) rotateY(0deg);
    }
}

/* Нижняя панель */
.bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    margin: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    width: calc(100% - 16px);
    box-sizing: border-box;
}

.action-hint {
    font-size: 12px;
    color: #666;
    font-style: italic;
    flex: 1;
}

.surrender-btn {
    background: linear-gradient(135deg, #F44336 0%, #D32F2F 100%);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
    transition: all 0.2s;
    white-space: nowrap;
}

.surrender-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

.surrender-btn:active {
    transform: translateY(0);
}

