/* ============================================================
   涉川 TRACE
   全站可调值集中在 :root。改气质只改这一段。
   ============================================================ */

:root {
  /* 颜色 —— 只用四个灰阶 + 一个黑 */
  --ink:      #111111;
  --text:     #222222;
  --soft:     #555555;
  --faint:    #999999;
  --ghost:    #AAAAAA;
  --rule:     #E5E5E5;
  --bg:       #FFFFFF;

  /* 排版 */
  --fs-lead:    13.5px;
  --fs-section: 13px;
  --fs-title:   15.5px;
  --fs-label:   12.5px;
  --fs-body:    14.5px;
  --fs-meta:    12px;
  --fs-toc:     12px;

  --lh-body:    1.92;
  --lh-lead:    1.85;
  --ls-body:    .025em;

  /* 尺寸 */
  --measure:    600px;
  --rail:       26px;
  --toc-w:      112px;
  --toc-gap:    56px;

  /* 动效 */
  --ease: cubic-bezier(.22, .61, .36, 1);
  --fast: 160ms;
  --mid:  260ms;

  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
          "Source Han Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--ink); color: #fff; }
a { color: inherit; }
img { -webkit-user-drag: none; }

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
  border-radius: 1px;
}

/* 阅读进度条 */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 1.5px;
  width: 100%;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: var(--ink);
  z-index: 60;
  opacity: 0;
  transition: opacity var(--mid) var(--ease);
  pointer-events: none;
}
.progress.ready { opacity: .85; }

/* ---------- 页面骨架 ---------- */

.page {
  max-width: calc(var(--measure) + var(--rail) + var(--toc-gap) + var(--toc-w));
  margin: 0 auto;
  padding: 88px 40px 72px;
}

/* ---------- 头部 ---------- */

.masthead { margin-bottom: 76px; }

.mast-copy { min-width: 0; }

/* 头部：小图贴标题行右上 */
.mast-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 32px;
}

.mast-copy { min-width: 0; }

.mast-illu {
  display: block;
  width: 110px;
  height: auto;
  margin-top: 0;
  align-self: start;
}

.wordmark-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.wordmark {
  display: block;
  height: 22px;
  width: auto;
  color: var(--ink);
  flex: none;
  align-self: center;
}
.wordmark svg { display: block; height: 22px; width: auto; }

.wordmark-latin {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--faint);
  transform: translateY(-1px);
}

.subtitle {
  margin: 0 0 24px;
  font-size: var(--fs-lead);
  line-height: var(--lh-lead);
  letter-spacing: .04em;
  color: #8C8C8C;
}

/* 正文引言：同一个字号、行距、颜色，只有段间距 */
.intro {
  max-width: 520px;
  font-size: var(--fs-lead);
  line-height: var(--lh-lead);
  letter-spacing: .02em;
  color: #5E5E5E;
}

.intro p { margin: 0 0 10px; }
.intro p:last-child { margin-bottom: 0; }

.about-link {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid #C9C9C9;
  padding-bottom: 1px;
  transition: border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.about-link:hover { color: #000; border-bottom-color: var(--ink); }

.quote {
  margin: 34px 0 0;
  padding: 2px 0 2px 16px;
  border-left: 1px solid var(--rule);
  font-size: var(--fs-label);
  line-height: 1.85;
  letter-spacing: .05em;
  color: #A0A0A0;
}
.quote cite {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .02em;
  color: #C4C4C4;
}

/* ---------- 双栏 ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  column-gap: var(--toc-gap);
  align-items: start;
}

.main { min-width: 0; max-width: calc(var(--measure) + var(--rail)); }

/* ---------- 分节栏 ---------- */

.section-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 40px;
}

.section-title {
  margin: 0;
  font-size: var(--fs-section);
  font-weight: 600;
  letter-spacing: .14em;
  color: #333333;
  text-transform: uppercase;
}

.sort {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex: none;
  white-space: nowrap;
  margin: 0;
  padding: 2px 0;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font);
  font-size: var(--fs-meta);
  letter-spacing: .06em;
  color: var(--ghost);
  transition: color var(--fast) var(--ease);
}
.sort:hover { color: var(--soft); }

