:root {
    --primary-color: #4A90E2; /* Blue */
    --secondary-color: #50E3C2; /* Teal */
    --accent-color: #F5A623; /* Orange */
    --background-light: #F0F2F5; /* Light Gray */
    --background-dark: #3C3C3C; /* Dark Gray */
    --text-color-dark: #333333;
    --text-color-light: #FFFFFF;
    --border-color: #D8D8D8;
    --success-color: #7ED321;
    --error-color: #D0021B;
}

body {
    font-family: 'Roboto', sans-serif; /* Using a more modern font */
    margin: 0;
    padding: 0; /* Remove padding to allow container to fill height */
    background-color: var(--background-light);
    color: var(--text-color-dark);
    height: 100vh; /* Make body fill the viewport height */
    display: flex;
    justify-content: center;
    align-items: center; /* Center the container */
    box-sizing: border-box;
}

.container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1400px; /* Wider for better use of space */
    height: 100%; /* Make container fill the body's height */
    background-color: var(--text-color-light);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease-in-out;
}

.header {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    padding: 15px 25px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--secondary-color);
}

.header h1 {
    margin: 0;
    font-size: 2.2em;
    font-weight: 700;
}

#player-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

#player-info p {
    margin: 0;
    font-size: 1.1em;
    font-weight: 500;
}

#my-name {
    color: var(--secondary-color);
    font-weight: bold;
}

#name-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 150px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

#name-input:focus {
    border-color: var(--primary-color);
    outline: none;
}

button {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.1s ease;
}

button:hover {
    background-color: #3A7BC8; /* Darker primary */
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

#set-name-btn {
    background-color: var(--secondary-color);
}

#set-name-btn:hover {
    background-color: #42C2AA; /* Darker secondary */
}

.game-and-chat-wrapper {
    display: flex;
    flex-grow: 1;
    min-height: 0; /* Important for flex-grow in a flex column */
    padding: 20px;
    gap: 20px;
}

.game-area {
    display: flex;
    flex-direction: row;
    flex-grow: 3;
    gap: 20px;
    min-width: 0; /* Prevent flex overflow */
}

.sidebar {
    width: 250px; /* Wider sidebar */
    background-color: var(--background-light);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto; /* Add scroll for sidebar if content overflows */
}

.sidebar h2 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.4em;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 5px; /* Reduced margin */
}

#player-list, #high-scores-list {
    list-style: none;
    padding: 0;
    margin: 0; /* Removed margin-bottom */
    /* Let the parent flexbox handle the growth */
}

#player-list li, #high-scores-list li {
    padding: 8px 0;
    border-bottom: 1px solid rgba(var(--border-color), 0.5);
    font-size: 1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#player-list li:last-child, #high-scores-list li:last-child {
    border-bottom: none;
}

#player-list li.drawer {
    font-weight: bold;
    color: var(--accent-color);
}

.player-score {
    font-weight: 600;
    color: var(--primary-color);
}

.score-buttons {
    margin-top: auto; /* Push buttons to the bottom */
    display: flex;
    flex-direction: column;
    gap: 10px; /* Add space between buttons */
}

#save-score-btn, #reset-scores-btn {
    background-color: var(--accent-color);
    width: 100%;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

#save-score-btn:hover, #reset-scores-btn:hover {
    background-color: #E2961F; /* Darker accent */
}

#game-round-info {
    text-align: center;
    padding: 10px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

#prompt-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.main-canvas-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0; /* Prevent flex overflow */
}

.controls {
    display: flex;
    flex-wrap: wrap; /* Allow controls to wrap */
    align-items: center;
    justify-content: center; /* Center controls */
    gap: 15px; /* Increase gap */
    background-color: var(--text-color-light);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.controls div {
    display: flex;
    align-items: center;
    gap: 5px;
}

.controls label {
    font-weight: 500;
    color: var(--text-color-dark);
}

#drawer-prompt-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
    width: 220px; /* Wider input */
}

