:root {
  --ink: #141821;
  --dusk: #2E3D52;
  --amber: #FF7A2F;
  --sodium: #FFC55C;
  --cream: #EDE3D0;
  --alarm: #E2383F;
  --teal: #2F8F86;
  --font-text: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-num: "Archivo", "Helvetica Neue", sans-serif;
  --font-display: "Titan One", "Arial Black", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d1118;
  color: var(--cream);
  font-family: var(--font-text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

button {
  font-family: var(--font-text);
  color: var(--cream);
  background: none;
  border: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .1em;
}

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

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .9s ease .15s;
  z-index: 10;
  text-shadow: 0 1px 12px rgba(10, 14, 20, .55);
}
#hud.live { opacity: 1; }

.hud-top-left {
  position: absolute;
  top: calc(16px + var(--safe-t));
  left: calc(18px + var(--safe-l));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.hud-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(20, 24, 33, .38);
  border: 1px solid rgba(237, 227, 208, .26);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  transition: background .2s ease, border-color .2s ease;
}
.hud-icon:hover { background: rgba(20, 24, 33, .6); border-color: rgba(255, 197, 92, .55); }
.hud-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--cream);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hud-icon svg path:first-child { fill: rgba(237, 227, 208, .18); }
#soundBtn.muted .wave { opacity: .22; }
#soundBtn.muted svg { stroke: rgba(237, 227, 208, .55); }

.hud-top-right {
  position: absolute;
  top: calc(16px + var(--safe-t));
  right: calc(20px + var(--safe-r));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.stars {
  display: flex;
  gap: 3px;
  padding: 3px 6px 2px;
  border-radius: 3px;
  background: rgba(20, 24, 33, .3);
  border: 1px solid rgba(237, 227, 208, .12);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: .9;
}
.stars svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--cream);
  stroke-width: 1.3;
  opacity: .8;
  filter: drop-shadow(0 1px 4px rgba(10, 14, 20, .5));
}

.cash {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 16px 8px 14px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(20, 24, 33, .52), rgba(20, 24, 33, .34));
  border: 1px solid rgba(237, 227, 208, .18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.cash-sign {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 15px;
  color: var(--sodium);
}
.cash-val {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}

.bottom-left {
  position: absolute;
  bottom: calc(22px + var(--safe-b));
  left: calc(22px + var(--safe-l));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.mode-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 15px 8px 12px;
  border-radius: 999px;
  background: rgba(20, 24, 33, .46);
  border: 1px solid rgba(239, 229, 209, .22);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 14px;
  letter-spacing: .18em;
  font-weight: 600;
  color: rgba(237, 227, 208, .92);
  transition: border-color .35s ease;
}
.mode-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sodium);
  box-shadow: 0 0 10px rgba(255, 197, 92, .85);
}
#modeChip.driving { border-color: rgba(255, 197, 92, .55); }

.speed-dial {
  position: relative;
  visibility: hidden;
  width: 96px;
  height: 96px;
  margin-left: 2px;
  opacity: 0;
  transform: translateY(10px) scale(.82);
  transform-origin: 20% 100%;
  transition: opacity .4s ease, transform .5s cubic-bezier(.2, .9, .25, 1);
  pointer-events: none;
}
#hud:not(.driving) .speed-dial { display: none; }
#hud.driving .speed-dial { opacity: 1; visibility: visible; display: block; transform: translateY(0) scale(1); }
.speed-dial svg { width: 100%; height: 100%; overflow: visible; }
.dial-bg { fill: rgba(20, 24, 33, .44); stroke: none; }
.dial-track {
  fill: none;
  stroke: rgba(237, 227, 208, .22);
  stroke-width: 2;
  stroke-dasharray: 236 78;
  stroke-linecap: round;
  transform: rotate(126deg);
  transform-origin: 60px 60px;
}
.dial-fill {
  fill: none;
  stroke: var(--sodium);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 0 314;
  transform: rotate(126deg);
  transform-origin: 60px 60px;
  filter: drop-shadow(0 0 5px rgba(255, 197, 92, .6));
  transition: stroke-dasharray .1s linear;
}
.dial-ticks line { stroke: rgba(237, 227, 208, .5); stroke-width: 1.4; }
.dial-needle {
  stroke: var(--alarm);
  stroke-width: 2.2;
  stroke-linecap: round;
  transform-origin: 60px 60px;
  filter: drop-shadow(0 0 4px rgba(226, 56, 63, .55));
}
.dial-hub { fill: var(--cream); }
.speed-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 8px;
}
#speedValue {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 24px;
  line-height: .9;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.speed-unit {
  font-size: 8.5px;
  letter-spacing: .22em;
  opacity: .62;
  margin-top: 3px;
}
.gear-readout {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-num);
  font-size: 9px;
  letter-spacing: .12em;
  color: var(--sodium);
  opacity: .85;
}

