/* ===== Google Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;600;900&display=swap');

/* ===== CSS 变量 ===== */
:root {
  --glass-bg: rgba(0, 0, 0, 0.45);
  --glass-border: rgba(255, 255, 255, 0.25);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  --primary: #4CAF50;
  --primary-dim: rgba(76, 175, 80, 0.35);
  --text-main: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.80);
  --radius-card: 14px;
  --radius-section: 20px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; outline: none; margin: 0; padding: 0; }

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

body {
  font-family: 'Noto Sans SC', sans-serif;
  color: var(--text-main);
  min-height: 100vh;
  background: #1a1a1a;
  overflow-x: hidden;
}

/* ===== 背景层 ===== */
#bgLayer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#bgOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: -1;
}

/* ===== 主容器 ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.2rem;
  width: 100%;
}

/* ===== 头部 ===== */
.header-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 1.5rem;
  width: 100%;
  overflow: hidden;
}

.header-icon {
  font-size: 2rem;
  flex-shrink: 0;
  filter: drop-shadow(0 0 12px rgba(76, 175, 80, 0.8)) drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  animation: float 3s ease-in-out infinite;
  user-select: none;
  display: flex;
  align-items: center;
}
.header-icon:last-child { animation-delay: 1.5s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

h1 {
  text-align: center;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: linear-gradient(135deg, #ffffff 0%, #a8f5ab 30%, #4CAF50 55%, #81e085 75%, #ffffff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter:
    drop-shadow(0 0 20px rgba(76, 175, 80, 0.7))
    drop-shadow(0 0 40px rgba(76, 175, 80, 0.35))
    drop-shadow(0 6px 16px rgba(0, 0, 0, 0.8));
}

h1::after {
  content: '';
  display: block;
  margin: 8px auto 0;
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #4CAF50, rgba(76,175,80,0.5), transparent);
  border-radius: 2px;
}

.header-subtitle {
  text-align: center;
  font-size: clamp(0.6rem, 1.5vw, 0.78rem);
  letter-spacing: 0.25em;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  margin-top: 5px;
  font-weight: 400;
}

/* ===== 搜索区域 ===== */
.search-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2rem;
  gap: 14px;
  width: 100%;
}

/* 搜索框主体 */
.search-box {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2px solid var(--glass-border);
  border-radius: 50px;
  /* 修复：给左右两侧明确的 padding，避免内容溢出 */
  padding: 5px 8px 5px 12px;
  box-shadow: var(--glass-shadow);
  width: 100%;
  max-width: 700px;
  min-width: 0;
  gap: 6px;
}

/* 搜索引擎图标 */
#search-engine-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

/* 搜索引擎下拉 */
.search-box select {
  background: transparent;
  color: #fff;
  border: none;
  padding: 0 2px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
  /* 修复：限制最小宽度避免和箭头撞在一起，使用 appearance 统一箭头样式 */
  min-width: 48px;
  max-width: 72px;
  -webkit-appearance: none;
  appearance: none;
  /* 自定义下拉箭头，放在右侧不会与文字重叠 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.6)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 16px;
}
.search-box select option { background: #222; color: #fff; }

/* 分割线 */
.search-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.25);
  flex-shrink: 0;
}

/* 搜索输入框 */
.search-box input[type="text"] {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0 4px;
  height: 42px;
  font-size: 1rem;
  color: #fff;
  min-width: 0;
  width: 0;
  font-family: inherit;
}
.search-box input[type="text"]::placeholder { color: rgba(255, 255, 255, 0.65); }

