/* ============================================================
   legacy-fix.css  —— 老内核样式兜底
   在 style.css 之后加载。现代浏览器基本不受影响（规则要么等效、
   要么被 @supports 挡住）。

   处理三件事：
     1. <dialog> 的原生依赖（inset / dvh / ::backdrop）在 polyfill 之后失效
     2. display:grid 在 Chrome < 57 直接无效 → 关键容器改 flex
     3. flex gap 在 Chrome < 84 不生效 → 关键位置补 margin
   ============================================================ */

/* ---------- 1. 弹窗：补齐 dialog 的原生行为 ---------- */

/* 老写法兜底 inset:0（Chrome 87 以下不认 inset） */
.modal,
.membership-intro,
.dialog-backdrop-fallback {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* 100dvh 在 Chrome 108 以下无效，先给 vh，再用 dvh 覆盖 */
.modal {
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
}

/* 原生 dialog 有 UA 样式负责隐藏；polyfill 后必须自己写 */
.modal:not([open]) {
  display: none !important;
}
.modal[open] {
  display: block;
}

/* polyfill 生成的遮罩（原生 ::backdrop 只在真 dialog 上有效） */
.dialog-backdrop-fallback {
  position: fixed;
  background: rgba(41, 35, 47, 0.42);
  z-index: 998;
  -webkit-tap-highlight-color: transparent;
}
.modal[open] {
  z-index: 999;
}

/* ---------- 2. Grid 失效时的布局降级 ----------
   @supports not (display:grid) 只在老内核命中，
   现代浏览器整块忽略，不会有副作用。
   -------------------------------------------------- */

@supports not (display: grid) {
  /* 三档套餐：横排等宽 */
  .plans {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
  }
  .plans > * {
    -webkit-box-flex: 1;
    -webkit-flex: 1 1 0;
    flex: 1 1 0;
    min-width: 0;
  }
  .plans > * + * {
    margin-left: 8px;
  }

  /* 角色快捷入口：一行四个，两行八格 */
  .category-shortcuts {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    justify-content: flex-start;
  }
  .category-shortcuts > * {
    width: -webkit-calc(25% - 6px);
    width: calc(25% - 6px);
    margin: 3px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  /* 热门排行（桌面右栏两列） */
  .popular-grid {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
  }
  .popular-grid > * {
    width: -webkit-calc(50% - 8px);
    width: calc(50% - 8px);
  }
  .popular-grid > * + * {
    margin-left: 16px;
  }

  /* 底部四个 Tab */
  .mobile-navigation {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
  }
  .mobile-navigation > * {
    -webkit-box-flex: 1;
    -webkit-flex: 1 1 0;
    flex: 1 1 0;
    min-width: 0;
  }

  /* 桌面双栏（左内容 + 右排行） */
  .content-layout {
    display: block;
  }
  .popular-section {
    margin-top: 28px;
  }

  /* 分类目录（移动端） */
  .mobile-categories,
  .category-directory-head {
    display: block;
  }
}

/* ---------- 3. aspect-ratio 失效时图片不变形 ---------- */

@supports not (aspect-ratio: 1 / 1) {
  .game-art {
    height: 142px;
    overflow: hidden;
  }
  .game-art img {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
    object-fit: cover;
  }
  .detail-hero img {
    width: 100%;
    height: auto;
    display: block;
  }
}

/* ---------- 4. flex gap 不支持时的最小补救 ----------
   没法用 @supports 检测 flex gap（Chrome 66 起就能解析 gap 属性），
   所以在 polyfill 里做特性探测，给 <html> 打 .no-flex-gap。
   -------------------------------------------------- */

.no-flex-gap .plans > * + * {
  margin-left: 8px;
}
.no-flex-gap .category-shortcuts > * + * {
  margin-left: 6px;
}
.no-flex-gap .membership-body > * + * {
  margin-top: 10px;
}
.no-flex-gap .modal-head > * + * {
  margin-left: 10px;
}
.no-flex-gap .mobile-navigation > * + * {
  margin-left: 4px;
}
.no-flex-gap .featured-games > * + * {
  margin-left: 14px;
}
.no-flex-gap .section-head > * + * {
  margin-left: 12px;
}
.no-flex-gap .member-benefits > * + * {
  margin-left: 8px;
}
.no-flex-gap .game-card-foot > * + * {
  margin-top: 4px;
}

/* ---------- 5. iOS 上 type=search 的默认样式 ---------- */

input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
  border-radius: 12px;
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* ---------- 6. 老 iOS 的 300ms 点击延迟与点击高亮 ---------- */

button,
a,
.plan,
.game-card,
.category {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* ---------- 7. 安全区（iPhone X 以后才有 env()，没有也不报错） ---------- */

.mobile-navigation {
  bottom: 12px;
  bottom: -webkit-calc(12px + env(safe-area-inset-bottom));
  bottom: calc(12px + env(safe-area-inset-bottom));
}
