/* Mobile detail views only. Desktop styles and game state stay unchanged. */
@media (max-width: 900px) {
  body:has(.game-hud) :is(main.realm, main.mapview, main.tower, main.full-hub, main.logview) {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  body:has(.game-hud) :is(.realm .realm-war-layout, .realm .rbody, .tower .rbody, main.mapview, .mapview:has(.realm-cross-nav), .craft-hub .hub-content > .list) {
    grid-template-columns: minmax(0, 1fr);
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) :is(.side, .box, .list, .item, .item .r, .rhead > div, .realm-war-left, .realm-war-right, .hub-title > div, .hub-content, .skillbar, .ranks li > *, .bt-side) {
    min-width: 0;
    max-width: 100%;
  }

  body:has(.game-hud) :is(.realm, .tower) .rhead {
    grid-template-columns: minmax(0, 1fr);
    padding: 18px 16px;
    gap: 14px;
  }

  body:has(.game-hud) .tower .tfloor {
    justify-items: start;
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) :is(.ops-head, .realm-cross-nav, .zph, .region .rh, .zone .zh) {
    flex-wrap: wrap;
  }

  body:has(.game-hud) :is(.realm, .mapview) .rank {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body:has(.game-hud) :is(.realm, .mapview) .rank span {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  body:has(.game-hud) .realm .realm-war-right .bang-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
  }

  body:has(.game-hud) .realm .realm-war-right .bang-tabs button {
    min-width: 0;
    min-height: 44px;
    padding: 9px 5px;
    font-size: 15px;
    white-space: normal;
    overflow-wrap: anywhere;
    border: 1px solid var(--line);
    margin: -1px 0 0 -1px;
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) :is(.ranks .nm, .log li, .bt-log li, .item .t, .say, .hint) {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) :is(.btn, .btn.sm, .mtabs button) {
    min-width: 44px;
    min-height: 44px;
    max-width: 100%;
    padding: 9px 12px;
    justify-content: center;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) .btn.sm {
    font-size: 15px;
  }

  body:has(.game-hud) :is(.realm, .mapview, .tower, .full-hub, .logview, #sheetRoot) :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
    line-height: 1.5;
  }

  body:has(.game-hud) :is(.full-hub, #sheetRoot) :is(.mtabs, .chips, .row-btns) {
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
  }

  body:has(.game-hud) :is(.full-hub, #sheetRoot) .badge {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body:has(.game-hud) :is(.market-hub .hub-content > .list, #sheetRoot .list) > .item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 13px 12px;
  }

  body:has(.game-hud) :is(.market-hub, .craft-hub, #sheetRoot) .item .r {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }

  body:has(.game-hud) .full-hub .hub-title {
    padding: 18px 16px;
  }

  body:has(.game-hud) .full-hub .hub-content {
    padding: 16px 12px;
  }

  body:has(.game-hud) .market-hub .market-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 12px;
  }

  body:has(.game-hud) .market-hub .market-search input {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  body:has(.game-hud) .market-hub .market-table-scroll {
    overflow: visible;
  }

  body:has(.game-hud) .market-hub .market-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  /* Keep table headings available to assistive technology, without a wide header. */
  body:has(.game-hud) .market-hub .market-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  body:has(.game-hud) .market-hub .market-table tbody {
    display: block;
    width: 100%;
  }

  body:has(.game-hud) .market-hub .market-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 14px;
    padding: 15px 12px;
    border-bottom: 1px solid rgba(152, 136, 108, .3);
  }

  body:has(.game-hud) .market-hub .market-table tbody tr:last-child {
    border-bottom: 0;
  }

  body:has(.game-hud) .market-hub .market-table tbody :is(th, td) {
    min-width: 0;
    padding: 5px 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 15px;
  }

  body:has(.game-hud) .market-hub .market-table tbody th {
    grid-column: 1 / -1;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(152, 136, 108, .2);
  }

  body:has(.game-hud) .market-hub .market-table tbody td {
    display: flex;
    flex-wrap: wrap;
    align-content: start;
    align-items: baseline;
    gap: 4px;
  }

  body:has(.game-hud) .market-hub .market-table td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 100%;
    color: var(--ink-soft);
    font-size: 15px;
    font-weight: 400;
  }

  body:has(.game-hud) .market-hub .market-table .market-trades {
    grid-column: 1 / -1;
    padding-top: 8px;
  }

  body:has(.game-hud) .market-hub .market-trades .row-btns {
    width: 100%;
    flex-wrap: wrap;
  }

  body:has(.game-hud) .market-hub .market-trades .btn {
    min-width: 80px;
  }

  body:has(.game-hud) .market-hub .market-table .mspark {
    max-width: 100%;
  }

  body:has(.game-hud) .market-hub .market-table tbody tr[hidden] {
    display: none !important;
  }

  body:has(.game-hud) #sheetRoot .sheet {
    top: max(8px, env(safe-area-inset-top, 0px));
    width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    height: calc(100vh - 16px);
    height: calc(100dvh - max(8px, env(safe-area-inset-top, 0px)) - max(8px, env(safe-area-inset-bottom, 0px)));
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top, 0px)) - max(8px, env(safe-area-inset-bottom, 0px)));
    min-width: 0;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  body:has(.game-hud) #sheetRoot .sheet header {
    padding: 12px 14px;
    align-items: flex-start;
  }

  body:has(.game-hud) #sheetRoot .sheet header > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  body:has(.game-hud) #sheetRoot .sheet header > .btn {
    flex: none;
  }

  body:has(.game-hud) #sheetRoot .sheet .body {
    min-width: 0;
    min-height: 0;
    padding: 16px 14px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 16px;
    font-size: 15px;
    line-height: 1.7;
    overflow-wrap: anywhere;
  }

  body:has(.game-hud) #sheetRoot .sheet .body :is(.hint, .label, small, .item .t div, .report dt) {
    font-size: 15px !important;
    line-height: 1.65;
  }

  body:has(.game-hud) #sheetRoot .mt-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body:has(.game-hud) #sheetRoot :is(.bt-top, .bt-end) {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  @media (max-width: 600px) {
    body:has(.game-hud) :is(.realm .bkmap, .mapview .regions) {
      grid-template-columns: minmax(0, 1fr);
    }

    body:has(.game-hud) .realm .bkmap :is(.z0, .z5) {
      width: 100%;
    }

    body:has(.game-hud) .realm .bacts {
      grid-template-columns: minmax(0, 1fr);
    }

    body:has(.game-hud) .full-hub .hub-resource {
      border-left: 0;
      padding-left: 0;
      justify-items: start;
    }

    body:has(.game-hud) .tower .tstats {
      grid-template-columns: minmax(0, 1fr);
    }
  }
}
