/* ══════════════════════════════════════════════════════════════════════════
   mobile.css —— 手机 / 触屏适配层
   载入顺序：styles.css → 页面内联 <style> → paper.css → mobile.css
   因为 paper.css 大量使用 body.paper X + !important，这里同样用 body.paper
   前缀 + !important，靠「后加载」赢下同名属性。桌面端（>900px 且精确指针）
   完全不受影响：所有规则都在媒体查询里。
   布局策略：
     · 顶栏折叠成两行 —— 第一行视图/名册/退出/状态，第二行地图标签横向滑动
     · 左侧 280px 侧栏 → 底部抽屉（可滑动关闭），收起态是一个左下角方块按钮
     · 观战栏 / 名册 → 贴底全宽横滑条
     · 悬停卡片 → 点按卡片（由 canvasRenderer 的触摸命中检测驱动）
     · 所有可点目标最小 34~44px，留出刘海/手势条 safe-area
   ══════════════════════════════════════════════════════════════════════════ */

html.is-touch { -webkit-tap-highlight-color: transparent; }
html.is-touch body {
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
  /* pan-x pan-y（不是 manipulation）：连页面级双指缩放一起关掉，
     否则页面缩放和地图 pinch 抢手势，松手就弹回。地图/3D 自己仍是 none。 */
  touch-action: pan-x pan-y;
}
html.is-touch input, html.is-touch select, html.is-touch textarea {
  -webkit-user-select: text; user-select: text;
}
/* 地图与 3D 画布自己处理手势 */
html.is-touch #map, html.is-touch .m3d, html.is-touch .m3d-canvas { touch-action: none; }

