:root {
  --cream: #f3e9d6;
  --cream-dim: #cfc3ab;
  --ink: #0b0f12;
  --ink-2: #11181c;
  --brass: #e8b23a;
  --brass-dim: rgba(232, 178, 58, .38);
  --red: #c33c2b;
  --sea: #123e5c;
  --glass: rgba(10, 15, 18, .66);
  --glass-2: rgba(12, 18, 22, .82);
  --line: rgba(243, 233, 214, .16);
  --display: 'Bevan', Georgia, serif;
  --text: 'Barlow Semi Condensed', 'Arial Narrow', sans-serif;
  --mono: 'Chivo Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070a0c;
  color: var(--cream);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { touch-action: none; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

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

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse at 50% 42%, transparent 42%, rgba(3, 6, 8, .35) 100%),
    linear-gradient(180deg, rgba(3, 6, 8, .35) 0%, transparent 22%, transparent 72%, rgba(3, 6, 8, .42) 100%);
}

.hidden { display: none !important; }

.eyebrow {
  margin: 0;
  font-family: var(--text);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .22em;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--brass);
}

.brand-mark { width: 46px; height: auto; display: block; border-radius: 50%; background: #f3e6c8; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5)); }

.btn {
  appearance: none;
  border: 1px solid rgba(243, 233, 214, .4);
  border-radius: 2px;
  background: rgba(243, 233, 214, .04);
  color: var(--cream);
  padding: 12px 20px;
  font-family: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .12s ease;
  white-space: nowrap;
}
.btn:hover { background: rgba(243, 233, 214, .12); border-color: rgba(243, 233, 214, .7); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--cream);
  border-color: var(--cream);
  color: var(--ink);
}
.btn.primary:hover { background: var(--brass); border-color: var(--brass); }
.btn.small { padding: 9px 14px; font-size: 10px; letter-spacing: .16em; }

/* ---------- loader ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  pointer-events: none;
}
.overlay > * { pointer-events: auto; }

#loader {
  pointer-events: auto;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #172027 0%, #080b0e 62%, #050708 100%);
  z-index: 60;
  transition: opacity .55s ease;
}
#loader.fade { opacity: 0; pointer-events: none; }
.loader-card { text-align: center; padding: 26px; width: min(360px, 84vw); }
.loader-card .brand-mark { margin: 0 auto 16px; width: 72px; }
.loader-card h1 {
  margin: 10px 0 26px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(26px, 5.4vw, 38px);
  letter-spacing: .03em;
  line-height: .98;
  text-transform: uppercase;
}
.loadbar { height: 2px; width: 100%; background: rgba(243, 233, 214, .14); overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 2%; background: var(--brass); transition: width .25s ease; }
.loadtext { margin: 12px 0 0; font-size: 9px; letter-spacing: .26em; color: var(--cream-dim); }

/* ---------- start ---------- */
#start {
  align-items: flex-end;
  justify-content: flex-start;
  padding: clamp(14px, 4vw, 58px);
  background:
    linear-gradient(90deg, rgba(3, 6, 8, .76) 0%, rgba(3, 6, 8, .34) 42%, transparent 72%),
    linear-gradient(0deg, rgba(3, 6, 8, .72) 0%, transparent 42%);
}
.start-card {
  width: min(452px, 100%);
  padding: clamp(20px, 3.4vw, 32px);
  background: linear-gradient(160deg, rgba(18, 25, 29, .8), rgba(8, 12, 15, .74));
  border: 1px solid var(--brass-dim);
  border-top: 2px solid var(--brass);
  border-radius: 2px;
  backdrop-filter: blur(14px) saturate(.9);
  -webkit-backdrop-filter: blur(14px) saturate(.9);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .45);
}
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.brand .brand-mark { width: 54px; }
.brand-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(17px, 2.4vw, 23px);
  letter-spacing: .045em;
  line-height: 1.05;
  text-transform: uppercase;
}
.start-card h2 {
  margin: 0 0 9px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(30px, 5.2vw, 46px);
  line-height: .92;
  letter-spacing: .01em;
  text-transform: uppercase;
}
.lede {
  margin: 0 0 21px;
  color: var(--cream-dim);
  font-size: clamp(13px, 1.7vw, 15px);
  font-weight: 400;
  line-height: 1.55;
  max-width: 38ch;
}
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.hint { margin: 16px 0 0; font-size: 10px; letter-spacing: .14em; color: rgba(243, 233, 214, .56); text-transform: uppercase; line-height: 1.6; }
.start-credit {
  position: absolute;
  right: clamp(14px, 4vw, 58px);
  bottom: clamp(14px, 4vw, 42px);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 9px;
  letter-spacing: .22em;
  color: rgba(243, 233, 214, .55);
}
.start-credit .rule { width: 38px; height: 1px; background: var(--brass); opacity: .7; }

