/* Vibe Space — 移动端优先 UI */
:root {
  --bg: #070a14;
  --panel: rgba(16, 22, 36, 0.94);
  --panel-border: rgba(120, 170, 255, 0.22);
  --text: #e8eefc;
  --muted: #8b9ab8;
  --accent: #6fd6ff;
  --good: #5ce0a0;
  --warn: #ffcf5c;
  --bad: #ff6b6b;
  --ore: #f0c07a;
  --alloy: #a9b6ff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* 顶部 HUD 下方的安全起点。默认值是单行状态栏的高度；窄屏时 HUD 会换行变高，
     HUD.update 会把实测底边写进这个变量，面板 / 详情卡 / 提示条就不会被盖住。 */
  --hud-bottom: calc(var(--safe-t) + 58px);
  /* 左下角摇杆占的横向宽度（含外边距）。驾驶条靠它让位，避免压住摇杆。 */
  --joy: 162px;

  /* ---- 动效曲线：全站统一，避免各处随手写 linear / ease ----
     out-quint  ：快速起步、柔和收尾 —— 按钮按下的"弹回"
     out-back   ：带一点过冲 —— 弹层/饼图出现的"弹一下"
     in-out     ：两端都缓 —— 位移类（面板进出、条状变化）
     spring     ：短促有弹性 —— 图标/格子选中 */
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.2, 0.9, 0.25, 1.15);
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#app { position: fixed; inset: 0; }
canvas#game { position: absolute; inset: 0; display: block; touch-action: none; }

.hidden { display: none !important; }

/* ---------- 顶部 HUD ---------- */
#hud-top {
  position: absolute; top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px);
  display: flex; gap: 6px; align-items: center;
  pointer-events: none; flex-wrap: wrap;
  font-size: 13px;
}
/* 状态条只用于显示：必须让指针穿透到画布，否则它下面的格子点不到、放不了东西。 */
.chip {
  pointer-events: none;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 6px 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  font-variant-numeric: tabular-nums;
}
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.ore { background: var(--ore); }
.dot.alloy { background: var(--alloy); }
.cap { color: var(--muted); font-size: 11px; }
.bolt { color: var(--warn); }
.sep { color: var(--muted); margin: 0 -2px; }
.batt { color: var(--muted); font-size: 11px; margin-left: 2px; }
#chip-power.low { border-color: rgba(255,107,107,0.6); }
#chip-power.low .bolt { color: var(--bad); }
#chip-warn {
  border-color: rgba(240,168,60,0.62);
  color: #ffce7a;
  max-width: 62vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#chip-warn.dead { border-color: rgba(255,107,107,0.62); color: #ff9d92; }
#chip-status { margin-left: auto; }
#chip-status.flying { border-color: rgba(111,214,255,0.6); }
#chip-status.flying #status-text { color: var(--accent); }

.icon-btn {
  pointer-events: auto;
  width: 42px; height: 42px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--panel-border);
  color: var(--text); font-size: 18px; cursor: pointer;
  display: grid; place-items: center;
  backdrop-filter: blur(10px);
}
.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; font-size: 14px; }
.icon-btn:active { transform: scale(0.94); }

/* ---------- toast ---------- */
#toast {
  /* --toast-top 由 HUD 在详情卡打开时改写成「卡片下方」：竖屏时卡片靠右、
     提示条居中，两者会重叠，标题被盖住。默认仍然贴着状态栏下方。 */
  position: absolute; top: var(--toast-top, calc(var(--hud-bottom) + 4px)); left: 50%;
  transform: translateX(-50%);
  background: rgba(10,16,28,0.94); border: 1px solid var(--panel-border);
  color: var(--text); padding: 8px 16px; border-radius: 999px;
  font-size: 13px; max-width: 80vw; text-align: center;
  animation: toastIn var(--dur-base) var(--ease-out-back); z-index: 40;
  pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -6px); } }

/* ---------- 建造面板 ---------- */
.panel {
  position: absolute;
  top: var(--hud-bottom);
  left: calc(var(--safe-l) + 8px);
  width: min(320px, 46vw);
  /* 面板从顶部状态栏下方一直延伸到屏幕底部，横屏手机也能放下列表 */
  max-height: calc(100vh - var(--hud-bottom) - var(--safe-b) - 10px);
  height: calc(100vh - var(--hud-bottom) - var(--safe-b) - 10px);
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 18px; padding: 10px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 20;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 14px; padding: 2px 4px; }
.build-tools { display: flex; gap: 6px; }
.tool {
  flex: 1; padding: 9px 4px; border-radius: 11px; font-size: 13px;
  background: rgba(255,255,255,0.06); border: 1px solid transparent;
  color: var(--muted); cursor: pointer; font-weight: 600;
}
.tool.active { background: rgba(111,214,255,0.16); border-color: rgba(111,214,255,0.55); color: var(--accent); }
.tool:active { transform: scale(0.96); }

