/* ============================================================
   门户首页样式（原 index.html 内联 <style> 外置于此）
   —— 深色星空 + 玻璃拟态主题；新增：sticky 工具栏、分类芯片、
      分类分段、搜索高亮、空态引导、显示全部按钮
   ============================================================ */
:root {
  --bg: #0a0e17;
  --bg2: #0d1220;
  --card: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-dim: #8b94a7;
  --accent: #4fd1c5;
  --accent-dim: rgba(79, 209, 197, 0.15);
  --glow: rgba(79, 209, 197, 0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  /* clip 而非 hidden：overflow-x:hidden 会把 body 变成滚动容器、使 sticky 工具栏失效 */
  overflow-x: clip;
}
@supports not (overflow-x: clip) {
  html, body { overflow-x: hidden; } /* 老 Safari 兜底：仅退化为不粘顶 */
}

/* ===== 背景层 ===== */
#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(79, 209, 197, 0.10), transparent 60%),
    radial-gradient(ellipse 60% 40% at 85% 110%, rgba(99, 102, 241, 0.08), transparent 60%);
}

.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.022) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 40%, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 40%, black 30%, transparent 75%);
}

/* ===== 内容 ===== */
.wrap {
  position: relative;
  z-index: 2;
  max-width: min(1320px, 94vw);
  margin: 0 auto;
  padding: clamp(2rem, 6vh, 4.5rem) 1.5rem 3rem;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== 头部 ===== */
header {
  text-align: center;
  margin-bottom: clamp(1.2rem, 3vh, 2.2rem);
  opacity: 0;
  animation: fadeDown 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.15s forwards;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.95rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  color: var(--text-dim);
  background: var(--card);
  backdrop-filter: blur(8px);
  margin-bottom: 1.4rem;
  text-transform: uppercase;
}

.badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--glow);
  animation: breathe 2.4s ease-in-out infinite;
}

h1 {
  font-size: clamp(2rem, 5.5vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 0.9rem;
}
h1 .fa-layer-group { color: var(--accent); margin-right: 0.4rem; }
#portal-title {
  background: linear-gradient(180deg, #ffffff 30%, #9fb3cc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-dim);
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  letter-spacing: 0.04em;
}

.divider {
  width: 72px;
  height: 2px;
  margin: 1.6rem auto 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  position: relative;
  overflow: hidden;
}
.divider::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.9), transparent);
  transform: translateX(-100%);
  animation: shimmer 2.8s ease-in-out infinite;
}

/* ===== 工具栏（搜索 + 分类芯片），粘顶毛玻璃 ===== */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -1.5rem;
  padding: calc(0.9rem + env(safe-area-inset-top, 0px)) 1.5rem 0.9rem;
  background: rgba(10, 14, 23, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease;
  opacity: 0;
  animation: fadeDown 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
}

.search-box {
  position: relative;
  max-width: 560px;
  margin: 0 auto 0.75rem;
}
.search-box .s-icon {
  position: absolute;
  left: 1.05rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 0.85rem;
  pointer-events: none;
}
#app-search {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* ≥16px 防 iOS 聚焦自动放大 */
  padding: 0.65rem 3.6rem 0.65rem 2.6rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
#app-search::placeholder { color: var(--text-dim); opacity: 0.8; }
#app-search::-webkit-search-cancel-button { display: none; }
#app-search:focus {
  border-color: rgba(79, 209, 197, 0.45);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.12);
}
.search-clear {
  position: absolute;
  right: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
  font-size: 0.7rem;
  cursor: pointer;
  transition: color 0.25s, background 0.25s;
}
.search-clear:hover { color: var(--text); background: rgba(255,255,255,0.14); }
.search-box.has-q .search-clear { display: inline-flex; }
.search-kbd {
  position: absolute;
  right: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 0.08rem 0.42rem;
  pointer-events: none;
}
.search-box.has-q .search-kbd,
.search-box:focus-within .search-kbd { display: none; }

.chips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.34rem 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.25s, border-color 0.25s, background 0.25s;
}
.chip:hover { color: var(--text); border-color: rgba(79, 209, 197, 0.3); }
.chip .chip-n {
  font-size: 0.68rem;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
}
.chip[aria-pressed="true"] {
  color: var(--accent);
  border-color: rgba(79, 209, 197, 0.5);
  background: var(--accent-dim);
}
.chip:focus-visible,
#app-search:focus-visible,
.more-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== 分类分段 ===== */
#sections { flex: 1; }

