:root {
  color-scheme: dark;
  --ink: #111217;
  --paper: #f4f0df;
  --yellow: #f4d929;
  --red: #f04336;
  --blue: #2448d8;
  --cyan: #4ee4e2;
  --muted: #929292;
  font-family: Inter, "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  background: var(--ink);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #17191c;
}

body::after {
  content: "";
  position: fixed;
  z-index: 20;
  inset: 0;
  pointer-events: none;
  opacity: .26;
  background: repeating-linear-gradient(0deg, #fff0 0 3px, #fff1 4px);
  mix-blend-mode: overlay;
}

button { font: inherit; }

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #9bc463;
  touch-action: none;
}

.hidden { display: none !important; }

.hud {
  position: fixed;
  z-index: 5;
  pointer-events: none;
}

#topbar {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
  gap: .5rem;
  padding: max(.75rem, env(safe-area-inset-top)) .75rem 0;
}

.brand-chip,
.race-chip,
.camera-chip,
.icon-button {
  min-height: 3.25rem;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 4px 4px 0 #1118;
}

.brand-chip {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .35rem .75rem .35rem .4rem;
  transform: rotate(-.5deg);
}

.brand-chip b {
  display: grid;
  place-items: center;
  width: 2.25rem;
  aspect-ratio: 1;
  font-size: 1.05rem;
  font-weight: 1000;
  background: var(--yellow);
}

.brand-chip span {
  font-size: .63rem;
  font-weight: 950;
  line-height: .85;
  letter-spacing: -.04em;
}

.race-chip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 8.4rem;
  padding: .35rem .75rem;
  background: var(--ink);
  color: var(--paper);
}

.race-chip small,
.camera-chip small,
.icon-button {
  font-size: .55rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.race-chip strong { font: 900 1.15rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.camera-chip {
  margin-left: auto;
  min-width: 8rem;
  padding: .35rem .8rem;
  text-align: left;
  pointer-events: auto;
  cursor: pointer;
  background: var(--cyan);
}

.camera-chip strong { display: block; font-size: .88rem; font-weight: 1000; }
.camera-chip:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #1118; }

.icon-button {
  padding: 0 .75rem;
  pointer-events: auto;
  cursor: pointer;
}

#race-hud {
  left: .8rem;
  bottom: .8rem;
  display: flex;
  align-items: flex-end;
  gap: .55rem;
}

.position-block,
.lap-block,
.split-block,
.speed-block,
.meter-block {
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 #1118;
}

.position-block {
  min-width: 6.7rem;
  padding: .25rem .7rem .4rem;
  color: var(--ink);
  background: var(--yellow);
  transform: rotate(.4deg);
}

.position-block strong { font-size: 3.4rem; line-height: .8; font-style: italic; letter-spacing: -.12em; }
.position-block sup { margin-left: .08em; font-size: .7rem; letter-spacing: 0; }
.position-block span { margin-left: .55rem; font-size: .55rem; font-weight: 1000; }

.lap-block,
.split-block,
.speed-block {
  display: flex;
  flex-direction: column;
  padding: .42rem .65rem;
  color: var(--paper);
  background: var(--ink);
}

.lap-block span,
.speed-block span,
.meter-block span { font-size: .52rem; font-weight: 950; letter-spacing: .12em; }
.lap-block strong { font-size: 1.4rem; line-height: 1; }
.split-block { min-width: 8.6rem; }
.split-block strong { font: 900 .98rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.split-block small { margin-top: .3rem; color: #aaa; font: 700 .48rem/1 ui-monospace, monospace; }
.split-block small b { color: var(--cyan); font-weight: 900; }
.speed-block { align-items: flex-end; min-width: 5.1rem; }
.speed-block strong { font: italic 1000 2rem/.9 "Arial Narrow", sans-serif; }

.meter-block {
  display: grid;
  gap: .35rem;
  width: min(15rem, 24vw);
  padding: .5rem;
  color: var(--paper);
  background: #111d;
}

.meter-block > div { display: grid; grid-template-columns: 3.4rem 1fr; align-items: center; gap: .35rem; }
.meter-block i { height: .6rem; border: 1px solid #fff7; background: #000; overflow: hidden; }
.meter-block i b { display: block; width: 100%; height: 100%; background: var(--cyan); transform-origin: left; }
#drift-meter b { background: var(--yellow); }
#drift-meter.ready b { background: #ff9e2c; }
#drift-meter.super b { background: var(--red); }
#drift-meter.ultra b { background: #fff; box-shadow: 0 0 .55rem var(--yellow); }
#draft-meter b { background: var(--cyan); }
#draft-meter.locked b { background: var(--yellow); box-shadow: 0 0 .45rem #f4d929aa; }
#draft-meter.slingshot b { background: #fff; box-shadow: 0 0 .7rem var(--cyan); }
#armor-meter b { background: var(--red); }

#minimap {
  right: .8rem;
  bottom: .8rem;
  width: 190px;
  height: 150px;
  border: 2px solid var(--ink);
  background: #f4f0dfdb;
  box-shadow: 4px 4px 0 #1118;
}

#announce {
  position: fixed;
  z-index: 7;
  top: 48%;
  left: 50%;
  min-width: 12rem;
  color: var(--paper);
  font-size: clamp(3rem, 12vw, 9rem);
  font-weight: 1000;
  font-style: italic;
  line-height: .8;
  letter-spacing: -.08em;
  text-align: center;
  text-shadow: 7px 7px 0 var(--ink), -3px -3px 0 var(--ink);
  white-space: pre-line;
  transform: translate(-50%, -50%) rotate(-3deg);
  pointer-events: none;
}

#impact-flash {
  position: fixed;
  z-index: 6;
  inset: 0;
  border: 0 solid var(--red);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, border-width .16s;
}

#impact-flash.hit { border-width: 1.2rem; opacity: .8; transition: none; }

.screen {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(.7rem, 2vw, 1.5rem);
  overflow: auto;
  background:
    linear-gradient(115deg, #111e 0 50%, #1118 50%),
    repeating-linear-gradient(45deg, #f4d929 0 20px, #e9cd22 20px 40px);
}

.menu-shell {
  display: grid;
  grid-template-columns: minmax(18rem, 1.05fr) minmax(25rem, .95fr);
  width: min(72rem, 100%);
  min-height: min(42rem, calc(100vh - 3rem));
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 12px 12px 0 #0008;
}

.title-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.5rem, 4vw, 4rem);
  overflow: hidden;
  color: var(--paper);
  background: var(--blue);
}

.title-panel::after {
  content: "88";
  position: absolute;
  right: -1rem;
  bottom: -3rem;
  color: #fff0;
  font-size: 18rem;
  font-weight: 1000;
  line-height: 1;
  -webkit-text-stroke: 2px #fff2;
  transform: rotate(-9deg);
}

.kicker { margin: 0 0 1.7rem; font: 900 .62rem/1.2 ui-monospace, monospace; letter-spacing: .16em; }

h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: clamp(4rem, 8vw, 7.5rem);
  font-weight: 1000;
  font-style: italic;
  line-height: .72;
  letter-spacing: -.09em;
  text-shadow: .05em .05em 0 var(--ink);
  transform: skew(-4deg);
}

