/* ============================================================================
   导航站样式表
   目录：1.主题变量  2.基础重置  3.布局  4.头部  5.搜索  6.分类导航
        7.卡片网格  8.空状态/页脚  9.回到顶部  10.响应式  11.动效偏好
   ========================================================================== */

/* ---------------------------- 1. 主题变量 ---------------------------- */
:root {
  --bg:            #f5f6f8;
  --bg-sunken:     #eceef2;
  --surface:       #ffffff;
  --border:        #e6e8ee;
  --border-strong: #d3d8e2;

  --text:          #15171c;
  --text-muted:    #6a7280;
  --text-faint:    #9aa1ad;

  --accent:        #4f46e5;
  --accent-soft:   #eef0fe;
  --accent-text:   #4338ca;
  --star:          #f59e0b;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 8px 22px -8px rgba(16, 24, 40, .16);
  --shadow-lg: 0 20px 48px -20px rgba(16, 24, 40, .28);

  --radius:    14px;
  --radius-sm: 10px;

  --container: 1180px;
  --header-h:  104px;   /* 由 JS 动态校正，用于锚点滚动偏移 */
}

[data-theme="dark"] {
  --bg:            #0d0f13;
  --bg-sunken:     #08090b;
  --surface:       #16191f;
  --border:        #24282f;
  --border-strong: #333944;

  --text:          #e9ebef;
  --text-muted:    #9aa3b2;
  --text-faint:    #6b7482;

  --accent:        #7c83ff;
  --accent-soft:   #1e2033;
  --accent-text:   #a5aaff;
  --star:          #fbbf24;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 22px -8px rgba(0, 0, 0, .6);
  --shadow-lg: 0 20px 48px -20px rgba(0, 0, 0, .75);
}

/* ---------------------------- 2. 基础重置 ---------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .2s ease, color .2s ease;
}

/* 顶部一层柔和的光晕，提升质感 */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 380px;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(60% 100% at 50% 0%, var(--accent-soft), transparent 72%);
  opacity: .85;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }
mark {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 3px;
  padding: 0 1px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------------------- 3. 布局 ---------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: 20px;
}

.main {
  position: relative;
  z-index: 1;
  flex: 1;
  padding-block: 26px 48px;
}

/* ---------------------------- 4. 头部 ---------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s ease, background-color .2s ease;
}

@supports (backdrop-filter: blur(1px)) {
  .site-header {
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
  }
}

.site-header.is-stuck { border-bottom-color: var(--border); }

.header-inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding-block: 12px;
}

/* 品牌区 */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-size: 20px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 图标按钮 */
.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, color .18s ease;
}
.icon-btn:hover { border-color: var(--border-strong); transform: translateY(-1px); color: var(--accent); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .icon-sun,
.icon-btn .icon-moon { position: absolute; transition: opacity .2s ease, transform .3s ease; }
[data-theme="light"] .icon-btn .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(.6); }
[data-theme="light"] .icon-btn .icon-moon { opacity: 1; transform: none; }
[data-theme="dark"]  .icon-btn .icon-moon { opacity: 0; transform: rotate(90deg) scale(.6); }
[data-theme="dark"]  .icon-btn .icon-sun  { opacity: 1; transform: none; }

/* ---------------------------- 5. 搜索 ---------------------------- */
.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding-inline: 13px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon { width: 18px; height: 18px; flex: 0 0 auto; color: var(--text-faint); }
.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input::-webkit-search-cancel-button { display: none; }

