/* ==================== 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"] .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 16px;
  gap: 12px;
}
.logo {
  --logo-title-size: 18px;
  --logo-sub-size: 11px;
  --logo-text-gap: 2px;
  --logo-text-block-h: calc(
    var(--logo-title-size) * 1.25 +
    var(--logo-sub-size) * 1.2 +
    var(--logo-text-gap)
  );
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  min-width: 0;
}
.logo-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--logo-text-gap);
  min-width: 0;
  min-height: var(--logo-text-block-h);
}
.logo-title {
  font-size: var(--logo-title-size);
  line-height: 1.25;
  font-weight: 700;
  color: var(--accent);
}
.logo-img {
  width: var(--logo-text-block-h);
  height: var(--logo-text-block-h);
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.logo-sub {
  font-size: var(--logo-sub-size);
  line-height: 1.2;
  color: var(--text-muted);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.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); }
/* ==================== 布局 ==================== */
.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 20px;
  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: 12px;
  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); }

/* 热点轮播（管理预览，正式站 M2 前仅壳层） */
.hot-carousel-banner {
  cursor: default;
  display: block;
  background: transparent;
  border: none;
  padding: 0;
  margin-bottom: 16px;
  min-height: 0;
  height: var(--hot-strip-h);
  max-height: var(--hot-strip-h);
  overflow: hidden;
  box-sizing: border-box;
  --hot-base-h: 72px;
  --hot-height-scale: 1;
  --hot-strip-h: calc(var(--hot-base-h) * var(--hot-height-scale));
  --hot-poster-aspect: 3;
  --hot-poster-w: calc(var(--hot-strip-h) * var(--hot-poster-aspect));
  --hot-gap: calc(6px * var(--hot-ui-scale) * var(--hot-height-scale));
  --hot-ui-scale: clamp(0.72, calc(0.84 + var(--hot-height-scale) * 0.16), 1);
  --hot-text-scale: max(0.72, var(--hot-height-scale));
}
.hot-carousel-slides {
  width: 100%;
  height: var(--hot-strip-h);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  cursor: grab;
}
.hot-carousel-slides:active {
  cursor: grabbing;
}
.hot-carousel-track {
  display: flex;
  align-items: stretch;
  gap: var(--hot-gap);
  width: max-content;
  height: var(--hot-strip-h);
  box-sizing: border-box;
  will-change: transform;
}
.hot-carousel-slide {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  position: relative;
  width: var(--hot-poster-w);
  max-width: var(--hot-poster-w);
  min-width: 0;
  height: var(--hot-strip-h);
  max-height: var(--hot-strip-h);
  border: none;
  background: linear-gradient(135deg, #001020, #002040);
  border: 1px solid rgba(200, 169, 81, 0.28);
  border-radius: var(--radius);
  cursor: grab;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  box-sizing: border-box;
  overflow: hidden;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
  user-drag: none;
}
.hot-carousel-page {
  display: none;
}
.hot-carousel-poster-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  z-index: 0;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.hot-carousel-slide.hot-carousel-poster-ready .hot-carousel-poster-img {
  opacity: 1;
}
[data-theme="light"] .hot-carousel-slide:not(.has-poster) {
  background: linear-gradient(135deg, #e8f0f8, #d0e4f5);
  border-color: rgba(0, 48, 135, 0.15);
}
.hot-carousel-slide.has-poster {
  position: relative;
  padding: 0;
  overflow: hidden;
  background-color: #001020;
  border-color: rgba(200, 169, 81, 0.35);
}

.hot-carousel-badges {
  position: absolute;
  left: calc(6px * var(--hot-ui-scale) * var(--hot-height-scale));
  bottom: calc(5px * var(--hot-ui-scale) * var(--hot-height-scale));
  top: auto;
  right: auto;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(4px * var(--hot-ui-scale) * var(--hot-height-scale));
  max-width: calc(100% - 12px);
  pointer-events: none;
}
.hot-carousel-host-badge,
.hot-carousel-vpn-badge {
  flex: 0 1 auto;
  font-size: calc(10px * var(--hot-ui-scale) * var(--hot-text-scale));
  font-weight: 700;
  line-height: 1;
  padding: calc(2px * var(--hot-ui-scale) * var(--hot-height-scale)) calc(6px * var(--hot-ui-scale) * var(--hot-height-scale));
  border-radius: calc(3px * var(--hot-ui-scale) * var(--hot-height-scale));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.hot-carousel-host-badge {
  display: inline-flex;
  align-items: center;
  gap: calc(4px * var(--hot-ui-scale) * var(--hot-height-scale));
  color: #f5f5f5;
  background: rgba(0, 8, 22, 0.72);
}
.hot-carousel-host-icon {
  height: 1em;
  width: 1em;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: calc(2px * var(--hot-ui-scale) * var(--hot-height-scale));
  background: rgba(255, 255, 255, 0.12);
}
.hot-carousel-host-icon[hidden] { display: none !important; }
.hot-carousel-host-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.hot-carousel-vpn-badge {
  color: #fff;
  background: rgba(220, 38, 38, 0.92);
}
.hot-carousel-host-badge[hidden],
.hot-carousel-vpn-badge[hidden] { display: none !important; }
[data-theme="light"] .hot-carousel-host-badge {
  color: #0a1628;
  background: rgba(255, 255, 255, 0.88);
}
[data-theme="light"] .hot-carousel-host-icon {
  background: rgba(0, 0, 0, 0.06);
}

.hot-carousel-caption {
  position: absolute;
  left: calc(6px * var(--hot-ui-scale) * var(--hot-height-scale));
  bottom: calc(5px * var(--hot-ui-scale) * var(--hot-height-scale));
  z-index: 2;
  max-width: calc(100% - 12px);
  padding: calc(2px * var(--hot-ui-scale) * var(--hot-height-scale)) calc(6px * var(--hot-ui-scale) * var(--hot-height-scale));
  border-radius: calc(3px * var(--hot-ui-scale) * var(--hot-height-scale));
  font-size: calc(10px * var(--hot-ui-scale) * var(--hot-text-scale));
  font-weight: 600;
  line-height: 1.2;
  color: #f5f5f5;
  background: rgba(0, 8, 22, 0.72);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  box-sizing: border-box;
}
/* 有海报时成图已含标题，关掉 DOM 叠字；无海报仍显示 caption */
.hot-carousel-slide.has-poster .hot-carousel-caption {
  display: none !important;
}
[data-theme="light"] .hot-carousel-caption {
  color: #0a1628;
  background: rgba(255, 255, 255, 0.82);
}
[data-theme="light"] .hot-carousel-slide:not(.has-poster) .hot-carousel-caption {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.92);
}
.hot-carousel-slide:not(.has-poster) .hot-carousel-caption {
  color: #f5f5f5;
  background: rgba(0, 16, 32, 0.78);
}
.hot-carousel-slide-inner,
.hot-carousel-slide-inner .promo-tag,
.hot-carousel-title,
.hot-carousel-go {
  display: none;
}

/* 主分类区块 */
.cat-section { margin-bottom: 16px; }
.cat-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  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: 12px; }
.subcat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.subcat-tab-wrap {
  margin-bottom: 12px;
}
.subcat-tab-nav {
  margin-bottom: 6px;
  color: inherit;
}
.subcat-tab-items {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 4px;
  min-width: 0;
}
.subcat-tab-nav .subcat-tab {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  opacity: 0.72;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.25;
  text-decoration: none;
  transition: color 0.15s, opacity 0.15s;
}
.subcat-tab-nav .subcat-tab:hover {
  color: var(--accent);
  opacity: 0.9;
}
.subcat-tab-nav .subcat-tab.active,
.subcat-tab-nav .subcat-tab[aria-selected="true"] {
  color: var(--accent);
  opacity: 1;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.subcat-tab-sep {
  display: inline-block;
  margin: 0 12px;
  color: var(--accent);
  opacity: 0.55;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}
.subcat-tab-panel { margin: 0; padding: 0; }
.subcat-tab-panel.hidden { display: none; }
.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(148px, 1fr));
  gap: 6px;
}

