/* Game-local mobile exceptions. Desktop native pixels, shared portal CSS and
   fullscreen/leave logic remain owned by their existing modules. */
body[data-hud-profile='portal-mobile'] {
  --tc-safe-top: env(safe-area-inset-top, 0px);
  --tc-safe-right: env(safe-area-inset-right, 0px);
  --tc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tc-safe-left: env(safe-area-inset-left, 0px);
}
@media (min-width: 600px) and (max-width: 950px) and (max-height: 280px) {
  body[data-hud-profile='portal-mobile']:not(.mobile-keyboard) #world {
    height: calc(100% - 48px);
  }
  body[data-hud-profile='portal-mobile']:not(.mobile-keyboard) #hud {
    height: 48px;
  }
  body[data-hud-profile='portal-mobile']:not(.mobile-keyboard) #mini {
    top: 1px;
    width: 44px;
    height: 44px;
  }
  body[data-hud-profile='portal-mobile']:not(.mobile-keyboard) #commander-status {
    top: 1px;
    height: 44px;
    right: 54px;
    font-size: 10px;
  }
}
@media (max-width: 700px),
  (max-width: 950px) and (max-height: 500px),
  (max-width:1100px) and (pointer:coarse), (max-width:1600px) and (max-height:700px) and (any-pointer:coarse) {
  body[data-hud-profile='portal-mobile']:not(.embedded):not(.mobile-keyboard) {
    grid-template-rows: calc(44px + var(--tc-safe-top)) minmax(0, 1fr);
  }
  body[data-hud-profile='portal-mobile'] .native-mobile-bar {
    height: calc(44px + var(--tc-safe-top));
    min-height: calc(44px + var(--tc-safe-top));
    padding-top: var(--tc-safe-top);
    padding-left: max(6px, var(--tc-safe-left));
    padding-right: max(6px, var(--tc-safe-right));
    border-bottom: 0;
  }
  body[data-hud-profile='portal-mobile'] #viewport {
    padding-left: max(4px, var(--tc-safe-left));
    padding-right: max(4px, var(--tc-safe-right));
    padding-bottom: max(4px, var(--tc-safe-bottom));
  }
  body[data-hud-profile='portal-mobile'] .mobile-orders {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    align-content: start;
  }
  body[data-hud-profile='portal-mobile'] dialog {
    max-width: calc(100% - max(12px, var(--tc-safe-left)) - max(12px, var(--tc-safe-right)));
    max-height: calc(
      var(--mobile-vh, 100dvh) - max(8px, var(--tc-safe-top)) - max(8px, var(--tc-safe-bottom))
    );
    margin-top: max(8px, var(--tc-safe-top));
    margin-bottom: max(8px, var(--tc-safe-bottom));
    overscroll-behavior: contain;
  }
  body[data-hud-profile='portal-mobile'] #mobile-menu-dialog[open] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    grid-template-rows: 44px minmax(0, 1fr);
    gap: 8px;
  }
  body[data-hud-profile='portal-mobile'] #mobile-menu-dialog h2 {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    padding: 0;
    min-height: 44px;
  }
  body[data-hud-profile='portal-mobile'] .mobile-menu-close {
    position: static;
    grid-column: 2;
    grid-row: 1;
    width: 48px;
    min-height: 44px;
  }
  body[data-hud-profile='portal-mobile'] .mobile-menu-grid {
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }
  body[data-hud-profile='portal-mobile'] > #panel #panel-close {
    top: max(4px, var(--tc-safe-top)) !important;
    right: max(6px, var(--tc-safe-right));
    width: 48px;
    height: 44px !important;
  }
  body[data-hud-profile='portal-mobile'] > #panel #panel-title {
    left: max(8px, var(--tc-safe-left));
    top: max(8px, var(--tc-safe-top));
    max-width: calc(100% - max(8px, var(--tc-safe-left)) - max(6px, var(--tc-safe-right)) - 60px);
  }
  body[data-hud-profile='portal-mobile'] > #panel #panel-content {
    margin: calc(58px + var(--tc-safe-top)) max(8px, var(--tc-safe-right))
      max(16px, var(--tc-safe-bottom)) max(8px, var(--tc-safe-left));
  }
  body[data-hud-profile='portal-mobile'] > #panel .native-confirm {
    padding-bottom: max(10px, var(--tc-safe-bottom));
  }
  body[data-hud-profile='portal-mobile'].mobile-keyboard {
    grid-template-rows: minmax(0, 1fr);
  }
  body[data-hud-profile='portal-mobile'].mobile-keyboard .native-mobile-bar {
    display: none;
  }
  body[data-hud-profile='portal-mobile'].mobile-keyboard .mobile-orders {
    display: none;
  }
  html.game-screen-expanded body[data-hud-profile='portal-mobile'] {
    height: var(--mobile-vh, 100dvh) !important;
  }
  body[data-hud-profile='portal-mobile'].mobile-chat-open .game-fullscreen-notice {
    display: none;
  }
  body[data-hud-profile='portal-mobile'].mobile-chat-open :is(#chat-form, #chat-log) {
    left: max(8px, var(--tc-safe-left));
    right: max(8px, var(--tc-safe-right));
  }
  body[data-hud-profile='portal-mobile'].mobile-keyboard.mobile-chat-open #chat-form {
    bottom: calc(max(8px, var(--tc-safe-bottom)) + var(--mobile-keyboard-inset, 0px));
  }
  body[data-hud-profile='portal-mobile'].mobile-keyboard.mobile-chat-open #chat-log {
    bottom: calc(68px + max(0px, var(--tc-safe-bottom) - 8px) + var(--mobile-keyboard-inset, 0px));
  }
}
