html,
body {
    overscroll-behavior: none;
}

#game-top-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 60;
    display: flex;
    gap: 7px;
    align-items: center;
}

#game-top-controls[hidden],
#mobile-controls[hidden] {
    display: none !important;
}

#game-top-controls button {
    display: inline-flex;
    width: 30px;
    height: 30px;
    margin: 0;
    padding: 0;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 5px;
    background: rgba(13, 17, 23, 0.92);
    color: #fff;
    box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.7);
    font-size: 0;
    line-height: 1;
}

#game-top-controls button:hover {
    background: #1f2937;
}

#game-top-controls button:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

#game-back-btn::before {
    content: '↩';
    font-family: Arial, sans-serif;
    font-size: 17px;
    font-weight: 700;
}

#pause-btn::before {
    content: 'Ⅱ';
    font-family: Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
}

#pause-btn[aria-pressed='true']::before {
    content: '▶';
    font-size: 11px;
}

/*
 * The virtual controls are a viewport overlay rather than part of the canvas
 * flex layout. This prevents mobile browsers with tall canvases or desktop-site
 * viewport widths from pushing the controls below the visible screen.
 */
#mobile-controls:not([hidden]) {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 80;
    display: flex !important;
    width: 100vw !important;
    margin: 0 !important;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom)) !important;
    align-items: flex-end;
    justify-content: space-between;
    background: linear-gradient(to top, rgba(13, 17, 23, 0.88), rgba(13, 17, 23, 0));
    pointer-events: none;
    touch-action: manipulation;
}

#mobile-controls:not([hidden]) > * {
    pointer-events: auto;
}

@media (min-width: 1025px) {
    .controls-hint {
        padding-top: 40px;
    }
}

@media (max-width: 1024px) {
    html,
    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    body {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
    }

    #game-container {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
        overscroll-behavior: none;
    }

    #game-canvas {
        touch-action: none;
        overscroll-behavior: none;
    }

    #game-top-controls {
        position: fixed;
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        z-index: 90;
        gap: 6px;
    }

    #game-top-controls button {
        width: 28px;
        height: 28px;
        border-width: 2px;
    }

    #game-back-btn::before {
        font-size: 16px;
    }

    #pause-btn::before {
        font-size: 11px;
    }

    #pause-btn[aria-pressed='true']::before {
        font-size: 10px;
    }
}

@media (max-width: 430px) {
    #mobile-controls:not([hidden]) {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    #mobile-controls .action-btn {
        width: 72px;
        height: 72px;
        margin: 0 5px;
    }

    #mobile-controls .small-btn {
        width: 44px;
        height: 44px;
    }
}
