:root {
  --navy: #071018;
  --panel: rgba(8, 14, 24, 0.72);
  --cyan: #3ee0ff;
  --green: #7cffb1;
  --amber: #ffb703;
  --red: #ff4d4d;
  --text: #e8f4ff;
  --muted: #9bb0c4;
  --line: rgba(62, 224, 255, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body,
#app,
#viewport,
#scene {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #071018;
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  position: relative;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

#hud .hud-actions,
#hud button,
#hud input,
#hud select,
#hud label {
  pointer-events: auto;
}

canvas#scene {
  display: block;
}

.label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.hidden {
  display: none !important;
}

.panel,
.start-card,
.help-card,
.crash-card {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.panel {
  position: absolute;
  min-width: 220px;
  padding: 12px 14px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.tl { top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); }
.tr { top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
.bl { bottom: calc(12px + env(safe-area-inset-bottom)); left: calc(12px + env(safe-area-inset-left)); }

.row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  line-height: 1.55;
}

.k {
  color: var(--muted);
  letter-spacing: 0.08em;
  font-size: 10px;
  padding-top: 3px;
}

#hud-motors[data-state="ok"],
#hud-battery[data-state="ok"] {
  color: var(--green);
}

#hud-battery[data-state="warn"],
#hud-motors[data-state="idle"] {
  color: var(--amber);
}

#hud-battery[data-state="critical"] {
  color: var(--red);
}

.top-center {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.compass-wrap {
  text-align: center;
}

.compass {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--cyan);
  display: grid;
  place-items: center;
  color: var(--cyan);
  font-size: 13px;
  background: rgba(7, 16, 24, 0.55);
}

#hud-heading {
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--cyan);
}

#hud-warning {
  min-height: 22px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.04em;
}

#hud-warning[data-level="warn"] {
  color: #1a1204;
  background: var(--amber);
}

#hud-warning[data-level="critical"] {
  color: white;
  background: var(--red);
}

.fineprint {
  margin: 8px 0 0;
  font-size: 10px;
  color: var(--muted);
  max-width: 260px;
}

.minimap-wrap {
  position: absolute;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  padding: 8px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

#minimap {
  display: block;
  width: 180px;
  height: 180px;
  border-radius: 6px;
}

.minimap-legend {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.06em;
}

.hud-actions {
  position: absolute;
  right: calc(12px + env(safe-area-inset-right));
  top: calc(148px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  max-height: calc(100dvh - 220px);
  overflow-y: auto;
}

.weather-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.weather-control select {
  min-width: 118px;
}

#branding-label {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 40;
  background: #ffffff;
  color: #000000;
  font-weight: 500;
  font-size: 12px;
  line-height: 1.2;
  padding: 6px 12px;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(10, 20, 32, 0.85);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.04em;
}

button:hover,
button:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
}

button:disabled {
  opacity: 0.45;
  cursor: wait;
}

#fpv-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fpv-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 48%, rgba(0, 0, 0, 0.42) 100%);
}

#fpv-crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(62, 224, 255, 0.9);
  border-radius: 50%;
}

#fpv-crosshair::before,
#fpv-crosshair::after {
  content: "";
  position: absolute;
  background: rgba(62, 224, 255, 0.9);
}

#fpv-crosshair::before {
  left: 50%;
  top: -8px;
  width: 1px;
  height: 34px;
}

#fpv-crosshair::after {
  top: 50%;
  left: -8px;
  height: 1px;
  width: 34px;
}

.horizon {
  position: absolute;
  left: 50%;
  bottom: 52px;
  width: 84px;
  height: 84px;
  transform: translateX(-50%);
  border: 2px solid var(--cyan);
  border-radius: 50%;
  overflow: hidden;
  background: #1b2430;
}

#horizon-ball {
  width: 84px;
  height: 168px;
  margin-top: -42px;
  background: linear-gradient(#4c91d4 50%, #8a6a3a 50%);
}

.world-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #d7f6ff;
  background: rgba(7, 16, 24, 0.62);
  border: 1px solid rgba(62, 224, 255, 0.35);
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
  transition: opacity 0.2s linear, transform 0.2s linear;
}