h1 em { color: var(--yellow); font-style: inherit; }
.tagline { position: relative; z-index: 1; max-width: 31rem; margin: 2rem 0; font-size: 1rem; font-weight: 750; line-height: 1.45; }

.feature-strip {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.feature-strip span { padding: .4rem .55rem; border: 1px solid #fff8; font-size: .57rem; font-weight: 950; letter-spacing: .08em; }

.controls-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .35rem;
  margin-top: 1.5rem;
}

.controls-grid div { display: flex; flex-direction: column; gap: .25rem; }
.controls-grid kbd { color: var(--yellow); font: 900 .7rem ui-monospace, monospace; }
.controls-grid span { font-size: .5rem; font-weight: 900; letter-spacing: .1em; }

.garage-panel { display: flex; flex-direction: column; min-width: 0; padding: clamp(1.1rem, 3vw, 2.3rem); color: var(--ink); }
.garage-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1.25rem; }
.garage-heading > div { display: flex; flex-direction: column; }
.garage-heading span { font-size: .55rem; font-weight: 950; letter-spacing: .12em; }
.garage-heading strong { font-size: 1.02rem; font-weight: 1000; }
.garage-heading .cash { align-items: flex-end; }
.garage-heading .cash strong { color: var(--blue); font-size: 1.45rem; }

