* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --accent: #10b981;
    --accent-light: #34d399;
    --light: #f8fafc;
    --dark: #0f172a;
    --dark-light: #1e293b;
    --gray: #64748b;
    --gray-light: #cbd5e1;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --card-bg: rgba(30, 41, 59, 0.8);
    --glass: rgba(255, 255, 255, 0.1);
    --x-color: #4facfe;
    --o-color: #43e97b;
    --ai-color: #fa709a;
}

[data-theme="light"] {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --accent: #10b981;
    --accent-light: #34d399;
    --light: #0f172a;
    --dark: #f8fafc;
    --dark-light: #e2e8f0;
    --gray: #64748b;
    --gray-light: #475569;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --card-bg: rgba(255, 255, 255, 0.9);
    --glass: rgba(255, 255, 255, 0.7);
    --x-color: #4f46e5;
    --o-color: #10b981;
    --ai-color: #8b5cf6;
}

body {
    background: var(--gradient);
    color: var(--light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-x: hidden;
    transition: all 0.3s ease;
}

.container {
    width: 100%;
    max-width: 500px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 30px;
    margin: 20px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to right, var(--primary), var(--accent));
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

header {
    text-align: left;
}

h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 4px;
    background: linear-gradient(to right, var(--primary-light), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.theme-toggle {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--light);
    font-size: 1.2rem;
}

.theme-toggle:hover {
    transform: rotate(15deg);
    background: rgba(99, 102, 241, 0.2);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    background: var(--glass);
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.player-turn {
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.turn-indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary);
    animation: pulse 2s infinite;
}

.turn-indicator.o {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.turn-indicator.ai {
    background: var(--secondary);
    box-shadow: 0 0 10px var(--secondary);
}

.score {
    display: flex;
    gap: 15px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 15px;
    background: rgba(15, 23, 42, 0.3);
    border-radius: 10px;
    min-width: 70px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .score-item {
    background: rgba(255, 255, 255, 0.5);
}

.score-label {
    font-size: 0.85rem;
    opacity: 0.7;
    font-weight: 500;
}

.score-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--light);
}

.game-settings {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-light);
}

.toggle-buttons {
    display: flex;
    background: var(--glass);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.toggle-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--light);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.toggle-btn.active {
    background: rgba(99, 102, 241, 0.3);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
}

.ai-settings {
    display: none;
    flex-direction: column;
    gap: 15px;
    margin-top: 10px;
    padding: 20px;
    background: var(--glass);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.ai-settings.active {
    display: flex;
}

.board-container {
    background: var(--glass);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 25px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.board-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 12px;
    background: rgba(15, 23, 42, 0.3);
    padding: 15px;
    border-radius: 16px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 1;
}

[data-theme="light"] .board {
    background: rgba(255, 255, 255, 0.5);
}

.cell {
    aspect-ratio: 1;
    background: rgba(30, 41, 59, 0.7);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

[data-theme="light"] .cell {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.cell:hover {
    border-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

/* X Symbol */
.cell.x::before, .cell.x::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 70%;
    background: var(--x-color);
    border-radius: 6px;
    top: 15%;
    left: calc(50% - 6px);
}

.cell.x::before {
    transform: rotate(45deg);
}

.cell.x::after {
    transform: rotate(-45deg);
}

/* O Symbol - Simplified version */
.cell.o::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    border: 8px solid var(--o-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--o-color);
}

.winning-cell {
    animation: pulse 1s infinite alternate;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
    border-color: var(--accent);
}

.winning-cell.x {
    box-shadow: 0 0 20px rgba(79, 172, 254, 0.5);
}

.winning-cell.o {
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.controls {
    display: flex;
    gap: 15px;
}

button {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.reset-btn {
    background: rgba(30, 41, 59, 0.7);
    color: var(--light);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.reset-btn:hover {
    background: rgba(30, 41, 59, 0.9);
    transform: translateY(-2px);
    box-shadow: 0 6px 10px -1px rgba(0, 0, 0, 0.2);
}

.new-game-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
}

.new-game-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 10px -1px rgba(99, 102, 241, 0.5);
}

.message {
    text-align: center;
    margin-top: 20px;
    padding: 16px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1.1rem;
    display: none;
    animation: slideIn 0.5s ease;
    background: rgba(30, 41, 59, 0.7);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .message {
    background: rgba(255, 255, 255, 0.8);
}

.message.win {
    display: block;
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent-light);
    border: 1px solid rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.message.draw {
    display: block;
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.2);
}

.difficulty, .first-move {
    display: flex;
    gap: 10px;
}

.difficulty-btn, .first-move-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--light);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

[data-theme="light"] .difficulty-btn, 
[data-theme="light"] .first-move-btn {
    background: rgba(255, 255, 255, 0.5);
    color: var(--gray-light);
}

.difficulty-btn:hover, .first-move-btn:hover {
    background: rgba(30, 41, 59, 0.9);
}

[data-theme="light"] .difficulty-btn:hover, 
[data-theme="light"] .first-move-btn:hover {
    background: rgba(255, 255, 255, 0.8);
}

.difficulty-btn.active, .first-move-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary);
}

footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

footer a {
    color: var(--primary-light);
    text-decoration: none;
    transition: all 0.3s ease;
}

footer a:hover {
    color: var(--accent-light);
    text-decoration: underline;
}

.heart {
    color: #ef4444;
    animation: heartbeat 1.5s ease infinite;
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 1.8rem;
    }

    button {
        padding: 12px;
    }
    
    .header-container {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .game-info {
        flex-direction: column;
        gap: 15px;
    }
}

@media (min-width: 768px) {
    .game-settings {
        grid-template-columns: 1fr 1fr;
    }
}