* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --glass: rgba(255, 255, 255, 0.18);
  --glass-hover: rgba(255, 255, 255, 0.3);
  --text: #fff;
  --slot: 74px;   /* 单个图标位宽度：容纳 5 个汉字（12px x 5 + 余量） */
  --gap: 8px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: var(--text);
  overflow: hidden;
  background: linear-gradient(160deg, #2c3e2d, #1a2a3a);
}

.hidden { display: none !important; }

/* ---- 背景 ---- */
#bg {
  position: fixed; inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.8s ease;
  z-index: -2;
}
#bg.loaded { opacity: 1; }
#bg-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.18);
  z-index: -1;
}

/* ---- 右上角按钮 ---- */
.topbar {
  position: fixed; top: 16px; right: 20px;
  display: flex; gap: 10px;
  z-index: 10;
}
.top-btn {
  border: none; cursor: pointer;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--text);
  font-size: 13px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.2s;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.top-btn:hover { background: var(--glass-hover); }

/* ---- 主区域 ---- */
main {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 13vh;
}

#time {
  font-size: 88px;
  font-weight: 300;
  letter-spacing: 2px;
  text-align: center;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
  font-variant-numeric: tabular-nums;
}
#date {
  text-align: center;
  font-size: 15px;
  opacity: 0.9;
  margin-top: 2px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

/* ---- 搜索框 ---- */
#search-form {
  margin-top: 36px;
  width: min(560px, 86vw);
  height: 46px;
  display: flex;
  align-items: center;
  position: relative; /* 收藏建议下拉的定位基准 */
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  transition: background 0.2s, box-shadow 0.2s;
}
#search-form:focus-within {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25);
}
#search-form:focus-within #search-input,
#search-form:focus-within #engine-btn { color: #333; text-shadow: none; }
#search-form:focus-within #search-input::placeholder { color: #999; }

#engine-btn {
  border: none; background: none; cursor: pointer;
  color: var(--text);
  font-size: 13px;
  padding: 0 8px 0 20px;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
#search-input {
  flex: 1;
  border: none; outline: none; background: none;
  color: var(--text);
  font-size: 15px;
  padding: 0 22px 0 8px;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
#search-input::placeholder { color: rgba(255, 255, 255, 0.85); }

/* ---- 搜索框收藏建议下拉 ---- */
#search-suggest {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.22);
  z-index: 20;
}
.suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  color: #333;
  font-size: 14px;
}
.suggest-item.active,
.suggest-item:hover { background: rgba(122, 168, 116, 0.16); }
.suggest-item img {
  width: 18px; height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}
.suggest-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest-item em {
  font-style: normal;
  color: #999;
  font-size: 12px;
  margin-left: auto;
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- 底部 dock ---- */
#dock-wrap {
  position: fixed;
  bottom: 24px; left: 0; right: 0;
  display: flex;
  justify-content: center;
  z-index: 5;
}
#dock-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* dock 上方的小控制栏：展开/收起、添加、编辑 */
#dock-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.bar-btn {
  width: 30px; height: 30px;
  border: none; cursor: pointer;
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.2s;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.bar-btn:hover { background: var(--glass-hover); }
.bar-btn.bar-danger { background: rgba(231, 76, 60, 0.55); }
.bar-btn.bar-danger:hover { background: rgba(231, 76, 60, 0.75); }

/* 宽度由 JS 按图标数自适应，最多一行 12 个 */
#dock {
  width: fit-content;
  max-width: min(calc(12 * var(--slot) + 11 * var(--gap) + 34px), 94vw);
  padding: 12px 16px;
  border-radius: 24px;
  /* 深色半透明 + 高斯模糊：白色文字在任何壁纸上都清晰 */
  background: rgba(30, 34, 40, 0.32);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.28);
  /* 宽度不参与过渡：展开时槽位变宽，若宽度渐变会导致图标先换行再恢复一行 */
  transition: padding 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-radius 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
/* 默认收起只显示一行图标（无名称），点击展开后显示图标+名称 */
#dock-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
  max-height: 44px;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: max-height;
}
/* 收起时压缩内边距，让整条收藏栏更矮更精致 */
#dock:not(.expanded) { padding: 6px 16px; border-radius: 18px; }
/* 收起只剩 40px 图标本体：槽位收窄，避免图标之间出现大片空隙 */
#dock-items:not(.expanded) .dock-item { width: 48px; padding: 2px; }
/* 名称用高度/透明度过渡，避免 display:none 造成生硬切换 */
#dock-items .dock-label {
  max-height: 0;
  opacity: 0;
  margin: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease,
              margin 0.3s ease;
}
#dock-items.expanded .dock-label {
  max-height: 30px;
  opacity: 1;
  margin-top: 0;
}
/* 只有真的多行时才开滚动条占位，避免 ≤12 个时被挤成两行 */
#dock-items.expanded.multi-row {
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
}
#dock-items.expanded:not(.multi-row) {
  overflow: visible;
}
#dock-items::-webkit-scrollbar { width: 5px; }
#dock-items::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

#dock-hint {
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 13px;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: background 0.2s;
}
#dock-hint:hover { background: var(--glass-hover); }
#dock-empty {
  padding: 14px 22px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  text-align: center;
}

/* ---- 图标项（dock 与文件夹内共用） ---- */
.dock-item {
  width: var(--slot);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  border: none; background: none;
  padding: 4px 2px;
  border-radius: 12px;
  position: relative;
}
/* 悬停只动图标本身，不动按钮整体，避免命中区域移动导致抖动 */
.dock-item:hover .dock-icon { transform: translateY(-3px); }

