/* ================= Agent Lab ================= */
:root {
  --bg-0: #05070f; --bg-1: #0a0f1e; --bg-2: #10141c;
  --fg: #e6ecf5; --fg-dim: #94a3b8; --fg-faint: #64748b;
  --accent: #5eead4; --accent-hover: #22d3ee;
  /* 品牌锚色 */
  --r0: #2dd4bf; --r1: #22d3ee; --r2: #3b82f6; --r3: #8b5cf6; --r4: #d946ef;
  --sun: #f6c453; --ember: #ff7a59; --leaf: #9be66d;
  --ok: #34d399; --fail: #f87171; --warn: #fbbf24;
  --glass-bg: rgba(15, 23, 42, .55);
  --glass-border: rgba(148, 163, 184, .18);
  --glass-blur: 14px;
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; }
[hidden] { display: none !important; }

body {
  margin: 0; min-height: 100vh; color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 16px; line-height: 1.75; letter-spacing: 0;
  /* CSS 兜底背景：canvas 只是增强，bg.js 缺席时依然好看 */
  background:
    radial-gradient(1200px 800px at 70% -10%, #1b2a4a, transparent 60%),
    radial-gradient(900px 600px at 10% 110%, #17313b, transparent 55%),
    var(--bg-0);
}

#bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; width: 100%; height: 100%; }

code, pre, .mono { font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace; }

:focus-visible { outline: 2px solid var(--r1); outline-offset: 2px; }

/* ---------- 玻璃卡 ---------- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
}
@supports not (backdrop-filter: blur(1px)) {
  .glass { background: rgba(10, 15, 30, .88); }
}

/* ---------- 渐变字 ---------- */
.grad-text {
  background: linear-gradient(120deg, var(--r0), var(--r2), var(--r3));
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  color: transparent; text-decoration: none;
}

/* ---------- 顶栏 ---------- */
header {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem clamp(1rem, 4vw, 2.5rem);
  background: rgba(5, 7, 15, .6);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(148, 163, 184, .1);
}
#logo { font-size: 1.3rem; font-weight: 700; }
nav { display: flex; align-items: center; gap: .25rem; }
nav a, nav button {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .8rem;
  color: var(--fg-dim); text-decoration: none; font-size: .95rem;
  background: none; border: none; cursor: pointer; border-radius: 8px;
}
nav a:hover, nav button:hover { color: var(--accent-hover); }
#motion-toggle[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
#account-link { gap: .45rem; max-width: 11rem; }
#account-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-avatar {
  flex: 0 0 auto; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #06111b; font-size: .78rem; font-weight: 800; line-height: 1;
  background: linear-gradient(135deg, var(--r0), var(--r2));
  box-shadow: 0 0 0 1px rgba(94, 234, 212, .28);
}
.panel-session-bridge {
  position: fixed; width: 1px; height: 1px; left: -10000px; bottom: 0;
  border: 0; opacity: 0; pointer-events: none;
}

/* ---------- 布局 ---------- */
main { max-width: 72rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem); }

#hero { min-height: 58vh; display: flex; flex-direction: column; justify-content: center; padding: 4rem 0 2rem; }
#hero h1 { font-size: 3.5rem; line-height: 1.05; font-weight: 800; margin: .15rem 0 .65rem; }
#slogan { font-size: 1.35rem; color: var(--fg); margin: 0 0 .8rem; min-height: 1.5em; }
#slogan span { opacity: 0; display: inline-block; }
.intro { color: var(--fg-dim); margin: 0; max-width: 42rem; }
.eyebrow {
  margin: 0 0 .45rem; color: var(--sun); font-size: .78rem;
  text-transform: uppercase; letter-spacing: 0;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.6rem; }
.action-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 1rem; text-decoration: none; border-radius: 8px;
}
.btn-secondary {
  min-height: 44px; padding: 0 1rem; border-radius: 8px;
  color: var(--fg); border: 1px solid rgba(246, 196, 83, .36);
  background: rgba(246, 196, 83, .08); font-weight: 600;
}
.signal-row {
  display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1.2rem;
  color: var(--fg-dim); font-size: .88rem;
}
.signal-row span {
  min-height: 32px; display: inline-flex; align-items: center;
  padding: 0 .7rem; border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, .16);
  background: rgba(5, 7, 15, .34);
}