/* ---------- hud ---------- */
#hud { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .panel {
  background: linear-gradient(160deg, rgba(12, 18, 22, .78), rgba(7, 11, 14, .64));
  border: 1px solid var(--brass-dim);
  border-radius: 2px;
  backdrop-filter: blur(10px) saturate(.85);
  -webkit-backdrop-filter: blur(10px) saturate(.85);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .32);
}
.brand-small {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-small .brand-mark { width: 36px; }
.brand-small .brand-name { font-size: clamp(12px, 1.5vw, 16px); }
.brand-small .eyebrow { font-size: 8px; letter-spacing: .19em; color: rgba(232, 178, 58, .8); margin-top: 2px; }

.top-actions {
  position: absolute;
  top: max(78px, calc(env(safe-area-inset-top) + 64px));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  gap: 7px;
}
.icon-btn {
  border: 1px solid var(--brass-dim);
  background: rgba(10, 15, 18, .6);
  color: var(--cream);
  padding: 8px 11px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .16em;
  border-radius: 2px;
  backdrop-filter: blur(8px);
}
.icon-btn:hover { border-color: var(--brass); color: var(--brass); }
.icon-btn.round { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-size: 12px; letter-spacing: 0; }

.minimap {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 196px;
  padding: 8px 9px 7px;
}
.map-head { display: flex; justify-content: space-between; align-items: center; font-size: 8px; letter-spacing: .16em; color: rgba(243, 233, 214, .7); }
.map-live { color: var(--brass); font-size: 7px; letter-spacing: .2em; }
.map-live::before { content: ''; display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--red); margin-right: 4px; vertical-align: 1px; }
#pr-map { display: block; width: 100%; height: auto; margin: 5px 0 4px; }
#pr-land path { fill: rgba(243, 233, 214, .22); stroke: rgba(243, 233, 214, .55); stroke-width: .55; }
.map-route { fill: none; stroke: var(--brass); stroke-width: .85; stroke-dasharray: 2 2.2; opacity: .8; }
.map-labels text { fill: rgba(243, 233, 214, .62); font-family: var(--text); font-size: 3.1px; letter-spacing: .06em; font-weight: 600; }
.map-dot { fill: var(--red); stroke: var(--cream); stroke-width: .8; }
.map-pulse { fill: none; stroke: var(--red); stroke-width: .7; opacity: .55; animation: pulse 2s ease-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes pulse { 0% { transform: scale(.7); opacity: .6; } 70% { transform: scale(2.2); opacity: 0; } 100% { opacity: 0; } }
.map-foot { display: flex; justify-content: space-between; font-size: 7px; letter-spacing: .13em; color: rgba(243, 233, 214, .55); border-top: 1px solid var(--line); padding-top: 4px; }
#map-place { color: var(--brass); }

.timing {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 186px;
  padding: 11px 13px;
}
.timing-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(243, 233, 214, .1); }
.timing-row:last-child { border-bottom: none; }
.timing-row span { font-size: 8px; letter-spacing: .2em; color: rgba(243, 233, 214, .55); }
.timing-row b { font-family: var(--mono); font-size: 17px; font-weight: 400; color: var(--cream); letter-spacing: .02em; }
.timing-row b em { font-style: normal; font-size: 10px; color: rgba(243, 233, 214, .48); }
#pos-read { color: var(--brass); }

.gauge-wrap {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 152px;
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, .5));
}
#gauge { display: block; width: 100%; height: auto; }
.gauge-label { fill: rgba(243, 233, 214, .55); font-family: var(--text); font-size: 7px; letter-spacing: .18em; font-weight: 600; }
.gauge-label.small { font-size: 6px; letter-spacing: .22em; color: rgba(232, 178, 58, .8); fill: rgba(232, 178, 58, .8); }
.gauge-digital { font-family: var(--mono); font-size: 22px; fill: var(--cream); letter-spacing: .02em; }
#gauge-ticks line { stroke: rgba(243, 233, 214, .45); stroke-width: 1; }
#gauge-ticks line.major { stroke: rgba(243, 233, 214, .86); stroke-width: 1.8; }
#gauge-ticks text { fill: rgba(243, 233, 214, .7); font-family: var(--mono); font-size: 7px; text-anchor: middle; }
.gear-read {
  display: flex; align-items: center; gap: 7px; margin-top: -4px;
  font-size: 8px; letter-spacing: .18em; color: rgba(243, 233, 214, .55);
}
.gear-read b { font-family: var(--mono); font-size: 13px; font-weight: 400; color: var(--brass); border: 1px solid var(--brass-dim); padding: 1px 6px; }

