/* RF-AVALON Market V61.0.99 — mobile market fixes.
   UI-only: no trade, SQL, inventory or balance logic changes. */

@media (max-width: 760px) {
  /* 1) Header rule cards: never split the highlighted value word-by-word. */
  .item-market-heading .market-rule,
  .item-market-heading .item-duration-rule {
    box-sizing: border-box !important;
    display: flex !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    align-items: center !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    gap: 4px 7px !important;
    margin-left: 0 !important;
    padding: 10px 12px !important;
    text-align: left !important;
    line-height: 1.42 !important;
  }

  .item-market-heading .market-rule::before,
  .item-market-heading .item-duration-rule::before {
    flex: 0 0 auto !important;
  }

  .item-market-heading .market-rule strong,
  .item-market-heading .item-duration-rule strong {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
  }

  /* 1) Category counters were hidden by an older responsive rule. Restore them. */
  .item-category-panel nav button {
    grid-template-columns: 34px minmax(0, 1fr) 32px !important;
    column-gap: 10px !important;
  }

  .item-category-panel nav button > strong {
    min-width: 0 !important;
    justify-self: start !important;
    text-align: left !important;
  }

  .item-category-panel nav button > small,
  .item-category-panel nav .item-subcategory-button > small {
    display: inline-grid !important;
    place-items: center !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 30px !important;
    min-width: 30px !important;
    min-height: 22px !important;
    padding: 2px 4px !important;
    justify-self: end !important;
    white-space: nowrap !important;
  }

  .item-category-panel nav .item-subcategory-button {
    grid-template-columns: minmax(0, 1fr) 30px !important;
  }

  /* 2) Keep all seven talics on one row on phones. */
  .v61-touch .item-tooltip .talic-sockets,
  .v61-touch .item-tooltip .item-game-weapon .weapon-game-upgrades .talic-sockets {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 1px !important;
    min-width: 0 !important;
    width: max-content !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  /* Keep the native 22px talic atlas geometry. With the mobile tooltip using
     the full row width, all seven sockets fit without wrapping or sprite drift. */
  .v61-touch .item-tooltip .talic-socket {
    width: 22px !important;
    height: 22px !important;
    flex: 0 0 22px !important;
  }

  /* Weapon content gets the full card width below the reserved icon header. */
  .v61-touch .item-tooltip > .item-game-weapon:first-of-type,
  .v61-touch .item-tooltip > .item-game-special-v59:first-of-type .item-game-special-grid-v59 {
    padding-right: 0 !important;
    min-height: 0 !important;
  }

  .v61-touch .item-tooltip .item-game-weapon .weapon-game-upgrades,
  .v61-touch .item-tooltip .item-upgrade-row {
    grid-template-columns: 96px minmax(0, 1fr) !important;
    column-gap: 8px !important;
  }

  /* 3) Touch browsers synthesize :hover on first tap. Do not let that display
     a second, desktop-shaped tooltip. Only the explicit open class may show it. */
  html.v61-touch .equipment-slot.filled:not(.v61-tooltip-open) > .item-tooltip,
  html.v61-touch .equipment-slot.filled:not(.v61-tooltip-open):hover > .item-tooltip,
  html.v61-touch .equipment-slot.filled:not(.v61-tooltip-open):focus-visible > .item-tooltip {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  html.v61-touch .equipment-slot.filled {
    touch-action: manipulation !important;
  }

  /* Stable mobile bottom sheet. Its geometry is identical on first/repeated taps. */
  html.v61-touch .equipment-slot.v61-tooltip-open > .item-tooltip {
    box-sizing: border-box !important;
    left: 10px !important;
    right: 10px !important;
    top: auto !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: min(72dvh, 620px) !important;
    padding: 13px 14px 14px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  /* 4) Sprite math is generated for native 64x64 cells. Older mobile CSS forced
     the tooltip art to 58x58, clipping/offsetting atlas cells. Keep native size. */
  html.v61-touch .item-tooltip-art {
    width: 64px !important;
    min-width: 64px !important;
    height: 64px !important;
    min-height: 64px !important;
    top: 12px !important;
    right: 12px !important;
  }

  html.v61-touch .item-tooltip-title {
    box-sizing: border-box !important;
    min-height: 70px !important;
    padding-right: 76px !important;
    align-content: start !important;
  }

  html.v61-touch .item-tooltip > small {
    padding-right: 0 !important;
  }
}

@media (max-width: 420px) {
  .item-market-heading .market-rule,
  .item-market-heading .item-duration-rule {
    padding: 9px 10px !important;
    gap: 3px 6px !important;
  }

  .item-category-panel nav button {
    grid-template-columns: 34px minmax(0, 1fr) 32px !important;
  }
}
