/* Touch reading screens share viewport bounds and reachable controls. The
   desktop layouts and each panel's existing state/controller remain intact. */
.mobilePanelBack {display:none;}
body.touchDevice.mobileMatchMode {
  --mobile-panel-top:calc(var(--mobile-visual-top, 0px) + max(8px, env(safe-area-inset-top, 0px)));
  --mobile-panel-left:max(8px, env(safe-area-inset-left, 0px));
  --mobile-panel-right:max(8px, env(safe-area-inset-right, 0px));
  --mobile-panel-height:calc(var(--mobile-visual-height, 100dvh) - max(8px, env(safe-area-inset-top, 0px)) - max(8px, env(safe-area-inset-bottom, 0px)));
}
body.touchDevice.mobileMatchMode :is(#exploreInventoryPanel,#spellbookPanel,#exploreMasteryPanel,#runicCorePanel,#exploreVendorShopPanel) {
  position:fixed;inset:var(--mobile-panel-top) var(--mobile-panel-right) auto var(--mobile-panel-left);
  width:auto;height:var(--mobile-panel-height);max-height:none;padding:0;
}
body.touchDevice.mobileMatchMode :is(.inventoryPhase2Shell,.spellbookShell,.exploreMasteryShell,.runicCoreShell,.exploreVendorShopShell) {
  box-sizing:border-box;position:relative;inset:auto;transform:none;margin:0;
  width:100%;height:100%;max-height:100%;min-height:0;max-width:100%;
  overflow:auto;overscroll-behavior:contain;touch-action:pan-y pinch-zoom;
  scroll-padding:64px 12px 20px;scrollbar-width:thin;
}
body.touchDevice.mobileMatchMode :is(#exploreInventoryClose,#spellbookClose,#exploreMasteryClose,#runicCoreClose,#exploreVendorShopClose) {
  position:fixed;top:calc(var(--mobile-panel-top) + 8px);right:calc(var(--mobile-panel-right) + 8px);
  width:44px;height:44px;min-height:44px;padding:0;z-index:8;
  display:grid;place-items:center;border-radius:10px;background:#202c40;color:#f5eddf;
  box-shadow:0 3px 12px #0008;border:1px solid #8c7e68;
}
body.touchDevice.mobileMatchMode :is(.inventoryScreenHeader,.spellbookHeader,.exploreMasteryHeader,.runicCoreHeader,.exploreVendorShopHeader) {padding-right:54px;}
body.touchDevice.mobileMatchMode :is(#exploreInventoryPanel,#spellbookPanel,#exploreMasteryPanel,#runicCorePanel,#exploreVendorShopPanel,#npcDialogue,#npcInteractionMenu,.questMapPanel,.gameSettingsDialog,.adventurePanel,.matchChat.is-open) :is(button,select,summary) {min-height:44px;touch-action:manipulation;}
body.touchDevice.mobileMatchMode :is(#exploreInventoryPanel,#spellbookPanel,#exploreMasteryPanel,#runicCorePanel,#exploreVendorShopPanel,.gameSettingsDialog,.adventurePanel,.matchChat.is-open) :is(input:not([type=range]):not([type=checkbox]),select,textarea) {font-size:16px;min-width:0;max-width:100%;box-sizing:border-box;}
body.touchDevice.mobileMatchMode :is(.inventoryPhase3Filters,.spellbookFilters,.exploreMasterySchoolList,.exploreVendorShopFilters) {gap:8px;}
body.touchDevice.mobileMatchMode :is(.inventoryPhase2Shell,.spellbookShell,.exploreMasteryShell,.runicCoreShell,.exploreVendorShopShell) :is(.inventoryGridZone,.inventoryDetailsZone,.spellbookLibrary,.spellbookDetails,.exploreMasteryCenter,.exploreMasteryDetails,.runicOwnedPanel,.runicFocusPanel,.runicDetailsPanel) {min-width:0;}
body.touchDevice.mobileMatchMode :is(.inventoryPhase2Hint,.runicCoreFooterHint,.spellbookFooterHint,.exploreMasteryFooterHint,.exploreVendorShopHint) > :is(kbd,span) {display:none;}

/* Native dialogs already trap focus. Keep their existing scroll containers. */
body.touchDevice.mobileMatchMode :is(.gameSettingsDialog,.questMapPanel,.adventurePanel) {
  box-sizing:border-box;position:fixed;inset:var(--mobile-panel-top) var(--mobile-panel-right) auto var(--mobile-panel-left);
  margin:0 auto;width:auto;max-width:none;max-height:var(--mobile-panel-height);overscroll-behavior:contain;
}
body.touchDevice.mobileMatchMode .gameSettingsDialog {width:min(650px,calc(100% - var(--mobile-panel-left) - var(--mobile-panel-right)));}
body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsRow select {font-size:16px;}
body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsSlider input {height:44px;}
body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsClose {width:44px;}
body.touchDevice.mobileMatchMode .questMapPanel .questMapHeader {position:sticky;top:0;z-index:2;gap:12px;}
body.touchDevice.mobileMatchMode .questMapPanel .questMapClose {min-width:88px;flex-shrink:0;}
body.touchDevice.mobileMatchMode .questMapPanel .questMapBody {grid-template-columns:minmax(0,1fr);}
body.touchDevice.mobileMatchMode .questMapPanel .questMapSidebar {max-height:none;overflow:visible;}
body.touchDevice.mobileMatchMode .questMapPanel .questMapQuestList {grid-template-columns:minmax(0,1fr);}

body.touchDevice.mobileMatchMode :is(#npcDialogue,#npcInteractionMenu) {
  bottom:auto;top:var(--mobile-panel-top);left:var(--mobile-panel-left);right:var(--mobile-panel-right);
  transform:none;width:auto;max-height:var(--mobile-panel-height);overscroll-behavior:contain;background:linear-gradient(135deg,#1b283b,#0d1422 70%);
}
body.touchDevice.mobileMatchMode :is(#npcDialogue .npcDialogueClose,#npcInteractionMenu .npcInteractionClose) {width:44px;height:44px;top:8px;right:8px;}
body.touchDevice.mobileMatchMode #npcInteractionMenu .npcInteractionClose {position:fixed;top:calc(var(--mobile-panel-top) + 8px);right:calc(var(--mobile-panel-right) + 8px);}
body.touchDevice.mobileMatchMode :is(#npcDialogue .npcDialogueSpeaker,#npcInteractionMenu .npcInteractionName) {padding-right:44px;}
body.touchDevice.mobileMatchMode #npcDialogue .npcDialogueShell {scroll-padding-top:56px;}

/* The composer follows the visible viewport, rather than sitting underneath
   the keyboard at the bottom of a fixed-height game canvas. */
body.touchDevice.mobileMatchMode .matchChat.is-open {
  position:fixed;inset:auto var(--mobile-panel-right) auto var(--mobile-panel-left);
  top:calc(var(--mobile-panel-top) + var(--mobile-panel-height));transform:translateY(-100%);
  width:auto;max-width:none;max-height:var(--mobile-panel-height);z-index:185;
  display:flex;flex-direction:column;box-sizing:border-box;padding:12px;
}
body.touchDevice.mobileMatchMode .matchChat.is-open .matchChatLog {flex:1 1 auto;min-height:0;max-height:180px;overscroll-behavior:contain;}
body.touchDevice.mobileMatchMode .matchChat.is-open .matchChatComposer {flex-shrink:0;}
body.touchDevice.mobileMatchMode .matchChat.is-open .matchChatHeading button {padding:8px 12px;min-width:60px;font-size:12px;}

body.touchDevice.mobileMatchMode .mobileBossGateDialog {
  box-sizing:border-box;position:fixed;inset:var(--mobile-panel-top) var(--mobile-panel-right) auto var(--mobile-panel-left);
  margin:auto;width:min(470px,calc(100% - var(--mobile-panel-left) - var(--mobile-panel-right)));
  max-height:var(--mobile-panel-height);overflow:auto;overscroll-behavior:contain;
  padding:24px;border:1px solid #b49a67;border-radius:16px;background:linear-gradient(145deg,#253047,#111a2b);
  color:#f0eadc;box-shadow:0 24px 75px #000b;font:14px/1.6 var(--ui-font,system-ui);
}
body.touchDevice.mobileMatchMode .mobileBossGateDialog::backdrop {background:#080b16cc;}
body.touchDevice.mobileMatchMode .mobileBossGateDialog h2 {margin:0 0 12px;font:25px/1.25 Georgia,serif;color:#f0d599;overflow-wrap:anywhere;}
body.touchDevice.mobileMatchMode .mobileBossGateDialog p {margin:10px 0;overflow-wrap:anywhere;}
body.touchDevice.mobileMatchMode .mobileBossGateDialog [data-boss-gate-detail] {color:#d1c4ad;}
body.touchDevice.mobileMatchMode .mobileBossGateActions {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-top:20px;}
body.touchDevice.mobileMatchMode .mobileBossGateActions button {min-height:48px;padding:10px 12px;border:1px solid #8f7b57;border-radius:8px;font:600 14px/1.4 var(--ui-font,system-ui);background:#29364d;color:#f5ead5;touch-action:manipulation;}
body.touchDevice.mobileMatchMode .mobileBossGateActions [data-boss-gate-enter] {background:#d8bd83;border-color:#f1dca8;color:#172033;}
body.touchDevice.mobileMatchMode .mobileBossGateActions button:focus-visible {outline:2px solid #9ddfff;outline-offset:3px;}

@media(max-width:1024px) {
  body.touchDevice.mobileMatchMode .mobilePanelBack {display:block;align-self:start;justify-self:start;margin:0 0 12px;padding:10px 14px;min-height:44px;border:1px solid #786d86;border-radius:8px;background:#242c40;color:#e7d4ac;font:600 13px/1.4 var(--ui-font,system-ui);text-align:left;}
  body.touchDevice.mobileMatchMode .mobilePanelBack:focus-visible {outline:2px solid #9ddfff;outline-offset:3px;}
  body.touchDevice.mobileMatchMode :is(.inventoryPhase2Shell,.spellbookShell,.exploreMasteryShell,.runicCoreShell,.exploreVendorShopShell) {display:block;padding:16px;}
  body.touchDevice.mobileMatchMode .inventoryScreenHeader {margin-bottom:14px;}
  body.touchDevice.mobileMatchMode .inventoryCharacterZone {display:grid;grid-template-columns:minmax(0,.75fr) minmax(0,1fr);border:0;padding:0;overflow:visible;align-items:center;margin-bottom:18px;}
  body.touchDevice.mobileMatchMode #exploreInventoryCharacterPreview {width:100%;max-width:100%;height:auto;max-height:200px;}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlots {min-width:0;}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlot {min-width:0;padding:10px;}
  body.touchDevice.mobileMatchMode .inventoryGridZone {overflow:visible;margin-bottom:18px;}
  body.touchDevice.mobileMatchMode .inventoryDetailsZone {max-height:none;overflow:visible;}
  body.touchDevice.mobileMatchMode .inventoryDetailsZone .inventoryPhase4Actions {position:static;}
  body.touchDevice.mobileMatchMode .inventoryPhase3Grid {max-height:min(420px,60dvh);min-height:160px;grid-template-columns:repeat(auto-fill,minmax(100px,1fr));overscroll-behavior:auto;}
  body.touchDevice.mobileMatchMode :is(.spellbookBody,.exploreMasteryBody,.runicCoreBody) {display:flex;flex-direction:column;overflow:visible;gap:14px;height:auto;}
  body.touchDevice.mobileMatchMode :is(.spellbookFilters,.exploreMasterySchoolList) {display:flex;flex-direction:row;flex-wrap:wrap;overflow:visible;}
  body.touchDevice.mobileMatchMode .spellbookFilters>button {flex:1 1 120px;}
  body.touchDevice.mobileMatchMode .spellbookFilterLore {display:none;}
  body.touchDevice.mobileMatchMode .spellbookLibrary {min-height:0;}
  body.touchDevice.mobileMatchMode .spellbookGrid {max-height:min(440px,60dvh);grid-template-columns:repeat(auto-fit,minmax(200px,1fr));overscroll-behavior:auto;}
  body.touchDevice.mobileMatchMode :is(.spellbookDetails,.exploreMasteryDetails,.runicOwnedPanel,.runicFocusPanel,.runicDetailsPanel,.runicDetailsScroll) {min-height:0;overflow:visible;}
  body.touchDevice.mobileMatchMode .exploreMasterySchoolButton {flex:1 1 160px;}
  body.touchDevice.mobileMatchMode .exploreMasteryTree {max-height:min(500px,65dvh);overscroll-behavior:auto;}
  body.touchDevice.mobileMatchMode .runicCoreMilestone {grid-template-columns:minmax(0,1fr);}
  body.touchDevice.mobileMatchMode .runicOwnedList {max-height:min(300px,50dvh);overscroll-behavior:auto;}
  body.touchDevice.mobileMatchMode .runicSchoolGuide {border-left:0;padding-left:0;}
  body.touchDevice.mobileMatchMode .exploreVendorShopColumns {grid-template-columns:minmax(0,1fr);overflow:visible;}
  body.touchDevice.mobileMatchMode .exploreVendorShopPane {max-height:440px;min-height:220px;}
  body.touchDevice.mobileMatchMode .exploreVendorShopDetails {grid-template-columns:minmax(0,1fr);max-height:none;overflow:visible;}
}
@media(max-width:420px) {
  body.touchDevice.mobileMatchMode .inventoryCharacterZone {grid-template-columns:minmax(0,1fr);}
  body.touchDevice.mobileMatchMode #exploreInventoryCharacterPreview {max-height:145px;}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlots {grid-template-columns:repeat(2,minmax(0,1fr));}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlot>div {grid-template-columns:minmax(0,1fr);}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlot b {display:none;}
  body.touchDevice.mobileMatchMode .inventoryEquipmentMiniSlot strong {font-size:12px;}
  body.touchDevice.mobileMatchMode .equipmentInventoryBrowser {grid-template-columns:minmax(0,1fr);}
  body.touchDevice.mobileMatchMode .equipmentInventoryBrowser>details {max-width:100%;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsRow {flex-wrap:wrap;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsRow>span {flex-basis:160px;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsRow select {max-width:100%;flex:1 1 150px;}
  body.touchDevice.mobileMatchMode .questMapPanel .questMapHeader h2 {font-size:20px;overflow-wrap:anywhere;}
}
@media(max-height:500px) {
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsHeader {padding:10px 16px 4px;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsLiveNote {padding:0 16px 6px;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsTabs {padding-bottom:6px;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsFooter {padding:8px 16px;}
  body.touchDevice.mobileMatchMode .gameSettingsDialog .settingsBody {padding:12px 16px;}
}
