body {
    font-family: sans-serif;
    display: flex;
    /* Change flex direction to stack controls on top */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #282c34;
    color: white;
    margin: 0;
    overflow: hidden; /* Prevent scrollbars */
}

#loadingMessage {
    font-size: 1.5em;
    color:#282c34;
    font-weight: bold;
    text-align: center;
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20; /* Ensure it's above everything */
    background: rgba(233, 233, 233, 0.9);
    padding: 20px;
    border-radius: 10px;
}

#controlPanel {
    background-color: rgba(0, 0, 0, 0.6);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 15px; /* Spacing between elements */
    z-index: 10;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    justify-content: center;
}

#controlPanel h2 {
    margin: 0 10px 0 0;
    font-size: 1.2em;
    white-space: nowrap;
}

#songSelector, #startButton {
    padding: 10px 15px;
    font-size: 1em;
    border-radius: 5px;
    cursor: pointer;
}

#songSelector {
    background-color: #fff;
    color: #282c34;
    border: 1px solid #ccc;
    min-width: 150px;
}

#startButton {
    background-color: #61dafb;
    border: none;
    color: #282c34;
    font-weight: bold;
}

#startButton:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.help-button {
    background-color: #5d6574;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

.help-button:hover {
    background-color: #4a5261;
}

#score {
    font-size: 1.5em; /* Slightly smaller to fit better */
    font-weight: bold;
    margin-left: 15px; /* Add some space */
}

/* Game Stats Section */
.gameStats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    width: 100%;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-item {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.stat-label {
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 3px;
}

#elapsedTimeValue, #timeLeftValue, #missesLeftValue {
    font-weight: bold;
    font-size: 1.1em;
}

#missesLeftValue {
    color: #61dafb;
}

/* Change color when misses are low */
.low-misses {
    color: #ff4444 !important;
}


#gameContainer {
    position: relative;
    /* Let width be determined by content, up to a max */
    width: 90vw; /* Use viewport width */
    max-width: 1100px; /* Adjust max width as desired */
    /* Maintain aspect ratio for the game display area */
    aspect-ratio: 16 / 9;
    border: 2px solid #61dafb;
    background-color: #000; /* Black background for letter/pillarboxing */
    overflow: hidden; /* Crucial: clip content outside */
    margin: 0 auto; /* Center the container */
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* JS handles drawing, no CSS transform needed here */
    display: block; /* Ensure it's treated as a block element */
}

/* Hide the original video element */
#webcam {
    display: none;
}

/* Old UI container, hide it */
#uiContainer {
    display: none;
}

/* --- How to Play Modal Styles --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    justify-content: center;
    align-items: center;
    z-index: 30; /* Above all other elements */
}

.modal-content {
    background-color: #282c34;
    width: 80%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 10px;
    border: 2px solid #61dafb;
    padding: 20px;
    position: relative;
    overflow-y: auto; /* Allow scrolling if content is too tall */
}

.close-button {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

.close-button:hover {
    color: #fff;
}

.modal-content h2 {
    color: #61dafb;
    text-align: center;
    margin-top: 10px;
    margin-bottom: 20px;
}

.instructions {
    padding: 0 15px;
}

.instruction-section {
    margin-bottom: 25px;
}

.instruction-section h3 {
    color: #61dafb;
    border-bottom: 1px solid rgba(97, 218, 251, 0.3);
    padding-bottom: 5px;
    margin-bottom: 10px;
}

.instruction-section p {
    margin-bottom: 15px;
    line-height: 1.5;
}

.instruction-section ul {
    padding-left: 20px;
    margin-bottom: 15px;
}

.instruction-section li {
    margin-bottom: 8px;
    line-height: 1.4;
}

.modal-button {
    display: block;
    width: 150px;
    margin: 20px auto 10px;
    padding: 12px 0;
    background-color: #61dafb;
    color: #282c34;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    font-size: 1.1em;
    cursor: pointer;
    text-align: center;
}

.modal-button:hover {
    background-color: #4db6d6;
}

/* --- Game Over Overlay Styles --- */
#gameOverOverlay {
    position: fixed; /* Cover the whole screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75); /* Semi-transparent black */
    display: flex; /* Use flexbox for centering */
    justify-content: center;
    align-items: center;
    z-index: 15; /* Above game, below loading message */
    color: white;
    text-align: center;
    /* display: none; Initially hidden - controlled by JS */
}

.gameOverContent {
    background-color: #282c34; /* Match body background */
    padding: 40px 60px;
    border-radius: 10px;
    border: 2px solid #61dafb;
}

/* Style for the main Game Over message */
#gameOverMessage {
    margin-top: 0;
    margin-bottom: 25px; /* Add some space below message */
    font-size: 2.5em; /* Make it prominent */
    color: #61dafb; /* Default Accent color (JS might change it) */
}

.gameOverContent p {
    font-size: 1.4em;
    margin-bottom: 30px;
}

#finalScoreValue {
    font-weight: bold;
    font-size: 1.2em;
    color: yellow;
}

#backToMenuButton {
    padding: 12px 25px;
    font-size: 1.1em;
    cursor: pointer;
    background-color: #61dafb;
    border: none;
    border-radius: 5px;
    color: #282c34;
    font-weight: bold;
}
/* --- End Game Over Styles --- */

/* Hide audio elements */
#musicPlayer, #winSound, #loseSound {
    display: none;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    #controlPanel {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }
    
    .gameStats {
        gap: 10px;
    }
    
    .stat-item {
        min-width: 80px;
        padding: 5px 8px;
    }
    
    #score {
        margin-left: 0;
    }
    
    .modal-content {
        width: 95%;
        padding: 15px;
    }
    
    .instructions {
        padding: 0 5px;
    }
}