:root {
  /* ai-bot.cn 风格：深色背景 + 红色主调 */
  --bg-from: #1a1d29;
  --bg-to: #2c2e2f;
  --fg: #e5e7eb;
  --muted: #94a3b8;
  --card: rgba(255, 255, 255, 0.05);
  --card-solid: #2a2d3a;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --hover: rgba(255, 255, 255, 0.08);
  --accent: #e40c53;
  --accent-hover: #b80940;
  --accent-fg: #ffffff;
  --icon-border: rgba(160, 160, 170, 0.35);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --radius: 10px;
  --danger: #ef4444;
  /* 内容区统一宽度：搜索区与 AI 分类导航同宽居中 */
  --content-w: 1100px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-from: #f5f7fa;
    --bg-to: #e8ecf3;
    --fg: #1a1f2c;
    --muted: #6b7280;
    --card: rgba(255, 255, 255, 0.85);
    --card-solid: #ffffff;
    --border: rgba(15, 23, 42, 0.1);
    --border-strong: rgba(15, 23, 42, 0.18);
    --hover: rgba(15, 23, 42, 0.04);
    --icon-border: rgba(120, 120, 130, 0.35);
    --shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  background-attachment: fixed;
  transition: background 0.3s ease, color 0.2s ease;
}

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
  gap: 32px;
}

.section {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

/* 开启 AI 分类导航后：分区不再平分高度，内容自然高度、向上对齐 */
.container.has-ai-nav .section {
  flex: 0 0 auto;
  justify-content: flex-start;
}

/* ===== 搜索区 ===== */
.search-section {
  align-items: center;
}

/* LOGO 独占左侧两行：右列依次为搜索框、搜索引擎；整块固定与 AI 导航同宽并居中 */
.search-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 24px;
  row-gap: 12px;
  align-items: center;
  width: 100%;
  max-width: var(--content-w);
  margin-inline: auto;
}

.logo-wrap {
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.logo {
  width: 194px;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* ===== 搜索框（胶囊形 + 右侧放大镜；铺满 LOGO 右侧整列）===== */
.search-form {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  min-width: 0;
  width: 100%;
  position: relative;
}

.search-input {
  flex: 1;
  padding: 16px 56px 16px 24px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #1a1f2c;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input::placeholder {
  color: #6b7280;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.search-btn:hover {
  background: var(--accent-hover);
}

/* ===== 搜索引擎选项（第二行，铺满右列，与搜索框左对齐）===== */
.engine-options {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: flex-start;
  width: 100%;
  margin-top: 0;
}

.engine-opt {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 4px;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s ease;
  font-family: inherit;
  position: relative;
}

.engine-opt:hover {
  color: var(--fg);
}

.engine-opt.active {
  color: var(--accent);
  font-weight: 600;
}

.engine-opt.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* ===== 收藏夹区 ===== */
/* 收藏夹标题/编辑按钮已移到右侧设置面板，这里只保留网格 */
/* 编辑模式顶部居中的"完成编辑"按钮条 */
.bookmark-edit-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 0;
}

/* hidden 属性优先级要高于 display:flex，否则按钮在不编辑时也会显示 */
.bookmark-edit-bar[hidden] {
  display: none !important;
}

.done-edit-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 8px 24px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: background 0.15s ease, transform 0.1s ease;
}

.done-edit-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.done-edit-btn:active {
  transform: scale(0.98);
}

.bookmark-grid {
  /* --bm-cols 由 scripts.js 按用户设置写入；--bm-cell-w 为单列自然宽度 */
  --bm-cols: 12;
  --bm-cell-w: 102px;
  display: grid;
  /* 1fr 保证窄屏可收缩，max-width 限制宽屏下列数不被过度拉伸，整体居中 */
  grid-template-columns: repeat(var(--bm-cols), minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: calc(var(--bm-cols) * var(--bm-cell-w) + (var(--bm-cols) - 1) * 10px);
  margin-inline: auto;
}

.bm-cell {
  appearance: none;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 70px;
  font: inherit;
  color: var(--fg);
}

.bm-cell.filled:hover {
  transform: translateY(-2px);
}

/* 鼠标悬停收藏图标：边框变红 + 名称加粗 + 字体加大一号 */
.bm-cell.filled:hover .bm-icon {
  border-color: var(--accent);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 25%, transparent);
}

.bm-cell.filled:hover .bm-label {
  font-weight: 700;
  font-size: 13px;
}

.bm-cell.empty {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
}

.bm-cell.empty:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== 编辑模式：拖动排序 ===== */
.bm-cell.dragging,
.ai-site-card.dragging {
  opacity: 0.3;
}

