:root {
  color-scheme: dark;
  background: #000;
}

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

body {
  display: flex;
}

/* Play area + optional touch bar share the viewport. */
#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #000;
}

#play {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game:fullscreen {
  width: 100vw;
  height: 100vh;
}

#status,
#help {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #9fc3d6;
  background: rgba(0, 0, 0, 0.62);
  padding: 4px 8px;
  border-radius: 3px;
  text-shadow: 0 1px 0 #000;
  max-width: calc(100% - 16px);
  box-sizing: border-box;
}

#status {
  left: 8px;
  bottom: 8px;
  white-space: normal;
}

#help {
  right: 8px;
  bottom: 8px;
  color: #7f9aaa;
  white-space: nowrap;
}

#touch-controls {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px calc(12px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: linear-gradient(#0a1015, #04070a);
  border-top: 1px solid #1c2a33;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body.touch.touch-ready #touch-controls {
  display: flex;
}

body.touch #help {
  display: none;
}

body.touch #status {
  bottom: 4px;
  font-size: 10px;
  opacity: 0.85;
}

.touch-pad {
  display: flex;
  align-items: center;
  gap: 10px;
}

.touch-pad:last-child {
  margin-left: auto;
}

.touch-button {
  width: 76px;
  height: 64px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid #2a4654;
  background: linear-gradient(#182833, #0d161d);
  color: #cfe9f5;
  font: 700 15px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 0 #000;
}

.touch-button.gas {
  border-color: #2b6b3b;
  color: #b9f5c6;
  background: linear-gradient(#14301e, #09170e);
}

.touch-button.brake {
  border-color: #6b2b2b;
  color: #f5c0c0;
  background: linear-gradient(#301414, #170909);
}

.touch-button.active {
  background: #1f6f8b;
  color: #fff;
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

.touch-button.gas.active {
  background: #2e8b4a;
}

.touch-button.brake.active {
  background: #8b2e2e;
}

/* Show the bar on coarse pointers even before the first touch event. */
@media (pointer: coarse), (hover: none) {
  body.touch-ready #touch-controls {
    display: flex;
  }

  #help {
    display: none;
  }
}

@media (max-width: 900px) {
  #help {
    display: none;
  }
}

@media (max-width: 480px) {
  .touch-button {
    width: 64px;
    height: 58px;
    font-size: 13px;
  }

  .touch-pad {
    gap: 8px;
  }
}
