/* ============================================================================
   英语小精灵 · 移动端 / 触屏适配
   安卓 Chrome、微信内置、iOS Safari、iPad 都能玩。
   桌面宽屏保持 1:1 固定舞台；竖屏窄屏把战斗/结算/地图改成流式重排，
   保证按钮 ≥44px 触控目标，而不是把 1180px 舞台缩成一粒米。
   ============================================================================ */

/* ---------- 全局触屏基线（所有设备） ---------- */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { -webkit-user-select: none; user-select: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; }
button, .opt-btn, .qz-chip, .qz-pair, .qz-letter-keys button,
.bi-btn, .nav-pill, .icon-btn, .mp-node, .book-chip, .touch-go {
  touch-action: manipulation;
  cursor: pointer;
}
.touch-active { filter: brightness(.93); transform: scale(.98); }
.page-scroll, .book-bar, .bt-items, .nav-pills, .mp-nodes, .skill-cards, .qz-letter-keys, .qz-chips {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- 中等宽度（平板 / 横屏手机）：主窗顶栏允许换行 ---------- */
@media (max-width: 1100px) {
  .topbar { padding: 0 10px; }
  .brand { gap: 8px; }
  .brand-title { font-size: 20px; }
  .nav-pill { padding: 9px 10px; font-size: 12.5px; margin: 0 2px; }
  .icon-btn { width: 40px; height: 40px; }
}

/* ============================================================================
   竖屏窄屏：核心重排
   ============================================================================ */
@media (max-width: 900px) and (orientation: portrait) {

  /* 登录窗：保留 470×660 设计稿，按宽度等比缩放（fitStages 已处理），
     但外层要能容纳缩放后的高度并留安全区 */
  .login-screen { align-items: flex-start; padding-top: calc(env(safe-area-inset-top, 0px) + 12px); overflow-y: auto; }
  .login-win { margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }

  /* ---- 主窗顶栏 ---- */
  .topbar { height: auto; min-height: 0; padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px; }
  .topbar-inner { flex-wrap: wrap; gap: 6px; }
  .brand { order: 1; flex: 1; }
  .logo-disc { width: 42px; height: 42px; border-width: 2px; }
  .logo-disc img { width: 38px; height: 38px; }
  .brand-title { font-size: 17px; }
  .brand-sub, .edition-select { display: none; }
  .res-area { order: 2; gap: 5px; }
  .res-pill { padding: 5px 9px; }
  .res-num { font-size: 13px; }
  .res-ico { width: 16px; height: 16px; }
  .icon-btn { width: 40px; height: 40px; min-width: 40px; }
  #btnStory { display: none; }
  .nav-pills {
    order: 3; width: 100%; flex: none; justify-content: flex-start;
    gap: 6px; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px;
    scrollbar-width: none;
  }
  .nav-pills::-webkit-scrollbar { display: none; }
  .nav-pill { flex: none; min-height: 44px; padding: 0 15px; font-size: 13px; margin: 0; }

  /* ---- 地图 ---- */
  .map-page { padding: 8px; gap: 8px; }
  .map-detail { flex: 1.05; }
  .map-path { flex: 1; }
  .md-pill { font-size: 10px; padding: 3px 9px; top: 8px; }
  .md-pill-left { left: 8px; } .md-pill-right { right: 8px; }
  .md-center { top: 16px; }
  .md-mon-cn { font-size: 16px; }
  .md-mon-en { font-size: 10px; }
  .md-monster { top: 42px; width: 92px; height: 92px; }
  .md-group { top: 82px; width: 42%; gap: 4px; }
  .md-group.right { width: 44%; }
  .md-group-title { font-size: 10px; padding: 2px 7px; }
  .md-chip { font-size: 10px; padding: 2px 7px; }
  .md-dots { bottom: 7px; }
  .mp-route { display: none; }
  .mp-nodes {
    top: 14%; height: auto; bottom: 8px; justify-content: flex-start;
    gap: 14px; padding: 0 12px; overflow-x: auto; overflow-y: hidden;
    align-items: flex-start; scroll-snap-type: x proximity;
  }
  .mp-node { width: 84px; flex: none; scroll-snap-align: center; }
  .mp-ring { width: 68px; height: 68px; border-width: 2px; }
  .mp-ring img { width: 62px; height: 62px; }
  .mp-stars img { width: 15px; height: 15px; }
  .mp-tag { font-size: 10px; }
  .book-bar { height: 48px; padding: 0 8px; gap: 5px; }
  .book-chip { min-height: 38px; font-size: 11px; }

  /* ---- 战斗：整屏流式重排 ---- */
  .battle-screen .stage-wrap { display: block; align-items: stretch; }
  .battle-stage {
    width: 100% !important; height: 100dvh !important;
    transform: none !important; box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
  }
  .bt-top { height: 42px; padding: 0 8px; flex: none; }
  .bt-left { font-size: 12px; gap: 4px; white-space: nowrap; flex: none; max-width: 33%; overflow: hidden; }
  .bt-left .bt-book { font-size: 10px; white-space: nowrap; }
  .bt-center { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; text-align: center; }
  .bt-right { gap: 6px; flex: none; }
  .bt-coin { padding: 3px 8px; font-size: 12px; }
  .bt-surrender { min-height: 38px; padding: 0 12px; font-size: 12px; }

  /* 上半区严格按行高分配，避免左列 5 行内容溢出压到题目区 */
  .bt-upper { height: 194px; padding: 0 8px; align-items: flex-start; }
  .bt-side { width: 49%; height: 100%; justify-content: flex-start; overflow: hidden; }
  .fighter-name { font-size: 13px; height: 18px; line-height: 18px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .fighter-en { font-size: 9px; height: 13px; line-height: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bar { width: 100%; height: 17px; margin-top: 2px; flex: none; }
  .bar.exp { height: 12px; margin-top: 2px; }
  .bar.exp .bar-num { font-size: 8px; line-height: 12px; }
  .bar-lv { width: 42px; font-size: 9px; }
  .bar-num { font-size: 10px; }
  .strike-bar { width: 100%; height: 14px; margin-top: 2px; flex: none; }
  .strike-bar .strike-num { font-size: 9px; }
  .fighter-art { height: 88px; flex: none; }
  .fighter-art .sprite,
  .fighter-art.enemy .sprite { width: 100px; height: 88px; left: calc(50% - 50px); }
  .ground-ellipse { width: 92px; height: 18px; }
  .skill-cards { gap: 5px; overflow-x: auto; overflow-y: hidden; width: 100%;
    justify-content: flex-start; height: 32px; margin-top: 2px; flex: none; }
  .skill-card { width: 96px; min-width: 96px; height: 30px; padding: 0 5px; }
  .skill-card img { width: 16px; height: 16px; }
  .skill-card .sc-name { font-size: 10px; }
  .skill-card .sc-sub { font-size: 8px; }
  .bt-divider { height: 1px; flex: none; }

  .bt-quiz { flex: 1; min-height: 0; padding: 8px 10px; overflow-y: auto; }
  /* 题面 + 选项作为一个整体垂直居中：两个弹性占位平分剩余高度。
     内容超高时占位自动缩到 0，不会像 auto margin 那样把顶部裁掉。 */
  .bt-quiz::before, .bt-quiz::after {
    content: ''; display: block; flex: 1 1 0; min-height: 0; pointer-events: none;
  }
  .bt-quiz > .qz-body { margin-top: 18px !important; margin-bottom: 0; }
  .qz-title img { display: none; }
  .qz-icon { height: 34px; width: 54px; }
  .qz-bigletter { font-size: 28px; }
  .qz-title { font-size: 21px; margin-top: 0; }
  .qz-title.small { font-size: 17px; }
  .qz-maskword { font-size: 26px; letter-spacing: 3px; }
  .qz-maskword .blank { min-width: 15px; border-bottom-width: 3px; }
  .qz-meaning { font-size: 12px; padding: 2px 9px; margin-top: 3px; }
  .qz-meaning.blank-sentence { font-size: 13px; }
  .qz-hint { font-size: 11px; margin-top: 4px; }
  .qz-progress { width: 100%; height: 7px; margin-top: 6px; }
  .qz-body { margin-top: 9px; }
  .qz-options { width: 100%; grid-template-columns: 1fr 1fr; gap: 11px; }
  .opt-btn { min-height: 58px; height: auto; padding: 6px 9px; font-size: 15px; gap: 7px; border-radius: 14px; }
  .opt-key { width: 25px; height: 25px; font-size: 12px; }

  .qz-letter-grid { gap: 5px; flex-wrap: wrap; }
  .qz-letter-cell { width: 34px; height: 40px; font-size: 18px; }
  .qz-letter-keys { width: 100%; gap: 6px; margin-top: 9px; }
  .qz-letter-keys button { width: 42px; height: 44px; min-width: 42px; font-size: 17px; }
  .qz-typed-slots span { min-width: 15px; height: 30px; font-size: 18px; }
  .qz-typed-note { font-size: 11px; margin-top: 7px; }
  .qz-input { width: 100%; height: 48px; font-size: 16px; padding: 0 10px; }
  .touch-submit-row { width: 100%; display: flex; justify-content: center; margin-top: 9px; }
  .touch-go { min-height: 48px; width: 60%; border-radius: 12px; background: #2D9CFF;
    color: #fff; font-size: 16px; font-weight: 800; letter-spacing: 2px; }
  .qz-chips { width: 100%; gap: 8px; }
  .qz-chip { min-width: 80px; min-height: 48px; height: auto; font-size: 15px; padding: 8px 12px; }
  .qz-order-display { font-size: 16px; min-height: 26px; }
  .qz-tf-card { font-size: 18px; padding: 9px 14px; gap: 7px; }
  .qz-tf-btns { gap: 14px; margin-top: 12px; }
  .tf-btn { min-height: 52px; padding: 8px 16px; }
  .qz-match-title { font-size: 18px; }
  .qz-match-board { gap: 10px; width: 100%; }
  .qz-match-col { flex: 1; gap: 8px; }
  .qz-pair { width: 100%; min-height: 48px; height: auto; font-size: 14px; padding: 5px; }

  .bt-items { height: 62px; gap: 7px; justify-content: flex-start; overflow-x: auto; padding: 0 10px; }
  .bi-btn { flex: none; min-height: 48px; height: 48px; padding: 0 11px; font-size: 12px; }
  .bi-btn img { width: 22px; height: 22px; }
  .fx-dmg { font-size: 24px; }
  .fx-dmg.crit { font-size: 32px; }

  /* ---- 结算：zoom 等比缩放（会真实占据布局高度），外层可纵向滚动 ---- */
  .result-screen .stage-wrap { display: block; overflow-y: auto; padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 12px); }
  .result-stage {
    zoom: var(--stage-scale, .55);
    transform: none !important;
    margin: 0 auto;
    transform-origin: top center;
  }
  .rs-continue { min-height: 58px; }

  /* ---- 其它页面 ---- */
  .page-scroll { overflow-y: auto; }
  .overlay-card { max-width: 94vw; max-height: 88dvh; overflow-y: auto; }
  .toast { max-width: 92vw; }
}

/* ---------- 横屏矮屏（手机横过来）：保持 1:1 缩放，只压缩安全区 ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .battle-screen, .login-screen, .result-screen { padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
  .opt-btn, .qz-chip, .bi-btn, .nav-pill { touch-action: manipulation; }
  /* 844×390 这类横屏：顶栏三段总宽会超屏，压缩品牌与导航避免横向溢出 */
  .topbar { padding-left: 8px; padding-right: 8px; min-height: 56px; }
  .topbar-inner { gap: 5px; }
  .brand { gap: 5px; }
  .logo-disc { width: 38px; height: 38px; }
  .logo-disc img { width: 34px; height: 34px; }
  .brand-title { font-size: 15px; }
  .brand-sub, .edition-select { display: none; }
  .nav-pills { overflow-x: auto; overflow-y: hidden; justify-content: flex-start; gap: 3px; scrollbar-width: none; }
  .nav-pills::-webkit-scrollbar { display: none; }
  .nav-pill { flex: none; padding: 6px 9px; margin: 0; font-size: 11.5px; min-height: 40px; }
  .res-area { gap: 3px; }
  .res-pill { padding: 4px 7px; }
  .res-num { font-size: 12px; }
  .icon-btn { width: 36px; height: 36px; min-width: 36px; }
  #btnStory, #btnClose { display: none; }

  /* 横屏手机高度只有 390px：等比缩放会把选项压到 23px，改成紧凑流式重排 */
  .battle-screen .stage-wrap { display: block; align-items: stretch; }
  .battle-stage {
    width: 100% !important; height: 100dvh !important;
    transform: none !important; box-shadow: none;
    box-sizing: border-box;
  }
  .bt-top { height: 34px; padding: 0 8px; }
  .bt-left { font-size: 12px; white-space: nowrap; }
  .bt-center { font-size: 10px; white-space: nowrap; }
  .bt-upper { height: 122px; padding: 0 8px; align-items: flex-start; }
  .bt-side { width: 49%; height: 100%; justify-content: flex-start; overflow: hidden; }
  .fighter-name { height: 15px; line-height: 15px; font-size: 11px; white-space: nowrap; }
  .fighter-en { height: 11px; line-height: 11px; font-size: 8px; white-space: nowrap; }
  .bar { height: 14px; width: 100%; margin-top: 1px; flex: none; }
  .bar.exp, .strike-bar { height: 11px; margin-top: 1px; }
  .bar.exp .bar-num, .strike-bar .strike-num { font-size: 8px; }
  .bar-lv { width: 36px; font-size: 8px; }
  .fighter-art { height: 56px; flex: none; }
  .fighter-art .sprite, .fighter-art.enemy .sprite {
    width: 62px; height: 56px; left: calc(50% - 31px);
  }
  .ground-ellipse { width: 62px; height: 12px; }
  .skill-cards { height: 26px; margin-top: 1px; gap: 4px; }
  .skill-card { width: 84px; min-width: 84px; height: 24px; }
  .skill-card img { width: 14px; height: 14px; }
  .skill-card .sc-name { font-size: 9px; }
  .skill-card .sc-sub { font-size: 7px; }
  .bt-divider { height: 1px; }
  .bt-quiz { flex: 1; min-height: 0; padding: 3px 8px; overflow-y: auto; }
  .qz-icon { height: 26px; width: 40px; }
  .qz-bigletter { font-size: 20px; }
  .qz-title { font-size: 17px; }
  .qz-title.small { font-size: 14px; }
  .qz-maskword { font-size: 20px; }
  .qz-meaning { font-size: 11px; margin-top: 2px; padding: 1px 8px; }
  .qz-hint { font-size: 10px; margin-top: 2px; }
  .qz-progress { width: 100%; height: 6px; margin-top: 3px; }
  .qz-body { margin-top: 5px; }
  .qz-options { width: 100%; grid-template-columns: 1fr 1fr; gap: 6px; }
  .opt-btn { min-height: 44px; height: auto; padding: 4px 8px; font-size: 13px; gap: 6px; border-radius: 12px; }
  .opt-key { width: 22px; height: 22px; font-size: 11px; }
  .qz-input { width: 100%; height: 42px; font-size: 16px; }
  .touch-go { min-height: 42px; }
  .qz-letter-cell { width: 30px; height: 34px; font-size: 16px; }
  .qz-letter-keys { width: 100%; gap: 5px; margin-top: 5px; }
  .qz-letter-keys button { width: 38px; min-width: 38px; height: 40px; font-size: 15px; }
  .qz-chip { min-height: 42px; font-size: 13px; }
  .tf-btn, .qz-pair { min-height: 42px; }
  .bt-items { height: 46px; gap: 6px; overflow-x: auto; justify-content: flex-start; padding: 0 8px; }
  .bi-btn { height: 40px; min-height: 40px; font-size: 11px; }
  .fx-dmg { font-size: 20px; } .fx-dmg.crit { font-size: 28px; }
}

/* ---------- 刘海屏横屏：左右留边 ---------- */
@supports (padding: env(safe-area-inset-left)) {
  .is-landscape .topbar { padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
}