.bm-cell.drag-target,
.ai-site-card.drag-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius);
}

.drag-ghost {
  position: fixed !important;
  margin: 0 !important;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.92;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  transform: rotate(2deg) scale(1.04);
  background: var(--card-solid);
  border-radius: var(--radius);
}

.bm-cell.edit-mode {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius);
}

/* 收藏图标：screenshot_1 风格 - 白色 squircle 圆角方块 + 中间彩色 favicon */
.bm-icon {
  width: 57px;
  height: 57px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  flex-shrink: 0;
  /* squircle 风格：白底 + 圆角较大 + 浅边框 */
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  background: #ffffff;
  overflow: hidden;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

@media (prefers-color-scheme: light) {
  .bm-icon {
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  }
}

.bm-favicon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bm-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
}

.bm-label {
  font-size: 11px;
  color: var(--fg);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* 固定行高与高度：hover 时放大字号/加粗不再撑高行盒，避免整页跳动 */
  line-height: 16px;
  height: 16px;
  transition: font-size 0.15s ease, font-weight 0.15s ease;
}

.bm-plus {
  font-size: 20px;
  color: var(--muted);
  font-weight: 300;
  line-height: 1;
}

.bm-cell.empty:hover .bm-plus {
  color: var(--accent);
}

/* ===== AI 工具分类导航 ===== */
.ai-nav-section {
  flex: none;
  justify-content: flex-start;
  gap: 14px;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
}

/* .section 的 display:flex 会覆盖 hidden 的默认隐藏，需显式声明 */
.ai-nav-section[hidden] {
  display: none !important;
}

.ai-nav-editbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-bottom: 2px;
}

.ai-nav-editbar[hidden] {
  display: none !important;
}

.ai-nav-hint {
  font-size: 12px;
  color: var(--muted);
}

/* 分类药丸条（参考 ai-bot.cn：灰色圆角胶囊容器） */
.ai-cat-bar {
  background: rgba(120, 120, 130, 0.16);
  border-radius: 999px;
  padding: 6px;
}

.ai-cat-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border-radius: 999px;
}

.ai-cat-pills::-webkit-scrollbar {
  display: none;
}

.ai-cat {
  appearance: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 22px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease;
}

.ai-cat:hover {
  color: var(--fg);
}

.ai-cat.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

/* 编辑模式下分类的删除/重命名小叉 */
.ai-cat .ai-cat-x {
  display: none;
  margin-left: 6px;
  font-size: 13px;
  opacity: 0.75;
}

.ai-nav-section.edit-mode .ai-cat .ai-cat-x {
  display: inline-block;
}

.ai-cat-add {
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  flex-shrink: 0;
}

/* 站点卡片网格（参考 faxianai：白底圆角卡片 + 左 logo + 标题/描述） */
.ai-sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.ai-site-card {
  appearance: none;
  text-align: left;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  color: var(--fg);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.ai-site-card:hover {
  transform: translateY(-2px);
  background: var(--hover);
  border-color: var(--accent);
}

.ai-site-logo {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 12px;
  object-fit: cover;
  background: rgba(120, 120, 130, 0.12);
}

.ai-site-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
}

.ai-site-info {
  flex: 1;
  min-width: 0;
}

.ai-site-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--fg);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-site-desc {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-site-card.add-card {
  justify-content: center;
  border: 1px dashed var(--border-strong);
  color: var(--muted);
  font-size: 14px;
  background: transparent;
}

.ai-site-card.add-card:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ai-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 0;
}

/* 设置面板两个并排按钮 */
.settings-row-btns {
  gap: 10px;
}

.settings-row-btns .settings-edit-btn {
  flex: 1;
}

.settings-edit-btn.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.settings-edit-btn.secondary:hover {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.settings-edit-btn.secondary:active {
  transform: scale(0.98);
}

/* ===== 右上角齿轮设置按钮 ===== */
.settings-btn {
  position: fixed;
  top: 18px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.2s ease, color 0.15s ease;
}

.settings-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: rotate(45deg);
}

@media (prefers-color-scheme: light) {
  .settings-btn {
    background: rgba(255, 255, 255, 0.7);
    border-color: var(--border);
  }
}

/* ===== 右侧设置面板 ===== */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: var(--card-solid);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.25);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  display: flex;
  flex-direction: column;
  font-family: inherit;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--fg);
}

.settings-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}

