body:has(#flight[data-handheld]:not([data-commands])) {
    grid-template-rows: minmax(0, 1fr);
}
body:has(#flight[data-handheld]:not([data-commands])) > .topbar {
    display: none;
}
#flight[data-handheld] {
    grid-template-rows: minmax(0, 1fr) auto auto;
}
#flight[data-handheld] .flight-dashboard {
    grid-area: 3 / 1;
    min-width: 0;
    padding: 7px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: var(--dashboard-sill), var(--metal);
}
#flight[data-handheld] #handheld-deck {
    grid-area: menu;
    flex-direction: column;
    align-self: stretch;
    gap: 2px;
    padding: 3px;
    min-height: 44px;
    font: 600 .75rem/1.1 var(--sans);
}
#flight[data-handheld] .flight-actions {
    grid-area: actions;
    display: block;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
}
#flight[data-handheld] .flight-stop-actions button:not(#flight-neutral) kbd {
    display: none;
}
#flight[data-handheld] .action-buttons {
    display: grid;
    width: 100%;
    max-width: none;
    gap: 4px;
}
#flight[data-handheld] .flight-stop-actions {
    display: contents;
}
#flight[data-handheld] .action-buttons :is(.deck-key, #flight-main, .flight-stop-actions button) {
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 4px;
    visibility: visible;
    font: 600 clamp(.75rem, 2.8vw, .86rem)/1.12 var(--sans);
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
}
#flight[data-handheld] .action-buttons .deck-key {
    flex-direction: column;
    gap: 2px;
}
#flight[data-handheld] .action-buttons .deck-key svg { width: 15px; height: 15px; }
#flight[data-handheld] .flight-stop-actions [aria-pressed=true],
#flight[data-handheld] .flight-stop-actions [aria-busy=true] {
    border-color: #ffc16e;
    box-shadow: inset 0 -3px #eaa65e;
}

#flight[data-handheld]:not([data-commands]) .flight-dashboard {
    display: grid;
    grid-template:
        "thrust radar menu" auto
        "actions actions actions" auto / minmax(55px, 1fr) minmax(90px, 2.45fr) minmax(55px, 1fr);
    align-items: center;
    gap: 5px 7px;
    border-block-start: 1px solid #9e7954;
    background:
        var(--contact-wear) 11% bottom / 570px 145px repeat-x,
        linear-gradient(67deg, transparent 37%, #bc86503d 38%, #0d1417a8 40%, transparent 41%) left / 48% 100% no-repeat,
        linear-gradient(-67deg, transparent 37%, #bc86503d 38%, #0d1417a8 40%, transparent 41%) right / 48% 100% no-repeat,
        linear-gradient(176deg, #675443b8, #222321df 15%, #151a1ce6 66%, #332b22cf), var(--alloy-texture);
}
#flight[data-handheld]:not([data-commands]) .console,
#flight[data-handheld]:not([data-commands]) .throttle {
    display: contents;
}
#flight[data-handheld]:not([data-commands]) .console :is(.steer-pad, .flight-shortcuts, .missile-rack, .weapon-actions),
#flight[data-handheld]:not([data-commands]) .action-buttons .deck-key:not([data-drawer="orbital-contacts"]) {
    display: none;
}
#flight[data-handheld]:not([data-commands]) .action-buttons {
    grid-template-columns: minmax(0, .85fr) minmax(0, .93fr) minmax(0, 1.25fr) minmax(0, 1fr) minmax(76px, 1.05fr);
    grid-template-areas: "main contacts trim stop neutral";
}
#flight[data-handheld]:not([data-commands]) #flight-main { grid-area: main; }
#flight[data-handheld]:not([data-commands]) #stabilize-flight { grid-area: trim; }
#flight[data-handheld]:not([data-commands]) #stop-flight { grid-area: stop; }
#flight[data-handheld]:not([data-commands]) [data-drawer="orbital-contacts"] { grid-area: contacts; }
#flight[data-handheld]:not([data-commands]) #flight-neutral {
    grid-area: neutral;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 2px;
}
#flight[data-handheld]:not([data-commands]) #flight-neutral kbd { font: 650 .68rem var(--mono); }
#flight[data-handheld]:not([data-commands]) .action-buttons :is(#stabilize-flight,#stop-flight,#flight-neutral,[data-drawer="orbital-contacts"]) {
    padding-inline: 3px;
    font-size: clamp(.7rem, 2.85vw, .78rem);
    hyphens: auto;
}
#flight[data-handheld]:not([data-commands]) .thrust-controls {
    grid-area: thrust;
    display: grid;
    min-width: 0;
    align-content: center;
}
#flight[data-handheld]:not([data-commands]) #throttle { min-width: 0; height: 44px; }
#flight[data-handheld]:not([data-commands]) .thrust-controls .thrust-scale { display: none; }
#flight[data-handheld]:not([data-commands]) .radar-line {
    display: block;
    grid-area: radar;
    width: 100%;
    padding: 0 2px;
    border: 0;
    background: none;
    box-shadow: none;
}
#flight[data-handheld]:not([data-commands]) .radar-field { display: block; }
#flight[data-handheld]:not([data-commands]) .radar-glass {
    border-color: #a18b73 #595f5c #81725e;
    background: #0c1214;
    box-shadow: 0 0 0 2px #131918, 0 3px 4px #070909;
}
#flight[data-handheld]:not([data-commands]) #radar { width: 100%; height: clamp(48px, 7dvh, 62px); }
#flight[data-handheld]:not([data-commands]) .radar-line :is(.instrument-heading, .echo-readout) { display: none; }