.race-hint {
  position: absolute;
  left: 50%;
  bottom: max(17px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: .18em;
  color: rgba(243, 233, 214, .5);
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------- touch controls ---------- */
.touch-controls { display: none; }
.touch-btn {
  border: 1px solid rgba(243, 233, 214, .28);
  background: rgba(10, 15, 18, .54);
  color: rgba(243, 233, 214, .9);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  user-select: none;
  touch-action: none;
  transition: background .1s ease, transform .1s ease, border-color .1s ease;
}
.touch-btn.pressed { background: rgba(232, 178, 58, .82); border-color: var(--brass); color: var(--ink); transform: scale(.96); }
.touch-btn.steer::before { content: ''; width: 0; height: 0; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.touch-btn.steer[data-steer="-1"]::before { border-right: 11px solid currentColor; }
.touch-btn.steer[data-steer="1"]::before { border-left: 11px solid currentColor; }
.steer-pad { display: flex; gap: 10px; align-items: center; }
.pedal-pad { display: flex; flex-direction: column; gap: 8px; }
.touch-btn.pedal { width: 66px; height: 46px; border-radius: 5px; font-size: 9px; letter-spacing: .14em; }
.touch-btn.pedal.gas { border-color: rgba(232, 178, 58, .5); }

/* ---------- countdown ---------- */
#countdown {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(90px, 22vw, 190px);
  letter-spacing: .02em;
  color: var(--cream);
  text-shadow: 0 6px 40px rgba(0, 0, 0, .6), 0 0 2px rgba(0, 0, 0, .8);
  background: radial-gradient(ellipse at 50% 50%, rgba(3, 6, 8, .24), transparent 62%);
}
#countdown.tick { animation: countpop .58s ease-out; }
@keyframes countpop { 0% { transform: scale(1.3); opacity: 0; } 26% { opacity: 1; } 100% { transform: scale(.92); opacity: .88; } }

/* ---------- results ---------- */
#results {
  z-index: 30;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 40%, rgba(6, 10, 13, .55), rgba(4, 6, 8, .85));
  backdrop-filter: blur(4px);
}
.results-card {
  width: min(560px, 100%);
  padding: clamp(24px, 4vw, 40px);
  background: linear-gradient(160deg, rgba(20, 28, 33, .92), rgba(8, 12, 15, .9));
  border: 1px solid var(--brass-dim);
  border-top: 2px solid var(--brass);
  border-radius: 2px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
}
.results-card h2 {
  margin: 9px 0 4px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(38px, 7vw, 62px);
  line-height: .95;
  text-transform: uppercase;
}
.result-sub { margin: 0 0 22px; color: var(--cream-dim); font-size: 14px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 0 24px; }
.result-grid > div { border-top: 1px solid var(--line); padding-top: 9px; }
.result-grid span { display: block; font-size: 8px; letter-spacing: .2em; color: rgba(243, 233, 214, .5); margin-bottom: 5px; }
.result-grid b { font-family: var(--mono); font-size: clamp(17px, 3.2vw, 23px); font-weight: 400; color: var(--cream); }