.prompt {
  position: absolute;
  left: 50%;
  bottom: calc(30px + var(--safe-b));
  transform: translate(-50%, 8px);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity .28s ease, transform .28s ease;
  pointer-events: auto;
  padding: 4px 14px 5px 5px;
  border-radius: 4px;
  background: rgba(20, 24, 33, .3);
  border: 1px solid rgba(237, 227, 208, .14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.prompt.show { opacity: 1; transform: translate(-50%, 0); }
.keycap {
  display: grid;
  place-items: center;
  min-width: 27px;
  height: 27px;
  padding: 0 6px;
  border-radius: 3px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: linear-gradient(180deg, #f5eddc, #d7cab2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), inset 0 -1px 0 rgba(0, 0, 0, .25), 0 1px 2px rgba(0, 0, 0, .4);
}
#promptText {
  font-size: 14px;
  letter-spacing: .16em;
  font-weight: 600;
  color: rgba(237, 227, 208, .95);
}

.tip {
  position: absolute;
  top: calc(18px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  font-size: 10.5px;
  letter-spacing: .2em;
  color: rgba(237,227,208,.62);
  background: rgba(20,24,33,.32);
  border: 1px solid rgba(237,227,208,.12);
  border-radius: 3px;
  padding: 5px 13px 6px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 1.2s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.tip.show { opacity: 1; }
.tip.hide { opacity: 0; }

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity .3s ease;
}
.crosshair.show { opacity: .55; }
.crosshair .tick { position: absolute; background: var(--cream); border-radius: 1px; }
.crosshair .top { width: 1.5px; height: 6px; left: 12px; top: 0; }
.crosshair .bottom { width: 1.5px; height: 6px; left: 12px; bottom: 0; }
.crosshair .left { width: 6px; height: 1.5px; top: 12px; left: 0; }
.crosshair .right { width: 6px; height: 1.5px; top: 12px; right: 0; }
.crosshair .dot { position: absolute; width: 2px; height: 2px; border-radius: 50%; left: 12px; top: 12px; background: var(--sodium); }

.bottom-right {
  position: absolute;
  right: calc(20px + var(--safe-r));
  bottom: calc(20px + var(--safe-b));
}
.minimap-wrap {
  position: relative;
  width: clamp(112px, 16vw, 158px);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  filter: drop-shadow(0 4px 18px rgba(8, 10, 14, .55));
}
#minimap { width: 100%; height: 100%; display: block; border-radius: 50%; }
.minimap-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(237, 227, 208, .32);
  box-shadow: inset 0 0 22px rgba(10, 14, 20, .55);
  pointer-events: none;
}
.compass-notch {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--cream);
  z-index: 2;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}
.minimap-label {
  position: absolute;
  top: 13px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  letter-spacing: .2em;
  color: rgba(237, 227, 208, .75);
  z-index: 2;
}

/* ---------- touch ---------- */

.touch { display: none; position: absolute; inset: 0; pointer-events: none; }
body.touch-mode .touch { display: block; }

.stick {
  position: absolute;
  left: calc(24px + var(--safe-l));
  bottom: calc(26px + var(--safe-b));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}
.stick-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(237, 227, 208, .22);
  background: radial-gradient(circle at 50% 45%, rgba(30, 40, 54, .22), rgba(10, 14, 20, .34));
  backdrop-filter: blur(4px);
}
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 240, 214, .32), rgba(120, 130, 140, .18));
  border: 1px solid rgba(237, 227, 208, .38);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

