:root {
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --board-bg: #2a2a2a;
    --border-thick: 4px solid #404040;
    --border-thin: 2px solid #333333;
    --x-color: #ff5555;
    --o-color: #55aaff;
    --active-board-bg: rgba(255, 255, 255, 0.05);
    --active-board-border: 4px solid #888888;
    --won-x-bg: rgba(255, 85, 85, 0.15);
    --won-o-bg: rgba(85, 170, 255, 0.15);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    user-select: none;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 600px;
    padding: 15px;
}

header {
    text-align: center;
}

h1 {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    margin-bottom: 15px;
    color: #ffffff;
}

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

select, button {
    background-color: #333;
    color: #fff;
    border: 1px solid #555;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
}

select:hover, button:hover:not(:disabled) {
    background-color: #444;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.status-msg {
    font-size: 1.1rem;
    height: 1.5rem;
    color: #aaaaaa;
    word-wrap: break-word;
    max-width: 600px;
}

/* Board Layout */
.board-wrapper {
    background-color: var(--board-bg);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1 / 1;
}

.global-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    background-color: #404040; /* acts as borders */
    border: var(--border-thick);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100%;
}

.global-board.disabled {
    pointer-events: none;
    opacity: 0.7;
}

.local-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    background-color: #333333; /* local borders */
    width: 100%;
    height: 100%;
    position: relative;
}

/* Big X or O overlay for a won local board */
.local-board::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 8rem;
    font-weight: 800;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.local-board.won-X { background-color: var(--won-x-bg); }
.local-board.won-X::after {
    content: 'X';
    color: var(--x-color);
    opacity: 0.9;
}
.local-board.won-O { background-color: var(--won-o-bg); }
.local-board.won-O::after {
    content: 'O';
    color: var(--o-color);
    opacity: 0.9;
}
.local-board.draw { background-color: rgba(255,255,255,0.05); }

/* Fade out cells when board is won */
.local-board.won-X .cell, .local-board.won-O .cell, .local-board.draw .cell {
    opacity: 0.1;
}

/* Active local board highlight */
.local-board.active {
    background-color: var(--active-board-bg);
    outline: 3px solid #888888;
    outline-offset: -3px;
    z-index: 5;
}

.cell {
    background-color: var(--board-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.cell:hover {
    background-color: #383838;
}

.global-board.disabled .cell {
    cursor: not-allowed;
}

/* SVG paths for X and O */
.cell svg {
    width: 60%;
    height: 60%;
}

.path-o {
    fill: none;
    stroke: var(--o-color);
    stroke-width: 8;
    stroke-linecap: round;
}

.path-x1, .path-x2 {
    fill: none;
    stroke: var(--x-color);
    stroke-width: 8;
    stroke-linecap: round;
}

/* Win Overlay */
#win-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(20, 20, 20, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
}

#win-overlay.show {
    opacity: 1;
    pointer-events: all;
}

#win-message {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 800;
    margin-bottom: 30px;
    color: #ffffff;
    text-align: center;
}
