/* ==========================================================
   破晓号 · 星际战舰模拟器 —— UI 样式
   设计：军用航天 HUD（青蓝为主 / 琥珀警示），全响应式
   ========================================================== */
:root {
  --cyan: #4fe3ff;
  --cyan-dim: rgba(79, 227, 255, 0.5);
  --amber: #ffb43a;
  --red: #ff4d4d;
  --green: #57ffa8;
  --ink: #04070d;
  --panel: rgba(8, 18, 30, 0.42);
  --panel-line: rgba(79, 227, 255, 0.28);
  --text: #d9ecff;
  --hud-scale: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ===================== 加载页 ===================== */
#loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(18, 46, 78, 0.9), rgba(4, 7, 13, 0.98) 65%),
    var(--ink);
  transition: opacity 0.7s ease;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-inner { width: min(520px, 82vw); text-align: center; }
.brand-mark {
  font: 700 12px/1 "Consolas", monospace;
  letter-spacing: 0.42em;
  color: var(--cyan);
  opacity: 0.85;
}
.brand-mark span { opacity: 0.5; }
.loader-inner h1 {
  margin: 10px 0 4px;
  font-size: clamp(30px, 7vw, 54px);
  letter-spacing: 0.22em;
  font-weight: 300;
  text-shadow: 0 0 34px rgba(79, 227, 255, 0.4);
}
.loader-inner .sub {
  margin: 0 0 26px;
  font: 400 clamp(10px, 2.4vw, 12px)/1.7 "Consolas", monospace;
  letter-spacing: 0.24em;
  color: rgba(150, 200, 235, 0.65);
}
.bar {
  height: 3px;
  background: rgba(79, 227, 255, 0.14);
  border-radius: 2px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1b6fa8, var(--cyan));
  box-shadow: 0 0 14px var(--cyan);
  transition: width 0.25s ease;
}
.load-label {
  margin-top: 12px;
  font: 400 11px/1.6 "Consolas", monospace;
  letter-spacing: 0.16em;
  color: rgba(150, 200, 235, 0.75);
  min-height: 18px;
}

/* ===================== HUD 基础 ===================== */
.hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
  font-size: calc(13px * var(--hud-scale));
}
.hud.hud-hidden { opacity: 0; }

.panel {
  position: absolute;
  padding: calc(10px * var(--hud-scale)) calc(13px * var(--hud-scale));
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 3px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: inset 0 0 22px rgba(79, 227, 255, 0.06);
  min-width: calc(168px * var(--hud-scale));
}
.panel::before {
  content: "";
  position: absolute;
  left: -1px; top: -1px;
  width: 12px; height: 12px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
}
.panel::after {
  content: "";
  position: absolute;
  right: -1px; bottom: -1px;
  width: 12px; height: 12px;
  border-bottom: 2px solid var(--cyan);
  border-right: 2px solid var(--cyan);
}
.panel-tl { left: calc(14px + env(safe-area-inset-left)); top: calc(14px + env(safe-area-inset-top)); }
.panel-tr { right: calc(14px + env(safe-area-inset-right)); top: calc(14px + env(safe-area-inset-top)); text-align: right; }

