/* ============================================================
   兼容模式 (CompatMode) 样式
   作用域：html.compat-mode
   目标：适配较旧的 WebView / 安卓系统 / 旧浏览器，避免 UI 排版错乱。
   设计变量沿用 css/theme.css（--accent / --bg-card / --radius / --text-* …），
   与本体视觉保持高度一致；仅对“旧引擎不支持”的特性做安全降级。
   ============================================================ */

html.compat-mode {
  /* 安全区内边距：旧引擎不支持 env(safe-area-inset-*) 时，env() 声明整体失效，
     会导致 var(--safe-top) 解析失败；此处显式归零，避免无效声明使内边距丢失。 */
  --safe-top: 0px;
  --safe-bottom: 0px;

  /* 玻璃背景改不透明实色：旧引擎 backdrop-filter 失效时，半透明背景会让底层内容
     透出、文字难以辨认；改为实色后即便无模糊也清晰可读。颜色取自主题卡片色。 */
  --bg-glass: #fffdf8;
  --bg-glass-dark: #211e18;
}

/* 全局禁用毛玻璃模糊（旧 WebView 不支持；且兼容模式已改用不透明背景，无需模糊） */
html.compat-mode *,
html.compat-mode *::before,
html.compat-mode *::after {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* 视口高度单位降级：旧引擎不支持 dvh，强制回退 vh（!important 覆盖主题中的 100dvh） */
html.compat-mode html,
html.compat-mode body,
html.compat-mode #app-root {
  height: 100% !important;
}
html.compat-mode #app-root {
  height: 100vh !important;
}

/* 降低动画/过渡开销：旧设备更流畅，并规避旧引擎对 animation/transition 的异常表现 */
html.compat-mode *,
html.compat-mode *::before,
html.compat-mode *::after {
  transition: none !important;
  animation: none !important;
}

/* ----------------------------------------------------------------
   flex / grid 的 gap 在旧引擎（如 Android < 10 的 WebView）不支持，
   会导致子元素紧贴甚至重叠（“排版错乱”）。
   做法：先清零 gap（避免双份间距），再用“相邻兄弟 margin”按方向替补。
   ---------------------------------------------------------------- */

/* 清零受管容器的 gap */
html.compat-mode .menu,
html.compat-mode .save-slots,
html.compat-mode .modal-content,
html.compat-mode .modal .section,
html.compat-mode .ret-choice-list,
html.compat-mode .ret-impact-list,
html.compat-mode .rsb-impact-list,
html.compat-mode .rsi-ast-list,
html.compat-mode .ps-bureau-left,
html.compat-mode .corrupt-card .cc-effects,
html.compat-mode .policy-card .pc-control,
html.compat-mode .ret-prop-actions {
  gap: 0 !important;
}

/* 纵向堆叠：相邻兄弟上方补间距（值对齐原 gap） */
html.compat-mode .menu > * + * { margin-top: 12px; }
html.compat-mode .save-slots > * + * { margin-top: 12px; }
html.compat-mode .modal-content > * + * { margin-top: 8px; }
html.compat-mode .modal .section > * + * { margin-top: 8px; }
html.compat-mode .ret-choice-list > * + * { margin-top: 6px; }
html.compat-mode .ret-impact-list > * + * { margin-top: 8px; }
html.compat-mode .rsb-impact-list > * + * { margin-top: 8px; }
html.compat-mode .rsi-ast-list > * + * { margin-top: 6px; }
html.compat-mode .ps-bureau-left + .ps-bureau-left { margin-top: 2px; }
html.compat-mode .corrupt-card .cc-effects > * + * { margin-top: 6px; margin-left: 6px; }

/* 横向控制行：相邻兄弟左方补间距 */
html.compat-mode .policy-card .pc-control > * + * { margin-left: 10px; }
html.compat-mode .ret-prop-actions > * + * { margin-left: 4px; }

/* ===================== 升级提示遮罩 ===================== */
#compat-upgrade-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(32, 29, 24, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.compat-upgrade-box {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px 20px;
  text-align: center;
}
.compat-upgrade-icon { width: 44px; height: 44px; margin: 0 auto 8px; color: var(--orange, #e0a020); }
.compat-upgrade-icon svg { width: 100%; height: 100%; }
.compat-upgrade-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}
.compat-upgrade-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
  margin-bottom: 18px;
}
.compat-upgrade-text b { color: var(--text); }
.compat-upgrade-btn { width: 100%; padding: 12px; font-size: 14px; }
