@media (pointer:coarse) and (orientation:landscape) {
  /*
   * Slice 7.12O — ergonomic phone HUD.
   * DEV-only overlay. Keep production mobile HUD untouched until PASS.
   */
  #hud {
    --erg-left: max(18px, calc(env(safe-area-inset-left) - 26px));
    --erg-right: max(18px, calc(env(safe-area-inset-right) - 26px));
    --erg-bottom: max(4px, calc(env(safe-area-inset-bottom) - 12px));
  }

  /* Upper-left information belongs to the contract card in this layout. */
  #hud .top-left.panel {
    display: none !important;
  }

  /* Contract card: lower-left, immediately right of the joystick.
   * Keep the left edge fixed so expand/collapse grows toward the callsign. */
  .sector-contract-panel {
    left: calc(var(--erg-left) + 142px) !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(var(--erg-bottom) + 14px) !important;
    width: min(224px, 43vw) !important;
    max-height: 34vh !important;
    transform: none !important;
  }
  .sector-contract-panel.contract-collapsed {
    left: calc(var(--erg-left) + 142px) !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(var(--erg-bottom) + 14px) !important;
    width: 118px !important;
  }

  /* Transient gameplay messages belong below the horizon, just above callsign/status. */
  #hud #message {
    left: 50% !important;
    top: auto !important;
    bottom: calc(var(--erg-bottom) + 82px) !important;
    width: min(420px, 48vw) !important;
    transform: translateX(-50%) !important;
    text-align: center !important;
    line-height: 1.25 !important;
    z-index: 24 !important;
  }

  /* Wide, high, transparent compass: readable without masking the battlefield. */
  #hud .heading-compass {
    top: calc(4px + env(safe-area-inset-top, 0px)) !important;
    width: min(54vw, 470px) !important;
    opacity: .76;
  }
  #hud .compass-window {
    width: 100% !important;
    height: 30px;
    background: linear-gradient(
      90deg,
      rgba(0, 0, 0, .22),
      rgba(0, 24, 12, .11) 18%,
      rgba(0, 24, 12, .11) 82%,
      rgba(0, 0, 0, .22)
    ) !important;
    border-top-color: rgba(110, 255, 135, .34) !important;
    border-bottom-color: rgba(110, 255, 135, .20) !important;
  }
  #hud .compass-window::before,
  #hud .compass-window::after {
    opacity: .28;
  }
  #hud .compass-readout {
    margin-top: 2px;
    opacity: .76;
  }

  /* Right information stack: bearing is redundant with compass. */
  #hud .top-right.panel {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    right: var(--erg-right) !important;
    font-size: 10px;
    line-height: 1.45;
    letter-spacing: .07em;
  }

  /*
   * Left thumb zone.
   * Primary joystick is ~10% smaller than the earlier 126px control.
   */
  #hud #stick {
    left: calc(var(--erg-left) + 14px) !important;
    bottom: var(--erg-bottom) !important;
    width: 113px !important;
    height: 113px !important;
  }
  #hud #stick .stick-knob {
    left: 37px !important;
    top: 37px !important;
    width: 39px !important;
    height: 39px !important;
  }

  /* Radar is information, so lift it completely out of the movement path. */
  #hud .radar-wrap {
    left: calc(var(--erg-left) + 18px) !important;
    bottom: calc(var(--erg-bottom) + 132px) !important;
    width: 106px !important;
    transform: none !important;
  }
  #hud .radar {
    width: 96px !important;
    height: 96px !important;
  }
  #hud .radar-label {
    width: 96px !important;
    margin-bottom: 3px;
  }

  /*
   * Circular perimeter legend.
   * Keep symbol definitions on the radar itself instead of consuming a second
   * rectangular column that collides with JUMP.
   */
  #hud .radar-legend {
    position: absolute !important;
    left: -5px !important;
    bottom: -5px !important;
    width: 106px !important;
    height: 106px !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    background: transparent !important;
    pointer-events: none !important;
    z-index: 14 !important;
    font-size: 6px !important;
    line-height: 1 !important;
    letter-spacing: .035em !important;
  }
  #hud .radar-legend span {
    position: absolute !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
    padding: 1px 3px !important;
    margin: 0 !important;
    border-radius: 8px;
    background: rgba(0,0,0,.48);
    text-shadow: 0 0 5px currentColor;
    white-space: nowrap !important;
  }
  #hud .radar-legend span i {
    width: 4px !important;
    height: 4px !important;
    flex: 0 0 4px !important;
  }
  #hud .radar-legend span:nth-child(1) {
    top: 4px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
  #hud .radar-legend span:nth-child(2) {
    top: 50% !important;
    right: 1px !important;
    transform: translateY(-50%) !important;
  }
  #hud .radar-legend span:nth-child(3) {
    bottom: 3px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
  #hud .radar-legend span:nth-child(4) {
    top: 50% !important;
    left: 1px !important;
    transform: translateY(-50%) !important;
  }
  #hud .radar-legend span:nth-child(n+5) {
    display: none !important;
  }

  /* Jump: above and inward, one short extension from the movement thumb. */
  #hud #jumpBtn {
    left: calc(var(--erg-left) + 132px) !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(var(--erg-bottom) + 113px) !important;
    width: 56px !important;
    height: 56px !important;
  }

  /*
   * Right thumb zone — Slice 7.12O2.
   * Keep FIRE under the resting thumb, but move the full combat fan slightly inward.
   */
  #hud #fireBtn {
    right: calc(var(--erg-right) + 22px) !important;
    bottom: calc(var(--erg-bottom) + 4px) !important;
    width: 113px !important;
    height: 113px !important;
    font-size: 12px !important;
  }

  /* Missile is the closest secondary action: diagonal up-left from FIRE. */
  #hud #missileBtn {
    right: calc(var(--erg-right) + 126px) !important;
    bottom: calc(var(--erg-bottom) + 102px) !important;
    top: auto !important;
    width: 82px !important;
    height: 82px !important;
    font-size: 9px !important;
  }

  /* NOS is secondary and sits above the missile. */
  #hud #nosBtn {
    left: auto !important;
    right: calc(var(--erg-right) + 46px) !important;
    top: auto !important;
    bottom: calc(var(--erg-bottom) + 194px) !important;
    width: 56px !important;
    height: 56px !important;
    font-size: 8px !important;
  }

  /* TOW is deliberate utility: upper-left of the cluster, clear of MISSILE. */
  #hud #towBtn {
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    right: calc(var(--erg-right) + 134px) !important;
    bottom: calc(var(--erg-bottom) + 194px) !important;
    width: 58px !important;
    height: 46px !important;
    font-size: 9px !important;
  }
  #hud #towBtn.towing {
    width: 70px !important;
  }
  body .tow-state-indicator {
    right: calc(max(18px, calc(env(safe-area-inset-right) - 26px)) + 132px) !important;
    bottom: calc(max(4px, calc(env(safe-area-inset-bottom) - 12px)) + 244px) !important;
  }

  /* Bottom-center identity/status stack sits almost on the lower screen edge. */
  #hud .bottom-center.status {
    left: 50% !important;
    bottom: max(1px, calc(env(safe-area-inset-bottom) - 18px)) !important;
    width: min(330px, 38vw);
    transform: translateX(-50%) !important;
    font-size: 10px !important;
    line-height: 1.42 !important;
    letter-spacing: .14em !important;
    z-index: 10;
  }
  #hud .bottom-center.status .upgrade-status {
    margin-top: 0 !important;
    font-size: 9px !important;
  }
  #hud .mobile-brand-sector-row {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 30px;
    margin-top: 1px;
    white-space: nowrap;
  }
  #hud .mobile-brand-sector-row .brand,
  #hud .mobile-brand-sector-row .sector-name {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 1.2 !important;
    letter-spacing: .32em !important;
  }
  #hud .mobile-brand-sector-row .sector-name {
    color: #59d8ff;
    opacity: .92;
  }

  /* Keep center interaction/aiming lane clear. */
  #hud .touch-look {
    left: 39% !important;
    right: 23% !important;
    top: 16% !important;
    bottom: 22% !important;
  }

  /* DEV badge should not sit behind the primary fire control. */
  body .niterange-build-id {
    right: calc(var(--erg-right) + 96px) !important;
    bottom: 1px !important;
  }
}

@media (pointer:coarse) and (orientation:portrait) {
  /* Existing portrait gate owns the UI; no ergonomic landscape overrides. */
  #hud .mobile-brand-sector-row {
    display: none !important;
  }
}
