/* Touch-only race layout. Desktop retains its HUD and keyboard controls. */
#touch-controls, #touch-select { display: none; }
body.touch {
  --drive-width: 240px;
  --touch-left: calc(14px + env(safe-area-inset-left, 0px));
  --touch-right: calc(14px + env(safe-area-inset-right, 0px));
  --touch-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  --touch-top: calc(12px + env(safe-area-inset-top, 0px));
  touch-action: none; overscroll-behavior: none;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
.tbtn, .party-touch button {
  box-sizing: border-box; padding: 0; color: #f2f5eb;
  background: #111d25b8; border: 1px solid #dce9ed70; border-radius: 16px;
  font: 650 13px/1.2 system-ui, sans-serif; letter-spacing: .015em;
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tbtn.on, .party-touch button.on { background: #355347e6; border-color: #e6f87b; }
.tbtn:focus-visible { outline: 3px solid #e6f87b; outline-offset: 3px; }
#t-drive-controls {
  position: fixed; right: var(--touch-right); bottom: var(--touch-bottom);
  width: var(--drive-width); display: grid; gap: 10px; z-index: 30;
}
#t-secondary { display: flex; justify-content: flex-end; gap: 8px; }
.tbtn.slide-held, .party-touch button.slide-held {
  flex-direction: column; gap: 3px; border-color: #e6f87b; background: #355347f5;
  box-shadow: 0 0 0 2px #e6f87b38;
}
.tbtn.slide-held::after, .party-touch button.slide-held::after { content: '+ ACCELERATOR'; font: 700 8px/1 system-ui; color: #e6f87b; }
#t-secondary .tbtn { position: static; width: 80px; height: 48px; }
#t-fire { display: none; }
body.touch.battle #t-fire { display: flex; }
body.touch #t-fire { width: 64px; background: #692f2cda; }
#t-gas, .party-touch .drive-pedal {
  position: relative; display: grid; grid-template-columns: 80% 20%; width: 100%;
  height: 68px; min-height: 68px; border-radius: 999px; overflow: hidden; padding: 0;
  background: #172621d9; border: 1px solid #c5d596a8; color: #f2f5eb;
  text-align: left; font: 700 15px/1.2 system-ui, sans-serif;
}
.drive-pedal > span { pointer-events: none; }
.pedal-drive { padding-left: 24px; display: grid; align-content: center; gap: 6px; height: 100%; box-sizing: border-box; }
.pedal-slide { display: flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 500; color: #c5cfbd; }
.pedal-slide svg { width: 24px; height: 12px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.pedal-boost { height: 100%; box-sizing: border-box; border-left: 1px solid #c5d59670; background: #e6f87b24; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #e6f87b; font-size: 8px; text-transform: uppercase; }
.pedal-boost svg { width: 19px; height: 24px; fill: currentColor; }
.pedal-charge { position: absolute; left: 24px; right: 24px; bottom: 5px; height: 3px; border-radius: 3px; background: #b7c4b73d; overflow: hidden; }
.pedal-charge i { display: block; width: var(--boost-charge, 0%); height: 100%; background: #d9f88e; transition: width .1s linear; }
#t-gas.on, .party-touch .drive-pedal.on { background: #3a5147e8; border-color: #e6f87b; }
.drive-pedal.boost-held .pedal-boost { background: #e6f87b; color: #172621; }
.drive-pedal[data-boost="boosting"] .pedal-boost { background: #f9d378; color: #172621; }
.drive-pedal[data-boost="boosting"] .pedal-charge i { background: #f9d378; }
.drive-pedal[data-boost="charging"] .pedal-boost { color: #afc1b4; background: #e6f87b24; }
.drive-pedal[data-boost="disabled"] .pedal-boost { opacity: .35; background: transparent; }
.drive-pedal[data-boost="disabled"] .pedal-slide { visibility: hidden; }
.drive-pedal[data-boost="disabled"] .pedal-charge { display: none; }
#t-pause { position: fixed; right: var(--touch-right); top: var(--touch-top); width: 44px; height: 44px; z-index: 30; border-radius: 14px; }
#t-pause svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 3; }
#t-left, #t-right { display: none; position: fixed; bottom: var(--touch-bottom); height: 68px; width: 60px; z-index: 30; font-size: 30px; }
#t-left { left: var(--touch-left); }
#t-right { left: calc(var(--touch-left) + 68px); }
body.steer-buttons #t-left, body.steer-buttons #t-right { display: flex; }
#t-steer { position: fixed; left: 0; bottom: 0; width: min(44vw, calc(100vw - var(--drive-width) - var(--touch-right) - 12px)); height: 65vh; z-index: 28; touch-action: none; }
#t-steer-hint { position: fixed; left: var(--touch-left); bottom: calc(var(--touch-bottom) + 14px); width: 120px; height: 40px; display: flex; align-items: center; justify-content: space-between; color: #edf4eabd; font: 600 10px system-ui, sans-serif; letter-spacing: .14em; pointer-events: none; text-shadow: 0 1px 4px #142016; z-index: 29; }
#t-steer-hint span { font-size: 24px; }
body.steer-buttons #t-steer, body.steer-buttons #t-steer-hint { display: none; }
#t-steer-ui { position: fixed; width: 0; height: 0; opacity: 0; transition: opacity .18s; pointer-events: none; z-index: 29; }
#t-steer-track { position: absolute; left: -65px; top: -2px; width: 130px; height: 4px; border-radius: 4px; background: #f2f5eb40; }
#t-steer-thumb { position: absolute; left: 0; top: 0; width: 44px; height: 44px; border-radius: 50%; transform: translate(-50%, -50%); background: #d9ed9140; border: 1px solid #e6f87b; }
#t-steer:has(#t-steer-ui[style*="opacity: 1"]) ~ #t-steer-hint { visibility: hidden; }
#rotate { display: none; }
body.touch.game-paused #touch-controls, body.touch.garage #touch-controls { display: none !important; }
body.touch #pause .hint { display: none; }
#pause #btn-steer { display: none; }
body.touch #pause #btn-steer { display: block; }

/* One top band for race essentials. Detail remains in results/settings. */
body.touch.t-play #laps { left: calc(var(--touch-left) + 72px); top: calc(var(--touch-top) + 2px); font-size: 13px; line-height: 1.6; }
body.touch.t-play .hud .sub { font-size: 11px; }
body.touch.t-play .hud-extra { display: none; }
body.touch.t-play #pos { left: var(--touch-left); right: auto; top: var(--touch-top); font-size: 28px; }
body.touch.t-play #pos small { font-size: 12px; }
body.touch.t-play #minimap { left: auto; right: calc(var(--touch-right) + 54px); top: var(--touch-top); bottom: auto; width: 80px; height: 94px; opacity: .78; z-index: 10; }
body.touch.t-play #speed { right: calc(var(--touch-right) + 150px); top: calc(var(--touch-top) + 3px); bottom: auto; font-size: 26px; }
body.touch.t-play #speed small { font-size: 10px; }
body.touch #nitro, body.touch.t-play #weather-status { display: none; }
body.touch #weapon { left: auto; right: var(--touch-right); bottom: calc(var(--touch-bottom) + 136px); transform: none; max-width: var(--drive-width); font: 700 11px system-ui, sans-serif; text-align: right; }
body.touch #scorestrip { top: calc(var(--touch-top) + 55px); left: var(--touch-left); transform: none; gap: 8px; font-size: 10px; }
body.touch #center { font-size: clamp(28px, 5vw, 52px); width: max-content; max-width: 90vw; text-align: center; }
body.touch #msg { font-size: 12px; width: min(420px, 80vw); max-height: 32vh; overflow-y: auto; pointer-events: auto; touch-action: pan-y; }
body.touch.t-play #msg { top: 48%; }
body.touch #wrong { top: 28%; font-size: 14px; max-width: 70vw; }
body.touch #pops { top: 26%; max-width: 80vw; text-align: center; }
body.touch .pop { font-size: 16px; }
body.touch .pop-big { font-size: 22px; }
body.touch #ttdelta { top: 22%; font-size: 18px; }
body.touch-selecting #laps, body.touch-selecting #pos, body.touch-selecting #speed, body.touch-selecting #minimap { display: none; }

#touch-select { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); flex-direction: column; align-items: center; gap: 8px; z-index: 30; max-width: 96vw; }
#touch-select .ts-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
#touch-select button { font: 600 13px system-ui, sans-serif; min-height: 44px; padding: 10px 14px; background: #182b25ee; color: #edf4ea; border: 1px solid #bacba280; border-radius: 12px; }
#touch-select .ts-go { font-weight: 800; padding: 12px 44px; background: #e6f87b; color: #172621; }
#ts-menu { display:none; position:fixed; top:var(--touch-top); left:var(--touch-left); z-index:30;
  align-items:center; min-height:44px; padding:10px 16px; border:1px solid #bacba280; border-radius:12px;
  background:#182b25ee; color:#edf4ea; font:650 13px system-ui,sans-serif; touch-action:manipulation; }
body.touch.touch-selecting:not(.home):not(.garage):not(.rewards):not(.booting):not(.game-paused) #ts-menu:not([hidden]) { display:inline-flex; }
#ts-menu:active { background:#355347; }
#ts-menu:focus-visible { outline:3px solid #e6f87b; outline-offset:3px; }
body.touch.touch-selecting:not(.garage) #garage-shortcut { top:var(--touch-top); right:var(--touch-right); bottom:auto; left:auto; transform:none;
  box-sizing:border-box; max-width:calc((100vw - var(--touch-left) - var(--touch-right) - 12px)/2); min-height:44px; padding:8px 12px; font-size:11px; line-height:1.2; }
body.touch.touch-selecting:not(.garage) #account-shortcut { top:calc(var(--touch-top) + 54px); left:var(--touch-left); bottom:auto;
  max-width:calc(100vw - var(--touch-left) - var(--touch-right)); box-sizing:border-box; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@media (orientation:landscape) {
  body.touch.touch-selecting:not(.garage) #account-shortcut { max-width:calc((100vw - 340px)/2 - var(--touch-left)); }
}
body.touch #menu .panel { touch-action: pan-y; min-width: 0; width: min(440px, 92vw); box-sizing: border-box; padding: 22px 20px; }
body.touch #menu button, body.touch #pause button { min-height: 48px; }
body.touch #menu .card .row button { min-height: 44px; }
body.touch #pause .panel { padding: 24px 30px; touch-action: pan-y; }
body.touch #settings .panel { touch-action: pan-y; max-height: calc(100dvh - 24px); padding: 20px; }
body.touch #menu button:active, body.touch #pause button:active { background: #2d4363; }

/* Free Drive uses the same HUD: map and garage are available in pause. */
body.touch.freeroam #free-toolbar { display: none; }
body.touch.freeroam #free-route { left: var(--touch-left); top: var(--touch-top); bottom: auto; max-width: min(210px, 32vw); padding: 8px 10px; font-size: 12px; }
body.touch.freeroam #free-prompt { left: 50%; top: 32%; bottom: auto; width: auto; max-width: min(300px, 70vw); padding: 8px 12px; font-size: 13px; z-index: 31; }
body.touch.freeroam #free-prompt button { min-height: 44px; margin-top: 6px; padding: 8px 14px; }
body.touch.freeroam #free-credit {
  top: var(--touch-top); right: var(--touch-right); bottom: auto;
  box-sizing: border-box; width: 134px; padding: 4px 6px;
  font-size: 10px; line-height: 12px; text-align: right; border-radius: 4px;
}
body.touch.freeroam #free-credit a { display: block; }
body.touch.freeroam #free-credit span { display: none; }
body.touch.freeroam.t-play #minimap, body.touch.freeroam #t-pause { top: calc(var(--touch-top) + 50px); }
body.touch.freeroam #free-objective {
  left: var(--touch-left); right: auto; top: var(--touch-top); box-sizing: border-box;
  width: min(280px, calc(100vw - var(--touch-left) - var(--touch-right) - 150px)); max-width: none;
  font-size: 13px; padding: 10px 12px;
}
body.touch.game-paused #free-route { visibility: hidden; }

@media (orientation: portrait) {
  body.touch { --drive-width: 220px; }
  #t-secondary .tbtn { width: 76px; }
  body.touch #t-fire { width: 52px; }
  #t-left, #t-right { width: 56px; }
  #t-right { left: calc(var(--touch-left) + 64px); }
  #t-steer-hint { width: 100px; }
  body.touch.t-play #laps { left: var(--touch-left); top: calc(var(--touch-top) + 42px); }
  body.touch.t-play #speed { right: var(--touch-right); top: auto; bottom: calc(var(--touch-bottom) + 166px); }
  body.touch #scorestrip { top: calc(var(--touch-top) + 96px); max-width: 55vw; flex-wrap: wrap; }
  body.touch #wrong { top: 22%; }
  body.touch #ttdelta { top: 20%; }
  body.touch #pops { top: 28%; }
  body.touch #msg { top: 52%; }
  body.touch.freeroam #free-route { max-width: 42vw; }
}
@media (max-width: 374px) and (orientation: portrait) {
  body.touch { --drive-width: 200px; --touch-left: calc(8px + env(safe-area-inset-left, 0px)); --touch-right: calc(8px + env(safe-area-inset-right, 0px)); }
  #t-left, #t-right { width: 44px; }
  #t-right { left: calc(var(--touch-left) + 52px); }
  #t-steer-hint { width: 84px; }
  #t-secondary .tbtn { width: 68px; }
  body.touch #t-fire { width: 48px; }
  .pedal-drive { padding-left: 18px; }
}
@media (max-height: 480px) {
  body.touch #menu .panel { max-height: 92vh; padding: 14px 16px; }
  body.touch #menu h1 { font-size: 24px; }
  body.touch #pause .panel { padding: 18px 24px; }
  body.touch #pause h1 { font-size: 26px; }
}

/* Garage: keep category navigation in reach while the parts list scrolls. */
.g3-checkout-controls { display: contents; }
body.touch #garage3d .gcard { padding: 12px; }
body.touch #garage3d .g3-car-nav { grid-template-columns: 44px minmax(0, 1fr) 44px; }
body.touch #garage3d #g3-name { font-size: 17px; }
body.touch #garage3d #g3-sub { margin-top: 3px; font-size: 10px; }
body.touch #garage3d .g3-car-identity { gap: 11px; padding: 3px 0; }
body.touch #garage3d .g3-class-badge { flex-basis: 57px; height: 65px; padding: 3px; box-shadow: 3px 3px 0 #020912, 4px 4px 0 var(--class-ink); }
body.touch #garage3d #g3-class-letter { font-size: 40px; }
body.touch #garage3d #g3-class-rating { font-size: 12px; margin-top: 1px; padding: 1px 0; }
body.touch #garage3d .g3-class-label { font-size: 8px; margin-bottom: 3px; letter-spacing: .09em; }
body.touch #garage3d #g3-class-range { font-size: 9px; margin-top: 4px; }
body.touch #garage3d #g3-preview { margin: 8px 0 0; font-size: 9px; }
body.touch #garage3d .g3-shop {
  margin: 8px 0; padding: 0; touch-action: pan-y; overscroll-behavior-y: contain;
}
body.touch #garage3d #g3-performance { margin-bottom: 4px; }
body.touch #garage3d #g3-tabs {
  margin-top: 8px;
  display: flex; gap: 6px; padding: 6px 0 8px; min-height: 59px;
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
  touch-action: pan-x; scroll-padding-inline: 4px;
  background: #0c1522; border-bottom: 1px solid #405673;
  scrollbar-width: thin; scrollbar-color: #637d93 transparent;
}
body.touch #garage3d #g3-tabs button {
  flex: 0 0 auto; min-height: 44px; padding: 10px 14px; white-space: nowrap;
  font-size: 12px; border-radius: 10px; background: #172738;
}
body.touch #garage3d #g3-tabs button[aria-selected="true"] { background: #203b4a; border-color: #72cdd5; color: #a6f4f7; }
body.touch #garage3d #g3-options { margin-top: 10px; }
body.touch #garage3d #g3-wheel-filters { gap: 5px; }
body.touch #garage3d #g3-wheel-filters button { min-height: 40px; }
body.touch #garage3d .g3-checkout-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; flex: 0 0 auto; border-top: 1px solid #30465e; padding-top: 8px; }
body.touch #garage3d #g3-buy { grid-column: 1 / -1; }
body.touch #garage3d #g3-buy[data-equipped="true"] { display: none; }
body.touch #garage3d .g3-checkout-controls:has(#g3-buy[data-equipped="true"]) #g3-buy-all { grid-column: 1 / -1; }
body.touch #garage3d .g3-checkout-controls:has(#g3-buy-all-group:not([hidden])) #g3-buy { grid-column: auto; }
body.touch #garage3d #g3-buy-all-group:not([hidden]) { display: contents; }
body.touch #garage3d #g3-buy, body.touch #garage3d #g3-buy-all { min-height: 44px; margin: 0; padding: 8px; font-size: 11px; line-height: 1.3; }
body.touch #garage3d #g3-buy-all-note { grid-column: 1 / -1; margin: 0; font-size: 9px; line-height: 1.3; }
body.touch #garage3d #g3-status { grid-column: 1 / -1; margin: 0; min-height: 0; max-height: 32px; overflow-y: auto; touch-action: pan-y; }
body.touch #garage3d .g3-actions { grid-column: 1 / -1; margin: 0; gap: 6px; }
body.touch #garage3d .g3-actions button { min-height: 44px; padding: 8px; }
body.touch #g3-checkout { touch-action: pan-y; }
body.touch.garage #account-shortcut { top: calc(62px + env(safe-area-inset-top, 0px)); bottom: auto; }
@media (orientation: portrait) {
  body.touch #garage3d .g3-header { top: calc(12px + env(safe-area-inset-top, 0px)); left: 14px; right: 14px; }
  body.touch #garage3d .gcard { top: max(210px, 35dvh); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); left: 10px; right: 10px; width: auto; height: auto; }
  body.touch #garage3d #g3-options[data-picker="coat"], body.touch #garage3d #g3-options[data-picker="brakeDisc"], body.touch #garage3d #g3-options[data-picker="wheelStyle"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (orientation: landscape) {
  body.touch #garage3d .g3-header { top: calc(10px + env(safe-area-inset-top, 0px)); left: var(--touch-left); right: var(--touch-right); }
  body.touch #garage3d .g3-header h1 { margin-bottom: 4px; font-size: 18px; }
  body.touch #garage3d #g3-top { font-size: 9px; }
  body.touch #garage3d #g3-wallet { padding: 8px 10px; font-size: 12px; }
  body.touch #garage3d .gcard { top: calc(62px + env(safe-area-inset-top, 0px)); bottom: calc(8px + env(safe-area-inset-bottom, 0px)); left: auto; right: var(--touch-right); width: min(52vw, 370px); height: auto; }
  body.touch #garage3d .g3-car-nav { position: fixed; top: calc(66px + env(safe-area-inset-top, 0px)); left: var(--touch-left); width: calc(100vw - min(52vw, 370px) - var(--touch-left) - var(--touch-right) - 16px); }
  body.touch #garage3d #g3-preview { position: fixed; top: calc(145px + env(safe-area-inset-top, 0px)); left: var(--touch-left); margin: 0; }
  body.touch #garage3d #g3-status { position: fixed; bottom: calc(38px + env(safe-area-inset-bottom, 0px)); top: auto; left: var(--touch-left); width: calc(100vw - min(52vw, 370px) - var(--touch-left) - var(--touch-right) - 16px); }
  body.touch #garage3d .g3-spin { display: none; }
  body.touch.garage #account-shortcut { top: auto; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); left: var(--touch-left); max-width: calc(100vw - min(52vw, 370px) - var(--touch-left) - var(--touch-right) - 16px); font-size: 9px; }
}
@media (orientation: portrait) and (max-height: 620px) {
  body.touch #garage3d .gcard { top: max(180px, 32dvh); }
}
