/* ---------- 主题变量 ---------- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9ecf1;
  --text: #14171c;
  --text-2: #5f6773;
  --text-3: #98a1ad;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --accent: #2563eb;
  --accent-soft: #eaf1fe;
  --accent-text: #1d4ed8;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-2: 0 6px 20px rgba(15, 23, 42, 0.1);
  --shadow-3: 0 20px 50px rgba(15, 23, 42, 0.18);
  --radius-s: 9px;
  --radius-m: 13px;
  --radius-l: 18px;
  --topbar-h: 64px;
}

html[data-theme='dark'] {
  --bg: #101216;
  --surface: #191c22;
  --surface-2: #22262d;
  --surface-3: #2b3038;
  --text: #e9ebef;
  --text-2: #a1a9b6;
  --text-3: #6d7581;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #5b93f7;
  --accent-soft: rgba(91, 147, 247, 0.14);
  --accent-text: #94b8fb;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 20px 50px rgba(0, 0, 0, 0.6);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }

/* 作者样式里的 display 会覆盖 UA 的 [hidden]，这里强制兜底 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.18s ease, color 0.18s ease;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 3px solid transparent;
  background-clip: content-box;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 520px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 13px;
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 38px;
  padding: 0 62px 0 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#search-input::placeholder { color: var(--text-3); }
#search-input::-webkit-search-cancel-button { display: none; }

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-kbd {
  position: absolute;
  right: 12px;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

#search-input:focus ~ .search-kbd,
#search-input:not(:placeholder-shown) ~ .search-kbd { opacity: 0; }

.search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  color: var(--text-3);
  border-radius: 50%;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  border-radius: 10px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.is-active { background: var(--accent-soft); color: var(--accent-text); }

.account-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 4px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.account-btn:hover { border-color: var(--border-strong); }

.avatar {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 50%;
  overflow: hidden;
  flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.account-name {
  font-size: 13px;
  color: var(--text-2);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 主区 ---------- */
.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

.section + .section { margin-top: 34px; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.section-meta {
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- 常去区 ---------- */
.hot-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 14px;
}

.hot-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  border-radius: var(--radius-m);
  transition: transform 0.14s ease, background-color 0.14s ease;
}
.hot-item:hover { transform: translateY(-2px); background: var(--surface); }
.hot-item:hover .hot-tile { box-shadow: var(--shadow-2); border-color: transparent; }

.hot-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  transition: box-shadow 0.14s ease, border-color 0.14s ease;
}

.hot-name {
  font-size: 12px;
  color: var(--text-2);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 站点图标：img 成功则覆盖，失败则露出首字母色块 */
.site-icon {
  --ic: #e8f0fe;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 9px;
  overflow: hidden;
  flex: none;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--ic) 34%, var(--surface));
  color: color-mix(in srgb, var(--text) 74%, var(--ic));
}
.site-icon img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--surface);
}
.site-icon img.is-broken { display: none; }

.hot-tile .site-icon { width: 38px; height: 38px; border-radius: 11px; font-size: 16px; }
.hot-tile .site-icon img { padding: 0; }

/* ---------- 分类 tab ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 32px 0 18px;
  padding-bottom: 2px;
}

.tab {
  height: 32px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: all 0.14s ease;
}
.tab:hover { border-color: var(--border-strong); color: var(--text); }
.tab.is-active {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 34%, transparent);
}
.tab-count { font-size: 11px; color: var(--text-3); }
.tab.is-active .tab-count { color: var(--accent-text); opacity: 0.75; }

.tab-add { color: var(--text-3); border-style: dashed; }

/* ---------- 分类区 ---------- */
.categories { display: flex; flex-direction: column; gap: 30px; }

.cat-block { scroll-margin-top: calc(var(--topbar-h) + 16px); }
.cat-block[hidden] { display: none; }

.cat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cat-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.site-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}
.site-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}
.site-card .site-icon { width: 32px; height: 32px; font-size: 13px; }

