/* 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}
}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){
 #joystick{left:max(12px,env(safe-area-inset-left));bottom:calc(40px + env(safe-area-inset-bottom));width:128px;height:128px;background:#142519c9}#joystickKnob{width:46px;height:46px;left:40px;top:40px;pointer-events:none}
 .touch-actions{right:max(12px,env(safe-area-inset-right));bottom:max(12px,env(safe-area-inset-bottom));grid-template-columns:repeat(2,60px);gap:8px}.touch-actions button{height:60px;min-width:60px;min-height:60px;font-size:11px;border-radius:13px;background:#142719e8;touch-action:none}.touch-look{bottom:215px;right:12px;max-width:130px;line-height:1.5}
 .hud-top-right .icon-button,.icon-button{min-width:48px;min-height:48px}.hud-top-right{top:max(8px,env(safe-area-inset-top));right:12px;gap:8px}.hud-top-right>span{display:none}.inventory{bottom:230px!important}.inventory button{min-width:48px;min-height:48px}.player-status{bottom:16px!important;left:150px!important;right:150px!important;width:auto!important}.player-status .status-label{font-size:8px}.danger-label,.flashlight-label{max-width:50vw}.prompt{min-height:56px;max-width:calc(100vw - 28px)}.menu,.panel,.settings-panel,.chapter-panel,.journal-panel{max-height:calc(100dvh - 24px);overflow:auto;overscroll-behavior:contain}.menu button,.panel button,.settings-panel button,.settings-panel select,.journal-panel button{min-height:48px}.settings-grid{gap:12px}.settings-grid input{min-height:44px}#rescue-team-hud{bottom:220px!important;max-width:calc(100vw - 24px)!important;font-size:11px!important;padding:10px 12px!important}.touch-actions button[hidden]{display:none}
}
@media(max-width:359px){#joystick{width:112px;height:112px}#joystickKnob{width:40px;height:40px;left:35px;top:35px}.touch-actions{grid-template-columns:repeat(2,56px)}.touch-actions button{height:56px;min-width:56px;min-height:56px}.player-status{display:none!important}.touch-look{bottom:205px}.menu{padding:16px}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){#joystick{bottom:max(12px,env(safe-area-inset-bottom));width:112px;height:112px}#joystickKnob{left:35px;top:35px;width:40px;height:40px}.touch-actions{grid-template-columns:repeat(3,56px);gap:8px}.touch-actions button{height:56px;min-width:56px;min-height:56px}.touch-look{display:none}.inventory{bottom:148px!important}.player-status{display:none!important}#rescue-team-hud{bottom:146px!important;max-width:360px!important}.hud-top-right{top:8px}.menu,.panel{padding:16px;max-height:calc(100dvh - 16px)}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.rescue-room-active .hud-objective{top:132px!important}.rescue-room-active .danger-label{display:none!important}.rescue-room-active #prompt{bottom:230px!important}.rescue-room-active #rescue-team-hud{bottom:298px!important}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){.rescue-room-active .hud-objective{top:12px!important;max-width:300px}.rescue-room-active #prompt{bottom:146px!important}.rescue-room-active #rescue-team-hud{bottom:208px!important}}

@media(max-height:500px) and (min-width:520px) and (max-width:950px){.hud-top-right{right:292px!important}}

/* Keep the fixed masthead from swallowing taps on the native Pause button. */
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){
 .masthead,body.playing .masthead{height:64px;padding:0 12px;pointer-events:none}
 .masthead a,.masthead button{pointer-events:auto}
 body.playing .masthead #sound{position:fixed;top:8px;right:68px;width:48px;height:48px;min-width:48px;justify-content:center;padding:8px}
 body.playing .masthead #soundLabel{display:none}
 .masthead .brand{font-size:8px;letter-spacing:.5px}.masthead .brand-mark{font-size:20px}
 .hud-top-right{right:12px;top:8px;z-index:13}.hud-top-right .icon-button{width:48px;height:48px;padding:8px}
 #prompt{top:auto!important;bottom:230px!important;min-height:56px;max-height:72px;overflow:hidden;width:calc(100vw - 28px)}
 .hud-objective{top:132px!important;left:12px!important;max-width:calc(100vw - 24px);max-height:84px;overflow:hidden}
 .rescue-room-active .hud-objective{display:none!important}
 #rescue-team-hud,.rescue-room-active #rescue-team-hud{top:132px!important;bottom:auto!important;width:calc(100vw - 24px);max-height:68px;overflow:hidden;font-size:11px!important;line-height:14px!important;padding:6px 8px!important}
 .inventory{right:12px;max-width:calc(100vw - 24px);overflow-x:auto;gap:8px;touch-action:pan-x}.inventory button{flex:0 0 56px;width:56px;min-height:48px}
 .menu-screen{overflow:auto;padding:84px 24px 30px}.menu-screen .menu-content{position:relative;inset:auto;transform:none;width:100%;max-width:660px}.menu-screen .mission-card{display:none}.menu-screen .menu-footer{position:relative;inset:auto;height:auto;margin-top:28px}
 .modal-screen{overflow:auto;align-content:start;padding:80px 20px 20px}
 .modal-content,.chapter-content,.chapter-library,.journal-content,.puzzle-content{max-height:calc(100dvh - 104px);overflow:auto;min-height:0}
 .map-panel{max-height:calc(100dvh - 24px);overflow:auto}
 .radio-caption{top:132px;max-height:calc(100dvh - 348px);overflow:auto;overscroll-behavior:contain}
 #hud:has(#radioCaption:not([hidden])) :is(.hud-objective,.inventory,#prompt,.escape-clock){visibility:hidden}
}
@media(max-height:600px) and (max-width:519px){.escape-clock{top:218px;left:12px;transform:none;width:112px;max-height:80px}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){
 body.playing .masthead #sound{right:348px}.hud-top-right{right:292px!important}
 .hud-objective{top:76px!important;max-width:260px;max-height:116px}
 #rescue-team-hud,.rescue-room-active #rescue-team-hud{top:76px!important;width:calc(100vw - 300px);max-height:52px}
 #prompt,.rescue-room-active #prompt{top:auto!important;bottom:140px!important;left:300px;right:212px;transform:none;width:auto;max-height:56px;min-height:56px;max-width:none}
 .rescue-room-active #prompt{left:212px;right:212px}
 .inventory{right:12px;max-width:184px;bottom:148px!important}
 .radio-caption{left:212px;right:148px;top:76px;width:auto;max-height:116px}
 .escape-clock{left:212px;top:76px;transform:none;width:145px;max-height:110px}
}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.inventory{top:224px!important;bottom:auto!important;min-height:48px}}
@media(max-height:600px) and (max-width:519px){#prompt,.rescue-room-active #prompt{top:280px!important;bottom:auto!important;left:12px;right:auto;transform:none;width:calc(50vw - 18px);max-height:64px}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){.inventory{top:auto!important;bottom:148px!important}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.menu-screen{padding-top:132px}.modal-screen,.settings-screen{padding-top:132px}.modal-content,.chapter-content,.chapter-library,.journal-content,.puzzle-content{max-height:calc(100dvh - 156px)}.map-panel{top:132px;transform:translateX(-50%);max-height:calc(100dvh - 148px)}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){.menu-screen{padding-top:76px}.modal-screen,.settings-screen{padding-top:76px}.modal-content,.chapter-content,.chapter-library,.journal-content,.puzzle-content{max-height:calc(100dvh - 100px)}.map-panel{top:76px;max-height:calc(100dvh - 92px)}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){#joystick{bottom:max(40px,env(safe-area-inset-bottom))}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){#joystick{bottom:max(12px,env(safe-area-inset-bottom))}}

@media(max-height:500px) and (min-width:520px) and (max-width:950px){.hud-top-right{right:calc(292px + env(safe-area-inset-right,0px))!important}body.playing .masthead #sound{right:calc(348px + env(safe-area-inset-right,0px))}.inventory{right:max(12px,env(safe-area-inset-right))}#prompt{left:calc(300px + env(safe-area-inset-left,0px));right:calc(212px + env(safe-area-inset-right,0px))}.rescue-room-active #prompt{left:calc(212px + env(safe-area-inset-left,0px));right:calc(212px + env(safe-area-inset-right,0px))}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){.escape-clock{top:132px;left:auto;right:12px;transform:none;width:112px;max-height:80px}#hud:has(#escapeClock:not([hidden])) .hud-objective{max-width:calc(100vw - 148px)}}
@media(max-height:500px) and (min-width:520px) and (max-width:950px){.escape-clock{left:212px;right:auto;top:76px;width:145px}#hud:has(#escapeClock:not([hidden])) .hud-objective{max-width:180px}}

@media(max-height:500px) and (min-width:520px) and (max-width:950px){.escape-clock{height:54px;max-height:54px;padding:6px;overflow:hidden}.escape-clock>span{display:block;line-height:8px}.escape-clock b{font-size:22px;line-height:22px;margin-top:4px}.escape-clock>i{margin-top:4px}}

@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){#pauseMap,#pauseRecordings{min-height:48px;min-width:140px}}

/* A floating analog thumbstick replaces only the left movement pad. */
@media(pointer:coarse),(any-pointer:coarse),(max-width:950px) and (max-height:900px){#joystick{--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){#joystick{--xg-stick-size:112px;width:112px;height:112px}}
