/* ==========================================================================
   components.css — 所有可见组件
   --------------------------------------------------------------------------
   按"页面上从上到下"的顺序排列：
     1. 顶栏（品牌区 + 工具区）
     2. 搜索框与按钮
     3. 分类胶囊条
     4. 主体与分组标题
     5. 链接卡片（含悬停 / 按下 / 聚焦 / 点击后四种状态）
     6. 提示、页脚
     7. 返回顶部
   规则：除 tokens.css 里的变量外，不写死颜色与关键尺寸。
   ========================================================================== */

/* ==========================================================================
   1. 顶栏
   ========================================================================== */
.top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px var(--pad-x);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

/* 品牌区：logo + 标题 + 副标题，永远不参与收缩 */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-width: 0;
  text-decoration: none;
}
.logo { width: 18px; height: 18px; flex: none; color: var(--text); }

.brand-txt { min-width: 0; }
h1 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.brand-txt p {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* 工具区：搜索框 + 图标按钮，整体靠右 */
.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-end;
}

/* ==========================================================================
   2. 搜索框与按钮
   --------------------------------------------------------------------------
   桌面：常态 150px，聚焦拉宽到 230px（往左生长，右侧按钮不动）
   移动：整体 display:none，改由放大镜图标触发展开
   ========================================================================== */
.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: 150px;          /* 常态宽度 */
  min-width: 0;
  transition: width .24s cubic-bezier(.2, .8, .3, 1);
}
.search:focus-within { width: 230px; }   /* 聚焦时拉长 */

.search input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 40px;
  padding: 0 36px;       /* 左右都留出图标位 */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color .16s ease, border-color .16s ease;
}
.search input::placeholder { color: var(--muted); }
.search input:hover { border-color: var(--line-2); }
.search input:focus { background: var(--field-focus); border-color: var(--text); }
/* 关掉 Safari 自带的清除叉，用我们自己的 */
.search input::-webkit-search-cancel-button { display: none; }

/* 左侧放大镜 */
.s-ico {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

/* 右侧 "/" 快捷键提示，聚焦或有内容时让位 */
.s-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--panel);
  font-family: inherit;
  font-size: 10.5px;
  line-height: 1;
  color: var(--muted);
  pointer-events: none;
}
.search:focus-within .s-kbd { display: none; }

/* 输入框内的清除按钮（桌面 / 移动展开时都会用到） */
.s-clear {
  position: absolute;
  right: 4px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.s-clear svg { width: 13px; height: 13px; }
.s-clear:hover { background: var(--hover); color: var(--text); }

/* 移动端展开后的关闭按钮（✕），桌面恒为 display:none */
.s-cancel {
  display: none;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  place-items: center;
  transition: color .15s ease, background-color .15s ease;
}
.s-cancel svg { width: 14px; height: 14px; }
.s-cancel:hover { color: var(--text); background: var(--hover); }

/* 通用方形图标按钮（主题切换、移动端搜索图标） */
.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--hover); }

/* 搜索图标：桌面隐藏，移动端显示（用更高优先级压住 .icon-btn 的 display） */
.icon-btn.search-toggle { display: none; }
/* 有搜索词时点亮，提示"当前处于筛选状态" */
.icon-btn.search-toggle.active {
  border-color: var(--text);
  background: var(--hover);
}

/* ==========================================================================
   3. 分类胶囊条
   --------------------------------------------------------------------------
   sticky 贴在顶栏下方，滚动时保持可见。
   top 用 --top-h（由 JS 实测顶栏高度写入），避免硬编码。
   ========================================================================== */
.chips {
  position: sticky;
  top: var(--top-h);
  z-index: 25;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 12px var(--pad-x) 0;
  background: var(--bg);
  /* 下沿补一段同色底，卡片不会贴着胶囊边缘滚过去 */
  box-shadow: 0 9px 0 var(--bg);
}
.chips::-webkit-scrollbar { display: none; }

/* 首尾各塞一个零宽伪元素：内容不满一行时整体居中，
   溢出时自动收成 0，正常横向滚动（避免 justify-content:center 的裁切问题） */
.chips::before,
.chips::after {
  content: "";
  flex: 0 0 auto;
  margin: 0 auto;
}

.chip {
  flex: none;
  height: 28px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .14s ease, color .14s ease;
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ==========================================================================
   4. 主体与分组
   ========================================================================== */
.main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px var(--pad-x) 32px;
  display: flex;
  flex-direction: column;
  gap: var(--sec-gap);
}

.section { display: flex; flex-direction: column; gap: clamp(10px, .9vw, 13px); }

/* 分组标题：小号大写式，配一条向右延伸的细线 */
.sec-head { display: flex; align-items: center; gap: 9px; }
.sec-head h2 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.sec-head .count { font-size: 11px; color: var(--muted); opacity: .65; }
.sec-head .rule { flex: 1; height: 1px; background: var(--line); }

/* 卡片网格：列数与卡片尺寸全部由 tokens.css 的变量驱动 */
.grid {
  display: grid;
  gap: var(--card-gap);
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
}

/* ==========================================================================
   5. 链接卡片
   --------------------------------------------------------------------------
   四种状态：
     · 悬停  .card:hover        —— 描边加深、上浮 2px、左侧竖条展开、箭头淡入
     · 按下  .card:active       —— 底色转浅灰、整体缩到 0.988
     · 聚焦  .card:focus-within —— 2px 实心描边外扩（键盘可达）
     · 点过  .card.is-clicked   —— 收起以上全部反馈，直到鼠标真正移出
   ========================================================================== */