.portal-grid, .topic-grid, .module-grid, .agent-board {
  display: grid; gap: 1rem; padding-bottom: 1.8rem;
}
.portal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.topic-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.module-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.agent-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.portal-card, .topic-card, .module-card, .agent-card, .release-note {
  position: relative; overflow: hidden; color: var(--fg); text-decoration: none;
  padding: 1.2rem; min-height: 100%;
}
.portal-card { min-height: 15rem; display: flex; flex-direction: column; justify-content: flex-end; }
.portal-card::after, .agent-card::after, .module-card::after {
  content: ""; position: absolute; inset: auto 0 0; height: 3px;
  background: linear-gradient(90deg, var(--r0), var(--sun), var(--ember));
  opacity: .65;
}
.portal-card h2, .topic-card h2, .agent-card h2, .release-note h2 {
  margin: .25rem 0 .5rem; font-size: 1.25rem; line-height: 1.35;
}
.portal-card p, .topic-card p, .module-card p, .agent-card p, .release-note p {
  margin: 0; color: var(--fg-dim);
}
.kicker {
  color: var(--leaf); font-size: .74rem; text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
.portal-cta { margin-top: 1rem; color: var(--accent); font-weight: 700; }

.flow-section { padding: 1.5rem 0 .8rem; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-head h2 { margin: 0; font-size: 1.45rem; line-height: 1.25; }
.section-head .eyebrow { margin: 0; }

.module-card h3 {
  margin: .3rem 0 .45rem; font-size: 1.02rem; line-height: 1.35;
}
.module-card .module-index {
  color: var(--sun); font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
  font-size: .8rem;
}
.hotspot-card { display: flex; flex-direction: column; min-height: 26rem; }
.hotspot-list { display: grid; gap: .65rem; margin-top: 1rem; }
.hotspot-item {
  display: block; color: var(--fg); text-decoration: none;
  padding: .65rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, .12);
  background: rgba(5, 7, 15, .25);
}
.hotspot-item strong { display: block; color: var(--accent); line-height: 1.35; }
.hotspot-item span { display: block; margin-top: .25rem; color: var(--fg-faint); font-size: .86rem; line-height: 1.55; }

.page-hero { padding: 2rem 0 1.3rem; max-width: 46rem; }
.page-hero h1 { margin: .2rem 0 .5rem; font-size: 2.4rem; line-height: 1.15; }
.page-hero p:not(.eyebrow) { margin: 0; color: var(--fg-dim); }

.agent-card { min-height: 15rem; display: flex; flex-direction: column; }
.agent-card .status {
  align-self: flex-start; min-height: 28px; display: inline-flex; align-items: center;
  padding: 0 .6rem; border-radius: 8px; font-size: .78rem; color: #071015;
  background: var(--sun); font-weight: 700;
}
.agent-card .status.live { background: var(--leaf); }
.agent-card .status.planned { background: var(--fg-dim); }
.agent-card .agent-meta { margin-top: auto; padding-top: 1rem; color: var(--fg-faint); font-size: .84rem; }
.release-note { margin: .5rem 0 4rem; }

.ops-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; padding-bottom: 1rem; }
.ops-card, .role-banner, .user-panel, .ops-sop { padding: 1.15rem; }
.role-banner { margin-bottom: 1rem; }
.role-banner h2, .ops-card h2, .user-panel h2, .ops-sop h2 {
  margin: .25rem 0 .45rem; font-size: 1.12rem; line-height: 1.35;
}
.role-banner p, .ops-card p, .user-panel p, .ops-sop p, .ops-sop li { color: var(--fg-dim); }
.user-panel { margin: .2rem 0 1rem; }
.user-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; align-items: end; margin-top: 1rem; }
.user-form label { color: var(--fg-dim); font-size: .9rem; }
.user-form input, .user-form select {
  width: 100%; min-height: 44px; margin-top: .25rem; padding: .5rem .65rem;
  border-radius: 8px; border: 1px solid var(--glass-border);
  background: rgba(5, 7, 15, .45); color: var(--fg);
}
.inline-btn { width: auto; margin-top: 0; padding: 0 1rem; }
.ops-sop { margin: .5rem 0 4rem; }
.ops-sop ul { margin: .7rem 0 1rem; padding-left: 1.2rem; }
.ops-sop code {
  background: rgba(94, 234, 212, .08); padding: .1em .35em;
  border-radius: 4px; color: var(--accent);
}
.ops-sop a { color: var(--accent); text-decoration: none; font-weight: 700; }