.sort span[data-order] {
  transition: color var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.sort span[data-order].on { color: var(--ink); font-weight: 500; }
.sort .slash { color: #DADADA; }

/* ---------- 条目流 ---------- */

.stream {
  position: relative;
  border-left: 1px solid var(--rule);
  padding-left: var(--rail);
  margin-left: 1px;
}

.entry {
  position: relative;
  padding-bottom: 56px;
  scroll-margin-top: 32px;
  transition: padding-bottom 380ms var(--ease);
}
.entry:last-child { padding-bottom: 8px; }
.entry.folded { padding-bottom: 30px; }

/* 空心节点 */
.entry::before {
  content: "";
  position: absolute;
  left: calc(var(--rail) * -1 - 3.5px);
  top: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid #D5D5D5;
  transition: border-color var(--mid) var(--ease),
              background var(--mid) var(--ease),
              transform var(--mid) var(--ease),
              opacity 500ms var(--ease);
}

.entry.near::before { border-color: var(--ink); }
.entry.current::before { background: var(--ink); transform: scale(1.15); }

.entry-head {
  margin-bottom: 16px;
}

.entry-title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.55;
  letter-spacing: .01em;
  color: var(--ink);
}

/* 标题即按钮：整行可点，默认展开，点一下折叠 */
.entry-toggle {
  display: flex;
  align-items: baseline;
  width: 100%;
  gap: 16px;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  -webkit-tap-highlight-color: transparent;
}

.entry-label { flex: 1; min-width: 0; }

.entry-title .mid {
  color: #CFCFCF;
  font-weight: 400;
  margin: 0 4px;
}

.chev {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 1px;
  border-right: 1px solid #C4C4C4;
  border-bottom: 1px solid #C4C4C4;
  transform: rotate(45deg);
  transition: transform 320ms var(--ease), border-color var(--fast) var(--ease);
}

.entry-toggle:hover .chev { border-color: var(--ink); }
.entry.folded .chev { transform: rotate(-45deg); }

/* 折叠容器：0fr → 1fr 平滑收合 */
.entry-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 400ms var(--ease), opacity 280ms var(--ease);
}

.entry-body-inner {
  overflow: hidden;
  min-height: 0;
}

.entry.folded .entry-body {
  grid-template-rows: 0fr;
  opacity: 0;
}

.entry.folded .entry-title { color: #4A4A4A; }

/* ---------- 正文 ---------- */

.prose {
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-body);
  color: var(--text);
  max-width: var(--measure);
}

.prose p { margin: 0 0 15px; }
.prose p:last-child { margin-bottom: 0; }

.prose h3 {
  margin: 30px 0 10px;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .05em;
  color: #6A6A6A;
}
.prose h3:first-child { margin-top: 0; }

