/* Formatting Box — 日月为易（DESIGN.md v2）
   唯一视觉依据：docs/DESIGN.md（双极色板 / 日月场景 / 母题 / 动效白名单） */

/* ---- 自托管 JetBrains Mono（仅拉丁子集，约 21KB；CJK 不自托管） ---- */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #1A1D23;
  --surface: #232830;
  --line: rgba(214, 219, 228, 0.12); /* 银色 hairline */
  --text: #E8EBF1;
  --text-dim: #98A0AD;
  --moon: #D3D9E4; /* 月极·寒光银：交互反馈 */
  --sun: #B5977A;  /* 日极·氧化铜：印记与警示 */
  --sky: #14161B;  /* hero 天空层：比 --bg 深半档，夜空护月（DESIGN.md §1） */

  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', serif;
  --font-sans: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  --content: 880px;
}

/* 日月权重与日弧升沉：@property 注册使 CSS 变量本身可过渡（DESIGN.md §4-5），
   指针互动与回落全程缓动无跳变。app.js 按时刻写基线、按指针距离加权。 */
@property --moon-w {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.6;
}
@property --sun-w {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.6;
}
@property --sun-lift {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.6;
}

/* 权重变量挂在 :root（app.js 写入），.sky 与 .horizon--sky 均可继承；
   缓动在此统一（DESIGN.md §4-5） */
html {
  transition: --moon-w 1.4s ease, --sun-w 1.4s ease, --sun-lift 1.4s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.85;
}

.mono { font-family: var(--font-mono); }

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

/* ---- 入场淡入（DESIGN.md §4-2）。带静态 transform 的元素用 rise-fade ---- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
}
@keyframes rise-fade {
  from { opacity: 0; }
}
.rise { animation: rise 0.9s ease both; animation-delay: calc(var(--d, 0) * 0.12s); }
.rise-fade { animation: rise-fade 0.9s ease both; animation-delay: calc(var(--d, 0) * 0.12s); }

/* ---- 导航 ---- */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  transition: background 0.3s, border-color 0.3s;
  border-bottom: 1px solid transparent;
}
.nav.scrolled {
  background: rgba(22, 24, 28, 0.85); /* --surface 半透明 */
  -webkit-backdrop-filter: blur(10px); /* Safari ≤17 只认 -webkit- 前缀 */
  backdrop-filter: blur(10px);
  border-bottom-color: var(--line);
}
.nav-inner {
  max-width: var(--content);
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.nav-links { display: flex; gap: 1.75rem; font-size: 0.88rem; color: var(--text-dim); }
.nav-links a { transition: color 0.3s; }
.nav-links a:hover { color: var(--moon); }

/* ---- Hero（hero-band 全宽承载 --sky 天空层，地平线为明度分界）---- */
.hero-band { background: var(--sky); }
.hero {
  position: relative;
  min-height: 92vh;
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
}
.hero-main { width: 100%; position: relative; z-index: 1; }

/* ---- 日月平衡场景（背景层，DESIGN.md §3b）---- */
.sky {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
/* 新月：圆 + 内侧偏移圆相叠挖出月牙；亮度随 --moon-w */
.sky .moon {
  position: absolute;
  top: 16%;
  left: 6%;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  box-shadow: inset -9px 7px 0 0 rgba(211, 217, 228, 0.9);
  transform: rotate(-18deg);
  opacity: calc(0.45 + var(--moon-w) * 0.45);
}
.sky .moon-glow {
  position: absolute;
  top: calc(16% - 90px);
  left: calc(6% - 90px);
  width: 222px;
  height: 222px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(211, 217, 228, 0.9), transparent 72%);
  /* 冷晕半径随权重放大（v2.2 加幅：scale ≈0.9–1.6） */
  transform: scale(calc(0.55 + var(--moon-w) * 0.55));
  animation: breathe-moon 90s ease-in-out infinite;
}
/* 沉日：主体沉于地平线之下，只余线上一道弧；随 --sun-lift 升沉、--sun-w 明暗 */
.sky .sun-arc {
  position: absolute;
  bottom: -30px;
  left: 76%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(181, 151, 122, 0.85);
  border-bottom-color: transparent;
  opacity: calc(0.35 + var(--sun-w) * 0.5);
  /* v2.2 加幅：升沉幅度 ±6.4px → ±14px（lift 1.0 时升 14px） */
  transform: translateY(calc((0.6 - var(--sun-lift)) * 35px));
}
.sky .sun-glow {
  position: absolute;
  bottom: -110px;
  left: calc(76% - 88px);
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(181, 151, 122, 0.9), transparent 72%);
  animation: breathe-sun 90s ease-in-out infinite;
}
/* 呼吸：~90s 极缓透明度起伏，权重来自 --moon-w / --sun-w（DESIGN.md §4-3） */
/* v2.2 加幅：冷晕峰值 0.20→0.30、暖晕 0.17→0.26 */
@keyframes breathe-moon {
  0%, 100% { opacity: calc(var(--moon-w) * 0.20); }
  50% { opacity: calc(var(--moon-w) * 0.30); }
}
@keyframes breathe-sun {
  0%, 100% { opacity: calc(var(--sun-w) * 0.18); }
  50% { opacity: calc(var(--sun-w) * 0.26); }
}

