:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --paper-deep: #e9e3d8;
  --ink: #202825;
  --muted: #707873;
  --line: #c9c1b4;
  --card: rgba(255, 254, 250, .95);
  --accent: #aa4333;
  --accent-deep: #7f2f25;
  --accent-soft: #f1ddd7;
  --sage: #41695e;
  --sage-soft: #e2ece7;
  --gold: #9b6b2f;
  --gold-soft: #f4e9d7;
  --shadow: 0 22px 58px rgba(47, 39, 28, .13), 0 3px 12px rgba(47, 39, 28, .06);
  --radius: 20px;
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
/* 禁用浏览器自带的双击放大与双指捏合：pan-x/pan-y 保留手指滚动（弹窗列表仍可滑），页面缩放只走右上角按钮 */
html, body { touch-action: pan-x pan-y; }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 17% 10%, rgba(255,255,255,.85), transparent 28%),
    radial-gradient(circle at 82% 78%, rgba(178,146,111,.1), transparent 34%),
    var(--paper);
}
button, input { font: inherit; }
button { color: inherit; }

.timeline-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.timeline-viewport.dragging { cursor: grabbing; }
.timeline-viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  background-image: radial-gradient(rgba(70,59,43,.13) .7px, transparent .7px);
  background-size: 22px 22px;
}
.timeline-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 18000px;
  height: 1200px;
  transform-origin: 0 0;
  will-change: transform;
}
.timeline-axis {
  position: absolute;
  left: 150px;
  right: 150px;
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--line) 1%, var(--line) 99%, transparent);
}
.timeline-axis::after {
  content: "";
  position: absolute;
  right: 12px;
  top: -5px;
  border-left: 11px solid var(--line);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}
