:root {
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --board-bg: #2a2a2a;
    --cell-bg: #333;
    --cell-hover: #444;
    --primary: #3498db;
    --secondary: #e74c3c;
    --accent: #f1c40f;
    --highlight: #2ecc71;
    --disabled: #555;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

h1, h2, h3 {
    margin: 0.5rem 0;
}

.container {
    max-width: 800px;
    width: 100%;
    padding: 20px;
    text-align: center;
}

/* Lobby */
.lobby-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 50px;
    align-items: center;
}

input, button {
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 5px;
    border: none;
    outline: none;
}

input {
    background: #333;
    color: white;
    border: 1px solid #555;
}

button {
    cursor: pointer;
    background: var(--primary);
    color: white;
    transition: transform 0.1s, background 0.2s;
}

button:hover {
    background: #2980b9;
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
}

/* Game Info */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #333;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    width: 95vmin; /* Mesma largura do tabuleiro */
    max-width: 800px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.game-info > div {
    font-size: 1.1rem;
    font-weight: 500;
}

.info-timer {
    color: var(--accent);
    font-weight: bold;
    min-width: 100px;
    text-align: center;
}

/* Alinhamentos Específicos */
.game-info .info-left {
    text-align: left;
}

.game-info .info-center {
    text-align: center;
}

.game-info .info-right {
    text-align: right;
}

.turn-indicator {
    font-weight: bold;
    /* A cor será definida via JS agora */
}

/* Game Layout Container */
.game-container {
    /* Changed to simple block to allow absolute positioning of side panel */
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
}

/* Main Board */
.main-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr); /* Ensure rows are exactly equal */
    gap: 10px;
    background-color: var(--bg-color);
    padding: 10px;
    margin: 0 auto;
    
    /* Make it bigger and strictly square */
    width: 95vmin;
    height: 95vmin;
    max-width: 800px;
    max-height: 800px;
    
    /* Ensure content stays centered and constrained */
    justify-content: center;
    align-content: center;
}

/* Side Panel & Macro Board */
.side-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(42, 42, 42, 0.9);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 10;
}

.side-panel h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    text-align: center;
}

.macro-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    background-color: var(--bg-color);
    padding: 3px;
    width: 15vmin;
    height: 15vmin;
    max-width: 150px;
    max-height: 150px;
}

.macro-cell {
    background-color: var(--cell-bg);
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 1.5vw, 1.5rem);
    font-weight: bold;
    color: #777;
    border: 1px solid #444;
}

.macro-cell.won-X {
    background-color: var(--primary);
    color: white;
}

.macro-cell.won-O {
    background-color: var(--secondary);
    color: white;
}

/* Mini Board */
.mini-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr); /* Ensure rows are exactly equal */
    gap: 4px; /* Slightly larger gap for better definition */
    background-color: var(--board-bg);
    padding: 5px;
    border-radius: 5px;
    position: relative;
    border: 3px solid transparent; 
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
    
    /* Fix for grid item overflow */
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* Active State - Priority: Yellow Border */
.mini-board.active {
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.6); /* Yellow glow */
    border-color: var(--accent) !important; /* Yellow border always takes precedence */
    z-index: 1; /* Bring active board to front slightly */
}

/* Won Status - Internal Lines (Background Color) */
.mini-board.won-X {
    background-color: var(--primary); /* Blue lines for X */
}

.mini-board.won-O {
    background-color: var(--secondary); /* Red lines for O */
}

/* Ensure Active + Won shows both (Yellow Border + Colored Lines) */
.mini-board.active.won-X {
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.4); /* Blueish glow mixed */
}

.mini-board.active.won-O {
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.4); /* Reddish glow mixed */
}

/* Removed the ::after overlay that blocked clicks */


/* Cells */
.cell {
    background-color: var(--cell-bg);
    /* aspect-ratio: 1; Removed to let grid control size */
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 4vw, 1.5rem); /* Responsive font size */
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.cell:hover {
    background-color: var(--cell-hover);
}

.cell.taken {
    cursor: default;
}

.cell.X {
    color: var(--primary);
}

.cell.O {
    color: var(--secondary);
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.hidden {
    display: none !important;
}

@media (max-width: 1100px) {
    /* When screen is not wide enough to hold board + panel comfortably side-by-side */
    .side-panel {
        position: static;
        transform: none;
        margin-top: 20px;
        flex-direction: row; /* Horizontal layout for mobile */
        gap: 15px;
        width: 95vmin;
        max-width: 800px;
        justify-content: center;
    }
    
    .side-panel h3 {
        margin-bottom: 0;
        margin-right: 15px;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        padding-bottom: 20px; /* Space for panel */
    }
}

@media (max-width: 600px) {
    .main-board {
        gap: 5px;
    }
    .mini-board {
        padding: 2px;
        gap: 1px;
    }
    .cell {
        font-size: 1rem;
    }
}

/* Lobby Styles */
.divider {
    margin: 20px 0;
    border-top: 1px solid #444;
    width: 100%;
}

.button-group, .input-group {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-primary {
    background-color: var(--primary);
}

.btn-secondary {
    background-color: var(--highlight);
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.9rem;
    background-color: #7f8c8d;
    margin-top: 10px;
}

.games-list {
    background: #2a2a2a;
    border-radius: 5px;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    min-width: 300px;
}

.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #333;
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
}

.game-item span {
    font-family: monospace;
    font-size: 1.1rem;
}

.game-item button {
    padding: 5px 10px;
    font-size: 0.9rem;
}
