/* =============================================================================
 * base.css —— 重置、排版基座、背景层、公式排版
 * ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--void);
}
html.is-locked, html.is-locked body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.72;
  letter-spacing: 0.01em;
  background:
    radial-gradient(120% 80% at 50% 0%, #0a1730 0%, #050b18 45%, #03060f 100%) fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* JS 未启用时不应出现空白 */
html:not(.js) #bg,
html:not(.js) .intro { display: none; }
html:not(.js) body { background: #050b18; }

a { color: inherit; text-decoration: none; }
img, canvas, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.18; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

::selection { background: rgba(34, 211, 238, 0.28); color: #fff; }
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- 背景层 -- */
#bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-bg);
  display: block;
  transition: filter 1.4s var(--ease-out), opacity 1.2s var(--ease-out);
  will-change: filter;
}
body.is-revealed #bg { filter: blur(1.4px) saturate(0.92) brightness(0.62); }

/* 极淡的坐标网格：暗示「理性」 */
.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-grid);
  pointer-events: none;
  opacity: 0;
  background-image:
    linear-gradient(to right, rgba(120, 170, 255, 0.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(120, 170, 255, 0.055) 1px, transparent 1px);
  background-size: 84px 84px;
  mask-image: radial-gradient(120% 90% at 50% 45%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(120% 90% at 50% 45%, #000 20%, transparent 78%);
  transition: opacity 2.4s var(--ease-out);
}
body.is-revealed .grid-overlay { opacity: 1; }

/* ------------------------------------------------------------- 公式排版 --- */
.math {
  font-family: var(--math);
  font-style: normal;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  line-height: 1.1;
}
.math i, .math .m-var { font-style: italic; }
.math .m-text, .math .m-fn { font-style: normal; }
.math .m-fn { padding-right: 0.12em; }
.math .m-sym { font-style: normal; }
.math .m-op { font-size: 1.35em; line-height: 0.9; }
.math .m-gap { margin: 0 0.2em; }
.math .m-int { font-size: 1.6em; transform: translateY(0.04em); }
.math .m-big { font-size: 1.5em; }
.math .m-thin { display: inline-block; width: 0.24em; }

/* 上下标：绝对定位，确保在 <span class="math">（inline-flex）里也生效 */
.math .m-base {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}
/* 上下标放进一个独立列，参与正常布局，避免绝对定位压到后续字符 */
.math .m-scripts {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  align-self: stretch;
  margin-left: 0.06em;
  line-height: 1;
  white-space: nowrap;
}
.math .m-scripts .m-sup,
.math .m-scripts .m-sub {
  position: static;
  left: auto;
  margin: 0;
  font-size: 0.62em;
  line-height: 1;
  font-style: normal;
}
.math .m-scripts .m-sup:only-child { margin-bottom: auto; }
.math .m-scripts .m-sub:only-child { margin-top: auto; }

.math .m-sup, .math .m-sub {
  font-size: 0.62em;
  line-height: 1;
  font-style: normal;
}

.math .m-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: -0.42em;
  margin: 0 0.16em;
  font-size: 0.94em;
}
.math .m-frac .m-num { padding: 0 0.22em 0.08em; }
.math .m-frac .m-den {
  padding: 0.08em 0.22em 0;
  border-top: 0.055em solid currentColor;
}
.math .m-sqrt { display: inline-flex; align-items: stretch; }
.math .m-sqrt .m-radic { transform: scaleY(1.18) translateY(-0.04em); }
.math .m-sqrt .m-rad {
  border-top: 0.05em solid currentColor;
  padding: 0.06em 0.14em 0 0.12em;
  margin-left: -0.08em;
}
.math .m-vec { position: relative; }
.math .m-vec::after {
  content: "→";
  position: absolute;
  left: 50%;
  top: -0.72em;
  transform: translateX(-50%) scaleX(0.72);
  font-size: 0.8em;
}
.math .m-hat::after {
  content: "^";
  position: absolute;
  left: 50%;
  top: -0.8em;
  transform: translateX(-50%);
  font-size: 0.9em;
}
.math .m-hat { position: relative; }
.math .m-delim { font-style: normal; padding: 0 0.04em; }

/* 烘焙宿主：不可见但保留真实布局尺寸 */
.bake-host {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 2400px;
  opacity: 0.001;
  pointer-events: none;
  z-index: -1;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}
.bake-host .math { font-size: 30px; color: #dff1ff; }

/* ------------------------------------------------------------- 无障碍 ----- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  padding: 1rem;
  text-align: center;
  background: rgba(232, 121, 249, 0.14);
  border-top: 1px solid var(--line-2);
  color: var(--paper);
  z-index: 100;
}

/* 打印时回到朴素排版 */
@media print {
  #bg, .grid-overlay, .intro, .nav, .scroll-progress, .cursor-halo { display: none !important; }
  body { background: #fff; color: #111; }
}
