@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');

:root {
    --bg-dark: #111111;
    --bg-medium: #1a1a1a;
    --bg-light: #252525;
    --accent-green: #00ff9d;
    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --color-x: #00aaff;
    --color-o: #ff44aa;
    --font-main: 'Roboto Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

/* --- Welcome Page & Background Animation --- */
#background-animation {
    position: fixed; top: -10%; left: -10%;
    width: 120%; height: 120%;
    display: grid; grid-template-columns: repeat(9, 1fr);
    gap: 5px; z-index: 0; opacity: 0.05;
}
.bg-cell {
    background-color: var(--bg-light);
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
}
.bg-cell .x, .bg-cell .o { font-size: 2rem; transition: opacity 2s ease-out; }

.game-setup {
    position: relative; z-index: 1; text-align: center;
}
.setup-content {
    background: rgba(26, 26, 26, 0.5);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    padding: 3rem 4rem; border-radius: 16px;
    border: 1px solid var(--bg-light);
}
.setup-content h1 { font-size: 2.5rem; margin-bottom: 0.5rem; color: var(--accent-green); }
.setup-content .subtitle { font-size: 1rem; color: var(--text-secondary); margin-bottom: 2.5rem; }

/* --- Main Game & Header --- */
.game-container {
    display: flex; flex-direction: column; gap: 1rem;
    position: relative; z-index: 1;
}
.game-header {
    display: flex; justify-content: space-between; align-items: center; width: 100%;
}
.status-display {
    display: flex; gap: 1rem; background: var(--bg-medium);
    padding: 0.5rem 1rem; border-radius: 10px;
}
.player-info {
    font-weight: 700; transition: all 0.3s ease; opacity: 0.4;
}
.player-info.active-player { opacity: 1; transform: scale(1.05); }
#player-x-display.active-player { color: var(--color-x); }
#player-o-display.active-player { color: var(--color-o); }

/* --- Game Board --- */
.main-board {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px; background-color: var(--bg-medium);
    padding: 8px; border-radius: 12px;
}
.small-board {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
    position: relative; border-radius: 8px;
    border: 2px solid transparent; transition: all 0.3s ease;
}
.cell {
    width: 55px; height: 55px;
    background-color: var(--bg-dark); border-radius: 6px;
    display: flex; justify-content: center; align-items: center;
    cursor: pointer; transition: background-color 0.2s ease;
    position: relative; font-size: 2.5rem; font-weight: 700;
}
.cell.x { color: var(--color-x); }
.cell.o { color: var(--color-o); }
.cell:not(.x):not(.o):hover { background-color: var(--bg-light); }
.cell .mark { animation: pop-in 0.3s ease; }

/* --- Highlighting & Animations --- */
.small-board.active-board { border-color: var(--accent-green); }
.small-board.next-move-indicator { border-color: rgba(255, 255, 255, 0.4); border-style: dashed; }
.cell.last-move::after {
    content: ''; position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border-radius: 8px; animation: flash 0.8s ease-out;
    pointer-events: none;
}
@keyframes flash {
    0%, 100% { border: 2px solid transparent; }
    50% { border: 2px solid var(--accent-green); }
}
.small-board.won { opacity: 0.7; }
.small-board.won::after {
    content: attr(data-winner); position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26, 26, 26, 0.8);
    display: flex; align-items: center; justify-content: center;
    font-size: 4rem; font-weight: 700;
    color: var(--accent-green);
    border-radius: 6px; animation: pop-in 0.3s ease;
    z-index: 10;
}
.small-board.won.x-win::after { color: var(--color-x); }
.small-board.won.o-win::after { color: var(--color-o); }
@keyframes pop-in { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --- Footer & Buttons & Modals --- */
.game-footer { height: 24px; }
.status-text {
    font-size: 1rem; font-weight: 700; text-align: center;
    color: var(--accent-green); height: 100%;
}
button {
    font-family: var(--font-main); font-weight: 700;
    padding: 0.7rem 1.2rem; border-radius: 8px;
    cursor: pointer; border: 1px solid var(--bg-light);
    background-color: var(--bg-medium); color: var(--text-primary);
    transition: all 0.2s ease;
}
button:hover { background-color: var(--accent-green); color: var(--bg-dark); border-color: var(--accent-green); }
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal-overlay.visible { opacity: 1; pointer-events: all; }
.modal {
    background: var(--bg-medium); padding: 2rem;
    border-radius: 12px; border: 1px solid var(--bg-light);
    max-width: 500px; text-align: center;
    transform: scale(0.95); transition: transform 0.3s ease;
}
.modal-overlay.visible .modal { transform: scale(1); }
.modal h2 { margin-bottom: 1rem; color: var(--accent-green); }
.modal p { margin-bottom: 0.5rem; line-height: 1.6; color: var(--text-secondary); }
.modal p strong { color: var(--text-primary); }
.modal .modal-buttons { margin-top: 1.5rem; }

.hidden { display: none !important; }