:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #888888;
    --color-x: #ff6b6b;
    /* Pastel Red/Pink */
    --color-o: #4ecdc4;
    /* Pastel Teal/Cyan */
    --color-draw: #ffd166;
    /* Pastel Yellow */
    --shadow-soft: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff;
    --shadow-inset: inset 4px 4px 8px #d1d9e6, inset -4px -4px 8px #ffffff;
    --board-border: #e0e5ec;
    --win-bg: rgba(255, 255, 255, 0.5);
    --transition-speed: 0.3s;
}

body[data-theme="dark"] {
    --bg-color: #242629;
    --card-bg: #16161a;
    --text-main: #fffffe;
    --text-muted: #94a1b2;
    --shadow-soft: 8px 8px 16px #1e2023, -8px -8px 16px #2a2c30;
    --shadow-inset: inset 4px 4px 8px #1e2023, inset -4px -4px 8px #2a2c30;
    --board-border: #16161a;
    --win-bg: rgba(255, 255, 255, 0.05);
    /* Lighter background highlight for dark mode */
}

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

body {
    /* font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center; */
    /* height: 100vh; */
    /* padding: 2vh 2vw; */
    /* overflow: hidden; */
    /* Prevent body level scroll */
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;

    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2vh 2vw;
}



.container {
    flex: 1;
    background-color: var(--bg-color);
    /* Match body for neumorphism */
    border-radius: 24px;
    padding: 3vh 5vw;
    box-shadow: var(--shadow-soft);
    text-align: center;
    max-width: 500px;
    width: 100%;
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1vh;
    transition: background-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2vh;
}

.theme-btn {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--transition-speed) ease;
}

.theme-btn:active {
    box-shadow: var(--shadow-inset);
    transform: translateY(2px);
}

header h1 {
    font-weight: 600;
    font-size: 2.2rem;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.mode-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.mode-btn {
    background-color: var(--bg-color);
    border: none;
    border-radius: 12px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: all var(--transition-speed) ease;
    font-family: 'Inter', sans-serif;
}

.mode-btn:hover {
    color: var(--text-main);
}

.mode-btn.active {
    box-shadow: var(--shadow-inset);
    color: var(--text-main);
}

.scoreboard {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.score-card {
    flex: 1;
    background-color: var(--bg-color);
    padding: 1vh 1vw;
    /* Adjusted padding to be proportional */
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.score-card.active-turn {
    transform: translateY(-5px);
    box-shadow: 12px 12px 20px #d1d9e6, -12px -12px 20px #ffffff;
}

.player-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.score {
    font-size: 2rem;
    font-weight: 600;
}

.player-x .player-name,
.player-x .score {
    color: var(--color-x);
}

.player-o .player-name,
.player-o .score {
    color: var(--color-o);
}

.message-area {
    font-size: 1.2rem;
    font-weight: 600;
    min-height: 1.5em;
    color: var(--text-main);
    transition: color var(--transition-speed) ease;
}

.message-area.win-x {
    color: var(--color-x);
}

.message-area.win-o {
    color: var(--color-o);
}

.message-area.draw {
    color: var(--color-draw);
}

.board-container {
    display: flex;
    justify-content: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, min(25vw, 12vh, 90px));
    grid-template-rows: repeat(3, min(25vw, 12vh, 90px));
    gap: min(2vw, 1.5vh, 12px);
    margin: 0 auto;
}

.cell {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(2.5rem, 10vmin, 4rem);
    font-weight: 300;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    user-select: none;
}

.cell:hover:not(.taken) {
    box-shadow: 4px 4px 8px #d1d9e6, -4px -4px 8px #ffffff;
    transform: scale(0.98);
}

.cell.taken {
    cursor: default;
    box-shadow: var(--shadow-inset);
}

/* Colors for marks */
.cell[data-mark="X"] {
    color: var(--color-x);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.cell[data-mark="O"] {
    color: var(--color-o);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

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

.cell.winning-cell {
    background-color: var(--win-bg);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: var(--shadow-inset);
    }

    100% {
        transform: scale(1.05);
        box-shadow: var(--shadow-soft);
    }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
}

.control-btn {
    background-color: var(--bg-color);
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: all var(--transition-speed) ease;
    font-family: 'Inter', sans-serif;
}

.control-btn:hover {
    box-shadow: 4px 4px 8px #d1d9e6, -4px -4px 8px #ffffff;
    transform: translateY(2px);
}

.control-btn:active {
    box-shadow: var(--shadow-inset);
    transform: translateY(4px);
}

footer {
     height: 10vh;
    width: 100%;

    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 2vh;
    background-color: var(--card-bg);
    box-shadow: 0 -4px 10px rgba(0,0,0,0.05);

    font-size: 0.9rem;
    color: var(--text-muted);
    border-radius: 16px;
}

footer p {
    margin: 0;
    transition: color var(--transition-speed) ease;
}

footer p:hover {
    color: var(--text-main);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .container {
        padding: 20px;
        border-radius: 16px;
    }

    .board {
        grid-template-columns: repeat(3, 80px);
        grid-template-rows: repeat(3, 80px);
        gap: 10px;
    }

    .cell {
        width: 80px;
        height: 80px;
        font-size: 3rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .mode-selector {
        flex-direction: column;
        align-items: center;
    }

    .mode-btn {
        width: 100%;
        max-width: 250px;
    }

    .controls {
        flex-direction: column;
        align-items: center;
    }

    .control-btn {
        width: 100%;
        max-width: 200px;
    }
}