.prose strong { font-weight: 600; color: #141414; }

.prose ul { margin: 0 0 15px; padding-left: 16px; }
.prose li { margin-bottom: 6px; }
.prose li::marker { color: var(--ghost); }

.prose em {
  font-style: normal;
  background: linear-gradient(transparent 62%, #F0F0F0 62%);
}

.prose code {
  font-family: var(--mono);
  font-size: .92em;
  padding: 1px 4px;
  background: #F5F5F5;
  border-radius: 2px;
}

/* ---------- 条目流末尾的小图 ---------- */

.stream-tail {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 0;
  padding-right: 6px;
}
.stream-tail img {
  width: 176px;
  height: auto;
  opacity: .82;
}

/* ---------- 桌面侧边目录 ---------- */

.toc {
  position: sticky;
  top: 88px;
  padding-top: 2px;
  font-size: var(--fs-toc);
  line-height: 1.5;
}

.toc-title {
  margin: 0 0 14px;
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #CFCFCF;
}

.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }

.toc a {
  display: block;
  padding: 4px 0 4px 10px;
  text-decoration: none;
  color: var(--ghost);
  border-left: 1px solid transparent;
  margin-left: -1px;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.toc a:hover { color: var(--soft); }

.toc a.active {
  color: var(--ink);
  font-weight: 600;
  border-left-color: var(--ink);
}

.toc-round {
  margin-left: 6px;
  font-size: 10px;
  color: #D4D4D4;
  transition: color var(--fast) var(--ease);
}
.toc a.active .toc-round { color: var(--faint); }

/* ---------- 关于弹窗 ---------- */

.about-modal {
  width: min(560px, calc(100vw - 40px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 80px -32px rgba(0, 0, 0, .38);
  overflow: auto;
  opacity: 0;
  transform: translateY(12px) scale(.985);
  transition: opacity 240ms var(--ease), transform 320ms var(--ease),
              overlay 320ms allow-discrete, display 320ms allow-discrete;
}

.about-modal[open] {
  opacity: 1;
  transform: none;
}

.about-modal::backdrop {
  background: rgba(17, 17, 17, .28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 240ms var(--ease), overlay 320ms allow-discrete,
              display 320ms allow-discrete;
}

.about-modal[open]::backdrop { opacity: 1; }

@starting-style {
  .about-modal[open] { opacity: 0; transform: translateY(12px) scale(.985); }
  .about-modal[open]::backdrop { opacity: 0; }
}

.about-modal-inner {
  position: relative;
  padding: 26px 30px 32px;
}

.about-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--ghost);
  transition: color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.about-modal-close:hover { color: var(--ink); transform: rotate(90deg); }

.about-modal-close span {
  position: relative;
  width: 12px;
  height: 12px;
  display: block;
}
.about-modal-close span::before,
.about-modal-close span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px;
  height: 1px;
  background: currentColor;
}
.about-modal-close span::before { transform: rotate(45deg); }
.about-modal-close span::after  { transform: rotate(-45deg); }

.about-figure {
  display: flex;
  justify-content: flex-end;
  margin: 22px 0 0;
}
.about-figure img {
  display: block;
  width: 148px;
  height: auto;
}

.about-copy {
  font-size: var(--fs-lead);
  line-height: 1.95;
  color: #4F4F4F;
  max-width: none;
}
.about-copy p { margin: 0 0 13px; }
.about-copy p:first-child {
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 14px;
}
.about-copy p:last-child { margin-bottom: 0; }

/* ---------- 桌面常驻小图：钉在左侧留白里 ---------- */

.companion {
  display: none;
  position: fixed;
  left: 34px;
  top: 50%;
  width: 150px;
  height: auto;
  transform: translateY(-50%);
  opacity: .9;
  pointer-events: none;
  z-index: 10;
}

@media (min-width: 1320px) {
  .companion { display: block; }
}

/* ---------- 页脚 ---------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 88px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  letter-spacing: .06em;
  color: #C4C4C4;
}

/* ---------- 浮动目录 ---------- */

.toc-fab {
  position: fixed;
  right: 20px;
  bottom: 22px;
  z-index: 70;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 15px 10px 13px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  letter-spacing: .06em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -12px rgba(0, 0, 0, .18);
  transition: transform var(--mid) var(--ease), box-shadow var(--mid) var(--ease),
              opacity var(--mid) var(--ease);
}

.toc-fab:hover { transform: translateY(-1px); }
.toc-fab:active { transform: scale(.97); }

.toc-fab-icon {
  width: 13px;
  height: 9px;
  position: relative;
  display: block;
}
.toc-fab-icon::before,
.toc-fab-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 13px;
  height: 1px;
  background: currentColor;
  transition: transform var(--mid) var(--ease), top var(--mid) var(--ease);
}
.toc-fab-icon::before { top: 1px; }
.toc-fab-icon::after  { top: 7px; }

.toc-fab[aria-expanded="true"] .toc-fab-icon::before { top: 4px; transform: rotate(45deg); }
.toc-fab[aria-expanded="true"] .toc-fab-icon::after  { top: 4px; transform: rotate(-45deg); }
.toc-fab[aria-expanded="true"] .toc-fab-text { opacity: 0; width: 0; overflow: hidden; }

.toc-fab-text { transition: opacity var(--fast) var(--ease); }

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(17, 17, 17, .18);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  opacity: 0;
  transition: opacity var(--mid) var(--ease);
}
.toc-backdrop.show { opacity: 1; }

.toc-fab[aria-expanded="true"] {
  opacity: 0;
  transform: translateY(8px) scale(.96);
  pointer-events: none;
}

.toc-panel {
  position: fixed;
  z-index: 68;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: 64vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 22px calc(22px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--rule);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -8px 40px -16px rgba(0, 0, 0, .22);
  transform: translateY(102%);
  transition: transform var(--mid) var(--ease), visibility 0s linear var(--mid);
  visibility: hidden;
}
.toc-panel.open {
  transform: translateY(0);
  visibility: visible;
  transition: transform var(--mid) var(--ease), visibility 0s;
}

.toc-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.toc-panel-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #CFCFCF;
}

