:root {
  color-scheme: dark;
  --bg: #04070d;
  --panel: rgba(8, 14, 24, 0.76);
  --panel-border: rgba(182, 212, 255, 0.16);
  --text: #eef4ff;
  --muted: #a2afc8;
  --accent: #6fd3ff;
  --accent-strong: #ffd36f;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-top-gap: calc(var(--safe-top) + 44px);
  --mobile-side-gap: 10px;
  --mobile-bottom-gap: calc(var(--safe-bottom) + 54px);
  --mobile-bottom-gap-compact: calc(var(--safe-bottom) + 74px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at top, rgba(33, 65, 120, 0.18), transparent 35%),
    radial-gradient(circle at bottom, rgba(129, 73, 18, 0.14), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body::-webkit-scrollbar,
.hud::-webkit-scrollbar {
  width: 6px;
}

body::-webkit-scrollbar-thumb,
.hud::-webkit-scrollbar-thumb {
  background: rgba(157, 190, 238, 0.38);
  border-radius: 999px;
}

body::-webkit-scrollbar-track,
.hud::-webkit-scrollbar-track {
  background: transparent;
}

button,
input,
select {
  font: inherit;
}

button,
.mobile-hud-toggle,
.flight-key {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100dvw;
  height: 100dvh;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.mobile-hud-toggle,
.mobile-flight-pad {
  display: none;
}

.hud {
  position: absolute;
  inset: 20px auto 20px 20px;
  width: min(380px, calc(100vw - 40px));
  overflow: auto;
  max-height: calc(100vh - 40px);
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: rgba(157, 190, 238, 0.38) transparent;
}

.glass {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 42%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05), transparent 12%);
}

.brand h1,
.panel h2,
.eyebrow,
.subtitle,
.panel p,
label span,
output {
  margin: 0;
}

.brand h1 {
  font-size: 2rem;
  letter-spacing: 0.04em;
}

.eyebrow {
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}

.status-banner {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(111, 211, 255, 0.35);
  background:
    linear-gradient(135deg, rgba(111, 211, 255, 0.18), rgba(255, 211, 111, 0.12)),
    rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.status-banner.is-active {
  border-color: rgba(138, 232, 162, 0.38);
  background:
    linear-gradient(135deg, rgba(67, 145, 94, 0.2), rgba(73, 143, 224, 0.12)),
    rgba(255, 255, 255, 0.04);
}

.status-banner strong {
  color: var(--accent-strong);
}

.panel {
  margin-top: 16px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.panel.compact p,
.panel.compact h2 {
  margin-bottom: 10px;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

label span,
.panel p {
  color: var(--muted);
  line-height: 1.45;
}

input[type="range"] {
  accent-color: var(--accent);
}

input,
select,
button {
  width: 100%;
  border: 0;
  border-radius: 12px;
}

input[type="datetime-local"],
select {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

button {
  padding: 11px 12px;
  background: linear-gradient(135deg, rgba(96, 184, 255, 0.9), rgba(66, 114, 255, 0.8));
  color: #04111f;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

button.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0 10px;
}

output {
  font-size: 0.92rem;
  color: var(--accent);
}

.info-panel p {
  margin-top: 8px;
}

@media (max-width: 900px) {
  .hud {
    inset: auto 12px 12px 12px;
    width: auto;
    max-height: 52vh;
    border-radius: 20px;
    padding: 16px;
  }

  .brand h1 {
    font-size: 1.65rem;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .mobile-hud-toggle {
    display: inline-flex;
    position: absolute;
    right: calc(var(--safe-right) + var(--mobile-side-gap));
    top: var(--mobile-top-gap);
    z-index: 30;
    width: auto;
    min-height: 40px;
    padding: 9px 14px;
    border-radius: 999px;
    background: rgba(7, 15, 28, 0.82);
    color: var(--text);
    border: 1px solid rgba(157, 190, 238, 0.22);
    backdrop-filter: blur(12px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  }

  .hud {
    left: calc(var(--safe-left) + var(--mobile-side-gap));
    right: calc(var(--safe-right) + var(--mobile-side-gap));
    top: auto;
    bottom: var(--mobile-bottom-gap);
    width: auto;
    max-height: min(520px, calc(100dvh - var(--mobile-top-gap) - var(--mobile-bottom-gap) - 24px));
    padding: 14px 14px calc(18px + var(--safe-bottom) + 18px);
    border-radius: 18px;
    background:
      linear-gradient(180deg, rgba(14, 20, 34, 0.94), rgba(7, 12, 21, 0.86)),
      var(--panel);
    transition: transform 180ms ease, opacity 180ms ease;
    z-index: 20;
  }

  .hud.is-collapsed {
    transform: translateY(calc(100% + 18px));
    opacity: 0.18;
    pointer-events: none;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .subtitle,
  .panel p,
  .status-banner,
  label span,
  output,
  button,
  input,
  select {
    font-size: 0.92rem;
  }

  .eyebrow {
    font-size: 0.64rem;
    letter-spacing: 0.14em;
  }

  .status-banner {
    margin-top: 12px;
    padding: 10px 12px;
    line-height: 1.4;
  }

  .panel {
    margin-top: 12px;
    padding: 12px;
    border-radius: 16px;
  }

  input[type="datetime-local"],
  select,
  button {
    min-height: 44px;
  }

  .info-panel {
    padding-bottom: calc(18px + var(--safe-bottom));
  }

  .mobile-flight-pad {
    display: grid;
    position: absolute;
    left: calc(var(--safe-left) + var(--mobile-side-gap));
    bottom: calc(var(--safe-bottom) + 112px);
    z-index: 25;
    width: 156px;
    height: 156px;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    pointer-events: none;
  }

  .flight-key {
    pointer-events: auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: manipulation;
    border-radius: 18px;
    border: 1px solid rgba(157, 190, 238, 0.2);
    background: rgba(7, 15, 28, 0.72);
    color: var(--text);
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(12px);
  }

  .flight-key:active,
  .flight-key.is-active {
    background: rgba(81, 133, 232, 0.7);
    color: #f9fcff;
    transform: scale(0.98);
  }

  .flight-key-up {
    grid-column: 2;
    grid-row: 1;
  }

  .flight-key-left {
    grid-column: 1;
    grid-row: 2;
  }

  .flight-key-right {
    grid-column: 3;
    grid-row: 2;
  }

  .flight-key-down {
    grid-column: 2;
    grid-row: 3;
  }
}

@media (max-width: 420px) {
  .hud {
    left: calc(var(--safe-left) + 8px);
    right: calc(var(--safe-right) + 8px);
    bottom: var(--mobile-bottom-gap-compact);
    max-height: calc(100dvh - var(--mobile-top-gap) - var(--mobile-bottom-gap-compact) - 18px);
    padding: 12px 12px calc(18px + var(--safe-bottom) + 16px);
  }

  .mobile-flight-pad {
    width: 138px;
    height: 138px;
    left: calc(var(--safe-left) + 8px);
    bottom: calc(var(--safe-bottom) + 106px);
  }

  .brand h1 {
    font-size: 1.2rem;
  }

  .panel.compact p,
  .panel.compact h2 {
    margin-bottom: 8px;
  }
}