.site-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(3.4rem, 11vw, 7rem);
  line-height: 1.04;
  letter-spacing: 0.01em;
}

/* 母题 c：镜面 —— scaleY(-1)，透明度约 0.13，裁剪至约半字高 */
.mirror {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(3.4rem, 11vw, 7rem);
  line-height: 1.04;
  letter-spacing: 0.01em;
  transform: scaleY(-1);
  opacity: 0.13;
  height: 0.52em;
  overflow: hidden;
  -webkit-user-select: none; /* Safari ≤18.3 只认 -webkit- 前缀 */
  user-select: none;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 90%);
  mask-image: linear-gradient(to bottom, #000 0%, transparent 90%);
}

.motto {
  margin-top: 2.2rem;
  font-family: var(--font-serif);
  color: var(--text-dim);
  font-size: 1.02rem;
  letter-spacing: 0.06em;
}

/* 母题 e：竖排「且易生」+ 生印（旧铜底） */
.vertical-motto {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  z-index: 1;
}
.v-text {
  writing-mode: vertical-rl;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  letter-spacing: 0.55em;
  color: var(--text-dim);
}
.seal {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  background: var(--sun);
  color: var(--bg);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  line-height: 1;
}

/* 母题 a：地平线（日月分野 / 明度分界）—— 左寒银右旧铜，均衡交汇点约 58% */
.horizon {
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(211, 217, 228, 0.9) 26%,
    rgba(211, 217, 228, 0.15) 57%,
    rgba(181, 151, 122, 0.15) 59%,
    rgba(181, 151, 122, 0.85) 82%,
    transparent 100%);
}
/* hero 侧地平线：双色明度随权重向所悬停一极偏移（v2.2，DESIGN.md §3b） */
.horizon--sky { position: relative; background: none; }
.horizon--sky::before,
.horizon--sky::after {
  content: "";
  position: absolute;
  inset: 0;
}
.horizon--sky::before {
  background: linear-gradient(90deg,
    transparent 0%, rgba(211, 217, 228, 0.9) 26%, rgba(211, 217, 228, 0.12) 58%, transparent 62%);
  opacity: calc(0.3 + var(--moon-w) * 0.35);
}
.horizon--sky::after {
  background: linear-gradient(90deg,
    transparent 54%, rgba(181, 151, 122, 0.12) 58%, rgba(181, 151, 122, 0.85) 82%, transparent 100%);
  opacity: calc(0.3 + var(--sun-w) * 0.35);
}

/* ---- 区块 ---- */
.section {
  max-width: var(--content);
  margin: 0 auto;
  padding: 5.5rem 1.5rem 4.5rem;
}
.section-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  margin-bottom: 2.4rem;
}

/* 母题 d：爻线 —— 阴爻即月，阳爻即日 */
.yao {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0.4rem 0;
}
.yao .yin { display: flex; gap: 6px; transition: gap 0.3s; }
.yao .yin i,
.yao .yang {
  display: block;
  height: 1px;
  transition: background 0.3s, opacity 0.3s;
}
.yao .yin i { width: 14px; background: var(--text-dim); opacity: 0.65; }
.yao .yang { width: 28px; background: var(--sun); opacity: 0.55; } /* 阳爻常态微含旧铜 */
.yao:hover .yin { gap: 0; }
.yao:hover .yin i { background: var(--moon); opacity: 1; } /* 月满则易 */

/* ---- 分类栏（v2.2）：mono 小字，选中态寒银下划线，克制，可换行 ---- */
.cat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  margin-bottom: 1.8rem;
}
.cat-item {
  background: none;
  border: none;
  padding: 0 0 2px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: color 0.3s, border-color 0.3s;
}
.cat-item:hover { color: var(--moon); }
.cat-item.is-selected { color: var(--moon); border-bottom-color: var(--moon); }

/* ---- 内嵌媒体与下载链接（v2.2，DESIGN.md §5-01）---- */
.entry-body .media-img {
  display: block;
  max-width: 100%;
  border-radius: 4px;
  border: 1px solid var(--line);
  margin: 1rem 0;
}
.entry-body .media-file {
  display: block;
  margin: 0.6rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: color 0.3s;
}
.entry-body .media-file:hover { color: var(--moon); }

