/* =============================================================================
 *  base.css —— 重置 / 排版 / 通用工具类
 * -----------------------------------------------------------------------------
 *  美术风格：明朝体标题 + 等线正文，宽字距，刊物式排版，细线分隔
 * ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

/* 刷新恢复滚动位置期间只显示主题底色，避免首页顶部先闪一帧。 */
html.is-booting {
  scroll-behavior: auto;
  background: var(--bg-0);
  /* 数据渲染时若高度短暂变化，浏览器默认滚动锚定会再次挪动位置。 */
  overflow-anchor: none;
}

html.is-booting body {
  visibility: hidden;
  overflow-anchor: none;
}

body {
  min-height: 100dvh;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out);
}

/* 主题切换：只在根节点插值一次颜色变量。
 * 组件颜色通过变量继承同步更新；若让每个元素各自 transition，会在全站
 * 创建数千条动画并造成明显卡顿。 */
html.theme-switching {
  transition-property: --bg-0, --bg-1, --bg-2, --surface, --surface-hover,
    --surface-strong, --border, --border-strong, --text-0, --text-1, --text-2,
    --accent, --accent-soft, --accent-2, --accent-3, --on-accent, --glow-1,
    --glow-2, --ok, --warn, --danger, --grain-opacity, --grid-line,
    --hero-gradient-end, --theme-light, --rainbow-text-1, --rainbow-text-2, --rainbow-text-3,
    --rainbow-text-4, --rainbow-text-5, --rainbow-fill-1, --rainbow-fill-2,
    --rainbow-fill-3, --rainbow-fill-4, --rainbow-fill-5;
  transition-duration: var(--dur);
  /* 主题色用对称缓动。若沿用普通控件的 ease-out，文字会在前 1/5 时间内
   * 走完大半颜色，看起来像“瞬间切换”，而背景仍停在中间色。 */
  transition-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
}

html.theme-sampling {
  transition: none !important;
}

html.theme-switching body,
html.theme-switching body *,
html.theme-switching body *::before,
html.theme-switching body *::after {
  /* 临时关闭组件自己的短时长 transition，避免它们在根变量之后追赶。
   * 这不新建动画，只让同一帧的变量值直接绘制。 */
  transition: none !important;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

/* 有些元素被设成 flex / grid，hidden 属性会被覆盖，这里强制生效 */
[hidden] {
  display: none !important;
}

img {
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

/* ---- 焦点可见（键盘操作） -------------------------------------------------- */
:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---- 滚动条 ---------------------------------------------------------------- */
/* 原生 WebKit 滚动条伪元素对颜色过渡支持不稳定，改用普通元素绘制。
 * 原生根滚动条只负责保留滚动能力和右侧留白，视觉部分交给 ui-float.js。 */
html.has-custom-scrollbar {
  scrollbar-width: none;
  scrollbar-gutter: stable;
}

@supports selector(::-webkit-scrollbar) {
  html.has-custom-scrollbar::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}

.site-scrollbar {
  position: fixed;
  inset-block: 0;
  right: 0;
  z-index: calc(var(--z-toast) + 10);
  width: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  touch-action: none;
  transition: opacity var(--dur-fast) var(--ease-out),
    visibility var(--dur-fast) linear;
}

.site-scrollbar.is-scrollable {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* 站点菜单打开时主页面被锁定，让菜单自身保留可用的滚动条。 */
body.is-menu-open .site-scrollbar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.site-scrollbar__thumb {
  position: absolute;
  top: 0;
  right: 3px;
  width: 6px;
  min-height: 36px;
  border-radius: 999px;
  background-color: rgba(127, 127, 127, 0.34);
  pointer-events: none;
  will-change: transform;
  transition: background-color 280ms var(--ease-out);
}

.site-scrollbar:hover .site-scrollbar__thumb,
.site-scrollbar.is-dragging .site-scrollbar__thumb {
  /* 与左侧导航的激活竖条使用同一个强调色。 */
  background-color: var(--accent);
}

/* ---- 排版：标题走明朝体（衬线）+ 宽字距，正文走等线 ------------------------ */
h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  line-height: 1.22;
  font-weight: 550;
  letter-spacing: 0.06em;
  text-wrap: balance;
}

h1 {
  letter-spacing: 0.12em;
}

h2 {
  letter-spacing: 0.08em;
}

p {
  text-wrap: pretty;
}

/* ---- 布局工具 -------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.section {
  position: relative;
  padding-block: var(--section-gap);
}

.section + .section {
  padding-top: 0;
}

.section-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: var(--space-3);
  max-width: 64ch;
  margin-bottom: var(--space-8);
}

/* 眉标：小号宽字距，靠左，下面接一条短细线 */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
}

.eyebrow::before,
.eyebrow::after {
  content: "";
  width: 26px;
  height: 1px;
  background: var(--accent);
  opacity: 0.55;
}

.section-title {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: 0.1em;
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 3rem);
}

