:root {
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --stage: #999999;
  --ink: #999999;
  --link: #cccccc;
  --chrome: linear-gradient(180deg, #ffffff 0%, #e6e9ee 22%, #8a93a1 46%, #3c4350 50%, #dfe4ea 54%, #b4bcc7 76%, #ffffff 100%);
  --shine: linear-gradient(110deg, transparent 40%, rgba(255, 255, 255, 0.95) 50%, transparent 60%);
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000000;
  color: var(--ink);
  font: 13px/1.4 var(--sans);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

#screen {
  position: relative;
  overflow: hidden;
  background: #000000;
  flex: none;
}

[data-mode="remastered"] #screen[data-screen="game"] {
  background: var(--stage);
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 800px;
  height: 600px;
  overflow: hidden;
  transform-origin: 0 0;
}

.layer {
  position: absolute;
  inset: 0;
}

.layer[hidden] {
  display: none;
}

#title {
  background: #000000;
}

#game {
  background: var(--stage);
}

#skids {
  width: 800px;
  height: 600px;
  pointer-events: none;
}

.obj {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.art {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  max-width: none;
  user-select: none;
  pointer-events: none;
}

svg.art {
  overflow: visible;
}

svg.art text {
  white-space: pre;
}

[data-mode="remastered"] svg.art text {
  font-family: var(--sans) !important;
}

[data-mode="remastered"] .classic-only,
[data-mode="classic"] .native-only {
  display: none;
}

.button .state {
  display: none;
}

.button[data-state="up"] .state[data-state="up"],
.button[data-state="over"] .state[data-state="over"],
.button[data-state="down"] .state[data-state="down"] {
  display: block;
}

.button .hit {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.chrome {
  font-family: var(--sans);
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: transparent;
  background: var(--shine), var(--chrome);
  background-size: 300% 100%, 100% 100%;
  background-position: 120% 0, 0 0;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(1px 0 0 #1b2230) drop-shadow(-1px 0 0 #1b2230) drop-shadow(0 1px 0 #1b2230) drop-shadow(0 -1px 0 #1b2230);
  animation: shine 3.2s ease-in-out infinite;
}

@keyframes shine {
  0%, 55% { background-position: 120% 0, 0 0; }
  100% { background-position: -20% 0, 0 0; }
}

#stamp {
  position: absolute;
  left: 400px;
  top: 300px;
  width: 0;
  height: 0;
  pointer-events: none;
  display: none;
}

[data-mode="remastered"] #stamp {
  display: block;
}

#stamp .chrome {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%) rotate(-8deg);
  font-size: 76px;
  line-height: 1;
  padding: 0 12px;
  white-space: nowrap;
  filter: drop-shadow(2px 0 0 #0d1320) drop-shadow(-2px 0 0 #0d1320) drop-shadow(0 2px 0 #0d1320) drop-shadow(0 -2px 0 #0d1320) drop-shadow(0 4px 0 #000000) drop-shadow(0 0 14px rgba(70, 150, 255, 0.85));
}

#stamp .burst {
  position: absolute;
  left: 262px;
  top: -112px;
  z-index: 1;
  width: 104px;
  height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, #fff35c 0%, #ffd400 55%, #ff8a00 100%);
  clip-path: polygon(50% 0%, 59% 16%, 75% 7%, 75% 25%, 93% 25%, 84% 41%, 100% 50%, 84% 59%, 93% 75%, 75% 75%, 75% 93%, 59% 84%, 50% 100%, 41% 84%, 25% 93%, 25% 75%, 7% 75%, 16% 59%, 0% 50%, 16% 41%, 7% 25%, 25% 25%, 25% 7%, 41% 16%);
  color: #d0021b;
  font: italic 900 22px/1.05 var(--sans);
  transform: rotate(14deg);
  animation: throb 0.9s ease-in-out infinite alternate;
}

@keyframes throb {
  from { transform: rotate(14deg) scale(0.94); }
  to { transform: rotate(14deg) scale(1.06); }
}

