/* ==========================================================================
   私人视觉档案 / Living Index — 设计系统
   依据：docs/design-personal.md §8 视觉系统、§9 构图、§10 组件、§11 动效、§12 响应式
   原则：零 JavaScript、零外部请求、零字体下载；内容不依赖脚本即可完整阅读
   ==========================================================================

   目录
   1. 设计 token
   2. 基础与重置
   3. 排版
   4. 布局与栅格
   5. 组件
   6. 状态与无障碍
   7. 动效
   8. 响应式
   ========================================================================== */


/* ==========================================================================
   1. 设计 token
   ========================================================================== */

:root {
  /* 底色与文字 */
  --paper: #F3F0E8;
  --ink: #171714;
  --secondary: #5E5D54;          /* 纸底对比 5.82:1 */
  --surface: #E6E2D8;

  /* 强调色
     文档建议值为 #B83B24，实测在 paper 上 5.00:1（达标）但在 surface #E6E2D8 上仅
     4.40:1（不达标）。故统一加深为 #B03521：
       vs paper   5.46:1 ✅
       vs surface 4.81:1 ✅
     这样一个强调色在两种底色上都满足小字 4.5:1，不需要维护两套。
     详见 docs/pitfalls.md 第 6.6 条。 */
  --accent: #B03521;

  /* 仅用于大字（≥24px）与图形，不承载小字：纸底 3.05:1 */
  --vermilion: #ED5838;

  /* 内容色：只在作品内容里出现，不承担全站语义 */
  --cobalt: #4858EC;
  --yellow: #FFC928;             /* 只能配 ink 文字（11.66:1），不能配白字 */

  /* 线条 */
  --divider: rgba(23, 23, 20, .20);
  --divider-strong: rgba(23, 23, 20, .40);

  /* 字体：全部使用系统字体栈，不下载任何字体文件
     （Google Fonts 在大陆不可达；自托管中文字体需子集化，见 pitfalls 6.3/6.4） */
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --font-sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  /* 间距基准 §8.4 */
  --s1: 4px;   --s2: 8px;   --s3: 12px;  --s4: 16px;  --s5: 24px;
  --s6: 32px;  --s7: 48px;  --s8: 64px;  --s9: 96px;  --s10: 128px;

  /* 版心 §8.4 */
  --measure: 680px;              /* 正文阅读栏上限 */
  --container: 1248px;           /* 1440 画板下的主体宽 */
  --gutter: clamp(20px, 4vw, 48px);
  --gap: 24px;

  /* 动效 §11.2 */
  --t-fast: 180ms;
  --t-mid: 220ms;
  --t-slow: 340ms;
  --ease: cubic-bezier(.2, .6, .3, 1);
}


/* ==========================================================================
   2. 基础与重置
   ========================================================================== */

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

hr, .rule {
  border: 0;
  border-top: 1px solid var(--divider);
  margin: var(--s6) 0 var(--s4);
}


/* ==========================================================================
   3. 排版 §8.3
   ========================================================================== */

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -.01em;
  text-wrap: balance;
}

/* 首页展示标题：桌面 104–120px，手机 46–58px */
.display {
  font-family: var(--font-serif);
  font-size: clamp(46px, 8.6vw, 118px);
  line-height: 1.1;
  letter-spacing: -.02em;
}

/* 页面标题：桌面 64–80px，手机 36–44px */
.page-title {
  font-family: var(--font-serif);
  font-size: clamp(36px, 5.6vw, 76px);
  line-height: 1.18;
}

/* 章节标题：桌面 36–48px，手机 26–32px */
.section-title { font-size: clamp(26px, 3.4vw, 44px); line-height: 1.25; }

/* 项目名称 24–28px */
.item-title { font-size: clamp(22px, 2.2vw, 27px); line-height: 1.35; }

/* 引言 22–26px */
.lede {
  font-size: clamp(19px, 2vw, 24px);
  line-height: 1.6;
  color: var(--secondary);
  max-width: var(--measure);
}

/* 正文 17–18px / 行高 1.75–1.9 */
.prose { max-width: var(--measure); }
.prose p { margin: 0 0 var(--s5); font-size: 17px; line-height: 1.85; }
.prose p:last-child { margin-bottom: 0; }

/* 正文内的列表（清单类条目会用） */
.prose ul, .prose ol { margin: 0 0 var(--s5); padding-left: 1.3em; }
.prose li { margin-bottom: var(--s3); font-size: 17px; line-height: 1.8; }
.prose li:last-child { margin-bottom: 0; }

/* 正文内的引文 */
.prose blockquote {
  margin: var(--s7) 0;
  padding-left: var(--s5);
  border-left: 2px solid var(--accent);
  font-size: 19px;
  line-height: 1.7;
}

/* 说明与图注 13–14px */
.caption, .meta {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--secondary);
}

/* 英文档案编号 12px */
.mono, .num {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--secondary);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--secondary);
  margin: 0 0 var(--s5);
}

