/* Reset and box model setup for predictable sizing. */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Page background and centered container layout. */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: radial-gradient(circle at top left, rgba(255,255,255,0.18), transparent 35%),
                linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    color: #333;
}

/* Main application card with subtle elevation. */
.container {
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 18px 45px rgba(24, 30, 63, 0.14);
    padding: 28px;
    max-width: 720px;
    width: 100%;
    border: 1px solid rgba(102, 126, 234, 0.16);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 2.5em;
}

.game-info {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    padding: 18px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.game-info > div {
    flex: 1;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.player-indicator,
.next-board-indicator {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #334155;
}

.player-indicator span,
.next-board-indicator span {
    display: inline-flex;
    align-items: center;
}

#currentPlayer,
#nextBoard {
    margin-left: 0;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: 700;
}

#currentPlayer {
    color: white;
}

#currentPlayer.player-x {
    background: #377dff;
}

#currentPlayer.player-o {
    background: #f05545;
}

#nextBoard {
    background: rgba(102, 126, 234, 0.12);
    color: #334155;
}

.mode-select {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.mode-select label {
    font-weight: bold;
    color: #333;
}

.mode-select select {
    padding: 10px 12px;
    border: 1px solid rgba(102, 102, 102, 0.22);
    border-radius: 10px;
    font-size: 1em;
    background: #ffffff;
    color: #333;
    min-width: 160px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mode-select select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.12);
}

#currentPlayer {
    margin-left: 10px;
    font-size: 1.3em;
    padding: 5px 10px;
    border-radius: 4px;
}

#currentPlayer.player-x {
    background: #3498db;
    color: white;
}

#currentPlayer.player-o {
    background: #e74c3c;
    color: white;
}

#nextBoard {
    margin-left: 10px;
    font-weight: bold;
    color: #667eea;
}

.secondary-btn {
    display: block;
    margin: 0 auto 14px;
    padding: 10px 20px;
    background: #f4f6ff;
    color: #2c3a73;
    border: 1px solid rgba(84, 104, 242, 0.25);
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.secondary-btn:hover {
    background: #e8ecff;
    transform: translateY(-1px);
}

.secondary-btn:active {
    transform: translateY(0);
}

.instructions-panel {
    background: rgba(102, 126, 234, 0.08);
    border: 1px solid rgba(102, 126, 234, 0.18);
    border-radius: 18px;
    padding: 20px;
    margin-top: 8px;
    color: #2d3a5b;
}

.instructions-panel.hidden {
    display: none;
}

.instructions-panel h2 {
    margin-bottom: 14px;
    font-size: 1.3rem;
    color: #1f2a4f;
}

.instructions-panel h3 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-size: 1rem;
    color: #2b3a5d;
}

.instructions-panel p,
.instructions-panel ul,
.instructions-panel ol {
    color: #3f4a6d;
    line-height: 1.75;
}

.instructions-panel ul,
.instructions-panel ol {
    margin-left: 18px;
}

.instructions-panel li {
    margin-bottom: 8px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 24px;
    padding: 12px;
    background: rgba(102, 126, 234, 0.08);
    border-radius: 14px;
    border: 1px solid rgba(102, 126, 234, 0.12);
}

/* Each mini-board is a 3x3 grid within the main board. */
.mini-board {
    background: #ffffff;
    border: 2px solid rgba(102, 102, 102, 0.2);
    border-radius: 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
    aspect-ratio: 1;
    position: relative;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.mini-board.active {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
    border-color: #5b6ff0;
    transform: translateY(-1px);
}

.mini-board.disabled {
    opacity: 0.38;
}

.mini-board.won {
    background: #fcfcfc;
}

.mini-board.won .cell {
    display: none;
}

.mini-board.won-x {
    background: #c8e6f5;
}

.mini-board.won-o {
    background: #fadbc8;
}

.mini-board.won-x::after {
    content: 'X';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5em;
    font-weight: bold;
    color: #3498db;
    pointer-events: none;
    z-index: 10;
}

.mini-board.won-o::after {
    content: 'O';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5em;
    font-weight: bold;
    color: #e74c3c;
    pointer-events: none;
    z-index: 10;
}

.cell {
    background: #f8f9ff;
    border: 1px solid rgba(102, 102, 102, 0.16);
    font-size: 1.5em;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
    transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
    border-radius: 8px;
    aspect-ratio: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.cell:hover:not(.played) {
    background: #eef2ff;
    transform: translateY(-1px);
}

.cell.x {
    color: #2d7ef6;
    text-shadow: 0 1px 1px rgba(45, 126, 246, 0.2);
}

.cell.o {
    color: #d94824;
    text-shadow: 0 1px 1px rgba(217, 72, 36, 0.2);
}

.cell.played {
    cursor: default;
    background: #ffffff;
}

.game-status {
    text-align: center;
    font-size: 1.25em;
    font-weight: 700;
    margin-bottom: 14px;
    min-height: 32px;
    color: #363636;
}

.game-status.winner {
    color: #27ae60;
    font-size: 1.5em;
}

.game-status.draw {
    color: #f39c12;
}

.reset-btn {
    display: block;
    margin: 0 auto 12px;
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}


.reset-btn:active {
    transform: scale(0.98);
}

@media (max-width: 600px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }

    .game-info {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .cell {
        font-size: 1.2em;
    }
}