.touch-actions {
  position: absolute;
  right: calc(20px + var(--safe-r));
  bottom: calc(154px + var(--safe-b));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}

.round-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(24, 30, 40, .55);
  border: 1.5px solid rgba(237, 227, 208, .38);
  color: var(--cream);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  user-select: none;
  pointer-events: auto;
}
#actBtn {
  background: rgba(217, 107, 42, .82);
  border-color: rgba(255, 231, 184, .8);
  color: #fff8ea;
  width: 66px;
  height: 66px;
}
.round-btn:active { transform: scale(.94); filter: brightness(1.15); }
.hb-btn { display: none; }
#hud.driving .hb-btn { display: flex; }
#hud.driving .run-btn { display: none; }

body.touch-mode .bottom-left { bottom: calc(152px + var(--safe-b)); }
body.touch-mode .speed-dial { transform-origin: 20% 100%; }
body.touch-mode .tip { top: calc(96px + var(--safe-t)); font-size: 8.5px; letter-spacing: .08em; padding: 4px 9px 5px; white-space: normal; max-width: calc(100vw - 40px); text-align: center; line-height: 1.3; }

@media (max-width: 760px) {
  .touch-actions { right: calc(14px + var(--safe-r)); bottom: calc(138px + var(--safe-b)); gap: 8px; }
  .prompt { bottom: calc(212px + var(--safe-b)); }
  .round-btn { width: 54px; height: 54px; font-size: 11px; }
  #actBtn { width: 60px; height: 60px; }
  .cash-val { font-size: 18px; }
  .bottom-left { bottom: calc(22px + var(--safe-b)); }
  .mode-chip { font-size: 12px; padding: 6px 12px 7px 10px; }
  .stick { width: 110px; height: 110px; }
  .knob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .stick { width: 96px; height: 96px; bottom: 16px; left: 18px; }
  .knob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  .round-btn { width: 48px; height: 48px; font-size: 10px; }
  #actBtn { width: 52px; height: 52px; }
  .minimap-wrap { width: 92px; }
  .touch-actions { bottom: 14px; right: calc(120px + var(--safe-r)); }
  .speed-dial { width: 84px; height: 84px; }
  .prompt { bottom: 16px; }
}

/* ---------- help ---------- */

.help-card {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 36px));
  background: rgba(16, 21, 29, .88);
  border: 1px solid rgba(237, 227, 208, .2);
  border-radius: 8px;
  padding: 24px 26px 22px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 24px 90px rgba(0, 0, 0, .5);
}
.help-card h2 {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: .05em;
  margin: 0 0 16px;
  color: var(--cream);
  font-weight: 400;
}
.help-grid { display: grid; grid-template-columns: 1fr; gap: 7px; }
.help-grid > div { display: flex; justify-content: space-between; gap: 20px; border-bottom: 1px solid rgba(237, 227, 208, .09); padding-bottom: 6px; }
.help-grid .k { font-family: var(--font-num); font-weight: 700; font-size: 12px; letter-spacing: .06em; color: var(--sodium); }
.help-grid span:last-child { font-size: 13px; letter-spacing: .12em; color: rgba(237, 227, 208, .78); }
.help-card p { margin: 16px 0 0; font-size: 13px; line-height: 1.35; letter-spacing: .04em; color: rgba(237, 227, 208, .62); }
.help-close {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 10px;
  letter-spacing: .14em;
  color: rgba(237, 227, 208, .55);
}
.help-close:hover { color: var(--cream); }