/* 链接卡片 */
.link-card {
  --card-title-size: 14px;
  --card-row-h: calc(var(--card-title-size) * 1.25);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid rgba(200, 169, 81, 0.25);
  border-radius: var(--radius);
  padding: 6px 8px;
  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: row;
  align-items: center;
  gap: 4px;
  position: relative;
}
.link-card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@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: 4px;
}
.link-favicon {
  width: var(--card-row-h);
  height: var(--card-row-h);
  border-radius: 4px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--card-title-size);
  flex-shrink: 0;
  overflow: hidden;
}
.link-favicon img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 4px;
}
.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: 10px;
  font-weight: 700;
}
.link-title {
  font-size: var(--card-title-size);
  line-height: 1.25;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-card-tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 3px;
  overflow: hidden;
  align-items: center;
  max-height: var(--card-row-h);
}
.link-card .fav-btn {
  margin-left: 0;
  align-self: center;
}
.link-card-tags .platform-tag,
.link-card-tags .vpn-badge,
.link-card-tags .rec-badge,
.link-card-tags .hd-badge,
.link-card-tags .speed-badge {
  flex-shrink: 0;
  font-size: 10px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 500;
  box-sizing: border-box;
  max-height: var(--card-row-h);
  display: inline-flex;
  align-items: center;
}
.platform-tag {
  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 / 荐 / 高清 / 速度） */
.vpn-badge {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
  pointer-events: none;
}
.rec-badge {
  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 {
  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 {
  pointer-events: none;
}
.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;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px 0;
  box-sizing: border-box;
}
.search-overlay-top {
  width: 100%;
  max-width: 480px;
  flex-shrink: 0;
}
.search-overlay-top:empty { display: none; }
.search-box--overlay {
  max-width: none;
  width: 100%;
  margin: 0 0 8px;
  touch-action: manipulation;
}
.search-box--overlay input {
  font-size: 16px;
  padding: 8px 12px;
}
.search-results-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 90%;
  max-width: 480px;
  max-height: min(70vh, calc(100% - 56px));
  overflow-y: auto;
  overscroll-behavior: contain;
  flex-shrink: 1;
  min-height: 0;
  touch-action: pan-y;
}
@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); }
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.header-icon-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;
  padding: 0;
  color: var(--text-secondary);
}
.header-icon-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.search-open-btn { display: none; }
.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) {
  .site-header { height: auto; }
  .header-inner {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    grid-template-areas: "menu logo actions";
    align-items: center;
    padding: max(6px, env(safe-area-inset-top)) 10px 8px;
    gap: 6px;
  }
  .hamburger { grid-area: menu; align-self: center; }
  .logo {
    grid-area: logo;
    justify-self: center;
    justify-content: center;
    --logo-title-size: 17px;
  }
  .header-actions {
    grid-area: actions;
    justify-self: end;
    align-self: center;
  }
  .search-open-btn { display: flex; }
  .header-inner > .search-box { display: none; }
  .settings-wrap { grid-area: unset; justify-self: unset; align-self: unset; }
}

