* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    color: #fff;
    min-height: 100vh;
    padding: 10px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 15px;
    box-shadow: 
        0 10px 25px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Заголовок */
h1 {
    text-align: center;
    margin-bottom: 15px;
    color: #fff;
    text-shadow: 
        0 0 8px rgba(76, 201, 240, 0.7),
        0 0 15px rgba(247, 37, 133, 0.5);
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    background: linear-gradient(45deg, #4cc9f0, #f72585);
    background: -webkit-linear-gradient(45deg, #4cc9f0, #f72585);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    padding: 8px 0;
    line-height: 1.2;
}

.server-info {
    text-align: center;
    margin: 10px 0 20px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.server-info p {
    margin: 5px 0;
}

/* Стили для игроков - мобильная версия */
.players {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.player {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 15px;
    border-radius: 12px;
    min-width: 0;
    flex: 1;
    max-width: 140px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.player::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    background: -webkit-linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
    transition: transform 0.6s;
    -webkit-transition: transform 0.6s;
}

.player:hover::before {
    transform: translateX(100%);
    -webkit-transform: translateX(100%);
}

.player.fedor {
    background: linear-gradient(135deg, rgba(76, 201, 240, 0.2), rgba(58, 12, 163, 0.3));
    background: -webkit-linear-gradient(135deg, rgba(76, 201, 240, 0.2), rgba(58, 12, 163, 0.3));
    border: 2px solid #4cc9f0;
    box-shadow: 0 4px 15px rgba(76, 201, 240, 0.2);
}

.player.nefedor {
    background: linear-gradient(135deg, rgba(247, 37, 133, 0.2), rgba(181, 23, 158, 0.3));
    background: -webkit-linear-gradient(135deg, rgba(247, 37, 133, 0.2), rgba(181, 23, 158, 0.3));
    border: 2px solid #f72585;
    box-shadow: 0 4px 15px rgba(247, 37, 133, 0.2);
}

.player-icon {
    font-size: clamp(2rem, 8vw, 2.5rem);
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
    text-shadow: 0 2px 8px currentColor;
}

.player.fedor .player-icon {
    color: #4cc9f0;
}

.player.nefedor .player-icon {
    color: #f72585;
}

.player-name {
    font-size: clamp(0.9rem, 4vw, 1.1rem);
    font-weight: bold;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

.vs {
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    font-weight: bold;
    color: #ffaa00;
    text-shadow: 
        0 0 8px rgba(255, 170, 0, 0.7),
        0 0 15px rgba(255, 170, 0, 0.5);
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    min-width: 50px;
    text-align: center;
}

/* Ход игрока */
.turn {
    text-align: center;
    font-size: clamp(1rem, 4vw, 1.2rem);
    margin: 15px 0;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#turn {
    font-weight: bold;
    color: #ffaa00;
    font-size: clamp(1.1rem, 5vw, 1.4rem);
}

/* Игровое поле - адаптивное и компактное */
.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 20px auto;
    width: min(90vw, 300px); /* Ограничиваем максимальную ширину */
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.cell {
    aspect-ratio: 1;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0.2));
    background: -webkit-linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0.2));
    border: none;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2rem, 10vw, 3rem);
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    background: -webkit-linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
}

.cell:active {
    transform: scale(0.95);
    -webkit-transform: scale(0.95);
}

.cell.f {
    color: #4cc9f0;
    text-shadow: 
        0 0 12px rgba(76, 201, 240, 0.8),
        0 0 25px rgba(76, 201, 240, 0.4);
    font-weight: 900;
}

.cell.n {
    color: #f72585;
    text-shadow: 
        0 0 12px rgba(247, 37, 133, 0.8),
        0 0 25px rgba(247, 37, 133, 0.4);
    font-weight: 900;
}

/* Кнопки управления - адаптивные */
.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
    width: 100%;
}

button {
    padding: clamp(14px, 4vw, 16px) clamp(20px, 6vw, 24px);
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: clamp(0.9rem, 3.5vw, 1rem);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s;
}

button:active {
    transform: scale(0.98);
    -webkit-transform: scale(0.98);
}

