/* Visible viewport hosting patch. Artwork and the original theme stay in game.html. */
:root{--visible-height:100vh;--visible-width:100vw;--pad:112px;--key:48px;--gas:calc(var(--key)*1.3);--edge-top:max(8px,env(safe-area-inset-top));--edge-bottom:max(46px,env(safe-area-inset-bottom));--edge-left:max(10px,env(safe-area-inset-left));--edge-right:max(10px,env(safe-area-inset-right))}
@supports(height:100dvh){:root{--visible-height:100dvh}}
html{width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
body{position:fixed;left:var(--visible-left,0px);top:var(--visible-top,0px);width:var(--visible-width);height:var(--visible-height);overflow:hidden;overscroll-behavior:none}
/* Explicit descendants cover Safari selection of HUD text and images. */
html,body,body *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
body img,body canvas{-webkit-user-drag:none}
html,body{touch-action:auto}
#scene,#sprites,#hud,#hud *,#touch,#touch *,#introOverlay button{touch-action:none}
body input,body textarea,body select,body [contenteditable]:not([contenteditable="false"]),body [contenteditable]:not([contenteditable="false"]) *{-webkit-user-select:text;user-select:text;-webkit-touch-callout:default;touch-action:auto}
body [contenteditable="false"]{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
#menu{padding:var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);overflow:hidden}
#panel{max-width:100%;max-height:100%;overflow:hidden}
#panel.splash{height:100%;width:100%}
.splash .openingBrand{padding-left:var(--edge-left);padding-right:var(--edge-right);padding-top:var(--edge-top)}
.splash .openingActions{padding-bottom:var(--edge-bottom)}
#panel.pilotScreen{position:relative;height:100%;display:flex;flex-direction:column;padding:0;width:min(850px,100%);gap:4px}
.pilotScreen .menuTitleArt{height:10%;max-height:50px;flex:none;margin:0 auto}
#panel.pilotScreen>p{margin:0;line-height:16px;flex:none}
#pilots{flex:1;min-height:0;grid-template-rows:repeat(2,minmax(0,1fr));margin:0;gap:5px}
.pilot{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:0;padding:3px;border-width:2px!important}
.pilot img,.pilot canvas{height:calc(100% - 30px);min-height:0;max-height:120px;flex:1;object-fit:contain}
.pilot b{font-size:13px;line-height:16px;flex:none}
.pilot small{font-size:10px;line-height:12px;flex:none}
.pilotScreen .raceOptions{margin:0;gap:8px;flex-wrap:nowrap;flex:none}
.pilotScreen .modeButton{min-width:0;width:210px;min-height:44px;padding:6px 10px;gap:2px}
.pilotScreen .modeButton b{font-size:16px}
#backLevel{align-self:center;min-height:36px}
.pilotSecondaryActions{display:flex;justify-content:center;align-items:center;gap:8px;flex:none;margin:0}
.pilotSecondaryActions button{min-height:34px;padding:6px 14px;font-size:11px;white-space:nowrap}
#settingsButton{display:inline-flex;align-items:center;justify-content:center;gap:6px}
#settingsButton span{font-size:16px;line-height:1}
#settingsOverlay{position:absolute;inset:0;z-index:30;display:grid;place-items:center;padding:10px;background:#031020e8}
.settingsCard{width:min(500px,100%);max-height:100%;overflow:hidden;display:flex;flex-direction:column;gap:10px;padding:16px;border:2px solid #d9ad42;border-radius:12px;background:linear-gradient(155deg,#102c47,#071524 72%);box-shadow:0 12px 36px #000b,inset 0 1px #fff2;color:#f5e7b0}
.settingsHeader{display:flex;align-items:center;justify-content:space-between;gap:12px;flex:none}
.settingsHeader h2{margin:0;color:#ffe278;font-size:20px;letter-spacing:.08em;font-style:italic}
#settingsClose{min-width:36px;min-height:32px;padding:2px 10px;font-size:24px;line-height:1}
.settingsToggles{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.settingsToggles button{min-height:38px;padding:7px;font-size:11px}
.settingsVolume{display:grid;grid-template-columns:64px minmax(0,1fr) 42px;align-items:center;gap:9px;font-size:12px;color:#d5e9f5}
.settingsVolume input{width:100%;min-width:0;accent-color:#e7b738}
.settingsVolume output{text-align:right;color:#ffe278;font-variant-numeric:tabular-nums}
.settingsDifficulty>span{display:block;margin-bottom:6px;text-align:center;color:#a4d7ef;font-size:10px;letter-spacing:.12em}
.settingsDifficulty>div{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px}
.settingsDifficulty button{min-height:36px;padding:6px 4px;font-size:11px;border-color:#8aa5b8;background:#102334}
.settingsDifficulty button.active{color:#142333;border-color:#fff0a5;background:linear-gradient(#fff3a0,#dfaa32);box-shadow:0 3px 0 #785018}
.resultsScreen .lapResultsTable.compactLaps tbody{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2px 8px}
.resultsScreen .lapResultsTable.compactLaps tr{display:flex;align-items:center;justify-content:space-between;gap:4px}
.resultsScreen .lapResultsTable.compactLaps td{padding:2px 3px;font-size:clamp(10px,1.45vh,13px)}
#panel.rankScreen{display:flex;flex-direction:column;max-height:100%;padding:10px}
.rankScreen .rankTableWrap{min-height:0;flex:1;overflow:auto;max-height:none;touch-action:pan-y}
#panel.resultsScreen{max-height:100%;width:min(1050px,100%)}
#introOverlay{padding:var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left)}
#touch{--pad:inherit;--key:inherit;--gas:inherit}
#stick{left:var(--edge-left);bottom:var(--edge-bottom)}
#buttons{right:var(--edge-right);bottom:var(--edge-bottom)}
@media(pointer:coarse),(max-width:800px){
 #lapsHUD{bottom:calc(var(--pad) + var(--edge-bottom) + 8px);left:var(--edge-left)}
 #gauge{bottom:calc(var(--key)*2 + var(--edge-bottom) + 12px);right:var(--edge-right);width:126px}
 #top{padding:var(--edge-top) var(--edge-right) 0 var(--edge-left)}
 #pause{right:var(--edge-right)}
 #rearMirror{top:var(--edge-top)}
}
@media(orientation:landscape) and (max-height:500px){
 :root{--pad:100px;--key:44px}
 #panel{padding:8px}
 #panel.pilotScreen{gap:2px}
 .pilotScreen .menuTitleArt{height:24px}
 #panel.pilotScreen>p{line-height:14px;font-size:10px!important}
 .pilot img,.pilot canvas{max-height:none;height:calc(100% - 24px)}
 .pilot b{font-size:11px;line-height:13px}.pilot small{font-size:9px;line-height:11px}
 #pilots{gap:3px;grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:minmax(0,1fr)}
 .pilotScreen .modeButton{min-height:44px;padding:4px 8px}
 .pilotScreen .modeButton b{font-size:14px}
 #panel.pilotScreen #backLevel{padding:4px 10px;min-height:28px}
 .pilotSecondaryActions{font-size:10px;gap:6px}
 .pilotSecondaryActions button{min-height:30px;padding:4px 10px}
 #settingsOverlay{padding:4px}
 .settingsCard{gap:4px;padding:7px 10px}
 .settingsHeader h2{font-size:14px}
 #settingsClose{min-height:24px;min-width:28px;font-size:18px;padding:0 6px}
 .settingsToggles button{min-height:26px;padding:3px;font-size:10px}
 .settingsVolume{grid-template-columns:50px minmax(0,1fr) 34px;gap:5px;font-size:10px;line-height:18px}
 .settingsVolume input{height:18px}
 .settingsDifficulty>span{margin-bottom:2px;font-size:9px}
 .settingsDifficulty button{min-height:26px;padding:2px 4px;font-size:10px}
 .resultsScreen .lapResultsTable.compactLaps td{padding:1px 2px;font-size:9px}
 .menuTitleArt{height:30px;margin:0 auto}
 .difficulties{margin:8px 0;gap:8px}
 .difficulties button{padding:12px 8px;min-height:66px;font-size:16px!important}
 .difficulties small{font-size:10px}
 #panel h1{font-size:26px;margin:4px 0}
 #panel p{margin:4px 0;font-size:11px}
 .rankTabs,.rankButtons{margin:5px 0;gap:5px}
 #aliasForm{margin:5px 0;gap:6px}#aliasInput{padding:8px;font-size:16px}
 #aliasMsg{font-size:11px;min-height:16px}
 #rearMirror{width:136px}
 #lapsHUD{bottom:auto;top:var(--edge-top);left:calc(var(--edge-left) + 92px)}
 #gauge{bottom:auto;top:var(--edge-top);right:calc(var(--edge-right) + 98px);width:112px}
 #pause{top:88px;min-height:36px;padding:6px 10px}
 #top #lapTimes{font-size:9px;min-width:80px}
}
@media(orientation:portrait) and (max-width:600px){
 :root{--pad:100px;--key:44px}
 #panel.pilotScreen{gap:6px}
 .pilotScreen .menuTitleArt{height:42px}
 .pilotScreen .modeButton{width:150px}
 .pilotSecondaryActions{max-width:100%;font-size:11px}
 #gauge{width:126px}
}

/* Keep the additional alias action in the existing visible-viewport layout. */
#aliasGuest{align-self:center;max-width:100%;white-space:normal;flex-shrink:0}
@media(orientation:landscape) and (max-height:500px){
 #aliasGuest{font-size:12px;min-height:36px;padding:6px 12px}
}
