/* 控件等比例紧凑化（保持标准阅读字号，仅按视口缩小按钮/输入框/留白壳体）与移动端左右滑动轨道适配 */
.appearance-mobile-links { display: none; }

@media (max-width: 1120px) {
  .topbar-inner { height: 50px; padding: 0 18px; }
  .app-main { padding: 12px 18px; }
  .panel { padding: 14px; }
  .question-box { padding: 18px 20px; }
  .bank-cover { width: 34px; height: 34px; border-radius: 9px; }
  .btn { padding: 6px 11px; border-radius: 7px; }
  .btn.tiny { padding: 4px 8px; }
  select, input, textarea { padding: 6px 9px; border-radius: 7px; }
}

@media (max-width: 960px) {
  .app-main { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
  .app-main.practice-full { padding: 10px 12px calc(116px + env(safe-area-inset-bottom)); }
  .practice-shell .practice-layout,
  .practice-shell.notes-collapsed .practice-layout,
  .practice-shell.aside-collapsed .practice-layout,
  .practice-shell.notes-collapsed.aside-collapsed .practice-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .practice-shell .practice-notes,
  .practice-shell .practice-aside,
  .practice-shell .pane-resizer,
  .desktop-only-btn { display: none !important; }
  .mobile-sheet-trigger, .mobile-only-btn { display: inline-flex !important; }
  .view-frame, .view-scroll, .practice-shell, .practice-shell .practice-layout,
  .practice-shell .question-box, .q-body-scroll, .aside-body-scroll {
    flex: none !important; height: auto !important; min-height: 0 !important;
    max-height: none !important; overflow: visible !important;
  }
  .practice-shell .question-box { width: 100%; min-width: 0; max-width: none; touch-action: pan-y; }
}

@media (max-width: 900px) {
  .sys-grid { grid-template-columns: minmax(0, 1fr); }
  .sys-card { min-width: 0; max-width: 100%; overflow: hidden; }
  .sys-card .row-gap { min-width: 0; }
  .sys-card input, .sys-card select { min-width: 0 !important; max-width: 100%; }
  .sys-card pre { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
  .sys-card .table-wrap { width: 100%; max-width: 100%; overflow-x: auto; }
}

@media (max-width: 860px) {
  button, a, select, input, textarea, .option-item, .mode-tile, .m-tab-btn {
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  }

  /* 仅缩小控件框体与内边距，保持阅读文字字号清晰 */
  .btn { padding: 5px 10px; border-radius: 7px; gap: 4px; }
  .btn.tiny { min-height: 26px; padding: 3px 8px; border-radius: 6px; gap: 3px; }
  .btn.icon-btn { width: 28px; height: 28px; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { padding: 5px 8px; border-radius: 7px; }
  .badge, .type-pill, .cat-pill, .tag-pill { padding: 1px 6px; }

  .topbar-inner { height: calc(46px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0; }
  .brand-icon { width: 26px; height: 26px; border-radius: 7px; }
  .avatar-btn { max-width: 136px; padding: 2px 8px 2px 4px; gap: 5px; }
  .avatar-btn > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .avatar-circle { width: 21px; height: 21px; }

  .admin-subbar-inner { padding: 6px 10px; scrollbar-width: none; }
  .admin-subbar-inner::-webkit-scrollbar { display: none; }
  .admin-subbar-inner .side-label { display: none; }

  .appearance-menu {
    position: fixed; left: 10px; right: 10px; top: calc(50px + env(safe-area-inset-top));
    width: auto; max-width: none; max-height: calc(100dvh - 70px - env(safe-area-inset-top)); z-index: 65;
  }
  .appearance-mobile-links {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line);
  }
  #user-dropdown { max-width: calc(100vw - 20px); max-height: calc(100dvh - 70px); overflow-y: auto; z-index: 65; }

  .panel { padding: 11px 12px; border-radius: 11px; }
  .app-main { padding: 9px 10px calc(62px + env(safe-area-inset-bottom)); }
  .app-main.practice-full { padding: 8px 10px calc(106px + env(safe-area-inset-bottom)); }
  body.focus-mode .app-main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  body.immersive-mode .app-main { padding: 0 0 calc(64px + env(safe-area-inset-bottom)); }

  .mobile-tabbar {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    padding: 3px 6px calc(3px + env(safe-area-inset-bottom));
    gap: 3px;
  }
  .m-tab-btn {
    min-height: 38px; padding: 3px 2px; border-radius: 8px; gap: 1px;
    transition: background-color .14s ease, color .14s ease;
  }
  .m-tab-btn svg { width: 16px; height: 16px; }
  .m-tab-btn.active { background: var(--accent-soft); color: var(--accent-fg); }

  .toast-container { top: calc(50px + env(safe-area-inset-top)); bottom: auto; left: 10px; right: 10px; align-items: center; pointer-events: none; }
  .toast { max-width: 100%; text-align: center; padding: 7px 12px; }

  /* 刷题页两行紧凑工具栏、缩窄控件盒体与吸底切题栏 */
  .practice-toolbar { gap: 6px; margin-bottom: 8px; }
  .toolbar-left, .toolbar-right { display: contents; }
  .bank-select-inline, .toolbar-bank-name { order: 1; flex: 1 1 130px; min-width: 0; max-width: 100%; height: 28px; padding: 3px 8px; }
  #btn-quick-recite, #btn-toggle-immersive, #btn-submit-exam, .practice-toolbar .badge { order: 2; }
  .mode-pills {
    order: 3; width: 100%; display: flex; flex-wrap: nowrap;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 2px;
  }
  .mode-pills::-webkit-scrollbar { display: none; }
  .mode-pill { flex: 0 0 auto; min-height: 26px; padding: 3px 9px; }
  .toolbar-sub-select { order: 4; width: 100%; padding: 4px 8px; }

  .question-box { padding: 11px 12px; border-radius: 11px; }
  .q-head { flex-wrap: nowrap; gap: 6px; }
  .q-head > .row-gap:first-child { min-width: 0; gap: 5px; }
  .q-head > .row-gap:last-child { flex-wrap: nowrap; flex-shrink: 0; gap: 5px; }
  .q-title { margin: 9px 0 11px; line-height: 1.62; }
  .options-list { gap: 7px; }
  .option-item { min-height: 40px; padding: 8px 11px; gap: 8px; border-radius: 8px; align-items: center; }
  .opt-key { width: 21px; height: 21px; }
  .answer-box { margin-top: 10px; padding: 10px 11px; border-radius: 8px; }
  .answer-box > .row-gap { gap: 6px; }

  .practice-nav-footer {
    position: fixed; left: 0; right: 0; bottom: calc(45px + env(safe-area-inset-bottom)); z-index: 44;
    display: flex; flex-wrap: nowrap !important; align-items: center; justify-content: space-between; gap: 5px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(10px); border-top: 1px solid var(--line);
    padding: 5px 10px !important; margin-top: 0 !important;
  }
  .practice-nav-footer .js-fav-btn { display: none !important; }
  .practice-nav-footer .btn { min-height: 29px; padding: 3px 8px; white-space: nowrap; flex-shrink: 0; }
  .practice-nav-footer #btn-prev, .practice-nav-footer #btn-next { padding: 3px 10px; }
  body.focus-mode .practice-nav-footer, body.immersive-mode .practice-nav-footer {
    bottom: 0; padding-bottom: calc(6px + env(safe-area-inset-bottom)) !important;
  }
  body.immersive-mode .immersive-bar { padding: 8px 10px; gap: 6px; flex-wrap: wrap; }
  body.immersive-mode .immersive-bar > .row-gap:first-child { min-width: 0; }
  body.immersive-mode .immersive-bar strong { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.immersive-mode .immersive-bar > .row-gap:last-child { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .sheet-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; max-height: 44dvh; }
  .sheet-cell { height: 32px; }

  /* 题库中心：考试卡片、科目条、科目概览、工作台与列表工具栏移动端深度适配 */
  .exam-notice-board { padding: 7px 10px; gap: 6px; }
  .exam-notice-grid {
    display: flex; flex-wrap: nowrap; gap: 7px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .exam-notice-grid::-webkit-scrollbar { display: none; }
  .exam-notice-card { flex: 0 0 276px; max-width: 84vw; }
  .exam-notice-sub { flex-direction: column; align-items: flex-start; gap: 2px; }
  .exam-notice-time { white-space: normal; word-break: break-word; }
  .exam-notice-note { max-width: 100%; }
  .exam-notice-edit-btn { min-height: 24px !important; padding: 2px 8px !important; }

  .subject-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; padding: 7px 10px; }
  .subject-bar-left { display: contents; }
  .subject-term-sel { order: 1; }
  #btn-new-subject { order: 2; margin-left: auto; }
  .subject-pills { order: 3; flex: 1 1 100%; width: 100%; }

  .subject-overview { flex-direction: column; align-items: stretch; gap: 8px; padding: 9px 11px; }
  .subject-overview > .row-gap:last-child { width: 100%; justify-content: space-between; gap: 6px; }
  .subject-ov-prog { flex: 1; min-width: 90px; }

  .bank-workbench { padding: 10px 11px; gap: 8px; }
  .wb-sub { -webkit-line-clamp: 1; }
  .wb-stats-row { padding: 6px 8px; gap: 8px; }
  .wb-primary-cta { height: 32px; }
  .mode-tiles {
    display: flex !important; flex-wrap: nowrap; gap: 7px; margin-top: 2px; padding-bottom: 2px;
    overflow-x: auto; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .mode-tiles::-webkit-scrollbar { display: none; }
  .mode-tile { flex: 0 0 auto; flex-direction: row; padding: 6px 10px; gap: 6px; scroll-snap-align: start; }
  .mode-tile-icon { width: 22px; height: 22px; border-radius: 6px; }
  .mode-tile-badge[data-count="0"] { display: none !important; }

  .cat-filter-row {
    flex-wrap: nowrap; overflow-x: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .cat-filter-row::-webkit-scrollbar { display: none; }
  .cat-filter-row .btn { flex: 0 0 auto; }
  .section-head { gap: 7px; }
  .section-head > .row-gap:first-child { flex-direction: column; align-items: stretch; gap: 6px; width: 100%; }
  .section-head > .row-gap:last-child { width: 100%; gap: 5px; flex-wrap: wrap; }
  .banks-filter-input { flex: 1 1 100%; min-width: 0; width: 100%; }
  .section-head .view-seg, .section-head .btn.tiny { flex: none; }

  /* 学习统计页（#stats）：紧凑 KPI 与趋势图、首屏展示更多排行榜 */
  .kpi-grid { gap: 8px; }
  .kpi-card { padding: 9px 11px; border-radius: 10px; }
  .kpi-icon { width: 22px; height: 22px; border-radius: 6px; }
  .kpi-val { font-size: 1.1875rem; margin-top: 2px; line-height: 1.2; }
  .kpi-sub { margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stats-grid { gap: 10px; }
  .stats-grid .seg-row.cols-2 { min-width: 116px !important; }
  .chart-stage { height: 108px; padding: 10px 6px 4px; margin-top: 8px; }
  .rank-list { max-height: none; overflow: visible; gap: 4px; }
  .rank-row { padding: 5px 8px; gap: 4px; }

  /* 搜题、考试、试题管理与批量导题页紧凑横滑适配 */
  #search-bank, #search-type, #f-type, #f-chapter { flex: 1 1 42%; min-width: 0; }
  #search-input, #f-kw, #imp-bank, #imp-chapter { min-width: 0 !important; max-width: 100%; }
  #search-input, #f-kw { flex: 1 1 100% !important; }
  .search-summary { padding: 9px 11px; gap: 8px; }
  .bank-card { padding: 12px 13px; gap: 9px; border-radius: 11px; }
  #m-stats-row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  #m-stats-row::-webkit-scrollbar { display: none; }
  #m-stats-row > * { flex: none; }
  #m-foot { gap: 8px; }
  #usr-kw { min-width: 0 !important; }
  .workbench-textarea { min-height: 170px; }
  .preview-scroll { max-height: 280px; }

  /* 管理后台与弹窗表格响应式卡片化 */
  .admin-table-wrap { border: 0; background: transparent; overflow: visible; }
  table.mobile-card-table { border-collapse: separate; }
  table.mobile-card-table thead { display: none; }
  table.mobile-card-table tbody { display: flex; flex-direction: column; gap: 8px; padding: 2px 0; }
  table.mobile-card-table tbody tr {
    display: flex; flex-direction: column; gap: 5px; padding: 10px; border: 1px solid var(--line);
    border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-sm);
  }
  table.mobile-card-table tbody td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
    padding: 2px 0; border-bottom: 0; text-align: right; word-break: break-word; white-space: normal !important;
  }
  table.mobile-card-table tbody td::before {
    content: attr(data-label); flex: none; font-weight: 600; color: var(--muted); text-align: left;
  }
  table.mobile-card-table tbody td[colspan] { justify-content: center; text-align: center; padding: 12px 8px; }
  table.mobile-card-table tbody td[colspan]::before { display: none; }
  table.mobile-card-table tbody td.mobile-card-full { flex-direction: column; align-items: stretch; text-align: left; }
  table.mobile-card-table tbody td.mobile-card-actions {
    flex-direction: column; align-items: stretch; text-align: left; margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--line);
  }
  table.mobile-card-table tbody td.mobile-card-actions .row-gap { flex-wrap: wrap !important; justify-content: flex-start; gap: 5px; }
}

@media (max-width: 640px) {
  .wb-head-right { width: 100%; justify-content: space-between; }
  .cards-grid { grid-template-columns: minmax(0, 1fr); }
  .hot-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .hot-row > div:first-child { min-width: 0 !important; }
  .hot-row > .row-gap:last-child { justify-content: flex-end; flex-wrap: wrap !important; }
  #sys-site-form > .row-gap { flex-direction: column; align-items: stretch; }
  .exam-notice-edit-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-card { width: 100%; max-width: 100% !important; max-height: 90dvh; border-radius: 16px 16px 0 0; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); }
  .modal-card.modal-shell { padding: 0; }
  .modal-shell > .modal-head { padding: 12px 14px; flex-wrap: wrap; gap: 6px; }
  .modal-shell .modal-body { padding: 12px 14px; }
  .modal-shell .modal-body > .row-gap { flex-direction: column; align-items: stretch; }
  .modal-shell .modal-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; gap: 6px; }
  .modal-shell .modal-foot > .row-gap { width: 100%; justify-content: flex-end; }
  #modal-ai-chat { height: 70dvh; max-height: none; }
}

@media (max-width: 480px) {
  .app-main { padding: 8px 10px calc(58px + env(safe-area-inset-bottom)); }
  .app-main.practice-full { padding: 8px 10px calc(100px + env(safe-area-inset-bottom)); }
  .bank-workbench { padding: 10px 11px; }
  .btn.tiny { min-height: 24px; padding: 2px 7px; }
  .option-item { min-height: 38px; padding: 7px 10px; }
}