#reset {
    background: linear-gradient(45deg, #7209b7, #3a0ca3);
    background: -webkit-linear-gradient(45deg, #7209b7, #3a0ca3);
    border: 2px solid #7209b7;
}

#hint-btn {
    background: linear-gradient(45deg, #4cc9f0, #4895ef);
    background: -webkit-linear-gradient(45deg, #4cc9f0, #4895ef);
    border: 2px solid #4cc9f0;
}

#troll-btn {
    background: linear-gradient(45deg, #f72585, #b5179e);
    background: -webkit-linear-gradient(45deg, #f72585, #b5179e);
    border: 2px solid #f72585;
}

/* История игры - адаптивная */
.log {
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 12px;
    margin-top: 20px;
    max-height: min(40vh, 200px);
    overflow-y: auto;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    line-height: 1.4;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.log p {
    margin: 8px 0;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    border-left: 3px solid;
    word-break: break-word;
}

.log p:first-child {
    border-left-color: #4cc9f0;
}

.log p:nth-child(2) {
    border-left-color: #f72585;
}

.log p:nth-child(3) {
    border-left-color: #ffaa00;
}

/* Победа и анимации */
.winning-cell {
    animation: winPulse 0.8s infinite;
    background: linear-gradient(135deg, rgba(76, 201, 240, 0.3), rgba(247, 37, 133, 0.3)) !important;
}

@keyframes winPulse {
    0%, 100% { 
        transform: scale(1);
        -webkit-transform: scale(1);
        box-shadow: 0 0 15px currentColor;
    }
    50% { 
        transform: scale(1.08);
        -webkit-transform: scale(1.08);
        box-shadow: 0 0 30px currentColor;
    }
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(15px); 
        -webkit-transform: translateY(15px);
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
        -webkit-transform: translateY(0);
    }
}

/* Адаптация для горизонтальной ориентации */
@media (orientation: landscape) and (max-height: 600px) {
    body {
        padding: 5px;
    }
    
    .container {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px;
    }
    
    .players {
        flex: 0 0 auto;
        width: 100%;
        margin-bottom: 10px;
    }
    
    .game-board {
        flex: 1;
        max-width: 50vh;
        margin: 0;
    }
    
    .controls {
        flex: 0 0 200px;
        margin: 0;
        flex-direction: column;
    }
    
    .log {
        flex: 0 0 100%;
        max-height: 30vh;
        margin-top: 10px;
    }
    
    .turn {
        order: -1;
        flex: 0 0 100%;
        margin: 0 0 10px 0;
    }
}

/* Планшеты и большие телефоны */
@media (min-width: 768px) {
    .container {
        max-width: 700px;
        margin: 20px auto;
        padding: 25px;
    }
    
    .players {
        gap: 30px;
    }
    
    .player {
        padding: 15px 25px;
        max-width: 160px;
    }
    
    .controls {
        flex-direction: row;
        justify-content: center;
        gap: 15px;
    }
    
    button {
        width: auto;
        min-width: 160px;
        max-width: 200px;
    }
    
    .game-board {
        width: min(90vw, 400px);
        gap: 12px;
        padding: 20px;
    }
    
    .cell {
        font-size: clamp(2.5rem, 8vw, 4rem);
    }
}

/* Десктопы */
@media (min-width: 1024px) {
    .container {
        max-width: 800px;
        padding: 30px;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    .player {
        max-width: 180px;
    }
    
    .player-icon {
        font-size: 3rem;
    }
    
    .player-name {
        font-size: 1.3rem;
    }
    
    .vs {
        font-size: 1.8rem;
    }
    
    .game-board {
        width: min(90vw, 450px);
    }
}

/* Очень маленькие телефоны */
@media (max-width: 320px) {
    .player {
        padding: 8px 10px;
        min-width: 0;
    }
    
    .player-name {
        font-size: 0.8rem;
    }
    
    .vs {
        padding: 3px 6px;
        min-width: 40px;
        font-size: 1rem;
    }
    
    .game-board {
        width: 95vw;
        gap: 5px;
        padding: 10px;
    }
    
    button {
        padding: 12px 15px;
        font-size: 0.85rem;
    }
}

/* Поддержка темной/светлой темы */
@media (prefers-color-scheme: light) {
    body {
        background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 50%, #a5b4fc 100%);
        color: #1e293b;
    }
    
    .container {
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid rgba(99, 102, 241, 0.2);
    }
    
    .player.fedor {
        background: linear-gradient(135deg, rgba(76, 201, 240, 0.3), rgba(58, 12, 163, 0.2));
        border-color: #4cc9f0;
    }
    
    .player.nefedor {
        background: linear-gradient(135deg, rgba(247, 37, 133, 0.3), rgba(181, 23, 158, 0.2));
        border-color: #f72585;
    }
    
    .cell {
        background: linear-gradient(145deg, rgba(255, 255, 255, 0.8), rgba(226, 232, 240, 0.9));
    }
    
    .log {
        background: rgba(255, 255, 255, 0.7);
        border-color: rgba(99, 102, 241, 0.2);
    }
    
    .log p {
        background: rgba(255, 255, 255, 0.9);
    }
}

/* Улучшение для устройств с большими вырезами (iPhone X и новее) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
        padding-top: max(15px, env(safe-area-inset-top));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
}

/* Улучшение производительности на мобильных */
.cell, button, .player {
    will-change: transform;
    backface-visibility: hidden;
}

/* Кастомный скроллбар для лога */
.log::-webkit-scrollbar {
    width: 6px;
}

.log::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.log::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #4cc9f0, #f72585);
    border-radius: 3px;
}

.log::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #f72585, #4cc9f0);
}

/* Анимация появления элементов */
.container > * {
    animation: fadeIn 0.5s ease-out backwards;
}

.container > *:nth-child(1) { animation-delay: 0.1s; }
.container > *:nth-child(2) { animation-delay: 0.2s; }
.container > *:nth-child(3) { animation-delay: 0.3s; }
.container > *:nth-child(4) { animation-delay: 0.4s; }
.container > *:nth-child(5) { animation-delay: 0.5s; }
.container > *:nth-child(6) { animation-delay: 0.6s; }
.container > *:nth-child(7) { animation-delay: 0.7s; }

/* Уведомления для пользователя */
@media (max-width: 768px) {
    .mobile-hint {
        display: block;
        text-align: center;
        font-size: 0.8rem;
        color: #94a3b8;
        margin-top: 10px;
        font-style: italic;
    }
}

/* Для очень высоких экранов */
@media (min-height: 1000px) {
    .container {
        margin-top: 5vh;
        margin-bottom: 5vh;
    }
    
    .game-board {
        width: min(90vw, 500px);
    }
    
    .cell {
        font-size: 4rem;
    }
}