/* ============================================================
   拾史 · 设计系统
   配色：A 宣纸朱砂
   规则：8px 网格 / 字号 4 级 / 色相 3 个 / 圆角统一
   ============================================================ */

:root {
  /* —— 颜色 —— */
  --paper:        #faf7f0;
  --paper-2:      #f3eee3;
  --surface:      rgba(255, 255, 255, 0.62);
  --ink:          #1f1b16;
  --ink-soft:     #3a332b;
  --sub:          #6d6357;
  --faint:        #9a9083;
  --accent:       #b03a2e;   /* 朱砂 — 印章红 */
  --accent-soft:  #b03a2e14;
  --accent-hover: #8f2c22;
  --ochre:        #8b6f47;
  --gold:         #c9a227;   /* 仅用于装饰（时间轴、描边），不做正文色 */

  --line:         rgba(139, 111, 71, 0.18);
  --line-strong:  rgba(139, 111, 71, 0.32);
  --border-card:  rgba(139, 111, 71, 0.16);

  /* —— 间距（8px 网格）—— */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-24: 96px;

  /* —— 圆角 —— */
  --r-sm: 8px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-full: 999px;

  /* —— 阴影 —— */
  --sh-sm: 0 1px 3px rgba(61, 47, 32, 0.06), 0 1px 2px rgba(61, 47, 32, 0.04);
  --sh-md: 0 4px 12px rgba(61, 47, 32, 0.07), 0 2px 4px rgba(61, 47, 32, 0.04);
  --sh-lg: 0 12px 32px rgba(61, 47, 32, 0.10), 0 4px 8px rgba(61, 47, 32, 0.05);

  /* —— 字体 —— */
  --font-serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "STSong", "SimSun", serif;
  --font-sans:  -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono:  ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* —— 过渡 —— */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 0.24s;

  /* —— 版心 —— */
  --w-read: 68ch;
  --w-page: 1120px;
}

/* 深色模式（墨夜） */
:root.dark {
  --paper:        #17140f;
  --paper-2:      #1f1a14;
  --surface:      rgba(255, 255, 255, 0.035);
  --ink:          #e8e2d6;
  --ink-soft:     #cdc5b6;
  --sub:          #9c9384;
  --faint:        #6f6759;
  --accent:       #d4574a;
  --accent-soft:  #d4574a1f;
  --accent-hover: #e2685b;
  --ochre:        #b08f61;
  --gold:         #d4b04a;

  --line:         rgba(212, 176, 74, 0.14);
  --line-strong:  rgba(212, 176, 74, 0.26);
  --border-card:  rgba(212, 176, 74, 0.14);

  --sh-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --sh-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --sh-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ============================================================
   基础
   ============================================================ */

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

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

body {
  margin: 0;
  background-color: var(--paper);
  /* 极淡宣纸纹理 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent-hover); }

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

/* 焦点可见（无障碍） */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   排版
   ============================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  color: var(--ink);
  line-height: 1.25;
  margin: 0;
  font-weight: 700;
}

.h-hero    { font-size: clamp(2.25rem, 5.5vw, 3.75rem); letter-spacing: -0.01em; line-height: 1.15; }
.h-section { font-size: 1.75rem; letter-spacing: -0.005em; }
.h-card    { font-size: 1.25rem; letter-spacing: 0.01em; }

.lede {
  font-size: 1.0625rem;
  line-height: 1.8;
  color: var(--sub);
  max-width: var(--w-read);
}

.prose { max-width: var(--w-read); }
.prose p { margin: 0 0 var(--sp-6); line-height: 1.9; color: var(--ink-soft); }
.prose h2 {
  font-size: 1.375rem; margin: var(--sp-12) 0 var(--sp-4);
  padding-left: var(--sp-4); border-left: 3px solid var(--accent);
}
.prose h3 { font-size: 1.125rem; margin: var(--sp-8) 0 var(--sp-3); }
.prose ul, .prose ol { margin: 0 0 var(--sp-6); padding-left: var(--sp-6); color: var(--ink-soft); }
.prose li { margin-bottom: var(--sp-2); line-height: 1.85; }
.prose blockquote {
  margin: var(--sp-6) 0; padding: var(--sp-4) var(--sp-6);
  border-left: 3px solid var(--gold);
  background: var(--accent-soft);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-family: var(--font-serif);
  color: var(--ink-soft);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  font-family: var(--font-mono); font-size: 0.875em;
  background: var(--paper-2); padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--line);
}

