/* ===== 全局变量 ===== */
:root {
  --bg: #f5f0e8;
  --bg-secondary: #ede4d3;
  --text: #2c2416;
  --text-secondary: #6b5e4a;
  --china-color: #8b2500;
  --china-bg: #fef5ee;
  --china-border: #d4a574;
  --china-accent: #c0392b;
  --world-color: #1a3a5c;
  --world-bg: #eef4fa;
  --world-border: #7ba4c7;
  --world-accent: #2471a3;
  --center-line: #b8a88a;
  --year-badge-bg: #3d3226;
  --year-badge-text: #f5f0e8;
  --modal-bg: #fffef9;
  --shadow: 0 2px 8px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
  --border-radius: 8px;
  --transition: 0.25s ease;
}

body.dark {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --text: #e0d6c2;
  --text-secondary: #a09888;
  --china-color: #f0a080;
  --china-bg: #2a1a1a;
  --china-border: #6b3a3a;
  --china-accent: #e07050;
  --world-color: #80b0d0;
  --world-bg: #1a2430;
  --world-border: #3a5a7a;
  --world-accent: #5090b0;
  --center-line: #5a4a3a;
  --year-badge-bg: #c0a880;
  --year-badge-text: #1a1a2e;
  --modal-bg: #1e1e32;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

/* ===== 基础 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "Noto Serif SC", "Source Han Serif SC", "SimSun", "STSong", Georgia, serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
}

/* ===== 头部 ===== */
.header {
  text-align: center;
  padding: 28px 16px 16px;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--center-line);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  max-width: 900px;
  margin: 0 auto;
}

.search-box { display: flex; gap: 6px; }

.search-box input {
  padding: 7px 12px;
  border: 1px solid var(--center-line);
  border-radius: var(--border-radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  width: 210px;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.search-box input:focus { outline: none; border-color: var(--china-accent); }

.search-box button,
#resetBtn,
#toggleModeBtn {
  padding: 7px 14px;
  border: 1px solid var(--center-line);
  border-radius: var(--border-radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all var(--transition);
  white-space: nowrap;
}

.search-box button:hover,
#resetBtn:hover,
#toggleModeBtn:hover {
  background: var(--text);
  color: var(--bg);
}

.filter-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.filter-box select {
  padding: 7px 10px;
  border: 1px solid var(--center-line);
  border-radius: var(--border-radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* ===== 时间线外层 ===== */
.timeline-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

/* ===== 列标题行 ===== */
.timeline-header-row {
  display: grid;
  grid-template-columns: 1fr 60px 1fr;
  align-items: center;
  position: sticky;
  top: 140px;
  z-index: 20;
  padding: 10px 0;
  backdrop-filter: blur(6px);
  margin-bottom: 12px;
}

.th-left { text-align: right; padding-right: 10px; }
.th-right { text-align: left; padding-left: 10px; }
.th-center { /* center gap */ }

.th-left h2 { color: var(--china-accent); font-size: 18px; letter-spacing: 2px; }
.th-right h2 { color: var(--world-accent); font-size: 18px; letter-spacing: 2px; }

/* ===== 滚动区域 ===== */
.timeline-scroll {
  position: relative;
}

.center-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--center-line);
  transform: translateX(-50%);
  z-index: 0;
  border-radius: 2px;
}

/* ===== 时间线主体 ===== */
.timeline-body {
  position: relative;
  z-index: 1;
}

/* ===== 朝代分隔条 (全宽) ===== */
.dynasty-row {
  display: grid;
  grid-template-columns: 1fr 0px 1fr;
  margin: 20px 0 10px;
  position: relative;
  z-index: 2;
}

.dynasty-bar {
  text-align: center;
  padding: 6px 0;
}

.dynasty-bar .label {
  display: inline-block;
  padding: 5px 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  border-radius: 4px;
}

.dynasty-bar.china .label {
  background: var(--china-bg);
  color: var(--china-accent);
  border: 1px solid var(--china-border);
}

.dynasty-bar.world .label {
  background: var(--world-bg);
  color: var(--world-accent);
  border: 1px solid var(--world-border);
}

/* ===== 年份标记 (全宽) ===== */
.year-row {
  display: grid;
  grid-template-columns: 1fr 0px 1fr;
  margin: 18px 0 8px;
  position: relative;
  z-index: 2;
}

.year-marker {
  text-align: center;
}

.year-badge {
  display: inline-block;
  background: var(--year-badge-bg);
  color: var(--year-badge-text);
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  transition: background var(--transition), color var(--transition);
}

/* ===== 事件行 ===== */
.event-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  position: relative;
  z-index: 2;
  margin-bottom: 3px;
}

.event-card {
  padding: 9px 13px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  min-height: 44px;
}

.event-card.empty {
  visibility: hidden;
  pointer-events: none;
}

.china-card {
  background: var(--china-bg);
  border-color: var(--china-border);
  text-align: right;
  margin-right: 12px;
}

.china-card:hover {
  box-shadow: var(--shadow);
  transform: translateX(-3px);
  border-color: var(--china-accent);
}

.world-card {
  background: var(--world-bg);
  border-color: var(--world-border);
  text-align: left;
  margin-left: 12px;
}

.world-card:hover {
  box-shadow: var(--shadow);
  transform: translateX(3px);
  border-color: var(--world-accent);
}

.card-year {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 1px;
}

.china-card .card-year { color: var(--china-accent); }
.world-card .card-year { color: var(--world-accent); }

.card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.4;
}

.china-card .card-title { color: var(--china-color); }
.world-card .card-title { color: var(--world-color); }

.card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ===== 高亮动画 ===== */
.event-card.highlight {
  animation: pulse 1s ease-in-out 2;
}

@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 14px 3px rgba(192,57,43,0.35); }
}

/* ===== 弹窗 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--modal-bg);
  border-radius: 12px;
  padding: 28px 30px;
  max-width: 540px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
  transition: background var(--transition);
}

.modal-close {
  position: absolute;
  top: 10px; right: 15px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal h3 { font-size: 19px; margin-bottom: 4px; }
.modal .modal-year { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.modal .modal-body { font-size: 14px; line-height: 1.8; color: var(--text); }

.modal .modal-related {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--center-line);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== 回到顶部 ===== */
.back-to-top {
  position: fixed;
  bottom: 28px; right: 28px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--year-badge-bg);
  color: var(--year-badge-text);
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px);
  transition: all var(--transition);
  z-index: 200;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--china-accent);
  transform: translateY(-2px);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .header h1 { font-size: 19px; }
  .controls { gap: 6px; }
  .search-box input { width: 140px; }

  .timeline-header-row { grid-template-columns: 1fr 0px 1fr; top: 155px; }
  .th-left h2, .th-right h2 { font-size: 14px; }

  .center-line { display: none; }

  .event-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .china-card { margin-right: 0; text-align: left; }
  .world-card { margin-left: 0; }

  .dynasty-row { grid-template-columns: 1fr; }
  .year-row { grid-template-columns: 1fr; }

  .year-marker .year-badge { font-size: 12px; padding: 3px 12px; }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--center-line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
