/* Smartphone controls: lightweight navigation over the existing Mountgate stone.
   Choose controls by purpose, not by their historical primary/secondary class:
   several secondary buttons execute purchases, crafting or item transfers.
   Main actions, confirmations, red close buttons and item slots keep their art. */
html.gom-compact {
  --mg-mobile-control-fill: rgb(12 13 12 / 42%);
  --mg-mobile-control-selected: rgb(191 151 82 / 16%);
  --mg-mobile-control-border: rgb(177 153 108 / 30%);
  --mg-mobile-control-accent: #d5b67a;
}

html.gom-compact :is(
  [data-processing-compact-back],
  [data-processing-compact-filters],
  [data-processing-filter],
  [data-processing-tab-scroll],
  .processing-category-list > button,
  .processing-qty-btn,
  .processing-qty-preset,
  .processing-favorite,
  .processing-queue-toggle,
  .crafting-duration-estimate-hint,
  [data-cooking-bulk-size],
  [data-mysticism-bulk-size],
  .mysticism-ingredient-option,
  .activity-session-btn,
  .trade-pane-selector,
  .trade-mode-tab,
  [data-action="select-trade-pane"],
  [data-action="select-sell-source"],
  [data-action="select-trade-item"],
  [data-action="trade-qty-step"],
  [data-action="trade-qty-preset"],
  [data-action="trade-qty-max"],
  .flea-market-tabs > [data-tab],
  .flea-market-categories [data-category],
  [data-select-visitor],
  [data-view-seller],
  [data-auto-health-category-toggle],
  [data-auto-health-mode],
  [data-auto-health-category-block],
  [data-auto-health-category-unblock],
  [data-auto-health-priority-add],
  [data-auto-health-priority-remove],
  [data-quantity-decrease],
  [data-quantity-increase],
  [data-quantity-preset],
  [data-quantity-choice],
  [data-quantity-cancel],
  [data-overview-skill],
  [data-skill-section],
  [data-skill-filter],
  [data-view-skill-masteries],
  [data-mastery-skill],
  [data-mastery-refresh],
  [data-mastery-reset],
  [data-mastery-remove],
  [data-settings-tab],
  .escape-menu-btn[data-menu-action="resume"],
  .escape-menu-btn[data-menu-action="view"],
  .escape-menu-btn[data-menu-action="external"],
  .journal-mode-tab,
  .journal-section-tab,
  .journal-chapter-tab,
  [data-quest-category],
  [data-quest-tab],
  [data-task-tab],
  [data-quest-back],
  .quest-track-button,
  [data-contract-refresh],
  [data-journal-back],
  [data-journal-search-clear],
  [data-journal-current-place],
  [data-office-tab],
  [data-office-refresh],
  [data-courier="back"],
  [data-courier="refresh"],
  [data-courier="previous"],
  [data-courier="next"],
  [data-courier="board"],
  [data-courier="mine"],
  .bottom-social-search > .bottom-chat-send-btn,
  .farming-window-tabs > button,
  [data-bank-coin-trigger],
  [data-storage-retry],
  [data-supporter-window-open],
  [data-supporter-refresh],
  [data-character-title-trigger],
  .character-title-select,
  .pro-preflight [data-action="refresh"],
  .pro-fishing-root [data-action="refresh"],
  #openConsentPreferencesBtn,
  .worldmap-layer-btn,
  [data-worldmap-presentation],
  [data-worldmap-legend-toggle],
  [data-bank-tab],
  .bank-storage-tab,
  [data-bank-storage-toggle],
  [data-freight-direction],
  .inventory-tools-toggle,
  [data-inventory-layout],
  .inventory-layout-presets > button,
  [data-layout-action="cancel"],
  [data-inventory-action="fill-bucket-back"],
  [data-rest-service-clear],
  [data-character-tab],
  [data-reputation-toggle],
  .bottom-chat-scope-btn,
  .chat-window-control,
  [data-chat-window-action]
):not(.gom-close-icon):not(.is-danger):not([data-menu-action="logout"]) {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  height: auto;
  padding: 9px 12px;
  border: 1px solid var(--mg-mobile-control-border) !important;
  border-image: none !important;
  border-radius: 7px !important;
  background: var(--mg-mobile-control-fill) !important;
  box-shadow: none !important;
  color: var(--mg-text-main, #eadfc7);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  text-shadow: none !important;
  white-space: normal;
  overflow-wrap: anywhere;
  transform: none !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgb(213 182 122 / 16%);
  transition: background-color 100ms ease, border-color 100ms ease, color 100ms ease;

  /* Replace the desktop decorative underline only on these utility controls.
     Unread badges and unrelated pseudo-elements are deliberately untouched. */
  &::after { display: none !important; }

  &:not(:disabled):not([aria-disabled="true"]):is(
    .active, .is-active, .is-selected, .selected, .is-tracked,
    [aria-pressed="true"], [aria-selected="true"], [aria-expanded="true"]
  ) {
    border-color: var(--mg-mobile-control-accent) !important;
    background: var(--mg-mobile-control-selected) !important;
    box-shadow: inset 0 -2px var(--mg-mobile-control-accent) !important;
    color: #f4e5bd;
  }

  &:not(:disabled):not([aria-disabled="true"]):active {
    background: rgb(213 182 122 / 23%) !important;
    border-color: var(--mg-mobile-control-accent) !important;
  }

  &:focus-visible {
    outline: 2px solid var(--mg-mobile-control-accent);
    outline-offset: 2px;
  }

  &:disabled, &[aria-disabled="true"] {
    opacity: .45;
    color: var(--mg-text-muted, #b7af9e);
  }
}

/* Preserve recognisable item/skill artwork; small utility icons need no skin. */
html.gom-compact :is(
  [data-overview-skill], .processing-favorite, [data-mastery-refresh],
  .inventory-tools-toggle, [data-inventory-layout], [data-rest-service-clear],
  .chat-window-control, [data-chat-window-action]
) {
  padding: 6px;
}
html.gom-compact .crafting-duration-estimate-hint {
  width: 44px;
  padding: 6px;
  flex: 0 0 44px;
}
/* Desktop paints this cog as the button background and hides the real image.
   The flat mobile button uses the existing image as its visible content. */
html.gom-compact [data-inventory-layout] {
  display: grid;
  place-items: center;
}
html.gom-compact [data-inventory-layout] > .settings-button-icon {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
}
html.gom-compact :is(.processing-qty-btn, .processing-qty-preset) {
  flex: 0 0 auto;
  padding-inline: 10px;
  font-variant-numeric: tabular-nums;
}
html.gom-compact .processing-queue-toggle {
  width: 100%;
  text-align: left;
}
html.gom-compact [data-processing-compact-filters] { text-align: left; }
html.gom-compact .escape-menu-btn { text-align: left; }

/* Nested map utilities share the panel material without another ornate frame.
   The surrounding map/window frame and all marker artwork stay intact. */
html.gom-compact :is(.worldmap-legend, .worldmap-world-info, .worldmap-zoom-controls) {
  border: 1px solid var(--mg-mobile-control-border) !important;
  border-radius: 8px !important;
  box-shadow: 0 3px 12px rgb(0 0 0 / 25%) !important;
}
html.gom-compact :is(.worldmap-legend, .worldmap-world-info, .worldmap-zoom-controls) > .mg-frame-art {
  display: none;
}

/* Readable native inputs avoid iOS focus zoom and keep the stone behind them. */
html.gom-compact [data-mg-surface="window"] :is(
  input[type="search"], input[type="number"], input[type="text"], select
) {
  box-sizing: border-box;
  min-height: 44px;
  max-width: 100%;
  border: 1px solid var(--mg-mobile-control-border);
  border-radius: 6px;
  background-color: rgb(10 11 10 / 55%);
  color: var(--mg-text-main, #eadfc7);
  font: 16px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
html.gom-compact [data-mg-surface="window"] :is(input, select):focus-visible {
  outline: 2px solid var(--mg-mobile-control-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html.gom-compact :is(button, input, select) { transition: none !important; }
}

/* Compact settings navigation only. Append after the existing mobile rules.
   Keep the single vertical content scroller and all current button skins. */
html.gom-compact #settingsOverlay .escape-menu-layout {
  touch-action: pan-x pan-y;
}
html.gom-compact #settingsOverlay .escape-menu-sidebar {
  min-width: 0;
  padding: 8px 10px;
}
html.gom-compact #settingsOverlay .escape-menu-nav {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding-bottom: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--mg-brass) transparent;
}
html.gom-compact #settingsOverlay .escape-menu-nav > .escape-menu-btn {
  flex: 0 0 auto;
  width: max-content;
  min-width: 100px;
  max-width: min(70vw, 220px);
  min-height: 44px;
  box-sizing: border-box;
  scroll-snap-align: start;
  scroll-margin-inline: 4px;
  white-space: normal;
}
html.gom-compact #settingsOverlay .settings-tabs {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding-bottom: 4px;
}
html.gom-compact #settingsOverlay .settings-tabs > button {
  flex: 0 1 auto;
  width: auto;
  min-width: 44px;
  max-width: 100%;
  min-height: 44px;
  height: auto;
  box-sizing: border-box;
  padding: 8px 10px;
  white-space: normal;
  overflow-wrap: anywhere;
}
/* The close button is already in the fixed compact header. */
html.gom-compact #settingsOverlay .escape-panel-actions:empty { display: none; }