/* 年代数字 */
.year {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: var(--sub);
}

/* 小标签 */
.eyebrow {
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  color: var(--faint);
  text-transform: uppercase;
}

/* ============================================================
   布局
   ============================================================ */

.wrap { max-width: var(--w-page); margin: 0 auto; padding: 0 var(--sp-6); }
@media (max-width: 640px) { .wrap { padding: 0 var(--sp-4); } }

section { padding: var(--sp-16) 0; }
section + section { border-top: 1px solid var(--line); }

.sec-head { margin-bottom: var(--sp-8); }
.sec-head .h-section { margin-bottom: var(--sp-2); }

/* ============================================================
   顶部导航
   ============================================================ */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; gap: var(--sp-6);
}

.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  font-family: var(--font-serif);
  font-size: 1.3125rem; font-weight: 700;
  color: var(--ink); letter-spacing: 0.12em;
}

/* 朱砂印章 */
.seal {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 6px;
  font-family: var(--font-serif); font-size: 0.8125rem; font-weight: 700;
  letter-spacing: 0; line-height: 1;
  box-shadow: var(--sh-sm);
}

.nav { display: flex; align-items: center; gap: var(--sp-6); }
.nav a {
  font-size: 0.9375rem; color: var(--sub);
  padding: var(--sp-2) 0;
}
.nav a:hover, .nav a[aria-current] { color: var(--accent); }

.nav-toggle {
  display: none; background: none; border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3);
  color: var(--ink); cursor: pointer; font-size: 1rem; line-height: 1;
}

@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .nav {
    position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--paper); border-bottom: 1px solid var(--line);
    padding: var(--sp-2) var(--sp-4);
    display: none;
  }
  .nav.open { display: flex; }
  .nav a { padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
  .nav a:last-child { border-bottom: none; }
}

/* ============================================================
   首页 Hero
   ============================================================ */

.hero { padding: var(--sp-24) 0 var(--sp-16); border-bottom: 1px solid var(--line); }
.hero .h-hero { margin-bottom: var(--sp-6); }
.hero .lede { margin-bottom: 0; }

.hero-rule {
  width: 64px; height: 3px; margin-bottom: var(--sp-8);
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 2px;
}

/* ============================================================
   朝代时间轴
   ============================================================ */

.timeline { position: relative; padding: var(--sp-8) 0 var(--sp-4); }

.tl-track {
  position: relative; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold) 8%, var(--gold) 92%, transparent);
  border-radius: 2px;
}

.tl-items {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-top: -6px;
}

.tl-item {
  position: relative; display: flex; flex-direction: column; align-items: center;
  flex: 1; min-width: 0; background: none; border: none; padding: 0;
  cursor: pointer; font: inherit; color: inherit;
}

.tl-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--gold);
  transition: all var(--dur) var(--ease);
  flex: none;
}
.tl-item:hover .tl-dot {
  border-color: var(--accent);
  transform: scale(1.35);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.tl-item.active .tl-dot {
  background: var(--accent); border-color: var(--accent);
  transform: scale(1.35);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.tl-name {
  margin-top: var(--sp-3);
  font-family: var(--font-serif); font-size: 0.875rem; font-weight: 600;
  color: var(--sub); white-space: nowrap;
  transition: color var(--dur) var(--ease);
}
.tl-item:hover .tl-name, .tl-item.active .tl-name { color: var(--accent); }

.tl-year {
  margin-top: var(--sp-1); font-family: var(--font-mono);
  font-size: 0.625rem; color: var(--faint); white-space: nowrap;
}

@media (max-width: 860px) {
  .tl-items { overflow-x: auto; justify-content: flex-start; gap: var(--sp-6); padding-bottom: var(--sp-2); }
  .tl-item { flex: none; min-width: 56px; }
}

/* 时间轴下方：选中朝代的面板 */
.tl-panel {
  margin-top: var(--sp-12);
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--r-md);
  min-height: 96px;
  transition: opacity var(--dur) var(--ease);
}
.tl-panel.fading { opacity: 0; }
.tl-panel h3 { font-size: 1.25rem; margin-bottom: var(--sp-2); }
.tl-panel .year { display: block; margin-bottom: var(--sp-3); }
.tl-panel p { margin: 0; color: var(--sub); line-height: 1.8; }
.tl-panel .more { display: inline-block; margin-top: var(--sp-4); font-size: 0.9375rem; }

/* ============================================================
   卡片
   ============================================================ */

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: var(--sp-4);
}

