/* 双端自适应：宽屏保留桌面布局，窄屏使用触摸友好的单栏界面。 */
.mobile-chapters, .chapter-shade, .mobile-chapter-close { display: none; }
.cover-stage { touch-action: none; }
@media (max-width: 900px) {
  html, body { min-width: 0; width: 100%; }
  .topbar { padding: 8px 12px; gap: 8px; height: auto; min-height: 60px; flex-wrap: wrap; }
  .brand h1 { font-size: 17px; letter-spacing: 1px; }
  .brand .sub { display: none; }
  .topbar > span { max-width: 25vw; overflow-wrap: anywhere; }
  .btn { min-height: 40px; justify-content: center; padding: 8px 10px; }
  input:not([type=range]):not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; min-width: 0; }
  .shelf-wrap { padding: 22px 14px 40px; }
  .shelf-head { flex-wrap: wrap; gap: 10px; }
  .shelf-head .hint { flex-basis: 100%; order: 2; line-height: 1.7; }
  #shelf-templates { margin-left: 0; }
  .shelf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .book-meta { padding: 10px; }
  .book-actions { flex-wrap: wrap; }
  .book-actions button { min-height: 44px; min-width: 42px; }
  .editor { height: calc(100vh - var(--bookpress-header, 60px)); height: calc(100dvh - var(--bookpress-header, 60px)); min-height: 420px; }
  .editor-top { padding: 8px 12px; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
  .editor-top .back { flex-basis: 100%; padding: 3px 0; }
  .title-input { flex: 1 1 55%; width: 55%; }
  .author-input { width: 30%; flex: 1 1 25%; }
  .editor-top > .spacer { display: none; }
  .save-status { margin-left: auto; order: 3; font-size: 11px; }
  .mobile-chapters { display: inline-flex; }
  .chapter-side { display: none; position: fixed; z-index: 85; inset: 0 auto 0 0; width: min(330px, 88vw); box-shadow: 6px 0 24px #33220f33; padding-bottom: env(safe-area-inset-bottom); }
  .chapter-side.mobile-open { display: flex; }
  .chapter-shade.mobile-open { display: block; position: fixed; inset: 0; z-index: 84; background: #28211877; border: 0; }
  .mobile-chapter-close { display: inline-flex; }
  .chapter-list { overscroll-behavior: contain; }
  .ch-item, .sec-item { min-height: 44px; }
  .ch-item .ch-ops, .sec-item .sec-ops { display: flex; }
  .ch-item .ch-ops button, .sec-item .sec-ops button { min-width: 30px; min-height: 34px; }
  .editor-main { min-height: 0; }
  .tabs { padding: 0 8px; gap: 0; overflow-x: auto; flex-shrink: 0; }
  .tabs button { flex: none; white-space: nowrap; min-height: 46px; padding: 10px 12px; }
  .pane-edit { padding: 12px; }
  .pane-edit .ch-title-row { flex-wrap: wrap; gap: 6px; }
  .pane-edit .ch-title-input { min-width: 0; width: 55%; }
  .ch-editor { padding: 12px; min-height: 240px; }
  .edit-foot, .edit-nav, .empty-btns { flex-wrap: wrap; gap: 6px; }
  .pane-bar, .cs-bar, .preview-bar { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  .pane-bar .spacer, .cs-bar .spacer { display: none; }
  .style-scroll, .history-scroll { padding: 12px 12px 30px; }
  .style-cols { grid-template-columns: minmax(0, 1fr); }
  .style-group { padding: 12px; min-width: 0; }
  .frow { flex-wrap: wrap; }
  .frow > select { max-width: 100%; }
  .hs-top { flex-wrap: wrap; gap: 8px; }
  .cover-studio { display: block; overflow-y: auto; }
  .cs-main { min-height: 550px; }
  .cs-stage-wrap { flex: none; height: 380px; height: clamp(280px, 55dvh, 520px); }
  .cs-inspector { max-height: none; padding: 12px; }
  .insp-sec { min-width: 0; flex-basis: 100%; }
  .cs-ai { width: 100%; min-height: 320px; border-left: 0; border-top: 1px solid var(--line); }
  .ai-log { max-height: 300px; }
  .ai-input-row textarea { min-width: 0; }
  .ai-quick { flex-wrap: wrap; }
  .ace-rh { width: 22px; height: 22px; right: -8px; bottom: -8px; }
  .ce-menu button { min-height: 40px; }
  .layout-main { position: relative; min-width: 0; }
  .layout-scroll { min-width: 0; }
  .gallery-drawer, .lx-note-editor { position: absolute; z-index: 35; right: 0; top: 0; bottom: 0; width: min(300px, 88%); box-shadow: -5px 0 20px #33220f22; }
  .lx-note-editor { z-index: 36; }
  .lx-card { right: 8px !important; bottom: 8px; max-width: calc(100% - 16px); max-height: 75%; overflow-y: auto; }
  .gdel { display: block; width: 32px; height: 32px; }
  .modal { max-width: calc(100vw - 20px); max-height: 92vh; max-height: 92dvh; }
  .modal-head, .modal-body { padding: 14px; }
  .modal-foot { padding: 0 14px 16px; flex-wrap: wrap; }
  .modal-head .close { min-width: 40px; min-height: 40px; }
  .form-inline { grid-template-columns: minmax(0, 1fr); }
  .check-row { flex-wrap: wrap; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-head, .template-content, .template-filters, .template-footer { padding-left: 14px; padding-right: 14px; }
  .template-footer { flex-wrap: wrap; }
  .ggrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toast { max-width: 90vw; }
  .office-chart { min-width: 0; gap: 3px; }
  .office-day { min-width: 0; }
  .forum-topbar { height: auto; min-height: 65px; flex-wrap: wrap; }
  .forum-tabs { overflow-x: auto; }
  .forum-tabs button { white-space: nowrap; }
}
@media (max-width: 480px) {
  .topbar .brand h1 { font-size: 15px; }
  .topbar .brand { gap: 6px; }
  .topbar .btn { font-size: 12px; padding: 7px 8px; }
  .template-grid { grid-template-columns: minmax(0, 1fr); }
  .cover-picks { gap: 5px; }
  .frow > label { width: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  .save-btn.is-dirty { animation: none; }
}

@media (max-width: 900px) {
  .ce-menu { max-height: 95%; overflow-y: auto; }
  .seg { max-width: 100%; flex-shrink: 0; }
}
