/* ========================================
   Mobile Controls
   ======================================== */

#mobile-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let touches pass through to zones */
    z-index: 150;
    display: none;
    /* Hidden by default, shown via JS if mobile */
}

#mobile-controls.visible {
    display: block;
}

#joystick-zone {
    position: absolute;
    bottom: 40px;
    left: 40px;
    width: 140px;
    height: 140px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(200, 200, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: transform 0.05s;
    box-shadow: 0 0 10px rgba(200, 200, 255, 0.3);
}

#mobile-buttons {
    position: absolute;
    bottom: 40px;
    right: 40px;
    display: flex;
    gap: 20px;
    pointer-events: auto;
}

.mobile-btn {
    width: 90px;
    height: 90px;
    background: rgba(201, 162, 39, 0.3);
    border: 2px solid rgba(201, 162, 39, 0.6);
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.mobile-btn:active,
.mobile-btn.active {
    background: rgba(201, 162, 39, 0.6);
    transform: scale(0.95);
}

@media (max-width: 800px) {

    /* Auto-show on small screens if JS doesn't force it */
    #mobile-controls.auto-show {
        display: block;
    }

    /* Move dialogue box to top on mobile so it doesn't cover controls */
    #dialogue-box {
        bottom: auto !important;
        top: 80px !important;
        height: 120px !important;
        padding: 10px !important;
    }

    #dialogue-portrait {
        width: 80px !important;
        height: 80px !important;
    }

    /* Adjust HUD for notches */
    #hud {
        top: max(12px, env(safe-area-inset-top));
        left: max(12px, env(safe-area-inset-left));
        right: max(12px, env(safe-area-inset-right));
    }

    /* Adjust controls for comfortable thumb reach with safe area */
    #joystick-zone {
        bottom: calc(30px + env(safe-area-inset-bottom));
        left: max(30px, env(safe-area-inset-left));
        width: 120px;
        height: 120px;
    }

    #mobile-buttons {
        bottom: calc(30px + env(safe-area-inset-bottom));
        right: max(30px, env(safe-area-inset-right));
    }

    .mobile-btn {
        width: 70px;
        height: 70px;
        font-size: 12px;
    }
}