/* ==========================================================================
   曾氏族谱 · 核心布局、时间轴、世系画布与传记画卷样式
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* ================= 1. 左侧栏：古风纪年时间轴 ================= */
.timeline-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid rgba(139, 38, 29, 0.12);
  display: flex;
  flex-direction: column;
  padding: 24px 10px 16px;
  z-index: 20;
  box-shadow: 2px 0 18px rgba(44, 38, 35, 0.05);
  position: relative;
}

.clan-brand {
  text-align: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(139, 38, 29, 0.15);
}

.clan-brand h1 {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
  color: var(--color-title);
  letter-spacing: 4px;
  margin-bottom: 6px;
}

.clan-brand .subtitle {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 2px;
}

.timeline-mode-label {
  font-size: 11px;
  color: var(--color-accent);
  background: rgba(139, 38, 29, 0.08);
  padding: 4px 8px;
  border-radius: 4px;
  text-align: center;
  margin-bottom: 16px;
  font-family: var(--font-serif);
}

/* 贯穿上下的细竖线与年份节点容器 */
.timeline-track-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 10px 4px 10px 6px;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 8px; /* 紧凑大年代间距，不再使用 justify-content: space-between 拉得过大 */
}

.timeline-track-wrapper::-webkit-scrollbar {
  width: 3px;
}
.timeline-track-wrapper::-webkit-scrollbar-thumb {
  background: rgba(139, 38, 29, 0.2);
  border-radius: 2px;
}

/* 贯穿竖线 */
.timeline-vertical-line {
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 13px;
  width: 1px;
  background-color: rgba(139, 38, 29, 0.28);
  z-index: 1;
}

.timeline-point {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 6px 0;
  transition: transform var(--transition-fast);
}

.timeline-point:hover .dot {
  border-color: var(--color-accent);
  transform: scale(1.2);
}

/* 空心圆点 ○ */
.timeline-point .dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background-color: var(--bg-sidebar);
  border: 2px solid var(--text-secondary);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

/* 年份与标签文本 */
.timeline-point .year-info {
  margin-left: 14px;
  display: flex;
  flex-direction: column;
}

.timeline-point .year-num {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  line-height: 1.2;
}

.timeline-point .year-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
}

/* 激活状态：实心放大 + 年份高亮 */
.timeline-point.active .dot {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
  transform: scale(1.35);
  box-shadow: 0 0 0 4px rgba(139, 38, 29, 0.15);
}

.timeline-point.active .year-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-accent);
}

.timeline-point.active .year-desc {
  color: var(--text-primary);
  font-weight: 500;
}

.timeline-footer {
  padding-top: 12px;
  border-top: 1px solid rgba(139, 38, 29, 0.12);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ================= 2. 右侧主区域：双模式视图容器 ================= */
.main-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-canvas);
  /* 微妙宣纸纹理点阵 */
  background-image: radial-gradient(rgba(139, 38, 29, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* 顶部悬浮导航与搜索工具栏 */
.stage-toolbar {
  position: absolute;
  top: 20px;
  left: 24px;
  right: 24px;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  padding: 8px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow-node);
  border: 1px solid rgba(184, 134, 85, 0.2);
}

.poem-banner {
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--color-title);
  letter-spacing: 1px;
  padding-right: 8px;
  border-right: 1px solid #e5dec9;
}

.btn-tool {
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--font-sans);
  background: #fff;
  color: var(--text-primary);
  border: 1px solid #dcd3c2;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.btn-tool:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--bg-card-hover);
}

.btn-tool.primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.btn-tool.primary:hover {
  background: #6e1c15;
}

.search-input {
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid #dcd3c2;
  border-radius: 4px;
  outline: none;
  width: 150px;
  background: #faf7f2;
}

.search-input:focus {
  border-color: var(--color-accent);
  background: #fff;
}

/* ================= 模式 A：世系脉络画布 ================= */
.tree-viewport {
  width: 100%;
  height: 100%;
  cursor: grab;
  position: relative;
  /* 5000x4000 的画布在这里裁切，避免把 .main-stage 撑成可被 scrollIntoView 滚动的容器 */
  overflow: hidden;
}