#stamp .ribbon {
  position: absolute;
  left: 0;
  top: 52px;
  transform: translate(-50%, 0) rotate(-8deg);
  padding: 3px 18px;
  white-space: nowrap;
  background: linear-gradient(180deg, #ff3b3b, #a00000);
  color: #ffffff;
  font: italic 700 16px/1.2 var(--sans);
  letter-spacing: 0.08em;
  box-shadow: 0 3px 0 #000000;
}

#stamp.pop .chrome {
  animation: pop 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) both, shine 3.2s ease-in-out 0.7s infinite;
}

#stamp.pop .ribbon {
  animation: pop 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) 0.15s both;
}

@keyframes pop {
  from { opacity: 0; scale: 2.4; }
  to { opacity: 1; scale: 1; }
}

#startButton {
  position: absolute;
  left: 400px;
  top: 448px;
  width: 280px;
  height: 68px;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  cursor: pointer;
  color: #e9fbff;
  font: italic 800 30px/1 var(--sans);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  text-shadow: 0 0 8px #00e5ff, 0 0 18px rgba(0, 229, 255, 0.6);
  background: linear-gradient(90deg, #00e5ff, #7a5cff 50%, #ff2bd6);
  clip-path: polygon(18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%, 0 18px);
  filter: drop-shadow(0 0 10px rgba(0, 229, 255, 0.7));
  animation: glow 1.6s ease-in-out infinite alternate;
}

#startButton span {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 0.32em;
  overflow: hidden;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #12203a, #060a14);
  clip-path: polygon(17px 0, 100% 0, 100% calc(100% - 17px), calc(100% - 17px) 100%, 0 100%, 0 17px);
}

#startButton span::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  left: -60%;
  background: linear-gradient(100deg, transparent, rgba(0, 229, 255, 0.35), transparent);
  animation: scan 2.4s ease-in-out infinite;
}

#startButton:hover span,
#startButton:focus-visible span {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #1b3460, #0a1226);
}

#startButton:active {
  transform: translate(-50%, -50%) scale(0.97);
}

#startButton:focus-visible {
  outline: none;
  filter: drop-shadow(0 0 16px rgba(255, 43, 214, 0.9));
}

@keyframes glow {
  from { filter: drop-shadow(0 0 6px rgba(0, 229, 255, 0.55)); }
  to { filter: drop-shadow(0 0 16px rgba(122, 92, 255, 0.95)); }
}

@keyframes scan {
  0%, 30% { left: -60%; }
  100% { left: 120%; }
}

.side {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--side, 0);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.4cqh;
  padding: 14cqh 1.2cqw 2cqh;
  box-sizing: border-box;
  container-type: size;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, #232a37, #10141c);
  color: #dfe8f5;
  overflow: hidden;
}

.side.left {
  left: 0;
  box-shadow: inset -3px 0 0 #8a93a1, inset -6px 0 12px rgba(0, 0, 0, 0.6);
}

.side.right {
  right: 0;
  box-shadow: inset 3px 0 0 #8a93a1, inset 6px 0 12px rgba(0, 0, 0, 0.6);
}

[data-mode="remastered"] #screen.roomy[data-screen="game"] .side {
  display: flex;
}

[data-mode="remastered"] #screen.roomy .hud {
  display: none;
}

.side .side-logo {
  position: absolute;
  top: 4cqh;
  left: 50%;
  font-size: min(15cqw, 5cqh);
  line-height: 1.1;
  white-space: nowrap;
  transform: translateX(-50%) rotate(-6deg);
}

