/* ============================================================
   style.css — 全屏黑底游戏样式（触屏优先）
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%;
  background: #0d0f1a; color: #eee;
  font-family: -apple-system, "PingFang SC", sans-serif;
  overflow: hidden;
  touch-action: none;               /* 全局掐掉浏览器手势 */
  user-select: none; -webkit-user-select: none;
}
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
/* 大厅内容高（竖排元素多），横屏矮屏塞不下：允许滚动。
   居中必须用 flex-start + margin:auto（直接 center 溢出后 scrollTop 无法为负，顶部内容永久截断；
   auto margin 富余时居中、溢出时归零从顶排起，顶部标题/金币永远可达） */
#screen-lobby { overflow-y: auto; justify-content: flex-start; }
#screen-lobby > :first-child { margin-top: auto; }
#screen-lobby > :last-child { margin-bottom: auto; }

/* ---------- 大厅 ---------- */
#screen-lobby h1 { font-size: 20px; margin-bottom: 0; color: #ffd24d; text-shadow: 0 0 18px rgba(255,210,77,.4); }
.lobby-coins-row { font-size: 15px; margin-bottom: 0; }
.portrait-wrap { width: min(92vw, 620px); height: 110px; }
#lobby-canvas { width: 100%; height: 100%; }
.char-cards { display: flex; gap: 10px; margin: 4px 0; }
.char-card {
  border: 2px solid #3a3f5c; border-radius: 12px; padding: 5px 12px;
  text-align: center; cursor: pointer; min-width: 122px; background: #171a2b;
}
.char-card.selected { border-color: #ffd24d; box-shadow: 0 0 14px rgba(255,210,77,.35); }
.char-card b { display: block; font-size: 16px; }
.char-skill { font-size: 11px; color: #9aa3c7; display: block; margin-top: 4px; }
.equip-bar { font-size: 12px; color: #9aa3c7; margin: 4px 0; }
.shop-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.shop-row button {
  background: #22263f; color: #eee; border: 1px solid #3a3f5c; border-radius: 10px;
  padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.shop-row button:active { background: #2e3355; }
#shop-msg { font-size: 12px; color: #7ee787; max-width: 180px; }
#btn-start {
  background: linear-gradient(135deg, #ff6b3d, #ff3d6b); color: #fff;
  border: none; border-radius: 14px; padding: 10px 54px; font-size: 18px; font-weight: bold; cursor: pointer;
  box-shadow: 0 4px 20px rgba(255,80,80,.4);
}
#btn-start:active { transform: scale(.97); }

/* ---------- 安装引导（iOS 加主屏 / 安卓 APK 下载） ---------- */
#install-bar { margin-top: 12px; font-size: 13px; }
#apk-link {
  display: inline-block; padding: 8px 22px; border-radius: 10px;
  background: #22263f; border: 1px solid #4dff88; color: #7ee787;
  text-decoration: none; font-weight: bold;
}
#apk-link:active { background: #2e3355; }
#ios-install-tip { color: #9aa3c7; max-width: 320px; display: inline-block; }

/* ---------- 战斗 ---------- */
#screen-game { background: #000; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-top {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.hp-wrap {
  position: relative; width: min(46vw, 260px); height: 18px;
  background: rgba(0,0,0,.55); border-radius: 9px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.25);
}
#hud-hp { height: 100%; width: 100%; background: linear-gradient(90deg, #4dff88, #ffd24d); transition: width .15s; }
#hud-hp-text { position: absolute; inset: 0; font-size: 11px; line-height: 18px; text-align: center; text-shadow: 0 1px 2px #000; }
.hud-stats { display: flex; gap: 12px; font-size: 12px; text-shadow: 0 1px 2px #000; }
#hud-boss-wrap {
  position: relative; align-self: center; width: min(60vw, 380px); height: 14px;
  background: rgba(0,0,0,.55); border-radius: 7px; overflow: hidden; border: 1px solid #c94dff;
}
#hud-boss { height: 100%; width: 100%; background: linear-gradient(90deg, #8a2be2, #c94dff); }
#hud-boss-text { position: absolute; inset: 0; font-size: 10px; line-height: 14px; text-align: center; }

/* 联机队伍面板（P2-2）：右上角列，色点+名字+迷你血条；离线置灰 */
#hud-team {
  align-self: flex-end;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-end;
  pointer-events: none;
}
.hud-team-row {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; line-height: 1; color: #eee; text-shadow: 0 1px 2px #000;
  background: rgba(0,0,0,.4); border-radius: 8px; padding: 3px 8px;
  width: max-content; max-width: 40vw;
}
.hud-team-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.hud-team-row .tname { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-team-row .thp {
  width: 44px; height: 4px; flex: none;
  background: rgba(255,255,255,.18); border-radius: 2px; overflow: hidden;
}
.hud-team-row .thp i { display: block; height: 100%; background: #5cc9ff; border-radius: 2px; transition: width .15s; }
.hud-team-row.dead { opacity: .5; }
.hud-team-row.dead .thp i { width: 0 !important; }
.hud-team-row.offline { opacity: .45; filter: grayscale(1); }
#banner {
  position: absolute; top: 32%; left: 0; right: 0; text-align: center;
  font-size: 24px; font-weight: bold; color: #ffd24d;
  text-shadow: 0 0 16px rgba(0,0,0,.9), 0 2px 4px #000;
}

/* 左摇杆（浮空基座，按下才出现） */
#joystick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 45%; pointer-events: auto; }
.joy-base {
  display: none; position: absolute; width: 110px; height: 110px;
  border-radius: 50%; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.25);
}
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%; background: rgba(255,255,255,.35);
}

