/* ==================================================================
   mindmap5.3 · responsive.css —— PC ↔ 手机自适应
   Design Read：手机多选栏是贴底实心图标栏（--ui-panel），
   不要把桌面玻璃胶囊缩小后居中悬浮。触控目标 44px，可横向滑。
   ================================================================== */
@media (min-width: 901px) and (max-width: 1280px) {
  /* 中等宽度优先保留右侧阅读区快捷按钮。 */
  .mb-hint { display: none; }
  .mb-reader-toggle { max-width: min(220px, 24vw); }
}

/* iPadOS 即使连接鼠标或横屏，也保留底部入口；输入手势仍按 pointerType 仲裁。 */
html.platform-ios .mb-multi-toggle { display: none; }
html.platform-ios #mobilebar {
  display: flex;
  bottom: calc(10px + env(safe-area-inset-bottom));
}
html.platform-ios body.batch-mode #mobilebar { display: none; }

@media (min-width: 901px) {
  #zoompop { right: auto; }
  html.platform-ios #dock { bottom: calc(74px + env(safe-area-inset-bottom)); }
  html.platform-ios #zoompop,
  html.platform-ios .panel { bottom: calc(130px + env(safe-area-inset-bottom)); }
}

/* 大屏触摸设备不一定进入 900px 响应式断点，但主操作仍需 44px 命中区。 */
@media (any-pointer: coarse) {
  .mb-multi-toggle { min-width: var(--editor-touch-target); min-height: var(--editor-touch-target); }
  .sel-quickbar { --sel-quick-action: var(--editor-touch-target); }
  .batch-action, .batch-exit, .mm-color-tray-btn {
    width: var(--editor-touch-target); min-width: var(--editor-touch-target);
    min-height: var(--editor-touch-target);
  }
}