.settings-close:hover {
  color: var(--accent);
  background: var(--hover);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.settings-row {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-row:last-child {
  border-bottom: none;
}

/* 行数 / 列数合并为一行：两组等宽，各自标签与下拉框两端对齐 */
.settings-size-group {
  display: flex;
  gap: 24px;
  width: 100%;
}

.settings-size-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
}

/* 设置面板底部作者信息 */
.settings-footer {
  padding: 14px 20px 18px;
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim, rgba(120, 120, 130, 0.85));
}

.settings-footer p {
  margin: 0;
}

.settings-footer a {
  color: var(--accent);
  text-decoration: none;
}

.settings-footer a:hover {
  text-decoration: underline;
}

/* 版本号与作者同一行 */
.settings-footer .settings-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

/* 备份与还原：说明行与按钮行合并成一组，去掉中间横线 */
.settings-row.settings-row-grouped {
  border-bottom: none;
  padding-bottom: 4px;
}

/* ===== 语言选择（带国旗的自定义下拉） ===== */
.lang-picker {
  position: relative;
}

.lang-picker-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 168px;
  height: 36px;
  padding: 0 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.lang-picker-btn:hover {
  border-color: var(--border-strong);
}

.lang-picker-btn > svg {
  margin-left: auto;
  opacity: 0.6;
  flex-shrink: 0;
}

.lang-picker-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-flag {
  display: block;
  width: 21px;
  height: 14px;
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.lang-flag svg {
  display: block;
  width: 100%;
  height: 100%;
}

.lang-picker-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1200;
  width: 210px;
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.lang-picker-list[hidden] {
  display: none !important;
}

.lang-picker-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
}

.lang-picker-list li:hover {
  background: var(--hover);
}

.lang-picker-list li[aria-selected="true"] {
  color: var(--accent);
  font-weight: 600;
}

.settings-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  display: block;
}

.settings-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  display: block;
}

.settings-toggle-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.settings-select {
  appearance: none;
  background: var(--bg-from);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 28px 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.15s ease;
}

.settings-select:hover {
  border-color: var(--accent);
}

.settings-edit-btn {
  width: 100%;
  background: var(--accent);
  border: none;
  color: var(--accent-fg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.1s ease;
}

.settings-edit-btn:hover {
  background: var(--accent-hover);
}

.settings-edit-btn:active {
  transform: scale(0.98);
}

.settings-edit-btn.active {
  background: var(--accent-hover);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Switch 开关 */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* 设置面板遮罩 */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.settings-overlay.show {
  opacity: 1;
}

/* ===== Bing 背景图层 ===== */
.bg-layer {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: -2;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.bg-layer.active {
  opacity: 1;
}

.bg-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(26, 29, 41, 0.65), rgba(44, 46, 47, 0.55));
  z-index: -1;
}

@media (prefers-color-scheme: light) {
  .bg-layer::after {
    background: linear-gradient(135deg, rgba(245, 247, 250, 0.75), rgba(232, 236, 243, 0.65));
  }
}

body.bing-bg-active {
  background: transparent;
}

body.bing-bg-active html {
  background: transparent;
}

/* ===== 自定义右键菜单 ===== */
.ctx-menu {
  position: fixed;
  z-index: 1500;
  min-width: 140px;
  padding: 6px;
  background: var(--card-solid);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ctx-menu[hidden] { display: none; }

.ctx-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg);
  padding: 8px 14px;
  font-size: 14px;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s ease, color 0.12s ease;
}
.ctx-item:hover {
  background: var(--accent);
  color: var(--accent-fg);
}

/* ===== 模态框 ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--card-solid);
  border-radius: 14px;
  padding: 24px;
  width: 380px;
  max-width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.modal-title {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.modal-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.modal-input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  outline: none;
  font-family: inherit;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}

.modal-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.modal-btn:hover {
  background: var(--hover);
}

.modal-btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.modal-btn.primary:hover {
  background: var(--accent-hover);
}

.modal-btn.secondary {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  margin-right: auto;
}

.modal-btn.secondary:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.modal-btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.modal-btn.danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* ===== Toast 提示 ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-solid);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2000;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 响应式 ===== */
/* 收藏网格列数上限由 scripts.js 的 getEffectiveBookmarkCols() 按相同断点控制，
   列宽保持自然宽度并整体居中（见 .bookmark-grid） */
