* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --secondary: #8b5cf6;
    --x-color: #ec4899;
    --o-color: #10b981;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    min-height: 100vh;
    padding: 1rem;
}

.container {
    max-width: 500px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.back-btn {
    position: absolute;
    left: 0;
    top: 0;
    background: white;
    color: var(--primary);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 2px solid var(--primary);
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
}

.back-btn:hover {
    transform: translateX(-5px);
    background: var(--primary);
    color: white;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.back-btn:active {
    transform: translateX(-3px) scale(0.98);
}

.brand h1 {
    color: white;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.brand-text {
    color: rgba(255,255,255,0.9);
    font-size: 0.9rem;
}

.game-container {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.mode-selector {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-btn:hover {
    transform: translateY(-2px);
}

.mode-btn.active {
    background: var(--primary);
    color: white;
}

.game-status {
    margin-bottom: 1.5rem;
}

.player-turn {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
}

.score-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.score-item {
    flex: 1;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 1rem;
    border-radius: 10px;
    text-align: center;
    color: white;
}

.score-label {
    display: block;
    font-size: 0.8rem;
    opacity: 0.9;
    margin-bottom: 0.25rem;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 1.5rem;
    background: var(--primary);
    padding: 10px;
    border-radius: 15px;
}

.cell {
    aspect-ratio: 1;
    background: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.cell:hover:not(.taken) {
    background: #f1f5f9;
    transform: scale(1.05);
}

.cell.x {
    color: var(--x-color);
    animation: placeAnimation 0.3s;
}

.cell.o {
    color: var(--o-color);
    animation: placeAnimation 0.3s;
}

.cell.winner {
    animation: winAnimation 0.6s infinite;
}

.player-names {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.player-name-box {
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    padding: 1rem;
    border-radius: 12px;
    border: 2px solid var(--primary);
}

.player-name-box label {
    display: block;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.player-name-box input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s;
}

.player-name-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.reset-btn, .reset-stats-btn {
    padding: 1rem;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.reset-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.reset-stats-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.reset-btn:hover, .reset-stats-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 5px 20px rgba(99, 102, 241, 0.4);
}

.reset-stats-btn:hover {
    box-shadow: 0 5px 20px rgba(239, 68, 68, 0.4);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    animation: scaleIn 0.3s;
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.modal-btn {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

@keyframes placeAnimation {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes winAnimation {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@media (max-width: 500px) {
    .header {
        margin-bottom: 1.5rem;
    }
    
    .back-btn {
        position: relative;
        left: auto;
        top: auto;
        margin-bottom: 1rem;
        width: 100%;
        justify-content: center;
        padding: 1rem;
        font-size: 1.1rem;
    }
    
    .brand {
        text-align: center;
    }
    
    .brand h1 {
        font-size: 2rem;
    }
    
    .player-names {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        grid-template-columns: 1fr;
    }
    
    .cell {
        font-size: 3rem;
    }
    
    .game-container {
        padding: 1rem;
    }
}
