/*
==============================================
  M4TH5 Resources Theme for Ultimate Tic-Tac-Toe
==============================================
*/

/* --- Color Palette & Universal Settings --- */
:root {
    --bg-color: #f5f5f5; --text-color: #333; --puzzle-bg: white;
    --border-color: #e5e7eb; --card-shadow: rgba(0, 0, 0, 0.1);
    --player-x-color: #3b82f6; --player-o-color: #dc2626; 
    --valid-move-bg: rgba(220, 38, 38, 0.1); --valid-move-border: #ef4444;
    --button-primary: #dc2626; --button-secondary: #6b7280; --disabled-grey: #9ca3af;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    display: flex; justify-content: center; align-items: flex-start;
    min-height: 100vh;
    background-color: var(--bg-color); color: var(--text-color); padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- Main Puzzle & Controls Areas --- */
.puzzle-area {
    background: white; border-radius: 12px; padding: 25px;
    box-shadow: 0 4px 15px var(--card-shadow); position: relative;
    display: flex; flex-direction: column; align-items: center;
    max-width: 650px;
    width: 100%;
}
.puzzle-area::before {
    content: ""; position: absolute; top: -3px; left: 50%;
    transform: translateX(-50%); width: 60px; height: 4px;
    background: var(--player-o-color); border-radius: 2px;
}

/* --- Top Controls --- */
.top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
}
.game-mode {
    display: flex;
    gap: 5px;
}
.game-mode button {
    padding: 10px 15px; font-size: 0.85em; font-weight: 600;
    border: 2px solid var(--border-color); border-radius: 8px;
    background-color: #f9fafb; color: var(--text-color); cursor: pointer;
    transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    flex-grow: 1;
}
.game-mode button:hover { background-color: #f1f5f9; border-color: #d1d5db; }
.game-mode button.active-mode {
    background-color: var(--button-primary); color: white; border-color: var(--button-primary);
}
.action-buttons button {
    padding: 12px 24px; font-size: 1em; font-weight: 600; cursor: pointer; border: none;
    border-radius: 8px; color: white; background-color: var(--button-secondary);
    transition: all 0.2s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.action-buttons button:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); background-color: #4b5563; }

/* Difficulty Selector Styles */
.difficulty-selector { display: flex; gap: 10px; margin-bottom: 20px; justify-content: center; }
.difficulty-selector button {
    padding: 8px 16px; font-size: 0.9em; font-weight: 600;
    border: 2px solid var(--border-color); border-radius: 8px;
    background-color: #f9fafb; color: var(--text-color); cursor: pointer;
    transition: all 0.2s ease;
}
.difficulty-selector button:hover { background-color: #f1f5f9; border-color: #d1d5db; }
.difficulty-selector button.active-mode {
    background-color: var(--button-primary); color: white; border-color: var(--button-primary);
}

/* Remote Lobby Styles */
.remote-lobby { 
    width: 100%; border-top: 2px solid var(--border-color); 
    margin-top: 5px; padding-top: 15px; 
}
.lobby-instructions { 
    margin: 0 0 15px 0; font-size: 1em; color: #6b7280; 
    text-align: center;
}
.join-game { 
    display: flex; gap: 10px; width: 100%; margin-top: 10px; 
}
.join-game input { 
    flex-grow: 1; padding: 10px; border: 2px solid var(--border-color); 
    border-radius: 8px; font-size: 1em; 
}
.join-game button { 
    padding: 10px 15px; font-weight: 600; cursor: pointer; border: none; 
    border-radius: 8px; color: white; background-color: var(--button-secondary); 
}
#createGameButton { 
    width: 100%; padding: 12px; font-size: 1em; font-weight: 600; 
    cursor: pointer; border: none; border-radius: 8px; color: white; 
    background-color: var(--button-primary); 
}
#shareGameSection { 
    margin-top: 15px; width: 100%; background: #f9fafb; padding: 15px; 
    border-radius: 8px; border: 1px solid var(--border-color); 
}
#shareGameSection p { font-weight: 600; margin-bottom: 10px; text-align: center; }
#shareableLink { 
    width: 100%; padding: 8px; text-align: center; font-size: 1.1em; 
    font-weight: 700; background: #fff; border: 1px solid var(--border-color); 
    border-radius: 6px; margin-bottom: 10px; 
}
#copyLinkButton { 
    padding: 8px 16px; font-size: 0.9em; width: 100%; 
    background-color: var(--button-secondary); color: white; border: none; 
    border-radius: 6px; cursor: pointer; 
}

.hidden { display: none !important; }