.card {
  position: relative;
  height: var(--card-h);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  -webkit-tap-highlight-color: transparent;   /* 关掉移动端系统点击高亮 */
  transition: border-color .16s ease, background-color .16s ease,
              transform .18s cubic-bezier(.2, .8, .3, 1);
}

/* 左边缘的 2px 竖条，悬停时从中间向上下展开 */
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: 50% 50%;
  transition: transform .22s ease, opacity .12s ease;
  pointer-events: none;
}

/* 可点击区域：整卡铺满 */
.link {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  box-sizing: border-box;
  padding: 0 24px 0 11px;    /* 右侧留出外链箭头的位置 */
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.link:focus { outline: none; }

/* 站点图标托盘 */
.thumb {
  position: relative;
  flex: none;
  width: var(--thumb-size);
  height: var(--thumb-size);
  border-radius: 7px;
  overflow: hidden;
  background: var(--thumb);
  display: grid;
  place-items: center;
}
/* favicon 加载成功前保持透明，失败则退回首字母 */
.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
  opacity: 0;
  transition: opacity .2s ease;
}
.thumb img.ok { opacity: 1; }
.fb { font-size: 12px; font-weight: 600; color: var(--muted); font-style: normal; }
.thumb img,
.fb { transition: opacity .2s ease, transform .22s cubic-bezier(.2, .8, .3, 1); }

/* 文字区：名字与简介都是单行省略 */
.txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .16s ease;
}
.desc {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 悬停时浮出的完整简介气泡 */
.tip {
  position: absolute;
  left: 6px;
  top: calc(100% + 6px);
  z-index: 30;
  width: max-content;
  max-width: 270px;
  padding: 7px 9px;
  border-radius: 6px;
  background: var(--tip-bg);
  color: var(--tip-fg);
  font-size: 11.5px;
  line-height: 1.5;
  font-weight: 400;
  text-align: left;
  white-space: normal;
  word-break: break-word;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
  pointer-events: none;      /* 气泡不参与命中测试，避免闪烁 */
}

/* 右下角外链箭头 */
.arrow {
  position: absolute;
  right: 9px;
  bottom: 8px;
  width: 11px;
  height: 11px;
  color: var(--muted);
  opacity: 0;
  transform: translate(-2px, 2px);
  pointer-events: none;
  transition: opacity .16s ease, transform .18s cubic-bezier(.2, .8, .3, 1);
}

/* ---- 悬停：只在有精确指针的设备上生效，触屏不受影响 ---- */
@media (hover: hover) and (pointer: fine) {
  .card:hover {
    border-color: var(--line-2);
    transform: translateY(-2px);
    z-index: 10;             /* 抬高整卡，气泡不会被子行卡片压住 */
  }
  .card:hover::before { transform: scaleY(1); }
  .card:hover .arrow { opacity: .9; transform: none; }
  .card:hover .thumb img,
  .card:hover .fb { transform: scale(1.08); }
  .card:hover .tip { opacity: 1; visibility: visible; transform: none; }
}

/* ---- 按下：鼠标左键与手指触摸都会触发 ---- */
.card:active {
  background-color: var(--press);
  border-color: var(--line-2);
  transform: translateY(0) scale(.988);
  transition-duration: .06s;   /* 按下要立刻响应 */
}
.card:active::before { transform: scaleY(1); opacity: .55; }
.card:active .arrow { opacity: 1; transform: none; }

/* ---- 键盘聚焦：外扩 2px 描边，不用默认 outline ---- */
.card:focus-within {
  border-color: var(--line-2);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.card:focus-within::before { transform: scaleY(1); }

/* ---- 点击过之后：悬停反馈全部收起，直到鼠标真的离开这张卡 ----
   用 :not(:active) 兜住，保证按住时仍有按下态反馈 */
.card.is-clicked:hover:not(:active) {
  transform: none;
  border-color: var(--line);
  background-color: var(--panel);
  z-index: auto;
}
.card.is-clicked:hover:not(:active)::before { transform: scaleY(0); }
.card.is-clicked:hover:not(:active) .arrow { opacity: 0; transform: translate(-2px, 2px); }
.card.is-clicked:hover:not(:active) .thumb img,
.card.is-clicked:hover:not(:active) .fb { transform: none; }
.card.is-clicked:hover:not(:active) .tip { opacity: 0; visibility: hidden; }

/* ==========================================================================
   6. 提示与页脚
   ========================================================================== */
/* 空状态 / 无结果提示 */
.hint { padding: 48px 20px; text-align:center; font-size: 13px; color: var(--muted); }

/* 移动端首次进入时的滑动提示，5 秒后淡出 */
.swipe-hint {
  display: none;
  margin: 0;
  padding: 10px var(--pad-x) 0;
  font-size: 11px;
  color: var(--muted);
  opacity: 1;
  transition: opacity .6s ease;
}
.swipe-hint.hide { opacity: 0; }

/* 页脚：只有一行站点总数 */
.foot {
  padding: 16px var(--pad-x) 40px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  opacity: .7;
}
/* 文字上方的短横线，比通栏分隔更安静 */
.foot::before {
  content: "";
  display: block;
  width: 160px;
  height: 1px;
  margin: 0 auto 16px;
  background: var(--line);
}

/* ==========================================================================
   7. 返回顶部
   ========================================================================== */
.to-top {
  position: fixed;
  right: var(--pad-x);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 35;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  /* 默认隐藏，滚动超过阈值后由脚本加 .show */
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease,
              background-color .15s ease, border-color .15s ease;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { background: var(--hover); border-color: var(--line-2); }
.to-top:active { transform: scale(.94); }
.to-top svg { width: 16px; height: 16px; }
