/* Mobile layout uses actual viewport height and keeps driving information off the horizon. */
@media(max-width:700px),(any-pointer:coarse) and (max-width:1100px),(max-width:1100px) and (max-height:600px){
 html,body{min-height:0;width:100%;overflow-x:hidden}
 body:not(.playing){min-height:100dvh;overflow-y:auto}
 body.playing{height:100dvh;overflow:hidden;overscroll-behavior:none}
 header{padding:0 max(12px,env(safe-area-inset-right)) 0 max(12px,env(safe-area-inset-left));height:58px;gap:6px}
 header .tag,header #volume{display:none}header .brand{font-size:11px;letter-spacing:1px}header button{min-height:44px}
 body:not(.playing) #performancePanel{top:62px;font-size:9px;right:12px;padding:3px 6px}body:not(.playing) #performanceHint{display:none}
 body:not(.playing) #menu{position:relative;left:auto;top:auto;width:calc(100% - 24px);max-width:740px;margin:96px auto 0;padding-bottom:max(24px,env(safe-area-inset-bottom))}
 #menu h1{font-size:clamp(34px,7vw,48px);margin:8px 0 12px}.menuHeading{margin-bottom:16px}.menuHeading .intro{font-size:13px}.raceFacts{display:none}
 .menuGrid{gap:12px}.menuCard{min-width:0;padding:14px}.modeCard{padding:14px}.sectionTitle{margin-bottom:14px}.menuBottom{gap:12px}
 #menu input,#menu select,dialog input,dialog select{font-size:16px!important;min-height:44px;max-width:100%}
 #menu button,dialog button,.customize summary,.menuControls summary{min-height:44px}
 dialog{max-width:calc(100vw - 20px);max-height:calc(100dvh - 20px);overscroll-behavior:contain}
 #graphicsPanel,#statsPanel,#tuningGarage{padding:16px;max-height:calc(100dvh - 20px)}
 #lobby,#result{width:min(420px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;padding:18px}
 .tuneFields{min-width:0}.tuneFields label{min-width:0}.tuneFooter{flex-wrap:wrap}.tuneFooter span{flex-basis:100%}
 #hud{inset: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))}
 #hud .raceDial{display:none}
 #hud .hudbottom{width:132px;height:auto;min-height:68px;right:0;bottom:auto;top:50px;transform:none;background:#08132170;border-radius:12px;padding:8px;display:grid;grid-template-columns:1fr 28px;gap:4px}
 #hud .hudbottom .speedReadout{position:static;width:auto;text-align:center;grid-column:1;padding:0}
 #hud .hudbottom #speed{font-size:40px;letter-spacing:-1px}
 #hud .hudbottom .speedReadout>div{gap:3px}#hud .speedReadout>div small{font-size:9px}
 #hud #speedStatus{font-size:8px;min-height:0;margin:3px 0 0}#hud #speedStatus:not(.overLimit){display:none}
 #hud .hudbottom .rev{position:static;width:auto;align-self:center;grid-column:2}
 #hud .gearReadout{flex-direction:column;gap:2px}#hud .gearReadout b{font-size:23px}#hud .gearReadout small{font-size:6px}
 #hud .hudbottom .nitro{position:static;grid-column:1/-1;width:auto;transform:none;padding:0}
 #hud .nitro>small:first-child{font-size:8px;letter-spacing:1px}#hud .nitro #nitroBar{height:5px;margin-top:3px}
 #hud .nitro #nitroHint{font-size:8px;transform:none;margin-top:3px}
 #hud .hudtop{gap:14px}#hud .hudtop>div{padding-left:7px}#hud .hudtop strong{font-size:28px}#hud .hudtop small{font-size:8px;letter-spacing:.6px}
 #hud .progress{width:110px;margin-top:6px}
 #hud #weatherBadge{top:79px;max-width:135px}#hud #weatherName{font-size:9px}#hud #weatherSurface{font-size:8px}
 #hud #radarWarning,#hud #radarNotice{top:160px;right:0;max-width:155px;width:155px;padding:7px;gap:3px}
 #hud #radarWarning strong{font-size:23px}#hud #radarWarning small,#hud #radarWarning [data-radar-title]{font-size:9px}
 #hud .radarIcon{display:none}#hud .radarNotice strong,#hud .radarNotice b{font-size:12px}#hud .radarNotice span,#hud .radarNotice small{font-size:9px}
 #hud #closure{left:0;top:118px;max-width:45%;width:auto;text-align:left;transform:none;font-size:9px}
 #hud .driving{bottom:156px;left:0;top:auto;max-width:50%;white-space:normal}
 #hud>.raceActions{bottom:164px;left:0;transform:none;gap:5px}#hud>.raceActions button{min-height:44px;min-width:54px;font-size:8px;padding:5px 7px}
 body.playing header{right:max(12px,env(safe-area-inset-right));top:max(5px,env(safe-area-inset-top));height:44px}
 body.playing #performancePanel{display:none}#countdown{font-size:72px;top:35%}#toast{max-width:90vw;font-size:12px}
}
@media(max-width:600px){.menuGrid{grid-template-columns:1fr}.setupFields,.onlineSetup{grid-template-columns:1fr}#menu .join{min-width:0}#menu .join input{min-width:0}.menuLinks{justify-content:flex-start}}
/* Reserve a separate top row for settings on upright phones. Long translated
   mode names may shrink, but the clock always keeps its own column. */
@media(orientation:portrait) and (max-width:700px),(orientation:portrait) and (any-pointer:coarse) and (max-width:1100px){
 #hud{top:calc(max(5px,env(safe-area-inset-top)) + 54px)}
 #hud .hudtop{display:grid;grid-template-columns:minmax(0,1fr) 88px;gap:12px;min-height:72px}
 #hud .hudtop>div{min-width:0}
 #hud .hudtop #mode{display:block;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
 #hud .hudtop>div:has(#sharedChallengeHud:not(.hidden)) #mode{max-width:100%}
 #hud .hudtop .timer{width:88px;white-space:nowrap}
 #hud .hudtop #sharedChallengeHud{max-width:100%;font-size:13px}
 #hud .hudbottom{top:74px}
 #hud #weatherBadge{top:96px}
 #hud #closure{top:140px}
 #hud #radarWarning,#hud #radarNotice{top:190px}
}
@media(orientation:landscape) and (max-height:600px) and (max-width:1100px){
 body:not(.playing) #menu{margin-top:82px}.menuHeading{margin-bottom:12px}#menu h1{font-size:34px}.menuGrid{grid-template-columns:1fr 1fr}
 #hud .hudbottom{top:auto;bottom:0;left:50%;right:auto;transform:translateX(-50%);width:150px;padding:6px 10px;min-height:0}
 #hud .hudbottom #speed{font-size:34px}#hud .nitro #nitroHint{display:none}
 #hud>.raceActions{top:0;bottom:auto;left:50%;transform:translateX(-50%)}
 #hud #weatherBadge{top:69px}#hud #closure{top:55px;left:50%;transform:translateX(-50%);max-width:30%;text-align:center}
 #hud #radarWarning,#hud #radarNotice{top:48px;right:0;width:146px;max-width:146px}
 #hud .driving{bottom:142px;max-width:180px}
 .tunePreview canvas{height:170px}#tuningGarage .tuneLayout{grid-template-columns:1fr 1fr}
}
@media(orientation:landscape) and (max-height:360px) and (max-width:1100px){#hud .driving{bottom:116px}#hud #weatherSurface{display:none}#hud .hudtop strong{font-size:24px}#hud #weatherBadge{top:60px}#hud #radarNotice{max-height:95px;overflow:hidden}}

/* Recovery and leaving are away from the thumb controls, with a dedicated top row. */
#hud>.raceUtilityActions{position:fixed;top:max(14px,env(safe-area-inset-top));left:50%;transform:translateX(-50%);display:flex;gap:6px;pointer-events:auto;z-index:3}
#hud>.raceUtilityActions button{min-height:44px;padding:8px 12px;font-size:11px;letter-spacing:.3px;border-radius:6px;background:#0b1420d9;white-space:nowrap}
@media(orientation:portrait) and (max-width:700px),(orientation:portrait) and (any-pointer:coarse) and (max-width:1100px){
 #hud>.raceUtilityActions{top:calc(max(5px,env(safe-area-inset-top)) + 49px)}
 #hud{top:calc(max(5px,env(safe-area-inset-top)) + 102px)}
}
@media(orientation:landscape) and (max-height:600px) and (max-width:1100px){
 #hud>.raceUtilityActions{top:max(5px,env(safe-area-inset-top))}
 #hud>.raceUtilityActions button{font-size:10px;padding:6px 9px}
 #hud>.raceActions{top:auto;bottom:145px;left:0;transform:none}
}