/* 右侧动作按钮 */
#action-btns {
  position: absolute; right: 14px; bottom: max(20px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: 64px 64px; gap: 12px; pointer-events: auto;
  justify-items: center; align-items: center;
}
.abtn {
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.3);
  color: #fff; font-size: 22px; position: relative;
}
.abtn.big { width: 76px; height: 76px; font-size: 30px; background: rgba(255,80,80,.25); border-color: rgba(255,120,120,.5); }
.abtn.wide { grid-column: span 2; }
.abtn.active { background: rgba(255,255,255,.35); }
.abtn.cooling { opacity: .45; }
.abtn.active-skill { border-color: #ffd24d; box-shadow: 0 0 12px rgba(255,210,77,.6); }
.btn-cd, .btn-count {
  position: absolute; right: -2px; bottom: -2px;
  font-size: 12px; background: rgba(0,0,0,.7); border-radius: 8px; padding: 1px 5px;
}

/* ---------- 结算 ---------- */
#screen-result h2 { font-size: 34px; margin-bottom: 16px; }
#result-detail { font-size: 16px; line-height: 2; text-align: center; margin-bottom: 24px; }
.result-btns { display: flex; gap: 14px; }
.result-btns button {
  border: none; border-radius: 12px; padding: 13px 34px; font-size: 17px; cursor: pointer; color: #fff;
}
#btn-again { background: linear-gradient(135deg, #ff6b3d, #ff3d6b); }
#btn-lobby { background: #2e3355; }

/* ---------- 竖屏提示 ---------- */
#rotate-tip {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: #0d0f1a; color: #ffd24d; font-size: 20px;
  align-items: center; justify-content: center; text-align: center;
}
@media (orientation: portrait) {
  #rotate-tip { display: flex; }
  /* ⚠️ 竖屏隐藏清单与 main.js SCREENS 数组两处必须同步（PLAN 风险 2），新 screen 漏一处=竖屏漏出 */
  #screen-lobby, #screen-game, #screen-result, #screen-auth, #screen-room { display: none !important; }
}

/* ---------- 认证屏幕 ---------- */
/* 显隐全由 main.js showScreen 内联控制；这里写 display:none 会跟内联''打架（ID 特异性回退即 none） */
#screen-auth {
  background: linear-gradient(135deg, #0d0f1a, #1a1d2e);
  padding: 20px;
}
/* 表单解锁：全局 touch-action:none/user-select:none 会掐死输入框（点不聚焦/选不了字）；
   font-size:16px 防 iOS 聚焦整页缩放（PLAN 风险 3） */
.screen input, .screen textarea {
  touch-action: manipulation;
  user-select: text; -webkit-user-select: text;
  pointer-events: auto;
  font-size: 16px;
}

.auth-container {
  position: relative; width: 100%; max-width: 380px;
  background: #171a2b; border-radius: 16px; padding: 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

.auth-close-btn {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: none; color: #9aa3c7;
  font-size: 24px; cursor: pointer;
}

/* Gate 面板 */
.auth-tab-row {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.auth-tab {
  flex: 1; padding: 8px; border: 1px solid #3a3f5c; border-radius: 8px;
  background: #22263f; color: #9aa3c7; cursor: pointer;
}
.auth-tab.active {
  background: #3a3f5c; color: #fff; border-color: #ffd24d;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 10px 12px; border: 1px solid #3a3f5c; border-radius: 8px;
  background: #0d0f1a; color: #eee;
  font-size: 16px; /* iOS 聚焦自动缩放阈值：≥16px 才不触发整页 zoom */
}
.auth-form button {
  padding: 10px; border: none; border-radius: 8px;
  background: linear-gradient(135deg, #ff6b3d, #ff3d6b); color: #fff;
  font-size: 16px; font-weight: bold; cursor: pointer;
}
.auth-error {
  font-size: 12px; color: #ff5252; min-height: 16px;
}

/* Profile 面板 */
.auth-profile-panel h3 {
  text-align: center; margin-bottom: 16px; color: #ffd24d;
}

.profile-avatar-wrap {
  display: flex; justify-content: center; margin-bottom: 16px;
}
#auth-profile-avatar {
  border-radius: 50%; background: #1a1d2e;
  border: 2px solid #3a3f5c;
}

.profile-section { margin-bottom: 14px; }
.profile-section label {
  display: block; font-size: 12px; color: #9aa3c7; margin-bottom: 6px;
}

/* 内置头像网格 */
.builtin-avatar-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.builtin-avatar-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid #3a3f5c; background: var(--c);
  cursor: pointer;
}
.builtin-avatar-btn.selected {
  border-color: #ffd24d; box-shadow: 0 0 10px rgba(255,210,77,.5);
}

/* 上传头像 */
#auth-upload-file {
  display: block; width: 100%; padding: 8px; margin-bottom: 8px;
  border: 1px solid #3a3f5c; border-radius: 6px;
  background: #0d0f1a; color: #eee; font-size: 12px;
}
#auth-upload-confirm {
  width: 100%; padding: 8px; border: none; border-radius: 6px;
  background: #2e3355; color: #eee; cursor: pointer;
}
#auth-upload-confirm:not(:disabled) {
  background: #7ee787; color: #0d0f1a; font-weight: bold;
}