.world-label.is-hidden {
  opacity: 0 !important;
}

#hud-kmh[data-speed="low"] { color: var(--green); }
#hud-kmh[data-speed="normal"] { color: var(--cyan); }
#hud-kmh[data-speed="high"] { color: var(--amber); }
#hud-kmh[data-speed="boost"] { color: var(--red); font-weight: 700; }

#hud-boost[data-state="boost"] {
  color: var(--red);
  font-weight: 700;
  letter-spacing: 0.12em;
}

#boost-banner {
  position: absolute;
  top: calc(86px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 4px 18px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.28em;
  color: #fff4f4;
  background: rgba(160, 16, 28, 0.72);
  border: 1px solid rgba(255, 90, 90, 0.8);
  pointer-events: none;
  text-shadow: 0 0 12px rgba(255, 40, 40, 0.8);
}

#speed-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

#speed-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 48%, rgba(4, 8, 16, calc(0.55 * var(--fx, 0))) 100%);
}

#speed-fx.boost #speed-vignette {
  background: radial-gradient(ellipse at center, transparent 42%, rgba(40, 0, 8, calc(0.72 * var(--fx, 0))) 100%);
}

#speed-lines {
  position: absolute;
  inset: 0;
  opacity: calc(var(--fx, 0) * 0.55);
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0 46%,
      rgba(220, 240, 255, 0.08) 48%,
      transparent 52% 100%
    );
  mask-image: radial-gradient(circle at center, transparent 42%, #000 78%);
  animation: speed-streak 0.28s linear infinite;
}

@keyframes speed-streak {
  from { transform: translateY(-6%); }
  to { transform: translateY(6%); }
}

#debug-panel {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  top: calc(178px + env(safe-area-inset-top));
  z-index: 14;
  margin: 0;
  padding: 8px 10px;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #c6f4ff;
  background: rgba(4, 10, 16, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: pre;
  pointer-events: none;
}

#start-screen,
#help-panel,
#crash-overlay,
#webgl-error,
#pause-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 14, 0.55);
  z-index: 18;
}

#start-screen {
  background:
    radial-gradient(circle at 20% 20%, rgba(62, 224, 255, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(7, 16, 24, 0.55), rgba(7, 16, 24, 0.78));
}

.start-card,
.help-card,
.crash-card {
  width: min(640px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 16px;
  max-height: min(90dvh, 760px);
  overflow-y: auto;
}

.start-card h1,
.help-card h2,
.crash-card h2 {
  margin: 0 0 6px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.eyebrow,
.subtitle {
  color: var(--cyan);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
}

.subtitle {
  margin: 0 0 16px;
}

.disclaimer {
  color: var(--amber);
  font-size: 13px;
  line-height: 1.45;
}

.loading {
  margin: 18px 0;
}

.loading-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

#loading-bar {
  height: 100%;
  width: 4%;
  background: linear-gradient(90deg, #1bb3b8, var(--cyan));
}

#loading-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.quality {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
}

select {
  background: #0d1722;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

.lang-start {
  width: auto;
  margin-bottom: 10px;
}

#start-button,
#help-close,
#crash-reset {
  width: 100%;
  padding: 12px;
  background: #123040;
  color: var(--cyan);
  font-size: 15px;
}

.controls-preview {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text);
}

.help-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 18px;
}

.help-card dt {
  color: var(--cyan);
  font-size: 12px;
}

.help-card dd {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

#pause-overlay {
  font-size: 42px;
  letter-spacing: 0.4em;
  color: var(--cyan);
  background: rgba(4, 8, 14, 0.35);
  pointer-events: none;
}

.harbour,
.project-name {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.sound-control,
.volume-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}

.volume-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.volume-row input[type="range"],
#chase-distance {
  width: 92px;
  accent-color: var(--cyan);
}

.sound-label {
  color: var(--text);
  font-size: 12px;
}

.key-legend {
  position: absolute;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(168px + env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  pointer-events: none;
  z-index: 3;
}

.key-legend span {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  background: rgba(8, 14, 24, 0.55);
}

.key-legend span.on {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(62, 224, 255, 0.16);
}

.flyto-progress {
  min-width: 220px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  pointer-events: none;
}

.flyto-title {
  font-size: 12px;
  color: var(--cyan);
}

.flyto-bar {
  height: 5px;
  margin: 6px 0;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

#flyto-bar-fill {
  height: 100%;
  width: 0;
  background: var(--amber);
}

.flyto-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 10px;
  color: var(--muted);
}

