/* ==========================================================================
   Navigation Hub — Design System
   基础单位 4px · 栅格 auto-fill · 浅深双主题 · WCAG AA 对比度
   ========================================================================== */

:root {
  /* 品牌色阶 */
  --primary-50:  #eef2ff;
  --primary-100: #e0e7ff;
  --primary-500: #4f46e5;
  --primary-600: #4338ca;
  --primary-700: #3730a3;

  /* 语义色 */
  --success: #059669;
  --warning: #d97706;
  --danger:  #dc2626;

  /* 中性色 — 浅色主题 */
  --bg:            #f6f7f9;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-hover: #ffffff;
  --surface-sunken:#f1f3f6;
  --border:        #e4e7ec;
  --border-strong: #d3d8e0;
  --text:          #101828;
  --text-secondary:#475467;
  --text-muted:    #8a94a6;
  --on-accent:     #ffffff;

  /* 阴影 */
  --shadow-xs: 0 1px 2px 0 rgb(16 24 40 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(16 24 40 / 0.08), 0 1px 2px -1px rgb(16 24 40 / 0.06);
  --shadow-md: 0 4px 8px -2px rgb(16 24 40 / 0.08), 0 2px 4px -2px rgb(16 24 40 / 0.05);
  --shadow-lg: 0 12px 20px -6px rgb(16 24 40 / 0.10), 0 4px 8px -4px rgb(16 24 40 / 0.06);
  --shadow-xl: 0 24px 48px -12px rgb(16 24 40 / 0.18);

  /* 间距 */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --space-12: 48px; --space-16: 64px;

  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* 字号 */
  --text-xs: 0.75rem;   /* 12 */
  --text-sm: 0.8125rem; /* 13 */
  --text-base: 0.875rem;/* 14 */
  --text-md: 0.9375rem; /* 15 */
  --text-lg: 1.0625rem; /* 17 */
  --text-xl: 1.375rem;  /* 22 */
  --text-2xl: 2rem;     /* 32 */
  --text-3xl: 2.5rem;   /* 40 */

  /* 动效 */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 140ms;
  --dur-normal: 240ms;

  --header-h: 60px;
  --tabs-h: 58px;
}

[data-theme="dark"] {
  --primary-50:  #1e1b4b;
  --primary-100: #262263;
  --primary-500: #7c76f2;
  --primary-600: #8d87f5;
  --primary-700: #a5a0f8;

  --bg:            #0a0c11;
  --bg-elevated:   #12151c;
  --surface:       #14171f;
  --surface-hover: #191d27;
  --surface-sunken:#0f1219;
  --border:        #232833;
  --border-strong: #2f3542;
  --text:          #e8eaf0;
  --text-secondary:#a4adc0;
  --text-muted:    #6f788c;
  --on-accent:     #ffffff;

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 10px -2px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 12px 24px -6px rgb(0 0 0 / 0.55);
  --shadow-xl: 0 24px 48px -12px rgb(0 0 0 / 0.7);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: var(--text-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur-normal) var(--ease-out), color var(--dur-normal) var(--ease-out);
}
h1, h2, h3, p, dl, dd, dt { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute; left: 50%; top: -60px; transform: translateX(-50%);
  z-index: 100; padding: var(--space-2) var(--space-4);
  background: var(--primary-500); color: #fff; border-radius: var(--radius-sm);
  text-decoration: none; transition: top var(--dur-fast);
}
.skip-link:focus { top: var(--space-2); }

.container {
  width: 100%; max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--space-5);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  height: 100%;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
}
.brand { display: inline-flex; align-items: center; gap: var(--space-3); text-decoration: none; color: inherit; }
.brand__mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--primary-500), #8b5cf6);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand__mark svg { width: 20px; height: 20px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: var(--text-md); font-weight: 650; letter-spacing: -0.01em; }
.brand__text em {
  font-style: normal; font-size: 10px; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text-muted);
}

