/* ============================================
   mobile.css — 移动端响应式增强
   与 shared.css / portal.css / forum.css / channel.css / qbank.css / training.css
   的现有 @media(max-width:768px) 规则互补，不覆盖已有布局。
   ============================================ */

/* ===== 全局安全边界：防止图片/表格撑出视口 ===== */
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
pre, table { overflow-x: auto; display: block; max-width: 100%; }
.md-content img { border-radius: 8px; }

/* ===== 主内容底部安全区：避免被底部固定按钮/栏遮挡 ===== */
main.wp { padding-bottom: 24px; }

/* ===== 添加到桌面：浮动按钮（PC + 移动端共用） ===== */
.install-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  display: flex; align-items: center; gap: 5px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  border: none; border-radius: 28px;
  padding: 11px 16px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 5px 16px rgba(74, 140, 94, .35);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}
.install-fab:hover { transform: translateY(-2px); box-shadow: 0 7px 20px rgba(74, 140, 94, .42); }
.install-fab .if-ico { font-size: 18px; line-height: 1; }
.install-fab .if-txt { white-space: nowrap; }

/* iOS / 安卓安装引导弹窗 */
.install-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.install-modal[hidden] { display: none; }
.install-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.install-modal-panel {
  position: relative; width: min(90%, 360px); background: #fff; border-radius: 16px;
  padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.2); animation: im-fade .2s ease;
}
.install-modal-panel h3 { margin: 0 0 10px; font-size: 18px; color: var(--text-1); }
.install-modal-panel p { margin: 0 0 8px; font-size: 14px; color: var(--text-2); line-height: 1.6; }
.install-modal-panel .im-step { font-weight: 700; color: var(--primary-dark); margin-right: 4px; }
.install-modal-panel button {
  margin-top: 10px; width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
@keyframes im-fade { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* 抽屉中的安装入口 */
.drawer-install-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent;
  padding: 12px 16px; font-size: 15px; color: var(--text-1); cursor: pointer; text-align: left;
}
.drawer-install-btn:hover { background: var(--bg-soft); color: var(--primary-dark); }

/* ===== 窄屏适配 ===== */
@media (max-width: 768px) {
  main.wp { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* --- 题库 qbank.css 缺失的移动端规则 --- */
  .qb-points { flex-direction: column; align-items: flex-start; gap: 8px; font-size: 13px; }
  .qb-points .qb-cta { margin-left: 0; width: 100%; }
  .qb-points .qb-cta a { display: block; width: 100%; text-align: center; }
  .qb-subjects { grid-template-columns: 1fr; gap: 14px; }
  .qb-subject-card { padding: 16px; gap: 10px; }
  .qb-subject-head h3 { font-size: 16px; }
  .qb-subject-foot { flex-direction: column; gap: 8px; }
  .qb-subject-foot a { flex: none; }
  .qb-section-title { font-size: 16px; }

  .qb-units { gap: 14px; }
  .qb-unit-card { padding: 16px; }
  .qb-unit-head { flex-wrap: wrap; gap: 8px; }
  .qb-unit-head .cnt { margin-left: 0; }
  .qb-sets { grid-template-columns: 1fr; gap: 12px; }
  .qb-set-card { padding: 12px; }
  .qb-set-actions { flex-direction: column; gap: 6px; }
  .qb-set-actions a { flex: none; }

  .qb-q { padding: 16px; margin: 12px 0; }
  .qb-q-stem { font-size: 15px; }
  .qb-opt { padding: 10px 12px; font-size: 14px; }
  .qb-opt.text input { padding: 10px 12px; }
  .qb-submit-bar { flex-direction: column; gap: 10px; }
  .qb-submit-bar .btn { width: 100%; }

  .qb-result-head { padding: 18px; }
  .qb-score-big { font-size: 36px; }
  .qb-result-item { padding: 14px; }
  .qb-wrong-item { padding: 14px; }
  .qb-print-sheet { padding: 16px; }
  .qb-print-title { font-size: 18px; }
  .qb-print-q { font-size: 14px; }

  /* --- 训练 training.css 补充规则 --- */
  .tr-hero { padding: 20px 22px; flex-direction: column; align-items: flex-start; gap: 14px; }
  .tr-hero h3 { font-size: 18px; }
  .tr-hero-stats { width: 100%; justify-content: space-between; gap: 12px; }
  .tr-hero-stat b { font-size: 22px; }
  .tr-mystats { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 16px; }
  .tr-mystats .ms-cta { margin-left: 0; width: 100%; }
  .tr-mystats .ms-cta a { display: block; width: 100%; text-align: center; }
  .tr-games { grid-template-columns: 1fr; gap: 14px; }
  .tr-game-card { padding: 18px; }
  .tr-game-icon { width: 48px; height: 48px; font-size: 24px; }
  .tr-game-card h4 { font-size: 16px; }

  .tr-game-wrap { margin: 12px 0; padding: 0; }
  .tr-game-head h2 { font-size: 18px; }
  .tr-game-head p { font-size: 13px; }
  .tr-diffbar { gap: 8px; }
  .tr-diff { padding: 6px 14px; font-size: 12px; }
  .tr-start-card { padding: 24px 16px; }
  .tr-start-title { font-size: 18px; }
  .tr-start-card .tr-btn { min-width: 140px; }
  .tr-board { padding: 16px; min-height: 220px; }
  .tr-status { gap: 12px; font-size: 13px; flex-wrap: wrap; justify-content: center; }
  .tr-grid { width: 100%; max-width: 100%; }
  .tr-cell { font-size: 18px; }
  .tr-cell.seq { min-height: 48px; }
  .tr-q { font-size: 15px; margin-bottom: 10px; }
  .tr-opts { gap: 8px; }
  .tr-opt { padding: 10px 12px; font-size: 14px; margin: 0; }
  .tr-hint { font-size: 12px; }
  .tr-result { padding: 18px; }
  .tr-result .score-circle { width: 100px; height: 100px; }
  .tr-result .score-circle b { font-size: 26px; }
  .tr-result .r-actions { gap: 8px; }
  .tr-btn { padding: 10px 22px; font-size: 14px; }
  .tr-btn--next { font-size: 15px; padding: 12px 24px; }
  .tr-recent { padding: 16px; margin-top: 18px; }
  .tr-recent-item { flex-wrap: wrap; gap: 8px; padding: 8px 0; }
  .tr-recent-item .ri-score { margin-left: 0; }
  .tr-recent-item .ri-date { min-width: auto; margin-left: auto; }

  .tr-catnav { gap: 6px; }
  .tr-catnav-item { padding: 5px 10px; font-size: 12px; }
  .tr-cat-head { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 0 10px; }
  .tr-cat-head .tr-cat-more { margin-left: 0; align-self: stretch; text-align: center; }
  .tr-games-row { gap: 12px; padding: 6px 0 14px; }
  .tr-games-row .tr-game-card { flex: 0 0 170px; padding: 16px; }
  .tr-cat-detail-head { flex-wrap: wrap; gap: 10px; }
  .tr-cat-detail-head h2 { font-size: 18px; }
  .tr-agefilter { gap: 6px; }
  .tr-age-item { padding: 5px 12px; font-size: 12px; }

  .tr-arena { height: 220px; border-radius: 12px; }
  .tr-target { width: 42px; height: 42px; font-size: 24px; }
  .tr-emojis { font-size: 24px; letter-spacing: 2px; }
  .tr-rule { padding: 12px 14px; }
  .tr-rule-list { padding-left: 16px; }
  .tr-science { flex-direction: column; gap: 8px; padding: 12px 14px; }
  .tr-science p { font-size: 13px; }
  .tr-fs-btn { padding: 4px 10px; font-size: 12px; }

  /* 全屏模式在手机上不宜过度放大，避免溢出 */
  .tr-game-wrap:fullscreen .tr-cell, .tr-game-wrap.tr-fs .tr-cell { font-size: 24px; }
  .tr-game-wrap:fullscreen .tr-target, .tr-game-wrap.tr-fs .tr-target { width: 64px; height: 64px; font-size: 36px; }
  .tr-game-wrap:fullscreen .tr-q, .tr-game-wrap.tr-fs .tr-q { font-size: 20px; }
  .tr-game-wrap:fullscreen .tr-opt, .tr-game-wrap.tr-fs .tr-opt { font-size: 16px; padding: 12px 14px; }
  .tr-game-wrap:fullscreen .tr-arena, .tr-game-wrap.tr-fs .tr-arena { height: 52vh; }
  .tr-game-wrap:fullscreen .tr-emojis, .tr-game-wrap.tr-fs .tr-emojis { font-size: 34px; }
  .tr-game-wrap:fullscreen .score-circle, .tr-game-wrap.tr-fs .score-circle { width: 120px; height: 120px; }
  .tr-game-wrap:fullscreen .score-circle b, .tr-game-wrap.tr-fs .score-circle b { font-size: 32px; }
  .tr-game-wrap:fullscreen .tr-hint, .tr-game-wrap.tr-fs .tr-hint { font-size: 14px; }

  /* 训练总结页已在 @media(max-width: 860px) 处理，这里做补充 */
  .tr-overall { font-size: 32px; }
  .tr-dim-card { padding: 14px 16px; }
  .tr-dim-icon { width: 34px; height: 34px; font-size: 18px; }
  .tr-dim-top h4 { font-size: 15px; }
  .tr-dim-meta b { font-size: 18px; }
  .tr-dim-guidance { font-size: 12px; }

  /* 浮动按钮在手机上抬高，避免与底部固定栏/安全区重叠 */
  .install-fab { right: 14px; bottom: calc(72px + env(safe-area-inset-bottom)); padding: 10px 14px; }
}