/* ---------- shop ---------- */
#shop {
  z-index: 35;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 7, 9, .76);
  backdrop-filter: blur(7px) saturate(.6);
  -webkit-backdrop-filter: blur(7px) saturate(.6);
}
.shop-panel {
  width: min(1140px, 100%);
  height: min(88dvh, 790px);
  display: grid;
  grid-template-rows: auto 1fr;
  background: #0d1316;
  border: 1px solid var(--brass-dim);
  border-top: 2px solid var(--brass);
  box-shadow: 0 34px 100px rgba(0, 0, 0, .68);
  overflow: hidden;
}
.shop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 32, 37, .9), rgba(12, 18, 22, .9));
}
.shop-head h2 { margin: 5px 0 0; font-family: var(--display); font-weight: 400; font-size: clamp(22px, 3vw, 32px); line-height: 1; text-transform: uppercase; }
.shop-head-right { display: flex; align-items: center; gap: 14px; }
.car-no { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--brass); border: 1px solid var(--brass-dim); padding: 5px 8px; }
.shop-body { display: grid; grid-template-columns: 1.28fr .72fr; min-height: 0; }
.shop-stage { position: relative; background: #080c0e; min-height: 0; overflow: hidden; }
#shop-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.stage-caption {
  position: absolute; left: 13px; bottom: 11px; right: 13px;
  display: flex; align-items: center; gap: 7px;
  font-size: 8px; letter-spacing: .13em; color: rgba(243, 233, 214, .52);
  text-transform: uppercase; pointer-events: none;
}
.stage-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 9px var(--brass); flex: none; }
.shop-tools {
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #11181c, #0b1013);
  overflow-y: auto;
  padding: 14px 15px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 178, 58, .35) transparent;
  touch-action: pan-y;
}
.shop-tools::-webkit-scrollbar { width: 6px; }
.shop-tools::-webkit-scrollbar-thumb { background: rgba(232, 178, 58, .3); border-radius: 3px; }
.shop-section { padding: 4px 0 16px; border-bottom: 1px solid rgba(243, 233, 214, .09); margin-bottom: 13px; }
.shop-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.section-head h3 { margin: 0; font-family: var(--text); font-size: 10px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--cream); }
.section-head span { font-size: 8px; letter-spacing: .13em; color: rgba(243, 233, 214, .52); text-align: right; }
.swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.swatch {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid rgba(243, 233, 214, .14);
  background: rgba(243, 233, 214, .03);
  padding: 6px 7px;
  border-radius: 2px;
  text-align: left;
  transition: border-color .14s ease, background .14s ease;
}
.swatch:hover { border-color: rgba(243, 233, 214, .45); }
.swatch.selected { border-color: var(--brass); background: rgba(232, 178, 58, .1); }
.swatch i {
  width: 22px; height: 22px; flex: none; border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, .4);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.swatch span { font-size: 9px; line-height: 1.15; letter-spacing: .07em; text-transform: uppercase; color: rgba(243, 233, 214, .82); }
.decals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.decal-btn {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid rgba(243, 233, 214, .16);
  background: #e7dece;
  border-radius: 2px;
  padding: 5px;
  overflow: hidden;
  transition: border-color .14s ease, transform .12s ease;
}
.decals { }
.decal-btn img { width: 100%; height: 100%; object-fit: contain; display: block; }
.decals .decal-btn.selected { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; transform: translateY(-1px); }
.decal-btn .decal-tag {
  position: absolute; left: 3px; right: 3px; bottom: 2px;
  font-size: 6px; letter-spacing: .08em; text-align: center;
  color: #1a1714; text-transform: uppercase; font-weight: 700;
  background: rgba(231, 222, 206, .8); padding: 1px 0;
}
.slot-row { display: flex; gap: 6px; margin-bottom: 11px; }
.slot-btn {
  flex: 1;
  border: 1px solid rgba(243, 233, 214, .18);
  background: rgba(243, 233, 214, .04);
  padding: 7px 6px;
  font-size: 8px; font-weight: 700; letter-spacing: .16em;
  text-transform: uppercase;
  border-radius: 2px;
}
.slot-btn.active { border-color: var(--brass); color: var(--brass); background: rgba(232, 178, 58, .08); }
.slot-btn.clear { flex: .8; color: rgba(243, 233, 214, .55); }
.range-row { display: grid; grid-template-columns: 46px 1fr 34px; align-items: center; gap: 8px; margin: 8px 0; }
.range-row span { font-size: 8px; letter-spacing: .16em; color: rgba(243, 233, 214, .55); }
.range-row b { font-family: var(--mono); font-size: 9px; font-weight: 400; color: var(--brass); text-align: right; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: rgba(243, 233, 214, .2);
  outline: none;
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--cream); border: 1px solid var(--brass);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--cream); border: 1px solid var(--brass);
  cursor: pointer;
}