.search-kbd {
  flex: 0 0 auto;
  padding: 1px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.search:focus-within .search-kbd { display: none; }

.search-clear {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.search-clear:hover { background: var(--bg-sunken); color: var(--text); }
.search-clear svg { width: 14px; height: 14px; }

/* ---------------------------- 6. 分类导航 ---------------------------- */
.cat-nav { padding-bottom: 10px; }

.cat-nav-inner {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.cat-nav-inner::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}
.chip:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.chip.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
  font-weight: 600;
}

/* ---------------------------- 7. 卡片网格 ---------------------------- */
.section {
  margin-bottom: 32px;
  scroll-margin-top: calc(var(--header-h) + 14px);
}
.section:last-child { margin-bottom: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 13px;
  padding-inline: 2px;
}
.section-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.section-title .section-emoji { margin-right: 7px; }
.section-count {
  font-size: 12.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 12px;
}

/* 单个卡片 */
.card {
  position: relative;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.card:has(.card-link:focus-visible) { border-color: var(--accent); }

.card-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  min-height: 66px;
  border-radius: inherit;
}

/* 图标容器：首字母兜底层与图标层叠在同一个网格单元里 */
.card-icon {
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-icon img {
  grid-area: 1 / 1;
  position: relative;
  z-index: 1;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

/* 图标抓取失败时的首字母兜底 */
.card-icon-letter {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  background: hsl(var(--h, 220) 62% 93%);
  color: hsl(var(--h, 220) 55% 38%);
}
[data-theme="dark"] .card-icon-letter {
  background: hsl(var(--h, 220) 34% 22%);
  color: hsl(var(--h, 220) 72% 76%);
}
/* 图标已加载：只隐藏字母本身，保留底色，避免透底图标与字母重叠 */
.card-icon.has-icon .card-icon-letter { color: transparent; }

/* 右侧留出收藏按钮的位置，长名称会被省略号截断而不是压到星星上 */
.card-body { flex: 1; min-width: 0; padding-right: 18px; }
.card-name {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-desc {
  display: block;
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 0 6px;
  font-size: 11px;
  line-height: 16px;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}

/* 收藏按钮 */
.card-star {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease, color .15s ease, background-color .15s ease, transform .15s ease;
}
.card:hover .card-star { opacity: 1; }
.card-star:hover { background: var(--bg); color: var(--star); transform: scale(1.12); }
.card-star.is-active { opacity: 1; color: var(--star); }

/* 触屏设备没有 hover，收藏按钮常驻显示 */
@media (hover: none) {
  .card-star { opacity: .55; }
  .card-star.is-active { opacity: 1; }
}

/* 搜索时隐藏的元素 */
.is-hidden { display: none !important; }

/* ---------------------------- 8. 空状态 / 页脚 ---------------------------- */
.empty {
  padding: 72px 20px;
  text-align: center;
}
.empty-icon { font-size: 40px; line-height: 1; }
.empty-title {
  margin-top: 14px;
  font-size: 16px;
  font-weight: 600;
}
.empty-hint {
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--text-muted);
}
.empty-hint a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--border);
  padding-block: 22px;
}
.footer-inner {
  font-size: 12.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------------------- 9. 回到顶部 ---------------------------- */
.to-top {
  position: fixed;
  right: 20px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(.9);
  transition: opacity .22s ease, transform .22s ease, color .18s ease, border-color .18s ease;
}
.to-top.is-visible { opacity: 1; pointer-events: auto; transform: none; }
.to-top:hover { color: var(--accent); border-color: var(--border-strong); }
.to-top svg { width: 19px; height: 19px; }

/* ---------------------------- 10. 响应式 ---------------------------- */
/* 平板 */
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(206px, 1fr)); }
}

/* 手机：头部改为两行（品牌 + 主题按钮 / 搜索独占一行） */
@media (max-width: 720px) {
  .container { padding-inline: 14px; }

  .header-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding-block: 10px;
  }
  .search {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 40px;
  }
  .brand-subtitle { display: none; }

  .cat-nav-inner { padding-inline: 14px; }

  .main { padding-block: 18px 40px; }
  .section { margin-bottom: 26px; }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 9px;
  }
  .card-link { gap: 10px; padding: 11px; min-height: 60px; }
  .card-icon { width: 32px; height: 32px; border-radius: 9px; }
  .card-icon img { width: 18px; height: 18px; }
  .card-name { font-size: 13.5px; }
  .card-desc { font-size: 11.5px; }
  .card-body { padding-right: 16px; }

  .to-top { right: 14px; }
}

/* ---------------------------- 11. 动效偏好 ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
