* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #030f18;
    color: #fff;
    font-family: 'Segoe UI', Impact, 'Arial Black', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    padding: 10px;
}

#game-container {
    position: relative;
    width: 95vw;
    height: calc(95vw * 3 / 4);
    max-width: 800px;
    max-height: 600px;
    background: linear-gradient(to bottom, #062b3d, #020c13);
    box-shadow: 0 0 40px rgba(0, 255, 255, 0.15), inset 0 0 20px rgba(0, 255, 255, 0.1);
    border: 3px solid #00f0ff;
    border-radius: 12px;
    overflow: hidden;
    container-type: size;
}

/* Landscape orientation adjustments to fit the height of screen */
@media (min-aspect-ratio: 4/3) {
    #game-container {
        height: 90vh;
        width: calc(90vh * 4 / 3);
    }
}

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

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#hud {
    display: flex;
    justify-content: space-between;
    padding: 20px 30px;
    padding: 2.5cqw 3.75cqw;
    font-size: 26px;
    font-size: 3.25cqw;
    font-weight: 900;
    text-transform: uppercase;
    text-shadow: 2px 2px 0 #004455, -1px -1px 0 #004455, 0 0 10px #00f0ff;
    text-shadow: 0.25cqw 0.25cqw 0 #004455, -0.125cqw -0.125cqw 0 #004455, 0 0 1.25cqw #00f0ff;
    letter-spacing: 2px;
    letter-spacing: 0.25cqw;
}

.hud-item {
    display: flex;
    align-items: center;
    color: #00f0ff;
}

#score {
    color: #fff;
    margin-left: 10px;
    margin-left: 1.25cqw;
}

.meter-container {
    gap: 15px;
    gap: 1.875cqw;
}

#balance-bar-bg {
    width: 180px;
    width: 22.5cqw;
    height: 24px;
    height: 3cqw;
    background-color: rgba(255, 0, 0, 0.4);
    border: 3px solid #fff;
    border: 0.375cqw solid #fff;
    border-radius: 12px;
    border-radius: 1.5cqw;
    overflow: hidden;
    position: relative;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 1.25cqw rgba(255, 255, 255, 0.5);
}

#balance-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff003c, #ffea00, #00ff73);
    transition: width 0.1s linear, background 0.2s;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(3, 15, 24, 0.8) 0%, rgba(1, 6, 10, 0.95) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: opacity 0.4s ease, backdrop-filter 0.4s;
    backdrop-filter: blur(4px);
    pointer-events: auto; /* Allow clicks on overlay */
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(0px);
}

.overlay h1 {
    font-size: 72px;
    font-size: 9cqw;
    margin-bottom: 15px;
    margin-bottom: 1.875cqw;
    color: #00f0ff;
    text-shadow: 0 0 15px #00f0ff, 0 0 30px #00f0ff, 5px 5px 0 #004455;
    text-shadow: 0 0 1.875cqw #00f0ff, 0 0 3.75cqw #00f0ff, 0.625cqw 0.625cqw 0 #004455;
    letter-spacing: 6px;
    letter-spacing: 0.75cqw;
    font-weight: 900;
}

.overlay p {
    font-size: 24px;
    font-size: 3cqw;
    margin-bottom: 25px;
    margin-bottom: 3.125cqw;
    color: #e0ffff;
    font-weight: bold;
    text-shadow: 1px 1px 3px #000;
}

#final-score {
    color: #00ff73;
    font-size: 32px;
    font-size: 4cqw;
    text-shadow: 0 0 10px #00ff73;
    text-shadow: 0 0 1.25cqw #00ff73;
}

.controls {
    background: rgba(0, 240, 255, 0.1);
    padding: 25px;
    padding: 3.125cqw;
    border-radius: 12px;
    border-radius: 1.5cqw;
    border: 2px solid rgba(0, 240, 255, 0.4);
    border: 0.25cqw solid rgba(0, 240, 255, 0.4);
    box-shadow: inset 0 0 15px rgba(0, 240, 255, 0.1);
    margin: 25px 0;
    margin: 3.125cqw 0;
}

.controls p {
    font-size: 20px;
    font-size: 2.5cqw;
    margin: 12px 0;
    margin: 1.5cqw 0;
    letter-spacing: 1px;
}

.controls span {
    color: #00f0ff;
    font-weight: 900;
    background: rgba(0,0,0,0.4);
    padding: 4px 8px;
    padding: 0.5cqw 1cqw;
    border-radius: 4px;
    border-radius: 0.5cqw;
    border: 1px solid #005555;
    border: 0.125cqw solid #005555;
}

.blink {
    animation: blinker 1.5s cubic-bezier(0.4, 0, 1, 1) infinite;
    font-size: 22px;
    font-size: 2.75cqw;
    color: #fff;
    margin-top: 35px;
    margin-top: 4.375cqw;
    text-shadow: 0 0 8px #fff;
}

@keyframes blinker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

/* Mobile responsive control hints */
.mobile-controls-hint {
    display: none;
}

@media (max-width: 1024px), (pointer: coarse) {
    .desktop-controls-hint {
        display: none;
    }
    .mobile-controls-hint {
        display: block;
    }
}

/* Touch controls for mobile */
#touch-controls {
    display: none;
    position: absolute;
    bottom: 25px;
    left: 0;
    width: 100%;
    padding: 0 25px;
    pointer-events: none;
    z-index: 10;
    justify-content: space-between;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (max-width: 1024px), (pointer: coarse) {
    #game-container.playing #touch-controls {
        display: flex;
        opacity: 1;
    }
    
    .touch-group {
        display: flex;
        flex-direction: column;
        gap: 15px;
        pointer-events: auto;
    }
    
    .left-group {
        align-items: flex-start;
    }
    
    .right-group {
        align-items: flex-end;
    }
    
    .touch-btn {
        width: 65px;
        height: 65px;
        background: rgba(0, 240, 255, 0.12);
        border: 2px solid rgba(0, 240, 255, 0.5);
        color: #00f0ff;
        border-radius: 50%;
        font-size: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        user-select: none;
        -webkit-user-select: none;
        outline: none;
        box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
        transition: background 0.1s, transform 0.1s, border-color 0.1s;
    }
    
    .touch-btn:active {
        background: rgba(0, 240, 255, 0.45);
        border-color: #ffffff;
        color: #ffffff;
        transform: scale(0.9);
        box-shadow: 0 0 15px rgba(0, 240, 255, 0.6);
    }
}

/* Optimize touch controls for smaller screens */
@media (max-width: 600px) {
    #touch-controls {
        padding: 0 15px;
        bottom: 15px;
    }
    .touch-btn {
        width: 56px;
        height: 56px;
        font-size: 20px;
    }
    .touch-group {
        gap: 10px;
    }
}