/* ---------- help ---------- */
#help {
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 7, 9, .78);
  backdrop-filter: blur(6px);
}
.help-card {
  width: min(760px, 100%);
  padding: clamp(22px, 4vw, 36px);
  background: linear-gradient(160deg, rgba(20, 28, 33, .95), rgba(8, 12, 15, .94));
  border: 1px solid var(--brass-dim);
  border-top: 2px solid var(--brass);
}
.help-card h2 { margin: 8px 0 20px; font-family: var(--display); font-weight: 400; font-size: clamp(28px, 5vw, 44px); line-height: .95; text-transform: uppercase; }
.help-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 24px; }
.help-cols h3 { margin: 0 0 6px; font-size: 9px; letter-spacing: .2em; color: var(--brass); }
.help-cols p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--cream-dim); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 50;
  padding: 9px 15px;
  background: rgba(12, 18, 22, .92);
  border: 1px solid var(--brass-dim);
  color: var(--cream);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  border-radius: 2px;
  pointer-events: none;
  transition: opacity .3s ease;
}

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls {
    display: flex;
    position: absolute;
    left: 0; right: 0; bottom: 0;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom));
    pointer-events: none;
  }
  .touch-controls > * { pointer-events: auto; }
  .gauge-wrap {
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: 112px;
  }
  .gear-read { display: none; }
  .timing {
    top: max(12px, env(safe-area-inset-top));
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 124px;
    padding: 6px 9px;
  }
  .timing-row { padding: 3px 0; }
  .timing-row b { font-size: 14px; }
  .timing-row span { font-size: 7px; }
  .race-hint { display: none; }
  .minimap { width: 104px; padding: 6px 7px 5px; }
  .map-labels { display: none; }
  .map-foot { font-size: 6px; letter-spacing: .08em; }
  .map-head { font-size: 7px; }
  .brand-small .brand-mark { width: 32px; }
  .brand-small .brand-name, .brand-small .eyebrow { display: none; }
  .top-actions { top: max(52px, calc(env(safe-area-inset-top) + 46px)); }
  .icon-btn { padding: 7px 9px; font-size: 8px; }
  .start-card .lede { font-size: 13px; }
  .shop-panel { height: 94dvh; width: 100%; }
  .shop-body { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 40dvh) 1fr; }
  .shop-tools { border-left: none; border-top: 1px solid var(--line); }
  .shop-head { padding: 10px 13px; }
  .shop-head h2 { font-size: 22px; }
  .swatches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .swatch { flex-direction: row; align-items: center; gap: 7px; padding: 6px; }
  .swatch i { width: 24px; height: 24px; }
  .swatch span { font-size: 8px; letter-spacing: .04em; }
  .decals { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .decal-btn .decal-tag { font-size: 5px; }
  .shop-tools { padding: 11px 12px 18px; }
  .help-cols { grid-template-columns: 1fr; gap: 14px; }
}

