/* ==========================================================================
   library.css — 知识库页面样式（复用 main.css 的设计令牌）
   ========================================================================== */

/* ---------- 页头 ---------- */
.lib-hero {
  padding-block: clamp(3.5rem, 10vh, 6.5rem) var(--s4);
}

.lib-hero__title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.03em;
  margin-bottom: var(--s3);
  max-width: 15ch;
}
.lib-hero__title .grad {
  background: var(--grad-text);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(34, 211, 238, .3));
}

.lib-hero__lead {
  font-size: var(--fs-lead);
  color: var(--fg-dim);
  max-width: 54ch;
  line-height: 1.9;
  margin-bottom: var(--s5);
}

/* ---------- 搜索 ---------- */
.lib-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1rem .85rem 1.1rem;
  border: 1px solid var(--line-hi);
  border-radius: 13px;
  background: linear-gradient(180deg, rgba(26, 37, 52, .8), rgba(17, 24, 35, .6));
  backdrop-filter: blur(10px);
  max-width: 640px;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.lib-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 129, 247, .14), 0 10px 34px -16px rgba(47, 129, 247, .7);
}
.lib-search__icon { width: 18px; height: 18px; color: var(--fg-faint); flex: none; }
.lib-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: var(--fs-sm);
  outline: none;
}
.lib-search input::placeholder { color: var(--fg-faint); }
.lib-search input::-webkit-search-cancel-button { display: none; }

.lib-search__clear {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,.09);
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1;
  display: grid; place-items: center;
  flex: none;
  transition: background .2s, color .2s;
}
.lib-search__clear:hover { background: rgba(255,255,255,.16); color: var(--fg); }
/* hidden 属性必须压过 display:grid，否则空状态也会显示清空按钮 */
.lib-search__clear[hidden] { display: none; }

.lib-search__kbd {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--fg-faint);
  border: 1px solid var(--line-hi);
  border-radius: 5px;
  padding: .1rem .4rem;
  flex: none;
}

/* ---------- 分类筛选 ---------- */
.lib-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: var(--s3);
}

.lib-filter {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .48rem .88rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(17, 24, 35, .5);
  color: var(--fg-dim);
  font-size: var(--fs-sm);
  transition: border-color .22s var(--ease), color .22s var(--ease), background .22s var(--ease), transform .22s var(--ease);
}
.lib-filter:hover {
  border-color: var(--line-hi);
  color: var(--fg);
  transform: translateY(-1px);
}
.lib-filter.is-active {
  color: #04121f;
  background: var(--grad);
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 6px 22px -10px rgba(47, 129, 247, .9);
}
.lib-filter__n {
  font-family: var(--font-mono);
  font-size: .72rem;
  opacity: .62;
  font-variant-numeric: tabular-nums;
}

/* ---------- 计数条 ---------- */
.lib-meta {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding-bottom: var(--s3);
  margin-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--fg-faint);
}
.lib-meta__hint { margin-left: auto; color: var(--fg-faint); opacity: .8; }

/* ---------- 分类分组 ---------- */
.lib-group { margin-bottom: var(--s6); }
.lib-group:last-child { margin-bottom: var(--section-y); }

.lib-group__head {
  display: flex;
  align-items: baseline;
  gap: .8rem;
  margin-bottom: var(--s3);
  flex-wrap: wrap;
}
.lib-group__title {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.2vw, 1.6rem);
  letter-spacing: -.02em;
}
.lib-group__n {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--accent-2);
}
.lib-group__desc {
  flex-basis: 100%;
  font-size: var(--fs-sm);
  color: var(--fg-faint);
  margin-top: -.2rem;
}

/* ---------- 条目 ---------- */
/* 一级：网站大卡片 */
.lib-sites {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: .7rem;
  align-items: start;
}

.lib-item {
  display: flex;
  flex-direction: column;
  gap: .38rem;
  padding: .95rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(170deg, rgba(26, 37, 52, .5), rgba(17, 24, 35, .38));
  position: relative;
  overflow: hidden;
  transition: border-color .25s var(--ease), transform .25s var(--ease), background .25s var(--ease);
}
.lib-item::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(120, 180, 255, .3), transparent);
  opacity: 0;
  transition: opacity .25s var(--ease);
}
.lib-item:hover {
  border-color: var(--line-hi);
  transform: translateY(-2px);
  background: linear-gradient(170deg, rgba(30, 43, 60, .62), rgba(20, 29, 42, .5));
}
.lib-item:hover::before { opacity: 1; }

.lib-item__top {
  display: flex;
  align-items: baseline;
  gap: .5rem;
}
.lib-item__title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.45;
  transition: color .22s;
}
.lib-item:hover .lib-item__title { color: var(--accent-2); }
.lib-item__ext {
  margin-left: auto;
  color: var(--fg-faint);
  flex: none;
  transition: color .22s, transform .22s;
}
.lib-item:hover .lib-item__ext { color: var(--accent-2); transform: translate(2px, -2px); }

.lib-item__desc {
  font-size: var(--fs-sm);
  color: var(--fg-faint);
  line-height: 1.7;
}
.lib-item:hover .lib-item__desc { color: var(--fg-dim); }

