/* ============================================= */
/* --- Global Styles & Variables --- */
/* ============================================= */
:root {
    --primary-blue: #0000FF;
    --light-text: #FFFFFF;
    --dark-bg: #333;
    --highlight-gold: #FFD700;
    --success-green: #4CAF50;
    --success-green-shadow: #388E3C;
    --action-blue: #007BFF;
    --action-blue-shadow: #0056b3;
    --action-purple: #6f42c1;
    --action-purple-shadow: #5a349a;
    --neutral-gray: #6c757d;
    --disabled-gray: #999;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Align content to the top */
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px; /* Add some padding around the content */
    background-color: var(--dark-bg);
    font-family: Arial, sans-serif;
    color: var(--light-text);
    box-sizing: border-box;
    position: relative;
}

.game-title img {
    max-width: 300px;
    height: auto;
    display: block;
    margin-bottom: 20px;
}

/* ============================================= */
/* --- Layout Containers --- */
/* ============================================= */

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

#game-container.hidden {
    display: none;
}

#game-controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background-color: var(--primary-blue);
    border: 2px solid var(--light-text);
    border-radius: 8px;
    padding: 15px;
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
}

/* ============================================= */
/* --- View Management --- */
/* ============================================= */

.view {
    display: none;
}

.view.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 10px;
}

/* ============================================= */
/* --- Canvas & Game Board --- */
/* ============================================= */

#gameCanvas {
    display: block;
    width: 100%;
    height: auto; /* Maintain aspect ratio */
    border: 2px solid var(--light-text);
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation; /* Improve touch responsiveness */
}

/* ============================================= */
/* --- Buttons --- */
/* ============================================= */

.menu-button {
    padding: 12px 24px;
    font-size: 1.2em;
    font-weight: bold;
    color: var(--light-text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    width: 80%;
    max-width: 280px;
    text-align: center;
    transition: transform 0.1s, box-shadow 0.1s;
}

.menu-button:hover {
    transform: translateY(-2px);
}

.menu-button:active {
    transform: translateY(1px);
}

.green-button {
    background-color: var(--success-green);
    box-shadow: 0 4px var(--success-green-shadow);
}
.green-button:hover {
    box-shadow: 0 6px var(--success-green-shadow);
}

.blue-button {
    background-color: var(--action-blue);
    box-shadow: 0 4px var(--action-blue-shadow);
}
.blue-button:hover {
    box-shadow: 0 6px var(--action-blue-shadow);
}

.purple-button {
    background-color: var(--action-purple);
    box-shadow: 0 4px var(--action-purple-shadow);
}
.purple-button:hover {
    box-shadow: 0 6px var(--action-purple-shadow);
}

.back-button {
    background-color: var(--neutral-gray);
    box-shadow: 0 4px #5a6268;
    margin-top: 10px;
}
.back-button:hover {
    box-shadow: 0 6px #5a6268;
}

.action-button {
    padding: 8px 16px;
    font-size: 1.1em;
    background-color: var(--success-green);
    color: var(--light-text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px var(--success-green-shadow);
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.2s;
    display: none; /* Hidden by default, shown via JS */
}

.action-button:hover {
    background-color: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 6px var(--success-green-shadow);
}

.action-button:active {
    transform: translateY(2px);
    box-shadow: 0 2px var(--success-green-shadow);
}

/* ============================================= */
/* --- Dropdown Menu --- */
/* ============================================= */

#menu-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
}

.menu-button-dropdown {
    background-color: var(--primary-blue);
    color: var(--light-text);
    border: 2px solid var(--light-text);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1em;
    cursor: pointer;
}

#menu-content {
    background-color: var(--primary-blue);
    border: 2px solid var(--light-text);
    border-radius: 8px;
    padding: 10px;
    margin-top: 5px;
    display: none;
    flex-direction: column;
    gap: 8px;
    width: 220px;
}

