﻿* {
    font-family: 'Exo 2', system-ui, sans-serif;
    box-sizing: border-box;
}

:root {
    --glow-x: 0 0 20px rgba(59, 130, 246, 0.6), 0 0 40px rgba(59, 130, 246, 0.3);
    --glow-o: 0 0 20px rgba(239, 68, 68, 0.6), 0 0 40px rgba(239, 68, 68, 0.3);
    --glow-neutral: 0 0 20px rgba(161, 161, 170, 0.4);
}

body {
    background: radial-gradient(ellipse at 20% 80%, rgba(59, 130, 246, 0.15) 0%, transparent 50%), radial-gradient(ellipse at 80% 20%, rgba(239, 68, 68, 0.15) 0%, transparent 50%), radial-gradient(ellipse at 50% 50%, rgba(124, 45, 189, 0.1) 0%, transparent 70%), #09090b;
    overflow: hidden;
    margin: 0;
}

/* Блокируем стандартный скролл браузера на мобильных */
body, html {
    overscroll-behavior: none;
    touch-action: none; /* Важно! Отдает все тачи нашему JS */
}

/* ========== ФОН ========== */
.grid-bg {
    position: fixed;
    inset: 0;
    background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

    .grid-bg::after {
        content: '';
        position: absolute;
        inset: 0;
        background: radial-gradient(ellipse at center, transparent 0%, rgba(9,9,11,0.8) 120%);
    }

/* ========== ВЕРХНЯЯ ПАНЕЛЬ ========== */
.topbar {
    background: rgba(9, 9, 11, 0.95); /* Чуть темнее для читаемости */
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(82,82,91,0.4);
    padding: 12px 16px;
    width: 100%;
}

.header-content {
    display: flex;
    flex-direction: column; /* По умолчанию (мобилка) - колонка */
    gap: 12px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Верхняя строка на мобилке: Лого + Статус */
.header-left {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Нижняя строка на мобилке: Стата + Кнопки */
.header-right {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.stats-row {
    display: flex;
    gap: 8px;
}

.buttons-row {
    display: flex;
    gap: 8px;
    flex: 1; /* Кнопки занимают оставшееся место */
    justify-content: flex-end;
}

.stat-badge {
    background: rgba(39,39,42,0.6);
    border: 1px solid rgba(82,82,91,0.5);
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

    /* Мини-бейджи для телефона */
    .stat-badge.mini {
        padding: 6px 10px;
        font-size: 14px;
    }

    .stat-badge:hover {
        border-color: rgba(161,161,170,0.7);
        background: rgba(50,50,55,0.7);
    }

.score-x {
    color: #60a5fa;
    text-shadow: 0 0 10px rgba(59,130,246,0.5);
    font-weight: 700;
}

.score-o {
    color: #f87171;
    text-shadow: 0 0 10px rgba(239,68,68,0.5);
    font-weight: 700;
}

/* ========== КНОПКИ КОМАНД ========== */
.team-btn {
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
}

    .team-btn::before {
        content: '';
        position: absolute;
        inset: -2px;
        background: linear-gradient(45deg, transparent, rgba(255,255,255,0.3), transparent);
        opacity: 0;
        transition: opacity 0.3s;
        border-radius: inherit;
        pointer-events: none;
    }

    .team-btn:hover::before {
        opacity: 1;
    }

    .team-btn.active {
        box-shadow: var(--glow-x);
        transform: translateY(-2px);
    }

        .team-btn.active[data-team="O"] {
            box-shadow: var(--glow-o);
        }

/* ========== СТАТУС ПОДКЛЮЧЕНИЯ ========== */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: rgba(161,161,170,0.9);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 10px rgba(239,68,68,0.6);
    transition: all 0.3s;
}

    .status-dot.connected {
        background: #22c55e;
        box-shadow: 0 0 10px rgba(34,197,94,0.6);
        animation: pulse-dot 2s infinite;
    }

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* ========== ИГРОВЫЕ ДОСКИ ========== */
.small-board {
    width: 240px;
    background: linear-gradient(145deg, rgba(39,39,42,0.9), rgba(24,24,27,0.95));
    border: 2px solid rgba(82,82,91,0.6);
    border-radius: 24px;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    flex-shrink: 0;
}

    .small-board::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: 22px;
        padding: 2px;
        background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
        -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
        mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
        pointer-events: none;
    }

    .small-board:hover {
        border-color: rgba(161,161,170,0.9);
        transform: translateY(-4px);
        box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 30px rgba(124,45,189,0.2);
    }

    .small-board.winner-x {
        border-color: #3b82f6;
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
    }

    .small-board.winner-o {
        border-color: #ef4444;
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
    }

    .small-board.winner-draw {
        border-color: #a1a1aa;
        box-shadow: 0 0 10px rgba(161, 161, 170, 0.3);
    }

/* ========== ЯЧЕЙКИ ========== */
.cell {
    aspect-ratio: 1 / 1;
    width: 100%;
    font-size: clamp(32px, 5vw, 52px);
    font-weight: 800;
    background: linear-gradient(145deg, rgba(63,63,70,0.8), rgba(39,39,42,0.9));
    border: 2px solid rgba(82,82,91,0.5);
    border-radius: 16px;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer !important;
    user-select: none;
    -webkit-tap-highlight-color: transparent;

    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}

    .cell::after {
        content: '';
        position: absolute;
        inset: 0;
        background: radial-gradient(circle at var(--x,50%) var(--y,50%), rgba(255,255,255,0.15) 0%, transparent 60%);
        opacity: 0;
        transition: opacity 0.2s;
        pointer-events: none;
    }

    .cell:hover {
        border-color: rgba(161,161,170,0.8);
        background: linear-gradient(145deg, rgba(71,71,78,0.9), rgba(50,50,55,0.95));
        transform: scale(1.03);
    }

        .cell:hover::after {
            opacity: 1;
        }

    .cell:active {
        transform: scale(0.97);
        transition-duration: 0.05s;
    }

    .cell.x {
        color: #60a5fa;
        text-shadow: 0 0 20px rgba(59, 130, 246, 0.7);
        animation: pop-in 0.2s ease-out;
    }

    .cell.o {
        color: #f87171;
        text-shadow: 0 0 20px rgba(239, 68, 68, 0.7);
        animation: pop-in 0.2s ease-out;
    }

@keyframes pop-in {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    70% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.disabled {
    cursor: default !important;
    opacity: 0.8;
    filter: grayscale(0.3);
}

/* ========== ВЬЮПОРТ И МИР ========== */
#viewport {
    cursor: grab;
    position: relative;
    z-index: 10;
    background: transparent;
    touch-action: none;
}

    #viewport:active {
        cursor: grabbing;
    }

    #viewport.dragging * {
        pointer-events: none;
    }

#world {
    transition: transform 0.03s ease-out;
    will-change: transform;
    transform-origin: 0 0;
    pointer-events: auto;
}

