/* Fumes: road-sign and rally-roadbook look.
   Condensed highway-sign type, signal yellow on deep ink, boards with a ruled border. */

:root {
  --ink: #14232b;
  --ink-soft: #2a3d47;
  --paper: #eef1ea;
  --paper-dim: #dde2d8;
  --sign: #ffc21a;
  --sign-deep: #e0a100;
  --red: #e5432e;
  --green: #1f9d6b;
  --muted: #5d6e76;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--body); color: var(--ink); -webkit-user-select: none; user-select: none; touch-action: none; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ------------------------------------------------------------------ buttons */

.btn {
  font: 700 1.35rem/1 var(--display); letter-spacing: 0.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  padding: 0.72em 1.1em; min-height: 52px;
  color: var(--ink); background: var(--paper);
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer; transition: transform 60ms, box-shadow 60ms;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible, .icon-btn:focus-visible, .car-tab:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn.primary { background: var(--sign); font-size: 1.7rem; min-height: 64px; }
.btn.small { font-size: 1.1rem; min-height: 42px; padding: 0.5em 0.8em; border-width: 2px; box-shadow: 0 3px 0 var(--ink); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn .sub { font: 500 0.95rem var(--body); opacity: 0.75; }
.btn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px var(--paper); }
.with-dot { display: inline-flex; align-items: center; gap: 0.5em; }
.btn kbd { font: 600 0.8rem var(--body); padding: 2px 6px; border: 1.5px solid currentColor; border-radius: 5px; opacity: 0.6; }

.icon-btn {
  width: 46px; height: 46px; padding: 0; display: grid; place-items: center;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: 12px; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink); pointer-events: auto;
}
.icon-btn svg { width: 22px; height: 22px; fill: var(--ink); }
.icon-btn.off { background: var(--paper-dim); }
.icon-btn.off svg { opacity: 0.35; }

/* ------------------------------------------------------------------ HUD */

#hud { position: absolute; inset: 0; pointer-events: none; padding: calc(12px + var(--safe-t)) 14px 14px; }

.odo { position: absolute; left: 14px; top: calc(12px + var(--safe-t)); color: var(--paper); }
.odo-num {
  display: inline-flex; align-items: baseline; gap: 6px;
  font: 800 clamp(2.6rem, 7vw, 4.2rem)/0.9 var(--display); font-variant-numeric: tabular-nums;
  background: var(--ink); padding: 8px 14px 6px; border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(238, 241, 234, 0.9);
}
.odo-num small { font-size: 0.42em; font-weight: 600; opacity: 0.7; }
.chase { margin-top: 10px; display: flex; align-items: center; gap: 8px; font: 600 1.05rem var(--display); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.chase-bar { width: 132px; height: 8px; border-radius: 4px; background: rgba(20, 35, 43, 0.55); position: relative; box-shadow: 0 0 0 1.5px rgba(238, 241, 234, 0.75); }
.chase-bar::after { content: ""; position: absolute; right: -2px; top: -9px; border-left: 3px solid var(--paper); height: 20px; }
.chase-bar::before { content: ""; position: absolute; right: -13px; top: -9px; border: 5px solid transparent; border-left: 9px solid var(--red); }
.chase-bar i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--sign); }
.chase.beaten .chase-bar i { background: var(--red); }
.chase.beaten #chaseText { color: var(--sign); }

.hud-right { position: absolute; right: 14px; top: calc(12px + var(--safe-t)); display: flex; align-items: center; gap: 8px; }
.pill {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px;
  background: var(--ink); color: var(--paper); border-radius: 12px;
  font: 700 1.5rem var(--display); font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px rgba(238, 241, 234, 0.9);
}
.coin { width: 20px; height: 20px; border-radius: 50%; background: var(--sign); box-shadow: inset 0 0 0 3px var(--sign-deep); flex: none; }
.fuel svg { width: 16px; height: 20px; color: var(--red); flex: none; }
.fuel-bar { width: clamp(70px, 14vw, 150px); height: 14px; border-radius: 7px; background: rgba(238, 241, 234, 0.18); overflow: hidden; }
.fuel-bar i { display: block; height: 100%; width: 100%; background: var(--green); border-radius: 7px; transition: background 200ms; }
.fuel.low .fuel-bar i { background: var(--sign); }
.fuel.crit .fuel-bar i { background: var(--red); }
.fuel.crit { animation: pulse 0.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px var(--red); } }