/* ---------- title ---------- */

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #131a26;
  transition: opacity 1.15s ease, visibility 1.15s;
  overflow: hidden;
}
.title-screen.hide { opacity: 0; visibility: hidden; pointer-events: none; }
#titleArt { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 46%, transparent 24%, rgba(9, 13, 20, .18) 62%, rgba(9, 13, 20, .62) 100%),
    linear-gradient(180deg, rgba(9, 13, 20, .3), transparent 26%, transparent 70%, rgba(9, 13, 20, .55));
}
.title-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 18px calc(26px + var(--safe-b));
  text-align: center;
}
.title-kicker {
  font-size: clamp(9px, 1.4vw, 12px);
  letter-spacing: .44em;
  color: rgba(237, 227, 208, .66);
  margin-bottom: clamp(10px, 2.4vh, 24px);
  text-indent: .44em;
}
.title-logo {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: .8;
  color: var(--cream);
  filter: drop-shadow(0 6px 30px rgba(255, 122, 47, .18));
}
.title-logo .city {
  font-size: clamp(24px, 5.2vw, 52px);
  letter-spacing: .24em;
  text-indent: .24em;
  color: #f0e5cf;
  text-shadow: 0 0 26px rgba(255, 197, 92, .6), 0 2px 0 rgba(88, 47, 20, .5);
  margin-bottom: clamp(2px, .8vh, 8px);
}
.title-logo .rush {
  font-size: clamp(76px, 19vw, 208px);
  letter-spacing: .015em;
  text-shadow:
    0 0 4px rgba(255, 197, 92, .9),
    0 0 28px rgba(255, 122, 47, .62),
    0 0 90px rgba(255, 122, 47, .34),
    0 5px 0 rgba(94, 48, 20, .55),
    0 10px 34px rgba(6, 9, 14, .6);
  -webkit-text-stroke: 1px rgba(255, 232, 186, .22);
}
.title-line {
  margin: clamp(34px, 6vh, 52px) 0 clamp(18px, 4vh, 38px);
  padding: 7px 16px 8px;
  border-radius: 2px;
  background: rgba(14, 19, 27, .32);
  border: 1px solid rgba(237, 227, 208, .14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: clamp(12px, 1.9vw, 16px);
  letter-spacing: .34em;
  text-indent: .34em;
  color: rgba(247, 238, 220, .96);
  text-shadow: 0 2px 12px rgba(8, 11, 16, .85);
}
.start-btn {
  min-width: 190px;
  padding: 13px 28px 14px;
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .24em;
  color: #201810;
  background: linear-gradient(180deg, #ffd27d, #f8ad48);
  border: 1px solid rgba(255, 241, 206, .85);
  border-radius: 3px;
  box-shadow: 0 6px 26px rgba(255, 140, 44, .3), inset 0 1px 0 rgba(255, 255, 255, .65);
  transition: transform .18s ease, filter .18s ease, opacity .4s ease;
}
.start-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); }
.start-btn:active:not(:disabled) { transform: translateY(1px); }
.start-btn:disabled { opacity: .42; cursor: default; color: rgba(32, 24, 16, .7); background: rgba(237, 227, 208, .32); border-color: rgba(237, 227, 208, .2); box-shadow: none; }
.load-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(5px + env(safe-area-inset-bottom, 0px));
  height: 3px;
  background: rgba(237, 227, 208, .1);
}
.load-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ff9b45, #ffd27d);
  box-shadow: 0 0 18px rgba(255, 170, 74, .9);
  transition: width .35s ease;
}
.load-label {
  position: absolute;
  bottom: calc(13px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: .3em;
  color: rgba(237, 227, 208, .52);
  transition: opacity .4s ease;
  white-space: nowrap;
}
.load-label.done { opacity: 0; }

/* portrait title */
@media (max-width: 560px) {
  .title-logo .rush { font-size: clamp(74px, 23vw, 130px); }
  .title-logo .city { font-size: clamp(22px, 6vw, 34px); }
  .title-line { font-size: 11px; letter-spacing: .22em; text-indent: .22em; }
  .title-kicker { letter-spacing: .3em; text-indent: .3em; }
}
@media (max-height: 520px) {
  .title-logo .rush { font-size: clamp(52px, 15vw, 120px); }
  .title-logo .city { font-size: 22px; }
  .title-line { margin: 10px 0 16px; }
  .title-kicker { margin-bottom: 6px; }
}
