/* Scale interface surfaces once, while boards and input coordinate spaces stay native. */
@media (max-width:700px), (max-width:1000px) and (max-height:500px) {
  :root { --mobile-ui-scale:.8; }

  header.arcade-top { zoom:var(--mobile-ui-scale); }
  header.arcade-top :is(.game-menu,.top-popover) {
    top:calc(var(--top-height) + 8px);
  }
  main { padding:4px; }
  .layout>section { min-height:calc(100dvh - var(--top-height)*var(--mobile-ui-scale) - 8px); }
  body:has(#rogue-panel:not([hidden])) main {
    height:calc(100dvh - var(--top-height)*var(--mobile-ui-scale));
    padding:3.2px;
  }
  html.arcade-immersive body:has(#rogue-panel:not([hidden])) main {
    height:100dvh;
    padding:0;
  }

  /* One outer surface per HUD, menu or dialog avoids nested 80% scaling. */
  #rogue-panel #r-screen:not(:has(.tw-screen)),
  #rogue-panel :is(.r-combat-top,.r-bottom,.r-minimap,.r-damage-meter,#r-dash,#r-evolution-notice),
  body>dialog,
  body>.r-vault-toast,
  body>#arcade-fullscreen {
    zoom:var(--mobile-ui-scale);
  }

  /* Keep the constellation viewport unscaled; its own zoom handles map input. */
  #rogue-panel #r-screen .tw-screen :is(.tw-head,.tw-toolbar,.tw-map-tools,.tw-detail,.tw-legend,.tw-guide) {
    zoom:var(--mobile-ui-scale);
  }

  /* Offline games share the compact chrome without shrinking their game boards. */
  .layout>section>:is(.game-heading,.b-head,.m-head,.s-head,.bird-head,.n-head,.t-head,.p-head,.f-head,
    .stats,.b-stats,.m-stats,.s-stats,.bird-stats,.t-stats,.p-stats,.f-hud,.n-journey,
    .m-actions,.s-actions,.bird-actions,.n-toolbar,.n-actions,.t-actions,.p-actions,.f-controls,
    .game-footer,.b-controls,.m-help,.s-help,.bird-help,.n-help,.t-help,.p-help,.f-help,
    #m-status,#s-status,#s-result,#bird-status,#bird-result,#n-status,#n-result,#n-save,
    #t-status,#t-save,#p-progress,#p-help,#p-result,#p-status,#p-tip,#p-save,#f-status),
  :is(#overlay,#b-overlay,#t-overlay,#f-overlay)>* {
    zoom:var(--mobile-ui-scale);
  }

  .game-admin :is(.admin-header,main,.admin-footer) { zoom:var(--mobile-ui-scale); }
}

@media (max-width:700px) and (min-height:501px) {
  /* Clear the floating equipment box after both controls have been compacted. */
  #rogue-panel #r-dash { bottom:96px; }
}

/* Scroll long menus with one finger, but never turn a game gesture into page zoom.
   Existing board/joystick touch-action:none rules have higher specificity. */
@media (pointer:coarse), (max-width:700px), (max-width:1000px) and (max-height:500px) {
  html,body,body * { touch-action:pan-x pan-y; }
}