#banner {
  position: absolute; left: 50%; top: calc(74px + var(--safe-t)); transform: translateX(-50%);
  font: 700 clamp(1.5rem, 4.4vw, 2.3rem) var(--display); color: var(--ink);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 10px; padding: 6px 18px;
  box-shadow: 0 0 0 3px var(--paper); opacity: 0; white-space: nowrap;
}
#banner.show { animation: banner 2.8s both; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -14px); } 10%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }

#stunts { position: absolute; left: 50%; top: 26%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stunt {
  font: 800 clamp(1.5rem, 4.6vw, 2.5rem) var(--display); color: #fff; white-space: nowrap;
  -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill;
  animation: stunt 1.5s both;
}
.stunt b { color: var(--sign); margin-left: 0.35em; }
.stunt.big { font-size: clamp(2rem, 6.5vw, 3.6rem); color: var(--sign); }
.stunt.record { font-size: clamp(2.2rem, 7.5vw, 4.2rem); color: var(--red); -webkit-text-stroke-color: #fff; }
@keyframes stunt { 0% { opacity: 0; transform: scale(0.5); } 14% { opacity: 1; transform: scale(1.12); } 24% { transform: scale(1); } 78% { opacity: 1; } 100% { opacity: 0; transform: translateY(-18px); } }

#hint {
  position: absolute; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  max-width: min(92vw, 620px); text-align: center;
  font: 500 1.02rem/1.35 var(--body); color: var(--paper); background: rgba(20, 35, 43, 0.82);
  padding: 10px 16px; border-radius: 12px; opacity: 0; transition: opacity 400ms;
}
#hint.show { opacity: 1; }
#hint b { color: var(--sign); font-weight: 600; }

/* Pedals are always on screen, so it is plain what is being pressed. They are
   drawn tilted away like real pedals and hinge down under your foot. */
