:root {
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --dark: #2d3436;
    --light: #f5f6fa;
    --success: #00b894;
    --danger: #d63031;
    --warning: #fdcb6e;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light);
    color: var(--dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    overflow-x: hidden;
}

h1 {
    color: var(--primary);
    margin-bottom: 20px;
    font-size: 3rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    animation: titleGlow 2s infinite alternate;
}

@keyframes titleGlow {
    0% {
        text-shadow: 0 0 10px rgba(108, 92, 231, 0.3);
    }

    100% {
        text-shadow: 0 0 20px rgba(108, 92, 231, 0.7);
    }
}

.game-container {
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 30px;
    width: 100%;
    max-width: 500px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.game-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(108, 92, 231, 0.05) 0%, transparent 70%);
    z-index: 0;
    pointer-events: none;
}

.player-setup {
    text-align: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.player-setup h2 {
    color: var(--primary);
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.avatar-selection {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.avatar-option {
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    padding: 8px;
    border-radius: 10px;
    background: rgba(108, 92, 231, 0.05);
    border: 2px solid transparent;
    width: 80px;
}

.avatar-option:hover {
    transform: scale(1.05);
    background: rgba(108, 92, 231, 0.1);
}

.avatar-option.selected {
    background-color: rgba(108, 92, 231, 0.15);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(108, 92, 231, 0.2);
}

.avatar-option img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 5px;
    border: 2px solid rgba(0, 0, 0, 0.1);
}

.avatar-selection h3 {
    width: 100%;
    text-align: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--dark);
}

.avatar-option div {
    font-size: 0.8rem;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.input-group {
    margin-bottom: 15px;
    text-align: left;
    position: relative;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--dark);
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    background-color: rgba(255, 255, 255, 0.8);
}

.input-group input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.input-group input:invalid {
    border-color: var(--danger);
}

.input-group input:invalid:focus {
    box-shadow: 0 0 0 3px rgba(214, 48, 49, 0.2);
}

.difficulty-selector {
    margin: 20px 0;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
}

.difficulty-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--dark);
}

.difficulty-btn:hover {
    border-color: var(--primary);
}

.difficulty-btn.selected {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

.difficulty-btn:disabled {
    opacity: 0.7;
    background-color: #e0e0e0;
    color: #666666;
    cursor: not-allowed;
    box-shadow: none;
}

.difficulty-btn:disabled:hover {
    transform: none;
    background-color: #e0e0e0;
    border-color: #ddd;
}

.scoreboard {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    background-color: var(--light);
    padding: 15px;
    border-radius: 10px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 1;
}

.player {
    text-align: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: bold;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 5px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.player.active .player-avatar {
    border-color: white;
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.player.active {
    background-color: var(--primary);
    color: white;
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.4);
}

.player-x {
    color: var(--danger);
}

.player-o {
    color: var(--success);
}

.score {
    font-size: 1.5rem;
    margin-top: 5px;
    font-weight: bold;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0;
    position: relative;
    z-index: 1;
}

.cell {
    aspect-ratio: 1/1;
    background-color: var(--light);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.cell:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.cell.x {
    color: var(--danger);
}

.cell.o {
    color: var(--success);
}

.cell.winner {
    animation: pulse 1s infinite;
    background-color: rgba(0, 184, 148, 0.1);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cell:hover::before {
    opacity: 1;
}

.controls {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    position: relative;
    z-index: 1;
}

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

button::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    transform: scale(0);
    transition: transform 0.5s ease;
}

button:hover {
    background-color: #5649c5;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(108, 92, 231, 0.4);
}

button:hover::after {
    transform: scale(1);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background-color: #e0e0e0;
    color: #666666;
    cursor: not-allowed;
    box-shadow: none;
}

button:disabled:hover {
    transform: none;
    background-color: #e0e0e0;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(5px);
}

.modal.show {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    transform: scale(0.8);
    transition: all 0.3s ease;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal h2 {
    margin-bottom: 20px;
    color: var(--primary);
    font-size: 2rem;
}

.modal p {
    font-size: 1.2rem;
    margin-bottom: 30px;
}

.confetti {
    position: fixed;
    width: 15px;
    height: 15px;
    background-color: #f00;
    border-radius: 50%;
    animation: confetti-fall 5s linear forwards;
    z-index: 999;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100px) rotate(0deg) translateX(0);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg) translateX(var(--tx, 100px));
        opacity: 0;
    }
}

.emoji-confetti {
    position: fixed;
    font-size: 24px;
    animation: emoji-fall 5s linear forwards;
    z-index: 999;
}

@keyframes emoji-fall {
    0% {
        transform: translateY(-100px) rotate(0deg) translateX(0) scale(0.5);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg) translateX(var(--tx, 100px)) scale(1);
        opacity: 0;
    }
}

.hidden {
    display: none;
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

.dark-mode {
    --primary: #a29bfe;
    --secondary: #6c5ce7;
    --dark: #f5f6fa;
    --light: #2d3436;
    background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
}

.dark-mode .game-container {
    background-color: #1e272e;
    color: #f5f6fa;
}

.dark-mode .input-group input {
    background-color: #2d3436;
    color: #f5f6fa;
    border-color: #57606f;
}

.dark-mode .cell {
    background-color: #2d3436;
}

.dark-mode .scoreboard {
    background-color: #1e272e;
}

.dark-mode .avatar-option {
    background: rgba(162, 155, 254, 0.05);
}

.dark-mode .avatar-option:hover {
    background: rgba(162, 155, 254, 0.1);
}

.dark-mode .avatar-option.selected {
    background-color: rgba(162, 155, 254, 0.15);
}

.dark-mode .avatar-option div {
    color: #f5f6fa;
}

.timer {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--primary);
    text-align: center;
}

.move-history {
    max-height: 100px;
    overflow-y: auto;
    margin-top: 15px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-size: 0.9rem;
}

.move-history p {
    margin: 3px 0;
}

.ai-thinking {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-thinking.show {
    opacity: 1;
}

.ai-thinking span {
    color: white;
    font-size: 1.2rem;
    animation: thinking 1.5s infinite;
}

@keyframes thinking {
    0% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.3;
    }
}

.error-message {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 5px;
    display: none;
}

.game-mode-selector {
    margin: 20px 0;
}

.game-mode-selector label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
}

.game-mode-buttons {
    display: flex;
    gap: 10px;
}

.game-mode-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--dark);
    font-weight: bold;
}

.game-mode-btn:hover {
    border-color: var(--primary);
}

.game-mode-btn.selected {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}