/* ---------- 文章卡片 ---------- */
.cards { display: grid; grid-template-columns: 1fr; gap: 1.2rem; padding-bottom: 4rem; }
.cards.compact { padding-bottom: 2.5rem; }
@media (min-width: 720px) { .cards { grid-template-columns: 1fr 1fr; } }

.card {
  position: relative; display: block; padding: 1.3rem 1.5rem;
  color: var(--fg); text-decoration: none; min-height: 110px;
}
.card h3 {
  margin: 0 0 .4rem; font-size: 1.125rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { margin: 0; }
.meta { color: var(--fg-faint); font-size: 13px; }

/* 渐变描边（hover 时点亮） */
.card::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: linear-gradient(135deg, var(--r0), var(--r2), var(--r4));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0; pointer-events: none;
}

.card-empty, .card-error { padding: 2rem; text-align: center; color: var(--fg-dim); grid-column: 1 / -1; }

/* ---------- 文章页 ---------- */
.article-card { max-width: 42rem; margin: 2rem auto 4rem; padding: clamp(1.2rem, 4vw, 2.5rem); }
.back { color: var(--accent); text-decoration: none; font-size: .9rem; }
#article-title { margin: .8rem 0 .3rem; font-size: 2rem; line-height: 1.3; }
article h2, article h3, article h4 {
  padding-left: .7rem; border-left: 3px solid transparent;
  border-image: linear-gradient(180deg, var(--r0), var(--r3)) 1;
  margin-top: 2rem;
}
article { content-visibility: auto; }
article pre {
  background: #10182b; border-radius: 12px; padding: 1rem; overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, .12); font-size: .88rem; line-height: 1.6;
}
article code { background: rgba(94, 234, 212, .08); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
article pre code { background: none; padding: 0; }
article blockquote {
  margin: 1rem 0; padding: .3rem 1rem; color: var(--fg-dim);
  border-left: 3px solid var(--glass-border);
}
article a {
  color: var(--accent); text-decoration: none;
  background: linear-gradient(currentColor, currentColor) no-repeat 0 100% / 0% 1.5px;
}
article a:hover { color: var(--accent-hover); }

/* ---------- 阅读进度条 ---------- */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 99;
  transform-origin: 0 50%; transform: scaleX(0);
  background: linear-gradient(90deg, var(--r0), var(--r2), var(--r4));
  display: none;
}
#progress.on { display: block; }

/* ---------- 面板 ---------- */
.panel-head { display: flex; align-items: center; gap: .8rem; margin: 2rem 0 1rem; }
.panel-head h2 { margin: 0; font-size: 1.3rem; }
#panel-refresh {
  min-width: 44px; min-height: 44px; border-radius: 10px; cursor: pointer;
  background: var(--glass-bg); color: var(--fg-dim); border: 1px solid var(--glass-border);
  font-size: 1.1rem;
}
#panel-refresh:hover { color: var(--accent-hover); }
.refresh-icon { display: inline-block; }
.panel-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem; padding-bottom: 4rem;
}
.svc { padding: 1.1rem 1.3rem; }
.svc-head { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; position: relative; flex: none; }
.dot.ok { background: var(--ok); }
.dot.fail { background: var(--fail); }
.dot.unknown { background: var(--fg-faint); }
.dot.ok::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: var(--ok); opacity: .6;
}
.svc .mono { color: var(--fg-dim); font-size: .85rem; margin: .4rem 0 .2rem; }
.svc .meta { margin: 0; }

/* ---------- 登录 ---------- */
dialog { color: var(--fg); padding: 1.8rem 2rem; max-width: 22rem; width: 90%; }
dialog::backdrop { background: rgba(5, 7, 15, .6); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 1rem; }
dialog label { display: block; margin: .7rem 0; color: var(--fg-dim); font-size: .9rem; }
dialog input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  background: rgba(5, 7, 15, .5); color: var(--fg);
  border: 1px solid var(--glass-border); border-radius: 8px; font-size: 1rem;
}
dialog input:focus { border-color: var(--r1); outline: none; }
.error { color: var(--fail); font-size: .9rem; }

.btn-primary {
  margin-top: .8rem; width: 100%; min-height: 44px; cursor: pointer;
  background: linear-gradient(120deg, var(--r0), var(--r2));
  color: #04121a; font-weight: 600; font-size: 1rem;
  border: none; border-radius: 10px;
}
.hero-actions .btn-primary, .hero-actions .btn-secondary { width: auto; margin-top: 0; }