.card {
  display: flex; flex-direction: column;
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--r-md);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-md);
  border-color: var(--line-strong);
}

.card .dyn-tag {
  display: inline-block; align-self: flex-start;
  font-size: 0.6875rem; letter-spacing: 0.1em;
  color: var(--accent); border: 1px solid var(--accent);
  border-radius: 4px; padding: 2px 8px; margin-bottom: var(--sp-4);
}

.card h3 { font-size: 1.25rem; margin-bottom: var(--sp-2); letter-spacing: 0.04em; }
.card .year { margin-bottom: var(--sp-4); }
.card p {
  margin: 0; font-size: 0.875rem; line-height: 1.75; color: var(--sub);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.card-link { position: relative; margin-top: auto; padding-top: var(--sp-4); font-size: 0.875rem; }
.card-title-link::after { content: ""; position: absolute; inset: 0; }

/* ============================================================
   人物页
   ============================================================ */

.person-head { padding: var(--sp-16) 0 var(--sp-8); border-bottom: 1px solid var(--line); }

.person-head .dyn-tag {
  display: inline-block; font-size: 0.75rem; letter-spacing: 0.12em;
  color: var(--accent); border: 1px solid var(--accent);
  border-radius: 4px; padding: 3px 12px; margin-bottom: var(--sp-6);
}
.person-head h1 {
  font-size: clamp(2rem, 4.5vw, 3rem); letter-spacing: 0.06em;
  margin-bottom: var(--sp-4);
}
.person-head .alias { font-size: 0.9375rem; color: var(--faint); margin-bottom: var(--sp-4); }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4) var(--sp-8); margin-top: var(--sp-8);
  max-width: var(--w-read);
}
.fact { border-top: 1px solid var(--line); padding-top: var(--sp-3); }
.fact dt { font-size: 0.6875rem; letter-spacing: 0.12em; color: var(--faint); margin-bottom: var(--sp-1); }
.fact dd { margin: 0; font-size: 0.9375rem; color: var(--ink-soft); }

.person-body { padding: var(--sp-12) 0; }

/* 关系 */
.relations { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-3); }
.rel {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: 1px solid var(--border-card);
  border-radius: var(--r-sm);
  transition: border-color var(--dur) var(--ease);
}
.rel:hover { border-color: var(--line-strong); }
.rel .rel-type {
  font-size: 0.6875rem; letter-spacing: 0.1em; color: var(--faint);
}
.rel .rel-name { font-family: var(--font-serif); font-size: 1rem; color: var(--ink); }

/* 出处 */
.source {
  margin-top: var(--sp-8); padding: var(--sp-4) var(--sp-6);
  background: var(--paper-2); border-radius: var(--r-sm);
  border-left: 3px solid var(--ochre);
  font-size: 0.875rem; color: var(--sub);
}
.source strong { color: var(--ink-soft); font-weight: 600; }

/* ============================================================
   朝代页
   ============================================================ */

.dyn-head { padding: var(--sp-16) 0 var(--sp-8); border-bottom: 1px solid var(--line); }
.dyn-head h1 { font-size: clamp(2rem, 4.5vw, 3rem); letter-spacing: 0.1em; margin-bottom: var(--sp-3); }

/* ============================================================
   检索
   ============================================================ */

.search-box { max-width: 640px; margin-bottom: var(--sp-8); }
.search-input {
  width: 100%; padding: var(--sp-4) var(--sp-6);
  font-size: 1.0625rem; font-family: var(--font-sans); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search-input::placeholder { color: var(--faint); }
.search-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* 检索结果 */
.result-count { font-size: 0.8125rem; color: var(--faint); margin: 0 0 var(--sp-4); letter-spacing: 0.06em; }

.results { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-12); }

