/* ==========================================================================
   Oasis Village — MOBILE / RESPONSIVE LAYER
   --------------------------------------------------------------------------
   文件职责（与 desktop 严格分离）：
   - styles.css  = 桌面 / 桌面优先的基础布局与组件样式（不要在那边加移动端断点）
   - 本文件      = 仅负责窄屏适配：断点覆盖、触控、刘海安全区、小屏重排
   - js/mobile.js = 仅负责移动端交互增强（抽屉滚动锁、外点关闭、跑马灯可见性等）

   加载顺序：styles.css → 本文件（后加载可覆盖同优先级规则）

   断点约定：
   - max-width: 1024px  平板竖屏 / 小笔记本（布局收窄）
   - max-width: 820px   手机横屏 / 小平板（汉堡菜单 + 双列/单列切换）
   - max-width: 560px   手机竖屏主战场
   - max-width: 380px   小屏手机（iPhone SE 等）
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. GLOBAL — 全局窄屏安全（始终生效，desktop 上 env() 为 0，无副作用）
   -------------------------------------------------------------------------- */

/* 防止超宽字距 / 弹性子项造成整页横向滚动（sticky nav 不受影响） */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  /* 刘海屏：左右与底部安全区（viewport-fit=cover 时生效） */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  /* 首页指示条区域，避免页脚贴边 */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  /* iOS 上点按高亮更克制；不改 desktop 鼠标行为（仅 touch） */
  -webkit-tap-highlight-color: rgba(232, 184, 75, 0.18);
}

/* 触控设备上禁用 hover 粘滞，避免卡片阴影卡住 */
@media (hover: none) and (pointer: coarse) {
  .element-card:hover,
  .gallery-card:hover,
  .community-card:hover,
  .btn:hover,
  .btn-play:hover {
    transform: none;
  }

  /* 焦点仍保留键盘/无障碍可见性 */
  .element-card:active,
  .gallery-card:active {
    transform: scale(0.985);
  }
}

