/* ============================================================
   航迹集 · 个人导航
   设计方向：「纸墨 · 编辑部」— 暖纸 / 深墨双主题 + 朱砂点缀
   ============================================================ */

/* ---------- 1. 主题变量 ---------- */
:root {
  --paper:        #f6f2ea;
  --surface:      #fdfbf6;
  --surface-2:    #f0e9dc;
  --ink:          #211c15;
  --ink-soft:     #6f6557;
  --ink-faint:    #a2988a;
  --hairline:     #e3dac8;
  --hairline-2:   #d4c9b2;
  --accent:       #b8442c;   /* 朱砂 */
  --accent-deep:  #8f2f1c;
  --accent-soft:  rgba(184, 68, 44, .09);
  --shadow-sm:    0 1px 2px rgba(48, 38, 24, .06), 0 2px 8px rgba(48, 38, 24, .05);
  --shadow-lg:    0 4px 10px rgba(48, 38, 24, .08), 0 14px 34px rgba(48, 38, 24, .12);
  --radius:       12px;
  --header-h:     64px;
  color-scheme: light;
}

[data-theme="dark"] {
  --paper:        #171310;
  --surface:      #201a15;
  --surface-2:    #2a221b;
  --ink:          #ede4d5;
  --ink-soft:     #b0a494;
  --ink-faint:    #7d7263;
  --hairline:     #322a21;
  --hairline-2:   #443a2e;
  --accent:       #e07a55;
  --accent-deep:  #f0936f;
  --accent-soft:  rgba(224, 122, 85, .12);
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, .4), 0 2px 8px rgba(0, 0, 0, .3);
  --shadow-lg:    0 4px 10px rgba(0, 0, 0, .45), 0 14px 34px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

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

html, body { overflow-x: clip; }   /* 兜底：任何固定 UI 不允许撑出屏幕 */

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background:
    radial-gradient(1100px 480px at 78% -12%, var(--accent-soft), transparent 62%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E"),
    var(--paper);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: "Noto Serif SC", "Fraunces", serif; margin: 0; }

a { color: inherit; text-decoration: none; }

::selection { background: var(--accent); color: #fff8f2; }

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

.shell {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: clamp(16px, 4vw, 32px);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ---------- 3. 顶部 Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}

.header-inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.5vw, 28px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.seal {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff8f2;
  font-family: "Noto Serif SC", serif;
  font-size: 21px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1.5px rgba(255, 248, 242, .35), var(--shadow-sm);
  transform: rotate(-4deg);
  transition: transform .3s ease;
}

.brand:hover .seal { transform: rotate(3deg) scale(1.05); }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }

.brand-name {
  font-family: "Noto Serif SC", serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .06em;
}

.brand-sub {
  font-size: 10.5px;
  letter-spacing: .22em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
  min-width: 0;           /* 防止溢出 */
  margin-inline: auto;
}

.search-icon {
  position: absolute;
  left: 13px; top: 50%;
  width: 16px; height: 16px;
  translate: 0 -50%;
  color: var(--ink-faint);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 38px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  transition: border-color .25s ease, box-shadow .25s ease;
}

#search-input::placeholder { color: var(--ink-faint); }

#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-kbd {
  position: absolute;
  right: 12px; top: 50%;
  translate: 0 -50%;
  padding: 1px 7px;
  font-family: inherit;
  font-size: 12px;
  color: var(--ink-faint);
  border: 1px solid var(--hairline-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  pointer-events: none;
}

.theme-toggle {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  cursor: pointer;
  transition: color .25s ease, border-color .25s ease, transform .2s ease, box-shadow .25s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: rotate(12deg);
  box-shadow: var(--shadow-sm);
}

.theme-toggle svg { width: 19px; height: 19px; }