@media (max-width: 420px) {
    #flight[data-handheld]:not([data-commands]) .action-buttons {
        grid-template-columns: minmax(0, .83fr) 44px minmax(0, 1.22fr) minmax(0, .97fr) minmax(63px, .92fr);
    }
    #flight[data-handheld]:not([data-commands]) #flight-main { font-size: .7rem; }
    #flight[data-handheld]:not([data-commands]) [data-drawer="orbital-contacts"] span { display: none; }
}
@media (min-width: 720px) and (max-height: 600px) {
    #flight[data-handheld]:not([data-commands]) .flight-dashboard {
        grid-template: "thrust main contacts radar trim stop neutral menu" auto /
            minmax(68px, 1.35fr) minmax(60px, 1.2fr) minmax(65px, 1.1fr) minmax(104px, 1.9fr)
            minmax(92px, 1.15fr) minmax(72px, .9fr) minmax(78px, .9fr) minmax(46px, .57fr);
    }
    #flight[data-handheld]:not([data-commands]) :is(.flight-actions,.action-buttons) {
        display: contents;
    }
}

/* Menu and contact reports open only on request. Both keep their return control within reach. */
#flight[data-handheld][data-commands] {
    display: block;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--metal);
}
#flight[data-handheld][data-commands] .window { display: none; }
#flight[data-handheld][data-commands] .flight-dashboard {
    display: grid;
    grid-template: "menu actions" auto "instruments instruments" auto / minmax(65px, .7fr) minmax(0, 3fr);
    align-content: start;
    gap: 6px;
}
#flight[data-handheld][data-commands] #handheld-deck { position: sticky; top: 0; z-index: 2; align-self: start; }
#flight[data-handheld][data-commands] .action-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#flight[data-handheld][data-commands] .action-buttons :is(#flight-main, .flight-stop-actions) { display: none; }
#flight[data-handheld][data-commands] .console {
    grid-area: instruments;
    display: grid;
    grid-template: "radar systems" auto "helm helm" auto / minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
}
#flight[data-handheld][data-commands] .console > .radar-line { grid-area: radar; }
#flight[data-handheld][data-commands] .console > .systems { grid-area: systems; }
#flight[data-handheld][data-commands] .console > .throttle {
    grid-area: helm;
    display: grid;
    grid-template: "thrust firing" auto "steering steering" auto "shortcuts shortcuts" auto "missiles missiles" auto / minmax(0, 1fr) auto;
    gap: 6px;
}
#flight[data-handheld][data-commands] .thrust-controls { display: block; grid-area: thrust; }
#flight[data-handheld][data-commands] .throttle .steer-pad { grid-area: steering; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; }
#flight[data-handheld][data-commands] .flight-shortcuts { grid-area: shortcuts; }
#flight[data-handheld][data-commands] .flight-shortcuts button { min-height: 44px; }
#flight[data-handheld][data-commands] .steer-pad [data-key] { grid-area: auto; min-width: 0; height: 44px; }
#flight[data-handheld][data-commands] .steer-pad #invert-steering,
#flight[data-handheld][data-commands] .throttle :is(#throttle, .weapon-actions button, #missile-model) { min-height: 44px; }
#flight[data-handheld][data-commands] .throttle .weapon-actions { grid-area: firing; }
#flight[data-handheld][data-commands] .weapon-actions [data-shortcut="C"] { min-width: 44px; }
#flight[data-handheld][data-commands] .throttle .missile-rack { grid-area: missiles; }
#flight[data-handheld] > .sidebar:not([hidden]) {
    position: fixed;
    inset: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    z-index: 8;
    width: auto;
    max-width: 520px;
    height: auto;
    max-height: none;
    margin: 0 0 0 auto;
    background: #0b1a21;
}
#flight[data-handheld] .sidebar .drawer-close,
#flight[data-handheld] .sidebar :is(.contact, #target-tools button, .terminal-pager button) { min-height: 44px; }
#flight[data-handheld] .sidebar :is(.drawer-close, .terminal-pager button) { min-width: 44px; }