.header-actions { display: flex; align-items: center; gap: var(--space-2); }

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn--plain { border-color: transparent; }
.icon-btn .icon-moon { display: none; }
[data-theme="dark"] .icon-btn .icon-moon { display: block; }
[data-theme="dark"] .icon-btn .icon-sun  { display: none; }

.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 36px; padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  font-size: var(--text-base); font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-out);
}
.btn__icon { width: 16px; height: 16px; }
.btn--primary { background: var(--primary-500); color: #fff; box-shadow: var(--shadow-xs); }
.btn--primary:hover { background: var(--primary-600); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn--ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.btn--danger:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- Hero ---------- */
.hero { padding: var(--space-12) 0 var(--space-8); text-align: center; }
.hero__eyebrow {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-4);
  font-size: var(--text-xs); font-weight: 550; letter-spacing: 0.04em;
  color: var(--primary-500);
  background: var(--primary-50);
  border: 1px solid color-mix(in srgb, var(--primary-500) 18%, transparent);
  border-radius: var(--radius-pill);
}
.hero__title {
  font-size: clamp(1.9rem, 5vw, var(--text-3xl));
  font-weight: 700; letter-spacing: -0.03em; line-height: 1.15;
}
.hero__title-accent {
  background: linear-gradient(100deg, var(--primary-500), #a855f7 60%, #ec4899);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__desc {
  max-width: 560px; margin: var(--space-4) auto 0;
  color: var(--text-secondary); font-size: var(--text-md);
}

.stats {
  display: inline-flex; gap: var(--space-8);
  margin-top: var(--space-8); padding: var(--space-4) var(--space-8);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
}
.stat { text-align: center; }
.stat dt { font-size: var(--text-xs); color: var(--text-muted); letter-spacing: 0.02em; }
.stat dd { font-size: var(--text-xl); font-weight: 680; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* ---------- Tabs ---------- */
.tabs-wrap {
  position: sticky; top: var(--header-h); z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.tabs {
  display: flex; gap: var(--space-1);
  height: var(--tabs-h); align-items: center;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 34px; padding: 0 var(--space-4);
  background: transparent; border: none; border-radius: var(--radius-pill);
  color: var(--text-secondary); font-size: var(--text-base); font-weight: 550;
  cursor: pointer; transition: all var(--dur-fast) var(--ease-out);
}
.tab:hover { background: var(--surface-sunken); color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--text); color: var(--bg-elevated);
}
.tab__count {
  min-width: 20px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken); color: var(--text-muted);
}
[data-theme="dark"] .tab[aria-selected="true"] .tab__count { background: rgb(255 255 255 / 0.16); color: var(--text); }
[data-theme="light"] .tab[aria-selected="true"] .tab__count { background: rgb(255 255 255 / 0.22); color: #fff; }

/* ---------- Grid & Cards ---------- */
.main-content { padding: var(--space-8) var(--space-5) var(--space-16); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(252px, 1fr));
  gap: var(--space-4);
}

.card {
  position: relative;
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  text-decoration: none; color: inherit;
  overflow: hidden;
  transition: transform var(--dur-normal) var(--ease-out),
              box-shadow var(--dur-normal) var(--ease-out),
              border-color var(--dur-normal) var(--ease-out);
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--card-accent, var(--primary-500));
  opacity: 0; transition: opacity var(--dur-normal) var(--ease-out);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card:hover::before { opacity: 1; }
.card:active { transform: translateY(-1px); }

.card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.card__mark {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--card-accent, var(--primary-500));
  color: #fff; font-size: var(--text-lg); font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 10px -3px color-mix(in srgb, var(--card-accent, var(--primary-500)) 60%, transparent);
}
.card__mark--compact { font-size: var(--text-base); letter-spacing: -0.01em; }
.card--unlinked { opacity: 0.62; }
.card--unlinked:hover { opacity: 1; }

.card__name {
  font-size: var(--text-lg); font-weight: 620; letter-spacing: -0.015em;
  line-height: 1.3; word-break: break-word;
}
.card__desc {
  font-size: var(--text-base); color: var(--text-secondary);
  line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__foot {
  margin-top: auto; padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
}
.card__cat { font-size: var(--text-xs); color: var(--text-muted); letter-spacing: 0.02em; }
.card__go {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--text-sm); font-weight: 550; color: var(--primary-500);
  transition: gap var(--dur-fast) var(--ease-out);
}
.card__go svg { width: 14px; height: 14px; }
.card:hover .card__go { gap: 8px; }

/* ---------- Empty ---------- */
.empty {
  padding: var(--space-16) 0; text-align: center; color: var(--text-muted);
}
.empty svg { width: 40px; height: 40px; margin-bottom: var(--space-3); opacity: 0.7; }

/* ---------- Footer ---------- */
.site-footer {
  padding: var(--space-8) 0; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: var(--text-sm); text-align: center;
}

/* ---------- Dialog ---------- */
.dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: min(84vh, 760px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--bg-elevated); color: var(--text);
  box-shadow: var(--shadow-xl);
}
.dialog::backdrop { background: rgb(9 12 18 / 0.45); backdrop-filter: blur(3px); }
.dialog[open] { animation: dialogIn var(--dur-normal) var(--ease-out); }
@keyframes dialogIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.dialog__form { display: flex; flex-direction: column; max-height: inherit; }
.dialog__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.dialog__head h2 { font-size: var(--text-lg); font-weight: 620; letter-spacing: -0.015em; }
.dialog__sub { margin-top: 4px; font-size: var(--text-sm); color: var(--text-muted); }

