:root {
    /* Dark Theme */
    --bg-color: #1a1a2e;
    --primary-color: #16213e;
    --secondary-color: #0f3460;
    --accent-color: #e94560;
    --font-color: #ffffff;

    /* Light Theme (overrides for light-mode class) */
    --light-bg-color: #f0f2f5;
    --light-primary-color: #ffffff;
    --light-secondary-color: #e0e2e5;
    --light-accent-color: #3498db;
    --light-font-color: #333333;

    --font-family: 'Poppins', sans-serif;
    --cell-size: 100px;
    --border-radius: 10px;
    --box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

body.light-mode {
    --bg-color: var(--light-bg-color);
    --primary-color: var(--light-primary-color);
    --secondary-color: var(--light-secondary-color);
    --accent-color: var(--light-accent-color);
    --font-color: var(--light-font-color);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--font-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background-color: var(--primary-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    width: 100%;
    max-width: 500px; /* Limit container width */
}

/* Player Setup Styles */
.player-setup-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.player-setup-container h2 {
    font-size: 2rem;
    color: var(--accent-color);
    margin-bottom: 1.5rem;
}

.player-input-group {
    width: 80%;
    margin-bottom: 1rem;
    text-align: left;
}

.player-input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.player-input-group input[type="text"] {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--secondary-color);
    border-radius: var(--border-radius);
    background-color: var(--secondary-color);
    color: var(--font-color);
    font-size: 1rem;
}

.player-input-group input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

#start-game-button {
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--font-color);
    background-color: var(--accent-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: var(--box-shadow);
    margin-top: 1.5rem;
    width: 80%;
}

#start-game-button:hover {
    background-color: #d43d51;
    transform: translateY(-2px);
}

.back-button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--font-color);
    background-color: var(--accent-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: var(--box-shadow);
    margin-top: 1.5rem; /* Add margin-top for spacing */
}

.back-button:hover {
    background-color: #d43d51;
    transform: translateY(-2px);
}

/* Game Container Styles (initially hidden) */
#game-container {
    display: none; /* Controlled by JavaScript */
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#game-container.active {
    display: flex;
}

/* Mode Selection Styles */
#mode-selection,
#online-game-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#mode-selection h2,
#online-game-setup h2 {
    font-size: 2rem;
    color: var(--accent-color);
    margin-bottom: 1.5rem;
}

#mode-selection button,
#online-game-setup button {
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--font-color);
    background-color: var(--accent-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: var(--box-shadow);
    margin-top: 1rem;
    width: 80%;
}

#mode-selection button:hover,
#online-game-setup button:hover {
    background-color: #d43d51;
    transform: translateY(-2px);
}

#online-game-setup .player-input-group {
    margin-bottom: 1rem;
}

#online-game-setup #game-id-input {
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 2.5rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
}

#status-container {
    margin-bottom: 1.5rem;
    min-height: 2.2rem;
}

#status-message {
    font-size: 1.5rem;
    font-weight: 600;
    transition: color 0.3s ease;
    animation: statusMessageChange 0.5s ease-out;
}

@keyframes statusMessageChange {
    0% { opacity: 0; transform: translateY(-10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.board {
    display: grid;
    grid-template-columns: repeat(3, var(--cell-size));
    grid-template-rows: repeat(3, var(--cell-size));
    gap: 10px;
    margin-bottom: 1.5rem;
}

.cell {
    width: var(--cell-size));
    height: var(--cell-size);
    background-color: var(--secondary-color);
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.cell.clicked {
    animation: cellClick 0.2s ease-out;
}

@keyframes cellClick {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.cell:not(.x):not(.o):hover {
    background-color: #1e4a8b;
}

.cell.x, .cell.o {
    cursor: not-allowed;
}

.cell.x {
    color: #3498db; /* Azul para X */
}

.cell.o {
    color: #e67e22; /* Laranja para O */
}

/* Animação de vitória */
.cell.winner {
    animation: pulse 0.8s infinite;
}

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

#scoreboard {
    margin-bottom: 1.5rem;
}

h2 {
    margin-bottom: 0.5rem;
}

#restart-button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--font-color);
    background-color: var(--accent-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: var(--box-shadow);
    margin-top: 1.5rem; /* Add margin-top for spacing */
}

#restart-button:hover {
    background-color: #d43d51;
    transform: translateY(-2px);
}

#clear-scores-button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--font-color);
    background-color: var(--accent-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: var(--box-shadow);
    margin-top: 1.5rem; /* Add margin-top for spacing */
}

#clear-scores-button:hover {
    background-color: #d43d51;
    transform: translateY(-2px);
}

/* Responsividade */
@media (max-width: 480px) {
    :root {
        --cell-size: 80px;
    }

    h1 {
        font-size: 2rem;
    }

    #status-message {
        font-size: 1.2rem;
    }

    .container {
        padding: 1.5rem;
    }
}

/* Theme Switch Styles */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

.theme-switch {
    display: inline-block;
    height: 34px;
    position: relative;
    width: 60px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
}

.slider:before {
    background-color: #fff;
    bottom: 4px;
    content: "";
    height: 26px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 26px;
}

input:checked + .slider {
    background-color: var(--accent-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.theme-switch-wrapper em {
    margin-left: 10px;
    font-size: 0.9rem;
    color: var(--font-color);
}
