/* ===== 主题变量 ===== */
:root {
  --bg: #f5f6f8;
  --bg-soft: #ffffff;
  --bg-hover: #eef0f4;
  --text: #1c1e21;
  --text-2: #5f6570;
  --text-3: #9aa0a8;
  --border: #e4e6eb;
  --accent: #3a6df0;
  --accent-soft: rgba(58, 109, 240, 0.1);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}
[data-theme='dark'] {
  --bg: #121417;
  --bg-soft: #1c1f24;
  --bg-hover: #262a31;
  --text: #e8eaed;
  --text-2: #a8b0ba;
  --text-3: #6b727c;
  --border: #2e333a;
  --accent: #6f93ff;
  --accent-soft: rgba(111, 147, 255, 0.14);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* ===== 基础 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme='dark'] { color-scheme: dark; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* 键盘焦点统一可见（搜索框自带焦点环，见 #search:focus） */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ===== 顶部栏 ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.site-header .wrap { display: block; }
.header-main {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.brand svg { width: 22px; height: 22px; fill: var(--accent); }

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--text-3);
  stroke-width: 2;
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 9px 90px 9px 36px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#search::placeholder { color: var(--text-3); }
.kbd-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  pointer-events: none;
  background: var(--bg);
}

/* ===== 地区切换（全部 / 国内 / 国外） ===== */
.region-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.region-btn {
  padding: 5px 12px;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  border-radius: 999px;
  color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
.region-btn:hover { background: var(--bg-hover); }
.region-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ===== 主题切换（亮 / 暗 / 水墨） ===== */
.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.theme-btn {
  padding: 5px 10px;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  border-radius: 999px;
  color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
.theme-btn:hover { background: var(--bg-hover); }
.theme-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ===== 分类快捷导航（单行横滑，不换行） ===== */
.quicknav { margin-top: 10px; }
.quicknav-track {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.quicknav-track::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--text-2);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.pill:hover { background: var(--bg-hover); color: var(--text); }
.pill .pill-count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pill.is-active .pill-count { color: rgba(255, 255, 255, 0.82); }

/* ===== 区块 ===== */
main { padding: 8px 0 64px; }
.page-meta {
  padding-top: 16px;
  font-size: 12.5px;
  color: var(--text-3);
}
.page-meta strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.section { margin-top: 30px; scroll-margin-top: var(--scroll-offset, 116px); }
.section-head { display: flex; align-items: center; margin-bottom: 14px; }
.section-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-align: left;
}
.section-toggle::before {
  content: '';
  flex: 0 0 auto;
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--accent);
}
.section-toggle:disabled { cursor: default; }
.section-toggle .chevron {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--text-3);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}
.section-toggle[aria-expanded='false'] .chevron { transform: rotate(-90deg); }
.section-toggle[aria-expanded='false'] .section-name { color: var(--text-2); }
.cat-section.is-collapsed .section-head { margin-bottom: 4px; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}
.section-title::before {
  content: '';
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--accent);
  align-self: center;
}
.section-count { font-size: 12px; font-weight: 400; color: var(--text-3); }

/* 收藏 / 最近访问：弱化层级，不与分类标题抢视觉 */
.section-aux { margin-top: 24px; }
.section-aux .section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}
.section-aux .section-title::before { display: none; }
.section-aux .section-count { font-size: 12px; }

/* 分类内的「国内 / 国外」子小节 */
.subsection + .subsection { margin-top: 16px; }
.subsection-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-2);
}
.subsection-dot { color: var(--text-3); font-weight: 400; }
.subsection-count { font-size: 12px; font-weight: 400; color: var(--text-3); }
.section-clear {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-3);
  padding: 2px 8px;
  border-radius: 6px;
}
.section-clear:hover { color: var(--accent); background: var(--accent-soft); }