.circuit-selector { margin: 0 0 .7rem; border: 2px solid var(--ink); background: var(--ink); color: var(--paper); }
.circuit-meta { display: flex; justify-content: space-between; padding: .36rem .5rem .25rem; color: var(--yellow); font: 900 .5rem/1 ui-monospace, monospace; letter-spacing: .12em; }
.circuit-choice { display: grid; grid-template-columns: 2.15rem 1fr 2.15rem; align-items: stretch; min-height: 3rem; border-block: 1px solid #fff4; }
.circuit-choice button { border: 0; color: var(--ink); background: var(--yellow); font-size: 1rem; font-weight: 1000; cursor: pointer; }
.circuit-choice button:hover { background: var(--cyan); }
.circuit-choice div { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: .35rem .55rem; }
.circuit-choice strong { overflow: hidden; font-size: .72rem; font-weight: 1000; letter-spacing: .025em; text-overflow: ellipsis; white-space: nowrap; }
.circuit-choice span { margin-top: .15rem; color: var(--cyan); font: 800 .48rem/1.2 ui-monospace, monospace; }
.circuit-selector p { margin: 0; padding: .38rem .5rem .42rem; color: #d1cdbc; font-size: .53rem; line-height: 1.25; }

.upgrades { display: grid; gap: .5rem; }
.upgrade { display: grid; grid-template-columns: minmax(6rem, 1fr) auto; align-items: center; gap: .8rem; min-height: 4rem; padding: .55rem .6rem .55rem .75rem; border: 2px solid var(--ink); background: #fff9; }
.upgrade-info { min-width: 0; }
.upgrade-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.upgrade-title strong { font-size: .75rem; font-weight: 1000; letter-spacing: .04em; }
.upgrade-title span { color: #555; font: 700 .55rem ui-monospace, monospace; }
.upgrade p { margin: .2rem 0 0; color: #656565; font-size: .6rem; line-height: 1.2; }
.pips { display: flex; gap: .2rem; margin-top: .35rem; }
.pips i { width: 1.05rem; height: .3rem; border: 1px solid var(--ink); background: transparent; }
.pips i.on { background: var(--blue); }
.upgrade button { min-width: 5.2rem; height: 2.6rem; border: 2px solid var(--ink); color: var(--ink); background: var(--yellow); font-size: .68rem; font-weight: 1000; cursor: pointer; box-shadow: 3px 3px 0 #111; }
.upgrade button:hover:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #111; }
.upgrade button:disabled { color: #777; background: #ccc; cursor: not-allowed; box-shadow: none; }
.garage-note { margin: .8rem 0; color: #666; font-size: .58rem; }
.garage-note strong { color: var(--blue); }

.race-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 3.8rem;
  margin-top: auto;
  padding: .7rem 1rem;
  border: 3px solid var(--ink);
  color: var(--paper);
  background: var(--red);
  box-shadow: 5px 5px 0 var(--ink);
  font-size: 1rem;
  font-weight: 1000;
  letter-spacing: .08em;
  cursor: pointer;
}

.race-button b { font-size: 2rem; line-height: 1; }
.race-button:hover { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }

.results-shell { width: min(68rem, 100%); border: 3px solid var(--ink); background: var(--paper); color: var(--ink); box-shadow: 12px 12px 0 #0008; }
.results-banner { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: .5rem 2rem; padding: 1.5rem 2rem; color: var(--paper); background: var(--blue); }
.results-banner p { grid-column: 1/-1; margin: 0; font-size: .6rem; font-weight: 950; letter-spacing: .15em; }
.results-banner h2 { margin: 0; font-size: clamp(2.2rem, 6vw, 4.8rem); font-weight: 1000; font-style: italic; line-height: .8; letter-spacing: -.06em; }
.results-banner h2 em { color: var(--yellow); font-style: inherit; }
.payout { display: flex; flex-direction: column; align-items: flex-end; }
.payout span { font-size: .55rem; font-weight: 950; letter-spacing: .12em; }
.payout strong { color: var(--yellow); font-size: 2rem; }
.results-body { display: grid; grid-template-columns: minmax(15rem, .75fr) minmax(24rem, 1.25fr); gap: 2rem; padding: 1.5rem 2rem 2rem; }
#standings { margin: 0; padding: 0; list-style: none; counter-reset: place; }
#standings li { counter-increment: place; display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .5rem; padding: .62rem .4rem; border-bottom: 1px solid #bbb; font-size: .75rem; font-weight: 850; }
#standings li::before { content: counter(place, decimal-leading-zero); color: var(--blue); font: 1000 1rem ui-monospace, monospace; }
#standings li.player { color: var(--red); background: #f0433614; }
#standings small { color: #777; font: 700 .58rem ui-monospace, monospace; }
.results-timing { min-width: 0; }
.lap-report { margin-top: 1.1rem; border: 2px solid var(--ink); background: #fff9; }
.lap-report > div { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem .55rem; color: var(--paper); background: var(--ink); }
.lap-report > div span { font-size: .55rem; font-weight: 950; letter-spacing: .1em; }
.lap-report > div strong { color: var(--yellow); font: 800 .52rem ui-monospace, monospace; }
#lap-times { margin: 0; padding: .25rem .55rem; list-style: none; }
#lap-times li { display: grid; grid-template-columns: 1fr auto 3.8rem; align-items: center; gap: .55rem; padding: .35rem 0; color: #666; font-size: .58rem; font-weight: 900; }
#lap-times li + li { border-top: 1px solid #ccc; }
#lap-times strong { color: var(--ink); font: 850 .7rem ui-monospace, monospace; }
#lap-times small { color: var(--red); font-size: .48rem; font-weight: 1000; text-align: right; }
#lap-times li.fastest strong { color: var(--blue); }
.compact { grid-template-columns: 1fr 1fr; }
.compact .upgrade { min-height: 3.4rem; }
.compact .upgrade p { display: none; }
.compact .upgrade button { min-width: 4.4rem; }

.pause-card { width: min(26rem, 90vw); padding: 2rem; border: 3px solid var(--ink); color: var(--ink); background: var(--paper); box-shadow: 10px 10px 0 #0008; }
.pause-card p { margin: 0; font-size: .6rem; font-weight: 900; letter-spacing: .14em; }
.pause-card h2 { margin: .2rem 0 2rem; color: var(--blue); font-size: 4rem; font-style: italic; line-height: 1; }

#touch-controls { position: fixed; z-index: 8; inset: 0; pointer-events: none; }
#touch-controls > div { position: absolute; bottom: max(1rem, env(safe-area-inset-bottom)); display: flex; gap: .4rem; pointer-events: auto; }
.touch-steer { left: max(1rem, env(safe-area-inset-left)); }
.touch-pedals { right: max(1rem, env(safe-area-inset-right)); }
#touch-controls button { width: 4.2rem; height: 4.2rem; border: 2px solid var(--paper); border-radius: 50%; color: var(--paper); background: #111b; font-size: .65rem; font-weight: 1000; touch-action: none; }
#touch-controls button[data-control="throttle"] { background: #2448d8d9; }
#touch-controls button[data-control="drift"] { background: #f4d929d9; color: var(--ink); }
#touch-controls button[data-control="boost"] { background: #f04336d9; }
#touch-controls button.active { transform: scale(.92); background: var(--yellow); color: var(--ink); }

noscript { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 2rem; color: white; background: #111; }

@media (max-width: 820px) {
  .screen { display: block; padding: .65rem; }
  .menu-shell { display: block; min-height: auto; }
  .title-panel { min-height: 22rem; padding: 1.6rem; }
  h1 { font-size: clamp(3.6rem, 16vw, 6rem); }
  .tagline { margin: 1.25rem 0; }
  .garage-panel { padding: 1.1rem; }
  .results-shell { margin: auto; }
  .results-banner { grid-template-columns: 1fr; }
  .payout { align-items: flex-start; }
  .results-body { grid-template-columns: 1fr; padding: 1rem; }
  .compact { grid-template-columns: 1fr; }
  #minimap { width: 130px; height: 103px; }
  #race-hud { left: .45rem; right: .45rem; display: grid; grid-template-columns: auto auto minmax(5.8rem, 1fr) auto; gap: .3rem; }
  .position-block { min-width: 5.4rem; padding-inline: .5rem; }
  .position-block strong { font-size: 2.75rem; }
  .position-block span { margin-left: .3rem; }
  .lap-block, .split-block, .speed-block { min-width: 0; padding: .38rem .45rem; }
  .lap-block strong { font-size: 1.15rem; }
  .split-block strong { font-size: .8rem; }
  .speed-block strong { font-size: 1.55rem; }
  .meter-block { display: none; }
  .split-block small { display: none; }
  .icon-button { display: none; }
  .brand-chip span { display: none; }
}

@media (max-height: 660px) and (min-width: 821px) {
  .menu-shell { min-height: calc(100vh - 1.4rem); }
  .title-panel { padding: 1.6rem 2.3rem; }
  .tagline { margin: 1rem 0; }
  .garage-panel { padding: 1rem 1.4rem; }
  .upgrade { min-height: 3.25rem; }
  .upgrade p { display: none; }
  .garage-note { display: none; }
  .circuit-selector p { display: none; }
}

@media (pointer: coarse) {
  #race-hud { bottom: 5.8rem; }
  #minimap { bottom: 5.8rem; }
}

@media (pointer: coarse) and (max-width: 520px) {
  #touch-controls button { width: 3.55rem; height: 3.55rem; font-size: .57rem; }
  #touch-controls > div { gap: .22rem; }
}

@media (max-width: 420px) {
  #touch-controls > .touch-pedals { display: grid; grid-template-columns: repeat(2, 3.55rem); }
  .touch-capable #race-hud,
  .touch-capable #minimap { bottom: 8.7rem; }
}

.touch-capable #race-hud,
.touch-capable #minimap { bottom: 5.8rem; }