.site-text { min-width: 0; flex: 1; }
.site-name {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.site-desc {
  font-size: 11.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

/* 搜索命中高亮 */
mark {
  padding: 0 1px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 3px;
}

/* 编辑模式 */
body.editing .hot-item,
body.editing .site-card { cursor: grab; }
body.editing .site-card { padding-right: 78px; }

.card-actions {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: none;
  gap: 2px;
}
body.editing .card-actions { display: flex; }

.mini-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  border-radius: 7px;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.mini-btn svg { width: 14px; height: 14px; }
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.mini-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.mini-btn.is-on { color: var(--accent-text); background: var(--accent-soft); }

.add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 58px;
  font-size: 13px;
  color: var(--text-3);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
  transition: all 0.14s ease;
}
.add-card:hover { color: var(--accent-text); border-color: var(--accent); background: var(--accent-soft); }
.add-card[hidden] { display: none; }
/* 内联 SVG 默认 300x150，不锁尺寸会把卡片撑成巨型方块并顶高整行 */
.add-card svg { width: 15px; height: 15px; flex: none; }

.add-cat-row { display: flex; align-items: center; }

.add-cat-tile {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-3);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
  transition: all 0.14s ease;
}
.add-cat-tile svg { width: 15px; height: 15px; flex: none; }
.add-cat-tile:hover {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* 拖拽 */
.dragging { opacity: 0.35; }
.drop-hint {
  box-shadow: 0 0 0 2px var(--accent);
  border-radius: var(--radius-m);
}

/* ---------- 空状态 / 页脚 ---------- */
.empty-state {
  padding: 70px 0;
  text-align: center;
}
.empty-title { font-size: 15px; font-weight: 500; }
.empty-hint { margin-top: 6px; font-size: 13px; color: var(--text-3); }

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 46px;
  padding-top: 18px;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
}
.footer span { display: inline-flex; align-items: center; gap: 4px; }
.sync-state { margin-left: auto; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 14, 20, 0.44);
  backdrop-filter: blur(3px);
  animation: fade 0.14s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

.modal {
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-3);
  animation: rise 0.16s ease;
}
.modal.is-wide { max-width: 620px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 4px 20px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-l) var(--radius-l);
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}
.field input[type='text'],
.field input[type='url'],
.field input[type='email'],
.field input[type='tel'],
.field input[type='password'],
.field textarea,
.field select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 76px; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-hint { margin-top: 5px; font-size: 11.5px; color: var(--text-3); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

.btn {
  height: 36px;
  padding: 0 16px;
  font-size: 13px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  transition: all 0.14s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }

.icon-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius-s);
  margin-bottom: 14px;
}
.icon-preview .site-icon { width: 34px; height: 34px; font-size: 14px; }

/* 登录方式 */
.auth-tip {
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--radius-s);
}
.auth-actions { display: flex; flex-direction: column; gap: 8px; }
.auth-actions .btn { height: 40px; }
.auth-err { margin-top: 10px; font-size: 12.5px; color: var(--danger); }
.auth-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 11.5px;
  color: var(--text-3);
}
.auth-sep::before, .auth-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.user-card { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.user-card .avatar { width: 44px; height: 44px; font-size: 16px; }
.user-card-name { font-size: 14px; font-weight: 500; }
.user-card-sub { font-size: 12px; color: var(--text-3); }

/* 导入 */
.import-area { min-height: 120px; font-family: ui-monospace, monospace; font-size: 12px; }
.import-stat { margin-top: 10px; font-size: 12.5px; color: var(--text-2); }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 200;
  transform: translateX(-50%);
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-3);
  animation: rise 0.16s ease;
}
.toast[hidden] { display: none; }
.toast.is-error { color: var(--danger); }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
  .hot-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  :root { --topbar-h: 58px; }
  .topbar { padding: 0 14px; gap: 8px; }
  .main { padding: 20px 14px 32px; }
  .hot-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .account-name { display: none; }
  .account-btn { padding: 0 4px; }
  .footer { font-size: 11.5px; gap: 12px; }
  .sync-state { margin-left: 0; width: 100%; }
  .modal { max-width: 100%; }
  .field-row { flex-direction: column; gap: 0; }
}

@media (max-width: 460px) {
  .hot-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cat-grid { grid-template-columns: 1fr; }
  .search-kbd { display: none; }
  #search-input { padding-right: 34px; }
  body.editing .site-card { padding-right: 78px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 最近访问 ---------- */
.recent-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px 0 6px;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 17px;
  transition: border-color 0.14s ease, color 0.14s ease;
}
.recent-chip:hover { border-color: var(--border-strong); color: var(--text); }
.recent-chip .site-icon { width: 22px; height: 22px; font-size: 10px; border-radius: 6px; }

/* ---------- 分类标题操作 ---------- */
.cat-actions {
  display: inline-flex;
  gap: 1px;
  order: 2;
}

/* ---------- 通用 ---------- */
.confirm-text {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-2);
}

.footer-tools {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.footer-tools[hidden] { display: none; }

.footer-btn {
  font-size: 12px;
  color: var(--accent-text);
  padding: 0 2px;
  border-radius: 4px;
}
.footer-btn:hover { text-decoration: underline; }

.mini-btn svg { width: 14px; height: 14px; }
.modal-head .mini-btn svg { width: 15px; height: 15px; }

.field input[type='file'] {
  height: auto;
  padding: 8px 10px;
  font-size: 12.5px;
}

