/* Compact phone layouts. Keep 44px action targets rather than scaling the page. */
@media(max-width:600px),(max-height:500px) and (pointer:coarse){
 body{--phone-edge:max(6px,env(safe-area-inset-left));--phone-right:max(6px,env(safe-area-inset-right))}
 .touch-enabled .touch-controls{--touch-stick-size:124px;--touch-arrow-reach:43px;--touch-edge:10px;--touch-floor:102px}
 .touch-enabled .touch-stick-group{gap:4px}
 .touch-enabled .touch-fire-modes{width:140px;gap:3px}
 .touch-enabled .touch-fire-modes button{min-height:44px;font-size:10px;padding:4px 1px 8px}
 .touch-enabled .touch-zoom{width:124px;gap:3px}
 .touch-enabled .touch-zoom button{height:44px;min-height:44px}
 .touch-enabled .touch-drive-hint{display:none}
 .touch-enabled .touch-actions{bottom:calc(6px + env(safe-area-inset-bottom));width:calc(100% - 20px - env(safe-area-inset-left) - env(safe-area-inset-right));min-width:0;max-width:420px;gap:4px;grid-template-columns:repeat(4,minmax(44px,1fr))}
 .touch-enabled .touch-actions button{min-height:44px;padding:4px 2px;gap:0}
 .touch-enabled .touch-actions b{font-size:10px}
 .touch-enabled .touch-actions small{display:none}
 .touch-enabled .touch-stick-caption{top:8px;font-size:9px}
 .touch-enabled .touch-range-hint{font-size:6px;bottom:8px}
 .touch-enabled .game-header{top:max(5px,env(safe-area-inset-top));left:var(--phone-edge);right:var(--phone-right);gap:4px;display:block}
 .touch-enabled .game-header h2{font-size:16px;max-width:calc(100vw - 140px);margin:2px 0 4px}
 .touch-enabled .game-header .eyebrow{font-size:7px}
 .touch-enabled .header-controls,.touch-enabled.feedback-owner .header-controls{margin:0;gap:4px}
 .touch-enabled .hud-button{font-size:10px;padding:5px 9px;min-height:44px}
 .touch-enabled .feedback-button{top:max(6px,env(safe-area-inset-top));right:var(--phone-right);font-size:10px;padding:6px 9px;min-height:44px;max-width:132px}
 .touch-enabled .dashboard{top:94px;bottom:auto;left:var(--phone-edge);transform:none;width:calc(100% - 12px - env(safe-area-inset-left) - env(safe-area-inset-right));padding:5px 8px;gap:8px}
 .touch-enabled .gauges{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));min-width:0;gap:8px}
 .touch-enabled .gauge>div{font-size:8px}.touch-enabled .gauge meter{height:4px}
 .touch-enabled .salvage-readout strong{font-size:18px}.touch-enabled .salvage-readout{min-width:45px;padding-left:6px}
 .touch-enabled .salvage-readout .small,.touch-enabled .controls-compact,.touch-enabled .drive-readout{display:none}
 .touch-enabled .objective-card{top:143px;left:var(--phone-edge);width:145px;padding:6px 8px;max-height:82px;overflow:auto;pointer-events:auto}
 .touch-enabled .objective-card .eyebrow,.touch-enabled .objective-card .small{display:none}
 .touch-enabled .objective-line{font-size:10px;line-height:1.25;margin:3px 0}
 .touch-enabled .map-card{top:143px;right:var(--phone-right);width:86px;bottom:auto;left:auto}
 .touch-enabled .map-heading{font-size:9px;padding:7px;min-height:44px}
 .touch-enabled .map-card:not(.expanded) #minimap,.touch-enabled .map-card:not(.expanded) .map-legend{display:none}
 .touch-enabled .map-card.expanded{top:143px;width:min(290px,calc(100vw - 12px));max-height:calc(100dvh - 410px);overflow:auto}
 .touch-enabled .map-card.expanded #hud~#minimap{max-height:180px}
 .touch-enabled .trap-notice,.touch-enabled .quest-notice{display:none}
 .touch-enabled .boss-notice{top:231px;bottom:auto;width:210px;padding:5px 8px}
 .touch-enabled .boss-notice strong{font-size:15px}.touch-enabled .boss-notice span{font-size:10px;margin:3px 0}.touch-enabled .boss-notice small{display:none}
 .touch-enabled .interact-prompt,.touch-enabled .thermal-warning{bottom:calc(282px + env(safe-area-inset-bottom));top:auto;font-size:10px;max-width:75vw;padding:5px 8px}
 .touch-enabled #toasts{top:145px;width:80vw;font-size:12px}
 .touch-enabled .modal-backdrop{padding:max(6px,env(safe-area-inset-top)) var(--phone-right) max(6px,env(safe-area-inset-bottom)) var(--phone-edge)}
 .touch-enabled .modal{padding:14px;max-height:calc(100dvh - 12px);border-radius:6px}
 .touch-enabled .modal-header h2{font-size:25px}.touch-enabled .modal-header p{font-size:12px}
 .touch-enabled .branch-grid,.touch-enabled .boss-brief{grid-template-columns:1fr}
 .touch-enabled .home{padding:0 18px;overflow:auto;height:100dvh}
 .touch-enabled .home-header{padding:14px 110px 10px 0;min-height:60px}.touch-enabled .home-header .fine,.touch-enabled .edition{display:none}
 .touch-enabled .home-main{display:flex;flex-direction:column;padding:10px 0;gap:10px}
 .touch-enabled .hero-copy h1{font-size:44px;line-height:1.05;margin:12px 0}.touch-enabled .hero-copy>p{font-size:12px}
 .touch-enabled .home-actions{margin-top:15px;gap:7px;flex-wrap:wrap}.touch-enabled .home-actions button{padding:10px 12px;font-size:12px}
 .touch-enabled .machine-exhibit{max-width:210px}.touch-enabled .home-footer{gap:10px;padding:10px 0}.touch-enabled .boss-request{padding:8px 12px;flex-basis:220px}.touch-enabled .boss-request strong{font-size:17px}
 /* Full-screen single-player workshop: small catalogue, spacious canvas. */
 #modal.workshop-screen .workshop-header{min-height:58px;padding:5px var(--phone-right) 5px var(--phone-edge);gap:5px;grid-template-columns:1fr auto}
 #modal.workshop-screen .workshop-header>div:first-child{display:none}
 #modal.workshop-screen #workshop-scrap{min-width:0;padding:4px 8px;gap:0 7px}
 #modal.workshop-screen #workshop-scrap-value{font-size:22px}
 #modal.workshop-screen #finish-build{min-height:44px;padding:6px 9px;font-size:11px}
 #modal.workshop-screen #workshop-body{grid-template-columns:110px minmax(0,1fr)}
 #modal.workshop-screen .workshop-catalogue{padding:0 4px 4px}
 #modal.workshop-screen .catalogue-heading{padding:6px 2px}.catalogue-heading>span:last-child{display:none}
 #modal.workshop-screen .catalogue-filters{gap:4px;padding-bottom:5px}
 #modal.workshop-screen .catalogue-filters input[type=search],#modal.workshop-screen .catalogue-filters select{padding:5px;font-size:16px;min-height:36px;height:36px}
 #modal.workshop-screen .catalogue-filters label{font-size:9px;min-height:26px}
 #modal.workshop-screen .part-button{flex-direction:row;align-items:center;min-height:49px;padding:4px;gap:4px}
 #modal.workshop-screen .part-button canvas{width:26px;height:26px}
 #modal.workshop-screen .part-button span{font-size:10px}.workshop-screen .part-button small{font-size:8px!important;margin-top:2px!important}
 #modal.workshop-screen .build-space{padding:8px}
 #modal.workshop-screen .build-navigation{padding:3px;gap:3px;flex-wrap:wrap}
 #modal.workshop-screen .build-navigation button{min-height:36px;padding:5px 8px}
 #modal.workshop-screen .dock-tabs>button{font-size:9px;min-height:44px;padding:5px;gap:3px}
 #modal.workshop-screen .dock-panel{padding:8px;max-height:34dvh;overflow:auto}
 #modal.workshop-screen .stats-rail:has(#workshop-stats:not([hidden])){position:absolute;right:0;top:0;bottom:0;z-index:9}
 #modal.workshop-screen #workshop-lesson{padding:5px 8px;max-height:60px;overflow:auto}
 #modal.workshop-screen #workshop-lesson strong,#modal.workshop-screen #workshop-lesson span{font-size:10px}
 /* Shared co-op and PvP menus/workshop. */
 #lobby{inset:max(6px,env(safe-area-inset-top)) auto auto 50%;max-height:calc(100dvh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));width:calc(100vw - 16px)}
 .panel{padding:14px;border-radius:8px}.panel h1{font-size:32px;margin:8px 0}.panel p{font-size:12px;line-height:1.4}.panel label{font-size:12px;margin:8px 0}.panel input,.panel select{font-size:16px;padding:7px;min-height:44px}
 .panel button{font-size:12px;padding:8px}.arena-options{padding:10px;margin:10px 0}.arena-preview{max-height:125px;object-fit:contain}
 #hud{padding:max(5px,env(safe-area-inset-top)) var(--phone-right) 5px var(--phone-edge);gap:4px;flex-direction:column}
 #hud strong{font-size:13px}#hud span{font-size:10px;margin-top:2px}#hud .buttons{gap:3px;flex-wrap:nowrap}#hud .buttons button{font-size:10px;padding:5px;min-height:44px;min-width:0;flex:1}
 #network{top:125px;left:var(--phone-edge);font-size:9px;padding:4px;max-width:calc(100% - 110px)}
 #hud~#minimap{top:125px;right:var(--phone-right);width:88px;height:65px}
 #encounter{top:195px;left:var(--phone-edge);width:220px;padding:5px 8px}#encounter strong{font-size:13px}#encounter small{display:none}
 #notice{top:130px;font-size:12px;padding:8px;max-width:85vw}
 #builder{padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom)}
 #builder header{padding:5px var(--phone-right) 5px var(--phone-edge);align-items:center;flex-shrink:0}#builder h2{font-size:13px;margin:0}#build-budget{font-size:17px}#build-warning{display:none}#builder #finish-build{font-size:11px;padding:6px;max-width:110px}
 .build-body aside{width:112px;min-width:112px;max-width:112px;padding:5px}.build-body aside label{font-size:10px;margin:0 0 5px}.build-body input{font-size:16px;padding:5px;min-height:36px}
 #part-list button{font-size:10px;padding:5px;min-height:46px}#part-list button span{font-size:9px;margin-top:2px}
 .grid-scroll{padding:8px;display:block}#build-grid{--coop-cell:24px;width:max-content;grid-template-columns:repeat(15,var(--coop-cell));grid-auto-rows:var(--coop-cell)}
 #build-grid button{width:var(--coop-cell);height:var(--coop-cell)}#build-grid canvas{width:calc(var(--coop-cell) - 2px);height:calc(var(--coop-cell) - 2px)}
 #builder footer{padding:5px;gap:4px;max-height:30dvh;flex-shrink:0}#builder footer button{padding:5px 8px;font-size:10px;min-height:44px}#selected{font-size:10px}#build-message{font-size:10px}
 .floating{max-height:calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom))}
 body.touch-enabled #arena-round{bottom:282px;padding:5px 10px;font-size:10px;max-width:85vw}#arena-round strong{font-size:16px}
 .touch-enabled #service-status{bottom:290px;padding:6px;font-size:11px}
 body.training-course.touch-enabled .touch-controls{--touch-floor:102px;--touch-stick-size:124px;--touch-arrow-reach:43px}
 body.training-course.touch-enabled .touch-actions{bottom:calc(6px + env(safe-area-inset-bottom))}
 body.training-course.touch-enabled .tutorial-card{top:100px;bottom:auto;width:calc(100vw - 16px);padding:6px 10px;max-height:150px;overflow:auto;pointer-events:auto}
 body.training-course.touch-enabled .tutorial-card h3{font-size:17px}body.training-course.touch-enabled .tutorial-card p{font-size:12px;line-height:1.25}
 body.training-course.touch-enabled #skip-tutorial,body.training-course.touch-enabled #tutorial-ack{font-size:11px;padding:5px 10px;min-height:44px}
 body.training-course.touch-enabled #interact-prompt{bottom:284px}
 #tutorial-feedback-pointer{top:55px;font-size:13px;padding:7px;max-width:240px}#tutorial-feedback-pointer small{font-size:11px}
}
@media(max-height:500px) and (orientation:landscape) and (pointer:coarse){
 .touch-enabled .touch-controls,body.training-course.touch-enabled .touch-controls{--touch-stick-size:102px;--touch-arrow-reach:35px;--touch-floor:6px;--touch-edge:20px}
 .touch-enabled .touch-actions{width:260px;bottom:calc(6px + env(safe-area-inset-bottom))}
 .touch-enabled .game-header{display:flex;align-items:start}.touch-enabled .game-header h2{max-width:200px}
 .touch-enabled .header-controls,.touch-enabled.feedback-owner .header-controls{margin-right:132px}
 .touch-enabled .dashboard{top:61px;left:50%;transform:translateX(-50%);width:310px}
 .touch-enabled .objective-card{top:58px;max-height:57px;width:140px}
 .touch-enabled .map-card,.touch-enabled .map-card.expanded{top:60px;max-height:145px}
 .touch-enabled .boss-notice{top:100px;width:220px}
 .touch-enabled .interact-prompt,.touch-enabled .thermal-warning{bottom:104px}
 #hud{flex-direction:row}#hud>div:first-child{max-width:48%}#hud .buttons{align-items:start}#hud .buttons button{max-width:82px}
 #network{top:78px;max-width:180px}#hud~#minimap{top:72px;width:78px;height:58px}#encounter{top:110px;left:50%;transform:translateX(-50%);width:220px}
 body.touch-enabled #arena-round{bottom:104px}.touch-enabled #service-status{bottom:108px}
 body.training-course.touch-enabled .tutorial-card{top:57px;width:calc(100vw - 310px);max-height:145px}
 .touch-enabled #toasts{top:65px;width:50vw}#notice{top:72px}
 .touch-enabled .home-main{flex-direction:row}.touch-enabled .machine-exhibit{max-width:190px}.touch-enabled .hero-copy h1{font-size:34px}
}
/* Panning deliberately disables painting until Draw is selected again. */
#builder.pan-mode #build-grid,#builder.pan-mode #build-grid button{touch-action:pan-x pan-y}
#build-pan[aria-pressed=true]{background:#496a52;border-color:#edce87}

@media(max-width:600px) and (max-height:650px){
 body.training-course.touch-enabled .tutorial-card{max-height:136px}
 body.training-course.touch-enabled .tutorial-card h3{font-size:15px}
}
@media(max-height:500px) and (orientation:landscape) and (pointer:coarse){
 body.training-course.touch-enabled .tutorial-card{max-height:115px}
 body.training-course.touch-enabled .tutorial-card h3{font-size:15px}
}
@media(max-height:500px) and (orientation:landscape) and (pointer:coarse){
 .touch-enabled .game-header{flex-wrap:nowrap;flex-direction:row}
 .touch-enabled .mission-name{flex:1;min-width:0}
 .touch-enabled .game-header h2{font-size:14px;max-width:180px}
 .touch-enabled .header-controls{flex-shrink:0;margin-right:80px}
 .touch-enabled .hud-button{font-size:9px;padding:4px 7px}
}
@media(max-height:350px) and (orientation:landscape) and (pointer:coarse){
 body.training-course.touch-enabled .tutorial-card{max-height:95px}
 .touch-enabled .objective-card{width:110px}
 .touch-enabled .dashboard{width:280px}
}
@media(max-width:600px) and (max-height:650px){
 body.training-course.touch-enabled #interact-prompt{display:none}
}