.cat-section {
  margin-bottom: 2.6rem;
  opacity: 0;
  animation: fadeDown 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(0.45s + var(--si, 0) * 0.1s);
  scroll-margin-top: 7.5rem;
}
.cat-section[hidden] { display: none; }

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}
.sec-icon {
  color: var(--accent);
  font-size: 0.95rem;
  align-self: center;
}
.sec-title {
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.sec-count {
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
}
.sec-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ===== 卡片网格 ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 1.4rem;
  align-content: start;
}

#results { flex: 1; }
.results-meta {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 1.1rem;
}
.results-meta b { color: var(--accent); font-weight: 600; }

.more-row { margin-top: 1.1rem; text-align: center; }
.more-btn {
  font: inherit;
  font-size: 0.8rem;
  color: var(--accent);
  background: transparent;
  border: 1px dashed rgba(79, 209, 197, 0.4);
  border-radius: 999px;
  padding: 0.42rem 1.3rem;
  cursor: pointer;
  transition: background 0.25s, border-color 0.25s;
}
.more-btn:hover { background: var(--accent-dim); border-color: rgba(79, 209, 197, 0.7); }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.8rem 1.7rem 1.6rem;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 12px 36px rgba(0,0,0,0.35);
  overflow: hidden;
  opacity: 0;
  transform: translateY(28px);
  animation: cardIn 0.85s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(0.35s + var(--i) * 0.12s);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.35s ease,
              box-shadow 0.35s ease;
}

/* 已入场卡片在筛选/搜索重排时原地保留，不再整屏重飞 */
.card.entered {
  animation: none;
  opacity: 1;
  transform: none;
}

.card:hover {
  transform: translateY(-6px);
  border-color: rgba(79, 209, 197, 0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08),
              0 20px 48px rgba(0,0,0,0.45),
              0 0 0 1px rgba(79,209,197,0.12),
              0 0 42px -8px var(--glow);
}

.card:active { transform: translateY(-3px) scale(0.985); }

/* 鼠标光斑 */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(320px circle at var(--mx, 50%) var(--my, 50%),
              rgba(79, 209, 197, 0.10), transparent 65%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.card:hover::before { opacity: 1; }

/* 扫光 */
.card::after {
  content: "";
  position: absolute;
  top: 0; left: -80%;
  width: 60%; height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,0.045), transparent);
  transform: skewX(-20deg);
  transition: left 0.7s ease;
  pointer-events: none;
}
.card:hover::after { left: 130%; }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.15rem;
}

.icon-box {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border: 1px solid rgba(79, 209, 197, 0.25);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.card:hover .icon-box { transform: scale(1.08) rotate(-4deg); }
.icon-box svg { width: 26px; height: 26px; }

.tag {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
}

.card h2 {
  font-size: 1.22rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 0.5rem;
}

.card p {
  font-size: 0.875rem;
  color: var(--text-dim);
  line-height: 1.65;
  margin-bottom: 1.3rem;
  flex: 1; /* 卡脚贴底对齐 */
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.status .s-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5b657a;
  transition: background 0.4s, box-shadow 0.4s;
}
.status.online .s-dot {
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.7);
  animation: breathe 2s ease-in-out infinite;
}
.status.online .s-text { color: #34d399; }
.status.offline .s-dot { background: #f87171; box-shadow: 0 0 8px rgba(248,113,113,0.6); }
.status.offline .s-text { color: #f87171; }

.enter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.03em;
}
.enter svg {
  width: 15px; height: 15px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.card:hover .enter svg { transform: translateX(5px); }

/* 搜索命中高亮 */
mark {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
}

/* 空状态 */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
  border: 1px dashed var(--card-border);
  border-radius: 20px;
}
.empty .empty-q { color: var(--text); }
.empty .empty-actions { margin-top: 1.2rem; display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

/* ===== 页脚 ===== */
footer {
  margin-top: 4rem;
  text-align: center;
  font-size: 0.75rem;
  color: #566074;
  letter-spacing: 0.08em;
  opacity: 0;
  animation: fadeDown 1s ease 1.1s forwards;
}

/* ===== 动画 ===== */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes cardIn {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  60%, 100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  header, .card, footer, .toolbar, .cat-section { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .chips {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 0.2rem;
    margin: 0 -1.5rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
  .chips::-webkit-scrollbar { display: none; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
}