/* 英文片段统一缩小一档，避免中英混排时英文喧宾夺主 */
[lang="en"] { font-variant-ligatures: none; }


/* ==========================================================================
   4. 布局与栅格 §8.4
   ========================================================================== */

.wrap {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
}

.section { padding-block: var(--s9); }
.section + .section { border-top: 1px solid var(--divider); }
.section--tight { padding-block: var(--s8); }

/* 通用列跨度（12 栏；小屏下全部退化为整行） */
.col-4  { grid-column: span 4; }
.col-5  { grid-column: span 5; }
.col-6  { grid-column: span 6; }
.col-7  { grid-column: span 7; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-12 { grid-column: 1 / -1; }
.col-from-3 { grid-column: 3 / span 10; }
.col-from-6 { grid-column: 6 / span 7; }

/* 标题错位：第二行起于第 3 列（桌面） */
.display .indent { display: block; padding-left: .12em; }

/* 章节头：标题在左，辅助动作在右（小屏下移） */
.section-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4) var(--s6);
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s7);
}

.stack > * + * { margin-top: var(--s5); }
.stack-sm > * + * { margin-top: var(--s3); }


/* ==========================================================================
   5. 组件 §10
   ========================================================================== */

/* --- 跳到正文（键盘用户） --- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 20;
  background: var(--ink);
  color: var(--paper);
  padding: var(--s3) var(--s5);
  text-decoration: none;
}
.skip-link:focus { left: var(--s4); top: var(--s4); }

/* --- 顶栏：普通文档流，不吸顶（§6.2） --- */
.site-header { border-bottom: 1px solid var(--divider); }
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4) var(--s6);
  min-height: 80px;
  padding-block: var(--s3);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s3);
  text-decoration: none;
  min-height: 44px;
  align-content: center;
}
.brand-name { font-size: 19px; font-weight: 600; letter-spacing: .01em; }
.brand-mark {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--secondary);
}

/* 导航：桌面与手机都直接可见。本站导航只有 2 项，
   内联展示比折叠菜单更直接、更可访问，也不需要 JS。
   这是对 §5.3"小屏用标有菜单的按钮"的有意偏离，理由见 README。 */
.site-nav { display: flex; flex-wrap: wrap; gap: var(--s5); }
.site-nav a {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s2);
  min-height: 44px;
  align-items: center;
  text-decoration: none;
  font-size: 15px;
}
.site-nav a:hover { text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
.site-nav a[aria-current="page"] {
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
}
.nav-num { font-family: var(--font-mono); font-size: 12px; color: var(--secondary); }

/* --- 图像占位框：真实图片就位前使用 --- */
.figure {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--divider);
  color: var(--secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .06em;
  text-align: center;
  padding: var(--s4);
  aspect-ratio: 4 / 3;
}
.figure--tall { aspect-ratio: 3 / 4; }
.figure--wide { aspect-ratio: 16 / 9; }
.figure--square { aspect-ratio: 1 / 1; }
.figure img { width: 100%; height: 100%; object-fit: cover; }

/* --- 首屏：封面型（模板 A） --- */
.hero { padding-block: var(--s9) var(--s8); }
.hero-head { max-width: 15ch; }
.hero-intro { margin-top: var(--s5); }
.hero .cta { margin-top: var(--s6); }

/* 主作 8 列 + 边注 4 列 */
.cover { margin-top: var(--s8); }
.cover-main { grid-column: 1 / span 8; }
.cover-aside { grid-column: 10 / span 3; align-self: end; }
.cover-aside .slice { margin-top: var(--s4); }

/* --- 作品卡（模板 B：7/5 错位） --- */
.card { display: block; text-decoration: none; color: inherit; }
.card:hover .item-title { text-decoration: underline; text-underline-offset: 5px; }
.card:hover .figure { border-color: var(--divider-strong); }
.card-a { grid-column: 1 / span 7; }
.card-b { grid-column: 9 / span 4; margin-top: var(--s9); }
.card-meta { margin-top: var(--s4); }
.card-meta .num { display: block; margin-bottom: var(--s2); }

/* --- 条目类型标签 --- */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--secondary);
  border: 1px solid var(--divider);
  padding: 2px 8px;
  white-space: nowrap;
}

/* --- 时间流条目列表：档案的主轴（替换原「作品目录行」） ---
   时间在左，内容在中，箭头在右。桌面三栏，手机纵向堆叠。 */
.entries { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--divider); }
.entries > li { border-bottom: 1px solid var(--divider); }
.entries a {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) auto;
  gap: var(--s3) var(--s6);
  align-items: baseline;
  padding-block: var(--s5);
  min-height: 44px;
  text-decoration: none;
  color: inherit;
}
.entries a:hover { background: var(--surface); }
.entries a:hover .entry-title { text-decoration: underline; text-underline-offset: 5px; }
.entry-date { font-family: var(--font-mono); font-size: 12px; color: var(--secondary); }
.entry-body { min-width: 0; }
.entry-title { display: block; font-size: 19px; line-height: 1.5; }
.entry-summary { display: block; margin: var(--s2) 0 0; font-size: 14.5px; line-height: 1.7; color: var(--secondary); }
.entry-arrow { color: var(--secondary); font-size: 13px; }