/* --------------------------------------------------------------------------
   1. TABLET ≤1024 — 从 5 列/4 列网格收拢（原 styles 断点迁入并微调）
   -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .feature-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .marquee-slide {
    width: min(360px, 78vw);
  }

  .marquee-slide img {
    height: 200px;
  }

  .element-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .element-card.featured {
    grid-column: span 3;
    grid-row: span 1;
  }

  .element-card.featured .element-art {
    min-height: 260px;
  }

  /* 编辑器：步骤列表在上、预览板在下 */
  .editor-layout {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --------------------------------------------------------------------------
   2. MOBILE / SMALL ≤820 — 汉堡菜单 + 主要重排
   -------------------------------------------------------------------------- */

@media (max-width: 820px) {
  /* 窄屏导航改为 fixed：
     若保持 sticky，抽屉打开时 html/body.overflow:hidden 会破坏 sticky
     （祖先变成非常规滚动容器），导航跳回文档顶部，菜单整块滚出视口。 */
  .site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    box-sizing: border-box;
  }

  /* fixed 导航脱离文档流，用 body padding 让出高度 */
  body {
    padding-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  }

  /* --- Nav：汉堡开关显示 --- */
  .nav-toggle {
    display: grid;
    /* 触控目标 ≥44px */
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  .nav-inner {
    gap: 8px;
    padding: 0 12px;
    height: var(--nav-h);
  }

  .nav-brand-logo {
    width: 36px;
    height: 36px;
  }

  .nav-brand-oasis {
    font-size: 18px;
    letter-spacing: 0.16em;
  }

  /* 抽屉：挂在 fixed .site-nav 下用 absolute（top:100%）。
     不要用抽屉自身的 position:fixed —— 锁滚 + backdrop-filter 会算错包含块。 */
  .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding:
      10px
      max(12px, env(safe-area-inset-right, 0px))
      max(14px, env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
    background: rgba(28, 16, 8, 0.98);
    border-bottom: 1px solid rgba(232, 184, 75, 0.25);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
    /* 抽屉打开时允许内部滚动（长菜单） */
    max-height: calc(100vh - var(--nav-h));
    max-height: calc(100dvh - var(--nav-h));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* 在 nav（z-index:50）的层叠上下文内即可 */
    z-index: 70;
  }

  .nav-links.is-open {
    display: flex;
  }

  .nav-links a {
    padding: 14px 16px;
    border-radius: 10px;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 16px;
  }

  /* 抽屉打开时锁定页面滚动（由 js/mobile.js 加/去 class）。
     导航已是 fixed，overflow 锁滚不会再把它顶飞。 */
  body.nav-locked,
  html.nav-locked {
    overflow: hidden;
    overscroll-behavior: none;
  }

  /* 滚动后导航更实底，提升内容可读性（mobile.js 切换 .is-scrolled） */
  .site-nav.is-scrolled {
    background: linear-gradient(180deg, rgba(61, 36, 18, 0.98), rgba(28, 16, 8, 0.97));
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
  }

  /* 窄屏隐藏顶栏社交图标，把空间留给语言 + 开始游戏 */
  .nav-actions .social-row {
    display: none;
  }

  .nav-actions {
    gap: 6px;
  }

  .lang-toggle {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    font-size: 13px;
  }

  .btn-play-nav {
    padding: 9px 12px 8px;
    min-height: 40px;
  }

  .btn-play-nav .btn-play-label {
    font-size: 13px;
  }

  /* --- 轮播：触控滑动时侧箭头常显（触屏没有 hover） --- */
  .carousel-side-btn {
    opacity: 0.92;
    pointer-events: auto;
    width: 44px;
    height: 44px;
    font-size: 26px;
    background: rgba(12, 21, 32, 0.55);
    /* 防止与页面纵向滚动手势冲突 */
    touch-action: manipulation;
  }

  .carousel-viewport {
    /* 仅允许横向手势被轮播消费，纵向仍滚页面 */
    touch-action: pan-y;
  }

  /* --- 区块留白略收紧 + 锚点避开固定导航 --- */
  .section {
    padding:
      64px
      max(16px, env(safe-area-inset-right, 0px))
      64px
      max(16px, env(safe-area-inset-left, 0px));
    scroll-margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + 8px);
  }

  [id] {
    scroll-margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + 8px);
  }

  /* --- 网格：玩法卡 / 社区卡双列；元素双列 --- */
  .feature-grid,
  .community-cards {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .element-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .element-card.featured {
    grid-column: span 2;
  }

  .element-card.featured .element-art {
    min-height: 220px;
  }

  /* 跑马灯卡片更贴合竖向滚动节奏 */
  .marquee-slide {
    width: min(300px, 82vw);
  }

  .marquee-slide img {
    height: 180px;
  }

  /* Hero cast 允许换行，避免小屏横向溢出 */
  .hero-cast {
    flex-wrap: wrap;
    gap: 12px 16px;
    min-height: auto;
  }

  /* 触控：可点区域明确 44px 下限 */
  .btn {
    min-height: 48px;
    touch-action: manipulation;
  }

  .carousel-dot {
    /* 指示点视觉仍小，用伪扩大命中区见下方 .carousel-controls */
    touch-action: manipulation;
  }

  .carousel-controls {
    padding: 4px 0;
    min-height: 44px;
    align-items: center;
  }

  /* 增大 dots 命中区而不改变视觉点大小 */
  .carousel-dot {
    position: relative;
  }

  .carousel-dot::after {
    content: "";
    position: absolute;
    inset: -10px;
  }

  /* 页脚底部留出 home indicator */
  .site-footer {
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  /* 编辑器步骤在窄屏更紧凑 */
  .editor-steps {
    gap: 12px;
  }

  .editor-copy .btn {
    width: 100%;
  }

  /* 社区卡片纵向内边距略减，首屏能多露一点内容 */
  .community-card {
    padding: 18px 14px;
  }

  .community-icon {
    width: 44px;
    height: 44px;
  }
}

/* --------------------------------------------------------------------------
   3. PHONE ≤560 — 手机竖屏：单列 + Hero 紧凑
   -------------------------------------------------------------------------- */

@media (max-width: 560px) {
  :root {
    --nav-h: 56px;
  }

  /* --- Hero --- */
  .hero {
    padding: 40px 12px 64px;
    /* 小屏用 svh，避开移动浏览器地址栏收起时的跳动 */
    min-height: calc(100svh - var(--nav-h));
  }

  .hero-content {
    padding: 64px 14px 24px;
    border-radius: 14px;
  }

  html[lang="en"] .hero-content {
    /* EN logo uses --hero-logo-y: -32% (112px → ~76px into the panel). */
    padding-top: 88px;
  }

  .hero-logo img {
    width: 112px;
    height: 112px;
  }

  .btn-play-hero {
    min-width: min(220px, 100%);
    width: 100%;
    max-width: 280px;
    padding: 14px 24px 12px;
    margin-left: auto;
    margin-right: auto;
  }

  .btn-play-hero .btn-play-label {
    font-size: 22px;
  }

  /* 字距过大导致 "OASIS" 在 375px 下溢出 — 收紧 */
  .wordmark-latin {
    letter-spacing: 0.14em;
    font-size: clamp(36px, 11vw, 48px);
  }

  .wordmark-sub {
    letter-spacing: 0.32em;
    font-size: 13px;
  }

  .hero-tagline {
    margin: 14px 0 8px;
    font-size: clamp(16px, 4.5vw, 18px);
  }

  .hero-intro {
    font-size: 14px;
    line-height: 1.65;
    margin-bottom: 16px;
  }

  /* 走路精灵整体缩小一档 */
  .walk-player {
    width: 56px;
    height: 56px;
  }

  .walk-cat {
    width: 46px;
    height: 46px;
  }

  .walk-dog {
    width: 52px;
    height: 42px;
  }

  .walk-duck,
  .walk-bird {
    width: 42px;
    height: 42px;
  }

  .hero-scroll {
    bottom: 14px;
    width: 26px;
    height: 40px;
  }

  /* --- 区块标题 --- */
  .section {
    padding: 52px 14px;
  }

  .section-head {
    margin-bottom: 28px;
  }

  .section h2 {
    font-size: clamp(24px, 6.5vw, 30px);
  }

  .section-lead {
    font-size: 15px;
  }

  /* --- 单列网格 --- */
  .feature-grid,
  .element-grid,
  .gallery-grid,
  .community-cards {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .element-card.featured {
    grid-column: span 1;
  }

  .feature-card {
    padding: 16px 14px 14px;
  }

  .feature-icon {
    height: 64px;
  }

  /* --- 轮播说明条：贴边全宽、字号可读 --- */
  .carousel-caption {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
    padding: 10px 12px;
  }

  .carousel-caption strong {
    font-size: 16px;
  }

  .carousel-caption span {
    font-size: 13px;
  }

  .carousel-caption em {
    font-size: 11px;
  }

  .carousel-side-prev {
    left: 8px;
  }

  .carousel-side-next {
    right: 8px;
  }

  /* --- 元素卡片：缩小插画区占高 --- */
  .element-art {
    min-height: 160px;
    padding: 14px 12px 6px;
  }

  .element-card.featured .element-art {
    min-height: 180px;
  }

  .element-art img {
    max-width: min(240px, 80%);
  }

  .element-card.featured .element-art img {
    max-width: min(300px, 90%);
  }

  .element-card figcaption {
    padding: 12px 12px 14px;
  }

  /* --- 编辑器 --- */
  .editor-steps li {
    grid-template-columns: 36px 1fr;
    gap: 8px;
  }

  .step-num {
    font-size: 14px;
  }

  .editor-board-bar {
    font-size: 11px;
    padding: 8px 10px;
  }

  .editor-board-foot {
    padding: 10px;
    gap: 6px;
  }

  /* --- 画廊说明条 --- */
  .gallery-note {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }

  .gallery-note .btn {
    width: 100%;
    text-align: center;
  }

  /* --- 跑马灯：更矮，减少移动端流量与占高 --- */
  .marquee-slide {
    width: min(260px, 78vw);
    border-width: 1.5px;
  }

  .marquee-slide img {
    height: 148px;
  }

  .marquee-slide figcaption {
    font-size: 13px;
    padding: 6px 10px;
    bottom: 8px;
    left: 8px;
    right: 8px;
  }

  /* --- 页脚 --- */
  .site-footer {
    padding: 32px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .footer-brand img {
    width: 72px;
    height: 72px;
  }

  .footer-oasis {
    font-size: 28px;
    letter-spacing: 0.2em;
  }

  /* --- 社区卡片单列 --- */
  .community-card {
    padding: 20px 16px;
  }

  .community-card > span:last-child {
    font-size: 13px;
  }
}

/* --------------------------------------------------------------------------
   4. SMALL PHONE ≤380 — iPhone SE / 小屏紧凑
   -------------------------------------------------------------------------- */

@media (max-width: 380px) {
  :root {
    --nav-h: 52px;
  }

  .nav-brand-oasis {
    font-size: 16px;
    letter-spacing: 0.12em;
  }

  .nav-brand-logo {
    width: 32px;
    height: 32px;
  }

  .btn-play-nav {
    padding: 8px 10px 7px;
  }

  .btn-play-nav .btn-play-label {
    font-size: 12px;
    /* 中文「开始游戏」在极窄栏换行会撑高 nav — 强制单行 */
    white-space: nowrap;
  }

  .lang-toggle {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
  }

  .hero-content {
    padding: 56px 12px 20px;
  }

  html[lang="en"] .hero-content {
    /* EN logo at -32% of 96px ≈ 65px into the panel. */
    padding-top: 76px;
  }

  .hero-logo img {
    width: 96px;
    height: 96px;
  }

  .wordmark-latin {
    letter-spacing: 0.1em;
  }

  .wordmark-sub {
    letter-spacing: 0.24em;
    font-size: 12px;
  }

  .btn-play-hero .btn-play-label {
    font-size: 20px;
  }

  .section {
    padding: 44px 12px;
  }

  .carousel-caption {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 8px 10px;
  }

  .carousel-caption strong {
    font-size: 15px;
  }

  .carousel-side-btn {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }
}

/* --------------------------------------------------------------------------
   5. LANDSCAPE PHONE（短视口）— 横屏手机避免 Hero 被裁切
   -------------------------------------------------------------------------- */

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .hero {
    min-height: auto;
    padding: 28px 16px 40px;
  }

  .hero-logo img {
    width: 80px;
    height: 80px;
  }

  .hero-content {
    padding-top: 48px;
  }

  html[lang="en"] .hero-content {
    /* EN logo at -32% of 80px ≈ 54px into the panel. */
    padding-top: 64px;
  }

  .hero-cast {
    min-height: 56px;
  }

  .walk-player {
    width: 48px;
    height: 48px;
  }

  .hero-scroll {
    display: none;
  }

  .section {
    padding-top: 40px;
    padding-bottom: 40px;
  }
}

/* --------------------------------------------------------------------------
   6. REDUCED MOTION + NARROW — 窄屏也尊重系统减弱动效
   （styles.css 已有全局 reduced-motion；这里补跑马灯在窄屏换行）
   -------------------------------------------------------------------------- */

@media (max-width: 820px) and (prefers-reduced-motion: reduce) {
  .marquee-track {
    animation: none;
    flex-wrap: wrap;
    width: auto;
    justify-content: center;
  }

  .gameplay-marquee {
    mask-image: none;
    -webkit-mask-image: none;
  }
}

/* --------------------------------------------------------------------------
   7. UTILITIES — 仅移动端使用的工具类（供 mobile.js 挂载）
   -------------------------------------------------------------------------- */

/* 抽屉打开时覆盖在内容上的半透明遮罩（js/mobile.js 创建 .nav-scrim） */
.nav-scrim {
  display: none;
}

@media (max-width: 820px) {
  .nav-scrim {
    display: block;
    position: fixed;
    /* 与 fixed 导航底边对齐（含刘海安全区） */
    inset:
      calc(var(--nav-h) + env(safe-area-inset-top, 0px))
      0
      0
      0;
    background: rgba(4, 12, 20, 0.45);
    /* 必须低于 .site-nav(50)：抽屉是 nav 的子元素，
       遮罩 z-index 过高会盖住菜单，看起来像“点了没弹出来” */
    z-index: 40;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    /* 由 mobile.js 控制显隐 */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .nav-scrim.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* 横向内容保险：任何意外超宽元素不应撑出页面 */
  .section-inner,
  .nav-inner,
  .footer-inner,
  .hero-content {
    max-width: 100%;
  }

  img {
    max-width: 100%;
    height: auto;
  }

  /* 长英文词/URL 不撑破卡片 */
  .gallery-meta p,
  .feature-card p,
  .editor-steps p,
  .element-card span,
  .section-lead,
  .hero-intro {
    overflow-wrap: break-word;
    word-break: break-word;
  }
}
