/* 移动端适配 · 雷霆前线 THUNDER FRONTLINE
 * 桌面端不受影响，所有规则限定在小屏 / 粗指针设备下生效 */

/* 安全区与动态视口高度（由 js/mobile.js 写入 --vh） */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --touch-btn: 60px;
}

html, body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* 大厅等非战斗界面允许纵向滚动时的手势优化 */
#screen-auth, #screen-lobby, #screen-loading {
  touch-action: pan-x pan-y;
}

/* 战斗界面禁止浏览器手势（滚动 / 缩放 / 双击放大） */
#screen-battle, #screen-battle * {
  -webkit-touch-callout: none;
}
#screen-battle {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* 通用：小屏下按钮最小触摸目标 */
@media (max-width: 900px), (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.big { padding: 15px 40px; font-size: 18px; letter-spacing: 4px; }
  .auth-tab, .shop-tab, .arm-tab { min-height: 44px; display: flex; align-items: center; justify-content: center; }
}

/* ============ 登录 / 加载 ============ */
@media (max-width: 900px) {
  #screen-auth {
    flex-direction: column;
    gap: 26px;
    padding: calc(20px + var(--sat)) 18px calc(28px + var(--sab));
    overflow-y: auto;
    justify-content: flex-start;
    padding-top: calc(48px + var(--sat));
  }
  .auth-hero { max-width: 100%; width: 100%; }
  .auth-hero h1 { font-size: 34px; letter-spacing: 6px; }
  .auth-hero ul { margin-top: 18px; }
  .auth-hero li { font-size: 12.5px; letter-spacing: 1px; margin-bottom: 9px; }
  .auth-box { width: 100%; max-width: 440px; padding: 24px 20px 22px; }
  .load-logo { font-size: 40px; letter-spacing: 8px; text-indent: 8px; }
  .load-sub { font-size: 12px; letter-spacing: 6px; text-indent: 6px; }
  .load-bar-wrap { width: min(78vw, 340px); }
  .load-tip { padding: 0 20px; bottom: calc(28px + var(--sab)); }
}