#guesser-prompt-display {
    font-size: 1.2em; /* Larger font */
    font-weight: bold;
    color: var(--accent-color);
    padding: 5px;
}

#drawing-canvas {
    border: 1px solid var(--border-color);
    background-color: var(--text-color-light);
    cursor: crosshair;
    touch-action: none;
    border-radius: 8px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    width: 100%; /* Make canvas fill width */
    height: 100%; /* Make canvas fill height */
    flex-grow: 1;
}

.chat-area {
    background-color: transparent; /* Make background transparent */
    border-left: 1px solid var(--border-color);
    padding: 0; /* Remove padding */
    padding-left: 20px; /* Keep left padding */
    display: flex;
    flex-direction: column;
    flex-basis: 350px; /* Set a base width */
    flex-shrink: 0; /* Don't shrink chat area */
    min-width: 300px;
    gap: 15px;
}

#messages {
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 10px;
    background-color: var(--text-color-light);
    border-radius: 6px;
    word-wrap: break-word;
    flex-grow: 1; /* Allow messages to grow */
    height: auto; /* Remove fixed height */
}

#messages div {
    margin-bottom: 8px;
    line-height: 1.4;
}

#messages .server-message {
    color: var(--primary-color);
    font-weight: 600;
    font-style: italic;
}

#messages .guess-correct {
    color: var(--success-color);
    font-weight: bold;
}

.chat-input-area {
    display: flex;
    flex-wrap: wrap; /* Allow buttons to wrap */
    gap: 10px;
}

#message-input {
    flex-grow: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
}


#send-button {
    background-color: var(--primary-color);
}

#send-button:hover {
    background-color: #3A7BC8;
}

#i-guessed-it-btn {
    background-color: var(--success-color);
}

#i-guessed-it-btn:hover {
    background-color: #6EB91D;
}

#confirm-winner-btn {
    background-color: var(--accent-color);
}

#confirm-winner-btn:hover {
    background-color: #E2961F;
}

/* Brush size and color picker styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100px;
    height: 8px;
    background: var(--border-color);
    border-radius: 5px;
    outline: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

input[type="range"]:hover {
    opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: 2px solid var(--text-color-light);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: 2px solid var(--text-color-light);
}

input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    border: none;
    padding: 0;
    background: none;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

input[type="color"]::-moz-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 6px;
}


/* Responsive Adjustments */
@media (max-width: 1100px) { /* Widen the breakpoint for switching to vertical layout */
    .game-and-chat-wrapper {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }

    .game-area {
        flex-direction: column;
        gap: 15px;
    }

    .sidebar {
        width: 100%;
        order: 2; /* Move sidebar below canvas on smaller screens */
        flex-direction: row; /* Make sidebar horizontal */
        flex-wrap: wrap;
        max-height: 200px; /* Constrain height */
    }

    .sidebar > div {
        flex: 1; /* Allow items to grow */
        min-width: 200px; /* Minimum width for each section */
    }

    .main-canvas-area {
        order: 1; /* Keep canvas area at top */
        min-height: 300px; /* Ensure canvas has a minimum height */
    }

    .chat-area {
        flex-basis: auto; /* Reset basis */
        min-width: unset;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding: 15px 0 0 0; /* Adjust padding */
        order: 3; /* Move chat below everything */
    }

    .header {
        flex-direction: column;
        gap: 10px;
        padding: 10px 15px;
    }

    #player-info {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    #name-input, #set-name-btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0; /* No padding on small screens */
    }

    .container {
        border-radius: 0;
        box-shadow: none;
    }
    
    .game-and-chat-wrapper {
        padding: 10px;
    }

    .header h1 {
        font-size: 1.8em;
    }

    .sidebar {
        max-height: unset; /* Allow sidebar to grow as needed */
        flex-direction: column;
    }

    .chat-input-area {
        flex-direction: column;
        gap: 10px; /* Ensure gap for column layout */
    }

    #message-input, #send-button, #i-guessed-it-btn, #confirm-winner-btn {
        width: 100%;
    }
}