:root {color-scheme:dark;font-family:Arial,Helvetica,sans-serif;background:#000;color:#fff}
* {box-sizing:border-box}
body {margin:0;overflow:hidden}
[hidden] {display:none!important}
#world,#headlights,#weather,#menu {position:fixed;inset:0;width:100%;height:100%}
#headlights,#weather {pointer-events:none}
#layout {position:fixed;inset:0;width:100%;height:100%;object-fit:cover;object-position:center;pointer-events:none;user-select:none}
#menu {display:flex;flex-direction:column;align-items:center;justify-content:center;background:#000;text-align:center}
#enable-sound {display:inline-grid;place-items:center;width:44px;height:44px;flex:none;color:inherit}
h1 {margin:0;font:italic 1000 clamp(48px,10vw,150px)/1 Arial,sans-serif;letter-spacing:-.075em;text-transform:uppercase}
h1 img {display:block;width:min(78vw,980px);height:auto;max-height:21vh;object-fit:contain}
#title {position:relative;overflow:hidden}
#title.sweeping::after {content:"";position:absolute;left:0;top:0;width:32%;height:100%;background:#000;clip-path:polygon(22% 0,100% 0,78% 100%,0 100%);pointer-events:none;animation:titleDrive .78s cubic-bezier(.333333,.133333,.666667,.466667) var(--drive-delay,0ms) both}
@keyframes titleDrive {from {transform:translateX(-105%)} to {transform:translateX(320%)}}
#loader {width:min(340px,72vw);margin-top:42px}
label {display:flex;justify-content:space-between;font:600 12px/1.25 Consolas,monospace;letter-spacing:.12em;text-transform:uppercase}
progress {width:100%;height:5px;margin-top:10px;border:0;appearance:none;background:#383838}
progress::-webkit-progress-bar {background:#383838}
progress::-webkit-progress-value {background:white}
progress::-moz-progress-bar {background:white}
#garage {margin-top:clamp(12px,3vh,32px)}
#best-score {display:flex;align-items:flex-end;justify-content:center;gap:.42em;margin-bottom:clamp(4px,1.2vh,12px);font-size:clamp(15px,2.7vh,26px)}
#best-score img {display:block;width:auto;height:1em}
.picker,.controls {display:flex;align-items:center;justify-content:center;gap:8px}
.preview {width:min(clamp(280px,62vw,720px),calc(100vw - 112px));height:clamp(136px,44vh,380px);display:grid;place-items:center}
#portrait {display:block}
#startVehicle {--role-height:clamp(13px,2vh,19px);display:grid;place-items:center;row-gap:calc(var(--role-height) + clamp(4px,1vh,8px))}
#vehicle-role {display:inline-flex;align-items:center;gap:.45em;font:600 var(--role-height)/1 Arial,sans-serif;height:1em}
#vehicle-role > span {height:100%}
#vehicle-role img {display:block;width:auto;height:100%}
button {color:white;background:transparent;border:0;padding:0;cursor:pointer;touch-action:manipulation;font:inherit}
button:focus-visible {outline:2px solid white;outline-offset:3px}
.picker > button,.controls button {width:clamp(40px,5vw,62px);height:44px;font:700 36px/1 Arial,sans-serif}
button img {display:block;width:100%;height:100%;object-fit:contain}
#go {min-width:112px;height:46px;margin-top:10px;transform:translateY(clamp(10px,2.2vh,20px));font:italic 900 26px/1 Arial,sans-serif;text-transform:uppercase}
#signal {position:fixed;inset:0;display:grid;place-items:center;font:italic 1000 clamp(52px,12vw,158px)/1 Arial,sans-serif;color:white;pointer-events:none}
#signal img {display:block;width:auto;height:min(24vh,190px);max-width:82vw;object-fit:contain}
#wanted-target {position:fixed;left:50%;top:calc(50% + min(12vh,95px) + 4px);transform:translateX(-50%);max-width:min(32vw,200px);max-height:min(14vh,104px);pointer-events:none}
#hud {position:fixed;left:max(5vw,env(safe-area-inset-left));right:max(5vw,env(safe-area-inset-right));bottom:max(5vh,env(safe-area-inset-bottom));display:flex;align-items:center;gap:clamp(22px,4vw,76px);pointer-events:none}
#hud strong {font:900 clamp(22px,3vw,44px)/1 Consolas,monospace;white-space:nowrap;font-variant-numeric:tabular-nums}
.instrument,#stars {display:inline-flex;align-items:flex-end;gap:clamp(2px,.25vw,4px)}
.instrument img,#stars img {display:block;height:clamp(20px,2.7vw,39px);width:auto}
.instrument span {width:.14em;height:.14em;background:white}
.instrument .colon {height:.45em;align-self:center;background:linear-gradient(white 0 .14em,transparent .14em calc(100% - .14em),white calc(100% - .14em))}
#stars img {filter:brightness(0)}
#stars img.earned {filter:none}
#hud {flex-wrap:wrap;row-gap:0}
#hud.phone .driving-arrows {display:none}
.run-actions {display:flex;align-items:center;gap:8px}
.controls .run-actions button {min-width:50px;width:auto;height:44px;padding:4px;font:italic 900 clamp(14px,1.5vw,20px)/1 Arial,sans-serif}
.run-actions button img {width:clamp(42px,5vw,70px);height:24px}
.run-actions button:disabled {opacity:.45}
.controls {margin-left:auto;pointer-events:none;column-gap:clamp(12px,2vw,28px)}
.control-pair {display:flex;align-items:center;gap:clamp(4px,.8vw,12px)}
.controls button {pointer-events:auto}
#up img {transform:rotate(-90deg)}
#down img {transform:rotate(90deg)}

#world,.picker,.picker button,.controls button {touch-action:none}
.picker img {pointer-events:none}
.picker,.picker button {-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
#world,#menu,#hud,#signal {
  -webkit-user-select:none;
  user-select:none;
  -webkit-touch-callout:none;
}
#menu img,#hud img,#signal img { -webkit-user-drag:none }

@media (any-pointer:coarse), (max-width:620px), (max-height:440px) {
  #world,#headlights,#weather,#layout,#menu,#signal {height:100dvh}
  #menu {
    padding:max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right))
      max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
  }
  #garage {width:min(100%,860px)}
  .picker {
    --nav-size:clamp(48px,6vw,62px);
    display:grid;
    grid-template-columns:var(--nav-size) minmax(0,1fr) var(--nav-size);
    gap:clamp(4px,1vw,12px);
    max-width:calc(720px + var(--nav-size) * 2 + 24px);
    margin-inline:auto;
  }
  .preview {width:100%;min-width:0}
  #startVehicle {display:grid;place-items:center;min-width:48px;min-height:48px;max-width:100%;touch-action:none}
  .picker > button,.controls button {width:clamp(48px,6vw,62px);height:48px;padding:3px}
  #go {height:48px;margin-top:clamp(10px,2vh,20px);transform:none}
  #hud {
    left:max(clamp(10px,3vw,50px),env(safe-area-inset-left));
    right:max(clamp(10px,3vw,50px),env(safe-area-inset-right));
    bottom:max(clamp(8px,2.8vh,30px),env(safe-area-inset-bottom));
    gap:clamp(8px,2.8vw,40px);
  }
  #hud strong {font-size:clamp(18px,3vw,42px)}
  #hud .instrument,#hud #stars {gap:clamp(1px,.24vw,4px)}
  #hud .instrument img,#hud #stars img {height:clamp(16px,2.7vw,39px)}
  .controls {gap:clamp(12px,2vw,24px)}
}

