/* ========================================
   移动端适配 · Mobile v2.0
   ======================================== */

/* --- 安全区域（刘海屏/底部手势条） --- */
@supports (padding: env(safe-area-inset-left)) {
  .nav-primary {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .site-footer {
    padding-bottom: calc(var(--sp-lg) + env(safe-area-inset-bottom));
  }
  .container {
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
  }
}

/* ═══════════════════════════════════════
   768px 以下 · 手机/小平板
   ═══════════════════════════════════════ */
@media (max-width: 768px) {

  /* --- 导航：全屏抽屉菜单 --- */
  .nav-toggle { display: flex; }

  .nav-menu {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--c-surface);
    flex-direction: column;
    padding: var(--sp-lg);
    padding-top: var(--sp-xl);
    gap: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 99;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .nav-menu.open { transform: translateX(0); }

  .nav-link {
    font-size: 18px;
    padding: var(--sp-md) 0;
    border-bottom: 1px solid var(--c-border);
    /* 增大点击区域 */
    min-height: 48px;
    display: flex;
    align-items: center;
  }
  .nav-link:active {
    color: var(--c-accent);
    background: var(--c-surface-alt);
  }

  /* 菜单打开时禁止背景滚动 */
  body.menu-open {
    overflow: hidden;
    touch-action: none;
  }

  /* --- 英雄区/标题区 --- */
  .hero { padding: var(--sp-lg) 0; }
  .hero h1 { font-size: var(--fs-h2); }
  .hero-sub { font-size: var(--fs-small); }
  .chapter-info { gap: var(--sp-xs); }
  .chapter-info .chip { font-size: 11px; padding: 2px 8px; }

  /* --- 主内容区：缩减上下间距 --- */
  .main-content { padding: var(--sp-lg) 0; }

  /* --- 卡片单列 --- */
  .card-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-sm);
  }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* 卡片触摸反馈 */
  .card {
    padding: var(--sp-md);
  }
  .card:active {
    background: var(--c-surface-alt);
    border-color: var(--c-accent);
  }

  /* --- 章节阅读：深度适配 --- */
  .chapter-body {
    font-size: 17px;
    line-height: 2;
    /* 中文阅读优化 */
    word-break: break-all;       /* 避免长英文/数字溢出 */
    overflow-wrap: break-word;
    text-size-adjust: 100%;      /* 禁止iOS自动调整字号 */
    -webkit-text-size-adjust: 100%;
  }
  .chapter-body p {
    text-indent: 2em;
    margin-bottom: var(--sp-md);
    /* 避免段间距在窄屏过大 */
    orphans: 2;
    widows: 2;
  }
  .chapter-body h2 {
    font-size: clamp(18px, 5vw, 24px);
    margin-top: var(--sp-xl);
  }
  .chapter-body h3 {
    font-size: clamp(16px, 4.5vw, 20px);
    margin-top: var(--sp-lg);
  }
  .chapter-body blockquote {
    margin: var(--sp-md) var(--sp-sm);
    font-size: 15px;
  }
  .chapter-body .scene-break {
    margin: var(--sp-lg) 0;
    letter-spacing: 0.6em;       /* 窄屏缩小间距 */
  }

  /* --- 章节导航：堆叠 + 全宽 --- */
  .chapter-nav {
    flex-direction: column;
    gap: var(--sp-sm);
    margin-top: var(--sp-xl);
    padding-top: var(--sp-lg);
  }
  .chapter-nav-btn {
    max-width: 100%;
    padding: var(--sp-md);
    min-height: 56px;            /* 拇指友好 */
  }
  .chapter-nav-btn.next { text-align: left; }
  .chapter-nav-title { font-size: 14px; }

  /* --- 圣经/设定页：移动适配 --- */
  .bible-body {
    font-size: 16px;
    line-height: 1.8;
    word-break: break-all;
    overflow-wrap: break-word;
    -webkit-text-size-adjust: 100%;
  }
  .bible-body h2 {
    font-size: clamp(17px, 5vw, 22px);
    margin-top: var(--sp-xl);
    /* 左侧色带缩窄 */
    border-left-width: 3px;
    padding-left: var(--sp-sm);
  }
  .bible-body h3 {
    font-size: clamp(15px, 4vw, 18px);
    margin-top: var(--sp-lg);
  }
  .bible-body blockquote {
    margin: var(--sp-sm) 0;
    padding: var(--sp-xs) var(--sp-sm);
    font-size: var(--fs-small);
  }

  /* 统计卡片：自适应列数 */
  .bible-body .stat-grid td {
    padding: var(--sp-sm);
  }
  .bible-body .stat-num {
    font-size: 20px;
  }
  .bible-body .stat-label {
    font-size: 11px;
  }

  /* 设定页表格：横向滚动 + 渐变提示 */
  .bible-body table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* 滚动渐变阴影提示（右侧有更多内容） */
    background:
      linear-gradient(to right, transparent 95%, rgba(0,0,0,0.04) 100%);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: 0 0;
  }
  .bible-body thead { display: table-header-group; }
  .bible-body tbody { display: table-row-group; }

  /* 基础表格也做响应式 */
  table {
    font-size: var(--fs-xs);
  }
  thead th {
    padding: var(--sp-xs) var(--sp-sm);
    white-space: nowrap;
  }
  tbody td {
    padding: var(--sp-xs) var(--sp-sm);
  }

  /* --- 角色布局：单列 --- */
  .character-body { grid-template-columns: 1fr; }
  .character-sidebar {
    position: static;
    /* 侧边栏变为底部信息卡 */
    background: var(--c-surface-alt);
    border-radius: var(--radius-md);
    padding: var(--sp-md);
    margin-top: var(--sp-lg);
  }
  .character-sidebar .info-table {
    margin: 0;
  }

  /* --- 信息表格 --- */
  .info-table { font-size: var(--fs-xs); }
  .info-table th, .info-table td { padding: var(--sp-xs) var(--sp-sm); }
  .info-table th { width: 80px; }

  /* --- 首页 --- */
  .home-hero { padding: var(--sp-xl) 0; }
  .home-title { font-size: clamp(24px, 8vw, 36px); }
  .home-desc { font-size: var(--fs-small); }

  /* --- 小说索引 --- */
  .volume-group { margin-bottom: var(--sp-lg); }
  .volume-title { font-size: var(--fs-body); }

  /* --- 影视剧本：等宽字体缩小 --- */
  .screenplay-body {
    font-size: 13px;
    line-height: 1.6;
  }
  .screenplay-body .dialogue {
    margin-left: 2em;
    margin-right: 2em;
  }

  /* --- 关联区 --- */
  .related-section {
    margin-top: var(--sp-xl);
    padding-top: var(--sp-lg);
  }

  /* --- 面包屑 --- */
  .breadcrumb {
    font-size: var(--fs-xs);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* ═══════════════════════════════════════
   超小屏 · 380px 以下（SE/老机型）
   ═══════════════════════════════════════ */
@media (max-width: 380px) {
  :root {
    --fs-body: 16px;
    --fs-chapter: 17px;
    --sp-xl: 32px;
    --sp-2xl: 48px;
  }
  .container {
    padding: 0 12px;
  }
  .home-title { font-size: clamp(22px, 9vw, 30px); }
  .card { padding: var(--sp-sm); }
  .card h3 { font-size: 15px; }
  .chapter-body { font-size: 16px; }
  .bible-body { font-size: 15px; }
  .nav-brand { font-size: 16px; }
}

/* ═══════════════════════════════════════
   触摸设备优化（不限宽度）
   ═══════════════════════════════════════ */
@media (pointer: coarse) {
  /* 所有可交互元素最小 44×44 */
  .nav-link, .tag, .chip, .chapter-nav-btn, .breadcrumb {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* 卡片全区域可点击 */
  .card {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* 标签触摸反馈 */
  .tag:active {
    background: var(--c-accent);
    color: #fff;
    border-color: var(--c-accent);
  }

  /* 禁止双击缩放（加速点击响应） */
  a, button, .card, .tag, .chip {
    touch-action: manipulation;
  }
}

/* ═══════════════════════════════════════
   减弱动画偏好
   ═══════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .nav-menu { transition: none; }
  .nav-toggle span { transition: none; }
  .card, .tag, .chapter-nav-btn { transition: none; }
}