.tree-viewport:active {
  cursor: grabbing;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 5000px;
  height: 4000px;
  transform-origin: 0 0;
}

#connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 人物白色矩形块 */
.person-node {
  position: absolute;
  width: var(--node-width);
  height: var(--node-height);
  background: var(--bg-card);
  border-radius: var(--radius-node);
  padding: 10px 14px;
  box-shadow: var(--shadow-node);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity 0.3s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 3px solid var(--node-male-border);
}

.person-node.female {
  border-left-color: var(--node-female-border);
}

.person-node.root-ancestor {
  border-left: 4px solid var(--color-accent);
  background: linear-gradient(to right, #fff9f5, #ffffff);
}

.person-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-node-hover);
}

.person-node.highlighted {
  box-shadow: 0 0 0 2px var(--color-accent), var(--shadow-node-hover);
}

.person-node.dimmed {
  opacity: 0.22;
  filter: grayscale(85%);
}

.person-node .node-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.person-node .gen-tag {
  font-size: 10px;
  color: var(--color-gold);
  font-family: var(--font-serif);
  letter-spacing: 0.5px;
}

.person-node .bio-indicator {
  font-size: 10px;
  color: var(--color-accent);
  background: rgba(139, 38, 29, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
}

.person-node .person-name {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.person-node .person-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 节点右侧折叠/展开子支小圆钮 */
.fold-toggle {
  position: absolute;
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--color-gold);
  color: var(--color-gold);
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  z-index: 5;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  transition: all var(--transition-fast);
}

.fold-toggle:hover {
  background: var(--color-gold);
  color: #fff;
  transform: translateY(-50%) scale(1.12);
}

/* 竖排（手机）：子支在下方，折叠按钮移到节点底边中间 */
#canvas-world.is-vertical .fold-toggle {
  right: auto;
  left: 50%;
  top: auto;
  bottom: -10px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  font-size: 12px;
  transform: translateX(-50%);
}

#canvas-world.is-vertical .fold-toggle:hover {
  transform: translateX(-50%) scale(1.12);
}

/* 竖排（手机）：人名竖写，节点变成一列字条 */
#canvas-world.is-vertical .person-node,
#canvas-world.is-vertical .spouse-node {
  padding: 6px 0 !important;
}

#canvas-world.is-vertical .person-node .person-name,
#canvas-world.is-vertical .spouse-node .person-name {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 2px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: visible;
}

#canvas-world.is-vertical .person-node .bio-indicator {
  margin-left: 0;
  margin-top: 4px;
}