.side .panel {
  width: 100%;
  max-width: 320px;
  box-sizing: border-box;
  padding: min(4cqw, 1.6cqh);
  border-radius: 10px;
  background: linear-gradient(180deg, #0b0f17, #161c28);
  box-shadow: inset 0 0 0 1px #4a5262, inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 0 14px rgba(0, 229, 255, 0.18);
  text-align: center;
}

.side .label {
  font: italic 800 min(7cqw, 2.4cqh)/1.2 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8fe9ff;
  margin-bottom: 0.6cqh;
}

.gauge {
  display: block;
  width: 100%;
  max-height: 34cqh;
}

.gauge .tick {
  stroke: #e8ecf0;
  stroke-width: 0.9;
}

.gauge .tick.major {
  stroke-width: 1.8;
}

.gauge .tick-label {
  fill: #f4f6f8;
  font: 600 6.6px Helvetica, Arial, var(--sans);
  text-anchor: middle;
}

.gauge .dial-unit {
  fill: #c9ced6;
  font: 600 5.5px Helvetica, Arial, var(--sans);
  text-anchor: middle;
}

.gauge .dial-badge {
  fill: #f4f6f8;
  font: italic 800 7.6px Helvetica, Arial, var(--sans);
}

.gauge .needle {
  fill: #ff4a12;
  transform-origin: 60px 60px;
  transition: transform 90ms linear;
  filter: drop-shadow(0 0 2px rgba(255, 74, 18, 0.8));
}

.gauge .hub {
  fill: #1b1c20;
  stroke: #5a6068;
  stroke-width: 1.2;
}

.side .readout {
  margin-top: -1cqh;
  font: italic 900 min(14cqw, 5cqh)/1 var(--sans);
  color: #e9fbff;
  text-shadow: 0 0 10px #00e5ff;
}

.side .readout .unit {
  margin-left: 0.3em;
  font-size: 0.4em;
  color: #8fe9ff;
}

.gear-row,
.error-row {
  display: flex;
  justify-content: center;
  gap: min(6cqw, 2cqh);
}

.gear-light {
  font: italic 900 min(18cqw, 6cqh)/1 var(--sans);
  color: #2a3242;
}

.gear-light.gear-d.on {
  color: #7dffb0;
  text-shadow: 0 0 12px #26ff7a, 0 0 24px rgba(38, 255, 122, 0.6);
}

.gear-light.gear-r.on {
  color: #ff8a8a;
  text-shadow: 0 0 12px #ff1f3d, 0 0 24px rgba(255, 31, 61, 0.6);
}

.error-light {
  width: min(11cqw, 3.6cqh);
  height: min(11cqw, 3.6cqh);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4a2a30, #1c1014);
  box-shadow: inset 0 0 0 1px #5a3a40;
}

.error-light.on {
  background: radial-gradient(circle at 35% 35%, #ffb3b3, #ff1f3d 55%, #8a0016);
  box-shadow: 0 0 12px #ff1f3d;
}

.errors.flash {
  animation: alarm 0.25s ease-in-out 4 alternate;
}

@keyframes alarm {
  to { box-shadow: inset 0 0 0 2px #ff1f3d, 0 0 22px #ff1f3d; }
}

.stages {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: stage;
  text-align: left;
  font: 600 min(6.4cqw, 2.3cqh)/1.25 var(--sans);
}

.stages li {
  counter-increment: stage;
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.3em;
  color: #6c7a90;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.stages li::before {
  content: counter(stage);
  flex: none;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8em;
  background: #1f2633;
  box-shadow: inset 0 0 0 1px #3a4458;
}

.stages li.done {
  color: #9fe7b9;
}

.stages li.done::before {
  content: "✓";
  background: #1d6b3d;
  color: #eafff1;
  box-shadow: 0 0 8px rgba(38, 255, 122, 0.5);
}

.stages li.current {
  color: #ffffff;
  background: linear-gradient(90deg, rgba(0, 229, 255, 0.22), transparent);
}

.stages li.current::before {
  background: #00b8d9;
  color: #001018;
  box-shadow: 0 0 10px #00e5ff;
  animation: pulse 0.9s ease-in-out infinite alternate;
}

@keyframes pulse {
  to { box-shadow: 0 0 2px #00e5ff; }
}

.side .badge {
  padding: 0.3em 0.7em;
  font: 700 min(5.4cqw, 1.9cqh)/1.2 "Courier New", monospace;
  color: #ffef5c;
  background: #000080;
  border: 2px outset #c0c0c0;
}

.side .badge.netscape {
  margin-top: -1.6cqh;
  max-width: 80%;
  text-align: center;
  font-size: min(4.6cqw, 1.6cqh);
  color: #ffffff;
  background: linear-gradient(180deg, #2f7d7d, #0e3f4f);
  font-style: italic;
}

.side .badge.counter {
  color: #39ff14;
  background: #000000;
  letter-spacing: 0.08em;
}

#failSign {
  position: absolute;
  left: 400px;
  top: 236px;
  transform: translate(-50%, -50%) rotate(-4deg);
  white-space: nowrap;
  pointer-events: none;
  font: italic 900 64px/1 var(--sans);
  letter-spacing: 0.04em;
  color: #ff2a2a;
  -webkit-text-stroke: 0;
  text-shadow: 0 0 2px #ffffff, 0 4px 0 #5a0000, 0 0 24px rgba(255, 40, 40, 0.8);
  animation: slam 0.45s cubic-bezier(0.2, 1.8, 0.4, 1) both, shake 0.12s linear 0.45s 6;
}

#failSign[hidden] {
  display: none;
}

@keyframes slam {
  from { opacity: 0; scale: 3; }
  to { opacity: 1; scale: 1; }
}

@keyframes shake {
  25% { translate: -4px 2px; }
  75% { translate: 4px -2px; }
}

.fire {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  display: none;
  pointer-events: none;
}

[data-mode="remastered"] .fire.on {
  display: block;
}

.fire .flame {
  position: absolute;
  bottom: 0;
  width: 22px;
  height: 34px;
  margin-left: -11px;
  border-radius: 50% 50% 45% 45% / 65% 65% 35% 35%;
  background: radial-gradient(ellipse at 50% 85%, #fffbd0 0%, #ffd23a 30%, #ff7a00 58%, rgba(255, 40, 0, 0.85) 72%, rgba(255, 0, 0, 0) 78%);
  transform-origin: 50% 100%;
  mix-blend-mode: screen;
  animation: flicker 0.16s ease-in-out infinite alternate;
}

.fire .flame-1 {
  left: -9px;
  height: 26px;
  animation-duration: 0.21s;
}

.fire .flame-2 {
  left: 9px;
  height: 28px;
  animation-duration: 0.13s;
}

.fire .flame-3 {
  height: 44px;
  width: 16px;
  margin-left: -8px;
  opacity: 0.85;
  animation-duration: 0.19s;
}

@keyframes flicker {
  from { transform: scale(0.9, 0.85) skewX(-6deg); }
  to { transform: scale(1.08, 1.12) skewX(6deg); }
}

.fire .smoke {
  position: absolute;
  bottom: 22px;
  left: -14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(60, 60, 60, 0.7), rgba(60, 60, 60, 0));
  animation: smoke 1.4s ease-out infinite;
}

@keyframes smoke {
  from { transform: translate(0, 0) scale(0.6); opacity: 0.9; }
  to { transform: translate(10px, -46px) scale(2.2); opacity: 0; }
}

#mobileHud,
#touchControls {
  display: none;
}

#screen.touch #mobileHud,
#screen.touch #touchControls {
  display: block;
}

#screen.touch .side,
#screen.touch .hud {
  display: none !important;
}

