/* ============================================================
 * home-m.css — 首页移动端专用样式（≤767px）
 * 从 home.css 拆出，仅 index.html 以 media="(max-width:767px)" 加载
 * 注意：PC 端隐藏 m-* 结构的规则仍留在 home.css，勿搬来
 * ============================================================ */

@media (max-width: 767px) {
  /* 隐藏桌面结构（home.css 仅首页引用，不影响其他页面） */
  .ag-header,
  .ag-main,
  .game-footer { display: none !important; }

  body.ag-page { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }

  .m-top { display: block; }
  .m-hero, .m-platforms, .m-sec { display: block; }
  .m-tabbar { display: flex; }

  /* ---------- 顶栏 ---------- */
  .m-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 8px;
  }
  .m-logo { display: flex; align-items: center; gap: 8px; text-decoration: none; }
  .m-logo img { height: 40px; }
  .m-logo-text { display: flex; flex-direction: column; line-height: 1.15; }
  .m-logo-text b {
    font-size: 19px; color: #ffcc00; letter-spacing: 2px; font-weight: 800;
    text-shadow: 0 0 14px rgba(255, 204, 0, .45);
  }
  .m-logo-text i {
    font-style: normal; font-size: 9.5px; color: #9a93a8; letter-spacing: 2.5px;
  }
  .m-topbar-actions { display: flex; gap: 8px; }
  .m-ico-btn {
    width: 40px; height: 40px; border-radius: 11px;
    background: #17171f; border: 1px solid #2b2b36; color: #e8e8f0;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
  }
  .m-ico-btn--gold {
    background: linear-gradient(160deg, #ffd54a, #ffaa00);
    border-color: transparent; color: #1a1206;
    box-shadow: 0 2px 10px rgba(255, 170, 0, .35);
  }

  /* ---------- 搜索框 ---------- */
  .m-search {
    display: flex; align-items: center; gap: 8px;
    margin: 2px 14px 10px; padding: 0 12px;
    height: 38px; border-radius: 11px;
    background: #14141b; border: 1px solid #2b2b36; color: #8a8a96;
  }
  .m-search input {
    flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
    color: #f0f0f5; font-size: 14px;
  }
  .m-search input::placeholder { color: #6b6b78; }
  .m-search button {
    background: transparent; border: 0; color: #ffcc00;
    font-size: 14px; font-weight: 700; cursor: pointer; padding: 4px 2px;
  }

  /* ---------- 分类导航条 ---------- */
  .m-catnav {
    display: flex; align-items: stretch;
    padding: 6px 10px 10px; gap: 4px;
    border-bottom: 1px solid #1d1d26;
  }
  .m-catnav a {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 0; border-radius: 11px; text-decoration: none;
    color: #c9c9d4; font-size: clamp(10.5px, 3.1vw, 12px); font-weight: 600;
  }
  .m-catnav a span { white-space: nowrap; }
  .m-catnav a svg { width: 21px; height: 21px; }
  .m-catnav a.active {
    background: linear-gradient(160deg, #ffd54a, #ffaa00);
    color: #1a1206; font-weight: 800;
    box-shadow: 0 2px 10px rgba(255, 170, 0, .3);
  }

  /* ---------- 抽屉菜单 ---------- */
  .m-drawer {
    display: none;
    position: fixed; z-index: 90;
    top: 64px; right: 14px; min-width: 148px;
    background: #17171f; border: 1px solid #2b2b36; border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
    overflow: hidden;
  }
  .m-drawer.open { display: block; }
  .m-drawer a {
    display: block; padding: 11px 18px; color: #d8d8e2;
    font-size: 14px; text-decoration: none; border-bottom: 1px solid #22222c;
  }
  .m-drawer a:last-child { border-bottom: 0; }
  .m-drawer a:active { background: #20202b; color: #ffcc00; }

  /* ---------- Banner ---------- */
  .m-hero {
    position: relative; display: block;
    margin: 12px 12px 4px;
    aspect-ratio: 1893 / 693;
    border-radius: 14px; overflow: hidden;
    border: 1px solid rgba(255, 204, 0, .3);
    background: url('../images/common/home-hero.jpg') center / 100% 100% no-repeat, #0a0a0f;
  }
  .m-hero-dots {
    position: absolute; left: 0; right: 0; bottom: 7px;
    display: flex; justify-content: center; gap: 6px;
  }
  .m-hero-dots i {
    width: 6px; height: 6px; border-radius: 50%;
    background: rgba(255, 255, 255, .38);
  }
  .m-hero-dots i.on { background: #ffcc00; }

  /* ---------- 平台宫格 ----------
   * 与 all-games-m.css 同源修复：1fr 1fr 的下限是 min-content，长英文名会把
   * 其中一列撑到 187px，两列总宽超容器 → 右列被推出视口并裁掉。
   * 改为 minmax(0,1fr) 严格等分，窄屏也不溢出。 */
  .m-platforms {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
    /* 左右边距收到 6px：图标与 PC 同尺寸(52px 盒)后，把省下的 12px 让给文字，
       保证 360px 起中文长名与英文副标题都不出省略号。 */
    margin: 12px 6px;
  }
  .m-plat {
    /* 图标尺寸刻度直接取 PC 端 all-games.css :root 的 --ico-box-w/h、--ico-lg，
       让同一张分类图标在移动端与 PC 端像素级一致（宽幅 48.5x32 / 方形 32x32）。
       旧方案「方形盒 + object-fit:contain」是压矩形画布的，移动端图标会比 PC 小 20~25%；
       PC 的 :root 注释也明确禁止用 contain + 方形盒放这套图标。 */
    --m-ico-w: var(--ico-box-w, 52px);
    --m-ico-h: var(--ico-box-h, 42px);
    --m-ico-lg: var(--ico-lg, 32px);
    min-width: 0;
    display: flex; align-items: center; gap: 8px;
    padding: 9px 8px; border-radius: 13px; text-decoration: none;
    background: linear-gradient(150deg, #16161e, #101016);
    border: 1px solid #26262f;
  }
  .m-plat .ico {
    width: var(--m-ico-w); height: var(--m-ico-h); flex: 0 0 var(--m-ico-w);
    display: flex; align-items: center; justify-content: center;
  }
  /* 与 PC 端 home.css / all-games.css 同一套规则：高度定尺寸、宽度自适应，
     各图标恒等高 32px；宽幅/方形两类画布都不会被压缩变形。 */
  .m-plat .ico img {
    height: var(--m-ico-lg); width: auto; max-width: 100%;
    object-fit: contain; display: block;
  }
  .m-plat .text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
  .m-plat .text b { color: #f2f2f5; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-plat .text i {
    /* 字距 1px→0：52px 图标盒下给 'NEO GEO POCKET' 等长英文名留足空间 */
    font-style: normal; font-size: 11px; color: #7d7d8a; letter-spacing: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-plat .arr { flex: 0 0 auto; color: #ffcc00; font-size: 20px; font-weight: 300; line-height: 1; }
  .m-plat--all     { border-color: rgba(255, 204, 0, .45); }
  .m-plat--fc      { border-color: rgba(255, 77, 77, .45); }
  .m-plat--arcade  { border-color: rgba(194, 83, 255, .45); }
  .m-plat--gba     { border-color: rgba(160, 64, 255, .45); }
  .m-plat--sfc     { border-color: rgba(220, 220, 235, .35); }
  .m-plat--psp     { border-color: rgba(140, 200, 120, .40); }
  .m-plat--ps2     { border-color: rgba(90, 120, 255, .45); }
  /* 页内筛选选中态：!important 覆盖动态卡片内联的 border-color */
  .m-plat.active {
    border-color: #ffcc00 !important;
    background: linear-gradient(150deg, rgba(255, 204, 0, .16), rgba(255, 170, 0, .05));
    box-shadow: 0 2px 14px rgba(255, 170, 0, .25);
  }
  .m-plat.active .text b { color: #ffcc00; }

  /* ---------- 通用 section 标题 ---------- */
  .m-sec { margin: 18px 12px 0; }
  .m-sec-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
  }
  .m-sec-head h2 {
    margin: 0; display: flex; align-items: center; gap: 7px;
    font-size: 16.5px; font-weight: 800; color: #f2f2f5; letter-spacing: .5px;
  }
  .m-sec-head h2 .m-ico { width: 19px; height: 19px; color: #ffcc00; }
  .m-sec-head h2 i { font-style: normal; font-size: 10.5px; font-weight: 600; color: #7d7d8a; letter-spacing: 1px; }
  .m-sec-head > a { color: #a8a8b4; font-size: 12.5px; text-decoration: none; }

  /* ---------- 平台宫格页内筛选结果区（点平台卡后在本页展开） ---------- */
  /* hidden 属性需 !important：.m-sec{display:block} 是作者样式，优先级高于 UA 的 [hidden] */
  .m-sec.m-plat-games[hidden] { display: none !important; }
  .m-plat-games {
    margin-top: 14px; padding: 12px 12px 14px;
    border-radius: 14px; scroll-margin-top: 12px;
    background: linear-gradient(160deg, rgba(255, 204, 0, .05), rgba(16, 16, 22, .9));
    border: 1px solid rgba(255, 204, 0, .22);
  }
  .m-plat-games .m-sec-head { margin-bottom: 10px; gap: 8px; }
  .m-plat-games .m-sec-head h2 { font-size: 15.5px; min-width: 0; white-space: nowrap; }
  .m-plat-games .m-sec-head h2 i { font-size: 10px; }
  .m-pg-actions { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 9px; }
  .m-plat-games .m-pg-actions > a { color: #ffcc00; font-size: 12px; white-space: nowrap; }
  .m-pg-clear {
    padding: 0; margin: 0; border: 0; background: none;
    color: #a8a8b4; font-size: 12px; font-family: inherit;
    cursor: pointer; white-space: nowrap;
  }
  .m-pg-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .m-pg-card { display: block; min-width: 0; text-decoration: none; }
  .m-pg-img {
    display: block; position: relative;
    aspect-ratio: 1/1; border-radius: 11px; overflow: hidden;
    border: 1px solid #2a2a34; background: #14141b;
  }
  .m-pg-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .m-pg-play {
    position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
    min-width: 30px; height: 22px; padding: 0 8px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(10, 10, 14, .72); color: #ffcc00; font-size: 10px;
  }
  .m-pg-name {
    display: block; margin-top: 6px; color: #f2f2f5; font-size: 13px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-pg-meta {
    display: block; margin-top: 2px; color: #8a8a96; font-size: 11px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-pg-empty {
    grid-column: 1 / -1; padding: 20px 0; text-align: center;
    color: #8a8a96; font-size: 13px; line-height: 1.9;
  }
  .m-pg-empty a { color: #ffcc00; text-decoration: none; }

  /* ---------- 最新上架（横滑） ---------- */
  .m-arrivals {
    display: flex; gap: 10px;
    overflow-x: auto; padding-bottom: 4px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .m-arrivals::-webkit-scrollbar { display: none; }
  .m-arr-card {
    flex: 0 0 128px; width: 128px; text-decoration: none; position: relative;
  }
  .m-arr-img {
    display: block;
    position: relative; aspect-ratio: 1/1; border-radius: 11px; overflow: hidden;
    border: 1px solid #2a2a34; background: #14141b;
  }
  .m-arr-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .m-arr-star {
    position: absolute; top: 5px; right: 5px; width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 10, 14, .62); border-radius: 6px;
    color: #ffcc00; font-size: 12px;
  }
  .m-arr-name {
    display: block;
    margin-top: 7px; color: #f2f2f5; font-size: 13px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-arr-tag { display: block; margin-top: 2px; color: #8a8a96; font-size: 11px; }
  .m-arr-play {
    margin-top: 6px; display: inline-flex; align-items: center; gap: 4px;
    color: #ffcc00; font-size: 12.5px; font-weight: 700;
  }
  .m-arr-play::before { content: '▶'; font-size: 10px; }

  /* ---------- 热门排行榜 ---------- */
  .m-rank { display: flex; flex-direction: column; gap: 8px; }
  .m-rank-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 12px; text-decoration: none;
    background: linear-gradient(150deg, #15151d, #101016);
    border: 1px solid #23232d;
  }
  .m-rank-num {
    width: 24px; height: 24px; flex: 0 0 24px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; font-style: normal;
    background: #20202a; color: #9a9aa6;
  }
  .m-rank-item:nth-child(1) .m-rank-num { background: linear-gradient(160deg, #ffe27a, #ffb400); color: #241a02; }
  .m-rank-item:nth-child(2) .m-rank-num { background: linear-gradient(160deg, #e8ecf5, #aab2c4); color: #17181d; }
  .m-rank-item:nth-child(3) .m-rank-num { background: linear-gradient(160deg, #e8b98a, #b5763a); color: #241505; }
  .m-rank-name {
    flex: 1; min-width: 0; color: #f2f2f5; font-size: 14.5px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-rank-fire { display: flex; align-items: center; gap: 4px; color: #ff6b4a; font-size: 12px; }
  .m-rank-fire svg { width: 14px; height: 14px; }
  .m-rank-fire i { font-style: normal; color: #b8b8c4; }

  /* ---------- 底部 TabBar ---------- */
  .m-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(14, 14, 20, .96);
    border-top: 1px solid #23232d;
    backdrop-filter: blur(10px);
  }
  .m-tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: #8a8a96; font-size: 11px; text-decoration: none;
  }
  .m-tabbar a svg { width: 22px; height: 22px; }
  .m-tabbar a.active { color: #ffcc00; font-weight: 700; }
}

/* ≤430px 窄屏：收紧宫格内部，保证「MD 世嘉五代」「GG 世嘉掌机」等中文长名完整。
   阈值由 400 提到 430：图标改为 PC 同尺寸 52x42 盒后，401~430px 的
   'NEO GEO POCKET' 等长英文副标题需要一并收紧字距与字号才不出省略号。
   与 all-games-m.css 的窄屏档保持一致。仅覆盖尺寸，PC 隐藏规则不受影响。 */
@media (max-width: 430px) {
  .m-platforms { gap: 8px; }
  .m-plat { gap: 5px; padding: 9px 6px; }
  /* 图标仍保持 PC 端同尺寸；只靠 gap/padding 收紧给文字让空间 */
  .m-plat .text b { font-size: 13px; }
  /* 装饰性英文副标题：8.5px + 零字距，保证 360px 起 'NEO GEO POCKET' 不出省略号 */
  .m-plat .text i { font-size: 8.5px; letter-spacing: 0; }
  .m-plat .arr { font-size: 17px; }
  .m-plat-games .m-sec-head h2 { font-size: 14px; }
  .m-plat-games .m-sec-head h2 i { display: none; }
  .m-pg-grid { gap: 8px; }
  .m-pg-name { font-size: 12px; }
  .m-pg-meta { font-size: 10px; }
}

/* ≤360px 边界档：341~360px 落在 430 档与 340 档之间，图标固定 52x42 后
   「MD 世嘉五代」中文与「NEO GEO POCKET」英文各差 1~8px。
   只收紧边距 + 微调字号补齐，英文副标题仍完整显示，不隐藏。 */
@media (max-width: 360px) {
  .m-platforms { gap: 6px; margin: 12px 3px; }
  .m-plat { gap: 4px; padding: 8px 4px; }
  .m-plat .text b { font-size: 12.5px; }
  .m-plat .text i { font-size: 8px; }
}

/* ≤340px 极窄屏：英文副标题为装饰信息，隐藏以让出主标题空间 */
@media (max-width: 340px) {
  /* 再收 8px 外边距 + 2px 间距：图标仍保持 PC 同尺寸(52x42)，
     320px 下「MD 世嘉五代」「GG 世嘉掌机」中文名才够 70px 不省略。 */
  .m-platforms { gap: 4px; margin: 12px 2px; }
  .m-plat { gap: 4px; padding: 8px 4px; }
  .m-plat .text b { font-size: 12px; }
  .m-plat .text i { display: none; }
  .m-plat .arr { font-size: 15px; }
  /* 极窄屏卡片只有 121px，长游戏名改两行显示（固定两行高度保证卡片对齐） */
  .m-pg-name {
    white-space: normal; overflow: hidden; text-overflow: clip;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    line-height: 1.35; min-height: 32px; font-size: 11.5px;
  }
}
