* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #e8ecf2;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

#glcanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  padding: 12px 14px;
  min-width: 235px;
  border: 1px solid rgba(120, 170, 255, 0.22);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.55);
  font-size: 13px;
  pointer-events: none;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 3px 0;
}

.hud-row span { color: #8ba3c4; }
.hud-row b { color: #d8e8ff; font-variant-numeric: tabular-nums; }

.bar {
  height: 5px;
  margin: 6px 0 8px;
  border-radius: 3px;
  background: rgba(120, 170, 255, 0.15);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3a7bd5, #6ee7ff, #ff5fa2);
  transition: width 0.08s linear;
}

#panel {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 272px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 14px;
  border: 1px solid rgba(120, 170, 255, 0.22);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.72);
  font-size: 13px;
}

#panel.collapsed > *:not(.panel-head) { display: none; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  color: #cfe2ff;
  font-weight: 600;
  letter-spacing: 1px;
}

.mini {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 5px;
  border: 1px solid rgba(120, 170, 255, 0.35);
  background: transparent;
  color: #9fb4d0;
  cursor: pointer;
}

.ctl {
  display: grid;
  grid-template-columns: 62px 1fr 50px;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  color: #9fb4d0;
}

.ctl b { text-align: right; color: #d8e8ff; font-variant-numeric: tabular-nums; }

input[type="range"] {
  width: 100%;
  accent-color: #5b9dff;
}

select {
  width: 100%;
  background: rgba(15, 22, 40, 0.9);
  color: #d8e8ff;
  border: 1px solid rgba(120, 170, 255, 0.3);
  border-radius: 5px;
  padding: 3px 6px;
}

.checks {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 8px 0;
  color: #9fb4d0;
}

.checks label { display: flex; align-items: center; gap: 7px; }

input[type="checkbox"] { accent-color: #5b9dff; }

.divider {
  height: 1px;
  margin: 10px 0;
  background: rgba(120, 170, 255, 0.18);
}

.file {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #9fb4d0;
  margin-bottom: 8px;
}

.file input { color: #b7c8e0; font-size: 12px; }

.status { min-height: 16px; font-size: 12px; color: #8fe08f; margin: 4px 0; }

.btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.btns button {
  padding: 7px 4px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid rgba(120, 170, 255, 0.35);
  background: rgba(30, 50, 90, 0.55);
  color: #d8e8ff;
  cursor: pointer;
}

.btns button:hover { background: rgba(50, 80, 140, 0.7); }

#help {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 25;
  max-width: 430px;
  padding: 14px 18px;
  border: 1px solid rgba(120, 170, 255, 0.25);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.82);
  font-size: 13px;
  line-height: 1.6;
  color: #a9bdd8;
}

#help h2 {
  margin: 8px 0 6px;
  font-size: 14px;
  color: #cfe2ff;
}

#help h2:first-child { margin-top: 0; }
#help p { margin: 3px 0; }
#help b { color: #d8e8ff; }

.help-mobile { display: none; }

#mobileControls {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

.touch-pad {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: 6px;
  pointer-events: auto;
  touch-action: none;
}

.touch-move {
  left: max(10px, env(safe-area-inset-left));
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
}

.touch-fly {
  right: max(10px, env(safe-area-inset-right));
  grid-template-columns: 52px;
  grid-auto-rows: 52px;
  align-content: end;
  justify-content: end;
}

.touch-btn {
  min-width: 52px;
  min-height: 52px;
  padding: 4px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid rgba(120, 170, 255, 0.4);
  background: rgba(8, 12, 24, 0.62);
  color: #d8e8ff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.touch-btn:active,
.touch-btn.touch-active {
  background: rgba(50, 90, 160, 0.85);
  border-color: rgba(140, 200, 255, 0.65);
}

.touch-hold.touch-active {
  background: rgba(180, 90, 40, 0.75);
}

.touch-sym {
  font-size: 22px;
  line-height: 1;
}

.touch-panel {
  font-size: 13px;
}

#bootOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(4, 6, 12, 0.92);
  color: #d8e8ff;
  text-align: center;
  padding: 24px;
}

#bootOverlay[hidden] {
  display: none !important;
}

#bootLoading {
  margin: 0;
  font-size: 16px;
  color: #9fb4d0;
}

#bootModePick {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 280px;
}

#bootModePick.is-visible {
  display: flex;
}

.boot-title {
  margin: 0 0 4px;
  font-size: 15px;
  color: #cfe2ff;
}

.boot-mode {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  border-radius: 10px;
  border: 1px solid rgba(120, 170, 255, 0.4);
  background: rgba(30, 50, 90, 0.65);
  color: #d8e8ff;
  cursor: pointer;
}

.boot-mode:hover {
  background: rgba(50, 80, 140, 0.85);
}

body.mobile #glcanvas {
  cursor: default;
  touch-action: none;
}

body.mobile {
  touch-action: none;
}

@media (max-width: 720px), (pointer: coarse) {
  body.mobile #hud {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    transform: none;
    min-width: 0;
    width: min(calc(100vw - 20px), 320px);
    padding: 8px 10px;
    font-size: 11px;
    pointer-events: auto;
  }

  body.mobile #hud .hud-row:nth-child(n+6) {
    display: none;
  }

  body.mobile #panel.collapsed {
    display: none;
  }

  body.mobile #panel:not(.collapsed) {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: min(72vh, 520px);
    border-radius: 12px 12px 0 0;
    z-index: 30;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  body.mobile #panel:not(.collapsed) .panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  body.mobile #help {
    top: max(12px, env(safe-area-inset-top));
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(400px, calc(100vw - 28px));
    max-width: none;
    max-height: min(55vh, 420px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12px;
    border-radius: 12px;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.48);
    z-index: 35;
  }

  body.mobile .help-desktop {
    display: none;
  }

  body.mobile .help-mobile {
    display: block;
  }
}
