* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #222;
    /* Darker bg clearly shows the game area */
    overflow: hidden;
    touch-action: none;
    /* Prevent browser zooming/scrolling on mobile */
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    /* Sky gradient game bg */
    background: linear-gradient(to bottom, #509deb 0%, #c1eafa 100%);
    box-shadow: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Mobile Controls */
#controls {
    display: none;
    /* Hidden on desktop by default, or shown via JS detection. For now we use media query */
    width: 100%;
    max-width: 1200px;
    height: 15vh;
    justify-content: space-between;
    align-items: center;
    padding: 10px 40px;
    box-sizing: border-box;
    pointer-events: none;
    /* Let clicks pass through empty space */
}

.control-group {
    display: flex;
    gap: 20px;
    pointer-events: auto;
}

.control-btn {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    color: white;
    font-size: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    touch-action: manipulation;
    pointer-events: auto;
    /* Buttons must be clickable */
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.6);
}

/* Show controls on smaller screens or touch devices */
@media (max-width: 1024px) {
    #controls {
        display: flex;
        position: absolute;
        bottom: 20px;
        z-index: 10;
        width: 100%;
    }

    #game-wrapper {
        max-width: 100vw;
        max-height: 100vh;
        /* Fill more of the screen on mobile */
    }
}

/* Door Loading Screen */
#door-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    /* Let clicks pass only after it opens (logic handled via remove) */
}

.door-panel {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: #333;
    /* Dark Door Color */
    border-bottom: 10px solid #111;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8);
    transition: transform 1.5s ease-in-out;
}

.door-panel.left {
    left: 0;
    border-right: 2px solid #000;
}

.door-panel.right {
    right: 0;
    border-left: 2px solid #000;
}

#loading-text {
    position: relative;
    z-index: 10000;
    color: white;
    font-size: 40px;
    font-family: Arial, sans-serif;
    font-weight: bold;
    text-shadow: 0 0 10px black;
    transition: opacity 0.5s;
}

/* Open State */
#door-container.open .door-panel.left {
    transform: translateX(-100%);
}

#door-container.open .door-panel.right {
    transform: translateX(100%);
}

#door-container.open #loading-text {
    opacity: 0;
}

#loading-poster {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 80%;
    /* Responsive sizing */
    max-height: 70vh;
    z-index: 10000;
    /* Same as text */
    border: 5px solid white;
    box-shadow: 0 0 20px black;
    transition: opacity 0.5s;
}

#door-container.open #loading-poster {
    opacity: 0;
}

/* ===========================
   Settings UI
   =========================== */
.ui-btn {
    padding: 10px 20px;
    font-size: 18px;
    background: #333;
    color: white;
    border: 2px solid #555;
    border-radius: 5px;
    cursor: pointer;
    font-family: Arial, sans-serif;
    transition: background 0.2s;
}

.ui-btn:hover {
    background: #444;
}

.ui-btn.primary {
    background: #4CAF50;
    /* Green */
    border-color: #45a049;
    width: 100%;
    margin-top: 20px;
}

.ui-btn.primary:hover {
    background: #45a049;
}

#settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
    /* Above canvas */
}

#note-btn {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

/* Modal Overlay */
#settings-modal,
#note-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    /* Above game and loading screen potentially */
}

#settings-modal.hidden,
#note-modal.hidden {
    display: none;
}

.modal-content {
    background: #222;
    padding: 30px;
    border-radius: 10px;
    border: 2px solid #444;
    color: white;
    width: 300px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

.modal-content h2 {
    margin-top: 0;
    color: #FFD700;
    /* Gold */
    border-bottom: 1px solid #444;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 18px;
}

/* Toggle Button */
.toggle-btn {
    padding: 5px 15px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    width: 80px;
}

.toggle-btn.on {
    background: #4CAF50;
    color: white;
}

.toggle-btn.off {
    background: #c62828;
    /* Red */
    color: white;
}

/* Select Dropdown */
#difficulty-select {
    padding: 5px;
    border-radius: 4px;
    background: #333;
    color: white;
    border: 1px solid #555;
    font-size: 16px;
    cursor: pointer;
}

/* Volume Control */
.volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    background: #555;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #4CAF50;
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #4CAF50;
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

#volume-label {
    font-size: 14px;
    color: #ccc;
    min-width: 35px;
}

/* ===========================
   HUD
   =========================== */
#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    width: calc(100% - 150px);
    /* Leave space for settings btn */
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    /* Let clicks pass through */
    z-index: 900;
}

#health-container {
    display: flex;
    gap: 5px;
}

.heart {
    font-size: 40px;
    filter: drop-shadow(2px 2px 0px rgba(0, 0, 0, 0.5));
}

#score-container {
    text-align: right;
    font-family: Arial, sans-serif;
    color: white;
    text-shadow: 2px 2px 0px black;
}

#score-display {
    font-size: 40px;
    font-weight: bold;
}

#highscore-display {
    font-size: 20px;
    color: #FFD700;
    /* Gold */
    margin-top: 5px;
}

/* ===========================
   MOBILE UI OVERRIDES
   =========================== */
@media (max-width: 1024px) {

    /* Full width HUD with padding for mobile */
    #hud {
        width: 100%;
        left: 0;
        padding: 0 20px;
        box-sizing: border-box;
        /* Ensure padding doesn't overflow */
    }

    /* Move Note Button to Top Right (Next to Settings) */
    #note-btn {
        left: auto;
        right: 90px;
        /* settings is at right: 20px. Button width ~50px? */
        transform: none;
    }

    /* Push Score Down to clear buttons */
    #score-container {
        margin-top: 70px;
    }

    /* Smaller Text for Mobile */
    #score-display {
        font-size: 24px;
    }

    #highscore-display {
        font-size: 14px;
    }

    .heart {
        font-size: 24px;
    }

    /* Glassmorphism for Controls */
    .control-btn {
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        width: 70px;
        /* Slightly smaller on mobile if needed, or keep 80 */
        height: 70px;
        font-size: 24px;
    }

    #controls {
        padding-bottom: 40px;
        /* Lift up from bottom edge */
    }

    #fullscreen-btn {
        display: block !important;
        /* Show on mobile */
        position: absolute;
        top: 20px;
        left: auto;
        right: 160px;
        /* Next to Note button */
        /* Top Left */
        z-index: 1000;
    }
}

#fullscreen-btn {
    display: none;
    /* Hidden by default on desktop */
}