/* Жесткая фиксация ширины арены, чтобы доски не сжимались */
#bigboard {
    display: grid !important;
    grid-template-columns: repeat(5, 240px) !important; /* 5 колонок строго по 240px */
    gap: 24px !important;
    width: max-content !important; /* Ширина по содержимому, не сжиматься */
    min-width: 1300px; /* Гарантируем минимальную ширину (5 досок + отступы) */
}

/* ========== ПОДСКАЗКА УПРАВЛЕНИЯ ========== */
.controls-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    background: rgba(24,24,27,0.9);
    border: 1px solid rgba(82,82,91,0.5);
    border-radius: 9999px;
    padding: 8px 20px;
    font-size: 14px;
    color: rgba(161,161,170,0.9);
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    animation: fade-in-up 0.4s ease-out forwards;
}

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* ========== ТУЛТИПЫ ========== */
.tooltip {
    position: relative;
}

    .tooltip::after {
        content: attr(data-tip);
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%) translateY(8px);
        background: rgba(24,24,27,0.95);
        color: white;
        padding: 6px 12px;
        border-radius: 8px;
        font-size: 12px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: all 0.2s;
        border: 1px solid rgba(82,82,91,0.5);
        z-index: 100;
    }

    .tooltip:hover::after {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

/* ========== СКРОЛЛБАРЫ ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(39,39,42,0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(82,82,91,0.7);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(161,161,170,0.8);
    }

/* ========== КОНФЕТТИ ========== */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    pointer-events: none;
    z-index: 1000;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100px) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* ========== МОБИЛЬНАЯ АДАПТАЦИЯ ========== */
@media (max-width: 768px) {
    #topbar {
        flex-wrap: wrap;
        gap: 12px !important;
    }

    .team-btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    .controls-hint {
        display: none !important;
    }
}

/* ========== АДАПТИВ ДЛЯ ПЛАНШЕТОВ И ПК (от 768px) ========== */
@media (min-width: 768px) {
    .header-content {
        flex-direction: row; /* В одну строку */
        justify-content: space-between;
        align-items: center;
    }

    .header-right {
        width: auto;
        gap: 20px;
    }

    .buttons-row {
        flex: 0; /* Кнопки не растягиваются */
    }

    .stat-badge.mini {
        padding: 8px 16px;
        font-size: 16px;
    }

    /* Показываем онлайн только на ПК */
    .hidden.sm\:flex {
        display: flex !important;
    }

    /* Показываем текст статуса */
    #statusText {
        display: inline !important;
    }
}