.list-status {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ---- 文章：账本式列表，行可展开（details/summary，纯 CSS）---- */
.ledger { display: flex; flex-direction: column; }
.entry-item { border-bottom: 1px solid var(--line); }
.entry-item:first-child { border-top: 1px solid var(--line); }
.entry {
  display: flex;
  align-items: baseline;
  gap: 1.6rem;
  padding: 1.05rem 0.2rem;
  cursor: pointer;
  list-style: none;
}
.entry::-webkit-details-marker { display: none; }
.entry time {
  font-size: 0.8rem;
  color: var(--text-dim);
  flex-shrink: 0;
}
.entry-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  background-image: linear-gradient(var(--moon), var(--moon));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition: background-size 0.3s;
  padding-bottom: 2px;
}
.entry:hover .entry-title { background-size: 100% 1px; }
.entry-item[open] .entry-title { background-size: 100% 1px; } /* 展开态标记：寒银下划线 */
.entry .arrow {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.85rem;
  transition: color 0.3s, transform 0.3s; /* 展开过渡（DESIGN.md §4-4） */
}
.entry:hover .arrow { color: var(--moon); }
.entry-item[open] .arrow { color: var(--moon); transform: rotate(90deg); }
.entry-body {
  font-family: var(--font-serif);
  max-width: 64ch;
  padding: 0.2rem 0.2rem 1.8rem;
  line-height: 2.05;
}
.entry-body p + p { margin-top: 1rem; }
.entry-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  margin-bottom: 1.2rem;
}
.entry-body .placeholder { color: var(--text-dim); }

/* ---- 联系 ---- */
.contact-line {
  font-size: 0.88rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: baseline;
}
.contact-line a { transition: color 0.3s; }
.contact-line a:hover { color: var(--moon); }
.contact-line .sep { opacity: 0.4; }

/* ---- 留言（输入聚焦寒银；错误旧铜）---- */
.gb-form { margin-bottom: 2.2rem; }
.gb-form textarea {
  width: 100%;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.8rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.7;
  transition: border-color 0.3s;
}
.gb-form textarea:focus {
  outline: none;
  border-color: var(--moon);
}
.gb-actions {
  margin-top: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.gb-status { font-size: 0.78rem; color: var(--text-dim); min-height: 1.2em; }
.gb-status.is-error { color: var(--sun); }
#gb-submit {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.35rem 1.1rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}
#gb-submit:hover:not(:disabled) { border-color: var(--sun); color: var(--sun); } /* 落笔即印记 */
#gb-submit:disabled { opacity: 0.45; cursor: default; }

.gb-entry {
  display: flex;
  align-items: baseline;
  gap: 1.4rem;
  padding: 1rem 0.2rem;
  border-bottom: 1px solid var(--line);
}
.gb-entry:first-child { border-top: 1px solid var(--line); }
.gb-meta {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.gb-text {
  font-family: var(--font-serif);
  font-size: 1rem;
  overflow-wrap: anywhere;
}
/* ---- Footer ---- */
.footer {
  max-width: var(--content);
  margin: 0 auto;
  padding: 2.2rem 1.5rem 2.6rem;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
}
.footer-right { font-size: 0.78rem; color: var(--text-dim); }

/* ---- 降级动效（DESIGN.md §4：reduced-motion 关闭全部动效，日月静止于均衡态）---- */
@media (prefers-reduced-motion: reduce) {
  .rise, .rise-fade { animation: none; }
  html { transition: none; }
  .sky .moon-glow { animation: none; opacity: calc(var(--moon-w) * 0.16); }
  .sky .sun-glow { animation: none; opacity: calc(var(--sun-w) * 0.14); }
}

/* ---- 移动端（<720px，DESIGN.md §6）---- */
@media (max-width: 719px) {
  .hero {
    min-height: 86vh;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 2.6rem;
  }
  .vertical-motto {
    position: static;
    transform: none;
    flex-direction: row;
    align-items: center;
    gap: 0.9rem;
  }
  .v-text { writing-mode: horizontal-tb; letter-spacing: 0.4em; font-size: 1rem; }
  .seal { width: 24px; height: 24px; font-size: 0.85rem; }

  /* 日月场景缩小，不遮挡文字 */
  .sky .moon { width: 30px; height: 30px; box-shadow: inset -7px 5px 0 0 rgba(199, 205, 216, 0.85); }
  .sky .moon-glow { width: 150px; height: 150px; top: calc(16% - 60px); left: calc(6% - 60px); }
  .sky .sun-arc { width: 34px; height: 34px; bottom: -22px; }
  .sky .sun-glow { width: 150px; height: 150px; bottom: -75px; left: calc(76% - 60px); }

  .section { padding: 4rem 1.25rem 3.4rem; }

  .entry { flex-wrap: wrap; gap: 0.35rem 1rem; }
  .entry time { width: 100%; }
  .entry .arrow { margin-left: auto; }

  .gb-entry { flex-direction: column; gap: 0.35rem; }
  .gb-meta { flex-direction: row; gap: 0.9rem; }

  .footer { flex-direction: column; gap: 0.5rem; }
}