.section-desc {
  color: var(--text-1);
  font-size: clamp(0.92rem, 0.88rem + 0.2vw, 1.02rem);
  line-height: 1.85;
  max-width: 52ch;
}

.muted {
  color: var(--text-2);
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.88em;
  letter-spacing: 0.02em;
}

/* 标题不再用发光渐变；强调文字用薄荷到砖红的一抹墨色渐变 */
.gradient-text {
  background: linear-gradient(
    100deg,
    var(--text-0) 0%,
    var(--accent) 52%,
    var(--hero-gradient-end) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon {
  flex: none;
  display: block;
}

/* ---- 无障碍：仅屏幕阅读器 -------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- 入场动画：只淡入，不改变元素位置 -------------------------------------- */
.reveal {
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
  transition-delay: var(--reveal-delay, 0ms);
  will-change: opacity;
}

.reveal.is-in {
  opacity: 1;
}

/* ---- 尊重「减少动效」系统设置 ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .reveal {
    opacity: 1;
  }
}

/* =============================================================================
 * 圆角策略：扁平哑光，统一用很小的直角微圆角，不再使用 squircle 连续圆角
 * ========================================================================== */

/* ---- 全站浮动控件：左下角主题切换、右下角返回顶部 -------------------------- */
.float-ctl {
  position: fixed;
  z-index: var(--z-float);
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-0);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease,
    background var(--dur-fast) ease, transform var(--dur) var(--ease-out),
    opacity var(--dur) var(--ease-out), visibility var(--dur);
}

.float-ctl:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.float-ctl--theme {
  left: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
}

.float-ctl__theme-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.float-ctl__theme-glyph--sun {
  opacity: calc(1 - var(--theme-light));
  transform: rotate(calc(18deg * var(--theme-light)))
    scale(calc(1 - 0.16 * var(--theme-light)));
}

.float-ctl__theme-glyph--moon {
  opacity: var(--theme-light);
  transform: rotate(calc(-18deg * (1 - var(--theme-light))))
    scale(calc(0.84 + 0.16 * var(--theme-light)));
}

.float-ctl--top {
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
}

.float-ctl--top .float-ctl__icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity var(--dur-fast) ease, transform var(--dur) var(--ease-out);
}

.float-ctl--top .float-ctl__icon svg {
  display: block;
  width: 20px;
  height: 20px;
}

.float-ctl__icon--top {
  opacity: 1;
  transform: none;
}

.float-ctl__icon--home {
  opacity: 0;
  transform: translateY(5px) scale(0.78) rotate(-10deg);
}

.float-ctl--top.is-home .float-ctl__icon--top {
  opacity: 0;
  transform: translateY(-5px) scale(0.78) rotate(10deg);
}

.float-ctl--top.is-home .float-ctl__icon--home {
  opacity: 1;
  transform: none;
}

.float-ctl--top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

/* 按钮压到正文时：主页把主题钮并入顶栏；子页面不再保留独立主题浮钮。
 * 必须保留 relative 作为日/月图标的定位锚点，否则绝对定位图标会以整个
 * fixed 顶栏为参照而跑到品牌名旁边。 */
.float-ctl--in-header {
  position: relative;
  inset: auto;
  flex: none;
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  box-shadow: none;
}

.float-ctl--in-header:hover {
  color: var(--text-0);
  border-color: var(--border-strong);
}

html[data-float-layout="compact"][data-page-kind="subpage"] .float-ctl--theme {
  display: none;
}