/* ============ 大厅：底部导航 ============ */
@media (max-width: 900px) {
  #screen-lobby { background: var(--bg-1); }
  .lobby-topbar {
    height: auto;
    min-height: 56px;
    padding: calc(8px + var(--sat)) 12px 8px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .profile-chip { border-right: none; padding-right: 0; gap: 9px; }
  .avatar { width: 34px; height: 34px; font-size: 16px; }
  .profile-name { font-size: 13.5px; }
  .exp-bar { width: 64px; }
  .wallet { margin-left: auto; gap: 8px; }
  .wallet-item { padding: 7px 10px; font-size: 12.5px; min-height: 36px; }

  .lobby-body { flex-direction: column; }
  .content {
    padding: 16px 14px calc(96px + var(--sab));
    order: 1;
  }
  .rail {
    order: 2;
    width: 100%;
    flex-shrink: 0;
    flex-direction: row;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    padding: 6px 4px calc(6px + var(--sab));
    gap: 2px;
    background: rgba(8, 13, 19, .96);
    border-right: none;
    border-top: 1px solid var(--line);
    backdrop-filter: blur(8px);
    justify-content: space-around;
  }
  .rail-item {
    flex: 1;
    padding: 8px 2px 7px;
    font-size: 11px;
    letter-spacing: 1px;
    gap: 4px;
    border-left: none;
    border-top: 2px solid transparent;
    min-height: 56px;
    justify-content: center;
  }
  .rail-item svg { width: 21px; height: 21px; }
  .rail-item.active {
    border-left-color: transparent;
    border-top-color: var(--gold);
    background: linear-gradient(180deg, rgba(255, 179, 0, .12), transparent);
  }
  .rail-badge { top: 6px; right: calc(50% - 20px); }

  .lobby-footer { display: none; }

  .panel-title h2 { font-size: 19px; letter-spacing: 4px; }
  .panel-title { flex-wrap: wrap; gap: 6px 10px; margin-bottom: 16px; }

  .hall-grid { grid-template-columns: 1fr; }
  .mode-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .mode-card b { font-size: 14.5px; }
  .map-strip { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
  .map-cell canvas { height: 78px !important; }
  .mc-random { height: 78px; }

  .goods-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .goods-card { padding: 12px; }
  .goods-desc { min-height: 0; }
  .gun-preview { height: 66px; }
  .gun-preview svg { width: 160px; }

  .armory-layout { grid-template-columns: 1fr; }
  .arm-detail { position: static; }
  .arm-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

  .signin-days { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .sign-day { padding: 12px 6px 10px; }
  .sd-reward { font-size: 12.5px; }

  .maps-grid { grid-template-columns: 1fr; }
  .map-big-card canvas { height: 150px !important; }

  .settings-form { max-width: 100%; }
  .set-row { flex-wrap: wrap; gap: 10px; }
  .set-row label { width: 100%; }
  .set-row input[type=range] { flex: 1; min-height: 32px; }
}

/* 超小屏微调 */
@media (max-width: 420px) {
  .mode-cards { grid-template-columns: 1fr 1fr; }
  .map-strip { grid-template-columns: 1fr 1fr; }
  .goods-grid { grid-template-columns: 1fr 1fr; }
  .signin-days { grid-template-columns: repeat(2, 1fr); }
  .end-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ============ 战斗 HUD：小屏压缩 ============ */
@media (max-width: 900px) {
  #hud-topbar { top: calc(8px + var(--sat)); transform: translateX(-50%) scale(.86); transform-origin: top center; }
  #tb-objective { top: 64px; font-size: 11px; max-width: 92vw; white-space: normal; text-align: center; }
  #minimap-wrap { top: calc(8px + var(--sat)); left: calc(8px + var(--sal)); width: 112px; }
  #minimap { width: 112px !important; height: 112px !important; }
  #mm-mapname, #mm-mode { font-size: 10px; }
  #killfeed { top: calc(8px + var(--sat)); right: calc(8px + var(--sar)); max-width: 46vw; }
  .kf-row { font-size: 11px; padding: 4px 8px; }
  #hud-bottom-left { left: calc(10px + var(--sal)); bottom: calc(150px + var(--sab)); width: 172px; }
  .hp-plate { padding: 8px 10px 9px; }
  #hp-num { font-size: 22px; min-width: 40px; }
  #hud-bottom-right { right: calc(10px + var(--sar)); bottom: calc(150px + var(--sab)); }
  .ammo-plate { padding: 7px 12px 9px; }
  #ammo-mag { font-size: 28px; }
  #wpn-name { font-size: 11px; }
  #slot-bar { display: none; }
  #crosshair { transform: scale(.9); }
  #banner-title { font-size: 28px; letter-spacing: 7px; text-indent: 7px; }
  #banner-sub { font-size: 12px; }
  #scoreboard { width: calc(100vw - 24px); padding: 14px; }
  .end-box { width: calc(100vw - 28px); padding: 26px 18px; }
  #end-result { font-size: 36px; letter-spacing: 10px; text-indent: 10px; }
  .end-btns { flex-direction: column; }
  .end-btns .btn { width: 100%; }
  .pm-box { width: calc(100vw - 40px); max-width: 340px; }
  #fps-counter { top: 70px; right: calc(10px + var(--sar)); }
  #bomb-status { bottom: 220px; }
  #center-prompt { top: 52%; }
  #lock-hint { display: none !important; }
}

/* ============ 触屏虚拟控件 ============ */
#touch-ui { position: absolute; inset: 0; z-index: 20; pointer-events: none; display: none; }
body.is-touch #screen-battle.active #touch-ui.on { display: block; }

/* 左侧摇杆 */
#stick-zone {
  position: absolute;
  left: calc(14px + var(--sal));
  bottom: calc(18px + var(--sab));
  width: 148px; height: 148px;
  pointer-events: auto;
  touch-action: none;
}
#stick-base {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(125, 147, 165, .5);
  background: radial-gradient(circle, rgba(10, 18, 26, .45) 0%, rgba(10, 18, 26, .25) 100%);
}
#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 215, 100, .9), rgba(217, 141, 0, .9));
  box-shadow: 0 2px 14px rgba(0, 0, 0, .5);
  transform: translate(0px, 0px);
}

/* 右侧按钮簇 */
.t-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1.5px solid rgba(125, 147, 165, .55);
  background: rgba(8, 13, 18, .55);
  color: #cfdde8;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1px;
  font-family: var(--font);
  backdrop-filter: blur(2px);
  user-select: none;
  -webkit-user-select: none;
}
.t-btn:active, .t-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255, 179, 0, .16);
}
#t-btn-fire {
  right: calc(18px + var(--sar));
  bottom: calc(24px + var(--sab));
  width: 92px; height: 92px;
  font-size: 15px;
  border-color: rgba(255, 179, 0, .65);
  color: var(--gold);
  background: rgba(255, 179, 0, .1);
}
#t-btn-fire.active { background: rgba(255, 179, 0, .3); color: #000; }
#t-btn-ads {
  right: calc(122px + var(--sar));
  bottom: calc(30px + var(--sab));
  width: 60px; height: 60px;
}
#t-btn-jump {
  right: calc(30px + var(--sar));
  bottom: calc(128px + var(--sab));
  width: 60px; height: 60px;
}
#t-btn-crouch {
  right: calc(102px + var(--sar));
  bottom: calc(112px + var(--sab));
  width: 56px; height: 56px;
}
#t-btn-reload {
  right: calc(170px + var(--sar));
  bottom: calc(96px + var(--sab));
  width: 52px; height: 52px;
}
#t-btn-weapon {
  right: calc(186px + var(--sar));
  bottom: calc(24px + var(--sab));
  width: 52px; height: 52px;
}
#t-btn-grenade {
  right: calc(30px + var(--sar));
  bottom: calc(196px + var(--sab));
  width: 50px; height: 50px;
}