.chapter-band {
  position: absolute;
  top: 112px;
  height: 976px;
  border-left: 1px dashed rgba(91,79,62,.18);
  pointer-events: none;
}
.chapter-band:nth-child(odd) { background: rgba(255,255,255,.12); }
.chapter-label {
  position: absolute;
  left: 24px;
  top: -35px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.chapter-label b {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
}

.timeline-node {
  position: absolute;
  left: var(--node-x);
  width: 370px;
}
.node-pin {
  position: absolute;
  left: 22px;
  top: -10px;
  z-index: 4;
  width: 21px;
  height: 21px;
  border: 5px solid var(--accent);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 0 0 6px rgba(170,67,51,.13);
}
.timeline-node.learned .node-pin { border-color: var(--sage); box-shadow: 0 0 0 6px rgba(65,105,94,.13); }
.timeline-node.active .node-pin { transform: scale(1.22); background: var(--accent); }
.node-date {
  position: absolute;
  left: 56px;
  top: -18px;
  z-index: 3;
  padding: 7px 11px;
  border: 1px solid rgba(170,67,51,.16);
  border-radius: 99px;
  background: var(--paper);
  color: var(--accent-deep);
  font: 800 14px/1 system-ui, sans-serif;
  letter-spacing: .02em;
  box-shadow: 0 5px 16px rgba(55,45,32,.07);
}
.node-connector {
  position: absolute;
  left: 32px;
  width: 1px;
  height: 57px;
  background: var(--line);
}
.timeline-node.above .node-connector { bottom: 9px; }
.timeline-node.below .node-connector { top: 10px; }
.node-card {
  position: absolute;
  left: 0;
  width: 356px;
  min-height: 180px;
  padding: 20px 21px 17px;
  border: 1px solid rgba(83,71,54,.13);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 12px 32px rgba(55,45,32,.09);
  cursor: pointer;
  user-select: none;
  text-align: left;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.timeline-node.above .node-card { bottom: 66px; }
.timeline-node.below .node-card { top: 66px; }
.node-card:hover, .node-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(170,67,51,.38);
  outline: none;
  box-shadow: var(--shadow);
}
.node-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 11px;
}
.node-meta strong { color: var(--accent); font-weight: 800; }
.topic-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.topic-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 0 10px 15px;
  border-top: 1px solid #eee9df;
  color: #303936;
}
.topic-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b8afa1;
}
.topic-row:first-child { border-top: 0; padding-top: 4px; }
.topic-row:first-child::before { top: 10px; }
.topic-row.major::before { width: 7px; height: 7px; background: var(--accent); }
.topic-row.secondary { color: var(--muted); }
.topic-title {
  flex: 1 0 82%;
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
}
.topic-row.major .topic-title { color: #202724; font-size: 18px; font-weight: 850; }
.topic-row.secondary .topic-title { font-size: 14px; font-weight: 600; }
.topic-badge {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.3;
}
.topic-row.secondary .topic-badge { background: #ece8df; color: var(--muted); }
.related-time {
  color: var(--sage);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
}
.node-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid #e9e4db;
  color: var(--muted);
  font-size: 11px;
}
.node-foot strong { color: var(--accent); font-weight: 750; }
.timeline-node.learned .node-foot strong { color: var(--sage); }

.drag-hint {
  position: fixed;
  left: 50%;
  top: 28px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  transform: translateX(-50%);
  border: 1px solid rgba(66,58,46,.08);
  border-radius: 99px;
  background: rgba(255,255,255,.66);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(12px);
  animation: hint-away .5s ease 5s forwards;
}
.mouse-mark { position: relative; width: 11px; height: 15px; border: 1.5px solid currentColor; border-radius: 6px; }
.mouse-mark::before { content: ""; position: absolute; left: 4px; top: 2px; width: 1px; height: 4px; background: currentColor; }
@keyframes hint-away { to { opacity: 0; transform: translate(-50%, -8px); visibility: hidden; } }

.toolbar {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  gap: 7px;
  padding: 6px;
  border: 1px solid rgba(73,62,48,.1);
  border-radius: 16px;
  background: rgba(255,254,250,.84);
  box-shadow: 0 8px 25px rgba(49,42,32,.08);
  backdrop-filter: blur(18px);
}
.icon-button {
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { background: #eee9df; }
.icon-button.primary { color: #fff; background: var(--accent); }
.icon-button.primary:hover { background: var(--accent-deep); }
.icon-button.install { color: var(--sage); background: var(--sage-soft); }
.icon-button[hidden] { display: none; }
.icon-button svg, .search-field svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button svg .fill { fill: currentColor; stroke: none; }

.chapter-dock {
  position: fixed;
  left: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 25;
  display: flex;
  gap: 4px;
  max-width: calc(100vw - 36px);
  padding: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid rgba(73,62,48,.1);
  border-radius: 14px;
  background: rgba(255,254,250,.84);
  backdrop-filter: blur(18px);
}
.chapter-dock::-webkit-scrollbar { display: none; }
.chapter-dock button {
  flex: 0 0 auto;
  width: 33px;
  height: 33px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}
.chapter-dock button:hover, .chapter-dock button.active { color: #fff; background: var(--accent); }
.status-bar {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 24;
  display: flex;
  gap: 3px;
  padding: 5px;
  transform: translateX(-50%);
  border: 1px solid rgba(73,62,48,.1);
  border-radius: 14px;
  background: rgba(255,254,250,.88);
  backdrop-filter: blur(18px);
}
.status-bar button { min-width: 34px; height: 33px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; }
.status-bar button:hover { background: #eee9df; }
#current-status { min-width: 146px; color: var(--muted); font-size: 12px; }

.modal[hidden], .detail-scrim[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: start center; padding: 8vh 18px 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31,39,37,.22); backdrop-filter: blur(5px); }
.search-panel, .info-panel { position: relative; z-index: 1; width: min(690px, 100%); border: 1px solid rgba(74,63,48,.13); border-radius: 23px; background: #fffefb; box-shadow: 0 30px 90px rgba(37,31,23,.22); }
.search-panel { padding: 21px; }
.search-panel > label { display: block; margin: 0 3px 12px; font-family: "Noto Serif SC", "Songti SC", serif; font-size: 21px; font-weight: 800; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid #d9d1c5; border-radius: 13px; background: #f8f5ef; }
.search-field svg { flex: 0 0 20px; color: var(--muted); }
.search-field input { width: 100%; height: 50px; border: 0; outline: none; background: transparent; color: var(--ink); font-size: 15px; }
kbd { padding: 3px 6px; border: 1px solid #d8d0c3; border-bottom-width: 2px; border-radius: 6px; background: #fff; color: var(--muted); font: 11px system-ui; }
.search-summary { margin: 12px 3px 8px; color: var(--muted); font-size: 12px; }
.search-results { max-height: min(58vh, 520px); overflow-y: auto; }
.search-result { display: grid; grid-template-columns: 68px 1fr auto; gap: 12px; align-items: start; width: 100%; padding: 13px 10px; border: 0; border-top: 1px solid #eee9e1; background: transparent; text-align: left; cursor: pointer; }
.search-result:hover, .search-result[aria-selected="true"] { background: #f7f1eb; }
.result-number { color: var(--accent); font: 800 12px/1.5 system-ui; }
.result-main strong { display: block; font-size: 14px; line-height: 1.45; }
.result-main span { display: -webkit-box; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result-years { color: var(--muted); font-size: 11px; white-space: nowrap; }
.empty-results { padding: 50px 20px; color: var(--muted); text-align: center; }

.detail-scrim { position: fixed; inset: 0; z-index: 49; background: rgba(28,34,32,.2); backdrop-filter: blur(2px); }
.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(720px, 94vw);
  background: #fffefb;
  box-shadow: -24px 0 70px rgba(39,32,23,.18);
  transform: translateX(105%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.detail-panel.open { transform: translateX(0); }
.detail-toolbar { display: flex; justify-content: space-between; padding: max(16px, env(safe-area-inset-top)) 23px 12px; border-bottom: 1px solid #eee9df; }
.plain-icon { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: #f3efe7; cursor: pointer; font-size: 24px; line-height: 1; }
.learned-button { padding: 9px 14px; border: 1px solid #d8d0c3; border-radius: 99px; background: transparent; cursor: pointer; color: var(--muted); font-size: 12px; }
.learned-button.active { color: #fff; border-color: var(--sage); background: var(--sage); }
.detail-content { flex: 1; padding: 32px clamp(24px,6vw,58px) 76px; overflow-y: auto; user-select: text; }
.event-detail-header { padding-bottom: 27px; border-bottom: 2px solid #e8e2d8; }
.event-detail-header .eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .15em; }
.event-detail-header h2 { margin: 0; color: var(--accent-deep); font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: clamp(38px,6vw,58px); line-height: 1.15; }
.event-detail-header > p:last-child { margin: 13px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.knowledge-section { padding: 33px 0 24px; border-bottom: 1px solid #e8e2d8; }
.knowledge-section.major { border-left: 4px solid var(--accent); padding-left: 24px; }
.knowledge-section.secondary { opacity: .88; }
.knowledge-section.search-hit { animation: search-hit 1.8s ease-out; }
@keyframes search-hit {
  0%, 35% { background: #fff1bd; box-shadow: 0 0 0 12px #fff1bd; }
  100% { background: transparent; box-shadow: 0 0 0 0 transparent; }
}
.knowledge-kicker { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 8px; color: var(--muted); font-size: 11px; letter-spacing: .05em; }
.knowledge-section h3 { margin: 0; font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: clamp(25px,3.5vw,34px); line-height: 1.35; letter-spacing: .01em; }
.knowledge-section.major h3 { color: #1d2522; font-size: clamp(29px,4vw,39px); font-weight: 900; }
.knowledge-section.secondary h3 { color: #4f5854; font-size: clamp(21px,3vw,28px); }
.knowledge-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 14px 0 23px; }
.knowledge-tags .topic-badge { font-size: 11px; padding: 5px 9px; }
.knowledge-tags .related-time { padding: 5px 9px; border-radius: 99px; background: var(--sage-soft); font-size: 11px; }
.knowledge-body { display: grid; gap: 4px; }
.detail-line { margin: 0 0 9px; color: #303835; font-size: 16px; line-height: 1.95; text-align: justify; }
.detail-line strong { color: #161d1b; font-weight: 850; }
.detail-line.content-heading { margin: 23px 0 10px; padding: 11px 14px; border-left: 4px solid var(--accent); background: linear-gradient(90deg, #f7ebe7, transparent); color: var(--accent-deep); font-size: 19px; font-weight: 850; line-height: 1.55; }
.detail-line.bullet-paragraph { padding: 10px 14px; border-left: 4px solid #d8c9c3; background: #fbf8f3; }
.detail-line.numbered { padding: 9px 14px 9px 18px; border-left: 3px solid #d8c9c3; background: #fbf8f3; }
.detail-line.exam-note { margin: 16px 0; padding: 13px 15px; border: 1px solid #ead1c9; border-radius: 12px; background: #fbefeb; color: var(--accent-deep); font-weight: 700; }
.detail-line.key-conclusion { margin: 14px 0; padding: 12px 15px; border-radius: 12px; background: var(--sage-soft); color: #274e43; font-size: 17px; font-weight: 800; }
.detail-line.subheading { margin-top: 20px; color: var(--gold); font-size: 18px; font-weight: 800; }
.inline-date { padding: 1px 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-deep); font-weight: 850; white-space: nowrap; }
.inline-tag { color: var(--gold); font-weight: 800; }
.detail-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 22px max(14px,env(safe-area-inset-bottom)); border-top: 1px solid #eee9df; background: rgba(255,254,251,.96); }
.detail-navigation button { height: 42px; border: 0; border-radius: 11px; background: #f1ede5; cursor: pointer; font-size: 12px; }
.detail-navigation button:hover { background: #e9e3d8; }

.info-panel { padding: 32px; }
.info-close { position: absolute; top: 18px; right: 18px; }
.info-panel > .eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.info-panel h2 { margin: 8px 50px 26px 0; font-family: "Noto Serif SC", "Songti SC", serif; font-size: 28px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.info-grid > div { padding: 16px; border-radius: 13px; background: #f6f2eb; }
.info-grid span { color: var(--accent); font-size: 12px; font-weight: 750; }
.info-grid p { margin: 7px 0 0; color: #525b57; font-size: 13px; line-height: 1.65; }
.source-note { margin: 18px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.6; }

@media (max-width: 760px) {
  .timeline-stage { height: 1300px; }
  .chapter-band { top: 98px; height: 1104px; }
  .timeline-node { width: 320px; }
  .node-card { width: 306px; padding: 17px 18px 15px; }
  .topic-title { font-size: 14px; }
  .topic-row.major .topic-title { font-size: 16px; }
  .toolbar { top: max(12px,env(safe-area-inset-top)); right: 12px; }
  .toolbar #reset-view { display: none; }
  .chapter-dock { left: 12px; bottom: max(12px,env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
  .status-bar { bottom: calc(max(12px,env(safe-area-inset-bottom)) + 49px); }
  .drag-hint { top: 67px; }
  .modal { padding: 5vh 10px 10px; }
  .search-panel { padding: 17px; border-radius: 19px; }
  .search-result { grid-template-columns: 63px 1fr; }
  .result-years { display: none; }
  .detail-panel { width: 100vw; }
  .knowledge-section.major { padding-left: 16px; }
  .detail-line { font-size: 15px; line-height: 1.9; }
  .info-panel { padding: 26px 20px; }
  .info-grid { grid-template-columns: 1fr; }
}

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