/* ==================== CSS 变量 ==================== */
:root {
  --bg: #001428;
  --bg-secondary: #002040;
  --bg-card: #002a52;
  --bg-hover: #003366;
  --sidebar-bg: #001020;
  --accent: #C8A951;
  --accent-light: #e8c96a;
  --text-primary: #e8eef5;
  --text-secondary: #8aaac8;
  --text-muted: #4d6a85;
  --border: #0a3060;
  --border-light: #0d3d78;
  --header-height: 68px;
  --quick-height: 0px;
  --sidebar-width: 160px; /* 首屏占位，由 main.js 按实测宽度覆盖 */
  --float-height: 44px;
  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef1f8;
  --sidebar-bg: #003087;
  --accent: #003087;
  --accent-light: #1a4db3;
  --text-primary: #001a3d;
  --text-secondary: #2a3f6e;
  --text-muted: #6b7a99;
  --border: #d0d7e3;
  --border-light: #e4e9f2;
}

/* 浅色主题：侧边栏深蓝背景，文字改为白色系 */
[data-theme="light"] .sidebar {
  border-right-color: rgba(255,255,255,0.2);
}
[data-theme="light"] .cat-main {
  border-bottom-color: rgba(255,255,255,0.15);
}
[data-theme="light"] .cat-main-link {
  color: rgba(255,255,255,0.75);
}
[data-theme="light"] .cat-main-link:hover {
  background: rgba(255,255,255,0.1);
  color: #ffffff;
}
[data-theme="light"] .cat-main-link.active {
  color: #ffffff;
  background: rgba(255,255,255,0.15);
}
[data-theme="light"] .cat-main-link.active::before {
  background: #C8A951;
}
[data-theme="light"] .cat-sub-link {
  color: rgba(255,255,255,0.6);
}
[data-theme="light"] .cat-sub-link:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.08);
}
[data-theme="light"] .cat-sub-link.active {
  color: #C8A951;
}
[data-theme="light"] .sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
}

/* 浅色主题：header 深蓝背景，内部元素改为白色 */
[data-theme="light"] .site-header {
  border-bottom-color: rgba(255,255,255,0.15);
}
[data-theme="light"] .logo-title {
  color: #ffffff;
}
[data-theme="light"] .logo-sub {
  color: rgba(255,255,255,0.65);
}
[data-theme="light"] .search-box input {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.25);
  color: #ffffff;
}
[data-theme="light"] .search-box input::placeholder {
  color: rgba(255,255,255,0.5);
}
[data-theme="light"] .search-box input:focus {
  border-color: rgba(255,255,255,0.6);
}
[data-theme="light"] .filter-pill {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.8);
}
[data-theme="light"] .filter-pill:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
  color: #ffffff;
}
[data-theme="light"] .filter-pill.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #003087;
}
[data-theme="light"] .settings-btn {
  color: rgba(255,255,255,0.8);
}
[data-theme="light"] .hamburger span {
  background: #ffffff;
}

