:root {
  --navy: #0b2a5b;
  --navy-2: #12397a;
  --yellow: #ffd200;
  --orange: #ff7a00;
  --red: #e63b2e;
  --ink: #111;
  --paper: #fffdf5;
  --display: 'Bungee', 'Arial Black', Impact, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--navy); color: #fff;
  font-family: var(--body);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
canvas#game {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  display: block; touch-action: none;
}
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-t) + 10px) 12px 0;
  pointer-events: none;
}
.hud-row { display: flex; gap: 8px; align-items: stretch; }
.hud-row.sub { margin-top: 6px; gap: 6px; flex-wrap: wrap; }
.stat {
  background: rgba(11, 42, 91, .82);
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 10px; padding: 4px 9px;
  display: flex; flex-direction: column; justify-content: center; line-height: 1;
}
.stat b { font-family: var(--display); font-size: 17px; font-weight: 400; }
.stat small { font-size: 9px; letter-spacing: .08em; text-transform: uppercase; opacity: .8; margin-top: 3px; }
.stat.bill { margin-left: auto; background: rgba(230, 59, 46, .9); }
.stat.over b { color: var(--yellow); }
.susp {
  /* up in the sky, under the HUD, where it never hides the roadside */
  position: fixed; right: 6px; top: calc(var(--safe-t) + 128px);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 3px; border-radius: 8px; pointer-events: none;
  background: rgba(11, 42, 91, .6); border: 1.5px solid rgba(255,255,255,.7);
  font-family: var(--display);
}
.susp small { font-size: 8px; }
.susp b { font-size: 10px; font-weight: 400; }
.susp-bar {
  position: relative; width: 10px; height: clamp(80px, 14vh, 130px);
  border-radius: 7px; background: rgba(255,255,255,.18); overflow: hidden;
}
.susp-bar i { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: #3ccf6e; transition: height .25s, background .25s; }
.susp.low { animation: pulse .6s infinite alternate; border-color: var(--red); }
@keyframes pulse { to { box-shadow: 0 0 14px var(--red); } }
.icon-btn {
  pointer-events: auto; width: 40px; border: 2px solid rgba(255,255,255,.85);
  background: rgba(11,42,91,.82); color: #fff; border-radius: 10px; font-size: 13px; cursor: pointer;
}
.tag {
  font-family: var(--display); font-size: 11px; padding: 4px 8px; border-radius: 6px;
  background: rgba(11,42,91,.85); border: 1.5px solid #fff;
}
.tag.warn { background: var(--orange); color: #000; border-color: #000; }
.tag.good { background: var(--yellow); color: #000; border-color: #000; }

#callout {
  position: fixed; left: 0; right: 0; top: 30%; text-align: center;
  font-family: var(--display); font-size: clamp(26px, 7vw, 56px);
  color: var(--yellow); text-shadow: 0 3px 0 #000, 0 0 18px rgba(0,0,0,.6);
  pointer-events: none; opacity: 0; transform: scale(.8);
  transition: opacity .25s, transform .25s; padding: 0 16px;
}
#callout.show { opacity: 1; transform: scale(1); }

/* Notices live up in the sky under the HUD, never over the car or the road ahead.
   Narrow enough to clear the suspension meter on the right. */
#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 140px);
  transform: translateX(-50%) translateY(-12px);
  width: min(calc(100vw - 92px), 440px); text-align: center;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 12px; padding: 10px 14px;
  font-weight: 700; font-size: 14px; line-height: 1.3;
  box-shadow: 0 4px 0 rgba(0,0,0,.3);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: #ffe1dc; }

#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

#brake {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 22px);
  width: 112px; height: 64px; border-radius: 16px;
  font-family: var(--display); font-size: 16px; color: #fff;
  background: rgba(230,59,46,.88); border: 3px solid #fff;
  touch-action: none;
}
#brake.on { background: #fff; color: var(--red); }
/* Visual steering pads. Purely a guide: the whole left/right half of the screen steers. */
#pads { position: fixed; inset: auto 0 calc(var(--safe-b) + 14px) 0; display: flex; justify-content: space-between; padding: 0 14px; pointer-events: none; }
.pad {
  width: 74px; height: 74px; border-radius: 50%;
  display: grid; place-items: center; font-size: 28px; color: #fff;
  background: rgba(11,42,91,.35); border: 3px solid rgba(255,255,255,.55);
  text-shadow: 0 2px 0 rgba(0,0,0,.5); transition: background .08s, transform .08s;
}
.pad.on { background: rgba(255,210,0,.75); border-color: #fff; color: #000; transform: scale(1.08); }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  background: linear-gradient(180deg, rgba(11,42,91,.35), rgba(11,42,91,.82));
  overflow-y: auto;
}
.card {
  margin: auto; width: min(100%, 420px); text-align: center;
  background: rgba(8, 26, 58, .9); border: 3px solid #fff; border-radius: 20px;
  padding: 22px 20px 18px; box-shadow: 0 12px 0 rgba(0,0,0,.35);
}
.card.small { width: min(100%, 320px); }
h1, h2 { font-family: var(--display); font-weight: 400; margin: 10px 0 6px; line-height: 1; }
h1 { font-size: clamp(40px, 13vw, 62px); color: #fff; text-shadow: 0 4px 0 #000; }
h1 span { color: var(--yellow); }
h2 { font-size: clamp(22px, 6.5vw, 30px); color: var(--yellow); }
.lede { margin: 6px 0 16px; font-weight: 700; opacity: .92; }
.kicker { font-family: var(--display); font-size: 11px; letter-spacing: .12em; color: var(--orange); margin: 0; }

.plate {
  display: inline-flex; flex-direction: column; align-items: center;
  background: #fff; color: var(--navy); border: 3px solid var(--navy);
  outline: 2px solid #fff; border-radius: 8px; padding: 4px 18px 5px; transform: rotate(-3deg);
}
.plate-top, .plate-bot { font-size: 9px; font-weight: 900; letter-spacing: .2em; }
.plate-num { font-family: var(--display); font-size: 30px; letter-spacing: .06em; line-height: 1.05; }

.big-btn {
  display: block; width: 100%; padding: 15px; margin-top: 6px;
  font-family: var(--display); font-size: 20px; color: #000;
  background: var(--yellow); border: 3px solid #000; border-radius: 14px;
  box-shadow: 0 5px 0 #000; cursor: pointer;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #000; }
/* the Start button stays reachable while the garage and routes scroll */
#playBtn { position: sticky; bottom: calc(var(--safe-b) + 6px); z-index: 3; }
button { touch-action: manipulation; -webkit-touch-callout: none; }
html, body { -webkit-touch-callout: none; }
.link-btn {
  margin: 12px 8px 0; background: none; border: 0; color: #fff; opacity: .85;
  font: 700 14px var(--body); text-decoration: underline; cursor: pointer;
}
.garage { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 14px; }
.veh {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px 8px; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.25); color: #fff;
  font-family: var(--body);
}
.veh canvas { width: 100%; height: 64px; display: block; }
.veh b { font-family: var(--display); font-weight: 400; font-size: 14px; }
.veh small { font-size: 10px; line-height: 1.25; opacity: .75; }
.veh.on { border-color: var(--yellow); background: rgba(255,210,0,.16); box-shadow: 0 0 0 2px var(--yellow) inset; }
.routes { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 14px; text-align: left; }
.route-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 12px; cursor: pointer; color: #fff; font-family: var(--body);
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.25); text-align: left;
}
.route-btn.on { border-color: var(--yellow); background: rgba(255,210,0,.16); box-shadow: 0 0 0 2px var(--yellow) inset; }
.shield {
  flex: none; min-width: 44px; padding: 5px 6px; text-align: center;
  font-family: var(--display); font-size: 14px; color: var(--yellow);
  background: #0f6b3a; border: 2px solid var(--yellow); border-radius: 6px;
}
.r-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.r-main b { font-family: var(--display); font-weight: 400; font-size: 14px; }
.r-main small { font-size: 11px; opacity: .75; line-height: 1.3; }
.r-stars { flex: none; color: var(--yellow); font-size: 13px; letter-spacing: 1px; }