body.touch-play #credits {
  display: none;
}

#mobileHud {
  position: absolute;
  display: none;
  color: #e9fbff;
  font-family: var(--sans);
}

#screen.touch #mobileHud {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 12px;
  box-sizing: border-box;
  padding: 6px 12px;
  background: linear-gradient(180deg, #232a37, #10141c);
  box-shadow: inset 0 -2px 0 #8a93a1;
}

#screen.portrait #mobileHud {
  left: 0;
  right: 0;
  top: 0;
  height: var(--top);
}

#screen.landscape #mobileHud {
  left: 0;
  top: 0;
  width: var(--side);
  flex-direction: column;
  gap: 6px;
  box-shadow: inset -2px -2px 0 #8a93a1;
  border-bottom-right-radius: 12px;
}

#mobileHud .m-speed {
  font: italic 900 30px/1 var(--sans);
  text-shadow: 0 0 10px #00e5ff;
}

#mobileHud .m-speed .unit {
  margin-left: 4px;
  font-size: 12px;
  color: #8fe9ff;
}

#mobileHud .m-gear {
  display: flex;
  gap: 10px;
}

#mobileHud .gear-light {
  font-size: 30px;
}

#mobileHud .m-errors {
  display: flex;
  gap: 8px;
}

#mobileHud .error-light {
  width: 20px;
  height: 20px;
}

#touchControls .pad {
  position: absolute;
  display: flex;
  gap: 12px;
  box-sizing: border-box;
}