.panel-title {
  font: 600 calc(10px * var(--hud-scale))/1.4 "Consolas", monospace;
  letter-spacing: 0.2em;
  color: var(--cyan);
  opacity: 0.9;
  margin-bottom: 7px;
  text-transform: uppercase;
}
.panel-title .hint { opacity: 0.5; }
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font: 400 calc(11.5px * var(--hud-scale))/1.9 "Consolas", monospace;
}
.stat-row .k { color: rgba(160, 200, 230, 0.7); }
.stat-row .v { color: #eaf7ff; font-weight: 600; }
.target-name {
  font: 600 calc(14px * var(--hud-scale))/1.5 "Segoe UI", sans-serif;
  color: var(--amber);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.gauge { margin-top: 7px; }
.gauge-label {
  font: 400 calc(10px * var(--hud-scale))/1.5 "Consolas", monospace;
  letter-spacing: 0.14em;
  color: rgba(160, 200, 230, 0.72);
  display: flex; justify-content: space-between;
}
.gauge-label b { color: #eaf7ff; }
.gauge-track {
  height: 4px;
  background: rgba(120, 180, 220, 0.15);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}
.gauge-track .fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.12s linear;
}
.fill.energy { background: linear-gradient(90deg, #1b6fa8, var(--cyan)); box-shadow: 0 0 10px var(--cyan-dim); }
.fill.hull { background: linear-gradient(90deg, #1f8a54, var(--green)); box-shadow: 0 0 10px rgba(87, 255, 168, 0.4); }

.lamps { display: flex; gap: 6px; margin-top: 9px; justify-content: flex-start; }
.lamp {
  font: 600 calc(9px * var(--hud-scale))/1 "Consolas", monospace;
  letter-spacing: 0.12em;
  padding: 4px 6px;
  border: 1px solid rgba(120, 180, 220, 0.28);
  border-radius: 2px;
  color: rgba(150, 195, 225, 0.45);
  transition: all 0.15s ease;
}
.lamp.on {
  color: #04121a;
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 16px var(--cyan);
}
.lamp.warp.on { background: var(--amber); border-color: var(--amber); box-shadow: 0 0 16px var(--amber); }

.radar {
  width: calc(148px * var(--hud-scale));
  height: calc(148px * var(--hud-scale));
  margin-top: 9px;
  display: block;
}

/* 油门柱 */
.throttle-col {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(20px + env(safe-area-inset-bottom));
  text-align: center;
}
.throttle-track {
  width: calc(9px * var(--hud-scale));
  height: calc(132px * var(--hud-scale));
  background: rgba(120, 180, 220, 0.14);
  border: 1px solid var(--panel-line);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  margin: 0 auto;
}
.throttle-track i {
  position: absolute;
  inset: 0;
  transform-origin: bottom center;
  transform: scaleY(0);
  background: linear-gradient(180deg, var(--cyan), #1b6fa8);
  box-shadow: 0 0 12px var(--cyan-dim);
  transition: transform 0.1s linear;
}
.throttle-num {
  margin-top: 6px;
  font: 700 calc(13px * var(--hud-scale))/1 "Consolas", monospace;
  color: #eaf7ff;
}
.throttle-cap {
  font: 400 calc(9px * var(--hud-scale))/1.6 "Consolas", monospace;
  letter-spacing: 0.2em;
  color: rgba(150, 195, 225, 0.6);
}

/* 准星 / 速度矢量 */
.reticle {
  position: absolute;
  left: 50%; top: 50%;
  width: calc(78px * var(--hud-scale));
  height: calc(78px * var(--hud-scale));
  transform: translate(-50%, -50%);
  opacity: 0.62;
}
.reticle svg, .vel-vec svg { width: 100%; height: 100%; }
.reticle circle, .reticle path {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1.6;
}
.reticle .dot { fill: var(--cyan); stroke: none; }
.vel-vec {
  position: absolute;
  left: 0; top: 0;
  width: calc(30px * var(--hud-scale));
  height: calc(30px * var(--hud-scale));
  margin-left: calc(-15px * var(--hud-scale));
  margin-top: calc(-15px * var(--hud-scale));
  display: none;
  opacity: 0.8;
}
.vel-vec circle, .vel-vec path {
  fill: none;
  stroke: var(--green);
  stroke-width: 2;
}

/* 天体标记 */
.marker-layer { position: absolute; inset: 0; }
.marker {
  position: absolute;
  left: 0; top: 0;
  display: none;
  will-change: transform;
}
.mk-ring {
  position: absolute;
  left: -9px; top: -9px;
  width: 18px; height: 18px;
  border: 1px solid rgba(120, 200, 240, 0.55);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(79, 227, 255, 0.25);
}
.mk-label {
  position: absolute;
  left: 14px; top: -8px;
  white-space: nowrap;
  font: 400 calc(10.5px * var(--hud-scale))/1.4 "Consolas", monospace;
  letter-spacing: 0.06em;
  color: rgba(190, 225, 245, 0.8);
  text-shadow: 0 0 8px rgba(0, 12, 24, 0.9);
}
.marker-star .mk-ring { border-color: rgba(255, 200, 110, 0.7); }
.marker-star .mk-label { color: rgba(255, 219, 160, 0.9); }
.marker-blackhole .mk-ring { border-color: rgba(196, 130, 255, 0.8); }
.marker-blackhole .mk-label { color: rgba(210, 165, 255, 0.95); }
.marker.is-target .mk-ring {
  border-color: var(--amber);
  border-width: 2px;
  transform: scale(1.35);
  box-shadow: 0 0 14px rgba(255, 180, 58, 0.6);
}
.marker.is-target .mk-label { color: var(--amber); font-weight: 600; }
.marker.off-screen .mk-ring { border-style: dashed; opacity: 0.85; }

/* 警告 / 提示 */
.warn {
  position: absolute;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 7px 16px;
  font: 600 calc(12.5px * var(--hud-scale))/1.4 "Segoe UI", sans-serif;
  letter-spacing: 0.1em;
  color: var(--amber);
  background: rgba(40, 22, 4, 0.5);
  border: 1px solid rgba(255, 180, 58, 0.5);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
  text-align: center;
  max-width: 80vw;
}
.warn.show { opacity: 1; }
.warn.critical {
  color: #fff;
  background: rgba(120, 12, 12, 0.6);
  border-color: var(--red);
  animation: warnBlink 0.55s steps(2, end) infinite;
}
@keyframes warnBlink { 50% { opacity: 0.35; } }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(23% + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  padding: 8px 18px;
  background: rgba(8, 20, 32, 0.72);
  border: 1px solid var(--panel-line);
  border-radius: 3px;
  font: 400 calc(12.5px * var(--hud-scale))/1.5 "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  color: #dcf2ff;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  max-width: 86vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.fps {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  font: 400 calc(10px * var(--hud-scale))/1 "Consolas", monospace;
  letter-spacing: 0.12em;
  color: rgba(140, 190, 220, 0.45);
}

/* ===================== 触屏操控 ===================== */
.touch-ui {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: none;
}
.touch-ui.enabled { display: block; }

.stick-wrap {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  pointer-events: auto;
}
.stick-wrap.left { left: calc(16px + env(safe-area-inset-left)); }
.stick-wrap.right { right: calc(16px + env(safe-area-inset-right)); }
.stick {
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 1px solid rgba(79, 227, 255, 0.32);
  background:
    radial-gradient(circle at 50% 50%, rgba(15, 40, 62, 0.42), rgba(6, 14, 24, 0.26) 70%);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  touch-action: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.stick.active {
  border-color: var(--cyan);
  box-shadow: 0 0 22px rgba(79, 227, 255, 0.3), inset 0 0 22px rgba(79, 227, 255, 0.12);
}
.stick .knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #9fe6ff, #1d6f9c 62%, #0d3550 100%);
  box-shadow: 0 0 18px rgba(79, 227, 255, 0.5), inset 0 -4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.stick-cap {
  position: absolute;
  left: 50%;
  bottom: -19px;
  transform: translateX(-50%);
  white-space: nowrap;
  font: 400 10px/1 "Consolas", monospace;
  letter-spacing: 0.14em;
  color: rgba(150, 200, 230, 0.6);
}

.btn-cluster {
  position: absolute;
  right: calc(160px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
  pointer-events: auto;
}
.tbtn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  min-width: 64px;
  min-height: 50px;
  padding: 14px 10px;
  font: 600 13px/1 "Segoe UI", "PingFang SC", sans-serif;
  letter-spacing: 0.12em;
  color: #cfeaff;
  background: rgba(10, 24, 38, 0.5);
  border: 1px solid rgba(79, 227, 255, 0.3);
  border-radius: 4px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  touch-action: none;
  transition: all 0.12s ease;
}
.tbtn.small { min-width: 58px; min-height: 46px; padding: 12px 8px; font-size: 11.5px; }
.tbtn.boost { border-color: rgba(79, 227, 255, 0.6); color: #eafaff; }
.tbtn.warp { border-color: rgba(255, 180, 58, 0.55); color: #ffe6bd; }
.tbtn.on {
  background: rgba(79, 227, 255, 0.85);
  color: #04121a;
  box-shadow: 0 0 20px rgba(79, 227, 255, 0.55);
}
.tbtn.warp.on { background: rgba(255, 180, 58, 0.9); box-shadow: 0 0 20px rgba(255, 180, 58, 0.6); }

/* ===================== 开场 / 帮助 ===================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 45%, rgba(10, 26, 44, 0.82), rgba(3, 6, 11, 0.94));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.35s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card {
  width: min(760px, 94vw);
  max-height: 92vh;
  overflow: auto;
  padding: clamp(18px, 3vw, 30px);
  background: rgba(7, 16, 27, 0.72);
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6), inset 0 0 60px rgba(79, 227, 255, 0.05);
}
.overlay-card h2 {
  margin: 0 0 16px;
  font-size: clamp(19px, 4.4vw, 26px);
  font-weight: 400;
  letter-spacing: 0.16em;
  color: #eaf7ff;
}
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(14px, 3vw, 28px); }
.col h3 {
  margin: 0 0 8px;
  font: 600 11px/1 "Consolas", monospace;
  letter-spacing: 0.24em;
  color: var(--cyan);
  text-transform: uppercase;
}
.col ul { margin: 0; padding-left: 18px; }
.col li {
  font-size: clamp(11.5px, 2.6vw, 13px);
  line-height: 1.95;
  color: rgba(206, 230, 246, 0.86);
}
.col li b { color: var(--amber); font-weight: 600; }
.tips {
  margin: 18px 0 0;
  padding: 11px 14px;
  font-size: clamp(11.5px, 2.6vw, 13px);
  line-height: 1.8;
  color: rgba(190, 220, 240, 0.8);
  background: rgba(79, 227, 255, 0.06);
  border-left: 2px solid var(--cyan);
}
.tips b { color: #d6a6ff; }
.start-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  font: 600 15px/1 "Segoe UI", "PingFang SC", sans-serif;
  letter-spacing: 0.3em;
  color: #04121a;
  background: linear-gradient(90deg, #35c9f5, #8ef0ff);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(79, 227, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.start-btn:hover { transform: translateY(-1px); box-shadow: 0 0 44px rgba(79, 227, 255, 0.55); }
.start-btn:active { transform: translateY(1px); }
.foot {
  margin-top: 12px;
  text-align: center;
  font: 400 10px/1.6 "Consolas", monospace;
  letter-spacing: 0.16em;
  color: rgba(140, 185, 215, 0.45);
}

/* 竖屏提示 */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  place-items: center;
  background: rgba(3, 7, 13, 0.9);
  pointer-events: none;
}
.rh-inner {
  font: 400 14px/1.6 "Segoe UI", sans-serif;
  letter-spacing: 0.2em;
  color: var(--cyan);
  animation: rhPulse 1.6s ease-in-out infinite;
}
@keyframes rhPulse { 50% { opacity: 0.45; } }

/* ===================== 响应式 ===================== */
/* 触屏模式：油门柱右移，避让左摇杆 */
body.touch-mode .throttle-col {
  left: calc(154px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
}

@media (max-width: 900px) {
  :root { --hud-scale: 0.92; }
  .radar { width: calc(112px * var(--hud-scale)); height: calc(112px * var(--hud-scale)); }
  .btn-cluster { grid-template-columns: repeat(2, auto); right: calc(150px + env(safe-area-inset-right)); }
}
@media (max-width: 640px) {
  :root { --hud-scale: 0.84; }
  .panel { min-width: 0; }
  .throttle-col { left: calc(10px + env(safe-area-inset-left)); bottom: calc(150px + env(safe-area-inset-bottom)); }
  body.touch-mode .throttle-col {
    left: calc(134px + env(safe-area-inset-left));
    bottom: calc(150px + env(safe-area-inset-bottom));
  }
  .throttle-track { height: calc(96px * var(--hud-scale)); }
  .stick { width: 108px; height: 108px; }
  .stick .knob { width: 44px; height: 44px; }
  .btn-cluster { grid-template-columns: repeat(2, auto); gap: 6px; bottom: calc(140px + env(safe-area-inset-bottom)); right: calc(14px + env(safe-area-inset-right)); }
  .tbtn { min-width: 58px; min-height: 48px; padding: 13px 8px; font-size: 12px; }
  .tbtn.small { min-width: 54px; min-height: 44px; padding: 11px 6px; font-size: 11px; }
  .cols { grid-template-columns: 1fr; }
  .toast { bottom: calc(30% + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) and (orientation: portrait) {
  .rotate-hint { display: grid; }
}
/* 横屏手机：竖向空间紧张 —— 按钮改 3 列 2 行，避让右上角面板 */
@media (orientation: landscape) and (max-height: 520px) {
  .btn-cluster {
    grid-template-columns: repeat(3, auto);
    right: calc(154px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .panel-tl, .panel-tr { padding: 7px 10px; }
  .radar { width: calc(96px * var(--hud-scale)); height: calc(96px * var(--hud-scale)); }
}
@media (pointer: coarse) {
  .desktop-only { display: none; }
  #scene { cursor: none; }
}
@media (hover: hover) and (pointer: fine) {
  .touch-ui.enabled .stick-wrap, .touch-ui.enabled .btn-cluster { opacity: 0.9; }
}