/* These two legacy overlays do not use the shared .overlay class. Give their
   mobile windows the same available space as inventory, health and handbook. */
html.gom-compact :is(#skillOverlay, #settingsOverlay):not(.hidden) {
  position: fixed;
  inset: 0;
  width: 100%;
  height: var(--compact-viewport-height, 100dvh);
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) calc(var(--compact-nav-height) + env(safe-area-inset-bottom) + 6px) max(6px, env(safe-area-inset-left));
  box-sizing: border-box;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
}

/* The bank shares coin artwork with the top bar, but its balances need intact
   denomination groups and the full compact header width. */
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-window > .bank-workspace-header {
  grid-template-columns:minmax(0,1fr) auto;
  grid-template-areas:"main close" "balances balances";
  gap:8px;
  min-height:0;
  padding:10px 12px;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-workspace-header .bank-hero-main { gap:8px; }
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-workspace-header .bank-pennant {
  position:static; flex:0 0 32px; width:32px; height:48px;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-workspace-balances {
  display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); width:100%; box-sizing:border-box;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-workspace-balances .bank-hero-coins-wrap { grid-area:auto; }
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-workspace-balances .bank-balance {
  width:100%; min-width:0; min-height:56px; flex-direction:column; flex-wrap:nowrap; gap:4px; padding:6px;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-balance-label { font-size:12px; }
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-balance-value {
  display:flex; flex-wrap:wrap; justify-content:center; max-width:100%; gap:4px 6px; font-size:13px;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-balance-value .topbar-coin-group {
  flex:0 0 auto; gap:3px; white-space:nowrap;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-balance-value .topbar-coin-icon {
  flex:0 0 16px; width:16px; height:16px;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-balance-value .topbar-coin-value {
  flex:0 0 auto; max-width:none; white-space:nowrap; overflow-wrap:normal; word-break:normal;
}
/* Three labelled destinations remain readable at320px without splitting words. */
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-primary-tabs { gap:4px; padding:0 8px; }
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-primary-tab {
  flex-direction:column; gap:2px; min-height:56px; padding:6px !important; font-size:13px;
  white-space:nowrap; overflow-wrap:normal; word-break:normal;
}
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-primary-tab img { flex:0 0 24px; width:24px; height:24px; }
html.gom-compact body.bank-unified-workspace #bankOverlay .bank-primary-tab > span { white-space:nowrap; overflow-wrap:normal; word-break:normal; }
