html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: #000;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

* {
    box-sizing: border-box;
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100dvh;
    height: 100vh;
    background: #000;
    gap: 8px;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#canvas-holder {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 4px;
}

#canvas {
    background: #5c94fc;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    touch-action: none;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    outline: none;
}

.instructions-desktop {
    color: #ddd;
    font-family: "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    font-size: 13px;
    text-align: center;
    line-height: 1.6;
    padding-bottom: 4px;
}

/* ---------- Touch controls ---------- */
#touch-controls {
    display: none;
    flex: 0 0 auto;
    width: 100%;
    max-width: 640px;
    align-items: center;
    justify-content: space-between;
    padding: 6px 18px calc(10px + env(safe-area-inset-bottom));
    gap: 12px;
    touch-action: none;
}

.dpad {
    position: relative;
    width: 148px;
    height: 148px;
    flex: 0 0 auto;
}

.dpad-btn {
    position: absolute;
    width: 52px;
    height: 52px;
    background: rgba(255,255,255,0.14);
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 10px;
    color: #fff;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active, .dpad-btn.pressed {
    background: rgba(255,255,255,0.4);
}

.dpad-up    { top: 0;    left: 48px; }
.dpad-down  { top: 96px; left: 48px; }
.dpad-left  { top: 48px; left: 0; }
.dpad-right { top: 48px; left: 96px; }

.action-buttons {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 auto;
}

.action-btn {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    background: rgba(255,255,255,0.14);
    border: 2px solid rgba(255,255,255,0.5);
    color: #fff;
    font-size: 13px;
    font-weight: bold;
    font-family: "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.3;
}

.action-btn:active, .action-btn.pressed {
    background: rgba(255,255,255,0.4);
}

#btn-jump { margin-top: 34px; }

/* Show touch controls on touch-capable devices, or narrow/coarse-pointer screens */
@media (pointer: coarse) {
    #touch-controls { display: flex; }
    .instructions-desktop { display: none; }
}

/* Rotate hint for very narrow portrait phones */
#rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    color: #fff;
    z-index: 999;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    font-size: 16px;
    padding: 24px;
    line-height: 1.8;
}

#rotate-hint.dismissed {
    display: none !important;
}

@media (pointer: coarse) and (orientation: portrait) and (max-aspect-ratio: 3/4) {
    #rotate-hint { display: flex; }
}