.toc-close {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--ghost);
}
.toc-close span {
  position: relative;
  width: 12px;
  height: 12px;
  display: block;
}
.toc-close span::before,
.toc-close span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px;
  height: 1px;
  background: currentColor;
}
.toc-close span::before { transform: rotate(45deg); }
.toc-close span::after  { transform: rotate(-45deg); }

.toc-panel-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-panel-list li { border-top: 1px solid #F0F0F0; }
.toc-panel-list li:first-child { border-top: 0; }

.toc-panel-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 2px;
  text-decoration: none;
  font-size: 14px;
  color: var(--soft);
  transition: color var(--fast) var(--ease), padding-left var(--fast) var(--ease);
}
.toc-panel-list a:hover,
.toc-panel-list a.active { color: var(--ink); padding-left: 6px; }
.toc-panel-list .toc-round { margin: 0; font-size: 11px; color: #BFBFBF; }

/* ---------- 逐行进场 ---------- */

.js .rv {
  opacity: 0;
  transform: translateY(9px);
  will-change: opacity, transform;
}

.js .rv.in {
  opacity: 1;
  transform: none;
  transition: opacity 620ms var(--ease), transform 700ms var(--ease);
  transition-delay: var(--d, 0ms);
}

/* 首屏文字入场：只跑一次 */
.js [data-intro] {
  opacity: 0;
  transform: translateY(8px);
}
.js [data-intro].in {
  opacity: 1;
  transform: none;
  transition: opacity 700ms var(--ease), transform 800ms var(--ease);
  transition-delay: var(--d, 0ms);
}

/* 时间轴节点跟着标题一起亮 */
.js .entry::before { opacity: 0; }
.js .entry.shown::before { opacity: 1; }

/* 排序时的 FLIP 由 JS 加这个类 */
.stream.animating .entry { transition: transform 420ms var(--ease); }

/* 点击目录时短暂高亮目标条目 */
.entry.flash .entry-title { animation: flash 1100ms var(--ease); }

@keyframes flash {
  0%   { color: var(--ink); }
  35%  { color: #7A7A7A; }
  100% { color: var(--ink); }
}

/* ---------- 响应式 ---------- */

@media (max-width: 980px) {
  .page {
    padding: 60px 26px 84px;
    max-width: calc(var(--measure) + var(--rail) + 52px);
  }

  .layout { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }

  .toc-fab { display: inline-flex; }
  .toc-panel { display: block; }

  .mast-illu { width: 96px; }
}

@media (min-width: 981px) {
  .toc-panel, .toc-backdrop { display: none; }
}

@media (max-width: 560px) {
  :root { --rail: 20px; }

  .page { padding: 46px 20px 96px; }
  .masthead { margin-bottom: 54px; }
  .section-bar { margin-bottom: 32px; }

  .mast-grid { column-gap: 16px; }
  .mast-illu { width: 84px; }

  .subtitle { margin-bottom: 22px; }
  .quote { margin-top: 26px; }

  .entry { padding-bottom: 44px; }
  .entry.folded { padding-bottom: 24px; }

  .stream-tail { justify-content: center; }
  .stream-tail img { width: 150px; }

  .about-modal { width: calc(100vw - 24px); max-height: 84vh; }
  .about-modal-inner { padding: 22px 22px 26px; }
  .about-figure img { width: 124px; }

  .footer { flex-direction: column; align-items: flex-start; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }

  .js .rv { opacity: 1; transform: none; }
  .js [data-intro] { opacity: 1; transform: none; }
  .js .entry::before { opacity: 1; }
  .entry-body { transition: none; }
}