/* 甲板模块尺寸调节 */
.size-row {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: 12px;
  background: rgba(111,214,255,0.08);
  border: 1px solid rgba(111,214,255,0.22);
  font-size: 12px;
}
.size-row.hidden { display: none; }
.size-label { color: var(--muted); margin-right: 2px; }
.size-btn {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.10);
  color: var(--text); font-size: 16px; font-weight: 700; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.size-btn:active { transform: scale(0.92); background: rgba(111,214,255,0.20); }
.size-val {
  min-width: 20px; text-align: center; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--accent);
}
.size-x { color: var(--muted); margin: 0 2px; }

.build-list {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
  padding-right: 2px;
  /* flex 子项默认 min-height:auto，矮屏（横屏手机）下会撑破面板，
     导致列表沉到信息栏下面、点击被遮挡 */
  min-height: 0;
  flex: 1 1 auto;
  /* 底部渐隐：提示列表还可继续滚动，避免看起来像被裁断 */
  mask-image: linear-gradient(to bottom, #000 calc(100% - 14px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 14px), transparent 100%);
}
.build-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,0.05); border: 1px solid transparent;
  min-height: 46px;
}
.build-item:active { transform: scale(0.97); }
.build-item.sel { border-color: var(--accent); background: rgba(111,214,255,0.13); }
.build-item.disabled { opacity: 0.42; }
.swatch { width: 26px; height: 26px; border-radius: 8px; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25); }
.build-item .bi-t { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.build-item .bi-c { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.build-info {
  border-top: 1px solid rgba(255,255,255,0.08); padding-top: 8px; font-size: 12px;
  flex: 0 1 auto;
  max-height: 38%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel-head, .build-tools, .size-row { flex: 0 0 auto; }

/* 建造工具条：选零件的入口已经搬到屏幕底部的快捷栏，
   这里只剩「模式 + 尺寸」两行，所以不再撑满整屏 ——
   改成贴在状态栏下方的一个小胶囊，宽度随内容。
   之前沿用 .panel 的 height:100vh 会留下一大块空的黑面板挡住半屏。 */
#build-panel {
  height: auto;
  max-height: none;
  width: auto;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 14px;
  gap: 6px;
}
#build-panel .build-tools { flex-wrap: wrap; }
#build-panel .size-row { margin-top: 0; }
.bi-name { font-weight: 700; margin-bottom: 3px; }
.bi-desc { color: var(--muted); line-height: 1.45; }
.bi-cost { margin-top: 6px; display: flex; gap: 10px; font-size: 11.5px; }
.bi-cost span.lack { color: var(--bad); }

/* ---------- 设备详情卡 ---------- */
/* 复用 .panel 的毛玻璃外观，但定位到右上，避开左下摇杆与右下操作按钮。
   触摸端没有 hover，所以这张卡只能靠点选打开，字号按手指可读来定。 */
#inspector {
  top: var(--hud-bottom);
  left: auto;
  right: calc(var(--safe-r) + 8px);
  width: min(268px, 56vw);
  height: auto;
  max-height: calc(100vh - var(--hud-bottom) - var(--safe-b) - 72px);
  gap: 6px;
  z-index: 22;
}
#inspector .panel-head { font-size: 13px; }
.insp-body { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.insp-meta { font-size: 11px; color: var(--muted); }
.insp-status {
  font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 8px;
  background: rgba(255,255,255,0.06);
}
.insp-status.ok { color: var(--good); background: rgba(60,200,140,0.14); }
.insp-status.warn { color: #ffd479; background: rgba(255,212,121,0.14); }
.insp-status.bad { color: var(--bad); background: rgba(255,120,120,0.14); }
/* 信号状态行比电力状态行次要一级：同一张卡上两条同宽的粗条会抢注意力 */
.insp-status.mini { font-size: 11px; padding: 3px 7px; font-weight: 600; }
.insp-title-mini { font-size: 10.5px; color: var(--muted); letter-spacing: 0.08em; margin-top: 2px; }
.insp-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 5px 7px; border-radius: 9px;
  background: rgba(255,255,255,0.05);
  min-height: 34px;
}
.insp-dir {
  flex: none; width: 34px; text-align: center; font-size: 10.5px; font-weight: 700;
  padding: 2px 0; border-radius: 6px; color: var(--muted);
  background: rgba(255,255,255,0.07);
}
.insp-dir.out { color: #ffd479; background: rgba(255,212,121,0.14); }
.insp-dir.in { color: #7ce0a8; background: rgba(124,224,168,0.14); }
.insp-dir.store { color: #b48cf0; background: rgba(180,140,240,0.16); }
.insp-type { flex: 1 1 auto; display: flex; align-items: center; gap: 5px; font-weight: 600; }
.insp-type i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.insp-amt { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.insp-none, .insp-hint { font-size: 10.5px; color: var(--muted); line-height: 1.45; }
.insp-hint { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 5px; }

/* ---------- 操作按钮 ---------- */
/* 快捷栏常驻后，右下角按钮组必须上移让位，否则会被背包/建筑枪键盖住点不到。 */
#action-cluster {
  position: absolute; right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + var(--hotbar-h, 76px) + 12px);
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  z-index: 25;
}
.round-btn {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--panel-border);
  color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  transition: transform var(--dur-fast) var(--ease-out-quint);
}
.round-btn .ico { width: 26px; height: 26px; display: grid; place-items: center; }
.round-btn .ico svg { width: 26px; height: 26px; display: block; }
.round-btn .lbl { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.round-btn.primary { border-color: rgba(111,214,255,0.6); background: rgba(30,52,78,0.94); }
.round-btn.primary .lbl { color: var(--accent); }
.round-btn.active { border-color: var(--good); background: rgba(24,58,44,0.94); }
.round-btn:active { transform: scale(0.92); }
.round-btn:disabled { opacity: 0.4; }

/* ---------- 摇杆 ---------- */
/* 快捷栏是常驻底层 UI，摇杆必须让开它的高度（否则会压在快捷栏上）。
   --hotbar-h 由 HUD 实测写入，默认 76px（52 格 + padding）。 */
#joystick-zone {
  position: absolute; left: calc(var(--safe-l) + 12px);
  /* 驾驶时快捷栏收起（--hotbar-h 归零），摇杆回到常规底部位置。
     非驾驶时让开快捷栏高度，避免两者叠在一起。 */
  bottom: calc(var(--safe-b) + var(--hotbar-h, 0px) + 12px);
  width: 150px; height: 150px; z-index: 24;
  touch-action: none;
}
#joystick-base {
  position: absolute; inset: 0; border-radius: 50%;
  /* 0.55 在浅色地表（雪地/沙地）上几乎看不见，玩家会以为摇杆没了。
     提到 0.8 并加深底色，保证任何地形上都能一眼找到。 */
  background: radial-gradient(circle at 50% 45%, rgba(70,95,140,0.42), rgba(16,24,38,0.62));
  border: 2px solid rgba(140,185,255,0.42);
  opacity: 0.8; transition: opacity var(--dur-base) var(--ease-out-quint);
  backdrop-filter: blur(4px);
}
#joystick-zone.active #joystick-base { opacity: 1; border-color: rgba(111,214,255,0.6); }
#joystick-knob {
  position: absolute; width: 62px; height: 62px; left: 44px; top: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #9fd8ff, #4a7fb5);
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  transition: transform var(--dur-fast) var(--ease-spring);
}

/* ---------- 驾驶条 ---------- */
/* 定位方式很关键：绝对定位元素只给 left 时，可用宽度会被算成「容器宽 − left」，
   left:50% 就只剩半屏。早先这里正是 left:50% + translateX(-50%)，
   提示文案一长（「摇杆推进 · 2/2 台出力 · 推力 2.0 · 拖动空白处转向」），
   三个按钮就被压成竖排的「降/落」「起/飞」「离开/驾驶」。
   现在左右都定位、宽度 fit-content + 左右 auto 外边距，居中且拿到整条可用带。
   左边界让出左下角摇杆（--joy 见 :root），驾驶时右下角操作钮是收起的。 */
#pilot-bar {
  position: absolute;
  left: calc(var(--safe-l) + var(--joy) + 16px);
  right: calc(var(--safe-r) + 12px);
  bottom: calc(var(--safe-b) + 14px);
  width: fit-content; max-width: 660px; margin: 0 auto;
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid rgba(111,214,255,0.4);
  border-radius: 16px; padding: 8px 10px 8px 16px;
  backdrop-filter: blur(14px); z-index: 26;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
/* 文字列可以收窄换行，按钮列不许被挤 */
.pilot-left { flex: 1 1 auto; min-width: 0; }
.pilot-title { font-weight: 700; font-size: 13px; color: var(--accent); }
.pilot-hint { font-size: 10.5px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.pilot-right { display: flex; gap: 6px; flex: none; }
.pbtn {
  padding: 10px 14px; border-radius: 11px; font-size: 12.5px; font-weight: 700;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14);
  color: var(--text); cursor: pointer; min-height: 42px;
  white-space: nowrap; flex: none;
}
.pbtn:active { transform: scale(0.95); }
.pbtn.danger { color: #ffb0b0; border-color: rgba(255,107,107,0.4); }
.pbtn:disabled { opacity: 0.4; }

/* ---------- 弹层 ---------- */
.modal {
  position: absolute; inset: 0; background: rgba(4,7,14,0.72);
  display: grid; place-items: center; z-index: 50; padding: 16px;
  backdrop-filter: blur(6px);
}
.modal-card {
  background: linear-gradient(180deg, #141c2e, #0e1524);
  border: 1px solid var(--panel-border); border-radius: 22px;
  padding: 22px; width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-card.scroll { max-height: 86vh; overflow-y: auto; }
.modal-card h2 { margin: 0 0 4px; font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.menu-actions { display: flex; flex-direction: column; gap: 9px; margin: 18px 0 0; }
.wide {
  width: 100%; padding: 14px; border-radius: 13px; font-size: 15px; font-weight: 700;
  background: rgba(111,214,255,0.14); border: 1px solid rgba(111,214,255,0.45);
  color: var(--accent); cursor: pointer;
}
.wide.ghost { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.12); color: var(--text); }
.wide:active { transform: scale(0.97); }

/* ---------- 底部快捷栏（MC 式物品栏） ---------- */
#hotbar {
  position: absolute; z-index: 34;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 10px);
  /* 宽度必须锁死：只写 max-width 时，flex 子项会把容器撑到内容宽度（558px），
     再被 translateX(-50%) 推出屏幕左侧，最左边两格永远点不到。 */
  width: min(96vw, 720px);
  display: flex; flex-direction: column; gap: 5px; align-items: center;
  pointer-events: none;
}
#hotbar-row {
  display: flex; align-items: stretch; gap: 6px;
  pointer-events: auto; max-width: 100%;
  justify-content: center;
  /* 整条快捷栏是一块连续面板：8 个可移动格 + 右侧固定键同底同框，
     而不是两坨元素飘在画面上。内边距在 #hotbar-row 上，子元素不再各自描边。 */
  padding: 6px;
  background: rgba(12,17,28,0.92);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}
/* 固定键分组：和可移动格之间用一道分隔线隔开，暗示"这几格不能拖" */
.hb-keys {
  display: flex; align-items: center; gap: 6px;
  padding-left: 8px;
  border-left: 1px solid rgba(120,170,255,0.16);
}
/* 右侧两个固定键：背包 / 建筑枪（不可移动） */
.hb-fixed {
  flex: none; width: 52px; min-height: 52px;
  /* 行是 align-items: stretch，不覆盖的话固定键会被拉成和快捷栏一样高，
     圆形键就会变成椭圆（56×60）。这里自己定高并垂直居中。 */
  align-self: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 10px; cursor: pointer; font: inherit;
  background: rgba(255,255,255,0.055);
  border: 1px solid rgba(120,170,255,0.22);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease-out-quint), background var(--dur-fast) var(--ease-out-quint);
}
/* 圆键上的模式徽章：放置 / 拆除 / 接线。长按切完模式后能一眼看到结果。
   放右上角：右下角是圆键的文字标签，两个叠在一起会互相压字。 */