footer {
  text-align: center; padding: 2rem 0 2.5rem; color: var(--fg-faint);
  border-top: 1px solid rgba(148, 163, 184, .08); margin-top: 2rem;
}

/* ---------- 骨架屏 ---------- */
.skeleton { min-height: 110px; overflow: hidden; position: relative; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(148, 163, 184, .1) 50%, transparent 70%);
  background-size: 200% 100%;
}

/* ---------- 视图切换基础态 ---------- */
main > section { min-height: 40vh; }

/* ================= 动效（全部包在 no-preference 内） ================= */
@media (prefers-reduced-motion: no-preference) {
  .grad-text { animation: grad-flow 8s linear infinite; }
  @keyframes grad-flow { to { background-position: 200% center; } }

  #slogan span { animation: char-in .5s cubic-bezier(.22, 1, .36, 1) forwards; }
  @keyframes char-in { from { opacity: 0; transform: translateY(.4em); } to { opacity: 1; transform: none; } }

  .view-enter { animation: view-in .24s ease-out; }
  @keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  .card, .svc, .portal-card, .topic-card, .module-card, .agent-card, .release-note, .ops-card, .role-banner, .user-panel, .ops-sop { opacity: 0; transform: translateY(12px); }
  .card.in, .svc.in, .portal-card.in, .topic-card.in, .module-card.in, .agent-card.in, .release-note.in, .ops-card.in, .role-banner.in, .user-panel.in, .ops-sop.in {
    opacity: 1; transform: none;
    transition: opacity .5s cubic-bezier(.22, 1, .36, 1), transform .5s cubic-bezier(.22, 1, .36, 1);
  }
  .card, .portal-card, .module-card, .agent-card {
    transition: opacity .5s cubic-bezier(.22, 1, .36, 1), transform .5s cubic-bezier(.22, 1, .36, 1), box-shadow .2s;
  }
  .card::before { transition: opacity .25s; }

  @media (hover: hover) {
    .card.in:hover { transform: translateY(-4px); box-shadow: 0 12px 40px rgba(45, 212, 191, .12); }
    .portal-card.in:hover, .agent-card.in:hover { transform: translateY(-5px); box-shadow: 0 18px 48px rgba(246, 196, 83, .11); }
    .module-card.in:hover { transform: translateY(-3px); }
    .card:hover::before { opacity: .7; }
  }
  .card:active { transform: scale(.99); }

  .btn-primary { transition: transform .3s cubic-bezier(.34, 1.56, .64, 1); }
  .btn-primary:hover { transform: translateY(-2px); }
  .btn-primary:active { transform: scale(.96); transition-duration: .1s; }

  article a { transition: background-size .25s, color .15s; }
  article a:hover { background-size: 100% 1.5px; }

  .skeleton::after { animation: shimmer 1.4s infinite; }
  @keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

  .dot.ok::after { animation: ping 2s cubic-bezier(0, 0, .2, 1) infinite; }
  @keyframes ping { 75%, 100% { transform: scale(2.2); opacity: 0; } }

  dialog.shake { animation: shake .3s; }
  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); } 75% { transform: translateX(8px); }
  }

  .spin { animation: spin .8s ease; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

@media (prefers-reduced-motion: reduce) {
  #progress { display: none !important; }
  #slogan span { opacity: 1; }
}

/* ---------- 移动端：降合成开销 ---------- */
@media (max-width: 720px) {
  :root { --glass-blur: 8px; --glass-bg: rgba(15, 23, 42, .68); }
  #hero { min-height: 50vh; padding-top: 3rem; }
  #hero h1 { font-size: 2.4rem; }
  #slogan { font-size: 1.12rem; }
  .portal-grid, .topic-grid, .module-grid, .agent-board, .ops-grid, .user-form { grid-template-columns: 1fr; }
  .portal-card, .agent-card { min-height: 12rem; }
  .hotspot-card { min-height: auto; }
  .section-head { display: block; }
  .page-hero h1 { font-size: 2rem; }
  #article-title { font-size: 1.55rem; }
  nav a, nav button { padding: 0 .55rem; }
}

@media (max-width: 420px) {
  header { align-items: flex-start; gap: .5rem; }
  nav { flex-wrap: wrap; justify-content: flex-end; }
  .hero-actions { display: grid; grid-template-columns: 1fr; }
  .signal-row span { width: 100%; }
}