@media (max-width: 900px) {
  :root { --menubar-h: 54px; }

  /* 菜单栏折叠为汉堡抽屉 */
  .mb-item { display: none; }
  .mb-hint { display: none; }
  .mb-reader-toggle { display: none; }
  .mb-multi-toggle { display: none; }
  .mb-burger {
    display: flex; align-items: center; justify-content: center;
    appearance: none; border: 1px solid var(--ui-border); background: var(--ui-panel);
    color: var(--ui-text); width: 44px; height: 44px; flex-shrink: 0; border-radius: var(--ui-menu-radius);
    font-size: 16px; cursor: pointer; margin-right: 4px;
  }
  .mb-title { margin-right: 4px; }
  .mb-title-text { font-size: 13.5px; }

  /* Dock / 浮层 / 编辑器 / MD 面板：避开底部工具条 */
  #dock { bottom: calc(74px + env(safe-area-inset-bottom)); right: 10px; }
  #dock button[data-dock="zoom"] { display: inline-block; }
  #zoompop {
    left: 10px; right: auto; bottom: calc(130px + env(safe-area-inset-bottom));
    display: none; flex-direction: column; gap: 10px; padding: 12px;
  }
  #zoompop.show { display: flex; }
  #zoompop .zoom-scale-input { width: 44px; left: -10px; }
  .panel { right: 10px; bottom: calc(130px + env(safe-area-inset-bottom)); width: min(252px, 92vw); max-height: 52vh; }
  #mobilebar { display: flex; bottom: calc(10px + env(safe-area-inset-bottom)); }

  .dropdown {
    max-height: calc(100dvh - var(--menubar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px);
    overflow-y: auto; overscroll-behavior: contain;
  }
  .dropdown .di { min-height: var(--editor-touch-target); }
  .sel-quickbar { --sel-quick-action: var(--editor-touch-target); }
  .sel-quick-action {
    width: var(--sel-quick-action); height: var(--sel-quick-action);
    min-width: var(--sel-quick-action); min-height: var(--sel-quick-action); padding: 0;
  }

  /* 节点编辑器：全屏单列，正文保持唯一滚动容器 */
  #ed-modal { padding: 0; align-items: stretch; }
  #ed-modal .modal {
    width: 100vw; height: 100dvh; min-height: 0; max-height: none;
    border: 0; border-radius: 0;
  }
  #ed-modal .modal-head {
    min-height: 56px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  }
  #ed-modal .modal-heading p { display: none; }
  #ed-modal .modal-x { width: var(--editor-touch-target); height: var(--editor-touch-target); }
  #ed-modal .ed-tabs { height: 44px; padding: 0 14px; gap: 22px; }
  #ed-modal .ed-body { padding: 12px; scroll-padding: 12px; }
  #ed-modal .ed-workspace { display: flex; flex-direction: column; gap: 12px; }
  #ed-modal .ed-main { gap: 12px; }
  #ed-modal .ed-section { padding: 14px; }
  #ed-modal .ed-section-head { margin-bottom: 12px; }
  #ed-modal .ed-foot {
    min-height: calc(64px + env(safe-area-inset-bottom));
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  #ed-modal .ed-foot .btn { min-height: var(--editor-touch-target); }
  #ed-modal .ed-foot [data-cancel] { flex: 2; }
  #ed-modal .ed-foot [data-ok] { flex: 3; }

  #ed-modal .ed-preview-pane { position: static; order: -1; }
  #ed-modal .ed-preview-head { min-height: 54px; padding: 9px 12px; }
  #ed-modal .ed-preview-toggle { display: block; min-width: 44px; min-height: 36px; }
  #ed-modal .ed-preview-canvas { display: none; min-height: 0; max-height: 240px; padding: 10px; }
  #ed-modal .ed-preview-pane.is-expanded .ed-preview-canvas { display: flex; }

  #ed-modal .item-row-head { display: grid; grid-template-columns: var(--editor-touch-target) minmax(0, 1fr); }
  #ed-modal .item-row .ops { grid-column: 1 / -1; justify-content: flex-end; }
  #ed-modal .ed-icon-btn { width: var(--editor-touch-target); height: var(--editor-touch-target); }
  #ed-modal .item-tools { gap: 6px; }
  #ed-modal .item-tools .btn { min-height: var(--editor-touch-target); padding-inline: 6px; }
  #ed-modal .tag-color { min-height: var(--editor-touch-target); }
  #ed-modal .tag-delete { width: var(--editor-touch-target); }
  #ed-modal .tag-add .btn { min-height: var(--editor-touch-target); padding-inline: 10px; }
  #ed-modal .image-fields { grid-template-columns: 1fr; align-items: stretch; }

  #ed-modal .swatches { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
  #ed-modal .sw-c { min-height: var(--editor-touch-target); }
  #ed-modal .range-field { margin-top: 18px; }
  #ed-modal .range-field input[type="range"] { min-height: var(--editor-touch-target); }
  #ed-modal .gradient-controls { grid-template-columns: 1fr; }
  #ed-modal .color-control input[type="color"] { width: 58px; height: var(--editor-touch-target); }
  #ed-modal .ed-reset-section { align-items: stretch; flex-direction: column; }
  #ed-modal .ed-discard-dialog { padding: 18px; }
  #ed-modal .ed-discard-actions { display: grid; grid-template-columns: 1fr 1fr; }
  #ed-modal .ed-discard-actions .btn { min-height: var(--editor-touch-target); }

  /* 多选：贴底实心两行栏，替代普通手机工具条。 */
  body.batch-mode #mobilebar { display: none; }
  body.batch-mode #dock { bottom: calc(10px + var(--batch-dock-mobile-h) + env(safe-area-inset-bottom)); }
  body.batch-mode #zoompop { bottom: calc(66px + var(--batch-dock-mobile-h) + env(safe-area-inset-bottom)); }
  body.batch-mode .panel { bottom: calc(66px + var(--batch-dock-mobile-h) + env(safe-area-inset-bottom)); }
  .batch-dock {
    --batch-action: var(--editor-touch-target);
    left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
    min-height: calc(var(--batch-dock-mobile-h) + env(safe-area-inset-bottom));
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-width: 1px 0 0; border-radius: 0;
    background: var(--ui-panel);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    overflow: hidden;
    transform: translateY(100%);
  }
  .batch-dock.show { transform: translateY(0); }
  .batch-dock.is-wrap {
    --batch-tools-w: calc(6 * var(--batch-action) + 5 * 6px);
  }
  .batch-action.batch-count strong { font-size: 14px; }
  .batch-exit {
    width: var(--batch-action); min-width: var(--batch-action);
    min-height: var(--batch-action); height: var(--batch-action); padding: 0;
  }
  .batch-action {
    width: var(--batch-action); min-width: var(--batch-action);
    min-height: var(--batch-action); height: var(--batch-action); padding: 0;
  }
  .batch-colors { min-width: 0; min-height: var(--batch-action); padding: 0; }
  .batch-colors .mm-color-chip {
    width: var(--chip-size); height: var(--chip-size); border-radius: 6px;
  }
  .batch-colors .mm-color-tray-btn {
    width: var(--chip-size); min-width: 0;
    height: var(--chip-size); min-height: 0;
  }
  .batch-context-menu { width: min(300px, calc(100vw - 16px)); }
  .batch-menu-item { min-height: 52px; }
  .batch-dialog-mask { padding: 8px; }
  .batch-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 14px; }
  .batch-dialog-head { padding: 14px 14px 10px; }
  .batch-dialog-close { width: var(--editor-touch-target); height: var(--editor-touch-target); }
  .batch-dialog-body { padding: 0 14px 14px; }
  .batch-dialog-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .batch-dialog-foot .btn { min-height: var(--editor-touch-target); flex: 1; }
  .batch-color-option, .batch-remove-tag { min-height: var(--editor-touch-target); }
  .batch-remove-tag { grid-template-columns: auto minmax(0, 1fr); }
  .batch-remove-tag small { grid-column: 2; white-space: normal; }

  /* Markdown 面板改为全高抽屉；!important 压过桌面拖宽留下的内联宽度 */
  #mdpanel { width: 100vw !important; max-width: 100vw !important; z-index: calc(var(--z-modal) - 2); }
  #md-resizer { display: none; }

  #hint { display: none; }
}

