:root {
  --blue: #0066cc;
  --blue-focus: #0071e3;
  --ink: #1d1d1f;
  --ink-muted: #7a7a7a;
  --hairline: rgba(0, 0, 0, 0.08);
  --radius-card: 18px;
  --radius-pill: 9999px;
  --maxw: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Inter", system-ui, sans-serif;
}

/* ---------- 浅色主题 ---------- */
body[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --text: #1d1d1f;
  --text-muted: #7a7a7a;
  --card-border: rgba(0, 0, 0, 0.06);
  --appbar-bg: rgba(255, 255, 255, 0.8);
  --appbar-text: #1d1d1f;
  --chip-bg: #ffffff;
  --hover: rgba(0, 102, 204, 0.06);
}

/* ---------- 深色主题 ---------- */
body[data-theme="dark"] {
  --bg: #000000;
  --surface: #1d1d1f;
  --surface-2: #2a2a2c;
  --text: #f5f5f7;
  --text-muted: #a1a1a6;
  --card-border: rgba(255, 255, 255, 0.1);
  --appbar-bg: rgba(20, 20, 22, 0.8);
  --appbar-text: #f5f5f7;
  --chip-bg: #2a2a2c;
  --hover: rgba(41, 151, 255, 0.14);
}

/* ---------- 背景预设 ---------- */
body[data-bg="preset-light"] { --page-bg: #ffffff; --page-bg-2: #f5f5f7; }
body[data-bg="preset-dark"]  { --page-bg: #0b0b0d; --page-bg-2: #161618; }
body[data-bg="preset-blue"]  { --page-bg: #eef4fb; --page-bg-2: #dce9f8; }
body[data-bg="preset-sunset"]{ --page-bg: #fff3e6; --page-bg-2: #ffe0ec; }
body[data-bg="preset-forest"]{ --page-bg: #eaf3ec; --page-bg-2: #d6ecdd; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(180deg, var(--page-bg) 0%, var(--page-bg-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.2s ease;
}

/* ---------- 顶部导航 ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: var(--appbar-bg);
  border-bottom: 1px solid var(--hairline);
}
.appbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  height: 52px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { color: var(--blue); font-size: 20px; }
.brand-name { font-weight: 600; font-size: 17px; color: var(--appbar-text); letter-spacing: -0.2px; }
.appbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  border: 1px solid var(--card-border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.2s ease;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(0.95); }

.primary-btn {
  height: 36px;
  padding: 0 18px;
  border: none;
  background: var(--blue);
  color: #fff;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.1s ease, background 0.2s ease;
}
.primary-btn:hover { background: var(--blue-focus); }
.primary-btn:active { transform: scale(0.96); }
.primary-btn.active { background: var(--ink); }

/* ---------- 页面 ---------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 0 24px 64px; }

.hero { padding: 72px 0 56px; text-align: center; }
.greeting { font-size: 30px; font-weight: 400; margin: 0 0 28px; letter-spacing: 0.2px; }
.search {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  height: 56px;
  padding: 0 22px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.12); }
.search-icon { font-size: 16px; opacity: 0.6; }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 17px;
  color: var(--text);
  font-family: var(--font);
}
.search-input::placeholder { color: var(--text-muted); }

.engine-chips { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.chip {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--chip-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}
.chip:hover { background: var(--hover); }
.chip:active { transform: scale(0.95); }

/* ---------- 分组 ---------- */
.sections { display: flex; flex-direction: column; gap: 44px; }
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.section-title { font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }
.section-actions { display: flex; gap: 8px; margin-left: auto; }
.mini-btn {
  border: 1px solid var(--card-border);
  background: var(--chip-bg);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}
.mini-btn:hover { background: var(--hover); color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
@media (max-width: 1024px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px)  { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px)  { .grid { grid-template-columns: 1fr; } }

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--blue);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07);
}
.card-icon {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  border-radius: 11px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.card-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-url { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-edit {
  position: absolute; top: 8px; right: 8px;
  display: none;
  gap: 4px;
}
.card:hover .card-edit { display: flex; }
.edit-dot {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.edit-dot:hover { background: var(--hover); color: var(--text); }

/* 拖拽 */
.card.dragging { opacity: 0.4; }
.card.drop-target { border-style: dashed; border-color: var(--blue); }

/* 新增链接占位卡片 */
.add-link {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--card-border);
  border-radius: var(--radius-card);
  color: var(--text-muted);
  font-size: 14px;
  min-height: 76px;
  cursor: pointer;
  background: transparent;
  transition: background 0.2s ease;
}
.add-link:hover { background: var(--hover); color: var(--text); }

/* ---------- 页脚 ---------- */
.site-footer { text-align: center; margin-top: 64px; padding-top: 40px; border-top: 1px solid var(--hairline); }
.site-footer .brand-name { font-weight: 600; }
.footer-note { color: var(--text-muted); font-size: 13px; margin: 8px 0 0; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); }
.modal-card {
  position: relative;
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 22px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.modal-card.small { width: min(420px, 92vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.modal-body { display: flex; flex-direction: column; gap: 18px; }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.field .check { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; color: var(--text); font-weight: 400; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.text-input {
  flex: 1;
  min-width: 160px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}
.text-input:focus { border-color: var(--blue); }
select.text-input { cursor: pointer; }

.seg { display: inline-flex; border: 1px solid var(--card-border); border-radius: var(--radius-pill); overflow: hidden; }
.seg-item {
  border: none; background: transparent; color: var(--text-muted);
  padding: 8px 20px; cursor: pointer; font-size: 14px;
}
.seg-item.active { background: var(--blue); color: #fff; }

.bg-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.bg-swatch {
  height: 40px; border-radius: 10px; cursor: pointer;
  border: 2px solid transparent;
}
.bg-swatch.active { border-color: var(--blue); }

.ghost-btn {
  height: 38px; padding: 0 16px;
  border: 1px solid var(--card-border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px; cursor: pointer; font-size: 14px;
}
.ghost-btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.ghost-btn:hover { background: var(--hover); }
.ghost-btn.danger { color: #d70015; border-color: rgba(215,0,21,0.3); }
.ghost-btn.danger:hover { background: rgba(215,0,21,0.08); }
.spacer { flex: 1; }

.add-cat-wrap { margin-top: 36px; text-align: center; }