/* 搜索按钮 */
.search-box button {
  background: var(--primary);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  font-size: 1rem;
}
.search-box button:active { transform: scale(0.93); background: #388E3C; }

/* 站内搜索框 */
.local-search {
  width: 100%;
  max-width: 450px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid var(--primary);
  border-radius: 25px;
  padding: 10px 20px;
  color: #fff;
  font-size: 0.95rem;
  text-align: center;
  font-family: inherit;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.local-search:focus {
  border-color: #81e085;
  box-shadow: 0 0 0 3px rgba(76,175,80,0.2);
}
.local-search::placeholder { color: rgba(255, 255, 255, 0.75); }

/* ===== 分区 ===== */
.section {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-section);
  padding: 1.3rem;
  margin-bottom: 2rem;
}

.section.section-hidden { display: none; }

.section-title {
  color: var(--primary);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 1rem 0;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 1em;
  background: var(--primary);
  border-radius: 2px;
}

/* ===== 卡片网格 ===== */
.link-container {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.9rem;
  align-items: stretch;
}

/* ===== 卡片 ===== */
.card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  transition: background 0.25s, transform 0.25s, border-color 0.25s;
  position: relative;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  padding: 11px;
  gap: 5px;
  height: 100%;
  /* 防止点击穿透到不存在区域 */
  -webkit-tap-highlight-color: transparent;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.card img.favicon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

.card .title {
  font-weight: 600;
  font-size: 0.88rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.card .desc {
  font-size: 0.73rem;
  color: var(--text-dim);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
}

/* ===== Hover 弹出信息（桌面端） ===== */
@media (hover: hover) {
  .card:hover {
    background: rgba(255,255,255,0.18);
    transform: translateY(-4px);
    border-color: var(--primary);
  }

  .card .info-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    width: 200px;
    background: rgba(10, 10, 10, 0.92);
    border: 1px solid var(--primary);
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.74rem;
    color: #fff;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    z-index: 100;
    word-break: break-all;
    white-space: normal;
    /* 确保不超出屏幕右边 */
    max-width: calc(100vw - 24px);
  }

  .card:hover .info-popup {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ===== 触屏：长按弹出 tooltip（移动端） ===== */
/* 使用 JS 控制的 .touch-active 类，替代 hover */
@media (hover: none) {
  /* 禁用 hover 效果，改为 active */
  .card:active {
    background: rgba(255,255,255,0.18);
    border-color: var(--primary);
  }

  .card .info-popup {
    /* 移动端：固定在视口底部，不随卡片位置偏移 */
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: min(320px, calc(100vw - 32px));
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--primary);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    word-break: break-all;
    white-space: normal;
    transition: opacity 0.2s;
    /* 移动端额外显示域名标签 */
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  }

  .card.touch-active .info-popup {
    opacity: 1;
  }
}

/* 隐藏卡片 */
.card.hidden { display: none; }

/* ===== 无结果提示 ===== */
.no-result-tip {
  display: none;
  text-align: center;
  color: rgba(255,255,255,0.45);
  font-size: 0.9rem;
  padding: 1.2rem 0 0.4rem;
  grid-column: 1 / -1;
}

/* ===== 响应式断点 ===== */
@media (max-width: 1200px) {
  .link-container { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 960px) {
  .link-container { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 720px) {
  .link-container { grid-template-columns: repeat(3, 1fr); gap: 0.65rem; }
  .card { padding: 9px 8px; }
  .card .desc { -webkit-line-clamp: 2; font-size: 0.7rem; }
}

@media (max-width: 480px) {
  .container { padding: 0.75rem; }
  .header-area { gap: 8px; margin-bottom: 1rem; }
  .header-icon { font-size: 1.3rem; }

  .search-box {
    padding: 4px 8px 4px 10px;
    gap: 4px;
  }
  .search-box select {
    font-size: 0.78rem;
    min-width: 44px;
    max-width: 64px;
    padding-right: 14px;
  }
  .search-box input[type="text"] {
    font-size: 0.9rem;
    height: 38px;
  }
  .search-box button {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .local-search { font-size: 0.85rem; padding: 9px 14px; }

  .section { padding: 0.9rem 0.75rem; border-radius: 14px; }
  .link-container { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }

  .card { padding: 8px 6px; border-radius: 10px; gap: 4px; }
  .card .title { font-size: 0.75rem; }
  .card img.favicon { width: 16px; height: 16px; }
  .card .desc { font-size: 0.67rem; }
}

@media (max-width: 360px) {
  .link-container { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
  .card { padding: 7px 5px; }
  .card .title { font-size: 0.7rem; }
}