[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"]  .icon-moon { display: none; }

/* ---------- 4. 布局：侧边栏 + 内容 ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
  padding-block: 34px 56px;
  align-items: start;
}

@media (min-width: 1100px) {
  .layout { grid-template-columns: 216px minmax(0, 1fr); gap: 48px; }
}

/* 侧边栏（由配置自动生成） */
.sidebar { display: none; }

@media (min-width: 1100px) {
  .sidebar {
    display: block;
    position: sticky;
    top: calc(var(--header-h) + 28px);
    max-height: calc(100vh - var(--header-h) - 56px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 6px;
  }
  .sidebar::-webkit-scrollbar { width: 4px; }
  .sidebar::-webkit-scrollbar-thumb { background: var(--hairline-2); border-radius: 4px; }
}

.sidebar-title {
  margin: 0 0 14px;
  font-family: "Noto Serif SC", serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .5em;
  color: var(--ink-faint);
}

.sidebar-list {
  margin: 0; padding: 0;
  list-style: none;
  border-left: 1px solid var(--hairline);
}

.sidebar-list a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0 8px 16px;
  font-size: 13.5px;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
  margin-left: -1.5px;
  transition: color .2s ease, border-color .2s ease;
}

.sidebar-list a:hover { color: var(--ink); }

.sidebar-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 700;
}

.sidebar-count {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- 5. 分类区块 ---------- */
.cat-section {
  margin-bottom: 44px;
  scroll-margin-top: calc(var(--header-h) + 20px);
}

.cat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 0 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}

.cat-head:focus-visible { outline-offset: 6px; }

.cat-index {
  font-family: "Fraunces", "Noto Serif SC", serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: .05em;
}

.cat-icon {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  flex-shrink: 0;
}

.cat-icon svg { width: 16px; height: 16px; }

.cat-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .02em;
}

.cat-desc {
  font-size: 12.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-count {
  margin-left: auto;
  flex-shrink: 0;
  padding: 2px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 999px;
}

.cat-chevron {
  flex-shrink: 0;
  width: 16px; height: 16px;
  color: var(--ink-faint);
  transition: transform .35s cubic-bezier(.22, 1, .36, 1);
}

.cat-section.collapsed .cat-chevron { transform: rotate(-180deg); }

.cat-section.collapsed .cat-head { border-bottom-color: transparent; }

/* 平滑折叠：grid-rows 技巧 */
.cat-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .38s cubic-bezier(.22, 1, .36, 1);
}

.cat-section.collapsed .cat-body { grid-template-rows: 0fr; }

.cat-body-inner { min-height: 0; overflow: hidden; }

/* ---------- 6. 链接卡片网格 ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 14px;
  padding-top: 18px;
}

.link-card {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}

.link-card::after {
  /* 朱砂书脊 */
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 2.5px;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .25s ease;
}

.link-card:hover,
.link-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--hairline));
}

.link-card:hover::after { opacity: 1; }

.card-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  font-family: "Noto Serif SC", serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.card-icon img {
  width: 22px; height: 22px;
  object-fit: contain;
}

.card-text { min-width: 0; flex: 1; }

.card-title {
  margin: 2px 0 3px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.card-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-url {
  display: block;
  margin-top: 7px;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .2s ease;
}

.link-card:hover .card-url { color: var(--accent); }

/* ---------- 7. 状态：加载 / 错误 / 空结果 ---------- */
.loading-state,
.error-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 72px 20px;
  color: var(--ink-soft);
  text-align: center;
}

.loading-seal {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff8f2;
  font-family: "Noto Serif SC", serif;
  font-size: 26px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 248, 242, .35), var(--shadow-sm);
  animation: seal-pulse 1.6s ease-in-out infinite;
}

@keyframes seal-pulse {
  0%, 100% { transform: rotate(-4deg) scale(1); opacity: 1; }
  50%      { transform: rotate(4deg) scale(.92); opacity: .75; }
}

.empty-state .empty-glyph {
  font-family: "Fraunces", "Noto Serif SC", serif;
  font-size: 44px;
  color: var(--hairline-2);
}

.error-state { color: var(--accent-deep); }

/* ---------- 8. 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  padding-block: 22px;
  font-size: 12.5px;
  color: var(--ink-faint);
}

.footer-inner p { margin: 0; }

/* ---------- 9. 入场动画 ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.anim-rise {
  animation: rise .55s cubic-bezier(.22, 1, .36, 1) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

/* ---------- 10. 响应式微调 ---------- */
@media (max-width: 560px) {
  .brand-sub, .search-kbd { display: none; }
  .seal { width: 34px; height: 34px; font-size: 18px; }
  .brand-name { font-size: 17px; }
  .header-inner { gap: 10px; }
  .card-grid { grid-template-columns: 1fr; }
  .cat-name { font-size: 17px; }
  .cat-desc { display: none; }
}

@media (hover: none) {
  .search-kbd { display: none; }
}

/* ---------- 11. 减少动态 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
