/* ==========================================================================
   touch.css - 移动端触摸操控层
   --------------------------------------------------------------------------
   只在触摸设备上进对局时才可见（由 touch-controls.js 控制 hidden 属性 +
   body.touch 类）。桌面端整份样式实际上都是惰性的。

   排版思路：三个操作区分居屏幕三角，中间全部留空 —— 火箭是这款游戏的
   主角，控件绝不能盖住机身。所有定位都用「距边距离 + env(safe-area)」，
   这样刘海屏/圆角屏上按钮不会被系统手势条吃掉。

   ⚠️ 尺寸单位一律用 px 而非 vw：触摸目标有物理下限（约 44px），
      用 vw 会在窄屏上缩到点不准。这也是本项目唯一用固定 px 的地方。
   ========================================================================== */

/* 触摸设备上隐藏「键盘图例」：手机用户看到一排键位只会困惑。
   图例是 Tutorial 层左下角常驻的 .hud-hints（触摸层也在左下角，
   不藏会直接叠在一起）；指导卡片 .tutorial 同理，它教的全是键盘操作。 */
body.touch .hud-hints,
body.touch .tutorial {
  display: none !important;
}

.touch-flight {
  position: absolute;
  inset: 0;
  z-index: 20;               /* HUD 画布是 10，触摸层压在它上面 */
  pointer-events: none;      /* 整层不拦截，只有子控件可点 —— 保证捏合缩放能落到 canvas */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-flight[hidden] { display: none; }

/* ------------------------------------------------------------------ 摇杆 */

.tc-stick {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: calc(20px + env(safe-area-inset-left, 0px));
  width: 132px;
  height: 132px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;        /* 关键：不设的话浏览器会把手势当滚动抢走 */
  display: grid;
  place-items: center;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.tc-stick__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: radial-gradient(circle at 50% 50%, rgba(12, 18, 32, .62), rgba(12, 18, 32, .24));
  backdrop-filter: blur(3px);
}

.tc-stick__knob {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(150deg, rgba(56, 189, 248, .78), rgba(99, 102, 241, .68));
  border: 1px solid rgba(219, 230, 245, .42);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .3);
  transition: box-shadow var(--t-fast);
  will-change: transform;    /* 每帧改 transform，提前提升为合成层 */
}

.tc-stick.held .tc-stick__ring { border-color: var(--accent); background: rgba(12, 18, 32, .74); }
.tc-stick.held .tc-stick__knob { box-shadow: 0 0 18px rgba(56, 189, 248, .8), inset 0 1px 0 rgba(255, 255, 255, .35); }

.tc-stick__label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* 滚转摇杆放右侧：与俯仰摇杆分开，两个拇指各管一个，
   这样「一边压弯一边滚转」可以同时进行（键盘上就是 W+Q）。 */
.tc-stick--roll {
  left: auto;
  right: calc(96px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 104px;
  height: 104px;
}

.tc-stick--roll .tc-stick__knob { width: 44px; height: 44px; }

/* ------------------------------------------------------------- 节流滑块 */

/* 竖屏时贴右缘垂直居中会压住 HUD 的速度带（M 数、kW/m2 标签），
   放到右下角、滚转摇杆正上方 —— 那里是 HUD 面板之间的天然空档，
   而且节流在起飞阶段是高频操作，离拇指近才对。 */
.tc-throttle {
  position: absolute;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 150px;
  pointer-events: auto;
  touch-action: none;
  display: grid;
  place-items: center;
}

/* 命中区比视觉条宽：视觉上 18px 的竖条手指点不准，
   用 padding 把可点区域撑到 56px，但背景透明不影响观感。 */
.tc-throttle__track {
  position: relative;
  width: 18px;
  height: 100%;
  border-radius: 99px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 18, 32, .72);
  backdrop-filter: blur(3px);
  overflow: hidden;
}

.tc-throttle__fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(180deg, var(--hot), var(--accent));
  box-shadow: 0 0 12px rgba(56, 189, 248, .5);
  transition: height 80ms linear;
  pointer-events: none;
}

.tc-throttle.held .tc-throttle__track { border-color: var(--accent); }

.tc-throttle__label {
  position: absolute;
  bottom: -18px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------- 动作按钮 */

.tc-actions {
  position: absolute;
  right: calc(96px + env(safe-area-inset-right, 0px));
  bottom: calc(136px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 8px;
  justify-items: end;
  pointer-events: none;
}

.tc-act {
  pointer-events: auto;
  touch-action: none;
  min-width: 60px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--ink);
  background: rgba(12, 18, 32, .82);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms, background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

.tc-act.held,
.tc-act:active {
  transform: scale(.94);
  background: rgba(56, 189, 248, .3);
  border-color: var(--accent);
  color: #fff;
}

/* 点火是整局最关键、也是唯一「按错就完了」以外的主动作（它其实是必须按的），
   给它最高视觉权重，并且做得比其它键大一圈，方便盲按。 */
.tc-act--primary {
  grid-column: span 2;
  min-width: 128px;
  height: 52px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .16em;
  color: #04121f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(56, 189, 248, .3);
}

.tc-act--primary.held,
.tc-act--primary:active {
  background: linear-gradient(135deg, #7dd3fc, #818cf8);
  color: #04121f;
}

/* ------------------------------------------------------------- 逃生出口 */

/* 返回工坊放顶部居中：
   它是唯一会**丢掉当前飞行**的按钮，绝不能顺手碰到（远离双拇指区）。
   不能放左上（任务时钟 T+ 画在那里，实测被裁切）也不能放右上
   （PHASE 阶段横幅在那里）；顶部中间是 HUD 两条信息之间的空档。 */
.tc-escape {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  touch-action: none;
  height: 34px;
  padding: 0 12px;
  border-radius: 99px;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(12, 18, 32, .78);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.tc-escape.held,
.tc-escape:active {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(22, 32, 58, .92);
}

/* ------------------------------------------------------------ 横屏适配 */

/* 横屏时高度只有 390px 左右，摇杆和按钮簇会挤在一起。
   把两侧控件都压小、并排到同一水平线上。 */
@media (max-height: 520px) {
  .tc-stick { width: 104px; height: 104px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .tc-stick__knob { width: 42px; height: 42px; }
  .tc-stick--roll { width: 82px; height: 82px; right: calc(84px + env(safe-area-inset-right, 0px)); }
  .tc-stick--roll .tc-stick__knob { width: 34px; height: 34px; }
  .tc-stick__label { display: none; }
  /* 节流条压到最矮并贴到右下角：横屏时 HUD 速度带占据右缘上半，
     竖屏用的 bottom:168px 会把它顶进速度带里（实测）。 */
  .tc-throttle { height: 118px; width: 44px; bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
  .tc-throttle__label { display: none; }
  .tc-actions {
    right: calc(84px + env(safe-area-inset-right, 0px));
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(4, auto);
    gap: 6px;
  }
  .tc-act { min-width: 52px; height: 34px; font-size: 11px; padding: 0 9px; }
  .tc-act--primary { grid-column: span 1; min-width: 62px; height: 34px; font-size: 12px; letter-spacing: .06em; }
}
