* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    max-width: 500px;
    width: 90%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    text-align: center;
}

header .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

header h1 {
    color: #333;
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0;
}

.language-selector {
    display: flex;
    align-items: center;
}

.language-select {
    padding: 0.5rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.language-select:focus {
    outline: none;
    border-color: #667eea;
}

.menu {
    animation: fadeIn 0.5s ease-in;
}

.menu h2 {
    color: #555;
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

.btn {
    display: block;
    width: 100%;
    padding: 1rem 2rem;
    margin: 1rem 0;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn.primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.btn.secondary {
    background: #f8f9fa;
    color: #333;
    border: 2px solid #dee2e6;
}

.btn.secondary:hover {
    background: #e9ecef;
    transform: translateY(-2px);
}

.btn.tertiary {
    background: linear-gradient(45deg, #28a745, #20c997);
    color: white;
}

.btn.tertiary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(40, 167, 69, 0.3);
}

.btn.small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin: 0.5rem 0;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.input-group {
    margin: 1.5rem 0;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
    font-weight: 600;
}

.input-group input {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 300px;
    margin: 2rem auto;
    animation: slideIn 0.5s ease-out;
}

.cell {
    aspect-ratio: 1;
    background: #f8f9fa;
    border: 3px solid #dee2e6;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}

.cell:hover {
    background: #e9ecef;
    transform: scale(1.05);
}

.cell.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.cell.x {
    color: #e74c3c;
}

.cell.o {
    color: #3498db;
}

.game-info {
    margin-bottom: 1rem;
}

.game-mode {
    font-size: 1.2rem;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.current-player {
    font-size: 1.1rem;
    color: #555;
    margin-bottom: 0.5rem;
}

.status {
    padding: 1rem;
    margin: 1rem 0;
    border-radius: 8px;
    font-weight: 600;
}

.status.waiting {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status.success {
    background: #d1edff;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.status.winner {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    font-size: 1.2rem;
}

.status.draw {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    font-size: 1.2rem;
}

.game-controls {
    margin-top: 2rem;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.winner-animation {
    animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

/* Statistics styles */
.stats-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 2rem;
    justify-content: center;
}

.tab-btn {
    padding: 0.8rem 1.5rem;
    border: 2px solid #dee2e6;
    background: #f8f9fa;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.tab-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.tab-btn:hover {
    transform: translateY(-2px);
}

.stats-content {
    animation: fadeIn 0.3s ease-in;
}

.stats-display {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1rem 0;
    text-align: left;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 0;
    border-bottom: 1px solid #dee2e6;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    font-weight: 600;
    color: #555;
}

.stat-value {
    font-weight: bold;
    font-size: 1.1rem;
}

.stat-value.wins {
    color: #28a745;
}

.stat-value.losses {
    color: #dc3545;
}

.stat-value.draws {
    color: #ffc107;
}

.stat-value.winrate {
    color: #667eea;
}

.leaderboard {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 1rem;
    margin: 1rem 0;
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    margin: 0.5rem 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.leaderboard-item:hover {
    transform: translateY(-2px);
}

.leaderboard-item.top3 {
    background: linear-gradient(45deg, #ffd700, #ffed4e);
    color: #333;
}

.leaderboard-rank {
    font-weight: bold;
    font-size: 1.2rem;
    min-width: 30px;
}

.leaderboard-name {
    flex-grow: 1;
    margin-left: 1rem;
    font-weight: 600;
}

.leaderboard-stats {
    text-align: right;
    font-size: 0.9rem;
}

.leaderboard-wins {
    font-weight: bold;
    color: #28a745;
}

.leaderboard-winrate {
    color: #667eea;
    font-size: 0.8rem;
}

.no-stats {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 2rem;
}

/* Chat styles */
.global-chat {
    margin-top: 2rem;
    background: #f8f9fa;
    border-radius: 15px;
    padding: 1.5rem;
    max-width: 100%;
}

.global-chat h3 {
    margin: 0 0 1rem 0;
    color: #667eea;
    font-size: 1.1rem;
    text-align: center;
}

.chat-messages {
    height: 200px;
    overflow-y: auto;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    padding: 0.8rem;
    background: white;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.chat-message {
    margin-bottom: 0.8rem;
    padding: 0.5rem;
    border-radius: 8px;
    word-wrap: break-word;
}

.chat-message.own {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    margin-left: 20%;
    text-align: right;
    border-radius: 15px 15px 5px 15px;
}

.chat-message.own .chat-message-author {
    color: #e8eaf6;
    font-weight: 600;
}

.chat-message.own .chat-message-time {
    color: #c5cae9;
}

.chat-message.other {
    background: #f5f5f5;
    margin-right: 20%;
    border-radius: 15px 15px 15px 5px;
}

.chat-message.other .chat-message-author {
    color: #667eea;
    font-weight: 600;
}

.chat-message.system {
    background: #fff3cd;
    text-align: center;
    font-style: italic;
    color: #856404;
    margin: 0.5rem 10%;
}

.chat-message-author {
    font-weight: bold;
    color: #667eea;
    font-size: 0.8rem;
    margin-bottom: 0.2rem;
}

.chat-message-text {
    line-height: 1.4;
}

.chat-message-time {
    font-size: 0.7rem;
    color: #888;
    margin-top: 0.2rem;
}

.chat-input-container {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.chat-input-container input {
    flex: 1;
    padding: 0.6rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 0.9rem;
}

.chat-input-container input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-input-container .btn {
    margin: 0;
    white-space: nowrap;
    padding: 0.6rem 1rem;
}

/* Chat Preview in Main Menu */
.chat-preview {
    margin-top: 2rem;
    background: #f8f9fa;
    border-radius: 15px;
    padding: 1rem;
}

.chat-preview-messages {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    padding: 0.8rem;
    margin-top: 1rem;
    height: 60px;
    overflow: hidden;
    font-size: 0.8rem;
    color: #666;
}

.chat-preview-text {
    font-style: italic;
    text-align: center;
    color: #888;
    line-height: 2.5;
}

/* Game Chat Notification */
.game-chat-notification {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 1rem;
    margin: 1rem 0;
    text-align: center;
}

.new-message-indicator {
    background: #28a745;
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    margin-top: 0.5rem;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Chat toggle animation */
.chat-slide-in {
    animation: slideIn 0.3s ease-out;
}

.chat-slide-out {
    animation: slideOut 0.3s ease-in;
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateY(0);
        max-height: 300px;
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
        max-height: 0;
    }
}

/* Online indicator */
.online-count {
    background: #28a745;
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 15px;
    font-size: 0.8rem;
    margin-left: 0.5rem;
    display: inline-block;
}

/* Кнопка открытия чата */
.chat-open-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
}

.chat-open-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}

.chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #ff4757;
    border-radius: 50%;
    color: white;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: bounce 1s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
    50% { box-shadow: 0 5px 25px rgba(102, 126, 234, 0.5); }
    100% { box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* External Chat Container */
.chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    max-height: 500px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    animation: slideInUp 0.3s ease-out;
}

.chat-container.hidden {
    display: none;
}

.chat-container.minimized {
    max-height: 60px;
}

.chat-container.minimized .chat-content,
.chat-container.minimized .chat-tabs {
    display: none;
}

.chat-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 1rem;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.chat-controls {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.3);
}

.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.chat-tab-content {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 0;
}

.chat-tab-content.active {
    display: flex;
}

.chat-messages-external {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    max-height: 280px;
    min-height: 200px;
}

.chat-input-container-external {
    padding: 1rem;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 0.5rem;
}

.chat-input-container-external input {
    flex: 1;
    padding: 0.8rem;
    border: 2px solid #dee2e6;
    border-radius: 25px;
    font-size: 0.9rem;
    outline: none;
}

.chat-input-container-external input:focus {
    border-color: #667eea;
}

.chat-tabs {
    display: flex;
    background: #f8f9fa;
    border-radius: 0 0 15px 15px;
}

.chat-tab {
    flex: 1;
    padding: 0.8rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.chat-tab.active {
    background: white;
    border-bottom-color: #667eea;
    color: #667eea;
    font-weight: 600;
}

.chat-tab:hover {
    background: #e9ecef;
}

.chat-tab.hidden {
    display: none !important;
}

/* Game chat tab initially hidden */
#gameChatTab {
    display: none;
}

/* Open Chat Button */
.open-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    z-index: 999;
    transition: all 0.3s ease;
}

.open-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive design */
@media (max-width: 480px) {
    .container {
        padding: 1.5rem;
    }
    
    header .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .language-select {
        font-size: 0.8rem;
        padding: 0.4rem;
    }
    
    .board {
        max-width: 250px;
    }
    
    .cell {
        font-size: 2rem;
    }
    
    .btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }
    
    .global-chat {
        margin-top: 1rem;
        padding: 1rem;
    }
    
    .chat-messages {
        height: 150px;
        font-size: 0.8rem;
    }
    
    .chat-input-container {
        flex-direction: column;
        gap: 0.3rem;
    }
    
    .game-chat .chat-messages {
        height: 120px;
    }
    
    .chat-container {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .chat-header {
        border-radius: 0;
    }
    
    .open-chat-btn {
        bottom: 80px;
        right: 50%;
        transform: translateX(50%);
    }
    
    .chat-preview {
        margin-top: 1rem;
        padding: 0.8rem;
    }
    
    .chat-preview-messages {
        height: 40px;
        font-size: 0.7rem;
    }
    
    /* Mobile chat message adjustments */
    .chat-message.own {
        margin-left: 10%;
        border-radius: 12px 12px 4px 12px;
    }
    
    .chat-message.other {
        margin-right: 10%;
        border-radius: 12px 12px 12px 4px;
    }
}

/* Мобильная адаптация для чата */
@media (max-width: 768px) {
    .game-container {
        padding: 1rem;
        margin: 0.5rem;
    }
    
    .game-board {
        width: 280px;
        height: 280px;
    }
    
    .cell {
        font-size: 2rem;
    }
    
    .menu-buttons {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .btn {
        width: 100%;
        padding: 0.8rem;
    }
    
    /* Мобильная адаптация чата */
    .chat-container {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 15px 15px 0 0;
        animation: slideInUp 0.3s ease-out;
    }
    
    .chat-open-btn {
        bottom: 15px;
        right: 15px;
        width: 55px;
        height: 55px;
        font-size: 1.3rem;
    }
    
    .chat-messages-external {
        max-height: 200px;
        min-height: 150px;
    }
    
    .game-container.with-chat {
        margin-bottom: 80px;
    }
}