/* ==========================================================================
   移动端统一修正层（以 iPhone 15 Pro Max 430×932 为基准，向下兼容 390/375）
   必须在各页面自身 CSS 之后加载，用于修正页面级样式覆盖掉 common.css 的地方。
   ========================================================================== */

@media (max-width: 768px) {
  /* ── 1. 全局 ── */
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; overflow-wrap: anywhere; }
  .main {
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
  }

  /* Toast 的 z-index 原本高于弹窗遮罩（999 > 500），会盖住底部弹窗的按钮 */
  .toast {
    z-index: 400;
    bottom: calc(78px + env(safe-area-inset-bottom));
  }

  /* 底部弹窗：用 svh 适配 Safari 地址栏，给 home indicator 留空间 */
  .modal { max-height: 92vh; max-height: 92svh; }
  .modal-body {
    max-height: calc(92vh - 64px);
    max-height: calc(92svh - 64px);
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .modal-head { gap: 8px; }
  .modal-head h3 {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.35;
  }
  .modal-tools { flex-shrink: 0; }
  /* 讲解弹窗头部太挤：隐藏字号数字，只留 A− / A+ */
  .modal-tools .font-size-label { display: none; }

  /* iOS 聚焦输入框时字号 <16px 会自动放大页面 */
  input, textarea, select { font-size: 16px !important; }

  /* 触控：去掉点击灰色高亮，避免双击缩放 */
  button, a, .quiz-option, .clr-kp-chip, .tab-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .quiz-btn, .btn-sm { min-height: 42px; }

  /* ── 2. 顶部导航 ── */
  .nav {
    padding-left: 12px;
    padding-right: 12px;
  }
  .nav-logo {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    gap: 0;
  }
  .nav-logo::before {
    width: 30px; height: 30px; flex-basis: 30px; margin-right: 8px;
    border-radius: 10px; background-size: 18px 18px, 100% 100%;
  }
  .nav-right { flex-shrink: 0; }
  .nav-right > span:first-child {
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .admin-nav-sub { display: none; }

  /* ── 3. 首页 ── */
  /* 5 个标签页：图标在上、文字在下，一排排满不换行 */
  .tabs-bar { gap: 2px; padding: 4px; }
  .tab-btn {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    padding: 8px 2px;
    font-size: 11.5px;
    line-height: 1.1;
    white-space: nowrap;
  }
  .tab-ico { font-size: 17px; line-height: 1; }
  .tab-label { font-size: 11px; }

  .review-banner {
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 12px 14px;
  }
  .review-banner-icon { order: 1; }
  .review-banner-text { flex: 1 1 200px; min-width: 0; order: 2; font-size: 12.5px; }
  .review-banner-go { order: 3; margin-left: auto; }

  /* 书库两列：封面略收，按钮等宽不挤压 */
  .library-grid { gap: 10px; }
  .book-cover { aspect-ratio: 3 / 4; }
  .book-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .book-actions .btn-book-action {
    width: 100%; min-height: 38px; padding: 6px 4px; font-size: 12px;
  }
  /* 卡片元信息：竖排两行，避免「525.8 KB · 日期」在窄卡片里断成三行 */
  .book-card .book-meta {
    display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
    line-height: 1.35;
  }
  .book-card .book-meta > span:nth-child(even) { display: none; }

  /* 合集作者行：按钮不再把作者名挤成一字一行 */
  .author-group-head { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .author-group-head .author-arrow { font-size: 10px; }
  .author-group-head .author-avatar { width: 38px; height: 38px; font-size: 16px; }
  .author-group-head .author-name {
    display: flex; font-size: 14px; line-height: 1.35;
    white-space: normal; overflow: visible;
  }
  .author-group-head .author-name-text {
    min-width: 0; white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .author-group-head .author-badge { display: none; }
  .author-group-head .author-meta { font-size: 11.5px; line-height: 1.5; margin-top: 2px; }
  .author-group-head .author-actions { flex: 1 1 100%; display: flex; align-items: center; gap: 6px; }
  .author-group-head .author-actions .btn-book-action { flex: 1; min-width: 0; }
  .author-group-head .btn-book-action {
    flex-shrink: 0; min-height: 36px; padding: 5px 8px !important;
    font-size: 11.5px !important; white-space: nowrap !important;
  }
  .author-group-head .author-del { font-size: 14px; padding: 4px; }

  /* 列表视图（我的下载等）：缩略图上的角标隐藏，操作按钮整行铺满 */
  .library-grid.list-view .book-badge { display: none; }
  .library-grid.list-view .book-actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    width: 100%; margin-left: 0; margin-top: 6px;
  }
  .library-grid.list-view .book-actions .btn-book-action {
    width: 100%; min-height: 36px; font-size: 11.5px; padding: 5px 4px;
    white-space: nowrap;
  }
  .library-grid.list-view .book-actions .btn-book-action:nth-child(3) {
    grid-column: 1 / -1;
  }

  /* ── 4. 书籍学习页 ── */
  .book-bar { gap: 10px; }
  .book-name { white-space: normal; line-height: 1.35; }
  .book-meta { line-height: 1.6; }
  .kp-page-head { align-items: flex-start; }
  .desktop-hint { display: none !important; }
  .kp-card-actions { gap: 8px; }
  .kp-card-actions .btn-action {
    flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px;
  }

  /* 章末检验入口：文案在上，按钮整行 */
  .chapter-exam-bar { gap: 10px; padding: 14px; }
  .chapter-exam-info { min-width: 0; }
  .chapter-exam-bar .quiz-btn { width: 100%; }

  /* 章节检验答题页：操作区不再被挤成两行半 */
  .quiz-actions { gap: 8px; }
  .quiz-actions .quiz-btn { flex: 1 1 auto; padding: 10px 12px; font-size: 13.5px; }
  .exam-nav { margin-left: 0 !important; width: 100%; flex: 1 1 100%; }
  .exam-nav .quiz-btn { width: 100%; }
  .exam-kbd-hint { display: none !important; }
  .exam-result-actions .quiz-btn { flex: 1 1 100%; }
  .exam-score-num { font-size: 40px; }
  .exam-kp { gap: 6px; }
  .exam-kp-meta { font-size: 11px; }

  .quiz-stem { font-size: 14.5px; }
  .quiz-option { padding: 12px 12px; font-size: 14px; gap: 9px; }

  /* 弹窗头部章节名限宽省略，避免挤掉关闭按钮 */
  .quiz-head-chapter {
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .split-hint { display: none !important; }

  /* ── 5. 视频学习页 ── */
  .video-bar { flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 14px; }
  .video-bar .book-icon { font-size: 30px; }
  .video-bar .book-info { flex: 1 1 calc(100% - 48px); min-width: 0; }
  .video-bar .book-name {
    font-size: 16px; white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .video-bar .book-meta { flex-wrap: wrap; gap: 2px 8px; font-size: 12.5px; }
  .video-bar .book-meta > span:nth-child(even) { display: none; }
  .video-bar > .btn-action { flex: 1 1 100%; min-height: 42px; margin-top: 2px; }

  .kp-parent-head { flex-wrap: wrap; gap: 8px; }
  .kp-parent-left { min-width: 0; flex: 1 1 calc(100% - 120px); }
  .kp-parent-title { white-space: normal; }
  .kp-parent-head .kp-quiz-btn { margin-left: auto; }

  /* ── 6. 合集学习页 ── */
  .author-head { flex-wrap: wrap; align-items: flex-start; padding: 16px; gap: 12px; }
  .author-head .author-avatar { width: 44px; height: 44px; font-size: 20px; }
  .author-head > div:not(.author-avatar):not(.author-actions) { flex: 1 1 0; min-width: 0; }
  .author-head .author-title { font-size: 17px; line-height: 1.4; overflow-wrap: anywhere; }
  .author-head .author-sub { font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
  .author-actions { flex: 1 0 100%; display: flex; gap: 8px; }
  .author-actions .btn-action {
    flex: 1 1 0; min-width: 0; min-height: 40px;
    padding: 8px 6px; font-size: 12.5px;
  }

  .clr-progress { gap: 8px 14px; padding: 12px 14px; }
  .clr-progress-btn { margin-left: 0; width: 100%; min-height: 40px; }
  .clr-ch-head { flex-wrap: wrap; gap: 8px; padding: 14px; }
  .clr-ch-title { flex: 1 1 auto; min-width: 0; }
  .clr-ch-body { padding: 14px; }
  .clr-quiz-head { flex-wrap: wrap; row-gap: 4px; }
  .clr-quiz-state { margin-left: 0; }
  .clr-kp-chip { max-width: 100%; }
  .clr-kp-chip-title { max-width: 62vw; }
  .term-grid { grid-template-columns: 1fr; }

  /* ── 7. 直播页 ── */
  .live-wrap { padding: 4px 0 20px; }
  .live-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .live-head h2 { font-size: 20px; }
  .live-head > span { font-size: 12.5px; line-height: 1.6; }
  .live-form { padding: 16px 14px; border-radius: 14px; }
  .live-textarea, .live-input { font-size: 16px !important; }
  .live-textarea { min-height: 112px; line-height: 1.65; }
  .live-options { flex-wrap: wrap; row-gap: 10px; }
  .radio-group { flex-wrap: wrap; row-gap: 6px; }
  .btn-live { width: 100%; }
  .btn-live.stop { margin-left: 0 !important; margin-top: 10px; }

  /* ── 8. 复习页 ── */
  .review-wrap { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .review-head { align-items: flex-start; gap: 6px; padding: 4px 4px 14px; }
  .review-head h2 { font-size: 24px; }
  .review-item { padding: 14px 14px 16px; }
  .review-item-top { row-gap: 6px; }
  .review-kp { flex: 1 1 140px; min-width: 0; font-size: 15px; }
  .review-due { flex-shrink: 0; }
  .review-start .quiz-btn { width: 100%; }

  /* ── 9. 后台管理 ── */
  .admin-layout { display: block; min-height: auto; }
  .admin-main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)) !important; }
  .admin-sidebar {
    width: 240px !important;
    display: block !important;
    padding: 16px 0 !important;
    overflow: visible !important;
  }
  .admin-sidebar-item {
    display: flex !important;
    padding: 12px 20px !important;
    min-height: 0 !important;
    border-left: 3px solid transparent !important;
    border-radius: 0 8px 8px 0 !important;
    white-space: normal;
  }
  .admin-sidebar-item.active {
    border-left-color: var(--primary) !important;
    background: var(--primary-bg) !important;
    color: var(--primary) !important;
  }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .user-table { display: table !important; width: 100% !important; min-width: 560px !important; }
  .user-table thead { display: table-header-group !important; }
  .user-table tbody { display: table-row-group !important; }
  .user-table th, .user-table td {
    padding: 10px 8px !important; font-size: 12.5px !important; white-space: nowrap;
  }
  /* 技能表：手机上同时隐藏「描述」「指令」，保住名称/状态/操作三列 */
  .skill-table { min-width: 0 !important; }
  .skill-table th:nth-child(4), .skill-table td:nth-child(4) { display: none; }
  .skill-table th, .skill-table td { padding: 9px 6px !important; }
  .setting-row { margin-bottom: 18px; }
  .settings-actions { flex-direction: column; gap: 10px; }
  .btn-settings { width: 100%; }
  .modal-box { width: 94vw !important; max-width: 94vw !important; }
  .modal-footer { flex-wrap: wrap; }

  /* ── 10. PDF 逐页阅读器：知识面板从「盖住半屏的浮层」改为正文下方 ── */
  .reader-layout { display: block; }
  .reader-left { padding: 12px 12px 16px; max-height: none; }
  .reader-right {
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 14px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,.05);
    padding-bottom: 0;
  }
  .reader-right.collapsed {
    width: 100%;
    overflow: visible;
    max-height: none;
    border-top: 1px solid var(--border-light);
  }
  .panel-tabs { position: sticky; top: 0; z-index: 2; background: var(--card); }
  .panel-body { max-height: none; }
  .reader-content img { width: 100%; height: auto; }

  /* ── 11. 视频预览页 ── */
  .video-detail { padding: 6px 8px; }
  .video-title {
    white-space: normal; overflow: hidden;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    font-size: 17px; line-height: 1.45;
  }
  .content-summary-text, .content-summary-card, .video-content { overflow-wrap: anywhere; }
  /* 悬停术语 tooltip 在手机上不可用，而且绝对定位会撑大页面宽度 */
  .key-term::after { display: none !important; }
}

@media (max-width: 480px) {
  .nav-logo::before {
    width: 28px; height: 28px; flex-basis: 28px;
    border-radius: 9px; background-size: 17px 17px, 100% 100%;
  }
  .library-grid { gap: 8px; }
  .book-actions .btn-book-action { font-size: 11.5px; }
  .kp-card-actions .btn-action { font-size: 12px; }
  .chapter-exam-bar { padding: 12px; }
  .chapter-exam-title { font-size: 13.5px; }
  .chapter-exam-sub { font-size: 11.5px; }
  .review-banner { padding: 11px 12px; }
  .review-banner-text { font-size: 12px; }
  .review-head h2 { font-size: 22px; }
  .author-actions .btn-action { font-size: 12px; }
  .summary-font-controls .font-label,
  .summary-font-controls .font-size-value { display: none; }

  /* 用户表：小屏隐藏「注册时间」，让操作按钮不用横向拖拽 */
  .user-table { min-width: 0 !important; }
  .user-table th:nth-child(3),
  .user-table td:nth-child(3) { display: none; }
  .user-table th, .user-table td { padding: 10px 6px !important; }
}

@media (max-width: 420px) {
  /* 视频卡在窄屏改为单列按钮，避免「深入学习 / 内容总结」折行 */
  .book-card.video-card .book-actions { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* 合集/书库标题栏：导入进度按钮出现时，标题被挤成竖排 */
  .library-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
  }
  /* 让标题、计数、整理、进度按钮都直接参与外层 flex，避免被挤到单独一行 */
  .library-head > div:first-child { display: contents; }
  .library-head h3 { white-space: nowrap; flex-shrink: 0; font-size: 18px; }
  .library-head > div:first-child > span { font-size: 11.5px; }
  .library-head .view-toggle { margin-left: auto; }
}
