:root {
  color-scheme: dark;
  --cyan: #28f3ff;
  --cyan-soft: rgba(40, 243, 255, .24);
  --orange: #ff6932;
  --ink: #00083d;
  --panel: rgba(0, 16, 72, .78);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", sans-serif;
}

body { color: #e9feff; }
button { font: inherit; }

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 560px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 34%, #082c87 0, #00155f 42%, #00062e 100%);
  isolation: isolate;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(18px, 2.2vw, 34px) clamp(20px, 3vw, 54px);
  pointer-events: none;
}

.brand { display: flex; gap: 13px; align-items: center; }
.brand-mark {
  width: 6px;
  height: 42px;
  background: var(--cyan);
  box-shadow: 0 0 16px var(--cyan);
  transform: skewX(-16deg);
}
.brand p { margin: 0 0 3px; color: #78a8ad; font-size: 12px; letter-spacing: .28em; }
.brand h1 { margin: 0; font: 700 clamp(18px, 2vw, 28px)/1 "Arial Narrow", "Segoe UI", sans-serif; letter-spacing: .12em; }
.brand h1 span { color: var(--cyan); }
.sound-button {
  pointer-events: auto;
  color: #8ab1b6;
  border: 1px solid rgba(94, 222, 231, .28);
  background: rgba(2, 11, 17, .5);
  padding: 9px 12px;
  font-size: 9px;
  letter-spacing: .18em;
  cursor: pointer;
}

.hud {
  position: absolute;
  top: clamp(85px, 12vh, 120px);
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 165px));
  align-items: end;
  text-align: center;
  filter: drop-shadow(0 0 15px rgba(40, 243, 255, .12));
}
.hud-cell { position: relative; padding: 0 18px; }
.hud-cell + .hud-cell::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  width: 1px;
  height: 36px;
  background: linear-gradient(transparent, rgba(77, 209, 219, .45), transparent);
}
.hud span, .boost-wrap > span { display: block; color: #8dc9ce; font-size: 17px; font-weight: 700; letter-spacing: .2em; }
.hud strong { display: block; margin-top: 5px; font: 800 clamp(48px, 5vw, 74px)/.84 "Arial Narrow", "Segoe UI", sans-serif; letter-spacing: .01em; }
.hud strong small { font-size: .36em; color: #7da8ac; }
.hud em { color: var(--cyan); font-size: 15px; font-weight: 700; letter-spacing: .2em; font-style: normal; }
.pos-cell strong { color: var(--cyan); text-shadow: 0 0 14px rgba(40, 243, 255, .5); }
.pos-cell strong { font-size: clamp(74px, 8vw, 112px); font-weight: 900; line-height: .72; white-space: nowrap; }
.pos-cell strong small { display: inline-block; margin-left: 3px; font-size: .25em; line-height: 1; vertical-align: top; }
.pos-cell { transform: translateY(10px); }
.boost-wrap {
  position: absolute;
  width: 130px;
  left: 50%;
  top: 108px;
  transform: translateX(-50%);
}
.boost-track { height: 2px; margin-top: 6px; background: rgba(83, 173, 181, .2); }
.boost-track i { display: block; width: 0%; height: 100%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); transition: width .1s linear; }

.race-feed {
  position: absolute;
  left: clamp(20px, 3vw, 54px);
  bottom: 34px;
  color: #67989d;
  font: 16px/1.3 Consolas, monospace;
  letter-spacing: .14em;
  border-left: 2px solid var(--cyan);
  padding-left: 10px;
}

.reverse-alert {
  position: absolute;
  left: 50%;
  top: 27%;
  z-index: 4;
  transform: translate(-50%, -50%) scale(.84);
  padding: 22px 38px;
  color: #fff;
  border: 4px solid #ff315e;
  background: rgba(95, 0, 25, .78);
  box-shadow: 0 0 28px rgba(255, 49, 94, .68);
  font: 900 clamp(34px, 5vw, 78px)/1 Consolas, monospace;
  letter-spacing: .18em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s, transform .12s;
}
.reverse-alert.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: reverse-pulse .7s steps(2) infinite;
}
@keyframes reverse-pulse { 50% { filter: brightness(1.65); } }