/* ===== 卡片网格 ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}
/* 图标槽位：无底托、无边框，图标裸置于卡片上 */
.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: transparent;
  border: 0;
}
/* 首字母兜底时才显示彩色圆角色块 */
.avatar.is-fallback { border-radius: 8px; }
/* 品牌字标方块：SVG data URI 整图填充，圆角由容器裁剪，与首字母兜底一致 */
.avatar.is-wordmark { overflow: hidden; border-radius: 8px; }
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
/* 深色 Logo 仅在暗色主题反转，逐条由 links.js 的 invertOnDark 控制 */
[data-theme='dark'] .avatar-img.is-invert { filter: invert(1); }
/* 8 色哈希调色板（避免内联样式，兼容严格 CSP） */
.c0 { background: #3a6df0; } .c1 { background: #e05d5d; }
.c2 { background: #2ea97c; } .c3 { background: #d97b29; }
.c4 { background: #7c5cd6; } .c5 { background: #2a9db8; }
.c6 { background: #c94f8b; } .c7 { background: #5f7d3a; }

.card-body { min-width: 0; flex: 1; }
.card-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-desc {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fav-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.card:hover .fav-btn, .fav-btn.is-fav, .fav-btn:focus-visible { opacity: 1; }
.fav-btn:hover { background: var(--bg-hover); }
.fav-btn svg { width: 15px; height: 15px; fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linejoin: round; }
.fav-btn.is-fav svg { fill: #f4b400; stroke: #f4b400; }

/* ===== 空结果 ===== */
.empty {
  display: none;
  text-align: center;
  padding: 70px 0;
  color: var(--text-3);
}
.empty.is-visible { display: block; }
.empty .empty-title { font-size: 16px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }

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

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .header-main { gap: 8px 10px; }
  .brand span { display: none; }        /* 手机只留图标，空间让给搜索 */
  .search-box { order: 2; min-width: 130px; }
  .theme-switch { order: 3; }
  .theme-btn { padding: 4px 8px; font-size: 12px; }
  .region-switch { order: 4; flex: 1 0 100%; justify-content: center; }
  .quicknav { margin-top: 8px; }
  .pill { padding: 4px 9px; font-size: 12px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 12px 10px; gap: 10px; }
  .card-desc { display: none; }          /* 小屏精简展示，方便单手点按 */
  .kbd-hint { display: none; }
  .avatar { width: 28px; height: 28px; font-size: 14px; }
  .section { margin-top: 26px; }
  .section-toggle { font-size: 15px; gap: 8px; }
  .subsection-title { font-size: 12px; margin-bottom: 8px; }
  .region-btn { padding: 4px 10px; font-size: 12px; }
}
@media (max-width: 340px) {
  .grid { grid-template-columns: 1fr; }
}

/* ===== 水墨主题：宣纸底 / 墨线 / 单一朱砂 ===== */
[data-theme='ink'] {
  --bg: #f7f4ea;
  --bg-soft: #fbf9f1;
  --bg-hover: #efe9db;
  --text: #1f1d1b;
  --text-2: #47433c;
  --text-3: #6b655c;
  --border: #d5cdbb;
  --accent: #1f1d1b;                        /* 默认点缀回归墨色，避免整页着色 */
  --accent-soft: rgba(31, 29, 27, 0.07);
  --shadow: none;
  --shadow-hover: none;
  --radius: 0;
  --cinnabar: #a33b2e;                      /* 朱砂：只用于当前分类与收藏星标 */
}

/* 宣纸：淡墨洇染 + 极细帘纹。纯 CSS，body 背景铺在视口画布上，滚动不重绘 */
[data-theme='ink'] body {
  background-color: var(--bg);
  background-image:
    radial-gradient(58% 42% at 16% 0%, rgba(31, 29, 27, 0.05), rgba(31, 29, 27, 0) 72%),
    radial-gradient(46% 38% at 86% 4%, rgba(31, 29, 27, 0.03), rgba(31, 29, 27, 0) 74%),
    radial-gradient(72% 46% at 50% 100%, rgba(31, 29, 27, 0.028), rgba(31, 29, 27, 0) 76%),
    repeating-linear-gradient(0deg, rgba(31, 29, 27, 0.012) 0 1px, rgba(31, 29, 27, 0) 1px 4px);
}

/* 标题走中文衬线，正文保持无衬线（不引入任何外来字体） */
[data-theme='ink'] .brand,
[data-theme='ink'] .section-toggle,
[data-theme='ink'] .section-title,
[data-theme='ink'] .subsection-title {
  font-family: 'Songti SC', 'STSong', 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif;
}
[data-theme='ink'] .brand { font-weight: 600; letter-spacing: 0.14em; }
[data-theme='ink'] .section-toggle,
[data-theme='ink'] .section-title { font-weight: 600; letter-spacing: 0.06em; }

/* 「国内 / 国外」：小号题签感 —— 只调字号与字距，不伪造字形 */
[data-theme='ink'] .subsection-title {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: var(--text-3);
}
[data-theme='ink'] .subsection-count { font-size: 11px; letter-spacing: 0.06em; }

/* 分类标记：4px 色条 → 2px 墨线 */
[data-theme='ink'] .section-toggle::before {
  width: 2px;
  height: 18px;
  border-radius: 0;
  background: var(--text);
  opacity: 0.7;
}

/* 顶栏收边 */
[data-theme='ink'] .site-header { border-bottom-color: rgba(31, 29, 27, 0.22); }

/* 卡片：细墨线 + 留白；悬停只做墨晕加深，不抬升、不投影 */
[data-theme='ink'] .card {
  border-color: rgba(31, 29, 27, 0.18);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
[data-theme='ink'] .card:hover {
  transform: none;
  box-shadow: none;
  border-color: rgba(31, 29, 27, 0.5);
  background: rgba(31, 29, 27, 0.035);
}

/* 当前分类：全站唯一的大块朱砂 */
[data-theme='ink'] .pill.is-active {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: #fbf9f1;
}
[data-theme='ink'] .pill.is-active .pill-count { color: rgba(251, 249, 241, 0.82); }

/* 收藏星标：唯一的小点朱砂 */
[data-theme='ink'] .fav-btn.is-fav svg { fill: var(--cinnabar); stroke: var(--cinnabar); }

/* 焦点环保持可见，改用墨色；搜索框不做发光晕 */
[data-theme='ink'] :focus-visible { border-radius: 0; }
[data-theme='ink'] #search:focus {
  border-color: var(--text);
  box-shadow: none;
  outline: 1px solid rgba(31, 29, 27, 0.45);
  outline-offset: 2px;
}

/* 去圆角：控件一律直边纸片 */
[data-theme='ink'] #search,
[data-theme='ink'] .region-switch,
[data-theme='ink'] .theme-switch,
[data-theme='ink'] .region-btn,
[data-theme='ink'] .theme-btn,
[data-theme='ink'] .pill,
[data-theme='ink'] .kbd-hint,
[data-theme='ink'] .fav-btn,
[data-theme='ink'] .section-clear,
[data-theme='ink'] .avatar.is-fallback,
[data-theme='ink'] .avatar.is-wordmark { border-radius: 0; }

/* 首字母兜底收敛为墨块，避免彩色块破坏纸墨关系 */
[data-theme='ink'] .avatar.is-fallback { background: rgba(31, 29, 27, 0.82); }

/* 水墨下品牌字标方块不刺眼：降饱和 + 轻微压暗，保留品牌色相但融入宣纸 */
[data-theme='ink'] .avatar.is-wordmark .avatar-img { filter: saturate(0.35) brightness(0.92); }

/* 水墨是浅纸底，深色 Logo 本就可见：明确不反色 */
[data-theme='ink'] .avatar-img.is-invert { filter: none; }
