/* ==================== CSS 变量 ==================== */
:root {
  --bg: #0f0f13;
  --bg-secondary: #18181f;
  --bg-card: #1e1e28;
  --bg-hover: #252530;
  --sidebar-bg: #141419;
  --accent: #7c3aed;
  --accent-light: #ff5533;
  --text-primary: #e8e8ee;
  --text-secondary: #9999aa;
  --text-muted: #666677;
  --border: #2a2a38;
  --border-light: #333345;
  --header-height: 68px;
  --quick-height: 0px;
  --sidebar-width: 220px;
  --float-height: 44px;
  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="light"] {
  --bg: #f2f2f7;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #e8e8f0;
  --sidebar-bg: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #44445a;
  --text-muted: #8888aa;
  --border: #dddde8;
  --border-light: #e8e8f0;
}

/* ==================== Reset ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

/* ==================== Header ==================== */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
}
.header-inner {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.logo-icon { font-size: 22px; }
.logo-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.logo-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 768px) { .logo-sub { display: inline; } }

.search-box {
  display: flex;
  flex: 1;
  max-width: 500px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 24px;
  overflow: hidden;
}
.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  padding: 8px 16px;
  font-size: 14px;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-secondary);
}
.search-btn:hover { color: var(--accent); }

/* ==================== Header 快搜按钮 ==================== */
.qs-engines {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}
.qs-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.qs-btn:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 900px) { .qs-engines { display: none; } }

/* ==================== 布局 ==================== */
.layout {
  display: flex;
  padding-top: calc(var(--header-height) + var(--quick-height));
  padding-bottom: calc(var(--float-height) + 60px);
  min-height: 100vh;
}

/* ==================== 侧边栏 ==================== */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + var(--quick-height));
  left: 0;
  width: var(--sidebar-width);
  bottom: var(--float-height);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.cat-main {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.cat-main-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  position: relative;
}
.cat-main-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.cat-main-link.active {
  color: var(--accent);
  background: rgba(124, 58, 237, 0.08);
}
.cat-main-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.cat-icon { font-size: 16px; }

.cat-subs { display: none; }
.cat-subs.open { display: block; }
.cat-sub-link {
  display: block;
  padding: 7px 16px 7px 38px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.cat-sub-link:hover { color: var(--text-secondary); background: var(--bg-hover); }
.cat-sub-link.active { color: var(--accent); }

/* ==================== 内容区 ==================== */
.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 20px;
  min-width: 0;
}