.result {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  grid-template-areas:
    "dyn title life"
    "dyn sum   sum";
  gap: var(--sp-1) var(--sp-4);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  transition: background var(--dur) var(--ease), padding-left var(--dur) var(--ease);
}
.result:hover { background: var(--accent-soft); padding-left: var(--sp-6); color: var(--ink); }

.result-dyn {
  grid-area: dyn;
  font-size: 0.75rem; color: var(--accent); letter-spacing: 0.06em;
  border-right: 1px solid var(--line); padding-right: var(--sp-3);
  align-self: stretch; display: flex; align-items: center;
}
.result-title { grid-area: title; font-family: var(--font-serif); font-size: 1.0625rem; font-weight: 600; letter-spacing: 0.04em; }
.result-life  { grid-area: life; font-family: var(--font-mono); font-size: 0.75rem; color: var(--faint); white-space: nowrap; }
.result-sum   { grid-area: sum; font-size: 0.8125rem; line-height: 1.7; color: var(--sub);
                display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

mark { background: color-mix(in srgb, var(--gold) 38%, transparent); color: var(--ink); padding: 0 2px; border-radius: 2px; }

@media (max-width: 560px) {
  .result { grid-template-columns: 1fr auto; grid-template-areas: "title life" "dyn dyn" "sum sum"; }
  .result-dyn { border-right: none; padding-right: 0; }
}

/* ============================================================
   人物关系图
   ============================================================ */

.graph-wrap {
  position: relative;
  height: clamp(420px, 68vh, 720px);
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

#graph {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.graph-legend {
  position: absolute; top: var(--sp-4); left: var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-card);
  border-radius: var(--r-full);
  font-size: 0.8125rem;
  color: var(--ink);
  pointer-events: none;
  min-height: 34px;
}
.graph-legend:empty { display: none; }
.graph-legend b { font-family: var(--font-serif); font-size: 0.9375rem; letter-spacing: 0.04em; }
.gl-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.gl-meta { color: var(--sub); font-size: 0.75rem; }

.graph-hint {
  position: absolute; bottom: var(--sp-4); right: var(--sp-4);
  font-size: 0.75rem; color: var(--faint);
  padding: var(--sp-1) var(--sp-3);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  border-radius: var(--r-full);
  pointer-events: none;
}

/* 无脚本时的文字版关系列表 */
.rel-list { margin-top: var(--sp-12); }
.rel-list dl { margin: 0; }
.rel-list dt {
  font-family: var(--font-serif); font-size: 1.0625rem; font-weight: 600;
  margin-top: var(--sp-6); padding-top: var(--sp-3); border-top: 1px solid var(--line);
}
.rel-list dd { margin: var(--sp-2) 0 0; font-size: 0.875rem; color: var(--sub); line-height: 1.9; }
.rel-list dd a { border-bottom: 1px solid var(--line-strong); }
.rel-list dd span { color: var(--faint); font-size: 0.75rem; }

/* ============================================================
   页面过渡（View Transitions，浏览器支持时自动生效）
   ============================================================ */

@view-transition { navigation: auto; }

::view-transition-old(root) { animation: vt-out 0.22s var(--ease) both; }
::view-transition-new(root) { animation: vt-in 0.28s var(--ease) both; }

@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in  { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  html { scroll-behavior: auto; }
}

/* ============================================================
   页脚
   ============================================================ */

.site-footer {
  margin-top: var(--sp-16);
  padding: var(--sp-12) 0;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: var(--sp-6); align-items: center; justify-content: space-between; }
.site-footer p { margin: 0; font-size: 0.875rem; color: var(--sub); }
.site-footer nav { display: flex; gap: var(--sp-6); }
.site-footer nav a { font-size: 0.875rem; color: var(--sub); }

/* ============================================================
   工具类
   ============================================================ */

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: var(--sp-3) var(--sp-4);
  border-radius: 0 0 var(--r-sm) 0; z-index: 100;
}
.skip-link:focus { left: 0; }

.empty {
  padding: var(--sp-12) var(--sp-6); text-align: center;
  color: var(--sub); background: var(--surface);
  border: 1px dashed var(--line-strong); border-radius: var(--r-md);
}

/* ============================================================
   打印
   ============================================================ */

@media print {
  .site-header, .site-footer, .timeline, .nav-toggle { display: none; }
  body { background: #fff; }
}
