/* =========================================================
   金鸿文化 · 玄机盘 · 移动端 / 跨浏览器兼容层
   在 style.css、premium.css 之后加载，只做兼容与适配
   目标：iPhone（含 SE / 刘海屏）、华为 / 荣耀 / 小米 / OPPO / vivo /
        三星 / 一加、Android 各版本 WebView、微信内置浏览器、iPad、
        Windows / macOS 桌面浏览器
   ========================================================= */

/* ---------- 0. 基础 ---------- */
:root {
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
          "Source Han Sans SC", "HarmonyOS Sans SC", "MiSans",
          "WenQuanYi Micro Hei", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC",
           "SimSun", "STZhongsong", "KaiTi", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --vh100: 100vh;
}
@supports (height: 100dvh) {
  :root { --vh100: 100dvh; }
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-padding-top: 72px;
}
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: contain;
}
::selection { background: rgba(184, 145, 63, 0.28); }
button, .btn, a { -webkit-tap-highlight-color: transparent; }

/* iOS / Android 安全区 */
.nav-inner { padding-left: var(--safe-l); padding-right: var(--safe-r); }
.foot { padding-bottom: calc(30px + var(--safe-b)); }
.disclaimer { padding-bottom: calc(48px + var(--safe-b)); }
.float-wx { bottom: calc(26px + var(--safe-b)); }

/* ---------- 1. flex gap 兜底（iOS 14.0 及以下 / 旧 WebView 不支持 flex gap） ---------- */
@supports not (gap: 1px) {
  .nav-inner > * + * { margin-left: 16px; }
  .brand-mark + .brand-text { margin-left: 10px; }
  .nav-links a + a { margin-left: 4px; }
  .card-head > * + * { margin-left: 12px; }
  .form-head > * + * { margin-left: 12px; }
  .seg button + button { margin-left: 6px; }
  .check input { margin-right: 8px; }
  .row > * + * { margin-left: 8px; }
  .result-actions > * + * { margin-left: 8px; }
  .ov-bazi span + span { margin-left: 8px; }
  .chip-row > * + * { margin-left: 8px; }
  .kv-list li > * + * { margin-left: 10px; }
  .ss-badges li + li { margin-left: 7px; }
  .hero-meta .hm + .hm { margin-left: 26px; }
  .hero-feats span + span { margin-left: 8px; }
  .hero-cta > * + * { margin-left: 12px; }
  .hero-strip .hs + .hs { border-left: 1px solid rgba(200, 164, 92, 0.1); }
  .wx-row > * + * { margin-left: 10px; }
  .dayun .dy + .dy { margin-left: 10px; }
  .sec-head > * + * { margin-left: 20px; }
  .sec-tools > * + * { margin-left: 8px; }
  .luopan-tools > * + * { margin-left: 8px; }
  .legend > * + * { margin-left: 14px; }
  .yiji .tags span + span { margin-left: 6px; }
  .hh-score-wrap > * + * { margin-left: 24px; }
  .cr-badge > * + * { margin-left: 14px; }
  .foot-inner > * + * { margin-left: 16px; }
  .toolbar > * + * { margin-left: 10px; }
  .cap-grid { margin: -7px; }
  .cap { margin: 7px; }
  .howto .step + .step { margin-left: 0; }
  .contact-band .cb-actions > * + * { margin-left: 10px; }
  .wx-actions > * + * { margin-top: 8px; }
}

/* ---------- 2. aspect-ratio 兜底（iOS 14 / 旧 Android WebView） ---------- */
@supports not (aspect-ratio: 1) {
  .luopan-wrap { height: 480px; max-height: none; }
  @media (max-width: 980px) {
    .luopan-wrap { height: 340px; }
  }
}

/* ---------- 3. Safari 毛玻璃前缀 ---------- */
.nav {
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .nav { background: rgba(18, 16, 13, 0.97); }
}