@media (max-width: 480px) {
  .panel { width: 190px; }
  /* TWEAKS 沿用原型手机面板262px，容纳正式版三列预设与44px触摸按钮。 */
  #panel-tweaks { width: min(262px, calc(100vw - 32px)); }
}

/* 窄屏 Reader 仅作为粗指针实验能力：入口保留，打开后由 reader.css 使用全屏模式。 */
@media (max-width: 900px) and (any-pointer: coarse) {
  .mb-reader-toggle {
    width: var(--editor-touch-target); height: var(--editor-touch-target); flex: none;
    display: inline-flex; justify-content: center; padding: 0;
  }
  .mb-reader-toggle .mb-reader-label { display: none; }
  .mb-reader-toggle .mb-reader-icon { font-size: 17px; }
  .reader-dialog { width: 100vw; max-height: 100dvh; margin: 0; border-width: 0; border-radius: 0; }
  .reader-dialog-card { max-height: 100dvh; min-height: 100dvh; }
  .reader-dialog-card > header { padding-top: calc(10px + env(safe-area-inset-top)); }
  .reader-dialog-actions { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .reader-dialog-actions .btn, .reader-dialog-card header button { min-height: var(--editor-touch-target); }
  .reader-word-bg label { min-height: 76px; }
  .reader-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .reader-dialog-error { grid-column: 1 / -1; }
}

/* 阅读集总览在窄屏使用与桌面相同的树，只把承载面改为安全区全屏。 */
@media (max-width: 900px) {
  #reader-library.reader-library {
    z-index: calc(var(--z-modal) - 1); inset: 0; width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh; padding-top: env(safe-area-inset-top);
    overflow: hidden; border: 0; border-radius: 0; box-shadow: none; backdrop-filter: none;
    background: var(--reader-library-bg);
  }
  #reader-library .reader-library-head {
    min-height: 56px; padding: 6px 8px 6px 12px;
  }
  #reader-library .reader-library-head > button,
  #reader-library .reader-library-head .reader-library-close,
  #reader-library .reader-library-head .reader-library-new,
  #reader-library .reader-library-head .reader-library-search-toggle {
    width: var(--editor-touch-target); min-width: var(--editor-touch-target);
    height: var(--editor-touch-target); min-height: var(--editor-touch-target);
  }
  #reader-library .reader-library-search {
    grid-template-columns: minmax(0, 1fr) 56px; padding: 6px 9px;
  }
  #reader-library .reader-library-search input,
  #reader-library .reader-library-search button { height: var(--editor-touch-target); min-height: var(--editor-touch-target); }
  #reader-library .reader-library-notice { margin: 7px 9px 0; }
  #reader-library .reader-library-general,
  #reader-library [data-reader-library-general] { padding: 5px 7px; }
  #reader-library .reader-tree { padding: 6px 7px 12px; overflow-x: hidden; }
  #reader-library .reader-tree-row { min-height: 48px; padding-block: 2px; }
  #reader-library .reader-tree-caret,
  #reader-library .reader-tree-menu {
    width: var(--editor-touch-target); min-width: var(--editor-touch-target);
    height: var(--editor-touch-target); min-height: var(--editor-touch-target);
  }
  #reader-library .reader-tree-section { min-height: 46px; margin-left: 28px; }
  #reader-library .reader-tree-book { min-height: 50px; margin-left: 48px; }
  #reader-library .reader-tree-name { font-size: 13px; }
  #reader-library .reader-tree-meta { max-width: 66px; }
  #reader-library .reader-tree-footer {
    padding: 9px 9px calc(9px + env(safe-area-inset-bottom));
  }
  #reader-library .reader-tree-footer button { min-height: var(--editor-touch-target); }

  #reader-library button,
  #reader-library summary { min-height: var(--editor-touch-target); }
  #reader-library .reader-library-actions,
  #reader-library .reader-library-secondary-actions {
    padding: 9px 9px calc(9px + env(safe-area-inset-bottom));
  }
  #reader-library .reader-document-row { grid-template-columns: minmax(0, 1fr) auto auto; }
  #reader-library .reader-document-row .reader-document-reconnect { grid-column: 2; }
  #reader-library .reader-document-sort-actions {
    display: none; grid-column: 1 / -1; justify-content: flex-end; padding: 0 6px 6px;
  }
  #reader-library .reader-sort-mode .reader-document-sort-actions { display: flex; }
  #reader-library .reader-document-sort-actions button {
    min-width: var(--editor-touch-target); min-height: var(--editor-touch-target);
  }
  #reader-library .reader-row-menu > summary {
    min-width: var(--editor-touch-target); min-height: var(--editor-touch-target);
  }
  #reader-library .reader-row-menu-list,
  #reader-library .reader-tree-menu-popover {
    position: fixed; z-index: var(--z-modal); left: 8px; right: 8px; top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; max-height: min(62dvh, 440px);
    overflow: auto; padding: 8px; border-radius: 16px;
  }
  #reader-library .reader-row-menu-list button,
  #reader-library .reader-tree-menu-popover button { min-height: 48px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  #ed-modal *, #ed-modal *::before, #ed-modal *::after,
  .batch-dock, .batch-dock *, .batch-dock *::before, .batch-dock *::after,
  .batch-context-menu, .batch-context-menu *, .batch-dialog-mask, .batch-dialog-mask * {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .reader-dialog, .reader-dialog *, .reader-library, .reader-library * {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
