/* Touch input and compact layouts share the desktop game's hazard-yellow identity. */
:root{--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px);--safe-left:env(safe-area-inset-left,0px);--safe-right:env(safe-area-inset-right,0px)}
html,body{-webkit-text-size-adjust:100%;overscroll-behavior:none}
#c{width:100%;height:100%;height:100dvh;touch-action:none}
.screen,#hud,#touchControls,#loading{bottom:auto;height:100%;height:100dvh}
button,input,select,summary{touch-action:manipulation}
button:focus-visible,summary:focus-visible,#touchSteer:focus-visible{outline:2px solid var(--hazard);outline-offset:2px}
.screen>.topbar{flex-shrink:0;padding-top:max(14px,var(--safe-top));padding-left:max(20px,var(--safe-left));padding-right:max(20px,var(--safe-right))}
.cards,.form,.medal-body,.set-body{min-height:0;overscroll-behavior:contain}
.form input,.row2 input{max-width:100%}
.helpgrid{overflow:auto;min-height:0}
#menu{justify-content:flex-start;padding-top:max(32px,var(--safe-top));padding-bottom:max(32px,var(--safe-bottom))}
#menu.first-play{justify-content:center}
#menu>*{flex-shrink:0}
.screen.dim{overflow-y:auto;padding:max(16px,var(--safe-top)) max(16px,var(--safe-right)) max(16px,var(--safe-bottom)) max(16px,var(--safe-left))}
.screen.dim>*{flex-shrink:0}
.screen.dim::before,.screen.dim::after{content:"";margin:auto}
.screen.dim{justify-content:flex-start}
.set-box{max-height:100%;min-height:0;flex-shrink:1!important}
#resBody{min-width:0;width:min(560px,100%);flex-shrink:1;max-height:none;overflow:auto}
#results .menu-buttons.row{flex-wrap:wrap;justify-content:center}
#toast{max-width:calc(100% - 32px);width:max-content;bottom:max(28px,var(--safe-bottom))}
.garage-panels{display:contents}
#garagePreview{display:none;pointer-events:none}
#vehicleStats summary{display:none}
#vehicleStats:not([open])>#stats{display:block}
body:not(.touch) .touch-only,body.touch .kb-only,body.touch .pad-only{display:none!important}
body.touch #ctlHint{display:none}
body.touch{--drive-deck:0px}
@media (orientation:portrait){
  body.touch{--drive-deck:calc(164px + var(--safe-bottom))}
  body.touch:has(#hud:not(.hidden)) #c{height:calc(100dvh - var(--drive-deck))}
  body.touch:has(#hud:not(.hidden))::after{content:"";position:fixed;inset:auto 0 0;height:var(--drive-deck);background:var(--bg);border-top:1px solid var(--line);z-index:2;pointer-events:none}
  body.touch #bigmsg{top:calc((100% - var(--drive-deck)) * .3)}
  body.touch #center-flash{top:calc((100% - var(--drive-deck)) * .48)}
}

/* Only the actual driving controls suppress browser gestures; menus still scroll. */
#touchControls{position:fixed;inset:0;z-index:4;pointer-events:none;font-size:14px}
#touchControls button,#touchSteer{pointer-events:auto;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;border:1px solid rgba(255,255,255,.5);background:rgba(16,14,11,.82);border-radius:8px;color:var(--ink)}
#touchControls button{min-width:44px;min-height:44px;padding:8px 10px;font-weight:700}
#touchControls button.held,#touchControls button:active{background:var(--hazard);border-color:var(--hazard);color:#15130f}
.touch-toolbar{position:absolute;top:calc(8px + var(--safe-top));left:calc(10px + var(--safe-left));right:calc(10px + var(--safe-right));display:flex;justify-content:space-between;gap:6px}
#touchMore{position:absolute;top:calc(60px + var(--safe-top));left:50%;transform:translateX(-50%);width:min(320px,90%);display:grid;grid-template-columns:1fr 1fr;gap:6px;padding:10px;background:var(--panel);border:1px solid var(--line);pointer-events:auto;z-index:1}
#touchSteer{--steer:0;position:absolute;bottom:calc(12px + var(--safe-bottom));left:calc(12px + var(--safe-left));width:min(152px,calc(100vw - 190px - var(--safe-left) - var(--safe-right)));height:96px;display:flex;flex-direction:column;align-items:center;justify-content:space-between;padding:6px 8px;font-weight:700;overflow:hidden}
#touchSteer::before{content:"";position:absolute;left:12%;right:12%;top:47%;height:3px;background:var(--line)}
#touchSteer i{display:block;position:relative;width:40px;height:40px;border-radius:50%;background:var(--hazard);transform:translateX(calc(var(--steer) * min(40px,24vw - 58px)))}
#touchSteer small{font-size:12px;letter-spacing:.08em}
.touch-pedals{position:absolute;right:calc(12px + var(--safe-right));bottom:calc(12px + var(--safe-bottom));display:grid;grid-template-columns:repeat(2,76px);grid-template-rows:44px 48px;gap:4px}
#touchControls .touch-pedals button{padding:6px 2px;font-size:12px}
#touchControls .touch-pedals .touch-gas{border:2px solid var(--hazard);font-size:20px}
.touch-pedals small{display:block;font-size:12px;font-weight:400}
body.touch .hud-tl{left:calc(80px + var(--safe-left));right:calc(80px + var(--safe-right));top:calc(10px + var(--safe-top));max-width:none}
body.touch #modeLabel{font-size:16px;line-height:1.1}
body.touch #objective{font-size:12px;line-height:1.35}
body.touch #feed{font-size:11px;margin-top:6px;max-width:230px}
body.touch #minimap{width:64px;height:64px;right:calc(12px + var(--safe-right));top:calc(82px + var(--safe-top))}
body.touch .hud-bl{left:calc(12px + var(--safe-left));bottom:calc(116px + var(--safe-bottom));gap:8px}
body.touch .car-diagram{display:none}
body.touch .bar div{width:136px;height:8px}
body.touch .bar{display:flex;align-items:center;gap:6px}
body.touch .bar label{font-size:11px;width:38px}
body.touch .bar div{width:92px}
body.touch .bars{gap:5px}
body.touch .hud-br{right:calc(12px + var(--safe-right));bottom:calc(116px + var(--safe-bottom));display:flex;align-items:baseline;gap:4px}
body.touch #speed{font-size:32px}
body.touch .hud-br small{font-size:12px}
body.touch #combo{right:calc(12px + var(--safe-right));top:calc(158px + var(--safe-top));width:100px}
body.touch #combo:not(.on){visibility:hidden}
body.touch #comboMult{font-size:24px}
body.touch #comboPts{font-size:18px}
body.touch #comboTotal{font-size:10px}
body.touch #questPanel{right:calc(12px + var(--safe-right));top:calc(232px + var(--safe-top));width:180px;max-height:calc(100% - 242px - max(146px + var(--safe-bottom),var(--drive-deck)) - var(--safe-top));overflow:auto;pointer-events:auto}
body.touch #center-flash{font-size:24px;max-width:90%}
body.touch #popups .pop{font-size:18px;white-space:normal;text-align:center}
body.touch #bigmsg{font-size:clamp(38px,9vw,72px)}
body.touch #spawnClose{margin-top:12px}

@media (pointer:coarse){
  button,.buildrow,summary,.chip{min-height:44px}
  input,select{font-size:16px!important;min-height:44px}
  input[type=range]{min-width:0;max-width:100%;margin-inline:0}
  .sw{width:44px;height:44px}
  .chip{padding:8px}
  .chip input[type=color]{width:28px}
  .screen.dim{backdrop-filter:none}
  .menu-buttons button:hover{transform:none}
}
@media (max-width:1100px), (pointer:coarse){
  .topbar{gap:8px;padding:10px 12px}
  .topbar h2{font-size:clamp(20px,4vw,28px);text-align:center}
  .topbar .cash-pill{font-size:20px;white-space:nowrap}
  #menu{padding:20px max(16px,var(--safe-right)) max(20px,var(--safe-bottom)) max(16px,var(--safe-left));background:var(--bg)}
  #menu .cash-pill{position:absolute;top:max(20px,var(--safe-top));right:max(16px,var(--safe-right));font-size:22px}
  #menu .title{max-width:calc(100% - 90px)}
  #menu .title span{font-size:32px}
  #menu .title b{font-size:44px;text-shadow:3px 3px 0 var(--rust)}
  #menu .subtitle{margin:12px 0;font-size:10px}
  #menu #lvlPill{margin:4px 0 12px;font-size:12px}
  #menu .menu-buttons{width:100%}
  #menu .menu-buttons button{clip-path:none;background:#25221d;line-height:1.25}
  #menu .menu-buttons .primary-action{background:var(--hazard);font-size:24px;min-height:72px}
  #menu .menu-pair button,#more .menu-secondary button{min-height:48px;font-size:16px}
  #menu.first-play .first-play-intro{margin-top:20px}
  #more .save-row button{padding:8px 10px}
  .title span{font-size:clamp(40px,10vw,72px)}
  .title b{font-size:clamp(54px,14vw,96px)}
  .subtitle{font-size:11px;letter-spacing:.2em}
  .cards{grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr));padding:12px}
  .career-list{padding:12px}
  .form{padding:16px}
  .helpgrid{grid-template-columns:1fr;padding:16px;gap:14px;font-size:16px}
  .helpgrid .span2{grid-column:auto}
  .rec-grid{grid-template-columns:minmax(0,1fr)}
  .gp-player{margin:12px;padding:12px}
  .srow{grid-template-columns:100px minmax(0,1fr) 30px;gap:8px}
  div.srow{grid-template-columns:100px minmax(0,1fr)}
  .seg button{padding:8px 10px}
  #garage{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto clamp(120px,26dvh,230px) minmax(0,1fr) auto;grid-template-areas:"header" "preview" "catalog" "actions"}
  #garage .topbar{grid-area:header;flex-wrap:wrap;min-width:0;row-gap:4px;padding-top:max(8px,var(--safe-top))}
  #garage .tabs{order:1;width:100%;flex-wrap:nowrap;overflow-x:auto;min-width:0}
  #garage .tabs button{flex-shrink:0;padding:8px 12px}
  #garagePreview{grid-area:preview;display:block;position:relative}
  .garage-panels{grid-area:catalog;display:block;overflow:auto;min-width:0;min-height:0;background:var(--bg)}
  .gpanel,.statpanel{position:static;display:block;width:100%;padding:12px 16px;overflow:visible;background:none;border:0}
  .statpanel{border-bottom:1px solid var(--line)}
  #garage .statpanel>.buildname,#garage .statpanel>.hint{display:none}
  #garage .statpanel>#previewStatus{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);margin:0}
  #garage .statpanel{padding:0 16px}
  #garage .statpanel,#garage:has(#previewActions:not(.hidden)) .statpanel{max-height:none;overflow:visible}
  #vehicleStats summary{display:list-item;cursor:pointer;color:var(--dim);padding:10px 0}
  #vehicleStats:not([open])>#stats{display:none}
  .statpanel .buildname{margin-bottom:0;font-size:20px}
  .statpanel .hint{margin-top:4px}
  .btn-test{margin-top:8px}
  .garage-actions{grid-area:actions;position:static;width:100%;max-height:40dvh;padding:8px max(12px,var(--safe-right)) max(8px,var(--safe-bottom)) max(12px,var(--safe-left));background:var(--bg)}
  .garage-actions #previewActions{margin:0 0 8px;padding:0 0 8px}
  #previewInfo summary{min-height:44px;padding:8px 0}
  #previewActions .row2{display:grid;grid-template-columns:1fr 1fr}
  #garage .garage-actions .btn-test{min-height:44px}
  #garagePreview::after{content:"Drag to rotate | Pinch to zoom";position:absolute;bottom:6px;left:12px;font-size:11px;color:var(--ink);text-shadow:1px 1px 2px #000;pointer-events:none}
}
@media (max-width:1100px) and (orientation:landscape), (pointer:coarse) and (orientation:landscape){
  #garage{grid-template-columns:minmax(0,1fr) minmax(260px,50%);grid-template-rows:auto minmax(0,1fr) auto;grid-template-areas:"header header" "preview catalog" "preview actions"}
  #garage .tabs{order:0;width:auto;flex:1}
  .garage-actions{max-height:48dvh}
}
@media (orientation:landscape) and (max-height:600px){
  #menu{padding-top:max(16px,var(--safe-top));padding-bottom:max(16px,var(--safe-bottom))}
  #menu .title span{font-size:40px}
  #menu .title b{font-size:54px}
  #menu .subtitle{margin:4px 0}
  body.touch #touchSteer{width:156px}
  .touch-pedals{grid-template-columns:repeat(2,88px)}
  body.touch .hud-tl{left:calc(84px + var(--safe-left));right:calc(84px + var(--safe-right))}
  body.touch .hud-bl,body.touch .hud-br{bottom:calc(116px + var(--safe-bottom))}
  body.touch #minimap{top:calc(62px + var(--safe-top))}
}
@media (max-height:500px){
  #menu.first-play{justify-content:flex-start;padding-top:max(16px,var(--safe-top));padding-bottom:max(16px,var(--safe-bottom))}
  #menu.first-play .title span{font-size:40px}
  #menu.first-play .title b{font-size:54px}
  #menu.first-play .first-play-intro{margin:12px 0 4px}
  body.touch #combo{top:calc(100px + var(--safe-top));right:auto;left:50%;transform:translateX(-50%)}
  body.touch #questPanel{top:calc(178px + var(--safe-top));right:auto;left:50%;transform:translateX(-50%);width:min(180px,calc(100% - 400px - var(--safe-left) - var(--safe-right)));max-height:calc(100% - 198px - var(--safe-top) - var(--safe-bottom))}
  body.touch #feed div:nth-child(n+3){display:none}
  #touchMore{max-height:calc(100% - 74px - var(--safe-top) - var(--safe-bottom));overflow:auto}
}
@media (orientation:landscape) and (max-height:360px){
  #touchSteer{height:96px;padding:6px 8px}
  #touchSteer small{display:none}
  .touch-pedals{grid-template-rows:44px 44px}
  body.touch .hud-bl,body.touch .hud-br{bottom:calc(118px + var(--safe-bottom))}
  body.touch #minimap{width:64px;height:64px}
  body.touch #feed div:nth-child(n+2){display:none}
}