/* ---------- 4. 表单：iOS 不缩放、控件对齐 ---------- */
input[type="text"], input[type="date"], input[type="time"], input[type="number"],
input[type="search"], select {
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value { text-align: left; }
input[type="date"], input[type="time"] {
  min-height: 42px;
  line-height: 1.2;
  color-scheme: light;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }
/* iOS 对小于 16px 的输入框聚焦时会自动放大页面 */
@media (max-width: 900px) {
  input[type="text"], input[type="date"], input[type="time"], input[type="number"],
  input[type="search"], select { font-size: 16px !important; }
}

/* ---------- 5. 触摸滚动容器 ---------- */
.pillar-scroll, .dayun-scroll, .liunian-scroll, .shan-scroll,
.zr-list, .tbl-wrap, .kb-body, .luopan-card {
  -webkit-overflow-scrolling: touch;
}
.pillar-scroll, .dayun-scroll, .liunian-scroll, .shan-scroll,
.zr-list, .tbl-wrap {
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 145, 63, 0.45) transparent;
}

/* ---------- 6. 画布触摸 ---------- */
#luopan { touch-action: none; }
.hero-stage .instrument canvas { touch-action: none; }

/* ---------- 7. 小屏（iPhone SE 320–375 / 安卓小屏） ---------- */
@media (max-width: 380px) {
  .wrap { width: calc(100% - 24px); }
  .hero { padding-top: 92px; }
  .hero h1 { font-size: 29px; line-height: 1.2; }
  .hero-sub { font-size: 12.5px; line-height: 1.85; }
  .hero-topline { gap: 6px; margin-bottom: 18px; }
  .ht-chip { font-size: 9.5px; padding: 3px 8px; }
  .ht-today { font-size: 9.5px; width: 100%; margin-left: 0; }
  .hero-cta .btn-gold, .hero-cta .btn-line { padding: 11px 16px; font-size: 13px; }
  .hero-meta { gap: 16px; }
  .hero-meta .hm b { font-size: 19px; }
  .hero-strip .hs { padding: 12px 12px; }
  .hero-strip .hs .v { font-size: 12px; }
  .card { padding: 15px; border-radius: 14px; }
  .seg button { padding: 7px 4px; font-size: 12px; }
  .gan-row, .zhi-row { font-size: 27px; }
  .nav-inner { height: 58px; }
  .brand-text { font-size: 15px; }
  .jz-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .jz-cell { padding: 7px 3px; }
  .jz-cell .jz-jz { font-size: 15px; }
  .float-wx { width: 46px; height: 46px; }
}

/* ---------- 8. 横屏手机（高度受限） ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .nav-inner { height: 52px; }
  .hero { padding-top: 76px; }
  .hero-stage .instrument { display: none; }
}

/* ---------- 9. 平板 ---------- */
@media (min-width: 721px) and (max-width: 1024px) {
  .hero-grid { gap: 26px; }
  .luopan-grid { gap: 14px; }
  .jz-grid { grid-template-columns: repeat(8, 1fr); }
  .cap-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 10. 大屏 / 高分屏 ---------- */
@media (min-width: 1600px) {
  :root { --max: 1280px; }
  .hero h1 { font-size: 60px; }
}

/* ---------- 11. 深色模式不被系统反色 ---------- */
@media (prefers-color-scheme: dark) {
  :root { color-scheme: light; }
}

/* ---------- 12. 降级提示条（旧内核） ---------- */
.legacy-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9997;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: #2a1d0c;
  color: #f3e9d2;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  border-top: 1px solid rgba(200, 164, 92, 0.4);
}
.legacy-bar b { color: #e8c98a; }
.legacy-bar button {
  margin-left: 8px;
  border: 1px solid rgba(200, 164, 92, 0.5);
  background: transparent;
  color: #e8c98a;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

/* ---------- 13. 打印 ---------- */
@media print {
  .nav, .hero, .disclaimer, .foot, .float-wx, .legacy-bar, .contact-band { display: none !important; }
  .result { padding: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border-color: #ccc !important; break-inside: avoid; }
  a[href]::after { content: ""; }
}
