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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a2e;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

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

/* Touch Controls */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 160px;
    pointer-events: none;
    z-index: 10;
}

#touch-dpad {
    position: absolute;
    left: 12px;
    bottom: 12px;
    width: 180px;
    height: 140px;
}

#touch-buttons {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 160px;
    height: 140px;
}

.touch-btn {
    position: absolute;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.08s, transform 0.08s;
}

.touch-btn:active, .touch-btn.active {
    background: rgba(255, 255, 255, 0.45);
    border-color: rgba(255, 255, 255, 0.7);
    transform: scale(0.92);
}

/* D-pad layout */
#touch-left {
    left: 0;
    top: 38px;
}

#touch-right {
    left: 116px;
    top: 38px;
}

#touch-down {
    left: 58px;
    top: 76px;
}

/* Action buttons — right side */
#touch-jump {
    right: 10px;
    top: 0;
    background: rgba(80, 180, 255, 0.25);
    border-color: rgba(80, 180, 255, 0.5);
    color: rgba(180, 220, 255, 0.9);
}

#touch-jump:active, #touch-jump.active {
    background: rgba(80, 180, 255, 0.5);
    border-color: rgba(80, 180, 255, 0.8);
}

#touch-interact {
    right: 80px;
    top: 50px;
    background: rgba(255, 200, 50, 0.25);
    border-color: rgba(255, 200, 50, 0.5);
    color: rgba(255, 220, 120, 0.9);
}

#touch-interact:active, #touch-interact.active {
    background: rgba(255, 200, 50, 0.5);
    border-color: rgba(255, 200, 50, 0.8);
}

/* UI Overlay */
#ui-overlay {
    position: fixed;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    z-index: 20;
}

.ui-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.ui-btn:hover { background: rgba(0, 0, 0, 0.5); }
.ui-btn.muted { opacity: 0.4; }

/* Always show touch controls on touch devices */
@media (hover: none) and (pointer: coarse) {
    #touch-controls {
        display: block;
    }

    /* Shrink game canvas to make room for controls */
    #game {
        height: calc(100% - 140px);
    }
}

@media (max-width: 480px) {
    #touch-controls {
        display: block;
    }

    #game {
        height: calc(100% - 130px);
    }

    .touch-btn {
        width: 58px;
        height: 58px;
        font-size: 22px;
    }

    #touch-dpad {
        left: 8px;
        bottom: 8px;
        width: 160px;
        height: 130px;
    }

    #touch-left { left: 0; top: 34px; }
    #touch-right { left: 104px; top: 34px; }
    #touch-down { left: 52px; top: 68px; }

    #touch-buttons {
        right: 8px;
        bottom: 8px;
        width: 150px;
        height: 130px;
    }

    #touch-jump { right: 8px; top: 0; }
    #touch-interact { right: 72px; top: 46px; }
}