.dock-icon {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.dock-icon img {
  width: 26px; height: 26px;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.2s ease;
  -webkit-user-drag: none;
  user-select: none;
}
.dock-icon img.loaded { opacity: 1; }

/* 编辑模式多选勾选框 */
.dock-check {
  display: none;
  position: absolute;
  top: 0; left: 4px;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.25);
  background: rgba(255,255,255,0.9);
  color: transparent;
  font-size: 11px;
  line-height: 13px;
  text-align: center;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
#dock.editing .dock-check,
#folder-items.editing .dock-check { display: block; }
.dock-item.selected .dock-check {
  background: #7aa874;
  border-color: #7aa874;
  color: #fff;
}
.dock-item.selected .dock-icon {
  box-shadow: 0 0 0 2px #7aa874, 0 2px 8px rgba(0,0,0,0.12);
}
.btn-mini-danger { background: #fdecea; color: #e74c3c; }
.btn-mini-danger:hover { background: #f9d5d2; }
.dock-icon .letter {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 600;
}
.dock-label {
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  max-width: var(--slot);
  overflow: hidden;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
  word-break: break-all;
}

/* 文件夹图标：2x2 小图预览 */
.dock-icon.folder {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.78);
}
.dock-icon.folder .mini {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 3px;
  opacity: 0;
}
.dock-icon.folder .letter-mini {
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 9px; font-weight: 600;
  border-radius: 3px;
  width: 100%; height: 100%;
}

/* ---- 编辑模式：抖动，可拖拽 ---- */
#dock.editing .dock-item,
#folder-items.editing .dock-item {
  animation: wiggle 0.35s infinite alternate ease-in-out;
  touch-action: none;
}
@keyframes wiggle {
  from { transform: rotate(-2deg); }
  to { transform: rotate(2deg); }
}

/* ---- 拖拽 ---- */
.drag-ghost {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  opacity: 0.9;
  transform: scale(1.1);
  animation: none !important;
}
.dock-item.dragging { opacity: 0.3; }
.dock-item.folder-target .dock-icon {
  transform: scale(1.22);
  box-shadow: 0 0 0 3px rgba(122, 168, 116, 0.95), 0 4px 14px rgba(0,0,0,0.2);
}

/* ---- 文件夹弹层 ---- */
#folder-overlay {
  position: fixed; inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}
#folder-panel {
  /* 一行 8 个图标：8 格 + 7 间距 + 12px 滚动条预留 + 左右内边距 40px */
  width: min(calc(8 * var(--slot) + 7 * var(--gap) + 12px + 40px), 92vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 24px;
  padding: 18px 20px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
#folder-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
#folder-name {
  border: none; outline: none;
  background: none;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: #333;
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 8px;
}
#folder-name:not([readonly]) { background: rgba(255, 255, 255, 0.75); }
.btn-mini {
  border: none; cursor: pointer;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  color: #555;
  transition: background 0.2s;
}
.btn-mini:hover { background: rgba(0, 0, 0, 0.14); }
#folder-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
  overflow-y: auto;
  scrollbar-gutter: stable both-edges; /* 滚动条出现/消失时不左右重排 */
}
/* 文件夹面板是浅色底，名称用深色（收藏栏里是白色） */
#folder-items .dock-label {
  color: #333;
  text-shadow: none;
}

/* 从文件夹往外拖时，整层遮罩放行指针，可落到底部收藏栏 */
#folder-overlay.drag-through {
  pointer-events: none !important;
  background: rgba(0, 0, 0, 0.08);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
#folder-overlay.drag-through #folder-panel {
  pointer-events: none !important;
  opacity: 0.55;
  transition: opacity 0.15s;
}
/* 拖到「←」返回按钮上的高亮 */
.btn-mini.drop-hint { background: #7aa874; color: #fff; }
/* 拖出文件夹时，底部收藏栏高亮为可放置区 */
#dock.drop-active {
  outline: 2px solid #7aa874;
  outline-offset: 3px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18), 0 0 0 6px rgba(122, 168, 116, 0.25);
}
.dock-item.drag-hidden {
  visibility: hidden;
  pointer-events: none;
}
#folder-items::-webkit-scrollbar { width: 5px; }
#folder-items::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

/* ---- 弹窗 ---- */
#overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  width: min(380px, 90vw);
  background: #fff;
  color: #333;
  border-radius: 16px;
  padding: 26px 26px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal h2 { font-size: 18px; margin-bottom: 14px; font-weight: 600; }
.modal-tip { font-size: 13px; color: #888; margin-bottom: 12px; }
.modal input {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.2s;
}
.modal input:focus { border-color: #7aa874; }
.field-label { display: block; font-size: 12px; color: #888; margin: 6px 0 6px 2px; }
.ai-row { display: flex; align-items: center; gap: 8px; margin: -2px 0 10px 2px; }
.bm-icon-upload-btn { margin-bottom: 10px; }
#bm-ai-status { font-size: 12px; color: #888; }
.page-icon-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.page-icon-row input { flex: 1; margin-bottom: 0; min-width: 0; }
.page-icon-row img { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.dskey-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.dskey-row .spacer { flex: 1; }
#dskey-status { font-size: 13px; color: #666; padding-left: 2px; }
#dskey-verify input { flex: 1; margin-bottom: 0; }
.modal-error { color: #e74c3c; font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }

.btn-primary, .btn-plain, .btn-danger {
  border: none; cursor: pointer;
  padding: 9px 20px;
  border-radius: 10px;
  font-size: 14px;
  transition: opacity 0.2s;
}
.btn-primary { background: #7aa874; color: #fff; }
.btn-plain { background: #f0f0f0; color: #555; }
.btn-danger { background: #fdecea; color: #e74c3c; }
.btn-primary:hover, .btn-plain:hover, .btn-danger:hover { opacity: 0.85; }

@media (max-width: 600px) {
  #time { font-size: 64px; }
  main { padding-top: 16vh; }
}
