/* Global Styles */
* {
    box-sizing: border-box; /* Apply border-box globally */
}

body {
    font-family: sans-serif;
    margin: 0; /* Remove default margin */
    padding: 0; /* Remove padding to maximize space */
    background-color: #f0f0f0;
    color: #333;
    display: flex;
    justify-content: center;
    min-height: 100vh; /* Ensure body tries to fill viewport height */
}

.game-container {
    display: grid;
    grid-template-areas:
        "header header header"
        "start start start"
        "main main sidebar"
        "main main sidebar";
    /* Make sidebar flexible: minimum 280px, max 1fr (competes with other fr units), ideally ~350px */
    grid-template-columns: 1fr 1fr minmax(280px, 0.5fr); /* Adjusted sidebar width */
    grid-template-rows: auto auto 1fr auto;
    gap: 15px;
    max-width: 1400px;
    width: 100%; /* Take full available width */
    min-height: 100vh; /* Try to fill viewport height */
    background-color: #e0e0e0;
    padding: 15px; /* Keep internal padding */
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.main-header {
    grid-area: header;
    text-align: center;
    background-color: #4CAF50; /* Green */
    color: white;
    padding: 10px 0;
    border-radius: 5px;
}

.start-game-section {
    grid-area: start;
    background-color: #f8f8f8; /* Light grey */
}

.start-game-section .setup-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.start-game-section .api-status {
    margin-top: 10px;
    font-weight: bold;
}

#api-connection-indicator .fa-times-circle { color: red; }
#api-connection-indicator .fa-check-circle { color: green; }
#api-connection-indicator .fa-circle-notch { color: orange; }

.game-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Panel Styles */
.panel {
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #ccc;
}

.panel h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.2em;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

/* Scrabble Board */
#scrabble-board-container {
    position: relative; /* For recommendation overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #006400; /* Dark Green */
    padding: 20px;
    border-radius: 8px;
}

#scrabble-board {
    display: grid;
    grid-template-columns: repeat(15, 40px);
    grid-template-rows: repeat(15, 40px);
    gap: 2px;
    border: 3px solid #8B4513; /* Brown border */
}

.board-cell {
    width: 40px;
    height: 40px;
    background-color: #c8e6c9; /* Light green base */
    border: 1px solid #a5d6a7;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    color: #555;
    text-align: center;
    position: relative; /* For tile positioning */
    box-sizing: border-box;
}

/* Bonus Squares */
.board-cell.dl { background-color: #add8e6; color: #00008b; } /* Light Blue */
.board-cell.tl { background-color: #0000cd; color: white; } /* Medium Blue */
.board-cell.dw { background-color: #ffcccb; color: #b22222; } /* Light Red */
.board-cell.tw { background-color: #ff4500; color: white; } /* Orange Red */
.board-cell.center { background-color: #ffcccb; color: #b22222; } /* Same as DW */

/* Tile Styles */
.tile {
    width: 38px;
    height: 38px;
    background-color: #ffebcd; /* Blanched Almond - Base Tile */
    border: 1px solid #deb887; /* BurlyWood Border */
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: Arial, sans-serif;
    font-weight: bold;
    cursor: grab;
    user-select: none;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
    box-sizing: border-box;
}

.tile-letter {
    font-size: 20px;
}

.tile-points {
    font-size: 8px;
    position: absolute;
    bottom: 2px;
    right: 3px;
}

.tile-in-rack {
    position: relative;
}

.tile-on-board {
    position: absolute;
    top: 1px;
    left: 1px;
    cursor: default;
}

/* Player-specific tile colors (Example: max 4 players: human + 3 CPU) */
.tile-player-0 { background-color: #ffebcd; } /* Human - Default */
.tile-player-1 { background-color: #e6e6fa; border-color: #9370db; } /* CPU 1 - Lavender */
.tile-player-2 { background-color: #f0fff0; border-color: #98fb98; } /* CPU 2 - Honeydew */
.tile-player-3 { background-color: #fffacd; border-color: #ffd700; } /* CPU 3 - Lemon Chiffon */

.old-tile {
    opacity: 0.7; /* Make previously played tiles slightly dimmer */
}

.tile-dragging {
    opacity: 0.6;
    cursor: grabbing;
    z-index: 1000; /* Ensure it's above other elements */
    transform: scale(1.1);
}

.board-cell.drag-over {
    background-color: #a5d6a7; /* Highlight potential drop zones */
    border: 2px dashed #006400;
}

/* Player Rack */
.player-rack-area {
    background-color: #add8e6; /* Light Blue */
}

#player-rack {
    display: flex;
    gap: 5px;
    padding: 10px;
    background-color: #87ceeb; /* Sky Blue */
    border-radius: 5px;
    min-height: 50px; /* Ensure rack area has height */
    align-items: center;
}

/* Chat Interface */
.chat-interface {
    background-color: #90ee90; /* Light Green */
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allow chat to take available space */
}

#chat-history {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #f0fff0; /* Honeydew */
    padding: 10px;
    border: 1px solid #ccc;
    margin-bottom: 10px;
    min-height: 150px; /* Ensure minimum height */
}

.chat-message {
    margin-bottom: 8px;
    padding: 5px;
    border-radius: 4px;
}

.chat-message.user {
    background-color: #d1e7dd; /* Light green variant */
    text-align: right;
}

.chat-message.ai {
    background-color: #f8d7da; /* Light red variant */
}

.chat-message.system {
    background-color: #e2e3e5; /* Light grey variant */
    font-style: italic;
    text-align: center;
    font-size: 0.9em;
}

.chat-input {
    display: flex;
    gap: 5px;
}

#chat-input-box {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#send-chat-btn {
    padding: 8px 12px;
    background-color: #2e8b57; /* Sea Green */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
#send-chat-btn:hover:not(:disabled) {
    background-color: #3cb371; /* Medium Sea Green */
}
#send-chat-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.cooldown-info {
    font-size: 0.8em;
    color: #555;
    margin-top: 5px;
    text-align: center;
}

.recommendation-buttons {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Recommendation Overlay */
#recommendation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allows clicks to pass through */
    z-index: 10; /* Below dragging tiles but above board */
}

.recommended-tile {
    position: absolute;
    width: 38px;
    height: 38px;
    border: 2px dashed #ff4500; /* Orange Red dashed border */
    background-color: rgba(255, 235, 205, 0.5); /* Semi-transparent Blanched Almond */
    display: flex;
    justify-content: center;
    align-items: center;
    color: #ff4500;
    font-weight: bold;
    font-size: 20px;
    box-sizing: border-box;
}


/* Score & Stats */
.score-stats {
    background-color: #ffcdd2; /* Light Red */
}

#scoreboard .player-score {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px dashed #eee;
}

#scoreboard .player-score:last-child {
    border-bottom: none;
}

#scoreboard .player-name {
    font-weight: bold;
}

#scoreboard .player-icon {
    margin-right: 5px;
}

#scoreboard .human-icon { color: #1e90ff; } /* Dodger Blue */
#scoreboard .cpu-icon { color: #808080; } /* Grey */

#game-stats p {
    margin: 5px 0;
    font-size: 0.9em;
}