.option-button {
    background-color: #0000CC;
    color: var(--light-text);
    border: 1px solid var(--light-text);
    border-radius: 5px;
    padding: 8px 12px;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.menu-text-box {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9em;
}
.menu-text-box p, .menu-text-box ul {
    margin-top: 0;
    margin-bottom: 1em;
}
.menu-text-box a {
    color: var(--highlight-gold);
    word-break: break-all;
}

.copy-button-small {
    padding: 2px 6px;
    font-size: 0.8em;
    margin-left: 8px;
    background-color: var(--neutral-gray);
    border-radius: 5px;
    border: none;
    color: white;
    cursor: pointer;
}

/* ============================================= */
/* --- Lobby & Game Creation --- */
/* ============================================= */

.lobby-container {
    gap: 15px;
}

.info-text {
    margin: 5px 0;
    font-size: 1.1em;
    text-align: center;
}

#game-code-display {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--highlight-gold);
    background-color: #2a2a2a;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #444;
    user-select: all; /* Allow easy selection */
}

#copy-code-button {
    margin-left: 10px;
    padding: 8px 12px;
    font-size: 1em;
    background-color: var(--neutral-gray);
    border-radius: 5px;
}

#game-code-input {
    font-size: 1.5em;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #ccc;
    text-align: center;
    width: 180px;
    background-color: #eee;
    color: #333;
}

/* ============================================= */
/* --- In-Game Interface --- */
/* ============================================= */

#game-message-banner {
    width: 100%;
    text-align: center;
    padding: 12px;
    background-color: #FFFFFF;
    font-weight: bold;
    border-radius: 8px;
    margin-top: 15px;
    box-sizing: border-box;
    color: black;
    font-size: 1.3em;
    border: 6px solid transparent;
    transition: border-color 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    /* This ensures the text line-height matches the icon height, preventing layout shift */
    line-height: 1.5;
}

.banner-icon {
    height: 1.5em;
    width: auto;
    vertical-align: middle;
    margin-right: 10px;
}

#in-game-top-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0 10px;
    box-sizing: border-box;
}

#in-game-bottom-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center; /* Center the rematch button */
    min-height: 45px; /* Ensure space for the button */
}

/* --- Player Info & Color Selector --- */
#starting-color-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: opacity 0.3s ease;
}

#starting-color-selector.locked {
    opacity: 0.7; /* Dims the entire section when locked */
}

.column-title {
    font-weight: bold;
    font-size: 1.1em;
}

.player-rows-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Custom Radio Button Styles --- */
.color-choice-label input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    width: 20px;
    height: 20px;
    border: 2px solid var(--light-text);
    border-radius: 50%;
    display: grid;
    place-content: center;
}

.color-choice-label input[type="radio"]:not(:disabled) {
    cursor: pointer;
}

.color-choice-label input[type="radio"]::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    background-color: var(--highlight-gold);
}

.color-choice-label input[type="radio"]:checked::before {
    transform: scale(1);
}

.color-choice-label input[type="radio"]:disabled {
    border-color: var(--disabled-gray);
}

.color-choice-label input[type="radio"]:checked:disabled::before {
    background-color: var(--disabled-gray);
}


.player-icon {
    width: 35px;
    height: 35px;
}

.timer-display {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--highlight-gold);
    min-width: 60px; /* Prevent layout shift */
}

/* --- Timer Controls --- */
.timer-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-basis: 150px; /* Give it a consistent width */
}

.timer-input-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.timer-controls label {
    font-size: 1.1em;
    flex-shrink: 0;
}

.timer-controls input[type="checkbox"] {
    width: 22px;
    height: 22px;
}

.timer-controls input[type="text"] {
    width: 40px;
    padding: 3px 5px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background-color: #eee;
    color: #333;
    text-align: center;
    font-size: 1em;
}

.input-with-unit {
    display: flex;
    align-items: center;
    gap: 5px;
}

.timer-unit {
    font-size: 1.1em;
}

/* ============================================= */
/* --- Media Queries for Responsiveness --- */
/* ============================================= */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    .game-title img {
        max-width: 220px;
    }
    .menu-button {
        font-size: 1.1em;
        padding: 10px 20px;
        width: 90%;
    }
    #menu-container {
        top: 5px;
        left: 5px;
    }
    .player-icon {
        width: 30px;
        height: 30px;
    }
    .timer-display {
        font-size: 1.1em;
    }
    #game-message-banner {
        font-size: 1.1em;
        padding: 10px;
    }
}
