/* ===== 移动端适配（feature/mobile-adapt）=====
   覆盖范围：index.html 全部页面（首页/录题/AI录题/题库浏览/组卷中心/管理中心）+ paper.html 试卷预览
   排版中心 studio.html 不在本次适配范围。
   断点：≤640px 手机；641–900px 由 styles.css 既有规则接管（单列布局）。 */

@media (max-width: 640px) {

  /* ---- 基础 ---- */
  body { -webkit-text-size-adjust: 100%; overflow-x: clip; } /* 宽内容不撑出横向滚动(防浏览器改变视口缩放) */
  #nav-studio { display: none; } /* 排版中心仅电脑端显示 */
  main { padding: 12px; }
  .katex-display { overflow-x: auto; overflow-y: hidden; } /* 超长公式内部滚动, 不撑破页面 */
  .page h2 { font-size: 17px; margin-bottom: 12px; }
  .card { padding: 14px; border-radius: 10px; }
  .btn { min-height: 38px; padding: 8px 14px; font-size: 14px; }
  .btn.small { min-height: 32px; padding: 5px 10px; font-size: 12.5px; }
  input, select, textarea { font-size: 16px !important; } /* 防 iOS 聚焦自动放大页面 */

  /* ---- 顶栏: 汉堡 + logo + 当前页名(品牌文字让位) ---- */
  .topbar { flex-wrap: nowrap; gap: 8px; padding: 0 10px; height: 52px; }
  .brand { font-size: 15px; white-space: nowrap; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .brand .brand-text { display: none; }
  #topbar-title { display: inline; font-size: 15px; font-weight: 700; }
  #nav-burger { display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; font-size: 19px; line-height: 1; flex-shrink: 0;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
  .user-area { display: none; } /* 窄屏用户操作(个人中心/退出)收进左侧抽屉 */

  /* ---- 左侧可折叠抽屉菜单 ---- */
  .topbar nav { position: fixed; top: 0; left: 0; bottom: 0; width: 246px; z-index: 120;
    background: #fff; flex-direction: column; align-items: stretch; gap: 4px;
    padding: 16px 12px; box-shadow: 2px 0 18px rgba(15,23,42,.18);
    transform: translateX(-106%); transition: transform .22s ease;
    overflow-y: auto; -webkit-overflow-scrolling: touch; }
  body.nav-open .topbar nav { transform: translateX(0); }
  .topbar nav .nav-btn { width: 100%; text-align: left; padding: 12px 14px; font-size: 14.5px;
    border-radius: 9px; white-space: nowrap; flex-shrink: 0; }
  .nav-mask:not(.hidden) { display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(15,23,42,.42); }
  .topbar nav .nav-user { display: flex; flex-direction: column; gap: 4px;
    margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
  .nav-user-badge { font-size: 13px; color: var(--muted); padding: 2px 14px 8px; }

  /* ---- 登录页 ---- */
  .auth-card { width: 92vw; padding: 26px 22px; }

  /* ---- 首页统计卡 ---- */
  .stat-hero { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
  .hero-card { padding: 14px 14px 12px; border-radius: 12px; }
  .hero-card .hero-num { font-size: 28px; }
  .hero-card .hero-lbl { margin-top: 3px; font-size: 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .num { font-size: 24px; }

  /* ---- 手工录题 ---- */
  .edit-layout { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; min-width: 110px; }
  .paste-box { min-width: 100%; }

  /* ---- 题库浏览: 隐藏大类徽章行(顶栏已显示页名, 分类走筛选项) ---- */
  #cat-stats { display: none; }

  /* ---- 所有页面: 页内"菜单字"标题(h2)全部隐藏, 只留标题栏 ---- */
  .page > h2 { display: none; }

  /* ---- 题库浏览: 选题/查卷子页签(样式在 styles.css, 双端一致) ---- */

  /* ---- 查卷: 试卷库 ---- */
  /* 套卷卡片主体样式已并入 styles.css 全局(PC 网格/移动单列); 筛选条复用下方 .filter-bar 折叠机制 */

  /* ---- 筛选面板: 默认折叠为搜索入口, 点击展开 ---- */
  .filter-bar { padding: 10px; }
  .fb-entry { display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px;
    background: #f8fafc; font-size: 14px; color: var(--muted); cursor: pointer; }
  .fb-entry-ico { font-size: 15px; }
  .fb-entry-text { flex: 1; text-align: left; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; color: var(--text); }
  .fb-entry-badge { background: var(--primary); color: #fff; font-size: 11px;
    border-radius: 999px; padding: 1px 8px; font-weight: 700; }
  .fb-entry-arrow { transition: transform .18s; font-size: 12px; }
  .fb-entry.open .fb-entry-arrow { transform: rotate(180deg); }
  .filter-bar .fb-body { display: none; }
  .filter-bar.open .fb-body { display: block; margin-top: 10px; }
  .cat-stats { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .cat-chip { flex-shrink: 0; }
  .fb-main { flex-direction: column; align-items: stretch; gap: 8px; }
  .fb-search { min-width: 0; }
  .fb-field { flex-direction: row; align-items: center; gap: 8px; }
  .fb-field > label { width: 40px; flex-shrink: 0; padding-left: 0; }
  .fb-field select, .fb-field input { flex: 1; min-width: 0; width: 100%; }
  .fb-go { width: 100%; }
  .fb-more { align-self: center; }
  .fb-adv { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 8px 4px; }
  .fb-reset { margin-left: 0; align-self: center; }

  /* ---- 题目卡片(列表精简: 题干+出处, 无标签无按钮; 点卡片进详情) ---- */
  .q-card { padding: 14px; }
  .q-head { gap: 6px; }
  #question-list .q-card, #sheet-list .q-card { cursor: pointer; }
  #question-list .q-card .q-head,          /* 列表卡: 整行标签徽章不显示 */
  #question-list .q-card .q-actions,
  #question-list .q-card .q-foot,
  #question-list .q-card .q-panel,
  #question-list .q-card .opt-line,
  #sheet-list .q-card .q-head,             /* 套卷题卡: 与选题列表同款精简 */
  #sheet-list .q-card .q-actions,
  #sheet-list .q-card .q-foot,
  #sheet-list .q-card .q-panel,
  #sheet-list .q-card .opt-line { display: none; }
  /* 详情页: 标签+选题/编辑/删除在出处后; 头部只留考点标签, 答案/解析走独立大卡片 */
  #page-qdetail .q-card { display: flex; flex-direction: column; }
  #page-qdetail .q-card > .q-body { order: 1; }
  #page-qdetail .q-card > .q-head { order: 2; margin: 10px 0 0; flex-wrap: wrap; }
  #page-qdetail .q-card > .q-foot { order: 3; }
  #page-qdetail .q-head .q-type-badge,
  #page-qdetail .q-head .q-cat,
  #page-qdetail .q-head .q-diff,
  #page-qdetail .q-head .q-tag-en { display: none; }    /* 只显示考点标签 */
  /* 详情页内按钮排版 */
  .q-actions { margin-left: 0; width: 100%; display: flex; gap: 6px; }
  .q-actions .btn { flex: 1; white-space: nowrap; padding-left: 4px; padding-right: 4px; }
  .q-body { font-size: 15px; }
  .q-foot { flex-direction: column; align-items: stretch; gap: 8px; }
  .q-foot .q-meta { flex: none; }
  .q-foot-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-left: 0; width: 100%; }
  .q-foot-btns .btn { width: 100%; min-width: 0; white-space: nowrap; padding: 6px 2px; font-size: 12px; }
  .q-images img { max-width: 100%; max-height: none; }
  /* KaTeX 长公式允许横向滚动，不撑破卡片 */
  .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
  .math { overflow-wrap: anywhere; }
  .pager { flex-wrap: wrap; }

  /* ---- 组卷中心 ---- */
  .paper-layout { grid-template-columns: 1fr; }
  .paper-side { position: static; max-height: none; }
  /* 试卷 hover 操作（重命名/删除等）在触屏常显，否则点不到 */
  .paper-item .paper-ops { display: flex; }
  .folder-ops { display: inline-flex; }
  /* 文档编辑区收窄边距 */
  .doc-page { padding: 20px 16px; min-height: 400px; }
  .doc-toolbar { top: 56px; padding: 8px 10px; gap: 5px; flex-wrap: nowrap;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .doc-toolbar::-webkit-scrollbar { display: none; }
  .doc-toolbar .btn { padding: 6px 10px; white-space: nowrap; flex-shrink: 0; }
  /* A4 分页线标记在窄屏溢出，隐藏 */
  .a4-page-mark { display: none; }
  /* 题目悬浮工具栏触屏常显 */
  .pq-floater { opacity: 1; transform: none; pointer-events: auto; position: static;
    display: flex; margin-bottom: 6px; box-shadow: none; background: #f8fafc; }
  .paper-block .pb-ops { display: flex; }

  /* ---- 选题篮 ---- */
  .cart-fab { right: 16px; bottom: 76px; width: 52px; height: 52px; }  /* 让位给右下 back-fab 返回钮, 不重叠 */
  .cart-drawer { width: 100vw; max-width: 100vw; }

  /* ---- AI录题 ---- */
  .upload-zone { padding: 24px 12px; }
  .imp-edit textarea, .imp-edit input, .imp-edit select { width: 100%; }

  /* ---- 管理中心: 功能栏 3×2 网格全部展示, 不用横滑 ---- */
  .admin-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-bottom: 0; }
  .admin-tab { white-space: normal; text-align: center; padding: 9px 2px; font-size: 12.5px; line-height: 1.3; }
  .auto-row { flex-direction: column; align-items: stretch; }
  .auto-row input, .auto-row select { width: 100% !important; min-width: 0 !important; }
  .auto-row .btn { width: 100%; }
  .aq-filters { flex-direction: column; align-items: stretch; }
  .aq-filters input, .aq-filters select, .aq-filters .btn { flex: none; width: 100%; min-width: 0; }
  /* 题目管理: 筛选默认折叠(点入口展开), 查询后自动收起 */
  #aq-filter-body { display: none; }
  #aq-filter-body.open { display: block; margin-top: 10px; }
  /* 题目管理列表: 卡片化分行展示全部字段, 不横滑不截断 */
  :is(.aq-table, .sm-table) { min-width: 0; table-layout: auto; }
  :is(.aq-table, .sm-table) thead { display: none; }
  :is(.aq-table, .sm-table), :is(.aq-table, .sm-table) tbody,
  :is(.aq-table, .sm-table) tr, :is(.aq-table, .sm-table) td { display: block; width: 100%; }
  :is(.aq-table, .sm-table) tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; }
  :is(.aq-table, .sm-table) td { border-bottom: none; padding: 4px 0; }
  :is(.aq-table, .sm-table) td::before { content: attr(data-label) "："; font-weight: 600; color: var(--muted); }
  :is(.aq-table, .sm-table) td:not([data-label])::before { content: none; }
  .aq-table .aq-src { white-space: normal; overflow: visible; text-overflow: clip; }
  /* 数据表格横向滚动（保留 PC 表结构，不卡片化，信息不丢失） */
  .atab-page .card, #atab-questions .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 560px; }
  .tag-add { flex-wrap: wrap; }
  .tag-add input { min-width: 100%; }

  /* ---- 弹窗 / 通知 ---- */
  .confirm-box { width: 92vw; padding: 20px; }
  #uc-mask .confirm-box { width: 92vw !important; max-width: 400px; }
  #toast-wrap { top: auto; bottom: 14px; right: 12px; left: 12px; align-items: center; }
  .toast { min-width: 0; width: 100%; max-width: none; }

  /* ---- 试卷预览页 paper.html(悬浮工具栏 2×2 等宽网格, 不换行) ---- */
  .print-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; width: calc(100vw - 24px); max-width: 480px; }
  .print-bar .btn { width: 100%; white-space: nowrap; }
  .paper-wrap { padding-top: 118px; }   /* 悬浮条 2×2 网格更高, 让出更多顶部空间 */
  .paper-doc { padding: 20px 16px; line-height: 1.9; }
  .paper-doc h1 { font-size: 19px; }

  /* ---- 知识点筛选树: 侧栏变左侧抽屉(遮罩必须与抽屉同在 .page 内, 见 index.html 注释) ---- */
  .pick-wrap { display: block; }
  .kp-toggle-btn { display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 11px; margin-bottom: 10px; border: 1px solid #bfdbfe; border-radius: 10px;
    background: #eff6ff; color: var(--primary); font-size: 14px; font-weight: 600; cursor: pointer; }
  .kp-toggle-badge { background: var(--primary); color: #fff; font-size: 11px; border-radius: 999px;
    padding: 1px 7px; }
  #kp-mask:not(.hidden) { display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(15,23,42,.42); }
  /* 抽屉常驻 display:flex, 用 transform+visibility 滑入滑出(可过渡, 且避开 display 切换无法过渡的问题) */
  /* top:56px 避开顶栏: .page 的 page-in 动画使 .page 成为堆叠上下文, 抽屉被困在页内层级, 盖不住根级顶栏(z10), 顶部一行会被压盖 */
  .kp-side { display: flex; position: fixed; left: 0; top: 56px; bottom: 0; width: 302px; max-width: 86vw;
    max-height: none; border-radius: 0; z-index: 120; padding: 14px 12px;
    box-shadow: 8px 0 28px rgba(15,23,42,.18);
    transform: translateX(-105%); visibility: hidden;
    transition: transform .22s ease, visibility .22s; }
  .kp-side.open { transform: none; visibility: visible; }
  .kp-close { display: inline-block; }
  .kp-tree { min-height: 0; }
  /* 触摸友好的行高 */
  .kp-row { padding: 8px 6px; min-height: 36px; }
  .kp-arrow { width: 22px; font-size: 13px; }
  .kp-foot .btn.small { min-height: 34px; }
  /* 已选条件条: 窄屏同样允许换行, 最高两行后内滚, 标签/按钮不撑宽题卡 */
  .kp-active { gap: 6px; padding: 5px 6px 5px 10px; margin-bottom: 8px; }
  .kp-active-label { font-size: 12px; }
  .kp-active-chips { gap: 5px; }
  /* 题卡间隔收紧 */
  .q-card { margin-bottom: 8px; padding: 12px 14px; border-radius: 10px; }
  /* 查卷横向套卷卡片: 窄屏收紧 */
  .sheet-card { padding: 11px 13px; margin-bottom: 8px; border-radius: 10px; }
  .sheet-card-title { font-size: 13.5px; }
  .sheet-card-meta { gap: 4px 12px; font-size: 12px; }
  /* 图谱海报单列 */
  .gmap { grid-template-columns: 1fr; }
  .guide-map-bar { gap: 8px; }

  /* 图谱编辑输入弹窗: 窄屏贴边全宽 */
  .mapedit-box { width: 92vw; padding: 18px; }
  .mapedit-tags { gap: 6px; }
  .mapedit-tag { padding: 6px 12px; font-size: 12.5px; }

  /* 大类 tab 4 个一屏放不下: 容器横向滑动, 一屏固定显 3 个, 滑出第 4 个 */
  .kp-cats, #sl-cats, .guide-map-cats { overflow-x: auto; scrollbar-width: none; }
  .kp-cats::-webkit-scrollbar, #sl-cats::-webkit-scrollbar, .guide-map-cats::-webkit-scrollbar { display: none; }
  .kp-cats .kp-cat, #sl-cats .kp-cat, .guide-map-cats .kp-cat { flex: 0 0 33.4%; }

  /* 个人中心列表(收藏试卷/组卷): 操作按钮改成浅描边圆角小 pill, 不与元信息挤一行 */
  #ucl-body .qp-item-meta { gap: 4px 8px; }
  #ucl-body .uc-uncollect,
  #ucl-body .ucl-del { background: #fff; color: #64748b; border: 1px solid var(--border);
    border-radius: 999px; font-weight: 400; padding: 4px 12px; min-height: 28px; font-size: 12px; }
  #ucl-body .ucl-del { color: #dc2626; border-color: #fecaca; }
  #ucl-body .ucl-del:active { background: #fef2f2; }
}

/* 641–900px 补充：筛选项两列排布更整齐 */
@media (min-width: 641px) and (max-width: 900px) {
  .fb-main { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
  .fb-search { grid-column: 1 / -1; }
  .katex-display { overflow-x: auto; overflow-y: hidden; }
}
