/* 课间 · 工具箱整理 */
body.tool-sort-mode .update-notice {
  display: none !important;
}
.tool-directory {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.tool-directory .directory-item {
  position: relative;
}
.tool-directory.tool-sort-editing {
  gap: 8px !important;
}
.tool-directory.tool-sort-editing .directory-item {
  touch-action: none;
  cursor: grab;
  animation: none !important;
  min-height: 126px !important;
  padding: 12px 12px 11px !important;
  gap: 12px !important;
  outline: 1px solid rgba(47, 125, 90, .24);
  outline-offset: 2px;
  transition: box-shadow .22s ease, opacity .22s ease, outline-color .22s ease;
}
.tool-directory.tool-sort-editing .directory-icon {
  width: 40px !important;
  height: 40px !important;
  border-radius: 13px !important;
}
.tool-directory.tool-sort-editing .directory-icon svg {
  width: 24px !important;
  height: 24px !important;
}
.tool-directory.tool-sort-editing .directory-item h2 {
  font-size: 14.5px !important;
}
.tool-directory.tool-sort-editing .directory-item::after {
  content: "";
  position: absolute;
  top: 12px;
  right: 11px;
  width: 16px;
  height: 12px;
  color: var(--muted);
  opacity: .42;
  pointer-events: none;
  background-image: radial-gradient(circle, currentColor 1px, transparent 1.4px);
  background-size: 6px 6px;
  background-position: 0 0;
}
.tool-directory.tool-sort-editing .directory-item:active {
  transform: none;
}
.tool-directory.tool-sort-editing .directory-item:hover {
  transform: none;
}
.tool-directory.tool-sort-editing #ai-handwriting-entry .directory-arrow {
  opacity: 0 !important;
}
.tool-directory.tool-sort-editing .fb-badge,
.tool-directory.tool-sort-editing .wf-badge {
  display: none !important;
}

/* fixed 拖动时不能留在 grid 容器里：Chromium 会把原 grid area 当包含块，
   造成“目录偏移 + translate”二次叠加，卡片会瞬间跳到手指下方。 */
.tool-sort-drag-layer {
  position: fixed !important;
  inset: 0 !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background: none !important;
  border: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
  pointer-events: none !important;
  z-index: 2147483001;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}
html[data-theme][data-view="high"] .tool-directory.tool-sort-drag-layer,
body[data-page="tools"] .tool-directory.tool-sort-drag-layer {
  display: block !important;
  align-content: initial !important;
  min-height: 0 !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background: none !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

.tool-sort-slot {
  position: relative;
  box-sizing: border-box;
  border: 1.5px dashed rgba(47, 125, 90, .32);
  border-radius: 22px;
  background:
    radial-gradient(110% 80% at 12% 0%, rgba(36, 92, 255, .06), rgba(36, 92, 255, 0) 58%),
    rgba(255, 255, 255, .18);
  opacity: .92;
  pointer-events: none;
  animation: tool-sort-slot-in .18s cubic-bezier(.22, 1, .36, 1) both;
}

.tool-sort-dragging {
  opacity: .98 !important;
  cursor: grabbing !important;
  animation: none !important;
  transition: none !important;
  filter: saturate(1.08) brightness(1.02);
  box-shadow:
    0 28px 54px -28px rgba(24, 32, 44, .52),
    0 0 0 1px rgba(255, 255, 255, .10) !important;
}
html[data-theme][data-scheme="dark"] .tool-sort-dragging {
  box-shadow:
    0 30px 58px -28px rgba(0, 0, 0, .72),
    0 0 0 1px rgba(255, 255, 255, .08) !important;
}

body.tool-sort-mode main {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.tool-sort-toolbar {
  position: fixed;
  z-index: 2147483002;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 24px);
  padding: 7px 8px 7px 14px;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 999px;
  background:
    radial-gradient(120% 90% at 12% 0%, rgba(36, 92, 255, .10), rgba(36, 92, 255, 0) 58%),
    linear-gradient(155deg, rgba(255, 255, 255, .92), rgba(255, 252, 247, .66));
  box-shadow:
    0 18px 42px -22px rgba(31, 38, 48, .38),
    inset 0 1px 0 rgba(255, 255, 255, .96);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  backdrop-filter: blur(22px) saturate(1.6);
  color: var(--ink);
  font: 500 12px/1.2 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  white-space: nowrap;
}
.tool-sort-toolbar .tool-sort-title {
  padding-right: 2px;
  color: var(--muted);
  letter-spacing: .02em;
}
.tool-sort-toolbar button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tool-sort-toolbar button:active {
  transform: scale(.97);
}
.tool-sort-toolbar button.primary {
  background: var(--green, #2f7d5a);
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(47, 125, 90, .55);
}
html[data-theme][data-scheme="dark"] .tool-sort-toolbar {
  border-color: rgba(255, 255, 255, .14);
  background:
    radial-gradient(120% 90% at 12% 0%, rgba(96, 136, 255, .18), rgba(96, 136, 255, 0) 58%),
    linear-gradient(155deg, rgba(31, 40, 56, .90), rgba(17, 24, 35, .72));
  box-shadow:
    0 20px 44px -24px rgba(0, 0, 0, .70),
    inset 0 1px 0 rgba(255, 255, 255, .10);
  color: var(--ink);
}
html[data-theme][data-scheme="dark"] .tool-sort-toolbar button {
  color: var(--muted);
}
html[data-theme][data-scheme="dark"] .tool-sort-toolbar button.primary {
  background: var(--green, #7fb79a);
  color: #0e1512;
}
html[data-theme][data-scheme="dark"] .tool-sort-slot {
  border-color: rgba(127, 183, 154, .28);
  background:
    radial-gradient(110% 80% at 12% 0%, rgba(96, 136, 255, .10), rgba(96, 136, 255, 0) 58%),
    rgba(255, 255, 255, .04);
}

@media (hover: hover) and (pointer: fine) {
  .tool-sort-toolbar button:hover {
    background: rgba(127, 140, 158, .10);
    color: var(--ink);
  }
  .tool-sort-toolbar button.primary:hover {
    background: var(--green, #2f7d5a);
    color: #fff;
  }
  .tool-directory.tool-sort-editing .directory-item:hover {
    box-shadow:
      0 20px 42px -24px rgba(36, 47, 66, .32),
      inset 0 1px 0 rgba(255, 255, 255, .92) !important;
  }
}

@media (max-width: 650px) {
  body.tool-sort-mode .shell > aside {
    transform: translateY(calc(100% + 8px));
    opacity: 0;
    pointer-events: none;
    transition: transform .28s cubic-bezier(.22, 1, .36, 1), opacity .2s ease;
  }
  .tool-sort-toolbar {
    bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 6px;
    padding-left: 12px;
    font-size: 11.5px;
  }
  .tool-sort-toolbar button {
    min-height: 36px;
    padding: 0 12px;
  }
  .tool-sort-slot {
    border-radius: 20px;
  }
}

@media (min-width: 900px) {
  .tool-sort-toolbar {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

@keyframes tool-sort-slot-in {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: .92; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tool-sort-slot,
  .tool-sort-dragging {
    animation: none !important;
  }
}
