/* Phone controls: desktop layout and the flat theme remain unchanged. */
@media(max-width:760px){
 #workspace{height:100dvh}
 #map-controls{top:calc(8px + env(safe-area-inset-top));left:8px;gap:8px}
 #map-controls button{width:44px;height:44px}
 #edit-tools{top:calc(8px + env(safe-area-inset-top));left:60px;right:8px;width:auto;max-width:calc(100% - 68px);overflow-x:auto;scrollbar-width:none;gap:2px;padding:2px}
 #edit-tools button{width:44px;height:44px;flex:0 0 44px;touch-action:manipulation}
 #edit-tools>span{flex-shrink:0}
 #map-tools{left:60px;top:calc(66px + env(safe-area-inset-top))}
 #map-tools>summary{min-height:44px;padding:11px 14px}
 #map-tools .tools-actions{max-height:calc(100dvh - 220px);overflow:auto;max-width:calc(100vw - 76px)}
 #map-tools button{min-height:44px}
 #options{left:8px;right:8px;top:auto;bottom:calc(72px + env(safe-area-inset-bottom));width:auto;max-height:55dvh;padding:6px 10px;gap:10px;scroll-padding-top:50px}
 #options.collapsed{max-height:56px;overflow:hidden}
 #options.collapsed>:not(#mobile-toggle):not(#close-lines-panel){display:none}
 #options #mobile-toggle{position:sticky;top:-6px;background:#111;z-index:2;min-height:44px;font-size:14px;padding:10px 48px 10px 0;flex-shrink:0}
 #options #close-lines-panel{position:absolute;top:6px;right:6px;width:44px;height:44px;z-index:3}
 #line-groups{gap:8px}
 #line-groups .bullet{width:38px;height:38px;font-size:20px}
 #options button:not(.bullet),#options summary{min-height:44px}
 #options .network-pattern{white-space:normal;overflow-wrap:anywhere}
 #route-diagram{max-height:28dvh}
 #simulation-bar,body.panel-collapsed #simulation-bar{left:8px;right:8px;bottom:calc(8px + env(safe-area-inset-bottom));max-width:none;width:auto;height:56px;padding:5px;gap:5px;z-index:40}
 #simulation-bar button{min-width:44px;min-height:44px;flex-shrink:0}
 #simulation-bar #show-trains{margin-left:auto;font-size:12px;max-width:110px;white-space:normal}
 #simulation-bar .sim-info{font-size:10px}#simulation-bar .simulation-divider{display:none}
 #simulation-bar #sim-time{font-size:12px;white-space:nowrap}.sim-clock{gap:4px}
 #station-popup,#train-popup,.following-train #train-popup,#cab-display,#train-popup.user-positioned,#cab-display.user-positioned,body:not(.panel-collapsed) #station-popup{left:8px!important;right:8px!important;top:auto!important;bottom:calc(136px + env(safe-area-inset-bottom))!important;transform:none!important;width:auto!important;max-width:none;max-height:min(50dvh,calc(100dvh - 260px))!important;min-height:0;overflow-y:auto;overscroll-behavior:contain;z-index:35}
 #cab-display .cab-header,#train-drag-handle{touch-action:pan-y}
 .popup .close,#cab-display .cab-header button,#cab-display #cab-close{min-width:44px;min-height:44px}
 .popup button{min-height:44px}
 .popup input:not([type=checkbox]):not([type=range]),.popup select,#options input,#options select,dialog input,dialog select{font-size:16px;min-height:44px}
 #station-popup .station-editor-sign{margin-top:38px}
 #starter{inset:8px!important;transform:none!important;width:auto!important;max-width:none;max-height:none;overflow:auto;padding:20px;background:#111;z-index:60}
 #starter .start-grid{grid-template-columns:1fr}#starter .close{width:44px;height:44px}#starter .start-choice{min-height:48px}
 dialog,#dispatch-dialog,#yard-dialog{max-width:calc(100vw - 16px);max-height:calc(100dvh - 24px);width:calc(100vw - 16px);padding:16px;overflow:auto;overscroll-behavior:contain}
 dialog button{min-height:44px}dialog .close{min-width:44px}
 #map-warning{left:60px;right:8px;top:calc(118px + env(safe-area-inset-top));max-width:none;font-size:12px}
 #toast{left:8px;right:8px;bottom:calc(138px + env(safe-area-inset-bottom));transform:none;max-width:none;font-size:13px;pointer-events:none}
}
@media(max-width:760px) and (max-height:500px){
 #options{max-height:54dvh}#station-popup,#train-popup,.following-train #train-popup,#cab-display,#train-popup.user-positioned,#cab-display.user-positioned,body:not(.panel-collapsed) #station-popup{bottom:calc(72px + env(safe-area-inset-bottom))!important;max-height:calc(100dvh - 140px)!important;left:60px!important}
}

@media(max-width:360px){#simulation-bar .sim-info{font-size:0;gap:3px}#simulation-bar .sim-info b{font-size:11px}#simulation-bar #show-trains{max-width:80px}#simulation-bar .sim-clock{gap:2px}#simulation-bar .sim-day{padding:2px;font-size:9px}}
@media(max-width:760px){
 #simulation-bar #show-trains{width:44px;max-width:44px;font-size:0;padding:0}
 #simulation-bar #show-trains::after{content:'☰';font-size:20px}
 #cab-display .cab-header{height:auto;min-height:48px}
}