/* ================= 模式 B：人物传记画卷（3栏卡片并排阅读视图） ================= */
.biography-overlay {
  position: absolute;
  inset: 0;
  background: rgba(245, 239, 226, 0.94);
  backdrop-filter: blur(8px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.biography-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* 传记顶部人物抬头栏：自适应铺满舞台宽度，消除大屏两侧巨大空白 */
.bio-header-bar {
  width: 94%;
  max-width: calc(3 * var(--scroll-card-width) + 2 * var(--scroll-card-gap) + 120px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(139, 38, 29, 0.18);
}

.bio-person-title h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  color: var(--color-title);
  letter-spacing: 3px;
  display: inline-block;
  margin-right: 14px;
}

.bio-person-title .bio-badge {
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--text-secondary);
  background: rgba(184, 134, 85, 0.15);
  padding: 3px 10px;
  border-radius: 4px;
  margin-right: 10px;
}

.bio-person-title .bio-lifespan {
  font-size: 13px;
  color: var(--text-muted);
}

.bio-close-btn {
  padding: 7px 18px;
  font-size: 13px;
  font-family: var(--font-serif);
  background: transparent;
  color: var(--color-title);
  border: 1px solid var(--color-title);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.bio-close-btn:hover {
  background: var(--color-title);
  color: #fff;
}

/* 画卷主体：左右翻页大箭头 + 3栏高挑卡片视口（无死板1220px限制，随窗口自由伸缩） */
.scroll-gallery-container {
  position: relative;
  width: 96%;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-nav-arrow {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(139, 38, 29, 0.25);
  color: var(--color-title);
  font-size: 24px;
  font-family: var(--font-serif);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-node);
  transition: all var(--transition-fast);
  flex-shrink: 0;
  z-index: 5;
}

.gallery-nav-arrow:hover:not(:disabled) {
  background: var(--color-title);
  color: #fff;
  transform: scale(1.08);
}

.gallery-nav-arrow:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

/* 3栏并排卡片轨道视口：精确等于3张卡片+2个间距，绝不裁切或错位 */
.cards-viewport {
  flex: none;
  width: calc(3 * var(--scroll-card-width) + 2 * var(--scroll-card-gap));
  max-width: calc(100% - 116px);
  overflow: hidden;
  margin: 0 12px;
  padding: 12px 0 24px;
}

.cards-track {
  display: flex;
  gap: var(--scroll-card-gap);
  transition: transform var(--transition-smooth);
}

/* 单张高挑纵向传记卡片 */
.chapter-card {
  width: var(--scroll-card-width);
  box-sizing: border-box;
  height: var(--scroll-card-height);
  max-height: 780px;
  min-height: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  border-top: 3px solid transparent;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chapter-card:hover {
  transform: translateY(-4px);
}

/* 当前焦点年份卡片高亮 */
.chapter-card.active-card {
  border-top-color: var(--color-accent);
  box-shadow: 0 20px 48px rgba(139, 38, 29, 0.16);
}

/* 顶部复古色调配图 (占卡片高度减半至 18%) */
.chapter-card .card-image-box {
  height: 18%;
  min-height: 80px;
  width: 100%;
  position: relative;
  overflow: hidden;
  background: #e6dfd3;
}

.chapter-card .card-image-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(25%) contrast(95%);
  transition: transform 0.6s ease;
}

.chapter-card:hover .card-image-box img {
  transform: scale(1.04);
}

.chapter-card .card-year-tag {
  position: absolute;
  bottom: 10px;
  left: 16px;
  background: rgba(44, 38, 35, 0.78);
  color: #f5efe2;
  font-family: var(--font-serif);
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 3px;
  letter-spacing: 1px;
}

/* 下方章节标题与正文段落 */
.chapter-card .card-body {
  flex: 1;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  user-select: text;
}

.chapter-card .card-body::-webkit-scrollbar {
  width: 4px;
}

.chapter-card .card-body::-webkit-scrollbar-thumb {
  background: #dcd3c2;
  border-radius: 2px;
}

.chapter-card .chapter-title {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  line-height: 1.4;
  border-left: 3px solid var(--color-gold);
  padding-left: 10px;
}

.chapter-card .chapter-content p {
  word-break: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
  font-size: 14px;
  line-height: 1.85;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: justify;
}

.chapter-card .card-relations {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px dashed #e5dec9;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.relation-link {
  font-size: 12px;
  color: var(--color-accent);
  background: rgba(139, 38, 29, 0.06);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.relation-link:hover {
  background: rgba(139, 38, 29, 0.15);
}

/* 原版族谱扫描件对照弹窗 */
.image-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.85);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.image-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.image-modal img {
  max-width: 90vw;
  max-height: 82vh;
  border: 6px solid #f5efe2;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.image-modal .modal-bar {
  margin-top: 14px;
  display: flex;
  gap: 16px;
  align-items: center;
  color: #f5efe2;
  font-family: var(--font-serif);
}

/* ===== 配偶：本人正下方，短竖线连接 ===== */
.spouse-link { position: absolute; width: 0; border-left: 1.4px solid var(--line-stroke); }
.spouse-node {
  position: absolute; background: var(--bg-card); border-radius: var(--radius-node);
  border-left: 3px solid var(--node-female-border); box-shadow: var(--shadow-node);
  padding: 6px 14px; display: flex; flex-direction: column; justify-content: center;
}
.spouse-node .person-name { font-family: var(--font-serif); font-size: 15px; font-weight: 700; }
.spouse-node .gen-tag { font-size: 10px; color: var(--color-gold); font-family: var(--font-serif); }
.spouse-node.placeholder { background: transparent; border: 1px dashed var(--color-gold); box-shadow: none; opacity: .6; }

/* 紧凑节点：仅显示姓名 */
.person-node { padding: 0 10px; align-items: center; flex-direction: row; justify-content: center; position: absolute; }
.person-node .person-name { font-size: 15px; white-space: nowrap; }
.person-node .bio-indicator { margin-left: 6px; }
.spouse-node { padding: 0 10px; align-items: center; }

/* 超紧凑 */
.person-node, .spouse-node { padding: 0 6px !important; line-height: 1; }
.person-node .person-name { font-size: 13px; letter-spacing: 0; }
.spouse-node .person-name { font-size: 12px; }
.fold-toggle { width: 16px; height: 16px; line-height: 14px; font-size: 10px; right: -8px; }
.person-node { border-radius: 4px; }

.person-node.main-line { border-left: 2px solid var(--color-accent); }
.person-node.main-line .person-name { font-size: 15px; font-weight: 700; color: var(--color-title); }
.person-node:not(.main-line) .person-name { font-size: 12px; }

.person-node { cursor: grab; }
.person-node:active { cursor: grabbing; }

/* ================= 纪年树形时间轴与事件卡片扩展 ================= */

/* 左侧栏调整：无冗余滚动条，紧凑优雅 */
.timeline-track-wrapper {
  padding: 8px 4px 8px 6px;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 8px;
}
.timeline-track-wrapper::-webkit-scrollbar {
  width: 3px;
}
.timeline-track-wrapper::-webkit-scrollbar-thumb {
  background: rgba(139, 38, 29, 0.2);
  border-radius: 2px;
}

/* 贯穿竖线位置微调 */
.timeline-vertical-line {
  left: 14px;
  top: 14px;
  bottom: 14px;
}

/* 阶段组大容器 */
.timeline-stage-group {
  position: relative;
  margin-bottom: 10px;
  z-index: 2;
}

/* 阶段头部（中文时间大分隔） */
.stage-header {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 8px 8px 0;
  border-radius: 4px;
  transition: background var(--transition-fast);
}
.stage-header:hover {
  background: rgba(139, 38, 29, 0.05);
}

.stage-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #EAE3D2;
  border: 2px solid var(--color-title);
  flex-shrink: 0;
  margin-right: 12px;
  transition: all var(--transition-fast);
}
.timeline-stage-group.expanded .stage-dot {
  background: var(--color-title);
  box-shadow: 0 0 0 3px rgba(139, 38, 29, 0.18);
  transform: scale(1.15);
}

.stage-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stage-period {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--color-title);
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.stage-brief-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(139, 38, 29, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

.stage-arrow {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
  transition: transform var(--transition-fast);
}

/* 阶段下具体年份列表（点击展开） */
.stage-sub-years {
  display: none;
  flex-direction: column;
  padding-left: 14px;
  margin-top: 4px;
  margin-bottom: 6px;
  margin-left: 0;
}
.timeline-stage-group.expanded .stage-sub-years {
  display: flex;
}

.timeline-year-item {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.18s ease;
  line-height: 1.4;
  position: relative;
}
.timeline-year-item:hover {
  color: var(--color-title);
  background: rgba(139, 38, 29, 0.06);
}
.timeline-year-item .sub-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #EAE3D2;
  border: 1.5px solid var(--text-secondary);
  margin-right: 8px;
  margin-left: -1px;
  z-index: 2;
  flex-shrink: 0;
  transition: all 0.18s;
}
.timeline-year-item .sub-year-txt {
  font-family: var(--font-serif);
  font-weight: 500;
}
.timeline-year-item .sub-event-preview {
  font-size: 10px;
  color: var(--color-gold);
  margin-left: auto;
  padding-left: 4px;
}

/* 激活的具体年份 */
.timeline-year-item.active {
  color: var(--color-title);
  font-weight: 700;
  background: rgba(139, 38, 29, 0.1);
}
.timeline-year-item.active .sub-dot {
  background: var(--color-title);
  transform: scale(1.6);
}

/* ================= 3D 翻转卡片与动画 ================= */
.cards-viewport {
  perspective: 1600px;
}

.chapter-card.flip-card-item {
  opacity: 0;
  transform-origin: center center;
  transform: translateY(30px) rotateY(-85deg) scale(0.9);
  transition: transform 0.65s cubic-bezier(0.18, 0.9, 0.25, 1), opacity 0.5s ease;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.chapter-card.flip-card-item.flipped-in {
  opacity: 1;
  transform: translateY(0) rotateY(0deg) scale(1);
}

.chapter-card.flip-card-item:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 45px rgba(139, 38, 29, 0.18);
}

.card-inner-flip {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.event-era-seal {
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 900;
  color: rgba(139, 38, 29, 0.18);
  border: 1.5px solid rgba(139, 38, 29, 0.18);
  padding: 1px 8px;
  border-radius: 4px;
  transform: rotate(-10deg);
  pointer-events: none;
}

.event-meta-line {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--color-gold);
}
.event-age-tag {
  font-weight: 700;
  color: var(--color-title);
}
.event-loc-tag {
  color: var(--text-muted);
}

.event-footer-info {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px dashed rgba(184, 134, 85, 0.25);
  font-size: 11px;
}
.event-people {
  color: var(--text-secondary);
  margin-bottom: 3px;
}
.event-source {
  color: var(--color-gold);
}

/* ================= 底部进度条圆点 ================= */
.gallery-progress-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  z-index: 35;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(139, 38, 29, 0.22);
  cursor: pointer;
  transition: all 0.25s ease;
}
.progress-dot:hover {
  background: rgba(139, 38, 29, 0.5);
  transform: scale(1.2);
}
.progress-dot.active {
  background: var(--color-title);
  width: 22px;
  border-radius: 6px;
}

