* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #a8d8ff;
  font-family: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app,
#app canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 90, 40, 0.45);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.overlay.hidden,
.hidden {
  display: none;
}

#loading {
  background: #5cb03e;
}

.panel {
  max-width: 520px;
  margin: 16px;
  padding: 24px 32px;
  border-radius: 18px;
  background: #4f535b;
  border: 6px dashed #f4f4f0;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 34px;
  letter-spacing: 1px;
  color: #f5d020;
  text-shadow: 2px 2px 0 #d7312b;
}

.panel p {
  line-height: 1.45;
}

.start-panel {
  width: 680px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.control-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 22px 0;
  text-align: left;
}

.control-section {
  min-width: 0;
}

.control-section h2 {
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  color: #f5d020;
  font-size: 16px;
}

.keys {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 10px 12px;
  margin: 0;
  line-height: 1.4;
}

.keys dt,
.keys dd {
  margin: 0;
}

.control-note {
  font-size: 12px;
  color: #d7dbe0;
}

.keys .control-note {
  display: block;
}

.control-shortcuts {
  grid-column: 1 / -1;
}

.control-shortcuts .keys {
  grid-template-columns: max-content 1fr max-content 1fr;
}

kbd {
  display: inline-block;
  min-width: 26px;
  padding: 0 6px;
  margin-right: 3px;
  border-radius: 5px;
  background: #f4f4f0;
  color: #333;
  font-weight: bold;
  text-align: center;
  line-height: 22px;
  box-shadow: 0 2px 0 #999;
}

#start-button {
  margin-top: 6px;
  padding: 12px 28px;
  border: none;
  border-radius: 999px;
  background: #d7312b;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 #8f1d19;
}

#start-button:hover {
  background: #e8463f;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#title {
  position: absolute;
  top: 14px;
  left: 16px;
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(79, 83, 91, 0.85);
  border: 3px dashed #f4f4f0;
  color: #f5d020;
  font-size: 20px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #d7312b;
}

#speedometer {
  position: absolute;
  left: 16px;
  bottom: 16px;
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(79, 83, 91, 0.85);
  border: 3px solid rgba(255, 255, 255, 0.8);
  min-width: 150px;
}

#speed-value {
  font-size: 40px;
  font-weight: bold;
  color: #f5d020;
}

#speedometer .unit {
  margin-left: 6px;
  font-size: 16px;
}

#odometer {
  font-size: 13px;
  opacity: 0.85;
}

#surface {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

#minimap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

#help {
  position: absolute;
  top: 14px;
  right: 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(79, 83, 91, 0.8);
  font-size: 13px;
  line-height: 1.5;
}

.hide-help #help,
.hide-minimap #minimap {
  display: none;
}

#touch-controls {
  display: none;
}

.touch-mode .control-sections,
.touch-mode #help,
.touch-mode #title {
  display: none;
}

.touch-mode.playing #touch-controls {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

#touch-controls button {
  min-width: 56px;
  min-height: 56px;
  padding: 8px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  background: rgba(55, 59, 67, 0.85);
  color: #fff;
  font: bold 14px 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#touch-controls svg {
  display: block;
  width: 24px;
  height: 24px;
  margin: auto;
  fill: currentColor;
  pointer-events: none;
}

#touch-controls button[aria-pressed="true"],
#touch-controls button:active {
  background: #a92a25;
  border-color: #f5d020;
}

.touch-steering,
.touch-pedals,
.touch-toolbar {
  position: absolute;
  display: flex;
  gap: 8px;
}

.touch-steering {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
}

.touch-steering button {
  width: 64px;
  height: 72px;
}

.touch-pedals {
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  flex-direction: column;
}

.touch-pedals > div {
  display: flex;
  gap: 8px;
}

.touch-pedals > div button {
  width: 64px;
  height: 72px;
}

.touch-toolbar {
  left: max(12px, env(safe-area-inset-left));
  top: max(12px, env(safe-area-inset-top));
  gap: 6px;
}

#touch-controls .touch-toolbar button {
  min-width: 48px;
  min-height: 44px;
  font-size: 12px;
}

.touch-mode #speedometer {
  top: calc(max(12px, env(safe-area-inset-top)) + 54px);
  left: max(12px, env(safe-area-inset-left));
  bottom: auto;
  min-width: 0;
  padding: 4px 10px;
}

.touch-mode #speed-value {
  font-size: 26px;
}

.touch-mode #minimap {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  bottom: auto;
  width: 96px;
  height: 96px;
}

.touch-mode #surface {
  top: calc(max(12px, env(safe-area-inset-top)) + 108px);
  font-size: 14px;
}

@media (max-width: 400px) {
  .touch-mode #minimap {
    top: calc(max(12px, env(safe-area-inset-top)) + 54px);
    width: 76px;
    height: 76px;
  }
}

@media (max-width: 600px) {
  .start-panel {
    padding: 18px;
  }

  .control-sections {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  #minimap {
    width: 130px;
    height: 130px;
  }

  #help {
    display: none;
  }
}

@media (max-height: 640px) {
  .panel {
    padding: 12px 22px;
    font-size: 14px;
  }

  .panel h1 {
    font-size: 26px;
  }

  .keys {
    gap: 8px 12px;
  }
}