@media (max-width: 600px) {
  .container {
    padding: 16px;
    gap: 16px;
  }
  .search-top {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .logo-wrap,
  .search-form,
  .engine-options {
    grid-column: auto;
    grid-row: auto;
  }
  .logo {
    width: 150px;
    height: auto;
  }
  .engine-options {
    justify-content: center;
  }
  .ai-sites-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 400px) {
  .engine-opt {
    font-size: 13px;
  }
}

/* ===== 手机浏览器适配 ===== */
@media (max-width: 720px) {
  /* 收藏改为 4 列，避免 10/12 列在手机上挤成一团 */
  .bookmark-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .settings-panel {
    width: 100%;
  }
  .minimal-view {
    gap: 22px;
    padding: 28px 14px;
  }
  .minimal-bookmarks {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }
  .page-footer {
    padding: 4px 14px 16px;
  }
}

/* 网页模式下隐藏云端备份（没有 chrome.storage.sync） */
.web-mode [data-cloud-row] {
  display: none;
}

/* ===== 页脚标语 ===== */
.page-footer {
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 4px 20px 24px;
  text-align: center;
}

.page-footer p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  opacity: 0.75;
}

/* 收藏编辑模式末尾的“添加”格子（与 AI 导航的 add-card 一致） */
.bm-cell.bm-add-cell {
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  font-size: 22px;
  font-weight: 300;
  min-height: 70px;
  justify-content: center;
}

.bm-cell.bm-add-cell:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== 极简模式 ===== */
/* 开启后隐藏常规布局，只保留四行内容（时钟 / 搜索 / 两行收藏） */
body.minimal-mode .container,
body.minimal-mode .page-footer {
  display: none !important;
}

.minimal-view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 38px;
  padding: 48px 24px;
}

.minimal-view[hidden] {
  display: none !important;
}

/* 第一行：带秒的数字时钟 */
.minimal-clock {
  text-align: center;
  user-select: none;
}

.mc-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  font-size: clamp(54px, 8.5vw, 100px);
  font-weight: 200;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, var(--fg) 25%, color-mix(in srgb, var(--fg) 55%, transparent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.mc-sep {
  margin: 0 0.06em;
  animation: mcBlink 1s steps(1) infinite;
}

@keyframes mcBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.18; }
}

.mc-date {
  margin-top: 12px;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* 第二行：前置引擎下拉的搜索框 */
.minimal-search {
  display: flex;
  align-items: center;
  width: min(680px, 100%);
  height: 58px;
  padding: 5px 6px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.minimal-engine-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.minimal-engine-select {
  appearance: none;
  -webkit-appearance: none;
  height: 44px;
  padding: 0 30px 0 16px;
  border: none;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  color: #1a1f2c;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  max-width: 150px;
}

.minimal-engine-select:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.minimal-engine-arrow {
  position: absolute;
  right: 11px;
  color: #6b7280;
  pointer-events: none;
}

/* RTL（阿拉伯语）：下拉箭头移到左侧 */
[dir="rtl"] .minimal-engine-arrow {
  right: auto;
  left: 11px;
}

[dir="rtl"] .minimal-engine-select {
  padding: 0 16px 0 30px;
}

.minimal-search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 8px 0 14px;
  border: none;
  background: transparent;
  color: #1a1f2c;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.minimal-search-input::placeholder {
  color: #6b7280;
}

.minimal-search-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.minimal-search-btn:hover {
  background: var(--accent-hover);
}

/* 第三、四行：各 8 个收藏图标，整体居中 */
.minimal-bm-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.minimal-bookmarks {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 12px;
  width: min(680px, 100%);
}

.minimal-bookmarks:empty {
  display: none;
}

.minimal-bookmarks .bm-cell {
  min-height: 0;
  padding: 8px 2px;
}

/* 极简模式编辑栏：搜索框下方居中（与非极简模式一致） */
.minimal-edit-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: -14px;
}

.minimal-edit-bar[hidden] {
  display: none !important;
}

/* 编辑栏里的次要按钮（全部重排） */
.done-edit-btn.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid color-mix(in srgb, var(--fg) 20%, transparent);
  box-shadow: none;
}

.done-edit-btn.secondary:hover {
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}

/* 全部重排后的暂存区 */
.bm-pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  max-width: var(--content-w);
  margin: 18px auto 0;
  padding: 16px 12px;
  border-radius: 16px;
  border: 1px dashed color-mix(in srgb, var(--fg) 20%, transparent);
  background: color-mix(in srgb, var(--fg) 4%, transparent);
}

.bm-pool[hidden] {
  display: none !important;
}

.bm-pool .bm-cell {
  width: 84px;
  min-height: 0;
  padding: 6px 2px;
}

.bm-pool .bm-cell:empty {
  display: none;
}

@media (max-width: 720px) {
  .minimal-view {
    gap: 28px;
  }

  .minimal-bookmarks {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(460px, 100%);
  }

  .minimal-engine-select {
    max-width: 96px;
  }
}