/* ================= 右侧内容区背景模糊 ================= */
.tree-viewport.blurred-backdrop {
  filter: blur(8px) brightness(0.92);
  pointer-events: none;
  transition: filter 0.4s ease;
}

.stage-toolbar {
  transition: opacity 0.3s ease;
}
.event-mode-active .stage-toolbar {
  opacity: 0.15;
  pointer-events: none;
}

/* ================= 2026 高分屏、2K 响应式与右上角 - A + 字体缩放 ================= */

:root {
  --font-scale: 1.0;
}

/* 全站字号根据 --font-scale 动态倍率缩放 */
.person-node .person-name {
  font-size: calc(13px * var(--font-scale)) !important;
}
.person-node.main-line .person-name {
  font-size: calc(15px * var(--font-scale)) !important;
}
.chapter-card .chapter-title {
  font-size: calc(19px * var(--font-scale)) !important;
}
.chapter-card .chapter-content p {
  word-break: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
  font-size: calc(14px * var(--font-scale)) !important;
}
.timeline-year-item {
  font-size: calc(13px * var(--font-scale)) !important;
}

/* 右上角 - A + 字体调节胶囊按钮 */
.font-scaler-box {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(139, 38, 29, 0.25);
  border-radius: 20px;
  padding: 2px 6px;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.scaler-btn {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-title);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.scaler-btn:hover {
  background: rgba(139, 38, 29, 0.12);
  transform: scale(1.15);
}

.scaler-label {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 24px;
  text-align: center;
}

/* ================= 2K 大屏 (>=1800px) 卡片与阅读自适应增强 ================= */
@media screen and (min-width: 1800px) {
  .chapter-card {
    max-height: 820px;
  }

  .chapter-card .chapter-title {
    font-size: calc(22px * var(--font-scale)) !important;
  }

  .chapter-card .chapter-content p {
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    font-size: calc(16px * var(--font-scale)) !important;
    line-height: 1.95;
  }
}

/* ================= 中等窗口 (961px ~ 1280px)：自动切换为 2 张卡片并排铺满 ================= */
@media screen and (max-width: 1280px) and (min-width: 961px) {
  :root {
    --gallery-avail-width: calc(100vw - var(--sidebar-width) - 150px);
    --scroll-card-gap: 20px;
    --scroll-card-width: calc((var(--gallery-avail-width) - var(--scroll-card-gap)) / 2);
  }
  .cards-viewport {
    width: calc(2 * var(--scroll-card-width) + var(--scroll-card-gap)) !important;
  }
  .bio-header-bar {
    max-width: calc(2 * var(--scroll-card-width) + var(--scroll-card-gap) + 100px) !important;
  }
}

/* ================= 移动端 / 触屏设备 / 窄屏窗口 (<=960px 或 触屏手机) 彻底适配 ================= */
@media (hover: none) and (pointer: coarse), screen and (max-width: 960px) {
  .person-node {
    cursor: default !important;
  }
  .tree-viewport {
    touch-action: none !important;
  }
}

/* ================= 手机端（<=960px / 触屏窄屏）：竖向铺满 + 竖排世系 ================= */
@media screen and (max-width: 960px), (hover: none) and (pointer: coarse) and (max-width: 1100px) {
  /* 0. dvh 避免微信 / iOS Safari 地址栏盖住底部 */
  .app-container {
    flex-direction: column !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }

  /* 1. 隐藏窄屏用不到的控件 */
  #search,
  #btn-undo,
  #btn-redo,
  .poem-banner {
    display: none !important;
  }

  /* 2. 工具栏：重置视角贴左，字号调节居中顶部 */
  .stage-toolbar {
    top: 8px !important;
    left: 8px !important;
    right: 8px !important;
    padding: 0 !important;
    display: flex !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
  }
  .toolbar-left, .toolbar-right {
    padding: 3px 6px !important;
    gap: 6px !important;
  }
  .toolbar-right {
    position: absolute !important;
    left: 50% !important;
    top: 0 !important;
    transform: translateX(-50%) !important;
  }
  .btn-tool {
    padding: 4px 8px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
  }

  /* 3. 底部“纪年”胶囊：把手 + 提示，一眼看出能上滑展开 */
  #btn-mobile-timeline {
    position: fixed !important;
    left: 50% !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 3px !important;
    padding: 6px 24px 8px !important;
    border: none !important;
    border-radius: 999px !important;
    background: linear-gradient(180deg, #9E3325, #7E2119) !important;
    color: #fff !important;
    box-shadow: 0 8px 20px rgba(139, 38, 29, 0.35), 0 2px 6px rgba(0, 0, 0, 0.18) !important;
    transform: translateX(-50%) !important;
    z-index: 20 !important;
    pointer-events: auto !important;
  }
  #btn-mobile-timeline .mtl-handle {
    width: 26px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.65);
  }
  #btn-mobile-timeline .mtl-text {
    font-family: var(--font-serif);
    font-size: 13px;
    letter-spacing: 2px;
    line-height: 1.15;
  }
  #btn-mobile-timeline .mtl-hint {
    font-size: 10px;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.75);
  }

  /* 看卡片时：纪年入口留在底部左下角（与中间圆点错开），不用退回首页也能换年代 */
  .biography-overlay.active ~ #btn-mobile-timeline {
    top: auto !important;
    left: 10px !important;
    right: auto !important;
    bottom: calc(6px + env(safe-area-inset-bottom)) !important;
    transform: none !important;
    z-index: 40 !important;
    flex-direction: row !important;
    gap: 4px !important;
    padding: 7px 12px !important;
    border-radius: 999px !important;
    background: rgba(139, 38, 29, 0.92) !important;
    box-shadow: 0 2px 10px rgba(139, 38, 29, 0.3) !important;
  }
  .biography-overlay.active ~ #btn-mobile-timeline .mtl-handle,
  .biography-overlay.active ~ #btn-mobile-timeline .mtl-hint {
    display: none !important;
  }
  .biography-overlay.active ~ #btn-mobile-timeline .mtl-text {
    font-size: 12px !important;
    letter-spacing: 1px !important;
    line-height: 1.15 !important;
  }
  .biography-overlay.active ~ #btn-mobile-timeline .mtl-icon {
    margin-right: 3px;
  }

  /* 4. 纪年抽屉 */
  .timeline-sidebar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: auto !important;
    max-height: 58dvh !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3) !important;
    transform: translateY(105%) !important;
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1) !important;
    z-index: 100 !important;
    padding: 16px 18px calc(16px + env(safe-area-inset-bottom)) !important;
    background: #EAE3D2 !important;
  }
  .timeline-sidebar.mobile-open {
    transform: translateY(0) !important;
  }

  /* 5. 画布全屏 */
  .main-stage {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    flex: 1 !important;
  }
  .tree-viewport {
    width: 100% !important;
    height: 100% !important;
    cursor: default !important;
    touch-action: none !important;
  }

  /* 6. 卡片画卷：卡片撑满可用高度（右上角年代印章与电脑端一致保留） */
  .biography-overlay {
    height: 100vh !important;
    height: 100dvh !important;
    padding: 0 !important;
    justify-content: flex-start !important;
  }
  /* 手机端卡片配图只有 112px 高，印章略缩小、内缩一点更协调 */
  .chapter-card .event-era-seal {
    top: 9px !important;
    right: 10px !important;
    font-size: 17px !important;
  }
  .bio-header-bar {
    width: calc(100% - 24px) !important;
    max-width: none !important;
    margin: 8px 12px 0 !important;
    padding-bottom: 8px !important;
    flex-shrink: 0 !important;
    align-items: center !important;
  }
  .bio-person-title {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
  .bio-person-title h2 {
    font-size: 17px !important;
    margin-right: 0 !important;
    letter-spacing: 1px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .bio-person-title .bio-badge,
  .bio-person-title .bio-lifespan {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    font-size: 11px !important;
  }
  /* 手机端顶部只留人名与返回键：隐藏灰色的年份/生卒文字，以及空的标签胶囊 */
  .bio-person-title .bio-lifespan {
    display: none !important;
  }
  .bio-person-title .bio-badge:empty {
    display: none !important;
  }
  .bio-close-btn {
    padding: 5px 10px !important;
    font-size: 11px !important;
    flex-shrink: 0 !important;
  }

  .scroll-gallery-container {
    position: relative !important;
    width: 100% !important;
    max-width: none !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 0 6px !important;
    align-items: stretch !important;
  }
  .cards-viewport {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 4px 0 0 !important;
    height: 100% !important;
  }
  .cards-track {
    height: 100% !important;
  }
  .chapter-card {
    width: var(--scroll-card-width) !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
  }
  .chapter-card .card-image-box {
    height: 112px !important;
    min-height: 0 !important;
    flex-shrink: 0 !important;
  }
  .chapter-card .card-body {
    padding: 14px 15px !important;
  }
  .chapter-card .chapter-title {
    font-size: calc(15px * var(--font-scale)) !important;
    margin-bottom: 8px !important;
  }
  .chapter-card .chapter-content p {
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    font-size: calc(13.5px * var(--font-scale)) !important;
    line-height: 1.72 !important;
    margin-bottom: 10px !important;
  }

  /* 箭头会压住满幅卡片，改用左右滑动 + 底部圆点 */
  .gallery-nav-arrow {
    display: none !important;
  }
  .gallery-progress-dots {
    margin: 6px 0 0 !important;
    padding: 0 0 calc(6px + env(safe-area-inset-bottom)) !important;
    flex-shrink: 0 !important;
  }

  :root {
    --scroll-card-width: calc(100vw - 20px) !important;
    --scroll-card-gap: 10px !important;
  }
}
