html,
body {
    margin: 0;
    padding: 0;
    background-color: #000;
    overflow: hidden;
    width: 100%;
    height: 100%;
    position: fixed;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#mobile-ui {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    box-sizing: border-box;
}

@media (pointer: coarse) {
    #mobile-ui {
        display: none;
        justify-content: space-between;
        align-items: flex-end;
        /* Keep controls inside natural thumb zones instead of edge corners */
        padding-left: clamp(16px, 4vw, 56px);
        padding-right: clamp(16px, 4vw, 56px);
        padding-bottom: clamp(18px, 5vh, 48px);
        padding-bottom: max(clamp(18px, 5vh, 48px), env(safe-area-inset-bottom));
    }

    #mobile-ui.active {
        display: flex;
    }
}

.ui-btn {
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    /* Thinner border */
    color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    width: 48px;
    height: 48px;
    margin: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    opacity: 0.33;
    /* Low opacity like the joystick */
    transition: opacity 0.2s ease, transform 0.1s ease;
}

.ui-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
    opacity: 0.6;
    /* More visible on press */
}

.joystick-zone {
    width: clamp(190px, 30vw, 230px);
    height: clamp(190px, 30vw, 230px);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    /* Thinner border */
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
    touch-action: none;
    margin-bottom: 0;
    margin-left: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    opacity: 0.06;
    /* Subtle default visibility; still clear on touch */
    transition: opacity 0.3s ease;
}

.joystick-zone:active {
    opacity: 1;
    /* Slightly more visible when used */
}

.joystick-knob {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
    transition: transform 0.05s ease-out;
    /* smooth follow */
}

/* Remove CSS that cancels out touch actions on the general page? No, we need it. */

.action-buttons {
    position: relative;
    width: 170px;
    height: 170px;
    margin-bottom: 0;
    margin-right: 0;
}

.ui-btn-large {
    width: 64px;
    height: 64px;
    font-size: 33px;
}

/* Positioning specific buttons in an ergonomic thumb arc */
#btn-jump {
    position: absolute;
    bottom: 0;
    right: 0;
    margin: 0;
}

#btn-attack {
    position: absolute;
    bottom: 26px;
    left: 2px;
    margin: 0;
}

#btn-charge-toggle {
    position: absolute;
    bottom: 96px;
    left: 6px;
    margin: 0;
    font-size: 26px;
}

#btn-charge-toggle.is-active {
    opacity: 0.65;
    background: rgba(255, 176, 48, 0.35);
    border-color: rgba(255, 214, 128, 0.7);
}

#btn-bomb {
    position: absolute;
    top: 2px;
    right: 24px;
    margin: 0;
}

#btn-portal {
    position: absolute;
    bottom: 66px;
    right: -16px;
    margin: 0;
    font-size: 24px;
}

@media (pointer: coarse) and (orientation: landscape) {
    #mobile-ui {
        /* Typical landscape comfort zone: inward from edges and up from bottom */
        padding-left: clamp(28px, 7vw, 96px);
        padding-right: clamp(28px, 7vw, 96px);
        padding-bottom: clamp(20px, 7vh, 64px);
        padding-bottom: max(clamp(20px, 7vh, 64px), env(safe-area-inset-bottom));
    }

    .joystick-zone {
        width: clamp(185px, 26vw, 220px);
        height: clamp(185px, 26vw, 220px);
    }

    .action-buttons {
        width: 178px;
        height: 178px;
        transform: translate(-4px, -6px);
    }
}

@media (pointer: coarse) {
    .ui-btn-large {
        width: 78px;
        height: 78px;
        font-size: 36px;
    }

    .action-buttons {
        width: 176px;
        height: 176px;
    }

    #btn-jump {
        right: 0;
        bottom: 0;
    }

    #btn-attack {
        bottom: 30px;
        left: 0;
    }

    #btn-charge-toggle {
        bottom: 122px;
        left: 2px;
        font-size: 28px;
    }

    #btn-bomb {
        top: 0;
        right: 28px;
    }

    #btn-portal {
        bottom: 78px;
        right: -20px;
        font-size: 26px;
    }

    .ui-btn,
    .joystick-zone {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        box-shadow: none;
    }
}

#btn-pause {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 32px;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    line-height: 1;
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 0.5;
}

#btn-pause:active {
    background: none;
    transform: scale(1.2);
    opacity: 1;
}

#btn-camera {
    position: absolute;
    top: 24px;
    left: 170px;
    font-size: 22px;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    line-height: 1;
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 1;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

#btn-camera:active {
    background: none;
    transform: scale(1.3);
    opacity: 1;
}

#orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1a1a2e 0%, #0f0f1a 100%);
    z-index: 9999;
    color: white;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@media (pointer: coarse) and (orientation: portrait) {
    #orientation-warning {
        display: flex;
    }
}

.warning-content {
    animation: fadeInScale 0.5s ease-out;
}

.warning-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotatePulse 2s infinite ease-in-out;
    display: inline-block;
}

.warning-text {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    max-width: 300px;
    line-height: 1.3;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.warning-subtext {
    font-size: 16px;
    opacity: 0.7;
    margin-top: 15px;
    font-weight: 400;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes rotatePulse {
    0% {
        transform: rotate(0deg) scale(1);
    }

    50% {
        transform: rotate(180deg) scale(1.2);
    }

    100% {
        transform: rotate(360deg) scale(1);
    }
}
