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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background: #0a1628;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    font-family: 'Press Start 2P', 'Courier New', monospace;
}

#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    background: #050d18;
    border: 4px solid #1a4a7a;
    border-radius: 8px;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

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

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(5, 13, 24, 0.95);
    color: #fff;
    pointer-events: auto;
}

.screen.hidden {
    display: none;
}

.screen h1 {
    font-size: 48px;
    color: #00aaff;
    text-shadow: 0 0 20px #00aaff, 0 0 40px #00aaff;
    margin-bottom: 30px;
    letter-spacing: 4px;
}

.screen h2 {
    font-size: 32px;
    color: #ff66aa;
    text-shadow: 0 0 15px #ff66aa;
    margin-bottom: 20px;
}

.screen p {
    font-size: 14px;
    color: #88aacc;
    margin-bottom: 15px;
}

button {
    font-family: inherit;
    font-size: 16px;
    padding: 15px 40px;
    margin: 10px;
    background: #00aaff;
    color: #050d18;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 2px;
}

button:hover,
button.focused {
    background: #0088dd;
    transform: scale(1.05);
    box-shadow: 0 0 20px #00aaff;
}

button.focused {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

button:disabled {
    background: #334455;
    color: #667788;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#level-select {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 20px;
    gap: 10px;
}

.level-btn {
    width: 60px;
    height: 60px;
    padding: 0;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.level-btn.locked {
    background: #1a2a3a;
    color: #445566;
    cursor: not-allowed;
}

.level-btn.locked:hover,
.level-btn.locked.focused {
    background: #1a2a3a;
    transform: none;
    box-shadow: none;
    outline: none;
}

#hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    color: #fff;
    font-size: 14px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

#hud.hidden {
    display: none;
}

#progress {
    color: #00aaff;
}

#level-number {
    font-size: 18px;
    font-weight: bold;
}

#level-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Win screen specific */
#win-screen h2 {
    color: #00ddff;
    text-shadow: 0 0 15px #00ddff;
}

/* Mute button */
#mute-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 20px;
    background: rgba(0, 170, 255, 0.3);
    border: 2px solid #00aaff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    pointer-events: auto;
}

#mute-btn:hover {
    background: rgba(0, 170, 255, 0.5);
    transform: scale(1.1);
}

#mute-btn.muted {
    background: rgba(255, 100, 150, 0.3);
    border-color: #ff66aa;
}

/* Prevent text selection and touch callouts on mobile */
#game-container {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* ==================== MOBILE PORTRAIT ==================== */
@media (max-width: 820px) and (orientation: portrait) {
    body {
        align-items: flex-end;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    #game-container {
        width: 100vw;
        height: auto;
        aspect-ratio: 4 / 3;
        max-height: 75vh;
        border: none;
        border-radius: 0;
    }

    .screen h1 {
        font-size: 28px;
        margin-bottom: 20px;
    }

    .screen h2 {
        font-size: 20px;
        margin-bottom: 15px;
    }

    .screen p {
        font-size: 11px;
        margin-bottom: 10px;
    }

    button {
        font-size: 12px;
        padding: 12px 28px;
        margin: 6px;
    }

    .level-btn {
        width: 48px;
        height: 48px;
        font-size: 16px;
    }

    #level-select {
        gap: 8px;
        margin-top: 15px;
    }

    #mute-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    #hud {
        font-size: 11px;
    }

    #level-number {
        font-size: 14px;
    }
}

/* ==================== MOBILE LANDSCAPE ==================== */
@media (max-height: 500px),
       (max-width: 932px) and (orientation: landscape) {
    body {
        align-items: center;
    }

    #game-container {
        width: auto;
        height: 100vh;
        height: 100dvh;
        aspect-ratio: 4 / 3;
        max-width: 100vw;
        border: none;
        border-radius: 0;
    }

    .screen h1 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .screen h2 {
        font-size: 16px;
        margin-bottom: 8px;
    }

    .screen p {
        font-size: 9px;
        margin-bottom: 6px;
    }

    button {
        font-size: 10px;
        padding: 8px 20px;
        margin: 4px;
    }

    .level-btn {
        width: 36px;
        height: 36px;
        font-size: 12px;
    }

    #level-select {
        gap: 6px;
        margin-top: 8px;
    }

    #mute-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
        top: 5px;
        right: 5px;
    }

    #hud {
        font-size: 9px;
        top: 5px;
        left: 5px;
        right: 40px;
    }

    #level-number {
        font-size: 11px;
    }
}

/* ==================== VERY SMALL SCREENS ==================== */
@media (max-width: 400px) and (orientation: portrait) {
    .screen h1 {
        font-size: 22px;
    }

    .screen h2 {
        font-size: 16px;
    }

    .screen p {
        font-size: 9px;
    }

    button {
        font-size: 10px;
        padding: 10px 20px;
    }

    .level-btn {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
}