.missed-alert {
  position: absolute;
  left: 50%;
  top: 29%;
  z-index: 5;
  transform: translate(-50%, -50%) scale(.9);
  min-width: 410px;
  padding: 18px 30px;
  border: 4px solid #ffe84e;
  color: #fff8b0;
  background: rgba(75, 55, 0, .86);
  box-shadow: 0 0 26px rgba(255, 232, 78, .58);
  font: 900 clamp(28px, 4vw, 58px)/1.1 "Yu Gothic UI", sans-serif;
  text-align: center;
  letter-spacing: .06em;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.missed-alert.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
  animation: reverse-pulse .8s steps(2) infinite;
}

.final-lap-alert {
  position: absolute;
  left: 50%;
  top: 45%;
  z-index: 6;
  transform: translate(-50%, -50%) scale(.84);
  color: #ffffff;
  font: 900 clamp(58px, 10vw, 132px)/1 "Arial Narrow", "Yu Gothic UI", sans-serif;
  letter-spacing: .08em;
  white-space: nowrap;
  text-shadow: 0 0 14px #28f3ff, 0 0 38px rgba(40, 243, 255, .78);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.final-lap-alert.visible {
  visibility: visible;
  animation: final-lap-show 2.2s ease both;
}
@keyframes final-lap-show {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.24); }
  16%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.94); }
}

.retire-button {
  position: absolute;
  left: clamp(20px, 3vw, 54px);
  top: 118px;
  z-index: 4;
  width: 150px;
  height: 56px;
  border: 2px solid rgba(186, 255, 255, .72);
  border-radius: 0;
  color: #d9ffff;
  background: rgba(3, 21, 48, .88);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .12em;
  opacity: 0;
  visibility: hidden;
  cursor: pointer;
}
.retire-button.visible { opacity: 1; visibility: visible; }
.retire-button:hover { background: rgba(16, 57, 81, .96); }