.hb-mode {
  position: absolute; right: -5px; top: -5px;
  font-size: 8.5px; line-height: 1; font-weight: 700;
  padding: 3px 5px; border-radius: 999px;
  background: var(--accent); color: #071018;
  border: 1px solid rgba(7,16,24,0.55);
  pointer-events: none;
  transition: background var(--dur-base) var(--ease-out-quint);
}
.hb-mode.remove { background: var(--bad); color: #fff; }
.hb-mode.wire { background: var(--warn); color: #201704; }
.hb-fixed:active { transform: scale(0.95); }
.hb-fixed.sel { border-color: var(--warn); background: rgba(255,207,92,0.10); }
/* 建筑枪的选中环跟随当前模式颜色：放置=青、拆除=红、接线=黄 */
.hb-fixed.round[data-mode="place"] { border-color: var(--accent); background: rgba(111,214,255,0.12); }
.hb-fixed.round[data-mode="remove"] { border-color: var(--bad); background: rgba(255,107,107,0.12); }
.hb-fixed.round[data-mode="wire"] { border-color: var(--warn); background: rgba(255,207,92,0.12); }
.hb-fixed-lbl { font-size: 9px; color: var(--muted); line-height: 1; }
.hb-fixed.sel .hb-fixed-lbl { color: var(--warn); }
.hb-fixed-ico { width: 22px; height: 22px; border-radius: 6px; position: relative; }
/* 背包：方形背带箱 */
.hb-fixed-ico.bp {
  background: linear-gradient(160deg, #b9c3d6, #5b6478);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22);
}
.hb-fixed-ico.bp::after {
  content: ''; position: absolute; left: 5px; right: 5px; top: 7px;
  height: 3px; border-radius: 2px; background: rgba(20,26,40,0.65);
}
/* 建筑枪：枪身 + 前端发射口，和角色手里那把同一套配色 */
.hb-fixed-ico.gun {
  background: linear-gradient(160deg, #ffffff, #6b7791);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22);
  border-radius: 4px;
}
.hb-fixed-ico.gun::before {
  content: ''; position: absolute; left: 8px; top: 1px; bottom: 1px; width: 6px;
  border-radius: 3px; background: #1d2836;
}
.hb-fixed-ico.gun::after {
  content: ''; position: absolute; left: 2px; bottom: 2px; width: 6px; height: 9px;
  border-radius: 2px; background: #4f586c;
}
.hb-fixed-ico.gun { box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22), 0 0 0 2px rgba(111,214,255,0.5); }

#hotbar-slots {
  display: flex; gap: 5px; padding: 0;
  flex: 0 1 auto;
  background: none; border: 0; box-shadow: none;
  pointer-events: auto;
  /* 内容超出时在容器内滚动，而不是被裁掉 */
  max-width: 100%;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#hotbar-slots::-webkit-scrollbar { display: none; }
.hb-slot {
  position: relative; flex: none;
  width: 52px; height: 52px;               /* ≥44px 手指尺寸 */
  border-radius: 9px; border: 1px solid rgba(120,170,255,0.18);
  background: rgba(255,255,255,0.045);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 4px; cursor: pointer;
  font: inherit; color: var(--text);
  transition: border-color var(--dur-fast) var(--ease-out-quint), background var(--dur-fast) var(--ease-out-quint), transform var(--dur-fast) var(--ease-spring);
}
.hb-slot:active { transform: scale(0.94); }
.hb-slot.empty { border-style: dashed; border-color: rgba(120,170,255,0.08); background: transparent; cursor: default; }
.hb-slot.sel { border-color: var(--accent); background: rgba(111,214,255,0.14); }
#hotbar-slots.dragging .hb-slot { opacity: 0.82; }
.hb-slot.drag-src { border-color: var(--warn); background: rgba(255,207,92,0.16); }
.hb-slot.drop-target { border-color: var(--good); background: rgba(92,224,160,0.16); }
.hb-slot.poor { opacity: 0.42; }
.hb-ico {
  width: 20px; height: 20px; border-radius: 6px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22);
}
.hb-num {
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  line-height: 1;
}
.hb-name {
  font-size: 8.5px; line-height: 1; color: var(--muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hb-slot.sel .hb-name { color: var(--text); }
#hotbar-info {
  font-size: 10.5px; color: var(--muted); letter-spacing: 0.02em;
  background: rgba(12,17,28,0.82); padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(120,170,255,0.12);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  pointer-events: none;
}
#hotbar-info b { color: var(--text); font-weight: 600; }
#hotbar-info .lack { color: var(--bad); }

/* 建造模式下摇杆隐藏，快捷栏贴底；矮屏压缩 */
@media (max-height: 480px) {
  .hb-slot { width: 46px; height: 46px; }
  .hb-ico { width: 17px; height: 17px; }
  #hotbar-info { font-size: 9.5px; padding: 3px 8px; }
}

/* 窄屏（竖屏手机）：10 个零件横排会溢出，缩格子并允许横向滚动。
   格子仍保持 ≥40px，保证手指点得到。 */
@media (max-width: 520px) {
  .hb-slot { width: 42px; height: 42px; }
  .hb-ico { width: 15px; height: 15px; }
  .hb-name { font-size: 8px; }
  .hb-num { font-size: 10px; }
  #hotbar { max-width: 100vw; }
  #hotbar-slots { gap: 4px; padding: 5px; }
}

/* ---------- 背包 ---------- */
.inv-summary {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 11.5px; color: var(--muted); letter-spacing: 0.08em;
  padding: 2px 2px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.inv-summary b { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.inv-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.inv-slot {
  position: relative; aspect-ratio: 1 / 1;
  border: 1px solid rgba(120,170,255,0.16); border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px; overflow: hidden;
}
.inv-slot { cursor: pointer; font: inherit; color: inherit; }
.inv-slot.in-bar { border-color: var(--accent); background: rgba(111,214,255,0.10); }
.inv-slot.empty { border-style: dashed; border-color: rgba(120,170,255,0.08); background: transparent; }
.inv-empty-mark { color: rgba(139,154,184,0.35); font-size: 16px; }
.inv-ico {
  width: 26px; height: 26px; border-radius: 7px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22);
}
.inv-ico.ore { background: linear-gradient(160deg, var(--ore), #b8874a); }
.inv-ico.alloy { background: linear-gradient(160deg, var(--alloy), #6f7bd0); }
.inv-count {
  font-size: 13px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.inv-name { font-size: 9.5px; color: var(--muted); line-height: 1; }
.inv-slot.part { border-color: rgba(120,170,255,0.26); }
.inv-tag {
  font-size: 8.5px; color: var(--accent); line-height: 1;
  letter-spacing: 0.06em;
}
.inv-bar {
  position: absolute; left: 6px; right: 6px; bottom: 4px; height: 2px;
  background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden;
}
.inv-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.inv-note { margin: 12px 0 0; font-size: 10.5px; color: var(--muted); line-height: 1.5; }

/* 顶部资源条现在是可点的背包入口 */
/* 背包超容量：边框转警示色，提示「再采集也装不下」 */
.chip-btn.over {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px rgba(255,207,92,0.35), 0 4px 16px rgba(0,0,0,0.35);
}
.chip-btn.over #res-cap { color: var(--warn); }

/* 顶部资源条现在是按钮：必须覆盖 .chip 的 pointer-events:none，否则点不到。
   其他 chip 仍保持穿透，免得挡住画布上的放置。 */
.chip-btn {
  pointer-events: auto;
  border: 1px solid transparent; cursor: pointer;
  font: inherit; color: inherit; text-align: left;
}
.chip-btn:active { transform: scale(0.97); }
@media (hover: hover) { .chip-btn:hover { border-color: var(--panel-border); background: rgba(255,255,255,0.06); } }

/* ---------- 设置弹层 ---------- */
.set-group { margin: 16px 0 0; }
.set-group-title {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px; letter-spacing: 0.22em; color: #6f6f76;
  padding-bottom: 8px; margin-bottom: 4px;
  border-bottom: 1px solid rgba(244,244,246,0.1);
}
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 2px; min-height: 52px;
  border-bottom: 1px solid rgba(244,244,246,0.05);
  cursor: pointer;
}
.set-row.disabled { opacity: 0.4; pointer-events: none; }
.set-label { font-size: 13.5px; color: var(--text); line-height: 1.35; }
.set-label em {
  display: block; font-style: normal;
  font-size: 11px; color: #7d7d85; margin-top: 3px;
}
/* 黑白开关 */
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 46px; height: 26px; border-radius: 999px;
  background: rgba(244,244,246,0.14); position: relative;
  cursor: pointer; transition: background var(--dur-base) var(--ease-out-quint); margin: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #8a8a92; transition: transform var(--dur-base) var(--ease-spring), background var(--dur-base) var(--ease-out-quint);
}
.switch:checked { background: #f4f4f6; }
.switch:checked::after { transform: translateX(20px); background: #111114; }
.switch:focus-visible { outline: 2px solid #6fd6ff; outline-offset: 3px; }

#settings-modal .modal-card h2 { margin-bottom: 10px; }
#btn-close-settings { margin-top: 22px; }
/* debug 开启时给页面一个细微的边框提示，让人知道诊断层是开着的 */
body.debug-on #app::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 55;
  border: 1px solid rgba(111,214,255,0.25);
}
.menu-stats { margin-top: 16px; font-size: 12px; color: var(--muted); line-height: 1.8; }
.help-grid { display: grid; gap: 8px; margin: 14px 0; }
.help-grid > div { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 9px 11px; background: rgba(255,255,255,0.045); border-radius: 10px; }
.help-grid b { color: var(--accent); flex: none; font-weight: 600; }
.help-grid span { color: var(--muted); text-align: right; }

/* ---------- 启动 / 主页（黑白科技风） ---------- */
#boot {
  position: absolute; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: calc(var(--safe-t) + 18px) calc(var(--safe-r) + 20px)
           calc(var(--safe-b) + 18px) calc(var(--safe-l) + 20px);
  background: #08080a;
  overflow-y: auto;
  touch-action: pan-y;
}
.boot-pane {
  position: relative;
  width: min(560px, 100%);
  display: flex; flex-direction: column; gap: 22px;
  text-align: left;
}
/* 背景网格 + 扫描线：纯装饰，不接收指针事件 */
.home-grid {
  position: fixed; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 45%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 45%, #000 0%, transparent 78%);
}
.home-scan {
  position: fixed; inset: 0; pointer-events: none; opacity: 0.5;
  background: repeating-linear-gradient(
    180deg, transparent 0 3px, rgba(255,255,255,0.022) 3px 4px);
}
.home-mark { position: relative; }
.home-eyebrow {
  font-size: 10.5px; letter-spacing: 0.34em; color: #6f6f76;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 10px;
}
.home-title {
  margin: 0; line-height: 0.86;
  /* 高度也要参与限制：横屏矮屏（390px）下 13vw 会把按钮挤出屏幕 */
  font-size: clamp(38px, min(11vw, 13vh), 84px); font-weight: 800;
  letter-spacing: -0.03em; color: #f4f4f6;
}
.home-title.small { font-size: clamp(26px, 6vw, 40px); letter-spacing: 0.1em; }
.home-rule {
  height: 1px; margin: 18px 0 12px;
  background: linear-gradient(90deg, #f4f4f6, rgba(244,244,246,0.08));
}
.home-sub {
  margin: 0; font-size: 12.5px; color: #8a8a92; letter-spacing: 0.06em;
}
.home-mark.compact .home-rule { margin-bottom: 0; }

/* 按钮列表：左侧序号 + 主标签，像终端菜单 */
.home-actions { display: flex; flex-direction: column; gap: 9px; }
.home-btn {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px; min-height: 52px;
  background: transparent; color: #d6d6dc;
  border: 1px solid rgba(244,244,246,0.16); border-radius: 2px;
  font-size: 15px; font-weight: 600; letter-spacing: 0.04em;
  cursor: pointer; transition: border-color var(--dur-base) var(--ease-out-quint), background var(--dur-base) var(--ease-out-quint), color var(--dur-base) var(--ease-out-quint);
  text-align: left;
}
.home-btn:disabled { opacity: 0.34; cursor: default; }
.home-btn:not(:disabled):active { background: rgba(244,244,246,0.07); }
@media (hover: hover) {
  .home-btn:not(:disabled):hover {
    border-color: #f4f4f6; background: rgba(244,244,246,0.06); color: #fff;
  }
}
.hb-idx {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: #6f6f76; letter-spacing: 0.1em;
}
.home-btn.primary { border-color: #f4f4f6; color: #fff; }
.home-btn.primary .hb-idx { color: #f4f4f6; }
.hb-label { flex: 1 1 auto; }
.hb-note { font-size: 10.5px; color: #6f6f76; letter-spacing: 0.06em; }
.home-foot {
  display: flex; justify-content: space-between; gap: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px; letter-spacing: 0.16em; color: #5a5a61;
  border-top: 1px solid rgba(244,244,246,0.1); padding-top: 12px;
}

/* 加载页 */
.boot-bar {
  width: 100%; height: 3px; overflow: hidden;
  background: rgba(244,244,246,0.12);
}
#boot-fill {
  width: 0%; height: 100%;
  background: #f4f4f6;
  transition: width var(--dur-base) var(--ease-out-quint);
}
.boot-row {
  width: 100%; display: flex; justify-content: space-between;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: #8a8a92; letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  margin-top: -8px;
}
.boot-stages { display: flex; gap: 18px; flex-wrap: wrap; }
.stage {
  display: flex; align-items: center; gap: 7px;
  font-size: 10.5px; letter-spacing: 0.12em; color: #5a5a61;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.st-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: #3a3a40;
}
.stage.done { color: #d6d6dc; }
.stage.done .st-dot { background: #f4f4f6; }
.stage.active { color: #fff; }
.stage.active .st-dot {
  background: transparent; border: 1px solid #f4f4f6;
  animation: stPulse 1s ease-in-out infinite;
}
@keyframes stPulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

/* ---------- 竖屏提示 ---------- */
#rotate-hint {
  position: absolute; bottom: calc(var(--safe-b) + 4px); left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); background: rgba(10,14,24,0.8);
  padding: 4px 10px; border-radius: 999px; z-index: 30;
}
@media (orientation: landscape) { #rotate-hint { display: none !important; } }

/* 建造模式：收起摇杆，把左下角完全让给建造面板（摇杆层的 z-index 高于面板，
   不收起会遮挡建造列表下半部分的点击） */
body.building #joystick-zone { display: none; }

/* ---------- 小屏适配 ---------- */
@media (max-height: 480px) {
  .round-btn { width: 62px; height: 62px; }
  .round-btn .ico { font-size: 19px; }
  #joystick-zone { width: 124px; height: 124px; }
  #joystick-knob { width: 52px; height: 52px; left: 36px; top: 36px; }
  /* 横屏矮屏摇杆只有 124px，驾驶条能往左多借一点 */
  :root { --joy: 136px; }
  #pilot-bar { padding: 6px 8px 6px 12px; gap: 8px; }
  .pilot-title { font-size: 12px; }
  .pilot-hint { font-size: 10px; }
  .pbtn { padding: 9px 12px; font-size: 12px; min-height: 40px; }
  .panel { max-height: calc(100vh - var(--hud-bottom) - var(--safe-b) - 4px); width: min(300px, 44vw); }
  /* 横屏手机高度只有 390px 左右：信息栏压成单行，把空间留给可滚动的建造列表 */
  .build-info { font-size: 10.5px; max-height: 24%; padding-top: 5px; }
  .build-info .bi-desc {
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.3;
  }
  .build-info .bi-name { margin-bottom: 1px; }
  .build-info .bi-cost { margin-top: 3px; }
  .build-item { min-height: 38px; padding: 5px 6px; }
  .build-item .bi-t { font-size: 11.5px; }
  .size-row { padding: 4px 6px; }
  .size-btn { width: 28px; height: 28px; }
  #hud-top { font-size: 12px; }
  .chip { padding: 5px 10px; }
  /* 横屏矮屏：详情卡不能一路垂到右下角，否则会压住「交互 / 建造」按钮。
     底部给操作按钮留 162px（两个 62 圆钮 + 间距 + 安全边距），
     同时把卡片内边距收紧，让标题 / 状态 / 能量行 / 提示都在可视区内。 */
  #inspector {
    width: min(252px, 46vw);
    gap: 4px;
    padding: 8px;
    max-height: calc(100vh - var(--hud-bottom) - var(--safe-b) - 162px);
  }
  .insp-body { gap: 4px; min-height: 0; flex: 1 1 auto; }
  .insp-meta { font-size: 10px; }
  .insp-status { font-size: 11px; padding: 3px 7px; }
  .insp-title-mini { font-size: 10px; margin-top: 0; }
  .insp-row { min-height: 28px; padding: 4px 6px; font-size: 11.5px; }
  .insp-none, .insp-hint { font-size: 10px; }
  .insp-hint { padding-top: 4px; }
  /* 横屏手机高度只有 ~390px：启动页压成两栏，保证「开始探索」不被挤出屏幕 */
  #boot { padding-top: calc(var(--safe-t) + 8px); padding-bottom: calc(var(--safe-b) + 8px); }
  .boot-pane { gap: 8px; width: min(520px, 100%); }
  .boot-logo { font-size: 24px; letter-spacing: 0.16em; }
  .boot-sub { font-size: 11px; }
  .boot-tips { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .boot-tips li { font-size: 10px; padding: 5px 7px; }
  .boot-tips b { font-size: 10.5px; }
  #btn-start { padding: 11px; font-size: 14px; }
  .boot-note { font-size: 10px; }
}
@media (max-width: 560px) {
  .panel { width: 62vw; }
  .build-list { grid-template-columns: 1fr; }
  /* 竖屏窄屏：底部同时有摇杆（左）和操作圆钮（右），驾驶条横向挤不开。
     抬到摇杆上方、占满整行，文字换行、按钮始终单行。
     抬升量 = 摇杆高 150 + 底部边距 14 + 间距 12，少一像素都会压住摇杆。 */
  #pilot-bar {
    left: calc(var(--safe-l) + 8px);
    right: calc(var(--safe-r) + 8px);
    bottom: calc(var(--safe-b) + 176px);
    width: auto; max-width: none;
    padding: 7px 9px 7px 12px; gap: 8px;
  }
  .pilot-title { font-size: 12px; }
  .pilot-hint { font-size: 10px; }
  .pbtn { padding: 9px 10px; font-size: 12px; min-height: 40px; }
}
/* 触屏设备隐藏光标相关 */
@media (hover: none) { .icon-btn:hover { background: var(--panel); } }

/* ---------- 通用饼图选单（radial menu） ---------- */
.radial-menu {
  position: fixed; z-index: 70;
  transform: translate(-50%, -50%) scale(0.82);
  opacity: 0;
  transition: transform var(--dur-base) var(--ease-out-back), opacity var(--dur-base) var(--ease-out-quint);
  pointer-events: auto;
  touch-action: none;
}
.radial-menu.in { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.radial-menu.out { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }

.radial-scrim {
  position: fixed; inset: 0; z-index: 69;
  background: rgba(6,9,16,0.55);
  opacity: 0; transition: opacity var(--dur-base) var(--ease-out-quint);
}
.radial-scrim.in { opacity: 1; }
.radial-scrim.out { opacity: 0; }

.radial-svg { position: relative; display: block; overflow: visible; }

.radial-sector {
  --sec: #6fd6ff;
  fill: rgba(24,32,48,0.94);
  stroke: var(--sec);
  stroke-width: 1.6;
  opacity: 0.92;
  /* 预备选中时等比放大：矢量图元用 view-box 作变换基准 */
  transition: transform var(--dur-fast) var(--ease-spring), fill var(--dur-fast) var(--ease-out-quint), opacity var(--dur-fast) var(--ease-out-quint);
}
.radial-sector.current { stroke-width: 2.6; opacity: 1; }
.radial-sector.current + .radial-label { font-weight: 700; }
.radial-sector.hot {
  fill: rgba(111,214,255,0.26);
  stroke-width: 3;
  opacity: 1;
}

.radial-label {
  font-size: 13px; font-weight: 600;
  fill: #dbe6f7;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.radial-hint {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px; color: rgba(200,214,235,0.55);
  letter-spacing: 0.08em; pointer-events: none; white-space: nowrap;
}

/* ---------- 固定键的按压 / 长按视觉 ---------- */
.hb-fixed { transition: transform var(--dur-fast) var(--ease-spring), border-color var(--dur-fast) var(--ease-out-quint), background var(--dur-fast) var(--ease-out-quint); }
.hb-fixed.pressing { transform: scale(0.93); background: rgba(255,255,255,0.12); }
.hb-fixed.holding { border-color: var(--accent); background: rgba(111,214,255,0.2); }

/* 建筑枪是圆形图标键：和方形的背包键区分开，突出它是"工具"而不是"容器" */
.hb-fixed.round {
  width: 56px; min-height: 56px; height: 56px;
  border-radius: 50%;
  padding: 0;
  position: relative;
}
.hb-fixed.round .hb-fixed-ico { width: 24px; height: 24px; }
/* 圆键的文字标签压在圆内底部。早先放在圆外 bottom:-15px，
   结果在 390 高的横屏里直接贴到屏幕底边被切掉。 */
.hb-fixed.round .hb-fixed-lbl {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 8px; letter-spacing: 0.02em;
  opacity: 0.75;
}
.hb-fixed.round .hb-fixed-ico { margin-top: -6px; }