#flyto-panel,
#reset-confirm {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 14, 0.55);
  z-index: 19;
}

.flyto-card {
  width: min(420px, calc(100vw - 32px));
  max-height: min(86dvh, 640px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.flyto-list {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.flyto-list button,
#flyto-cancel,
#reset-no {
  width: 100%;
}

#speech-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.speech-bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 220px;
  padding: 6px 10px;
  border-radius: 12px 12px 12px 4px;
  background: rgba(250, 252, 255, 0.92);
  color: #111827;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  white-space: normal;
}

#mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

#mobile-controls button,
#stick-zone {
  pointer-events: auto;
  touch-action: none;
}

#stick-zone {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
}

#stick-base {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 2px solid rgba(62, 224, 255, 0.55);
  background: rgba(7, 16, 24, 0.45);
  position: relative;
}

#stick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(62, 224, 255, 0.85);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px rgba(62, 224, 255, 0.35);
}

#mobile-right {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, minmax(48px, 1fr));
  gap: 8px;
  width: 168px;
}

#mobile-right button,
#mobile-bar button,
#mobile-collapse {
  min-width: 44px;
  min-height: 44px;
  background: rgba(8, 16, 26, 0.62);
  border: 1px solid rgba(62, 224, 255, 0.45);
  color: #d7f6ff;
  font-size: 11px;
}

#mobile-right button.active,
#mobile-bar button:active,
#mobile-right button:active {
  background: rgba(62, 224, 255, 0.28);
  color: #fff;
}

#mobile-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  pointer-events: auto;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
}

#mobile-collapse {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  top: calc(12px + env(safe-area-inset-top));
}

#mobile-controls.collapsed #stick-zone,
#mobile-controls.collapsed #mobile-right {
  display: none;
}

#orientation-banner {
  position: absolute;
  left: 50%;
  top: calc(10px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 12;
  pointer-events: none;
  background: rgba(8, 14, 24, 0.78);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  max-width: min(92vw, 420px);
  text-align: center;
}

body.using-mobile-controls #branding-label {
  bottom: calc(58px + env(safe-area-inset-bottom));
}

body.using-mobile-controls .panel.bl {
  bottom: calc(230px + env(safe-area-inset-bottom));
}

body.using-mobile-controls .minimap-wrap {
  bottom: calc(58px + env(safe-area-inset-bottom));
}

body.using-mobile-controls .horizon {
  bottom: calc(210px + env(safe-area-inset-bottom));
}

#app.hud-compact .hud-actions .weather-control,
#app.hud-compact .hud-actions .sound-control,
#app.hud-compact .panel.tr,
#app.hud-compact .panel.bl .fineprint {
  display: none;
}

.mobile-help p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 1366px), (max-height: 768px) {
  .panel {
    min-width: 190px;
    padding: 8px 10px;
  }
  .row {
    font-size: 12px;
  }
  #minimap {
    width: 150px;
    height: 150px;
  }
  .hud-actions {
    top: calc(118px + env(safe-area-inset-top));
  }
  #branding-label {
    font-size: 10px;
    padding: 4px 8px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .help-card dl {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .tr,
  .bl {
    min-width: 148px;
  }
  .panel.tl,
  .panel.tr {
    min-width: 140px;
    font-size: 12px;
  }
  #minimap {
    width: 112px;
    height: 112px;
  }
  .compass {
    width: 40px;
    height: 40px;
    font-size: 11px;
  }
  #branding-label {
    font-size: 9px;
    padding: 3px 8px;
  }
  .hud-actions {
    max-height: 34dvh;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  .panel.bl {
    left: calc(8px + env(safe-area-inset-left));
    bottom: auto;
    top: calc(118px + env(safe-area-inset-top));
  }
  .minimap-wrap {
    right: calc(8px + env(safe-area-inset-right));
  }
  #stick-zone {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }
  #mobile-right {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }
}