#touchControls button {
  flex: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 18px;
  font-size: 34px;
  color: #e9fbff;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #1b3460, #0a1226);
  box-shadow: inset 0 0 0 2px #00e5ff, 0 0 14px rgba(0, 229, 255, 0.45);
  text-shadow: 0 0 10px #00e5ff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#touchControls .gear-button {
  flex: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  font: italic 900 26px/1 var(--sans);
  text-shadow: none;
}

#touchControls .gear-button span {
  color: #2a3242;
}

#screen[data-gear="D"] #touchControls .gear-button .gear-d {
  color: #7dffb0;
  text-shadow: 0 0 10px #26ff7a;
}

#screen[data-gear="R"] #touchControls .gear-button .gear-r {
  color: #ff8a8a;
  text-shadow: 0 0 10px #ff1f3d;
}

#touchControls button.held {
  background: linear-gradient(180deg, #2a5bd7, #10245a);
  box-shadow: inset 0 0 0 2px #ff2bd6, 0 0 22px rgba(255, 43, 214, 0.75);
}

#screen.portrait #touchControls .steer {
  left: 12px;
  bottom: 12px;
  width: calc(50% - 18px);
  height: calc(var(--bottom) - 24px);
}

#screen.portrait #touchControls .pedals {
  right: 12px;
  bottom: 12px;
  width: calc(50% - 18px);
  height: calc(var(--bottom) - 24px);
  flex-direction: column;
}

#screen.landscape #touchControls .steer {
  left: 8px;
  bottom: 10px;
  width: calc(var(--side) - 16px);
  height: 46%;
}

#screen.landscape #touchControls .pedals {
  right: 8px;
  top: 10px;
  bottom: 10px;
  width: calc(var(--side) - 16px);
  flex-direction: column;
}

.responder {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  display: none;
  pointer-events: none;
}

.responder svg {
  position: absolute;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
}

[data-mode="remastered"] .responder.driving {
  display: block;
}

.responder .beacon {
  animation: beacon 0.36s steps(1) infinite;
}

.responder .beacon.b {
  animation-delay: 0.18s;
}

.responder .beacon.red {
  animation-name: beacon-red;
}

@keyframes beacon-red {
  0% { fill: #ffb0b0; filter: drop-shadow(0 0 6px #ff2a2a); }
  50% { fill: #6a0a0a; filter: none; }
}

@keyframes beacon {
  0% { fill: #9fd0ff; filter: drop-shadow(0 0 6px #2f7bff); }
  50% { fill: #123a8c; filter: none; }
}

#credits {
  flex: none;
  padding: 6px 16px 8px;
  text-align: center;
}

#credits p {
  margin: 2px 0;
}

#credits a {
  color: var(--link);
}

#credits .bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 16px;
  margin-bottom: 4px;
}

#credits .keys {
  color: var(--link);
}

#modeButton {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 14px 2px;
  font: inherit;
  color: var(--link);
  background: linear-gradient(180deg, #3a4252, #11151d);
  border: 1px solid #8a93a1;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 10px rgba(70, 150, 255, 0.45);
  cursor: pointer;
}

#modeButton .chrome {
  font-size: 18px;
  line-height: 1.1;
}

#modeButton .caption {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#modeButton[aria-pressed="true"] .caption.off,
#modeButton[aria-pressed="false"] .caption.on {
  display: none;
}

#modeButton[aria-pressed="false"] {
  background: #222222;
  border-color: #555555;
  box-shadow: none;
}

#modeButton[aria-pressed="false"] .chrome {
  filter: grayscale(1) brightness(0.6) drop-shadow(1px 0 0 #111111) drop-shadow(-1px 0 0 #111111);
  animation: none;
}

#fullscreenButton {
  font: inherit;
  color: var(--link);
  background: #222222;
  border: 1px solid #555555;
  border-radius: 3px;
  padding: 2px 10px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .chrome,
  #stamp .burst,
  #stamp.pop .chrome,
  #stamp.pop .ribbon,
  #startButton,
  #startButton span::after,
  .errors.flash,
  .stages li.current::before,
  #failSign {
    animation: none;
  }
}