/* --- Outer Game Board --- */
.outer-grid {
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr);
    gap: 12px;
    background-color: var(--bg-color); 
    padding: 12px; 
    border-radius: 8px;
    border: 2px solid var(--border-color); 
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    max-width: 600px; 
    width: 100%;
    aspect-ratio: 1;
    transition: opacity 0.3s ease;
}
.outer-grid.disabled { pointer-events: none; opacity: 0.7; }

/* --- Large Grid Cells (Mini-boards) --- */
.grid-cell {
    background-color: #fff; 
    border: 3px solid var(--border-color);
    border-radius: 6px; 
    width: 100%;
    height: 100%;
    min-height: 0;
    position: relative;
    transition: all 0.2s ease-in-out; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.grid-cell.valid-grid {
    border-color: var(--valid-move-border);
    box-shadow: 0 0 15px rgba(220, 38, 38, 0.3); transform: scale(1.02);
}

/* --- Inner Grid & Individual Cells --- */
.inner-grid { 
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); 
    gap: 4px;
    height: 100%; 
    padding: 5px;
}
.cell {
    background-color: #f9fafb; border: 1px solid var(--border-color); border-radius: 4px;
    aspect-ratio: 1; display: flex; justify-content: center; align-items: center;
    font-size: clamp(1.2em, 5vw, 2.5em);
    font-weight: 700; cursor: pointer;
    transition: all 0.2s ease; position: relative;
    min-width: 0;
    min-height: 0;
}
.cell:hover:not(.disabled) { background-color: #f0f0f0; transform: translateY(-2px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.cell.disabled {
    pointer-events: none; background-color: #e2e8f0; opacity: 1;
    cursor: not-allowed; color: #94a3b8; box-shadow: none; transform: none;
}

/* --- Player Mark Styling --- */
.cell.O, .player-O { color: var(--player-o-color); }
.cell.X, .player-X { color: var(--player-x-color); }
.cell.O { text-shadow: 1px 1px 3px rgba(220, 38, 38, 0.2); }
.cell.X { text-shadow: 1px 1px 3px rgba(59, 130, 246, 0.2); }

/* --- Win State Styling --- */
.grid-cell.won { background-color: rgba(255, 255, 255, 0.5); }
.grid-cell.won::after {
    content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    font-size: clamp(5em, 20vw, 8em); font-weight: 900;
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.3s ease;
}
.grid-cell.won.O::after { content: 'O'; color: var(--player-o-color); text-shadow: 0 0 15px var(--player-o-color); }
.grid-cell.won.X::after { content: 'X'; color: var(--player-x-color); text-shadow: 0 0 15px var(--player-x-color); }
@keyframes winning-flash { 50% { transform: scale(1.1); opacity: 0.85; text-shadow: 0 0 25px currentColor; } }
.grid-cell.winning-line::after { animation: winning-flash 1.2s infinite ease-in-out; }

/* --- Controls Area Elements --- */
.status { min-height: 1.2em; font-style: italic; font-weight: 600; margin-bottom: 10px; font-size: 1.2em; }

/* --- Scoreboard Styling --- */
.scoreboard-area {
    margin-top: 25px; border-top: 2px solid var(--border-color);
    padding-top: 20px; width: 100%; text-align: center;
}
.scoreboard-area h2 { margin-bottom: 15px; font-size: 1.5em; }
.scores { display: flex; justify-content: space-around; margin-bottom: 20px; }
.score { text-align: center; }
.score-label {
    font-weight: 700; display: block; margin-bottom: 5px; font-size: 1.1em;
}
.score-value { font-size: 1.8em; font-weight: 700; }
#resetScoreButton { background-color: var(--button-secondary); padding: 8px 16px; font-size: 0.9em; color: white; border: none; border-radius: 6px; cursor: pointer; }
#resetScoreButton:hover { background-color: #4b5563; }

/* --- Responsive Design --- */
@media (max-width: 600px) {
    body { padding: 0; }
    .puzzle-area { border-radius: 0; min-height: 100vh; padding: 15px; }
    .top-controls { flex-direction: column; gap: 15px; }
    .game-mode { width: 100%; }
    .game-mode button { flex-grow: 1; font-size: 0.75em; padding: 8px 10px; }

    /* THE DEFINITIVE FIX: Reduce spacing on small screens */
    .outer-grid {
        gap: 5px;
        padding: 5px;
    }
    .inner-grid {
        gap: 3px;
        padding: 3px;
    }
    .grid-cell {
        border-width: 2px;
        border-radius: 4px;
    }
}