@media (max-width: 900px), (hover: none) and (pointer: coarse) {

  :root {
    --app-h: 100dvh;
    --sa-t: env(safe-area-inset-top, 0px);
    --sa-b: env(safe-area-inset-bottom, 0px);
    --sa-l: env(safe-area-inset-left, 0px);
    --sa-r: env(safe-area-inset-right, 0px);
  }

  html, body {
    height: var(--app-h, 100vh);
    min-height: var(--app-h, 100vh);
    overflow: hidden;
  }

  /* ── 顶栏：两行，触控加高 ─────────────────────────────────────────── */
  .topbar {
    height: auto !important;
    flex-wrap: wrap;
    gap: 6px;
    padding: calc(var(--sa-t) + 6px) calc(var(--sa-r) + 8px) 6px calc(var(--sa-l) + 8px) !important;
    align-items: center;
  }
  .topbar-logo, .topbar-sep { display: none !important; }

  .view-switch { order: 1; flex: 0 0 auto; padding: 3px; }
  .view-switch .vs-btn {
    min-height: 32px; padding: 4px 12px !important; font-size: 12.5px;
  }

  /* 第一行要塞下：视图切换 + 全屏/名册/退出 + 连接状态（363px 窄屏也不换行） */
  .topbar-pill {
    order: 2; flex: 0 0 auto;
    min-height: 32px; padding: 5px 10px; font-size: 12px;
  }
  #btnFullscreen { margin-left: auto !important; }
  .conn-dot { width: 7px; height: 7px; }

  .map-tabs {
    order: 10; flex: 1 0 100%; width: 100%;
    gap: 4px; padding: 2px 0 1px; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .map-tabs::-webkit-scrollbar { display: none; }
  .map-tab {
    flex: 0 0 auto; display: flex; align-items: center;
    min-height: 36px; padding: 6px 14px; font-size: 13px; border-radius: 10px;
  }

  /* ── 顶部队情计数条：收进顶栏，自成一行 ───────────────────────────── */
  /* styles.css 里它是 absolute + translate(-50%,-50%) + pointer-events:none 的浮块，
     浮在顶栏下沿会压住地图与公告条。这里让它回到文档流，当顶栏的第二行：
     第一行（视图切换/全屏/名册/退出/连接）→ order 8 计数条 → order 10 地图页签。
     高度由 syncTopbarHeight() 量进 --tb-h，公告条与抽屉都跟着它走。 */
  body.paper .player-counter {
    position: relative !important;
    top: auto !important; left: auto !important; transform: none !important;
    order: 8; flex: 1 0 100%; width: 100%;
    justify-content: center;
    min-height: 30px; padding: 1px calc(var(--sa-r) + 8px) 1px calc(var(--sa-l) + 8px);
    background: transparent !important;
    border: 0 !important;
    border-top: 1px solid var(--rule-2, rgba(23, 24, 26, .26)) !important;
    border-radius: 0 !important; box-shadow: none !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    pointer-events: auto;   /* 基线是 none，条尾的折叠钮要能点 */
  }
  .player-counter .pc-item { padding: 0 8px; }
  .player-counter .pc-item:first-child { padding-left: 0; }
  .pc-item { padding: 0 9px; gap: 5px; }
  .pc-val { font-size: 15px; letter-spacing: 0; }
  .pc-lbl { font-size: 11px; }
  .pc-dot { width: 6px; height: 6px; }
  .pc-sep { height: 18px; }
  /* 折叠钮：钉在行尾（▾ 展开 / ▸ 收起），中间的数字组保持居中；整条也能点 */
  .pc-toggle {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    position: absolute; right: calc(var(--sa-r) + 8px); top: 50%; transform: translateY(-50%);
    width: 26px; height: 26px; margin: 0; padding: 0;
    background: transparent; border: 0; border-left: 1px solid var(--rule-2, rgba(23, 24, 26, .26));
    color: var(--ink-3, #7c8388); font-size: 11px; line-height: 1; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  /* 折叠态：只留「点 + 数字 + 分隔线」，标签收起来，行也更矮
     （min-height 必须带着 body.paper 一起写，否则赢不过 paper.css 的 30px） */
  body.paper .player-counter.mini { min-height: 24px; padding-top: 1px; padding-bottom: 1px; }
  .player-counter.mini .pc-lbl { display: none; }
  .player-counter.mini .pc-item { padding: 0 6px; gap: 4px; }
  .player-counter.mini .pc-item:first-child { padding-left: 0; }
  .player-counter.mini .pc-val { font-size: 14px; }
  .player-counter.mini .pc-sep { height: 14px; }
  .player-counter.mini .pc-toggle { height: 22px; }

  /* ── 公告条：全宽，紧贴顶栏下沿（计数条已在顶栏里，不再单独让位） ──── */
  .announce-bar {
    left: calc(var(--sa-l) + 8px) !important;
    right: calc(var(--sa-r) + 8px) !important;
    top: calc(var(--sa-t) + var(--tb-h, 98px) + 6px) !important;
    transform: translateY(-10px) !important;
    max-width: none !important;
    padding: 9px 10px 9px 12px;
    font-size: 12.5px;
  }
  .announce-bar.show { transform: translateY(0) !important; }
  .announce-bar .ab-body { max-width: none; white-space: normal; }
  .announce-bar .ab-close { padding: 6px 8px; }

  /* ── 侧栏 → 底部抽屉 ─────────────────────────────────────────────── */
  body.paper .sidebar {
    top: auto !important; bottom: 0 !important;
    left: 0 !important; right: 0 !important;
    width: auto !important;
    max-height: 66dvh; height: auto;
    padding: 0 0 calc(var(--sa-b) + 12px) 0 !important;
    border-radius: 16px 16px 0 0 !important;
    border: 1px solid var(--border) !important;
    border-bottom: 0 !important;
    box-shadow: 0 -14px 44px rgba(0, 0, 0, .22) !important;
    z-index: 1200;
    transform: translateY(0);
    transition: transform .34s cubic-bezier(.16, 1, .3, 1);
  }
  body.paper .sidebar.collapsed { transform: translateY(calc(100% + 6px)) !important; }
  body.paper .panel { padding: 0 14px !important; }
  body.paper .panel + .panel { padding-top: 12px !important; margin-top: 2px !important; }
  body.paper .panel-title { font-size: 13px; margin-bottom: 10px; }

  /* 抽屉抓手（mobile.js 注入） */
  .sheet-grip {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px 2px; flex: 0 0 auto;
  }
  .sheet-grip i {
    width: 40px; height: 4px; border-radius: 2px;
    background: currentColor; opacity: .22; font-style: normal;
  }
  .sheet-grip .sg-title {
    font-size: 11px; letter-spacing: .18em; opacity: .55;
  }
  .sheet-grip .sg-x {
    margin-left: auto; width: 40px; height: 30px;
    border: 1px solid var(--border); border-radius: 9px;
    background: transparent; color: inherit; font-size: 13px; line-height: 1;
  }

  /* 抽屉里的行加高，便于手指点 */
  body.paper .stat-row, body.paper .layer-row { min-height: 36px; }
  body.paper .layer-lbl { font-size: 13px; }
  body.paper .layer-row { padding: 8px 2px; }
  body.paper .stat-row { padding: 8px 2px; }
  body.paper .ltog { width: 48px; height: 26px; }
  body.paper .ltog::after { width: 20px; height: 20px; }
  body.paper .ltog.on::after { transform: none; }
  .scale-row { min-height: 44px; }
  .scale-slider { height: 6px; }
  .scale-slider::-webkit-slider-thumb { width: 22px; height: 22px; }
  body.paper .scale-row input.scale-val-input { min-height: 32px; }

  /* ── 面板开关搬进底栏了：有共用底栏的页面上，浮在地图上的那个方块按钮不再出现
        （map.html 这类没有底栏的旧页面保留它，否则手机上没法开合侧栏）── */
  body.paper:has(#spectateBar) .sidebar-toggle { display: none !important; }

  /* 抽屉展开时让出底部区域 */
  body:has(.sidebar:not(.collapsed)) .spectate-bar,
  body:has(.sidebar:not(.collapsed)) #spectateFloat { display: none !important; }

  /* 收缩侧栏的浮动统计在手机上重复了顶部队情条 */
  .float-stats { display: none !important; }
  /* 观战浮动块在手机上由底部观战栏代替（它全仓库没有任何定位 CSS，是个空壳） */
  #spectateFloat { display: none !important; }

  /* ── 观战栏：贴底全宽横滑（沿用 paper 方角描边语言，跟顶栏是同一块纸）── */
  body.paper .spectate-bar {
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    transform: none !important;
    background: var(--paper-2) !important;
    border: 0 !important;
    border-top: 1px solid var(--rule-2) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    padding: 7px calc(var(--sa-r) + 10px) calc(var(--sa-b) + 7px) calc(var(--sa-l) + 8px) !important;
    gap: 7px; overflow-x: auto; overflow-y: hidden;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  body.paper .spectate-bar::-webkit-scrollbar { display: none; }
  /* 末尾留一格，最后一个按钮能完整滑出来 */
  body.paper .spectate-bar::after { content: ''; flex: 0 0 6px; }
  .spectate-bar > * { flex: 0 0 auto; }
  /* 面板开关钉在栏首：3D 段横向滑走时它也不动，随时能开抽屉 */
  body.paper .spectate-bar .sb-icon {
    position: sticky; left: calc(var(--sa-l) + 8px); z-index: 3;
    width: 38px; min-width: 38px; padding: 0; background: var(--paper-2);
  }
  .spectate-bar .sb-icon-t { display: none; }
  body.paper .spectate-label {
    font-size: 11px; letter-spacing: .1em; color: var(--ink-3) !important;
    padding-right: 7px; margin-right: 1px; border-right: 1px solid var(--rule-2);
  }
  body.paper .spectate-bar select {
    min-width: 96px; max-width: 160px; min-height: 32px; border-radius: 0 !important;
  }
  body.paper .spectate-btn { min-height: 32px; padding: 6px 14px; border-radius: 0 !important; font-size: 12px; }
  body.paper .lane-chip { min-height: 32px; padding: 6px 11px; border-radius: 0 !important; }
  .lane-sep { height: 18px; }

  /* ── 名册：贴底抽屉全宽 ───────────────────────────────────────────── */
  body.paper .roster {
    top: auto !important; right: 8px !important; left: 8px !important;
    bottom: calc(var(--sa-b) + 8px) !important;
    width: auto !important;
    max-height: 58dvh;
    border-radius: 12px !important;
  }
  /* 双排后不再有单排 grid；只收一下左右内距，手机全宽时名字更宽 */
  .rs-row { padding-left: 8px; padding-right: 8px; }
  .rs-row { padding-top: 6px; padding-bottom: 6px; }
  .rs-l2 { padding-left: 22px; }
  .rs-list { -webkit-overflow-scrolling: touch; }
  .rs-x { width: 30px; height: 28px; }
  /* 名册打开时不再藏底栏：两块浮窗是「浮」的，本来就被 bottomLimit 挡在底栏上方；
     藏掉反而让浮窗一路沉到底、跟随/视角那组控件凭空消失。 */
  body:has(#rosterPanel:not([hidden])) #spectateFloat { display: none !important; }

  /* ── 点按卡片（.rtip）─────────────────────────────────────────────── */
  .rtip {
    max-width: min(318px, 86vw) !important;
    font-size: 12.5px !important;
    padding: 9px 12px !important;
    border-radius: 12px;
  }
  .rtip .rtip-name { font-size: 13.5px; }
  .rtip-taphint {
    margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--border);
    font-size: 10px; color: var(--t3);
  }

  /* ── 3D 视图：控件就在底部那条共用观战栏里横向滑动，状态行贴在栏上方 ── */
  body.paper .spectate-bar .sb-3d { display: none; }
  body.paper .spectate-bar.m3d-mode .sb-3d { display: flex; align-items: center; }
  body.paper .spectate-bar.m3d-mode .sb-3d.lane-sep { display: block; }
  .spectate-bar .m3d-buttons { gap: 7px; }
  .spectate-bar .m3d-buttons button { width: 38px !important; min-width: 38px !important; height: 32px !important; font-size: 14px !important; }
  .m3d-status {
    left: calc(var(--sa-l) + 8px) !important; right: calc(var(--sa-r) + 8px) !important;
    bottom: calc(var(--sa-b) + var(--sb-h, 48px) + 8px) !important;
    transform: none !important; max-width: none !important;
    padding: 6px 10px; border-radius: 0 !important;
    background: var(--paper-2); border: 1px solid var(--rule-2); box-shadow: none;
  }

  /* 飞行手柄：左下角、压在状态行上方（状态行是整行满宽，手柄再低就会盖住它） */
  .fly-pad {
    left: calc(var(--sa-l) + 10px); right: auto; bottom: calc(var(--sa-b) + var(--sb-h, 48px) + 62px);
    gap: 8px;
  }
  .fly-stick { width: 104px; height: 104px; }
  .fly-ring { inset: 12px; }
  .fly-dot { width: 42px; height: 42px; margin: -21px 0 0 -21px; }
  .fly-btn { width: 42px; height: 34px; font-size: 13px; }
  .spectate-bar .m3d-buttons button.fly-toggle { width: 38px !important; }
  .fly-hint {
    left: auto; right: calc(var(--sa-r) + 8px); bottom: calc(var(--sa-b) + var(--sb-h, 48px) + 8px);
    max-width: calc(100vw - 150px); white-space: normal; font-size: 10.5px; text-align: right;
  }

  .m3d-card { min-width: 0 !important; max-width: 86vw !important; padding: 18px 16px !important; }
  .m3d-label { font-size: 10.5px; padding: 2px 6px; }

  /* ── 入场页：卡片自适应 + 口令框不溢出 ───────────────────────────── */
  body.paper .landing-overlay { align-items: center; padding: 16px calc(var(--sa-r) + 12px) 16px calc(var(--sa-l) + 12px); }
  body.paper .landing-card {
    width: min(420px, 100%) !important;
    min-width: 0 !important; max-width: none !important;
    padding: 30px 18px 26px !important;
  }
  body.paper .logo-box { width: 52px !important; height: 52px !important; margin-bottom: 14px !important; }
  .logo-box svg { width: 26px !important; height: 26px !important; }
  body.paper .landing-title { font-size: 22px !important; margin-bottom: 6px !important; }
  body.paper .landing-desc { font-size: 13px !important; margin-bottom: 22px !important; }
  /* 口令框：按容器宽度等分（窄屏 363px 也不会溢出），上限 48px */
  body.paper .otp-wrap {
    gap: 6px !important; margin-bottom: 18px !important;
    padding: 0 2px !important;
  }
  body.paper .otp-box {
    flex: 1 1 0 !important;
    width: auto !important; min-width: 0 !important; max-width: 48px !important;
    height: min(58px, 17vw) !important;
    font-size: min(22px, 6vw) !important;
  }
  body.paper .otp-hint { margin: -8px 0 14px !important; }
  body.paper .landing-btn { min-height: 52px; }
  body.paper .landing-input { min-height: 52px; font-size: 16px !important; }
  body.paper .lang-switch { top: calc(var(--sa-t) + 10px) !important; right: calc(var(--sa-r) + 10px) !important; }
  body.paper .lang-btn { min-height: 34px; padding: 7px 13px; }

  #toast { bottom: calc(var(--sa-b) + 16px) !important; font-size: 12.5px; padding: 10px 18px; }

  /* ── 局内外闸门：手机上一律贴底（浮条上方），别跟浮窗/公告抢正中 ─────
     原来它是「全屏居中 + z-index 40」：492px 实测被名册(998)和高价值窗(1002)
     整个压在下面，只剩左缘半行「房间…」和一颗「重试」漏在外面 —— 等待主端开局时
     最该看的那块反倒看不见。改成浮条上方的底卡：
       · z-index 1080：压过两块浮窗(1002/1003)，低于抽屉遮罩(1100)，抽屉打开时照常让位；
       · 父层保持 pointer-events:none，「重试」按钮自己才可点，不挡地图手势；
       · 宽度跟着屏走（340 上限），三条文案不再挤成一行。 */
  body.paper .raid-gate {
    align-items: flex-end !important;
    justify-content: center !important;
    z-index: 1080 !important;
    padding: 0 calc(var(--sa-r) + 10px) calc(var(--sa-b) + var(--sb-h, 50px) + 10px) calc(var(--sa-l) + 10px) !important;
    box-sizing: border-box;
  }
  /* 卡的尺寸/内距/皮肤统一在 miux §18；这里只管「手机上贴底」这件事 */
  body.paper .raid-gate .rg-card { max-width: min(330px, calc(100vw - 20px)) !important; }

  /* 弹层（容器/敌方筛选）点开后在抽屉里撑满 */
  .box-cfg-pop { border-radius: 10px; }
  .box-chk-row { padding: 9px 2px; font-size: 12.5px; }
  .box-chk-row input[type=checkbox] { width: 19px; height: 19px; }
}

/* ══ 横屏（手机横过来）：侧栏回到左侧，顶栏回到一行 ═══════════════════ */
@media (max-width: 960px) and (orientation: landscape) and (max-height: 560px) {
  .topbar { flex-wrap: wrap !important; padding-top: calc(var(--sa-t) + 4px) !important; }
  /* 横屏宽：计数条并回第一行右侧，地图页签单独一行（只在不连接时才显示） */
  .map-tabs { order: 10; flex: 1 0 100% !important; width: 100% !important; padding: 2px 0 1px !important; }
  .map-tab { min-height: 32px; padding: 4px 11px; font-size: 12px; }
  .view-switch .vs-btn { min-height: 30px; padding: 3px 12px !important; }
  .topbar-pill { min-height: 30px; }
  #btnFullscreen { margin-left: 6px !important; }

  body.paper .player-counter {
    order: 5; flex: 0 0 auto; width: auto;
    margin-left: auto; min-height: 26px; padding: 0 6px;
    border-top: 0 !important;
    border-left: 1px solid var(--rule-2, rgba(23, 24, 26, .26)) !important;
  }
  /* 横屏队情条很窄，折叠钮回成行内元素跟在数字后面 */
  .pc-toggle { position: static; transform: none; margin-left: 6px; border-left: 0; }
  .announce-bar { top: calc(var(--sa-t) + var(--tb-h, 49px) + 6px) !important; }
  /* 3D 控件已在底部共用观战栏里（横屏也是同一条），状态行贴栏上方 */
  .m3d-status {
    bottom: calc(var(--sa-b) + var(--sb-h, 52px) + 8px) !important; max-height: 40px; overflow: hidden;
  }
  .spectate-bar .m3d-buttons button { width: 38px !important; min-width: 38px !important; height: 32px !important; }
  .sheet-grip { display: none !important; }

  /* 侧栏改回左侧抽屉，收起时向左滑出 */
  body.paper .sidebar {
    top: calc(var(--sa-t) + 48px) !important;
    bottom: calc(var(--sa-b) + 8px) !important;
    left: calc(var(--sa-l) + 8px) !important; right: auto !important;
    width: min(306px, 46vw) !important;
    max-height: none;
    border-radius: 12px !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: var(--shadow) !important;
  }
  body.paper .sidebar.collapsed { transform: translateX(calc(-100% - 18px)) !important; }
  body.paper .sidebar-toggle { bottom: auto !important; top: calc(var(--sa-t) + 48px) !important; left: calc(var(--sa-l) + 12px) !important; }
  body.paper .sidebar-toggle.collapsed { left: calc(var(--sa-l) + 12px) !important; }
  body:has(.sidebar:not(.collapsed)) .sidebar-toggle:not(.collapsed) { bottom: auto !important; top: calc(var(--sa-t) + 48px) !important; }
  body.paper .sidebar-toggle:not(.collapsed) { left: calc(min(306px, 46vw) + var(--sa-l) + 16px) !important; }

  body.paper .roster { max-height: 74dvh; }
  .m3d-card { max-width: 62vw !important; }
}
