/* =========================================================
   Base —— 重置、背景材质、排版、布局工具、动效基础
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  font-family: var(--font-sans); font-size: var(--text-base); line-height: 1.75;
  color: var(--color-text); background: var(--color-bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg, canvas { display: block; max-width: 100%; }
main { flex: 1; }
::selection { background: var(--color-accent-soft); color: var(--color-accent); }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; border-radius: 8px; }

/* ---------- 背景层 1：渐变网格（会缓慢“呼吸”漂移） ---------- */
.bg-mesh {
  position: fixed; inset: -10%; z-index: var(--z-mesh); pointer-events: none; overflow: hidden;
}
.bg-mesh span {
  position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  will-change: transform;
}
.bg-mesh span:nth-child(1) { left: -10%; top: -15%; background: radial-gradient(closest-side, var(--mesh-1), transparent); animation: drift-a 26s var(--ease-in-out) infinite alternate; }
.bg-mesh span:nth-child(2) { right: -15%; top: -5%;  background: radial-gradient(closest-side, var(--mesh-2), transparent); animation: drift-b 32s var(--ease-in-out) infinite alternate; }
.bg-mesh span:nth-child(3) { left: 20%; bottom: -30%; background: radial-gradient(closest-side, var(--mesh-3), transparent); animation: drift-c 28s var(--ease-in-out) infinite alternate; }
.bg-mesh span:nth-child(4) { right: 5%; bottom: -10%; width: 40vmax; height: 40vmax; background: radial-gradient(closest-side, var(--mesh-4), transparent); animation: drift-a 22s var(--ease-in-out) infinite alternate-reverse; }
@keyframes drift-a { to { transform: translate(8vw, 6vh) scale(1.12); } }
@keyframes drift-b { to { transform: translate(-10vw, 8vh) scale(.9); } }
@keyframes drift-c { to { transform: translate(6vw, -10vh) scale(1.08); } }

/* 点阵网格（顶部渐隐） */
.bg-mesh::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(var(--color-border) 1px, transparent 1.2px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse 70% 55% at 50% 10%, #000 10%, transparent 75%);
          mask-image: radial-gradient(ellipse 70% 55% at 50% 10%, #000 10%, transparent 75%);
}

/* ---------- 背景层 2：Three.js 画布 ---------- */
.scene {
  position: fixed; inset: 0; z-index: var(--z-scene); pointer-events: none;
  width: 100vw; height: 100vh; height: 100lvh;
  opacity: 0; transition: opacity 1.2s var(--ease-out);
}
.scene.is-ready { opacity: 1; }
html:not([data-view="home"]) .scene.is-ready { opacity: .55; }

/* ---------- 背景层 3：颗粒纹理（覆盖在最上层） ---------- */
/* inset 只需略大于抖动幅度（±3%），不必铺 4 倍屏幕面积 */
.grain {
  position: fixed; inset: -8%; z-index: var(--z-grain); pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }   20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); } 60% { transform: translate(-2%, -1%); }
  80% { transform: translate(3%, 3%); }  100% { transform: translate(0, 0); }
}

/* ---------- 排版 ---------- */
.display { font-size: var(--text-display); line-height: 1.08; letter-spacing: -.035em; font-weight: 800; }
.h2 { font-size: var(--text-2xl); line-height: 1.2; letter-spacing: -.02em; font-weight: 800; }
.h3 { font-size: var(--text-lg); line-height: 1.35; letter-spacing: -.01em; font-weight: 700; }
.lead { font-size: clamp(17px, 2.1vw, 21px); color: var(--color-text-muted); }
.muted { color: var(--color-text-muted); }
.mono { font-family: var(--font-mono); }
.text-gradient {
  background: var(--gradient-brand); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: hue-flow 8s ease-in-out infinite alternate;
}
@keyframes hue-flow { to { background-position: 100% 0; } }

/* ---------- 布局工具 ---------- */
.container { width: min(var(--container), 100% - var(--gutter) * 2); margin-inline: auto; }
.stack > * + * { margin-top: var(--stack-gap, var(--space-4)); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-3)); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: var(--space-5); }

/* ---------- 动效：滚动渐入 ---------- */
[data-reveal] {
  opacity: 0;
  transform: translate3d(0, 28px, 0) scale(.97);
  filter: blur(6px);
  transition:
    opacity var(--dur-slow) var(--ease-out),
    transform 900ms var(--ease-spring),
    filter var(--dur-slow) var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms);
}
[data-reveal].is-in { opacity: 1; transform: none; filter: none; }
.no-js [data-reveal] { opacity: 1; transform: none; filter: none; }

/* ---------- 性能：手机 / 触屏设备减轻开销 ---------- */
@media (pointer: coarse), (max-width: 760px) {
  /* 颗粒纹理静止不动（视觉几乎一样，省掉持续的全屏合成） */
  .grain { inset: 0; animation: none; }
  /* 渐入动画去掉模糊滤镜，只保留位移和透明度 */
  [data-reveal] { filter: none; transition-property: opacity, transform; }
}

/* ---------- 无障碍：减少动画 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0ms !important; }
  [data-reveal] { opacity: 1; transform: none; filter: none; }
}
