/*
==============================================
  M4TH5 Resources Theme for Tic-Tac-GO!
==============================================
*/

/* --- 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; 
    --button-primary: #dc2626;
    --button-secondary: #6b7280;
    --disabled-grey: #9ca3af;

    /* MODIFIED: New variables for dynamic hover */
    --valid-move-bg-x: rgba(59, 130, 246, 0.1);
    --valid-move-border-x: #3b82f6;
    --valid-move-bg-o: rgba(220, 38, 38, 0.1);
    --valid-move-border-o: #ef4444;
}

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

/* --- General Page Layout --- */
body {
    display: flex;
    justify-content: center;
    align-items: flex-start; /* MODIFIED: Aligns content to the top to remove the gap */
    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 {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px var(--card-shadow);
    position: relative;
    width: 100%;
    max-width: 550px;
}

.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;
}

/* --- Game Board --- */
.tic-tac-go-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);
    width: clamp(280px, 90vw, 500px);
    aspect-ratio: 1;
}

.cell {
    background-color: #fff;
    border: 3px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(2.5em, 15vw, 5em);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    line-height: 1;
}

/* MODIFIED: Dynamic hover styles */
.puzzle-area.player-x-turn .cell:not(.X):not(.O):hover {
    background-color: var(--valid-move-bg-x);
    border-color: var(--valid-move-border-x);
}
.puzzle-area.player-o-turn .cell:not(.X):not(.O):hover {
    background-color: var(--valid-move-bg-o);
    border-color: var(--valid-move-border-o);
}

.cell.disabled {
    pointer-events: none;
    cursor: not-allowed;
}

/* --- Player Mark Styling & Animations --- */
@keyframes place-piece { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes remove-piece { from { transform: scale(1); opacity: 1; } to { transform: scale(0.5); opacity: 0; } }

.cell.O, .player-O { color: var(--player-o-color); }
.cell.X, .player-X { color: var(--player-x-color); }
.cell.X, .cell.O { animation: place-piece 0.2s ease-out; }
.cell.removing { animation: remove-piece 0.3s ease-in; }

/* --- Win State Styling --- */
@keyframes winning-flash-o { 0%, 100% { background-color: #fef2f2; } 50% { background-color: #fee2e2; } }
@keyframes winning-flash-x { 0%, 100% { background-color: #eff6ff; } 50% { background-color: #dbeafe; } }
.cell.winning-cell-o { animation: winning-flash-o 0.8s infinite ease-in-out; }
.cell.winning-cell-x { animation: winning-flash-x 0.8s infinite ease-in-out; }

/* --- Controls Area --- */
.status { min-height: 1.2em; font-style: italic; font-weight: 600; margin-bottom: 20px; font-size: 1.3em; }
#resetButton { display: none; }

/* --- Styles for the unified mode selector --- */
.mode-selection { display: flex; flex-direction: column; align-items: center; gap: 15px; width: 100%; margin-bottom: 25px; }
.game-mode-selector { display: flex; justify-content: center; gap: 5px; width: 100%; }
.difficulty-selector { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.remote-lobby { width: 100%; border-top: 2px solid var(--border-color); margin-top: 5px; padding-top: 15px; }
.hidden { display: none !important; }

.game-mode-selector button, .difficulty-selector button {
    padding: 10px 10px; 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;
    flex-grow: 1; 
    /* NEW: Flex properties for icon alignment */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.difficulty-selector button { flex-grow: 0; }
.game-mode-selector button:hover, .difficulty-selector button:hover { background-color: #f1f5f9; border-color: #d1d5db; }
.game-mode-selector button.active-mode, .difficulty-selector button.active-mode {
    background-color: var(--button-primary); color: white; border-color: var(--button-primary);
}
/* NEW: Styling for SVG icons */
.game-mode-selector button svg {
    stroke-width: 2.5;
}

/* Styles for remote lobby */
.lobby-instructions { margin: 0 0 15px 0; font-size: 1em; color: #6b7280; }
.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; }
#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; }

/* --- Scoreboard & Other Elements --- */
.scoreboard-area { margin-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; }
.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: 700px) {
    body { padding: 0; }
    .puzzle-area { min-height: 100vh; border-radius: 0; justify-content: flex-start; padding-top: 30px; }
}