/* Touch layouts keep real CSS hit areas; no scaled-down button groups. */
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){
 button,a[role=button],input,select,summary{min-height:44px;touch-action:manipulation}input,select,textarea{font-size:16px!important}button{scroll-margin:16px;min-width:44px}button:focus-visible,input:focus-visible,select:focus-visible{outline-offset:3px}
 [role=dialog],dialog,.modal-card,.modal,.screen,.overlay{overscroll-behavior:contain;scrollbar-width:thin}dialog{max-height:calc(100dvh - 24px);overflow:auto}.icon-button{min-width:48px;min-height:48px}
}

#touch-more,#touch-flight,#touch-descend{display:none}
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){
 .hud-top{padding:12px;gap:8px}.hud-actions{gap:6px;flex-shrink:0}.hud-actions .icon-button{width:48px;height:48px;min-width:48px}.hud-actions>span{display:none}.hud-identity{min-width:0}.hud-identity>span{max-width:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.hud-utilities{top:72px;gap:8px}.hud-utilities button{min-width:48px;min-height:44px;padding:8px}
 #touch-controls{--pad:60px;--edge:max(12px,env(safe-area-inset-bottom));--floor:calc(90px + var(--edge))}
 #touch-controls .dpad{left:max(12px,env(safe-area-inset-left));bottom:var(--floor);grid-template-columns:repeat(3,var(--pad));grid-template-rows:repeat(2,var(--pad));gap:8px}
 #touch-controls .dpad button{width:var(--pad);height:var(--pad);font-size:24px;border-radius:14px;background:#173d2cdd}
 #touch-controls .touch-actions{right:max(12px,env(safe-area-inset-right));bottom:var(--floor);grid-template-columns:repeat(2,var(--pad));grid-template-rows:repeat(2,var(--pad));gap:8px}
 #touch-controls .touch-actions button{height:var(--pad);width:var(--pad);font-size:12px;border-radius:14px;background:#173d2cdd}
 #touch-jump{grid-column:2!important;grid-row:2!important;height:var(--pad)!important;font-size:24px!important}#touch-mine{grid-column:1;grid-row:1}#touch-place{grid-column:2;grid-row:1}#touch-shield{grid-column:1;grid-row:2}
 #touch-more,#touch-flight,#touch-descend{display:block;position:absolute;bottom:calc(var(--floor) + var(--pad)*2 + 18px);width:56px;height:48px;min-height:48px;background:#193e2ef0;font-size:11px}
 #touch-more{right:12px}#touch-flight{right:76px}#touch-descend{right:140px}#touch-flight[hidden],#touch-descend[hidden]{display:none}
 #touch-controls .touch-tools{display:none!important;position:absolute;left:auto!important;right:12px!important;top:auto!important;bottom:calc(var(--floor) + var(--pad)*2 + 74px)!important;width:min(296px,calc(100vw - 24px));max-width:none;max-height:calc(100dvh - 340px);overflow:auto;grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:8px;padding:10px;background:#173326f5;border:1px solid #ccd8ad55;border-radius:14px;pointer-events:auto}
 body.mobile-tools-open #touch-controls .touch-tools{display:grid!important}#touch-controls .touch-tools button{min-width:0;width:100%!important;height:48px;min-height:48px;font-size:11px}#touch-controls .touch-tools #touch-map{grid-column:auto}
 .dialog{max-height:calc(100dvh - 24px);overflow:auto;padding:22px 18px}.palette-block{min-height:92px}.filter-tabs button,.atlas-notes button,.landmark-list button{min-height:48px}.hotbar-wrap{bottom:max(12px,env(safe-area-inset-bottom))}.hotbar{gap:3px}.hotbar button{min-height:44px}.control-hint{display:none}.toast{bottom:calc(246px + env(safe-area-inset-bottom));max-width:calc(100vw - 24px)}
}
@media(max-width:359px){#touch-controls{--pad:56px}#touch-controls .dpad{grid-template-columns:repeat(2,56px);grid-template-rows:repeat(2,56px)}#touch-controls .touch-up{grid-column:1;grid-row:1}#touch-controls .touch-right{grid-column:2;grid-row:1}#touch-controls .touch-left{grid-column:1;grid-row:2}#touch-controls .touch-down{grid-column:2;grid-row:2}.hud-identity>span{max-width:54px}.hud-identity strong>span{display:none}.hud-identity strong{font-size:8px;letter-spacing:1px}.hud-actions{gap:4px}.hud-actions .icon-button{width:44px;min-width:44px}.hud-utilities{max-width:calc(100vw - 24px);overflow:auto;white-space:nowrap}.hotbar{max-width:calc(100vw - 12px);overflow:auto;justify-content:flex-start}.hotbar button{min-width:44px}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){#touch-controls{--pad:56px;--floor:max(12px,env(safe-area-inset-bottom))}#touch-controls .touch-tools{max-height:calc(100dvh - 252px)}.hud-top{padding:8px 12px}.hud-utilities{top:64px}.hotbar-wrap{max-width:calc(100vw - 400px);left:50%;width:calc(100vw - 400px)}.hotbar{overflow:auto;justify-content:flex-start}.hotbar button{min-width:44px}.toast{bottom:160px;max-width:350px}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.hud-utilities{max-width:calc(100vw - 24px);overflow-x:auto;flex-wrap:nowrap;white-space:nowrap}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.hotbar{max-width:calc(100vw - 24px);overflow-x:auto;justify-content:flex-start;scrollbar-width:thin;touch-action:pan-x}.hotbar button,.hotbar-slot,.hotbar .slot{width:44px!important;min-width:44px!important;min-height:44px;flex:0 0 44px!important}}

/* Keep the More tray below the native room/chat header, including short windows. */
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){
 #touch-controls .touch-tools{max-height:max(70px,calc(100dvh - var(--floor) - var(--pad)*2 - 206px))}
 .mode-buttons .primary,.mode-buttons .secondary,.dialog .secondary,.panel-action{min-height:48px!important}
}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){#touch-controls .touch-tools{max-height:calc(100dvh - 264px)}}

@media(max-height:500px) and (min-width:520px) and (max-width:950px){.hotbar-wrap{max-width:calc(100vw - 424px);width:calc(100vw - 424px)}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){#touch-more,#touch-controls .touch-tools{right:max(12px,env(safe-area-inset-right))!important}#touch-flight{right:calc(max(12px,env(safe-area-inset-right)) + 64px)}#touch-descend{right:calc(max(12px,env(safe-area-inset-right)) + 128px)}}

@media(max-height:500px) and (min-width:520px) and (max-width:950px){.hotbar-wrap{max-width:calc(100vw - 424px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px));width:calc(100vw - 424px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px))}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.hud-top{padding-left:max(12px,env(safe-area-inset-left));padding-right:max(12px,env(safe-area-inset-right))}}

/* A floating analog thumbstick replaces only the left movement pad. */
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){#touch-controls .dpad{--xg-stick-size:128px;display:block!important;width:128px;height:128px;grid-template-columns:none;grid-template-rows:none;gap:0;padding:0;background:none;border:0;box-shadow:none}}
@media(max-width:359px), (max-height:500px) and (min-width:520px) and (max-width:950px){#touch-controls .dpad{--xg-stick-size:112px;width:112px;height:112px}}