.lib-item__dom {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--fg-faint);
  opacity: .65;
  margin-top: .1rem;
}

/* 搜索命中高亮 */
mark {
  background: rgba(34, 211, 238, .22);
  color: var(--accent-2);
  border-radius: 3px;
  padding: 0 .1em;
}

/* ---------- 空状态 ---------- */
.lib-empty {
  padding: var(--s6) 0 var(--section-y);
  text-align: center;
  color: var(--fg-dim);
}
.lib-empty__sub { font-size: var(--fs-sm); color: var(--fg-faint); margin-top: .5rem; }
.lib-empty a { color: var(--accent-2); text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 560px) {
  .lib-sites { grid-template-columns: 1fr; }
  .lib-search__kbd { display: none; }
  .lib-hero { padding-block: 2.5rem var(--s3); }
  .lib-meta__hint { display: none; }
}


/* ==========================================================================
   分层：二级（仓库）与三级（推文）
   一个仓库/一条推文不占一个完整网站的版面
   ========================================================================== */

/* ---------- 页头统计 ---------- */
.lib-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin: calc(-1 * var(--s3)) 0 var(--s5);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--fg-faint);
}
.lib-stats span { display: inline-flex; align-items: baseline; gap: .35rem; }
.lib-stats b {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--fg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 二级：开源项目 ---------- */
.lib-sub {
  margin-top: var(--s3);
  padding: var(--s2) var(--s3) var(--s2);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(17, 24, 35, .42);
}

.lib-sub__head {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-bottom: .7rem;
  margin-bottom: .35rem;
  border-bottom: 1px dashed rgba(43, 60, 80, .8);
}
.lib-sub__head svg { width: 15px; height: 15px; color: var(--fg-faint); flex: none; }
.lib-sub__title {
  font-size: var(--fs-sm);
  color: var(--fg-dim);
  font-weight: 500;
}
.lib-sub__n {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--fg-faint);
}

.lib-repos { display: flex; flex-direction: column; }

.lib-repo {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
  gap: .3rem var(--s2);
  align-items: baseline;
  padding: .52rem .4rem;
  margin-inline: -.4rem;
  border-radius: 7px;
  transition: background .2s var(--ease);
}
.lib-repo:hover { background: rgba(47, 129, 247, .07); }

.lib-repo__name {
  font-size: .88rem;
  color: var(--fg);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .2s;
}
.lib-repo:hover .lib-repo__name { color: var(--accent-2); }

.lib-repo__path {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--fg-faint);
  opacity: .72;
  grid-row: 2;
  grid-column: 1;
  margin-top: -.15rem;
}

.lib-repo__desc {
  font-size: var(--fs-sm);
  color: var(--fg-faint);
  line-height: 1.6;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  transition: color .2s;
}
.lib-repo:hover .lib-repo__desc { color: var(--fg-dim); }

/* ---------- 三级：推文折叠 ---------- */
.lib-posts {
  margin-top: var(--s2);
  border-top: 1px solid var(--line);
}

.lib-posts__head {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem .1rem;
  cursor: pointer;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--fg-faint);
  transition: color .2s;
  user-select: none;
}
.lib-posts__head::-webkit-details-marker { display: none; }
.lib-posts__head:hover { color: var(--fg-dim); }

/* 自绘三角 */
.lib-posts__head::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .22s var(--ease);
  flex: none;
}
.lib-posts[open] .lib-posts__head::before { transform: rotate(90deg); }

.lib-posts__title { font-weight: 500; }
.lib-posts__n {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--accent-2);
  opacity: .8;
}
.lib-posts__hint {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  opacity: .55;
}
.lib-posts[open] .lib-posts__hint { display: none; }

.lib-posts__list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: .2rem 0 .6rem;
}
.lib-posts__list li { border-bottom: 1px dashed rgba(43, 60, 80, .55); }
.lib-posts__list li:last-child { border-bottom: 0; }

.lib-posts__list a {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .15rem;
  padding: .6rem .4rem .6rem .9rem;
  border-radius: 6px;
  position: relative;
  transition: background .2s;
}
.lib-posts__list a::before {
  content: "";
  position: absolute;
  left: .15rem; top: 1.05rem;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--line-hi);
  transition: background .2s;
}
.lib-posts__list a:hover { background: rgba(255,255,255,.025); }
.lib-posts__list a:hover::before { background: var(--accent-2); }

.lib-post__t {
  font-size: .86rem;
  color: var(--fg-dim);
  line-height: 1.5;
  transition: color .2s;
}
.lib-posts__list a:hover .lib-post__t { color: var(--fg); }

.lib-post__d {
  font-size: .8rem;
  color: var(--fg-faint);
  line-height: 1.6;
  opacity: .85;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 640px) {
  .lib-repo {
    grid-template-columns: 1fr;
    gap: .15rem;
  }
  .lib-repo__path { grid-row: auto; grid-column: 1; }
  .lib-repo__desc { grid-column: 1; grid-row: auto; }
  .lib-sub { padding: var(--s2); }
  .lib-stats { gap: var(--s2); }
}