@media (max-width:600px) {
  #hud:not(.phone) {
    align-items:end;
    justify-content:space-between;
    gap:4px 3px;
  }
  #hud:not(.phone) .controls {
    flex:0 0 100%;
    display:flex;
    flex-wrap:wrap;
    justify-content:space-between;
    width:100%;
    margin:0;
  }
}

#hud.phone {
  --digit-height:clamp(15px,4.4vw,25px);
  flex-wrap:nowrap;
  justify-content:space-between;
  align-items:center;
  gap:clamp(3px,1.1vw,12px);
  left:max(2.5vw,env(safe-area-inset-left));
  right:max(2.5vw,env(safe-area-inset-right));
}
#hud.phone .instrument,#hud.phone #stars {min-width:0;gap:clamp(1px,.25vw,2px)}
#hud.phone .instrument img,#hud.phone #stars img {
  height:var(--digit-height);
  min-width:0;
  object-fit:contain;
}
/* Keep the space for each 88 × 157 glyph while Safari decodes a new digit. */
#hud.phone strong.instrument img {width:calc(var(--digit-height) * 88 / 157)}
#hud.phone .controls {flex:none;margin:0}
#hud.phone .run-actions {gap:clamp(2px,.8vw,8px)}
#hud.phone .run-actions button {
  display:grid;
  place-items:center;
  -webkit-tap-highlight-color:transparent;
  min-width:44px;
  height:44px;
  padding:0 2px;
  font-size:clamp(12px,3.2vw,18px);
  width:3.1em;
}
/* Reserve the width of RESUME so pausing doesn't shift the instruments or buttons. */
#hud.phone #pause-run {width:4.9em}
#hud.phone .run-actions img {width:100%;height:1em}

@media (max-height:480px) {
  #title img {width:auto;height:clamp(24px,13svh,60px);max-width:60vw}
  #garage {margin-top:4px}
  #best-score {font-size:clamp(13px,4svh,18px);margin-bottom:3px}
  #best-score .instrument img {height:1em}
  .preview {height:clamp(64px,35svh,168px)}
  #go {height:44px;margin-top:5px;transform:none}
}