/* 条目详情页头部 */
.entry-head { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); align-items: center; margin-bottom: var(--s5); }

/* --- 项目详情 --- */
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: var(--s6);
  color: var(--accent);
  text-decoration: none;
  font-size: 15px;
}
.back-link:hover { text-decoration: underline; text-underline-offset: 5px; }

/* 细线元信息表 §7.2 */
.spec { margin: var(--s7) 0; border-top: 1px solid var(--divider); }
.spec > div { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); padding-block: var(--s3); border-bottom: 1px solid var(--divider); }
.spec dt { flex: 0 0 132px; margin: 0; font-size: 13.5px; color: var(--secondary); }
.spec dd { margin: 0; font-size: 15.5px; }

.prose h2 { font-size: clamp(23px, 2.6vw, 31px); margin: var(--s8) 0 var(--s4); }
.prose h2:first-child { margin-top: 0; }
.prose .figure { margin-block: var(--s6); }

/* --- 结尾动作区 --- */
.end-line {
  font-family: var(--font-serif);
  font-size: clamp(32px, 5vw, 64px);
  line-height: 1.15;
  margin: 0 0 var(--s6);
  font-weight: 600;
}
.end-actions { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s6); }
.end-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  text-decoration: none;
  font-size: 16px;
}
.end-actions a:hover { text-decoration: underline; text-underline-offset: 5px; }

/* --- 主动作链接 --- */
.cta {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: var(--s1);
  font-size: 16px;
}
.cta:hover { color: var(--ink); }

/* --- 页脚 --- */
.site-footer { padding-block: var(--s8) var(--s7); }
.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s5);
  justify-content: space-between;
  font-size: 13.5px;
  color: var(--secondary);
}
.colophon .placeholder-flag { color: var(--secondary); }


/* ==========================================================================
   6. 状态与无障碍 §12.3
   ========================================================================== */

/* 焦点环 2px，且在纸底与 surface 上都有足够对比 */
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 1px;
}

/* 触控区一律 ≥44px */
a, button { touch-action: manipulation; }

/* 内容不依赖颜色表达：当前页除颜色外还有下划线 + aria-current */
::selection { background: var(--ink); color: var(--paper); }


/* ==========================================================================
   7. 动效 §11.2
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  /* 仅首屏做一次极轻的入场；其余内容静态呈现。
     不使用滚动触发动画，避免"脚本或动画失败导致内容不可见"的风险。 */
  .hero-enter { animation: rise var(--t-slow) var(--ease) both; }
  .hero-enter--2 { animation-delay: 80ms; }

  @keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }

  .card .figure { transition: border-color var(--t-fast) var(--ease); }
  .cta, .end-actions a, .back-link { transition: color var(--t-fast) var(--ease); }
  .site-nav a { transition: text-decoration-color var(--t-fast) var(--ease); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* ==========================================================================
   8. 响应式 §12.1
   ========================================================================== */

/* 中屏 768–1199：标题缩小错位幅度，双列保留但降低错位 */
@media (max-width: 1199px) {
  .card-b { margin-top: var(--s8); }
}

/* 小屏 <900：单列，取消所有错位 */
@media (max-width: 899px) {
  body { font-size: 16.5px; }

  .section { padding-block: var(--s8); }
  .section--tight { padding-block: var(--s7); }
  .hero { padding-block: var(--s8) var(--s7); }

  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .cover-main,
  .cover-aside,
  .card-a,
  .card-b,
  .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-12,
  .col-from-3, .col-from-6 {
    grid-column: 1 / -1;
    margin-top: 0;
  }
  .cover-aside { margin-top: var(--s6); }
  .card-b { margin-top: var(--s7); }
  .display .indent { padding-left: 0; }

  .header-inner { min-height: 64px; }
  .display { letter-spacing: -.01em; }

  .entries a { grid-template-columns: 1fr; gap: var(--s2); }
  .entries .entry-arrow { display: none; }
  .entry-title { font-size: 18px; }

  .spec > div { flex-direction: column; gap: var(--s1); }
  .spec dt { flex: none; }

  .colophon { flex-direction: column; }
}

/* 窄屏 320–389：标题可增行，边距收紧 */
@media (max-width: 389px) {
  :root { --gutter: 16px; }
  .display { font-size: 40px; }
  .section-title { font-size: 24px; }
}


/* ==========================================================================
   9. 打印
   ========================================================================== */

@media print {
  .site-header, .end-actions, .skip-link { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .section { padding-block: 12pt; }
  a { text-decoration: none; color: #000; }
  .figure { border: 1px solid #999; background: none; }
}