.dialog__body { padding: var(--space-4) var(--space-5); overflow-y: auto; flex: 1; }
.link-row {
  display: grid; grid-template-columns: 1fr; gap: var(--space-2);
  padding: var(--space-3) 0; border-bottom: 1px solid var(--border);
}
.link-row:last-child { border-bottom: none; }
.link-row__label { display: flex; align-items: center; gap: var(--space-2); }
.link-row__dot { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--row-accent); }
.link-row__name { font-size: var(--text-base); font-weight: 560; }
.link-row__cat { font-size: 11px; color: var(--text-muted); }
.link-row input {
  width: 100%; height: 36px; padding: 0 var(--space-3);
  background: var(--surface-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: var(--text-base); font-family: inherit;
  transition: all var(--dur-fast) var(--ease-out);
}
.link-row input:focus {
  outline: none; border-color: var(--primary-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-500) 16%, transparent);
  background: var(--surface);
}
.link-row.is-target {
  background: var(--primary-50);
  border-radius: var(--radius-sm);
  padding-inline: var(--space-2);
  margin-inline: calc(var(--space-2) * -1);
}

.dialog__foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border); background: var(--surface-sunken);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.dialog__foot-left, .dialog__foot-right { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px);
  z-index: 80;
  padding: var(--space-3) var(--space-5);
  background: var(--text); color: var(--bg-elevated);
  border-radius: var(--radius-pill);
  font-size: var(--text-base); font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; transition: opacity var(--dur-normal) var(--ease-out), transform var(--dur-normal) var(--ease-out);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .stats { gap: var(--space-6); padding: var(--space-3) var(--space-5); }
}
@media (max-width: 640px) {
  :root { --space-16: 48px; }
  .hero { padding: var(--space-8) 0 var(--space-6); }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; gap: var(--space-2); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
  .card { padding: var(--space-4); }
  .card__mark { width: 38px; height: 38px; font-size: var(--text-md); }
  .card__name { font-size: var(--text-md); }
  .card__desc { -webkit-line-clamp: 3; }
  .brand__text em { display: none; }
  .btn { padding: 0 var(--space-3); }
  #manageBtn .btn__icon { display: none; }
  .dialog__foot { justify-content: stretch; }
  .dialog__foot-left, .dialog__foot-right { flex: 1; }
  .dialog__foot .btn { flex: 1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