.routebar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  margin-top: 6px; padding: 5px 10px; border-radius: 10px;
  background: rgba(11, 42, 91, .82); border: 2px solid rgba(255,255,255,.85);
  font-family: var(--display); font-size: 11px;
}
.routebar .bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
.routebar .bar i { display: block; height: 100%; width: 0; background: var(--yellow); }
.routebar small { grid-column: 1 / -1; font-family: var(--body); font-weight: 700; font-size: 11px; opacity: .85; margin-top: -2px; }
.route-line { font-size: 12px; font-weight: 700; opacity: .8; margin: 4px 0 0; }
.stars { font-size: 40px; color: var(--yellow); letter-spacing: 6px; text-shadow: 0 3px 0 #000; margin: 4px 0; }

.how { list-style: none; padding: 0; margin: 16px 0 6px; font-size: 13px; line-height: 1.9; opacity: .9; }
kbd {
  display: inline-block; min-width: 20px; padding: 0 4px; margin-right: 2px;
  border: 1.5px solid #fff; border-radius: 4px; font-size: 11px; line-height: 16px;
}
.best { font-family: var(--display); color: var(--yellow); margin: 8px 0 0; font-size: 14px; }
.disc { font-size: 11px; opacity: .6; margin: 12px 0 0; line-height: 1.4; }
.disc a { color: #fff; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 10px; }
.stats div { background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px 4px; }
.stats b { display: block; font-family: var(--display); font-weight: 400; font-size: 20px; }
.stats small { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.score { font-family: var(--display); margin: 4px 0 12px; }
.score b { color: var(--yellow); font-size: 22px; font-weight: 400; }
.score span { font-size: 11px; color: var(--orange); }
.response {
  background: var(--paper); color: var(--ink); text-align: left;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; border-left: 6px solid var(--orange);
}
.response p:last-child { margin: 6px 0 0; font-weight: 700; font-size: 14px; line-height: 1.35; }

@media (min-width: 700px) {
  .stat b { font-size: 22px; }
}

/* Short screens (phones in landscape, small phones): tighter title and HUD */
@media (max-height: 700px) {
  .card { padding: 14px 14px 12px; }
  h1 { font-size: clamp(30px, 9vh, 48px); margin: 6px 0 4px; }
  .lede { margin: 4px 0 10px; }
  .how { display: none; }
  .veh canvas { height: 48px; }
  .r-main small { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (max-height: 500px) {
  .plate { display: none; }
  .susp { top: calc(var(--safe-t) + 96px); }
  .susp-bar { height: 60px; }
  .pad { width: 60px; height: 60px; font-size: 22px; }
  #brake { height: 52px; width: 96px; bottom: calc(var(--safe-b) + 12px); }
  #toast { top: calc(var(--safe-t) + 118px); width: min(60vw, 440px); font-size: 12px; padding: 6px 10px; }
  #callout { top: 46%; }
}