/* ==================== 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-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
}
.logo-img {
  height: 36px;
  width: 36px;
  object-fit: cover;
  border-radius: 6px;
  vertical-align: middle;
}
.logo-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 768px) { .logo-sub { display: inline; } }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 300px;
}
.search-box input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  outline: none;
  color: var(--text-primary);
  padding: 7px 12px;
  font-size: 14px;
  min-width: 0;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-muted); }
/* ==================== 筛选 Pills ==================== */
.filter-pills {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.filter-pill {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-pill:hover { border-color: var(--accent); color: var(--accent); }
.filter-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

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

/* ==================== 侧边栏 ==================== */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + var(--quick-height));
  left: 0;
  width: max-content;
  max-width: min(280px, 42vw);
  padding-inline: 10px;
  box-sizing: border-box;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  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: 10px 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s, background 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(200, 169, 81, 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 12px 7px 34px;
  white-space: nowrap;
  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, #001020, #002040);
  border: 1px solid rgba(200, 169, 81, 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, #e8f0f8, #d0e4f5); border-color: rgba(200, 169, 81, 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(200,169,81,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; }


/* 排序下拉 */
.sort-tabs {
  display: flex;
  gap: 4px;
}
.sort-select {
  padding: 2px 6px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.sort-select:focus { border-color: var(--accent); }
.pf-clear {
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: rgba(200,169,81,0.15);
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.pf-clear:hover { background: rgba(200,169,81,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-left: 3px solid rgba(200, 169, 81, 0.25);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;  /* 禁用 iOS 系统层坐标高亮，改用 .tapped DOM 锚定 */
  transition: border-color 0.2s, background 0.2s;  /* 精确属性：排除 box-shadow/transform，避免 iOS 合成层 */
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

@media (hover: hover) {
  .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.tapped {
  border-color: var(--accent);
  background: var(--bg-hover);
  /* box-shadow 移除：动态加 box-shadow 会触发 iOS 合成层提升，导致渲染偏位 */
}
.link-card:active {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.link-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.link-favicon {
  width: 32px; height: 32px;
  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-favicon[data-letter] {
  background: var(--accent);
}
.link-favicon[data-letter] img { display: none; }
.link-favicon[data-letter]::after {
  content: attr(data-letter);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.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); }

/* 需VPN 标签 */
.link-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}
.vpn-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
  pointer-events: none;
  font-weight: 500;
}
.rec-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(200,169,81,0.2);
  color: #C8A951;
  border: 1px solid rgba(200,169,81,0.4);
  pointer-events: none;
  font-weight: 600;
}
.hd-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(30,64,175,0.12);
  color: #1e40af;
  border: 1px solid rgba(30,64,175,0.3);
  pointer-events: none;
  font-weight: 600;
}
.speed-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
  font-weight: 500;
}
.speed-fast {
  background: rgba(16,185,129,0.15);
  color: #10b981;
  border: 1px solid rgba(16,185,129,0.3);
}
.speed-slow {
  background: rgba(245,158,11,0.15);
  color: #f59e0b;
  border: 1px solid rgba(245,158,11,0.3);
}


/* ==================== 搜索遮罩 ==================== */
.search-overlay {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
}
.search-results-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 90%;
  max-width: 480px;
  max-height: 70vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (max-width: 767px) {
  .search-results-panel {
    width: calc(100% - 32px);
    max-width: 360px;
  }
}
.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: 24px;
  cursor: pointer;
  padding: 8px 12px;
  margin: -8px -12px;
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.search-results-header button:hover { color: var(--text-primary); }
#searchResults {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  min-width: 0;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item > div:last-child { min-width: 0; overflow: hidden; }
.search-result-item > div:last-child span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.search-no-result { padding: 30px; text-align: center; color: var(--text-muted); }

/* ==================== 发现面板（聚焦空状态） ==================== */
.discovery-section { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.discovery-section:last-child { border-bottom: none; }
.discovery-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.discovery-clear { background: none; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 4px; transition: color 0.15s; }
.discovery-clear:hover { color: var(--text-primary); }
.history-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.history-chip { background: var(--bg-hover); border: 1px solid var(--border-light); border-radius: 20px; padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--text-secondary); transition: background 0.15s, color 0.15s, border-color 0.15s; }
.history-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.discovery-cards { display: flex; flex-wrap: nowrap; gap: 8px; overflow: hidden; }
.discovery-card { flex: 0 0 72px; min-width: 0; }
.discovery-card { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px; border-radius: 8px; text-decoration: none; color: var(--text-primary); transition: background 0.15s; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.discovery-card:hover { background: var(--bg-hover); }
.discovery-card-title { font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }


/* ==================== 底部浮动栏 ==================== */
.float-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--float-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
  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);
}

.footer-beian-link {
  margin-top: 6px;
}

.footer-beian-link a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.footer-beian-link img {
  width: 18px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.footer-beian-link span {
  line-height: 1.2;
}

/* ==================== 返回顶部 ==================== */
.back-top {
  position: fixed;
  right: 20px;
  bottom: calc(var(--float-height) + env(safe-area-inset-bottom, 0px) + 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); }

/* ==================== 设置按钮 ==================== */
.settings-wrap {
  position: relative;
  flex-shrink: 0;
}
.settings-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  width: 32px; height: 32px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}
.settings-btn:hover { border-color: var(--accent); }
.settings-panel {
  display: none;
  position: absolute;
  right: 0; top: calc(100% + 6px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 200px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.settings-panel.open { display: block; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.settings-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.settings-opts {
  display: flex;
  gap: 4px;
}
.settings-opt {
  padding: 3px 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;
}
.settings-opt:hover { color: var(--accent); border-color: var(--accent); }
.settings-opt.active { color: var(--accent); border-color: var(--accent); background: rgba(200,169,81,0.08); }

/* ==================== 汉堡按钮 ==================== */
.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; } }

/* ==================== 移动端：搜索独立一行 ==================== */
@media (max-width: 767px) {
  :root { --header-height: 100px; }
  .site-header { height: auto; }
  .header-inner {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 10px;
    row-gap: 0;
    position: relative;
  }
  .logo {
    flex: 1;
    justify-content: center;
  }
  .logo-title { font-size: 22px; }
  .search-box {
    order: 10;
    flex-basis: 100%;
    max-width: none;
    margin-bottom: 4px;
    gap: 6px;
  }
  .search-box input { font-size: 16px; }
  .filter-pills {
    order: 11;
    flex-basis: 100%;
    margin-bottom: 8px;
  }

}

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

/* ==================== 收藏按钮 ==================== */
.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;  /* 仅 color：排除 transform，避免 iOS 合成层延迟重绘 */
}
@media (hover: hover) {
  /* 桌面才启用 scale hover：iOS 粘性 hover 会保留 transform → 合成层 → 重绘延迟 */
  .fav-btn:hover { color: #C8A951; transform: scale(1.2); transition: color 0.15s, transform 0.15s; }
}
.fav-btn.active { color: #C8A951; }
/* 收藏入口固定金色：浅色主题 --accent 与侧栏背景同为 #003087，Safari 下会「蓝字蓝底」看不见 */
.fav-nav { border-bottom: 1px solid rgba(200, 169, 81, 0.45) !important; }
.fav-nav-link { color: #C8A951 !important; }
[data-theme="light"] .fav-nav-link {
  color: #e8c96a !important;
}
[data-theme="light"] .fav-nav-link:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.1);
}
.fav-nav-label {
  flex: 1;
  min-width: 0;
}
.fav-nav-count {
  margin-left: auto;
  flex-shrink: 0;
  min-width: 1.35rem;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #1a1408;
  background: linear-gradient(180deg, #e8c96a 0%, #c8a951 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}
[data-theme="light"] .fav-nav-count {
  color: #003087;
  background: #ffffff;
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .fav-nav-link:hover .fav-nav-count {
  color: #001428;
  background: #e8c96a;
  border-color: rgba(255, 255, 255, 0.7);
}

/* 收藏区紧凑卡片 */
.fav-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
}
.fav-link-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;  /* 禁用 iOS 系统层坐标高亮，改用 .tapped DOM 锚定 */
  transition: border-color 0.2s, background 0.2s;  /* 精确属性：排除 box-shadow/transform，避免 iOS 合成层 */
  position: relative;
  overflow: hidden;
  text-decoration: none;
}
@media (hover: hover) {
  .fav-link-item:hover { border-color: var(--accent); background: var(--bg-hover); }
}
.fav-link-item.tapped { border-color: var(--accent); background: var(--bg-hover); }
.fav-favicon { width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0; }
.fav-link-item .link-title { font-size: 13px; flex: 1; min-width: 0; }
.fav-link-item .fav-btn { font-size: 12px; padding: 0; line-height: 1; flex-shrink: 0; }

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

/* ==================== 响应式 ==================== */
@media (min-width: 769px) {
  .fav-nav-label { flex: 0 1 auto; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar {
    transform: translateX(-100%);
    width: max-content;
    min-width: 120px;
    max-width: min(260px, 78vw);
    padding-inline: 10px;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* 触摸设备：放大所有可点击元素的触摸区域（手指操作，44pt 最小目标） */
@media (hover: none) {
  .fav-btn { padding: 8px 10px; font-size: 16px; }
  .fav-link-item .fav-btn { padding: 6px 8px; font-size: 14px; }
  .fav-link-item { padding: 8px 10px; }
  .cat-main-link, .cat-sub-link { min-height: 44px; display: flex; align-items: center; }
  .sort-select { min-height: 44px; }
}