.pedal {
  position: absolute; bottom: calc(12px + var(--safe-b)); width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font: 700 1.05rem var(--display); color: var(--paper); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.pedal.brake { left: 16px; }
.pedal.gas { right: 16px; }
.pedal .pad {
  width: 100%; height: 96px; border: 3px solid var(--ink); border-radius: 12px 12px 16px 16px;
  background: repeating-linear-gradient(0deg, rgba(20, 35, 43, 0.22) 0 4px, transparent 4px 13px), var(--paper);
  box-shadow: 0 7px 0 var(--ink), 0 12px 14px rgba(0, 0, 0, 0.35);
  transform: perspective(240px) rotateX(26deg); transform-origin: 50% 100%;
  transition: transform 70ms ease-out, box-shadow 70ms ease-out, filter 70ms;
  opacity: 0.88;
}
.pedal.gas .pad { width: 62%; height: 108px; background: repeating-linear-gradient(0deg, rgba(20, 35, 43, 0.22) 0 4px, transparent 4px 13px), var(--sign); }
.pedal.down .pad {
  transform: perspective(240px) rotateX(52deg) translateY(5px);
  box-shadow: 0 2px 0 var(--ink), 0 4px 6px rgba(0, 0, 0, 0.35), 0 0 0 4px rgba(255, 255, 255, 0.55);
  filter: brightness(1.12); opacity: 1;
}
.pedal.down { color: var(--sign); }
.pedal kbd { font: 600 0.72rem var(--body); padding: 1px 5px; border: 1.5px solid currentColor; border-radius: 5px; opacity: 0.75; margin-left: 2px; }
.touch .pedal { width: clamp(92px, 24vw, 132px); }
.touch .pedal .pad { height: clamp(92px, 20vw, 124px); }
.touch .pedal.gas .pad { height: clamp(104px, 23vw, 138px); }
.touch .pedal kbd { display: none; }
.touch #hint { bottom: calc(190px + var(--safe-b)); }

/* ------------------------------------------------------------------ screens */

.screen { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.board {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 0 0 0 5px var(--paper), 0 18px 50px rgba(0, 0, 0, 0.45);
}
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 0.95; }
p { margin: 0; }

/* menu: board on the left, the demo drive stays visible beside it */
.screen-menu { display: flex; align-items: center; padding: 26px; background: linear-gradient(90deg, rgba(20, 35, 43, 0.72) 0, rgba(20, 35, 43, 0.35) 46%, rgba(20, 35, 43, 0) 78%); }
.menu-board { width: min(430px, 100%); padding: 26px 26px 22px; }
.title { font-size: clamp(3.6rem, 13vw, 5.4rem); font-weight: 800; letter-spacing: -0.015em; }
.ridge { display: block; width: 100%; height: 30px; margin: 2px 0 10px; }
.ridge path { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.ridge circle { fill: var(--red); }
.lede { font-size: 1.08rem; line-height: 1.4; color: var(--ink-soft); margin-bottom: 18px; }
.menu-actions { display: grid; gap: 12px; }
.menu-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.stack { flex-direction: column; gap: 3px; align-items: flex-start; text-align: left; padding: 0.6em 0.9em; }
.facts { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 6px 14px; margin-top: 18px; padding-top: 14px; border-top: 2px solid var(--ink); }
.fact { font: 500 0.86rem var(--body); color: var(--muted); }
.fact b { display: block; font: 700 1.45rem var(--display); color: var(--ink); font-variant-numeric: tabular-nums; }
.menu-tools { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.menu-tools .spacer { flex: 1; }
.credit { font-size: 0.82rem; color: var(--muted); }

/* sheets: garage, results, pause */
.screen-sheet { display: grid; place-items: center; padding: 20px 14px; background: rgba(20, 35, 43, 0.62); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.sheet { width: min(900px, 100%); padding: 22px; }
.sheet.narrow { width: min(460px, 100%); }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: clamp(2rem, 6vw, 2.8rem); font-weight: 800; flex: 1; }
.wallet { display: inline-flex; align-items: center; gap: 8px; font: 700 1.6rem var(--display); font-variant-numeric: tabular-nums; background: var(--ink); color: var(--paper); padding: 6px 14px; border-radius: 10px; }

/* garage */
.car-tabs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin-bottom: 16px; }
.car-tab { background: var(--paper-dim); border: 2.5px solid transparent; border-radius: 12px; padding: 4px 4px 6px; cursor: pointer; font: 600 0.95rem var(--display); color: var(--ink); text-align: center; }
.car-tab canvas { width: 100%; height: 46px; display: block; }
.car-tab.locked canvas { filter: grayscale(1) opacity(0.55); }
.car-tab.sel { border-color: var(--ink); background: #fff; box-shadow: 0 3px 0 var(--ink); }
.car-tab small { display: block; font: 500 0.74rem var(--body); color: var(--muted); }
.garage-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 20px; align-items: start; }
.showcase { background: linear-gradient(#fff, var(--paper-dim)); border-radius: 14px; border: 2px solid var(--ink); padding: 12px 14px; }
.showcase canvas { width: 100%; height: 170px; display: block; }
.showcase h3 { font-size: 2.1rem; font-weight: 800; }
.showcase .tag { color: var(--ink-soft); font-size: 0.98rem; margin: 4px 0 12px; min-height: 2.6em; }
.stat { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 10px; font: 600 0.98rem var(--display); margin-top: 5px; }
.stat-bar { height: 9px; border-radius: 5px; background: rgba(20, 35, 43, 0.14); overflow: hidden; }
.stat-bar i { display: block; height: 100%; background: var(--ink); border-radius: 5px; transition: width 250ms; }
.upgrades { display: grid; gap: 10px; }
.up { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; }
.up h4 { margin: 0; font: 700 1.3rem var(--display); }
.up p { font-size: 0.86rem; color: var(--muted); }
.pips { display: flex; gap: 3px; margin-top: 6px; }
.pips i { flex: 1; max-width: 22px; height: 7px; border-radius: 2px; background: rgba(20, 35, 43, 0.14); }
.pips i.on { background: var(--green); }
.price { display: inline-flex; align-items: center; gap: 6px; }
.price .coin { width: 16px; height: 16px; }
.btn.buy { background: var(--sign); min-width: 118px; }
.btn.buy.poor { background: var(--paper-dim); color: var(--muted); }
.locked-note { padding: 18px; border: 2px dashed var(--ink); border-radius: 12px; text-align: center; }
.locked-note p { margin-bottom: 12px; color: var(--ink-soft); }
.sheet-foot { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.sheet-foot .btn.primary { flex: 1; }

/* results */
.verdict { font: 800 clamp(2.2rem, 8vw, 3.4rem)/0.95 var(--display); }
.verdict span { color: var(--muted); font-weight: 600; font-size: 0.5em; display: block; margin-bottom: 4px; }
.stamp {
  display: inline-block; margin: 12px 0 2px; padding: 5px 14px; border: 3px solid var(--red); border-radius: 8px;
  font: 800 1.5rem var(--display); color: var(--red); transform: rotate(-3deg);
}
.stamp.in { animation: stamp 420ms 250ms both cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes stamp { from { opacity: 0; transform: rotate(-3deg) scale(2.2); } }
.near { margin-top: 10px; font: 600 1.25rem var(--display); color: var(--ink-soft); }
.near b { color: var(--red); }
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 16px; }
.ledger { border: 2px solid var(--ink); border-radius: 12px; background: #fff; padding: 6px 14px; }
.ledger div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed rgba(20, 35, 43, 0.25); font-size: 1rem; }
.ledger div b { font: 700 1.2rem var(--display); font-variant-numeric: tabular-nums; }
.ledger .total { border-bottom: 0; font: 700 1.35rem var(--display); padding-top: 9px; }
.ledger .total b { font-size: 1.7rem; display: inline-flex; align-items: center; gap: 7px; }
.missions h3 { font-size: 1.35rem; font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: baseline; }
.missions h3 small { font: 500 0.85rem var(--body); color: var(--muted); }
.mission { padding: 8px 0; border-bottom: 1px dashed rgba(20, 35, 43, 0.25); }
.mission:last-child { border-bottom: 0; }
.mission p { display: flex; justify-content: space-between; gap: 10px; font-size: 0.98rem; }
.mission p b { font: 700 1.05rem var(--display); white-space: nowrap; }
.mission.done p b { color: var(--green); }
.mbar { height: 6px; border-radius: 3px; background: rgba(20, 35, 43, 0.14); margin-top: 5px; overflow: hidden; }
.mbar i { display: block; height: 100%; background: var(--ink); }
.mission.done .mbar i { background: var(--green); }
.tip { margin-top: 14px; padding: 10px 14px; border-radius: 10px; background: var(--sign); font-weight: 500; }

/* pause and settings */
.toggles { display: grid; gap: 10px; margin: 6px 0 4px; }
.toggle { display: flex; align-items: center; justify-content: space-between; font: 600 1.25rem var(--display); padding: 8px 0; border-bottom: 1px dashed rgba(20, 35, 43, 0.25); cursor: pointer; }
.toggle i { width: 50px; height: 28px; border-radius: 14px; background: var(--paper-dim); border: 2.5px solid var(--ink); position: relative; flex: none; }
.toggle i::after { content: ""; position: absolute; left: 2px; top: 2px; width: 19px; height: 19px; border-radius: 50%; background: var(--ink); transition: transform 120ms; }
.toggle.on i { background: var(--sign); }
.toggle.on i::after { transform: translateX(22px); }
.how { font-size: 0.98rem; line-height: 1.45; color: var(--ink-soft); margin: 8px 0 14px; }
.how b { color: var(--ink); font-weight: 600; }
.stack-btns { display: grid; gap: 10px; margin-top: 14px; }

#toast {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 10px; font-weight: 500; z-index: 9;
  box-shadow: 0 0 0 2px var(--paper);
}

/* ------------------------------------------------------------------ small screens */

@media (max-width: 720px) {
  .screen-menu { align-items: flex-end; padding: 12px; background: linear-gradient(0deg, rgba(20, 35, 43, 0.8) 0, rgba(20, 35, 43, 0.3) 62%, rgba(20, 35, 43, 0) 100%); }
  .menu-board { width: 100%; padding: 18px 18px 16px; margin-bottom: var(--safe-b); }
  .title { font-size: clamp(3rem, 15vw, 4.2rem); }
  .lede { margin-bottom: 12px; font-size: 1rem; }
  .garage-main, .results-grid { grid-template-columns: 1fr; }
  .car-tabs { grid-template-columns: repeat(4, 1fr); }
  .sheet { padding: 16px; }
  .showcase canvas { height: 130px; }
  .odo-num { padding: 6px 10px 4px; }
  .pill { height: 40px; padding: 0 10px; font-size: 1.25rem; }
  .icon-btn { width: 40px; height: 40px; }
  .chase-bar { width: 96px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .screen-menu { align-items: center; padding: 10px 14px; }
  .menu-board { width: min(400px, 56vw); padding: 12px 16px; }
  .title { font-size: 2.6rem; }
  .ridge { height: 18px; margin: 0 0 4px; }
  .lede { display: none; }
  .facts { margin-top: 10px; padding-top: 8px; }
  .btn.primary { min-height: 50px; font-size: 1.4rem; }
  .btn { min-height: 44px; }
  .menu-tools { margin-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .stamp.in, .fuel.crit { animation: none; }
  .stunt, #banner.show { animation-name: plain-fade; }
  @keyframes plain-fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
}

/* Screenshot mode: no motion, so a captured frame is always the finished state. */
.still *, .still *::before, .still *::after { animation: none !important; transition: none !important; }
.still #banner.show, .still .stunt { opacity: 1; }

/* Keyboard hints mean nothing on a touch screen. */
@media (pointer: coarse) { .btn kbd { display: none; } }

/* The coin counter jumps when a coin lands in it. */
.pill.coins.bump { animation: bump 160ms; }
@keyframes bump { 40% { transform: scale(1.14); } }

/* Game over: a camera flash, then the photo it took sits on the results sheet. */
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 8; }
#flash.go { animation: flash 420ms ease-out; }
@keyframes flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
.results-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.photo {
  margin: 0 6px 0 0; width: min(240px, 38%); flex: none; background: #fff; padding: 8px 8px 6px;
  border: 2px solid var(--ink); border-radius: 4px; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3); transform: rotate(3deg);
  animation: snap 480ms 120ms both cubic-bezier(0.2, 1.5, 0.4, 1);
}
.photo img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 2px; }
.photo figcaption { font: 600 1rem var(--display); text-align: center; padding-top: 5px; }
@keyframes snap { from { opacity: 0; transform: rotate(-10deg) scale(1.5); } }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.badge { background: var(--sign); border: 2px solid var(--ink); border-radius: 10px; padding: 5px 12px 6px; position: relative; }
.badge b { display: block; font: 700 1.15rem var(--display); }
.badge small { font-size: 0.78rem; }
.badge.fresh::after {
  content: "New"; position: absolute; top: -9px; right: -8px; background: var(--red); color: #fff;
  font: 700 0.75rem var(--display); padding: 1px 6px; border-radius: 6px; transform: rotate(8deg);
}
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; margin-top: 14px; }
.tile { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px 7px; font-size: 0.82rem; color: var(--muted); line-height: 1.15; }
.tile b { display: block; font: 800 1.5rem var(--display); color: var(--ink); font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .photo { width: 42%; }
  .tally { grid-template-columns: repeat(3, 1fr); }
}
.still .photo { opacity: 1; }
