:root {
    --bg-color: #1a1a2e;
    --board-bg: #16213e;
    --cell-bg: #0f3460;
    --text-color: #e94560;
    --sub-text-color: #dcdcdc;
    --player-x-color: #f9ed69;
    --player-o-color: #49e8b2;
    --valid-hover-bg: rgba(73, 232, 178, 0.4);
    --valid-hint-bg: rgba(73, 232, 178, 0.15);
    --winning-line-color: #f7b733;
}

body {
    font-family: 'Poppins', sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--sub-text-color);
    padding: 10px;
    box-sizing: border-box;
}

/* --- Main Layout: Mobile First --- */
.main-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 525px;
}

header.title-container {
    order: 1; /* Title is always first */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    text-align: center;
    width: 100%;
    margin-top: 10px;
    position: relative; /* For mute button positioning */
}

.title-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#mascot {
    height: 100px;
    width: 100px;
    border-radius: 20px;
    background-color: var(--board-bg);
    padding: 5px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.title-text-group { text-align: center; }
h1 { color: var(--text-color); font-weight: 700; font-size: 2.2rem; margin: 0; }
h2 { font-weight: 400; font-size: 1.1rem; margin: -5px 0 0 0; }

main.game-area {
    order: 2; /* Game area is second on mobile */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.board-container { order: 1; }
#status-area { order: 2; width: 100%; text-align: center; margin-top: 15px; margin-bottom: 0; }

aside.info-area {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    align-items: center;
}

#game-controls {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 90%;
    gap: 10px;
    background-color: var(--board-bg);
    padding: 15px;
    border-radius: 12px;
}
.control-group { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.control-group.hidden { display: none; }
select, button {
    font-family: 'Poppins', sans-serif;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background-color: var(--cell-bg);
    color: var(--sub-text-color);
    font-size: 1rem;
    cursor: pointer;
}
#reset-button { background-color: var(--text-color); color: var(--bg-color); font-weight: 700; transition: transform 0.2s ease; margin-top: 5px; }
#reset-button:hover { transform: scale(1.05); }

#status-text { font-size: 1.2rem; font-weight: 600; margin-top: 0; margin-bottom: 15px; }
#score-board { display: flex; justify-content: center; gap: 20px; font-size: 1rem; }
.score-item { background-color: var(--cell-bg); padding: 5px 15px; border-radius: 8px; }

.board-container { position: relative; }
#game-board {
    display: grid;
    grid-template-columns: repeat(8, 10.5vmin);
    grid-template-rows: repeat(8, 10.5vmin);
    gap: 1vmin;
    padding: 1vmin;
    border: 5px solid var(--board-bg);
    background-color: #000;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    transition: cursor 0.3s ease, opacity 0.3s ease;
}
#game-board.ai-thinking { cursor: wait; opacity: 0.6; }

.cell {
    width: 100%; height: 100%; font-size: 7vmin;
    background-color: var(--cell-bg); border-radius: 1.5vmin; display: flex;
    align-items: center; justify-content: center; font-weight: bold;
    cursor: not-allowed; transition: background-color 0.2s;
}
.cell.valid:hover { background-color: var(--valid-hover-bg); cursor: pointer; }
.cell.valid-move-hint { background-color: var(--valid-hint-bg); }
.cell.valid-move-hint:hover { background-color: var(--valid-hover-bg); }

@keyframes pop-in { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.cell.X, .cell.O { animation: pop-in 0.3s ease-out; }
.cell.X { color: var(--player-x-color); text-shadow: 0 0 10px var(--player-x-color); }
.cell.O { color: var(--player-o-color); text-shadow: 0 0 10px var(--player-o-color); }
.cell.last-move { box-shadow: inset 0 0 8px 2px rgba(255, 255, 255, 0.6); }

#winning-line {
    position: absolute; background-color: var(--winning-line-color); height: 5px;
    border-radius: 5px; box-shadow: 0 0 15px var(--winning-line-color);
    transform-origin: left center; display: none;
}

#rules { text-align: center; font-size: 0.9rem; background: var(--board-bg); padding: 5px 20px 15px 20px; border-radius: 12px; width: 90%; box-sizing: border-box; }
#rules ul { text-align: left; }

#install-prompt-container {
    position: fixed; bottom: 0; left: 0; right: 0; padding: 15px;
    background-color: var(--board-bg); box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000; transform: translateY(120%); transition: transform 0.4s ease-in-out;
}
#install-prompt-container.visible { transform: translateY(0); }
#install-prompt-container.hidden { display: none; }
.install-prompt-content { max-width: 600px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 15px; flex-wrap: wrap; }
.install-prompt-text { flex-grow: 1; }
.install-prompt-content h3 { margin: 0 0 5px 0; color: var(--sub-text-color); font-size: 1.2rem; }
.install-prompt-content p { margin: 0; font-size: 0.9rem; line-height: 1.4; }
.install-prompt-buttons { display: flex; gap: 10px; flex-shrink: 0; }
.install-prompt-buttons button { padding: 8px 16px; font-weight: 600; }
.install-accept { background-color: var(--player-o-color); color: var(--bg-color); }
.install-decline { background-color: var(--cell-bg); }

/* --- Mute Button --- */
#mute-button {
    width: 44px; height: 44px; padding: 8px; border-radius: 50%;
    background-color: var(--cell-bg); border: 2px solid var(--board-bg);
    color: var(--sub-text-color); cursor: pointer; flex-shrink: 0;
    position: absolute; /* Position relative to the main container */
    top: 10px;
    right: 10px;
}
#mute-button:hover { background-color: var(--valid-hover-bg); }
#mute-button svg { width: 100%; height: 100%; }
#mute-button svg.hidden { display: none; }


@media (max-width: 600px) {
    .install-prompt-content { flex-direction: column; text-align: center; }
    .install-prompt-buttons { width: 100%; justify-content: center; margin-top: 10px; }
    .title-container { flex-direction: column; }
    .title-text-group { text-align: center; }
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.1rem; }
}

/* --- Tablet & Desktop Layout --- */
@media (min-width: 901px) {
    body { align-items: center; }
    .main-container {
        display: grid; max-width: 1100px;
        grid-template-columns: minmax(350px, 1fr) 1.5fr;
        grid-template-rows: auto 1fr;
        grid-template-areas: "header game" "info game";
        align-items: start; gap: 40px;
    }

    header.title-container {
        grid-area: header;
        flex-direction: row;
        justify-content: flex-start; /* Align left */
        position: relative; /* Ensure it contains the mute button */
        width: 100%;
    }
    main.game-area { grid-area: game; min-width: 525px; justify-content: center; }
    aside.info-area { grid-area: info; justify-content: flex-start; }

    .board-container { order: 2; }
    #status-area { order: 1; margin-bottom: 20px; }

    #mascot { height: 110px; width: 110px; }
    .title-text-group { text-align: left; }
    h1 { font-size: 2.8rem; }
    h2 { font-size: 1.3rem; }

    #mute-button {
        position: absolute;
        top: 0;
        right: 0;
    }

    #game-controls { flex-direction: row; justify-content: center; width: 100%; box-sizing: border-box; flex-wrap: wrap;}

    #game-board {
        grid-template-columns: repeat(8, 60px); grid-template-rows: repeat(8, 60px);
        gap: 5px; padding: 5px; max-width: none; max-height: none;
    }
    .cell { width: 60px; height: 60px; font-size: 40px; border-radius: 8px; }
    #status-area { font-size: 1.5rem; } #score-board { font-size: 1.1rem; }
    #rules { width: 100%; }
}
