/* Touch layout is opt-in by input mode; desktop and physical gamepad UI are unchanged. */
#touch-controls[hidden], #touch-controls [hidden] { display:none!important; }
#touch-controls { position:fixed;inset:0;z-index:22;pointer-events:none;user-select:none;-webkit-user-select:none;--touch-ink:#f4eedb;--touch-line:#e8dcba55; }
#touch-controls button { pointer-events:auto;touch-action:none;color:var(--touch-ink);background:#122829bc;border:1px solid var(--touch-line);border-radius:15px;min-width:48px;min-height:48px;font:600 12px system-ui;letter-spacing:.02em;box-shadow:0 3px 15px #0002;-webkit-tap-highlight-color:transparent; }
#touch-controls button.pressed,#touch-controls button.toggled { background:#d6bd7a;color:#172b2a;border-color:#fff2c4; }
.touch-toolbar { position:absolute;top:max(12px,env(safe-area-inset-top));right:max(16px,env(safe-area-inset-right));display:flex;gap:7px; }
.touch-toolbar button {padding:0 11px;}
.touch-movement { position:absolute;left:max(24px,calc(env(safe-area-inset-left) + 12px));bottom:max(24px,calc(env(safe-area-inset-bottom) + 12px));width:136px;text-align:center; }
#touch-controls .touch-stick { width:132px;height:132px;min-width:132px;border-radius:50%;background:radial-gradient(circle,#173b3b55,#162d2c77);border:1px solid #f2e7c93b;position:relative; }
.touch-stick span { position:absolute;width:54px;height:54px;left:38px;top:38px;border:1px solid #f1e4c26b;background:#e6ddc42e;border-radius:50%;pointer-events:none; }
.touch-stick-label { display:block;color:#f4edda90;font:9px system-ui;letter-spacing:.2em;margin-top:8px; }
.touch-actions { position:absolute;right:max(20px,calc(env(safe-area-inset-right) + 12px));bottom:max(24px,calc(env(safe-area-inset-bottom) + 12px));display:grid;grid-template-columns:70px 76px;gap:9px;align-items:end; }
#touch-controls .touch-actions button {min-height:53px;max-width:100%;padding:7px;}
#touch-controls .touch-use {background:#cbb781dd;color:#172b2a;border-color:#f2dc9a;font-size:14px;min-height:67px;}
.touch-tip {position:absolute;bottom:14px;left:180px;right:180px;text-align:center;color:#f4edda88;font:10px system-ui;pointer-events:none;}
.touch-build {display:none;position:absolute;left:50%;bottom:24px;transform:translateX(-50%);grid-template-columns:repeat(2,70px);gap:6px;}
#touch-controls[data-kind=build] .touch-build {display:grid;}
#touch-controls[data-kind=build] .touch-tip {display:none;}
.touch-active {overscroll-behavior:none;-webkit-user-select:none;user-select:none;}
.touch-active #inventory-button,.touch-active #held-button,.touch-active #fullscreen-toggle {display:none!important;}
.touch-active .quiet-header {left:max(16px,env(safe-area-inset-left));top:max(15px,env(safe-area-inset-top));}
.touch-active .wordmark {font-size:15px;letter-spacing:.18em;}
.touch-active .quiet-time {font-size:9px;}
.touch-active #interaction {bottom:196px;max-width:calc(100vw - 36px);padding:9px 13px;pointer-events:none;}
.touch-active #interaction kbd {display:none;}
.touch-active #interaction-subtitle {max-width:280px;white-space:normal;}
.touch-active #toast {top:max(76px,calc(env(safe-area-inset-top) + 65px));bottom:auto;max-width:calc(100vw - 40px);font-size:12px;}
.touch-active #health-warning {bottom:190px;left:16px;max-width:180px;}
.touch-active #boost-readout {bottom:190px;right:18px;}
.touch-active #modal {padding:max(10px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));z-index:40;}
.touch-active #panel,.touch-active #panel:has(.build-catalog) {width:min(940px,100%);max-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);padding:22px 18px;overflow:auto;overscroll-behavior:contain;touch-action:pan-y;}
.touch-active #panel button,.touch-active #equipment-wheel button {min-height:44px;touch-action:manipulation;}
.touch-active #close-panel {width:48px;height:48px;position:sticky;float:right;top:0;z-index:2;background:#213633;}
.touch-active #panel input,.touch-active #panel select {font-size:16px;min-height:44px;touch-action:manipulation;}
.touch-active #panel input[type=range] {touch-action:pan-x;}
.touch-active .cards,.touch-active .build-catalog .cards {grid-template-columns:repeat(2,minmax(0,1fr));}
.touch-active .card {min-width:0;padding:12px;}
.touch-active .build-catalog {min-width:0;}
.touch-active .build-menu-switch,.touch-active .tabs,.touch-active .pack-nav {flex-wrap:wrap;}
.touch-active #equipment-wheel {z-index:45;position:fixed;inset:16px max(16px,env(safe-area-inset-right)) 16px max(16px,env(safe-area-inset-left));width:auto;height:auto;max-width:640px;margin:auto;transform:none!important;border-radius:18px;background:#142827f5;overflow:auto;touch-action:pan-y;padding:20px;box-sizing:border-box;}
.touch-active #equipment-wheel.open {display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;align-content:start;}
.touch-active .wheel-center,.touch-active .wheel-footer {position:static;inset:auto;transform:none;grid-column:1/-1;}
.touch-active .wheel-item {position:static;transform:none!important;width:auto;height:auto;min-height:100px;padding:12px;display:flex;flex-direction:column;gap:5px;border-radius:10px;}
.touch-active .wheel-footer {display:flex;align-items:center;justify-content:center;gap:16px;}
.touch-active .wheel-center {padding-bottom:10px;}
#gamepad-setup, #touch-more {max-width:640px;width:calc(100vw - 48px);max-height:80dvh;overflow:auto;background:#172c2d;color:#f4edda;border:1px solid #b4c5ae55;border-radius:16px;padding:24px;font:14px system-ui;touch-action:pan-y;}
#gamepad-setup::backdrop, #touch-more::backdrop {background:#000b;}
#gamepad-setup button,#gamepad-setup select,#touch-more button {min-height:44px;padding:8px;border-radius:6px;background:#d8c8a0;color:#172c2d;margin:8px 0;max-width:100%;}
#gamepad-setup h3 {overflow-wrap:anywhere;}
.gamepad-fields {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 18px;}
.gamepad-fields label {display:flex;flex-direction:column;gap:4px;}
.gamepad-readout {grid-column:1/-1;overflow-wrap:anywhere;}
#controller-hint:not([hidden]) {position:fixed;left:50%;top:75px;transform:translateX(-50%);z-index:50;max-width:90vw;padding:14px;background:#172c2df0;border:1px solid #d8c8a0;border-radius:10px;color:#f4edda;cursor:pointer;font:13px system-ui;}
@media(max-width:600px) {
 .touch-active .quiet-header {top:max(12px,env(safe-area-inset-top));}
 .touch-toolbar {top:max(58px,calc(env(safe-area-inset-top) + 48px));left:14px;right:14px;justify-content:flex-end;}
 .touch-active .cards,.touch-active .build-catalog .cards {grid-template-columns:1fr;}
 .touch-active .inventory-grid {grid-template-columns:repeat(3,minmax(0,1fr));}
 .touch-active #equipment-wheel.open {grid-template-columns:repeat(2,minmax(0,1fr));}
 .touch-tip {bottom:188px;left:24px;right:24px;}
 .touch-active #interaction {bottom:226px;}
 .touch-build {bottom:200px;}
 #touch-controls .touch-toolbar button {min-width:46px;}
 .touch-active #toast {top:max(120px,calc(env(safe-area-inset-top) + 110px));}
}
@media(max-height:500px) and (min-width:601px) {
 .touch-movement {bottom:max(12px,env(safe-area-inset-bottom));left:max(18px,env(safe-area-inset-left));}
 .touch-actions {bottom:max(12px,env(safe-area-inset-bottom));}
 #touch-controls .touch-actions button {min-height:46px;}
 #touch-controls .touch-use {min-height:54px;}
 .touch-active #interaction {bottom:22px;max-width:calc(100vw - 420px);}
 .touch-tip {bottom:5px;}
 .touch-active #health-warning {top:100px;bottom:auto;}
 .touch-active #boost-readout {bottom:185px;}
}

#touch-more button {display:block;width:100%;}

#controller-hint:not([hidden]) {display:block!important;pointer-events:auto;bottom:auto;}
.touch-active #equipment-wheel:not(.open) {display:none;}
.touch-active #equipment-wheel {transition:none;}
@media(max-width:600px){.touch-tip{bottom:209px;font-size:9px}.touch-active .quiet-time{display:none}.touch-active #interaction{bottom:244px}}
@media(max-width:360px){
 .touch-toolbar{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:4px;left:12px;right:12px;}
 #touch-controls .touch-toolbar button{min-width:44px;padding:4px;font-size:10px;}
 .touch-movement{left:12px;width:112px;}
 #touch-controls .touch-stick{width:108px;height:108px;min-width:108px;}
 .touch-stick span{left:26px;top:26px;}
 .touch-actions{right:12px;}
}

.touch-active #build-help {top:80px;bottom:auto;left:50%;transform:translateX(-50%);width:min(340px,calc(100vw - 32px));padding:8px 12px;box-sizing:border-box;font-size:12px;}
.touch-active #build-help > p:not(#placement-status) {display:none;}
.touch-active #placement-status {margin:5px 0 0;font-size:12px;}
#touch-controls[data-kind=build] .touch-build {grid-template-columns:repeat(3,64px);bottom:24px;}
#touch-controls[data-kind=build] .touch-tip {display:none;}
.touch-active.in-space #boost-readout {display:none;}
@media(max-width:600px){.touch-active #build-help{top:118px;}#touch-controls[data-kind=build] .touch-build{bottom:190px;}}

/* Keep action targets fixed when nearby prompts appear or disappear. */
.touch-actions [data-slot=sprint]{grid-area:1 / 1;}
.touch-actions [data-slot=duck]{grid-area:1 / 2;}
.touch-actions [data-slot=interact]{grid-area:2 / 1;}
.touch-actions [data-slot=jump]{grid-area:2 / 2;}
.touch-actions .touch-equip{grid-area:3 / 1;}
.touch-actions [data-slot=use]{grid-area:3 / 2;}
#touch-controls[data-kind=build] [data-slot=duck]{grid-area:3 / 1;}