/* 交互键（E）：平时隐藏，有目标时由 JS 显示 */
#t-btn-interact {
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(190px + var(--sab));
  width: 76px; height: 76px;
  border-radius: 50%;
  border-color: var(--gold);
  color: var(--gold);
  font-size: 13px;
  display: none;
}
#t-btn-interact.show { display: flex; }

/* 顶部小按钮：暂停 / 记分板 */
#t-btn-pause, #t-btn-score {
  position: absolute;
  top: calc(8px + var(--sat));
  pointer-events: auto;
  touch-action: manipulation;
  width: 44px; height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line-hi);
  background: rgba(8, 13, 18, .7);
  color: var(--txt);
  font-size: 16px;
  z-index: 21;
  display: none;
  align-items: center;
  justify-content: center;
}
body.is-touch #screen-battle.active #t-btn-pause.on,
body.is-touch #screen-battle.active #t-btn-score.on { display: flex; }
#t-btn-pause { right: calc(8px + var(--sar)); }
#t-btn-score { right: calc(60px + var(--sar)); top: calc(8px + var(--sat)); font-size: 12px; }

/* 开火时隐藏中央准星扩散过大？保持默认 */

/* 竖屏提示：竖屏时在战斗顶部提示建议横屏，但不强制阻断 */
#rotate-hint {
  position: absolute;
  left: 50%; top: calc(52px + var(--sat));
  transform: translateX(-50%);
  display: none;
  padding: 7px 16px;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold);
  background: rgba(8, 13, 18, .85);
  border: 1px solid var(--gold-deep);
  z-index: 22;
  pointer-events: none;
  white-space: nowrap;
}
@media (orientation: portrait) {
  body.is-touch #screen-battle.active #rotate-hint.on { display: block; }
}

/* 小屏横屏高度不足时，进一步压缩 HUD */
@media (max-width: 900px) and (max-height: 500px) {
  #minimap-wrap { width: 92px; }
  #minimap { width: 92px !important; height: 92px !important; }
  #hud-bottom-left { bottom: calc(132px + var(--sab)); width: 150px; }
  #hud-bottom-right { bottom: calc(132px + var(--sab)); }
  #stick-zone { width: 128px; height: 128px; bottom: calc(10px + var(--sab)); }
  #t-btn-fire { width: 80px; height: 80px; bottom: calc(14px + var(--sab)); }
  #t-btn-jump { bottom: calc(106px + var(--sab)); }
  #t-btn-crouch { bottom: calc(92px + var(--sab)); }
  #t-btn-reload { bottom: calc(78px + var(--sab)); }
  #t-btn-grenade { bottom: calc(168px + var(--sab)); }
  #t-btn-interact { bottom: calc(160px + var(--sab)); }
  #hud-topbar { transform: translateX(-50%) scale(.78); }
}

/* 触屏下暂停 / 结算面板按钮更易点击 */
body.is-touch #pause-menu .btn, body.is-touch #end-screen .btn { min-height: 48px; }
body.is-touch .slot-chip { min-height: 32px; }
