@media (max-width: 900px) {
    body {
        overflow: hidden;
        touch-action: manipulation;
    }

    .game-shell {
        height: 100dvh;
        min-height: 100dvh;
        padding: 8px;
    }

    .game-panel {
        max-height: calc(100dvh - 16px);
        max-width: calc(100dvw - 16px);
    }

    .game-topbar {
        gap: 10px;
        grid-template-columns: 1fr;
        padding: 10px 12px;
    }

    .scoreboard {
        grid-template-columns: repeat(2, minmax(122px, 1fr));
        justify-self: stretch;
    }

    .mission-readout {
        justify-self: stretch;
    }

    .difficulty-readout,
    .challenge-readout,
    .scoreboard div {
        min-width: 0;
    }

    .arena-wrap {
        height: calc(100dvh - 178px);
        min-height: 360px;
    }

    .controls button {
        min-height: 44px;
    }

    .overlay-card {
        grid-template-columns: 1fr;
        max-height: calc(100% - 28px);
        max-width: 540px;
        overflow-y: auto;
        text-align: center;
    }

    .overlay-visual {
        display: none;
    }

    .how-to-card {
        max-height: calc(100dvh - 40px);
        overflow-y: auto;
    }

    .how-to-slide {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .slide-visual {
        min-height: 220px;
    }
}

@media (max-width: 640px) {
    .game-shell {
        padding: 6px;
    }

    .game-panel {
        border-radius: 8px;
        margin: 0;
        max-width: calc(100dvw - 12px);
        width: calc(100dvw - 12px);
    }

    .game-topbar {
        padding: 8px;
    }

    .scoreboard {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .scoreboard div {
        min-width: 0;
        padding: 7px 9px 8px;
    }

    .mission-readout {
        padding: 8px 9px 9px;
    }

    .mission-readout strong {
        font-size: 13px;
    }

    .mission-progress-row small {
        min-width: 38px;
    }

    .difficulty-readout,
    .challenge-readout {
        padding: 7px 9px 8px;
    }

    .difficulty-readout strong,
    .challenge-readout strong {
        font-size: 12px;
    }

    .scoreboard strong {
        font-size: 21px;
    }

    .arena-wrap {
        height: calc(100dvh - 222px);
        min-height: 0;
    }

    .controls {
        gap: 6px;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        padding: 8px;
    }

    .controls button {
        font-size: 10px;
        gap: 4px;
        min-height: 42px;
        min-width: 0;
        padding: 7px 4px;
    }

    .controls button::before {
        flex-basis: 21px;
        font-size: 8px;
        min-width: 21px;
        width: 21px;
    }

    .overlay {
        padding: 12px;
    }

    .overlay::after {
        inset: 8px;
    }

    .overlay-card {
        gap: 12px;
        max-height: calc(100% - 24px);
        max-width: min(342px, calc(100dvw - 44px));
        padding: 16px;
        width: min(342px, calc(100dvw - 44px));
    }

    .overlay-card h2 {
        font-size: 30px;
        margin-bottom: 8px;
    }

    .overlay-card p {
        font-size: 14px;
        line-height: 1.35;
        margin-bottom: 12px;
    }

    .asset-mode,
    .route-mode {
        margin-bottom: 12px;
        text-align: left;
    }

    .overlay-actions {
        grid-template-columns: 1fr;
    }

    .how-to-card {
        max-height: calc(100dvh - 72px);
        overflow-y: auto;
        padding: 14px;
    }

    .how-to-title-row {
        align-items: start;
        grid-template-columns: 1fr;
    }

    .how-to-dots {
        justify-content: start;
        padding-bottom: 0;
    }

    .how-to-slides {
        min-height: 0;
    }

    .slide-visual {
        min-height: 176px;
    }

    .slide-panel {
        padding: 14px;
    }

    .control-bank div {
        align-items: start;
        flex-wrap: wrap;
    }

    .how-to-footer {
        grid-template-columns: 1fr auto 1fr;
    }

    .how-to-footer button {
        min-width: 0;
        padding: 10px 8px;
    }

    .overlay-stats {
        grid-template-columns: 1fr;
        margin-bottom: 12px;
    }

    .overlay-stats div {
        align-items: center;
        display: flex;
        justify-content: space-between;
        padding: 8px 10px;
    }

    .overlay-stats strong {
        margin-top: 0;
    }
}

@media (max-width: 390px) {
    .scoreboard strong {
        font-size: 18px;
    }

    .scoreboard span,
    .mission-readout span {
        font-size: 8px;
    }

    .controls {
        gap: 5px;
        padding: 7px;
    }

    .controls button {
        font-size: 9px;
        min-height: 40px;
    }

    .controls button::before {
        flex-basis: 19px;
        min-width: 19px;
        width: 19px;
    }

    .overlay-card {
        max-width: calc(100dvw - 32px);
        width: calc(100dvw - 32px);
    }
}

@media (max-height: 680px) and (max-width: 900px) {
    .game-topbar {
        gap: 7px;
        padding: 7px 8px;
    }

    .mission-readout {
        gap: 4px;
        padding: 7px 8px;
    }

    .scoreboard div {
        padding: 6px 8px;
    }

    .scoreboard strong {
        font-size: 18px;
        margin-top: 3px;
    }

    .arena-wrap {
        height: calc(100dvh - 178px);
    }

    .controls {
        padding: 7px;
    }

    .controls button {
        min-height: 40px;
        padding-block: 6px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    .game-shell {
        padding: 4px;
    }

    .game-panel {
        max-height: calc(100dvh - 8px);
        max-width: calc(100dvw - 8px);
    }

    .game-topbar {
        grid-template-columns: minmax(180px, 0.85fr) minmax(340px, 1.15fr);
        padding: 6px 8px;
    }

    .mission-readout {
        padding: 6px 8px;
    }

    .mission-progress-row {
        gap: 6px;
    }

    .arena-wrap {
        height: calc(100dvh - 116px);
        min-height: 0;
    }

    .controls {
        padding: 6px 8px;
    }

    .controls button {
        min-height: 36px;
    }

    .overlay-card,
    .how-to-card {
        max-height: calc(100dvh - 24px);
    }
}

@media (hover: none) and (pointer: coarse) {
    .controls button,
    .overlay-card button,
    .how-to-head button,
    .how-to-footer button,
    .how-to-dots button {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .arena-wrap,
    .game-canvas {
        touch-action: manipulation;
    }
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
    .arena-wrap,
    .game-canvas {
        touch-action: none;
    }
}
/* Keep launch/help/return actions outside the scrolling setup content. */
.overlay-card { align-items: stretch; grid-template-rows: minmax(0, 1fr) auto; }
.overlay-card > .overlay-actions { grid-column: 1 / -1; margin: 0; padding: 10px; flex-shrink: 0; }
.overlay-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.arcade-return { display: grid; place-items: center; min-height: 44px; padding: 8px 12px; color: #b9f5ff; border: 1px solid #39758a; border-radius: 10px; text-decoration: none; }
.arcade-return:focus-visible { outline: 3px solid #ffd166; outline-offset: 2px; }
@media (max-width: 900px), (max-height: 520px) {
    .game-shell { min-height: 0; }
    .game-panel { height: calc(100dvh - 16px); }
    .arena-wrap { height: auto; min-height: 0; overflow: hidden; }
    .controls button { min-height: 44px; }
    .overlay { padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
    .overlay-card { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; max-height: calc(100dvh - 24px); overflow: hidden; }
    .overlay-visual { display: none; }
    .overlay-content { width: auto; padding: 12px; }
    .overlay-card > .overlay-actions { display: flex; flex-wrap: wrap; gap: 6px; background: #081923; }
    .overlay-card > .overlay-actions > * { flex: 1 1 100px; min-height: 44px; }
}
/* First-use guidance uses the existing scrollable Help dialog. */
.control-tip-context {
    margin: 8px 0 0; padding: 10px 12px; border-left: 3px solid #a7f3d0;
    border-radius: 6px; background: #082f28; color: #ecfdf5;
    font-size: 14px; line-height: 1.45; overflow-wrap: anywhere;
}
@media (max-width: 480px) {
    /* Give the action and charge count the full target on narrow phones. */
    .controls button::before { display: none; }
    .controls button { padding-inline: 2px; }
}
