@media (pointer: coarse) {
  body {
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .stage:has(#overlay[hidden]), #field, .touch {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  #language-help, .rail .keys { display: none; }
  .top { flex-wrap: wrap; }
  .actions { flex-wrap: wrap; gap: 5px; }
  .actions .chip { min-height: 36px; }
  .touch {
    display: grid;
    grid-template-columns: auto repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 8px;
  }
  .touch-pad {
    display: grid;
    grid-template-areas: ". up ." "left . right" ". down .";
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    width: 134px;
    height: 134px;
  }
  .touch-pad [data-key="ArrowUp"] { grid-area: up; }
  .touch-pad [data-key="ArrowLeft"] { grid-area: left; }
  .touch-pad [data-key="ArrowRight"] { grid-area: right; }
  .touch-pad [data-key="ArrowDown"] { grid-area: down; }
  .touch button {
    min-width: 0;
    min-height: 44px;
    padding: 4px;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    font-weight: 700;
  }
  .touch-pad button { font-size: 20px; line-height: 1; }
  .touch > button { grid-column: auto; min-height: 56px; }
  .touch > [data-key="Space"] { background: var(--amber); color: #132125; }
  .touch [data-held] { box-shadow: inset 0 0 0 2px var(--amber); background: #315052; color: white; }
  .touch > [data-key="Space"][data-held] { background: #ffdfa4; color: #132125; }
  .cabinet:has(#overlay:not([hidden])) .touch { display: none; }
}
@media (pointer: coarse) and (max-width: 640px) and (orientation: portrait) {
  .cabinet, .cabinet.flight-wide { width: 100%; }
  .stage:has(#overlay[hidden]) canvas {
    width: min(100%, max(160px, calc((100svh - 242px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .75)));
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .cabinet:has(#overlay[hidden]) {
    grid-template-columns: minmax(0, 3fr) minmax(220px, 2fr);
  }
  .touch {
    grid-template-columns: 134px minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(44px, 1fr));
    gap: 5px;
  }
  .touch-pad { grid-row: 1 / 3; }
  .touch > [data-key] { grid-column: 2; min-height: 44px; }
}

/* The same focus view works in native fullscreen and in the mobile browser. */
body.mobile-full {
  --focus-top: max(6px, env(safe-area-inset-top));
  --focus-left: max(8px, env(safe-area-inset-left));
  --focus-right: max(8px, env(safe-area-inset-right));
  --focus-bottom: max(8px, env(safe-area-inset-bottom));
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #06151b;
}
.mobile-full .cabinet {
  --natural-aspect: .75;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
}
.mobile-full .cabinet.flight-wide { --natural-aspect: 1.25; }
.mobile-full .cabinet .layout { display: contents; }
.mobile-full .cabinet .stage {
  position: absolute;
  inset: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  container-type: size;
}
/* Keep the element's actual rectangle equal to the artwork's hit area.
   The game supplies --focus-aspect when its camera opens to a wide viewport. */
body.mobile-full .cabinet :is(#world, #field) {
  width: min(100cqw, calc(100cqh * var(--focus-aspect, var(--natural-aspect))));
  height: auto;
  aspect-ratio: auto;
}
.mobile-full .cabinet .top {
  position: absolute;
  z-index: 4;
  top: var(--focus-top);
  right: var(--focus-right);
  display: flex;
  margin: 0;
  padding: 0;
  border: 0;
  pointer-events: none;
}
.mobile-full .top .wordmark,
.mobile-full .actions > :not(#full, #pause) { display: none; }
.mobile-full .top .actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.mobile-full .top :is(#full, #pause) {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #86a6a7;
  border-radius: 8px;
  background: #0b212ce8;
  color: #f9f3dc;
  font-size: 0;
  touch-action: manipulation;
  pointer-events: auto;
}
.mobile-full #pause::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  width: 15px;
  height: 17px;
  border-inline: 4px solid currentColor;
}
.mobile-full #full::before,
.mobile-full #full::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, transparent 42%, currentColor 44% 56%, transparent 58%);
}
.mobile-full #full::before {
  top: 9px;
  right: 9px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}
.mobile-full #full::after {
  left: 9px;
  bottom: 9px;
  border-right: 2px solid currentColor;
  border-top: 2px solid currentColor;
}
.mobile-full .cabinet:has(#overlay[hidden]) .rail {
  position: absolute;
  z-index: 3;
  top: var(--focus-top);
  left: var(--focus-left);
  display: flex;
  flex-direction: row;
  align-items: start;
  gap: 4px;
  pointer-events: none;
}
.mobile-full .rail .instrument { display: none; }
.mobile-full .rail .instrument:has(#score, #health) {
  display: block;
  padding: 4px 7px;
  border-color: #607e85;
  background: #0b212ce8;
}
.mobile-full .rail .label { color: #c0cfd0; font-size: 9px; }
.mobile-full .rail .readout { font-size: 15px; }
.mobile-full .cabinet:has(#overlay[hidden]) .touch {
  position: absolute;
  z-index: 4;
  right: var(--focus-right);
  bottom: var(--focus-bottom);
  display: block;
  margin: 0;
  pointer-events: none;
}
.mobile-full .touch > :not([data-key="KeyX"]) { display: none; }
.mobile-full .touch > [data-key="KeyX"] {
  min-width: 68px;
  min-height: 48px;
  padding: 7px 12px;
  border: 1px solid #d4b778;
  border-radius: 8px;
  background: #122735eb;
  color: #ffdb98;
  pointer-events: auto;
}
.mobile-full .touch > [data-key="KeyX"][data-held] {
  color: #112329;
  background: #ffdb98;
}

/* Menus take the area below the exit control and can scroll independently
   of the flight surface, including after a round or an orientation change. */
.mobile-full .cabinet:has(#overlay:not([hidden])) :is(#pause, .rail, .touch) { display: none; }
.mobile-full #overlay:not([hidden]),
.mobile-full #overlay.cover:has(#hangar) {
  position: absolute;
  inset: calc(var(--focus-top) + 50px) 0 0;
  grid-area: auto;
  align-content: safe center;
  justify-content: safe center;
  overflow: auto;
  overscroll-behavior: contain;
  padding-inline: max(15px, var(--focus-left)) max(15px, var(--focus-right));
  padding-bottom: var(--focus-bottom);
  touch-action: pan-y;
  pointer-events: auto;
}
.mobile-full #overlay:not([hidden]) > * { flex-shrink: 0; }
.mobile-full #overlay .overlay-actions button { min-height: 44px; }
.mobile-full #weekly-champions[open] {
  max-height: calc(100dvh - var(--focus-top) - var(--focus-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