/* ==================== 侧边栏遮罩 ==================== */
.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;
  appearance: none;
  -webkit-appearance: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;  /* 仅 color：排除 transform，避免 iOS 合成层延迟重绘 */
}
.fav-icon {
  width: 1em;
  height: 1em;
  display: block;
  pointer-events: none;
}
@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;
    padding: 10px;
    transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  /* 菜单打开：右侧内容区横向挤压，半透明遮罩不变，切换分类时仍可见内容 */
  html.sidebar-open .content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    flex: none;
    box-sizing: border-box;
  }
  html.sidebar-open .links-grid {
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  }
  html.sidebar-open .link-card {
    gap: 0;
    padding-right: 0;
  }
  html.sidebar-open .link-card-main {
    min-width: 0;
  }
  html.sidebar-open .link-title {
    flex: 1 1 auto;
    min-width: 0;
  }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* 触摸设备：放大所有可点击元素的触摸区域（手指操作，44pt 最小目标） */
@media (hover: none) {
  .link-card {
    --card-title-size: 13px;
    --card-row-h: calc(var(--card-title-size) * 1.25);
    padding: 5px 2px 5px 6px;
    gap: 2px;
  }
  .link-card-top { gap: 4px; }
  .link-card-main { gap: 2px; }
  .link-card-tags { gap: 2px; }
  .link-card-tags .platform-tag,
  .link-card-tags .vpn-badge,
  .link-card-tags .rec-badge,
  .link-card-tags .hd-badge,
  .link-card-tags .speed-badge {
    font-size: 9px;
    padding: 0 3px;
    max-height: var(--card-row-h);
  }
  .fav-btn { padding: 8px 10px; font-size: 16px; }
  .link-card .fav-btn {
    position: relative;
    z-index: 1;
    width: 18px;
    height: 18px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    font-size: 15px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  /* 视觉 18px，点击区 36×36，不撑高卡片 */
  .link-card .fav-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%);
  }
  .fav-link-item .fav-btn {
    position: relative;
    min-width: 0;
    min-height: 0;
    width: 18px;
    height: 18px;
    padding: 0;
    font-size: 14px;
  }
  .fav-link-item .fav-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%);
  }
  .fav-link-item { padding: 6px 8px; }
  .cat-main-link, .cat-sub-link { min-height: 44px; display: flex; align-items: center; }
  .sort-select { min-height: 44px; }
}

/* 供搜索引擎索引的静态摘要（视觉隐藏，不影响主 UI） */
.seo-static {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cat-loading {
  padding: 24px 8px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}
