* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: #0d0f17;
  color: #f2f4f8;
  font-family: 'DM Sans', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  /* 禁用 iPad 双击放大与 300ms 点击延迟，同时保留按钮单击 */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* 动态视口高度：避免 iOS/iPadOS 工具栏遮挡底部 */
  background: #10131c;
}

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

/* ===== 顶栏 ===== */
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  gap: 12px;
  pointer-events: none;
}
.topbar a, .topbar .top-center, .topbar .legend { pointer-events: auto; }
.home-link {
  color: #cfd6e2; text-decoration: none; font-weight: 600;
  background: rgba(0,0,0,0.35); padding: 6px 12px; border-radius: 20px;
  backdrop-filter: blur(4px);
}
.home-link:hover { color: #fff; }
.top-center { display: flex; align-items: center; gap: 14px;
  background: rgba(0,0,0,0.32); padding: 6px 16px; border-radius: 20px; backdrop-filter: blur(4px); }
.threat { color: #ffd34d; font-weight: 700; }
.timer { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.version { color: rgba(255,255,255,0.4); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { font-size: 13px; color: #dde3ee; background: rgba(0,0,0,0.32);
  padding: 6px 12px; border-radius: 20px; backdrop-filter: blur(4px); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.dot.p { background: #4f9bff; }
.dot.e { background: #c178f0; }

/* ===== HUD 角面板（左下=玩家1，右下=玩家2；均正向，PvP 并排操作） ===== */
.hud {
  position: absolute; bottom: 0;
  display: flex; flex-direction: column; gap: 6px;
  background: linear-gradient(to top, rgba(8,10,16,0.72), rgba(8,10,16,0));
  border-radius: 14px;
}
.hud-left {
  left: 0; align-items: flex-start;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.hud-right {
  right: 0; align-items: flex-end;
  padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) 12px;
}
.hud-energy { display: flex; align-items: center; gap: 8px; }
.hud-ctrl { display: flex; align-items: flex-end; gap: 8px; }
.hud-right .hud-ctrl { flex-direction: row-reverse; } /* 右侧镜像：选路在外缘 */
.hud-hint {
  position: absolute; bottom: calc(100% + 4px);
  background: rgba(255,221,77,0.95); color: #2a2410; font-weight: 700; font-size: 13px;
  padding: 6px 14px; border-radius: 999px; box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; white-space: nowrap; transition: opacity .12s;
}
.hud-left .hud-hint { left: 0; }
.hud-right .hud-hint { right: 0; }
.hud-hint.show { opacity: 1; }

.lane-select { display: flex; flex-direction: column; gap: 4px; }
.lane-btn {
  background: rgba(255,255,255,0.08); color: #dde3ee; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.lane-btn.active { background: #ffd34d; color: #2a2410; border-color: #ffd34d; }
.lane-btn.disabled { opacity: 0.32; cursor: not-allowed; filter: grayscale(0.6); text-decoration: line-through; }
.lane-btn.disabled.active { background: rgba(255,255,255,0.08); color: #dde3ee; border-color: rgba(255,255,255,0.12); }

.pips { display: flex; gap: 2px; }
.pip { width: 9px; height: 16px; border-radius: 2px; background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.1); transition: background .12s; }
.pip.on { background: linear-gradient(to top, #c061ff, #ffd34d); border-color: #ffe9a8; }
.energy-num { font-weight: 700; color: #ffd34d; font-size: 14px; }

.unit-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.unit-btn {
  position: relative;
  width: 56px; height: 58px;
  border: 2px solid rgba(255,255,255,0.18);
  border-radius: 11px;
  background: linear-gradient(to bottom, rgba(48,54,72,0.95), rgba(30,34,48,0.95));
  color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .08s, border-color .12s, opacity .12s;
}
.unit-btn:hover { border-color: #ffd34d; transform: translateY(-2px); }
.unit-btn:active { transform: translateY(0) scale(0.96); }
.unit-btn.disabled { opacity: 0.42; pointer-events: auto; cursor: not-allowed; filter: grayscale(0.4); }
.unit-btn.disabled:hover { border-color: rgba(255,255,255,0.18); transform: none; }
.ub-icon { font-size: 20px; line-height: 1; }
.ub-name { font-size: 10px; font-weight: 600; }
.ub-cost { font-size: 10px; color: #ffd34d; font-weight: 700; }
.ub-tip {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  width: 170px; background: rgba(12,14,22,0.96); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.4; color: #dde3ee;
  opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 5;
}
.unit-btn:hover .ub-tip { opacity: 1; }
/* 触摸设备（iPad 等）无真正 hover：禁用 tooltip 与 hover 位移，避免点完卡住/抖动 */
@media (hover: none) {
  .unit-btn:hover .ub-tip { opacity: 0; }
  .unit-btn:hover { transform: none; border-color: rgba(255,255,255,0.18); }
}
.unit-btn.flash { border-color: #4fd06a; box-shadow: 0 0 14px rgba(79,208,106,0.7); }
/* 未解锁兵种：灰显 + 锁定遮罩 */
.ub-lock {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border-radius: 12px;
  background: rgba(12,14,22,0.82); color: #cfd6e2;
  font-size: 13px; font-weight: 700; line-height: 1.2; text-align: center;
}
.unit-btn.locked { filter: grayscale(0.7); cursor: not-allowed; }
.unit-btn.locked .ub-lock { display: flex; }
.unit-btn.locked:hover { transform: none; border-color: rgba(255,255,255,0.18); }
.unit-btn.locked:hover .ub-tip { opacity: 0; }

/* 狙击手/投石机冷却 or 就绪 覆盖层 */
.ub-cd {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  border-radius: 12px; background: rgba(12,14,22,0.7);
  color: #fff; font-size: 14px; font-weight: 800;
}
.unit-btn.ready { border-color: #4fd06a; box-shadow: 0 0 12px rgba(79,208,106,0.7); }
.unit-btn.ready .ub-cd { background: rgba(20,60,30,0.35); color: #8dff9e; }

/* 放置/瞄准提示横幅 */
.aimhint {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(255,221,77,0.95); color: #2a2410;
  font-weight: 700; font-size: 15px; padding: 8px 18px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; z-index: 8; white-space: nowrap;
  transition: opacity .12s;
}
.aimhint.show { opacity: 1; }
.unit-btn.shake { animation: shake .25s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }

/* ===== 结算 ===== */
.result {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,14,0.7); backdrop-filter: blur(3px); z-index: 10;
}
.result.hidden { display: none; }
.result-card {
  background: linear-gradient(to bottom, #232838, #161a26);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 18px;
  padding: 32px 40px; text-align: center; min-width: 300px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.result-card h2 { font-size: 32px; margin-bottom: 10px; }
.result-card h2.win { color: #ffd34d; }
.result-card h2.lose { color: #e0556f; }
.result-card p { color: #cfd6e2; margin-bottom: 22px; }
.result-btns { display: flex; gap: 12px; justify-content: center; }
#restart-btn, .result-btns button {
  background: #ffd34d; color: #2a2410; border: none; border-radius: 10px;
  padding: 12px 24px; font-size: 16px; font-weight: 700; cursor: pointer;
}
#restart-btn:hover { background: #ffe07a; }
.result-btns .ghost { background: rgba(255,255,255,0.1); color: #dde3ee; }
.result-btns .ghost:hover { background: rgba(255,255,255,0.18); }

/* ===== 开始菜单 ===== */
.menu {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,14,0.82); backdrop-filter: blur(4px); z-index: 12;
}
.menu.hidden { display: none; }
.menu-card {
  background: linear-gradient(to bottom, #232838, #161a26);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 20px;
  padding: 36px 40px; text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,0.55);
}
.menu-card h1 { font-size: 26px; margin-bottom: 8px; color: #fff; }
.menu-card p { color: #aeb6c5; margin-bottom: 24px; }
.menu-btns { display: flex; flex-direction: column; gap: 12px; }
.mode-btn {
  background: linear-gradient(to bottom, #3a6fd0, #2f57b0); color: #fff;
  border: 1px solid rgba(255,255,255,0.18); border-radius: 12px;
  padding: 16px 36px; font-size: 18px; font-weight: 700; cursor: pointer;
  transition: transform .08s, filter .12s;
}
.mode-btn:hover { filter: brightness(1.12); transform: translateY(-2px); }
.mode-btn:active { transform: translateY(0) scale(0.97); }
#mode-pvp { background: linear-gradient(to bottom, #9d4bd0, #7a37a8); }

.hint {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: rgba(255,255,255,0.35); white-space: nowrap; pointer-events: none;
}

/* 解锁提示 toast */
.toast {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: linear-gradient(to bottom, rgba(255,221,77,0.96), rgba(255,180,60,0.96));
  color: #2a2410; font-weight: 700; font-size: 18px;
  padding: 10px 22px; border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none; z-index: 9; white-space: nowrap;
}
.toast.show { animation: toastPop 1.9s ease-out forwards; }
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-50%) translateY(4px) scale(0.9); }
  12% { opacity: 1; transform: translateX(-50%) translateY(-8px) scale(1.05); }
  20% { transform: translateX(-50%) translateY(-8px) scale(1); }
  80% { opacity: 1; transform: translateX(-50%) translateY(-8px) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(1); }
}

@media (max-width: 720px) {
  .unit-btn { width: 50px; height: 52px; }
  .ub-icon { font-size: 18px; }
  .ub-name { font-size: 9px; }
  .hint { display: none; }
  .legend { display: none; }
}