/* 推荐轮播 */
.promo-banner {
  background: linear-gradient(135deg, #0f0a1a, #1a0f2e);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  position: relative;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
[data-theme="light"] .promo-banner { background: linear-gradient(135deg, #f5f0ff, #ede0ff); border-color: rgba(124, 58, 237, 0.2); }
.promo-slides { flex: 1; position: relative; overflow: hidden; }
.promo-slide {
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  animation: fadeSlide 0.4s ease;
}
.promo-slide.active { display: flex; }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.promo-tag {
  background: var(--accent);
  color: white;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.promo-dots { display: flex; gap: 5px; margin-left: 12px; }
.promo-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(124,58,237,0.3);
  cursor: pointer;
  transition: background 0.2s;
}
.promo-dot.active { background: var(--accent); }

/* 主分类区块 */
.cat-section { margin-bottom: 32px; }
.cat-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.cat-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.cat-section-icon { font-size: 20px; }

/* 分类内搜索框 */
.cat-search {
  margin-left: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  width: 140px;
  transition: border-color 0.15s, width 0.2s;
}
.cat-search:focus { border-color: var(--accent); width: 180px; }
.cat-search::placeholder { color: var(--text-muted); }

/* 排序 tab */
.sort-tabs {
  display: flex;
  gap: 4px;
}
.sort-tab {
  padding: 2px 10px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  cursor: pointer;
  transition: all 0.15s;
}
.sort-tab:hover { color: var(--accent); border-color: var(--accent); }
.sort-tab.active { color: var(--accent); border-color: var(--accent); background: rgba(124,58,237,0.08); }
.pf-clear {
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: rgba(124,58,237,0.15);
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.pf-clear:hover { background: rgba(124,58,237,0.3); }
.platform-tag { cursor: pointer; }
.platform-tag:hover { filter: brightness(1.3); }
.tag-active { outline: 1px solid currentColor; filter: brightness(1.2); }

/* 子分类区块 */
.subcat-section { margin-bottom: 24px; }
.subcat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.subcat-title::before {
  content: '';
  width: 3px; height: 13px;
  background: var(--accent);
  border-radius: 2px;
}

/* 链接卡片网格 */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

/* 链接卡片 */
.link-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.link-status {
  position: absolute;
  top: 8px; right: 8px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
  transition: background 0.3s, opacity 0.3s;
}
.link-status.ok { background: #4caf50; opacity: 1; }
.link-status.fail { background: #e53935; opacity: 0.9; }
.link-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.link-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.link-favicon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.link-favicon img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 6px;
}
.link-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.link-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.platform-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 500;
}
.tag-web    { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.tag-android{ background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid rgba(34,197,94,0.3); }
.tag-ios    { background: rgba(156,163,175,0.15); color: #d1d5db; border: 1px solid rgba(156,163,175,0.3); }
.tag-tv     { background: rgba(168,85,247,0.15); color: #c084fc; border: 1px solid rgba(168,85,247,0.3); }
.tag-windows{ background: rgba(14,165,233,0.15); color: #38bdf8; border: 1px solid rgba(14,165,233,0.3); }
.tag-macos  { background: rgba(251,191,36,0.15); color: #fbbf24; border: 1px solid rgba(251,191,36,0.3); }

/* ==================== 搜索遮罩 ==================== */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.search-results-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 90%;
  max-width: 700px;
  max-height: 70vh;
  overflow-y: auto;
}
.search-results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.search-results-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}
.search-results-header button:hover { color: var(--text-primary); }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item:last-child { border-bottom: none; }
.search-no-result { padding: 30px; text-align: center; color: var(--text-muted); }

/* ==================== 预览弹窗 ==================== */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}
.preview-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 88vw;
  max-width: 1100px;
  height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  flex-shrink: 0;
}
.preview-header span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-open {
  font-size: 12px;
  color: var(--accent);
  padding: 3px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  white-space: nowrap;
}
.preview-header button {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 18px; cursor: pointer;
}
.preview-header button:hover { color: var(--text-primary); }
.preview-panel iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}
.preview-warn {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
}
/* 预览按钮 */
.preview-btn {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.link-card:hover .preview-btn { opacity: 1; }
.preview-btn:hover { color: var(--accent); }

/* ==================== 底部浮动栏 ==================== */
.float-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--float-height);
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.float-bar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}
.float-item { cursor: pointer; }
.float-item:hover { color: var(--accent); }
.float-divider { color: var(--border-light); }

/* ==================== 友链 ==================== */
.friendlinks {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  margin-left: var(--sidebar-width);
}
.friendlinks-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
}
.friendlinks-label { color: var(--text-muted); white-space: nowrap; }
.friendlinks a { color: var(--text-secondary); }
.friendlinks a:hover { color: var(--accent); }

/* ==================== 页脚 ==================== */
.site-footer {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ==================== 返回顶部 ==================== */
.back-top {
  position: fixed;
  right: 20px;
  bottom: calc(var(--float-height) + 16px);
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, color 0.2s;
}
.back-top.visible { opacity: 1; pointer-events: auto; }
.back-top:hover { color: var(--accent); border-color: var(--accent); }

/* ==================== 主题切换按钮 ==================== */
.theme-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  width: 32px; height: 32px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}
.theme-btn:hover { border-color: var(--accent); }

/* ==================== 汉堡按钮 ==================== */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px; height: 36px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 100%; height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: background 0.15s;
}
.hamburger:hover span { background: var(--text-primary); }
@media (max-width: 768px) { .hamburger { display: flex; } }

/* ==================== 侧边栏遮罩 ==================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}
.sidebar-overlay.visible { display: block; }

/* ==================== 收藏按钮 ==================== */
.fav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s, transform 0.15s;
}
.fav-btn:hover { color: #7c3aed; transform: scale(1.2); }
.fav-btn.active { color: #7c3aed; }
.fav-nav { border-bottom: 1px solid var(--accent) !important; }
.fav-nav-link { color: var(--accent) !important; }

/* ==================== 空状态 ==================== */
.empty-links {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(-200px); width: 200px; transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); --sidebar-width: 200px; }
  .content { margin-left: 0; }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
