/* 手机矮横屏（典型 844×390）专用：原版在 390 高度下控制区会超出视口约 20px，
 * 替补席和「自动」按钮被裁掉。这里只压缩控制条，不动战场 canvas，避免触控坐标错位。
 * 放在 looks/*.css 之后加载，才能覆盖皮肤里的按钮尺寸。
 */
@media (orientation: landscape) and (max-height: 430px) {
  body[data-screen="battle"] #controls {
    padding-bottom: 0;
  }
  body[data-screen="battle"] #controls .moves {
    margin-top: 2px !important;
    gap: 4px !important;
    min-height: 0 !important;
  }
  body[data-screen="battle"] #controls .moves .move {
    min-height: 38px !important;
    padding-top: 2px !important;
    padding-bottom: 2px !important;
  }
  body[data-screen="battle"] #controls .moves .move .ty {
    width: 22px !important;
    height: 22px !important;
  }
  body[data-screen="battle"] #controls .controls {
    margin-top: 2px !important;
    gap: 4px !important;
  }
  body[data-screen="battle"] #controls .bench {
    gap: 4px !important;
  }
  body[data-screen="battle"] #controls .bench .mon {
    min-height: 34px !important;
    padding: 2px 1px 3px !important;
  }
  body[data-screen="battle"] #controls .bench .mon > span {
    display: none;
  }
  body[data-screen="battle"] #controls .bench .mon img,
  body[data-screen="battle"] #controls .bench .mon canvas {
    width: 30px !important;
    height: 30px !important;
  }
  body[data-screen="battle"] #controls .note,
  body[data-screen="battle"] #controls .rotate {
    display: none !important;
  }
}

/* ================================================================
 * 手机端 App 化补丁（2026-11-16）
 *
 * 1. 皮肤 CSS 把 main 的 padding 改成了固定的 4px 8px，踩掉了作者原本写在
 *    style.css:1247 的 env(safe-area-inset-*)——刘海机横屏时右侧技能列会贴到圆角上。
 * 2. main 的上下 padding 和 #battle 的 100dvh 相加会溢出 8px（横屏）
 *    / 110px 底部留白溢出 24px（竖屏），Safari 地址栏一收一放就抖。
 * 3. 技能按钮只有 38~41px 高，低于 44px 触控下限，横屏连点容易点错。
 * ================================================================ */

/* 战斗界面锁死滚动：宁可裁掉底部空白，也不让地址栏抖动把技能键挤走 */
body[data-screen="battle"] {
  overflow: hidden;
  overscroll-behavior: none;
}

@media (max-height: 500px) and (orientation: landscape) {
  /* 皮肤覆盖了安全区，这里按优先级补回来 */
  body.sideplay main {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: max(8px, env(safe-area-inset-left)) !important;
    padding-right: max(8px, env(safe-area-inset-right)) !important;
  }

  /* 四个技能塞进右侧竖列：48px 是拇指盲点的下限 */
  body.sideplay[data-screen="battle"] #controls .moves .move {
    min-height: 48px !important;
    padding-top: 3px !important;
    padding-bottom: 3px !important;
  }
  body.sideplay .move .nm { font-size: 13px !important; }
  body.sideplay .move .meta { font-size: 10.5px !important; }

  /* 替补席和「自动」也放大到能点中（要带 #controls 才压得过上面那条 34px 的规则） */
  body.sideplay[data-screen="battle"] #controls .bench .mon { min-height: 44px !important; }
  body.sideplay #manualBtn { min-height: 34px !important; height: 34px !important; }

  /* 防御键抬到 Home 条上方 */
  body.sideplay .dodge.guard {
    margin-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    background: rgba(150, 210, 255, .3) !important;
  }
  body.sideplay.thumbs #guardBtn { background: rgba(150, 210, 255, .3) !important; }
}

/* 竖屏：底部那 110px 是给固定控制条留的位置，战斗中不需要它撑页面 */
@media (orientation: portrait) {
  body[data-screen="battle"] main {
    padding-bottom: max(4px, env(safe-area-inset-bottom)) !important;
  }
  body[data-screen="battle"] #battle {
    height: auto !important;
    min-height: 0 !important;
  }
}

/* ---------- 触屏手感：去掉浏览器默认行为，加按压反馈 ---------- */
@media (hover: none) and (pointer: coarse) {
  body,
  #battle,
  #battle button,
  #battle .move,
  #battle .mon {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  /* 双击不再缩放，也不再有 300ms 延迟 */
  #battle button,
  #battle .move,
  #battle .mon {
    touch-action: manipulation;
  }
  #battle .move:active {
    transform: scale(.97);
    filter: brightness(1.15);
  }
  #battle .mon:active {
    transform: scale(.95);
  }
  #battle .dodge:active {
    transform: scale(.94);
    filter: brightness(1.25);
  }

  /* 顶栏的四个次要按钮视觉尺寸不动，但把点击域往下扩 6px */
  body[data-screen="battle"] .stagebar > button {
    position: relative;
  }
  body[data-screen="battle"] .stagebar > button::after {
    content: '';
    position: absolute;
    inset: 0 -2px -6px;
  }
}

/* 装到桌面后（standalone）没有地址栏，全屏按钮和旋转提示都是多余的 */
body.pwa #fsBtn,
body.pwa #rotateHint {
  display: none !important;
}

/* iOS 的一次性「添加到主屏幕」指引（bridge.js 注入） */
.pbr-install {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(92vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #14161f;
  color: #eceef5;
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font-size: 13px;
  line-height: 1.5;
  z-index: 9999;
}
.pbr-install b { font-size: 14px; }
.pbr-install span { color: #b9bdd1; }
.pbr-install button {
  align-self: flex-end;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .22);
  background: transparent;
  color: #fff;
  font-size: 13px;
}

/* 底部固定操作条（组队页的「寻找对手」）原来紧贴 bottom:0，iPhone 上会被 Home 条压住 */
.actionbar {
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
}