/* 改名 */
#auth-profile-name {
  width: 100%; padding: 8px; margin-bottom: 8px;
  border: 1px solid #3a3f5c; border-radius: 6px;
  background: #0d0f1a; color: #eee; font-size: 16px; /* 同上：防 iOS 聚焦缩放 */
}
#auth-name-submit {
  width: 100%; padding: 8px; border: none; border-radius: 6px;
  background: #2e3355; color: #eee; cursor: pointer;
}
#auth-name-submit:not(:disabled) {
  background: #7ee787; color: #0d0f1a; font-weight: bold;
}

/* 登出 */
.btn-logout {
  width: 100%; padding: 10px; margin-top: 12px;
  border: none; border-radius: 8px;
  background: #c94dff; color: #fff; cursor: pointer;
}

/* 大厅账号栏 */
.lobby-account-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px; font-size: 14px;
}
.lobby-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #1a1d2e; border: 1px solid #3a3f5c;
  overflow: hidden;
}
.lobby-avatar canvas { width: 100%; height: 100%; }
.btn-login {
  padding: 6px 14px; border: none; border-radius: 6px;
  background: #5cc9ff; color: #0d0f1a; font-weight: bold; cursor: pointer;
}

/* 联机组队按钮 */
.btn-coop {
  background: linear-gradient(135deg, #5cc9ff, #7ee787); color: #0d0f1a;
  border: none; border-radius: 14px; padding: 10px 34px; font-size: 16px; font-weight: bold; cursor: pointer;
  box-shadow: 0 4px 16px rgba(92,201,255,.3);
  margin-top: 8px;
}
.btn-coop:active { transform: scale(.97); }

/* ---------- 房间（联机组队，P2-1） ---------- */
/* 沿用大厅滚动居中技巧：overflow-y:auto + 内容首尾 margin auto（直接 center 溢出会截顶） */
#screen-room {
  overflow-y: auto; justify-content: flex-start;
  background: linear-gradient(135deg, #0d0f1a, #1a1d2e);
}
.room-section {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: min(400px, 88vw); margin: auto 0; padding: 24px 0;
}
.room-section h2 { margin: 0; color: #ffd24d; font-size: 20px; }
.room-join-row { display: flex; gap: 8px; align-items: center; }
#room-code-input { width: 150px; text-align: center; letter-spacing: 6px; }
.room-msg { min-height: 18px; font-size: 13px; color: #ff9c40; text-align: center; }
.btn-room-primary {
  background: linear-gradient(135deg, #ff6b3d, #ff3d6b); color: #fff;
  border: none; border-radius: 14px; padding: 10px 54px; font-size: 18px; font-weight: bold; cursor: pointer;
  box-shadow: 0 4px 20px rgba(255,80,80,.4);
}
.btn-room-primary:active { transform: scale(.97); }
.btn-room-primary[hidden] { display: none; }
.btn-room-secondary {
  background: #22263f; color: #eee; border: 1px solid #3a3f5c;
  border-radius: 12px; padding: 10px 28px; font-size: 15px; cursor: pointer;
}
.btn-room-secondary:active { transform: scale(.97); }
.room-code-row { display: flex; align-items: center; gap: 14px; }
.room-code {
  font-size: 44px; letter-spacing: 12px; font-weight: bold; color: #ffd24d;
  text-shadow: 0 0 18px rgba(255,210,77,.4); padding-left: 12px; /* 抵消 letter-spacing 尾距 */
}
.room-members { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.room-member-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: #171a2b; border: 1px solid #3a3f5c; border-radius: 12px;
}
.room-member-card.me { border-color: #ffd24d; }
.room-member-card.offline { opacity: .45; }
.room-member-name { flex: 1; font-size: 14px; }
.room-member-tag { font-size: 12px; color: #ffd24d; }

/* ---------- 全局 toast（2s 自动消失，main.js 控制） ---------- */
#toast {
  position: fixed; left: 50%; top: 14%;
  transform: translateX(-50%);
  background: rgba(20, 24, 44, .92); color: #ffd24d;
  border: 1px solid #3a3f5c; border-radius: 10px;
  padding: 10px 22px; font-size: 15px; font-weight: bold;
  pointer-events: none; opacity: 0; transition: opacity .25s;
  z-index: 999; white-space: nowrap;
}
#toast.show { opacity: 1; }