.minimap-panel {
  position: absolute;
  right: clamp(14px, 2vw, 32px);
  top: 22px;
  width: min(33vw, 500px);
  text-align: right;
}
#minimap { width: 100%; height: auto; display: block; opacity: .98; }
.minimap-panel span { color: #a4e8ed; font: 16px Consolas, monospace; letter-spacing: .2em; }

.controls {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  gap: 32px;
  color: #6d999e;
  font-size: 21px;
}
.controls div { display: flex; align-items: center; gap: 6px; }
kbd {
  display: inline-grid;
  min-width: 54px;
  height: 48px;
  padding: 0 14px;
  place-items: center;
  color: #dcffff;
  border: 1px solid rgba(84, 221, 232, .42);
  border-bottom-color: rgba(84, 221, 232, .74);
  background: rgba(7, 28, 35, .8);
  box-shadow: inset 0 -2px rgba(20, 84, 91, .35);
  font: 16px Consolas, monospace;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 48%, rgba(0, 31, 116, .2), rgba(0, 4, 35, .82));
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s ease, visibility .45s;
  z-index: 5;
}
.overlay.visible { opacity: 1; visibility: visible; }
.overlay-grid {
  position: absolute;
  inset: 50% 0 0;
  background-image: linear-gradient(rgba(40, 243, 255, .08) 1px, transparent 1px), linear-gradient(90deg, rgba(40, 243, 255, .08) 1px, transparent 1px);
  background-size: 55px 32px;
  transform: perspective(400px) rotateX(62deg) scale(1.4);
  transform-origin: 50% 0;
  mask-image: linear-gradient(to bottom, transparent, black 25%, black);
}
.start-card, .finish-card {
  position: relative;
  width: min(640px, calc(100vw - 36px));
  padding: clamp(28px, 4vw, 54px);
  text-align: center;
  border: 1px solid rgba(64, 232, 241, .28);
  background: linear-gradient(145deg, rgba(2, 28, 91, .95), rgba(0, 8, 49, .95));
  box-shadow: 0 30px 100px #000, inset 0 0 40px rgba(40, 243, 255, .025);
  clip-path: polygon(20px 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%, 0 20px);
}
.start-card::before, .finish-card::before { content: ""; position: absolute; left: 0; top: 0; width: 110px; height: 2px; background: var(--cyan); box-shadow: 0 0 16px var(--cyan); }
.start-card-simple {
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  clip-path: none;
}
.start-card-simple::before { display: none; }
.start-card.start-card-simple #startButton {
  width: min(390px, calc(100vw - 48px));
  min-height: 104px;
  margin: 0;
  padding: 24px 42px;
  border: 2px solid #baffff;
  border-radius: 0;
  clip-path: none;
  box-shadow: 0 0 18px rgba(40, 243, 255, .24);
  font-size: 22px;
}
.demo-mode-button {
  position: absolute;
  right: clamp(22px, 3vw, 48px);
  bottom: clamp(22px, 3vw, 42px);
  min-width: 230px;
  min-height: 66px;
  padding: 14px 24px;
  border: 2px solid rgba(186, 255, 255, .82);
  border-radius: 0;
  color: #eaffff;
  background: rgba(3, 21, 48, .9);
  box-shadow: 0 0 18px rgba(40, 243, 255, .2);
  font: 900 18px/1 "Yu Gothic UI", sans-serif;
  letter-spacing: .08em;
  cursor: pointer;
}
.demo-mode-button:hover {
  color: #001418;
  background: #5af6ff;
}
.rival-speed-select,
.lap-count-select {
  display: grid;
  grid-template-columns: repeat(3, minmax(94px, 120px));
  gap: 10px;
  margin-bottom: 22px;
}
.rival-speed-select > span,
.lap-count-select > span {
  grid-column: 1 / -1;
  color: #d9fdff;
  font: 900 18px/1 "Yu Gothic UI", sans-serif;
  letter-spacing: .12em;
  text-align: center;
}
.start-card.start-card-simple .rival-speed-select button,
.start-card.start-card-simple .lap-count-select button {
  min-width: 0;
  height: 58px;
  margin: 0;
  padding: 8px 6px;
  border: 2px solid rgba(116, 220, 227, .72);
  border-radius: 0;
  clip-path: none;
  box-shadow: none;
  color: #b9dfe2;
  background: rgba(0, 20, 25, .92);
  font: 900 19px/1 "Yu Gothic UI", sans-serif;
  cursor: pointer;
}
.start-card.start-card-simple .rival-speed-select button small,
.start-card.start-card-simple .lap-count-select button small {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  letter-spacing: .03em;
}
.start-card.start-card-simple .rival-speed-select button:hover,
.start-card.start-card-simple .rival-speed-select button.selected,
.start-card.start-card-simple .lap-count-select button:hover,
.start-card.start-card-simple .lap-count-select button.selected {
  border-color: #ffffff;
  color: #001418;
  background: #5af6ff;
  box-shadow: 0 0 18px rgba(58, 243, 255, .5);
}
.eyebrow { margin: 0 0 17px; color: var(--cyan); font: 10px Consolas, monospace; letter-spacing: .32em; }
.start-card h2 { margin: 0; font: 300 clamp(36px, 6vw, 72px)/.98 "Arial Narrow", "Yu Gothic UI", sans-serif; letter-spacing: .04em; }
.start-card h2 span { color: transparent; -webkit-text-stroke: 1px rgba(172, 252, 255, .75); }
.lead { width: min(530px, 100%); margin: 22px auto; color: #a9d3d7; font-size: 17px; line-height: 1.8; }
.start-controls { display: flex; justify-content: center; gap: 28px; margin: 25px 0; }
.start-controls > div { display: flex; align-items: center; justify-content: center; gap: 8px; color: #a5d1d5; font-size: 16px; }
.start-card button, .finish-card button {
  min-width: 240px;
  margin-top: 6px;
  padding: 16px 25px;
  border: 0;
  color: #001014;
  background: var(--cyan);
  box-shadow: 0 0 28px rgba(40, 243, 255, .27);
  font-weight: 800;
  letter-spacing: .18em;
  cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}
.start-card button:hover, .finish-card button:hover { filter: brightness(1.14); }
.start-card button span, .finish-card button span { margin-left: 16px; }
.finish-card #restartButton {
  width: min(320px, calc(100vw - 72px));
  min-height: 82px;
  border: 2px solid #baffff;
  border-radius: 0;
  clip-path: none;
  box-shadow: 0 0 16px rgba(40, 243, 255, .22);
  font-size: 20px;
}
.finish-card.finish-card-simple {
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  clip-path: none;
}
.finish-card.finish-card-simple::before { display: none; }
.finish-card.finish-card-simple .finish-rank {
  margin: 0 0 24px;
  color: #ffffff;
  font: 900 clamp(64px, 11vw, 132px)/1 "Yu Gothic UI", sans-serif;
  letter-spacing: 0;
  text-shadow: none;
}
.finish-actions {
  display: grid;
  justify-items: center;
  gap: 12px;
}
.finish-card #returnToStartButton {
  width: min(320px, calc(100vw - 72px));
  min-height: 68px;
  margin-top: 0;
  border: 2px solid rgba(186, 255, 255, .72);
  border-radius: 0;
  color: #d8ffff;
  background: rgba(0, 20, 25, .9);
  box-shadow: none;
  clip-path: none;
  font-size: 17px;
  letter-spacing: .04em;
}
.tip { margin: 19px 0 0; color: #76a8ad; font-size: 14px; letter-spacing: .06em; }

.finish-card { width: min(500px, calc(100vw - 36px)); }
.finish-rank { color: var(--cyan); font: 200 clamp(90px, 16vw, 160px)/.8 "Arial Narrow", sans-serif; text-shadow: 0 0 35px rgba(40, 243, 255, .4); }
.finish-rank sup { font-size: .18em; vertical-align: top; }
.finish-card h2 { margin: 26px 0; font-size: 16px; letter-spacing: .22em; }
.result-row { display: flex; justify-content: space-between; padding: 14px 0; border-top: 1px solid rgba(69, 198, 207, .2); color: #759ca0; font: 10px Consolas, monospace; letter-spacing: .18em; }
.result-row strong { color: #d9feff; }

.countdown {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  color: var(--cyan);
  font: 200 min(28vw, 260px)/1 "Arial Narrow", sans-serif;
  text-shadow: 0 0 55px rgba(40, 243, 255, .6);
  opacity: 0;
  pointer-events: none;
}
.countdown.show { animation: count .75s ease both; }
@keyframes count { 0% { opacity: 0; transform: scale(1.35); } 20% { opacity: 1; } 100% { opacity: 0; transform: scale(.82); } }

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  opacity: .16;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(81, 154, 255, .08) 4px);
  mix-blend-mode: screen;
}

@media (max-width: 700px) {
  .game-shell { min-height: 500px; }
  .topbar { padding: 16px; }
  .brand p { display: none; }
  .brand-mark { height: 30px; }
  .hud { top: 72px; left: 50%; grid-template-columns: repeat(3, minmax(82px, 102px)); }
  .hud-cell { padding: 0 7px; }
  .boost-wrap { top: 62px; }
  .controls { bottom: 16px; gap: 12px; }
  .controls span { display: none; }
  .race-feed { left: 15px; bottom: 58px; font-size: 8px; }
  .retire-button { left: 14px; top: 104px; width: 124px; height: 48px; font-size: 14px; }
  .missed-alert { min-width: calc(100vw - 32px); padding: 14px 18px; font-size: 26px; }
  .minimap-panel { top: 70px; right: 10px; width: min(62vw, 360px); transform: none; }
  .start-card:not(.start-card-simple) { padding: 28px 20px; }
  .start-controls { gap: 12px; flex-wrap: wrap; }
  .start-controls > div { width: calc(50% - 8px); }
  .rival-speed-select, .lap-count-select { grid-template-columns: repeat(3, minmax(72px, 1fr)); width: min(88vw, 360px); }
  .demo-mode-button { right: 14px; bottom: 14px; min-width: 190px; min-height: 56px; font-size: 16px; }
  .tip { display: none; }
}