/* Game Controls */
.game-controls {
    background-color: #c8e6c9; /* Light Green base */
}

.game-controls button {
    background-color: #66bb6a; /* Medium Green */
    color: white;
    border: none;
    padding: 10px 15px;
    margin: 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.game-controls button:hover:not(:disabled) {
    background-color: #4caf50; /* Darker Green */
}

.game-controls button:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

/* Game History */
.game-history {
    background-color: #fffacd; /* Lemon Chiffon (Yellowish) */
}

#move-history-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    max-height: 150px; /* Limit height and make scrollable */
    overflow-y: auto;
    font-size: 0.9em;
}

#move-history-list li {
    padding: 3px 0;
    border-bottom: 1px dotted #eee;
}

#move-history-list li:last-child {
    border-bottom: none;
}

/* Modal Styles */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    min-width: 300px;
    max-width: 500px;
}

.modal-content h3 {
    margin-top: 0;
    text-align: center;
}

/* Exchange Modal Specifics */
#exchange-rack-display {
    display: flex;
    gap: 5px;
    justify-content: center;
    margin: 15px 0;
    min-height: 50px; /* Consistent height */
}

.tile.selected-for-exchange {
    outline: 3px solid #007bff; /* Blue outline for selected tiles */
    opacity: 0.8;
}

/* Game Over Modal Specifics */
#final-scores {
    margin-bottom: 15px;
}

#final-scores .player-final-score {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 1.1em;
}

#final-scores .winner {
    font-weight: bold;
    color: green;
}

.modal-content button {
     background-color: #66bb6a; /* Medium Green */
    color: white;
    border: none;
    padding: 10px 15px;
    margin: 5px;
    border-radius: 4px;
    cursor: pointer;
}

.modal-content button:hover {
     background-color: #4caf50; /* Darker Green */
}

/* Utility Classes */
.hidden {
    display: none;
}

/* Responsive Adjustments (Basic Example) */
@media (max-width: 1200px) {
    .game-container {
        grid-template-areas:
            "header header"
            "start start"
            "main sidebar"
            "main sidebar";
        /* Adjust sidebar width for this breakpoint too */
        grid-template-columns: 1fr minmax(250px, 0.6fr);
    }
}

@media (max-width: 992px) {
    .game-container {
        grid-template-areas:
            "header"
            "start"
            "main"
            "sidebar";
        grid-template-columns: 1fr; /* Single column */
        grid-template-rows: auto auto auto auto;
        min-height: auto; /* Allow height to adjust */
    }
    .sidebar {
        flex-direction: row; /* Stack sidebar items horizontally on smaller screens */
        flex-wrap: wrap;
        justify-content: space-around;
    }
    .panel {
        flex-basis: 48%; /* roughly half width for sidebar panels */
    }
     #scrabble-board {
        grid-template-columns: repeat(15, 35px); /* Slightly smaller cells */
        grid-template-rows: repeat(15, 35px);
    }
    .board-cell, .tile {
        width: 35px;
        height: 35px;
    }
    .tile-letter { font-size: 18px; }
    .tile-points { font-size: 7px; }
}

@media (max-width: 768px) {
     #scrabble-board {
        grid-template-columns: repeat(15, 30px);
        grid-template-rows: repeat(15, 30px);
    }
    .board-cell, .tile {
        width: 30px;
        height: 30px;
    }
     .tile-letter { font-size: 16px; }
     .panel { flex-basis: 100%; } /* Stack all panels vertically */
} 