@media (max-width: 760px) {
  #start { padding: 12px; background: linear-gradient(0deg, rgba(3, 6, 8, .82) 0%, rgba(3, 6, 8, .3) 55%, transparent 85%); }
  .start-card { width: 100%; padding: 18px; }
  .start-card h2 { font-size: clamp(26px, 7vw, 38px); }
  .start-card .lede { margin-bottom: 15px; }
  .start-credit { display: none; }
  .result-grid { gap: 8px; }
  .help-card { padding: 20px; }
  .shop-panel { height: 95dvh; }
  .shop-stage { min-height: 210px; }
  .stage-caption { font-size: 7px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .start-card { max-width: 410px; padding: 15px 18px; }
  .start-card h2 { font-size: 28px; margin-bottom: 4px; }
  .start-card .lede { display: none; }
  .brand { margin-bottom: 10px; }
  .hint { margin-top: 10px; }
  .brand-small .eyebrow { display: none; }
  .shop-panel { height: 96dvh; }
  .shop-body { grid-template-columns: 1.1fr .9fr; grid-template-rows: 1fr; }
  .shop-tools { border-left: 1px solid var(--line); border-top: none; }
  .shop-stage { min-height: 0; }
}

/* ---------- chart-paper interface over the realistic island ---------- */
:root {
  --paper: #f3e9d6;
  --paper-dim: #e4d8c2;
  --paper-shadow: rgba(20, 16, 10, .28);
  --chart-ink: #1a1714;
  --chart-red: #a83224;
  --chart-green: #215b42;
}

#loader {
  background: radial-gradient(ellipse at 50% 38%, #fbf4e4 0%, #f0e4cd 54%, #e4d5ba 100%);
  color: var(--chart-ink);
}
#loader .loader-card h1 { color: var(--chart-ink); }
#loader .eyebrow { color: var(--chart-red); }
#loader .loadtext { color: rgba(26, 23, 20, .62); }
#loader .loadbar { background: rgba(26, 23, 20, .16); }
#loader .loadbar i { background: var(--chart-ink); }
#loader .brand-mark { background: #fbf4e4; }

.start-card,
.results-card,
.help-card {
  background: linear-gradient(165deg, #f8efdf 0%, #f1e6d2 58%, #e8dbc2 100%);
  border: 1px solid rgba(26, 23, 20, .5);
  border-top: 3px solid var(--chart-ink);
  color: var(--chart-ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .42), inset 0 0 0 3px rgba(232, 178, 58, .22);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.start-card .eyebrow,
.results-card .eyebrow,
.help-card .eyebrow { color: var(--chart-green); }
.start-card .brand-name,
.start-card h2,
.results-card h2,
.help-card h2 { color: var(--chart-ink); }
.start-card .lede,
.results-card .result-sub,
.help-card p { color: rgba(26, 23, 20, .72); }
.start-card .hint { color: rgba(26, 23, 20, .58); }
.start-card .brand-mark { background: #fbf4e4; }
.start-credit { color: var(--paper); text-shadow: 0 1px 6px rgba(0,0,0,.65); }
.btn {
  background: rgba(243, 233, 214, .65);
  border-color: rgba(26, 23, 20, .55);
  color: var(--chart-ink);
}
.btn:hover { background: var(--paper); border-color: var(--chart-ink); }
.btn.primary {
  background: var(--chart-ink);
  border-color: var(--chart-ink);
  color: var(--paper);
}
.btn.primary:hover { background: var(--chart-red); border-color: var(--chart-red); color: var(--paper); }

.brand-small {
  background: rgba(243, 233, 214, .92);
  border: 1px solid rgba(26, 23, 20, .55);
  border-top: 2px solid var(--chart-ink);
  padding: 5px 10px 5px 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}
.brand-small .brand-name { color: var(--chart-ink); }
.brand-small .eyebrow { color: var(--chart-green); }
.top-actions .icon-btn,
.icon-btn {
  background: rgba(243, 233, 214, .92);
  border-color: rgba(26, 23, 20, .5);
  color: var(--chart-ink);
}
.icon-btn:hover { border-color: var(--chart-red); color: var(--chart-red); }

#hud .panel {
  background: rgba(243, 233, 214, .94);
  border: 1px solid rgba(26, 23, 20, .55);
  border-top: 2px solid var(--chart-ink);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
  backdrop-filter: blur(4px) saturate(.9);
  -webkit-backdrop-filter: blur(4px) saturate(.9);
}
#hud .map-head { color: var(--chart-ink); }
#hud .map-live { color: var(--chart-red); }
#hud .map-live::before { background: var(--chart-red); }
#pr-map { background: #123e5c; border: 1px solid var(--chart-ink); }
#pr-land path { fill: var(--paper); stroke: var(--chart-ink); stroke-width: .6; }
.map-route { stroke: #e8b23a; stroke-width: .9; stroke-dasharray: 2 2.2; opacity: .95; }
.map-labels text { fill: rgba(243, 233, 214, .8); }
.map-dot { fill: var(--chart-red); stroke: var(--paper); }
.map-pulse { stroke: var(--chart-red); }
.map-foot { color: rgba(26, 23, 20, .68); border-top-color: rgba(26, 23, 20, .18); }
#map-place { color: var(--chart-red); }
.timing-row { border-bottom-color: rgba(26, 23, 20, .16); }
.timing-row span { color: rgba(26, 23, 20, .56); }
.timing-row b { color: var(--chart-ink); }
.timing-row b em { color: rgba(26, 23, 20, .48); }
#pos-read { color: var(--chart-red); }

.gauge-label { fill: rgba(26, 23, 20, .68); }
.gauge-label.small { fill: var(--chart-green); }
.gauge-digital { fill: var(--chart-ink); }
#gauge-ticks line { stroke: rgba(26, 23, 20, .55); }
#gauge-ticks line.major { stroke: rgba(26, 23, 20, .92); }
#gauge-ticks text { fill: rgba(26, 23, 20, .8); }
.gear-read { color: rgba(26, 23, 20, .62); text-shadow: 0 1px 4px rgba(243, 233, 214, .8); }
.gear-read b { color: var(--chart-ink); border-color: rgba(26, 23, 20, .4); }
.race-hint { color: var(--chart-ink); background: rgba(243, 233, 214, .84); border: 1px solid rgba(26, 23, 20, .3); padding: 3px 9px; }

.touch-btn {
  background: rgba(243, 233, 214, .9);
  border-color: rgba(26, 23, 20, .55);
  color: var(--chart-ink);
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
.touch-btn.pressed { background: var(--chart-ink); border-color: var(--chart-ink); color: var(--paper); }
.touch-btn.pedal.gas { border-color: var(--chart-green); }

#countdown {
  color: var(--chart-ink);
  text-shadow: 0 2px 0 rgba(243,233,214,.92), 0 0 28px rgba(243,233,214,.95), 0 6px 34px rgba(0,0,0,.4);
}

#results { background: radial-gradient(ellipse at 50% 40%, rgba(6, 10, 13, .45), rgba(4, 6, 8, .82)); }
.result-grid > div { border-top-color: rgba(26, 23, 20, .25); }
.result-grid span { color: rgba(26, 23, 20, .58); }
.result-grid b { color: var(--chart-ink); }

#shop { background: rgba(4, 7, 9, .74); }
.shop-panel {
  background: var(--paper);
  border: 1px solid rgba(26, 23, 20, .6);
  border-top: 3px solid var(--chart-ink);
  box-shadow: 0 34px 100px rgba(0, 0, 0, .6), inset 0 0 0 3px rgba(232, 178, 58, .18);
}
.shop-head {
  background: linear-gradient(180deg, #f8efdf, #efe3cc);
  border-bottom-color: rgba(26, 23, 20, .25);
}
.shop-head .eyebrow { color: var(--chart-green); }
.shop-head h2 { color: var(--chart-ink); }
.car-no { color: var(--chart-ink); border-color: rgba(26, 23, 20, .45); }
.shop-tools {
  background: linear-gradient(180deg, #f7eedc, #eee2ca);
  border-left-color: rgba(26, 23, 20, .25);
  scrollbar-color: rgba(26, 23, 20, .3) transparent;
}
.shop-tools::-webkit-scrollbar-thumb { background: rgba(26, 23, 20, .28); }
.shop-section { border-bottom-color: rgba(26, 23, 20, .18); }
.section-head h3 { color: var(--chart-ink); }
.section-head span { color: rgba(26, 23, 20, .58); }
.swatch {
  background: rgba(255, 251, 243, .4);
  border-color: rgba(26, 23, 20, .22);
}
.swatch:hover { border-color: rgba(26, 23, 20, .6); }
.swatch.selected { border-color: var(--chart-ink); background: rgba(232, 178, 58, .22); }
.swatch span { color: var(--chart-ink); }
.decal-btn { border-color: rgba(26, 23, 20, .35); }
.slot-btn {
  background: rgba(255, 251, 243, .45);
  border-color: rgba(26, 23, 20, .28);
  color: var(--chart-ink);
}
.slot-btn.active { border-color: var(--chart-ink); color: var(--chart-red); background: rgba(232, 178, 58, .2); }
.slot-btn.clear { color: rgba(26, 23, 20, .55); }
.range-row span { color: rgba(26, 23, 20, .6); }
.range-row b { color: var(--chart-red); }
input[type="range"] { background: rgba(26, 23, 20, .22); }
input[type="range"]::-webkit-slider-thumb { background: var(--chart-ink); border-color: var(--chart-ink); }
input[type="range"]::-moz-range-thumb { background: var(--chart-ink); border-color: var(--chart-ink); }
.shop-panel .btn.primary { background: var(--chart-ink); color: var(--paper); border-color: var(--chart-ink); }

#help { background: rgba(4, 7, 9, .74); }
.help-card { background: linear-gradient(165deg, #f8efdf, #e8dbc2); color: var(--chart-ink); }
.help-cols h3 { color: var(--chart-green); }
.help-cols p { color: rgba(26, 23, 20, .72); }

.toast {
  background: rgba(243, 233, 214, .96);
  border-color: rgba(26, 23, 20, .5);
  color: var(--chart-ink);
}

.island-strip { padding-top: 2px; }
.island-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.island-photos figure {
  margin: 0;
  border: 1px solid rgba(26, 23, 20, .4);
  background: #fbf4e4;
  padding: 3px;
}
.island-photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.island-photos figcaption {
  padding: 3px 1px 1px;
  font-family: var(--text);
  font-size: 6px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--chart-ink);
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
