/* ============================================================
   基础与变量
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --ink:         #1c1917;
  --ink-mid:     #44403c;
  --ink-light:   #78716c;
  --paper:       #f7f4ef;   /* 暖纸色侧栏背景 */
  --panel-bg:    #ffffff;
  --border:      #e8e3db;
  --gold:        #fbbf24;   /* 路线/行迹金色 */
  --gold-dark:   #92400e;
  --purple:      #7c3aed;
  --amber:       #f59e0b;
  --rose:        #fb7185;
}

html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}

/* ============================================================
   整体布局
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 368px 1fr;
  height: 100vh;
  background: var(--paper);
}

/* ============================================================
   侧栏
   ============================================================ */
.sidebar {
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--border);
  /* 细滚动条 */
  scrollbar-width: thin;
  scrollbar-color: #d4cfc6 transparent;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #d4cfc6; border-radius: 3px; }

/* ---- 品牌区（深色墨色顶部）---- */
.brand {
  background: var(--ink);
  color: white;
  padding: 20px 22px 24px;
  position: relative;
  overflow: hidden;
}
/* 装饰大字 */
.brand::after {
  content: "鼐";
  position: absolute;
  right: -8px; top: -12px;
  font-size: 110px; font-weight: 900;
  color: rgba(255,255,255,0.05);
  line-height: 1; pointer-events: none; user-select: none;
}
.brand-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.brand-back {
  font-size: 11px; color: rgba(255,255,255,0.4);
  text-decoration: none; letter-spacing: 0.03em;
  transition: color 0.15s;
}
.brand-back:hover { color: rgba(255,255,255,0.75); }

.brand h1 {
  margin: 0 0 6px;
  font-size: 26px; font-weight: 800;
  letter-spacing: 0.06em; line-height: 1.2;
}
.brand-dates {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.intro {
  margin: 0; font-size: 12px;
  color: rgba(255,255,255,0.38);
  line-height: 1.75;
}

/* ---- 面板 ---- */
.panel {
  margin: 12px 14px 0;
  padding: 16px 16px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.panel:last-child { margin-bottom: 16px; }

/* 面板标题：小型大写标签风格 */
.panel h2 {
  margin: 0 0 14px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-light);
  padding-bottom: 10px;
  border-bottom: 1px solid #f0ece5;
  display: flex; align-items: center; gap: 8px;
}

/* ---- 基础信息 meta ---- */
.meta div, .stats div {
  display: flex; justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #f7f4ef;
}
.meta div:last-child, .stats div:last-child { border-bottom: 0; }
.meta span, .stats span { color: var(--ink-light); font-size: 12px; }
.meta strong, .stats strong { font-weight: 600; font-size: 13px; }

/* ---- 年份滑块 ---- */
.range-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--ink-mid);
  margin: 12px 0 6px;
}
.range-label span {
  font-weight: 700; color: var(--purple);
  font-variant-numeric: tabular-nums;
}

/* 自定义滑块样式 */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: linear-gradient(to right, var(--purple) 0%, var(--purple) 50%, #e8e3db 50%, #e8e3db 100%);
  border-radius: 2px; outline: none; cursor: pointer;
  margin: 2px 0 10px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: white;
  border: 3px solid var(--purple);
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 3px 12px rgba(124,58,237,0.45);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: white; border: 3px solid var(--purple);
  cursor: pointer;
}

/* ---- 按钮 ---- */
.actions { display: flex; gap: 8px; margin-top: 14px; }
button {
  appearance: none; border: 0;
  border-radius: 10px; padding: 9px 14px;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
button:active { transform: scale(0.97); }

/* 主操作按钮（第一个） */
#resetBtn { background: var(--ink); color: white; flex: 1; }
#resetBtn:hover { background: #374151; }
#fitBtn { background: #f0ece5; color: var(--ink); flex: 1; }
#fitBtn:hover { background: #e8e3db; }

/* ---- label 通用 ---- */
label {
  display: flex; align-items: center; gap: 8px;
  margin: 7px 0; font-size: 13px; color: var(--ink-mid);
  cursor: pointer;
}
label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--purple); }

/* ============================================================
   地图区
   ============================================================ */
.map-wrap { position: relative; }
#map { height: 100vh; width: 100%; }

/* ============================================================
   事件列表
   ============================================================ */
.event-list {
  display: grid; gap: 8px;
  max-height: 32vh; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #d4cfc6 transparent;
}
.event-card {
  padding: 10px 12px;
  border-radius: 10px;
  background: #faf8f4;
  border: 1px solid #ede9e1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.event-card:hover {
  background: #f0ebe0;
  border-color: #d4ccbc;
  transform: translateX(2px);
}
.event-year { font-size: 11px; color: var(--ink-light); margin-bottom: 3px; letter-spacing: 0.03em; }
.event-place { font-weight: 700; font-size: 13px; margin-bottom: 4px; color: var(--ink); }
.event-text { font-size: 12px; color: var(--ink-mid); line-height: 1.55; }

/* ============================================================
   高频地点前十
   ============================================================ */
.top10-list { display: grid; gap: 8px; }
.top10-row {
  display: grid; grid-template-columns: 32px 1fr;
  gap: 10px; align-items: center;
  padding: 9px 12px;
  border-radius: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.top10-row:hover { background: #fef3c7; transform: translateX(2px); }
.top10-rank {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  color: white; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.top10-place { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.top10-meta { font-size: 11px; color: var(--ink-light); }
.top10-empty { font-size: 12px; color: var(--ink-light); }

/* ============================================================
   地图弹窗（Leaflet popup）
   ============================================================ */
.leaflet-popup-content-wrapper {
  border-radius: 14px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15) !important;
  border: 1px solid rgba(0,0,0,0.06) !important;
}
.leaflet-popup-content {
  line-height: 1.7;
  min-width: 230px;
  margin: 16px 18px !important;
}
.popup-title {
  font-weight: 800; font-size: 15px;
  margin-bottom: 8px; color: var(--ink);
  padding-bottom: 8px;
  border-bottom: 1px solid #f0ece5;
}
.popup-meta {
  font-size: 12px; color: var(--ink-mid);
  margin-bottom: 6px;
  display: flex; align-items: baseline; gap: 6px;
}
.popup-text { font-size: 13px; color: var(--ink); line-height: 1.75; }

/* ============================================================
   图例
   ============================================================ */
.legend {
  position: absolute; right: 16px; bottom: 40px; z-index: 999;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 8px 28px rgba(0,0,0,0.1);
  font-size: 12px;
}
.legend-item {
  display: flex; align-items: center;
  gap: 9px; margin: 7px 0; color: var(--ink-mid);
}
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--rose); display: inline-block;
  box-shadow: 0 0 5px rgba(251,113,133,.6);
}
.legend-start {
  width: 10px; height: 10px; border-radius: 50%;
  background: #f97316; display: inline-block;
  border: 2px solid white;
  box-shadow: 0 0 5px rgba(249,115,22,.7);
}
.legend-line {
  width: 22px; height: 3px; display: inline-block;
  background: repeating-linear-gradient(
    90deg, var(--gold) 0, var(--gold) 10px,
    transparent 10px, transparent 15px
  );
  box-shadow: 0 0 6px rgba(251,191,36,.7);
}
.legend-scholar { font-size: 15px; display: inline-block; line-height: 1; }
.legend-hotspot {
  width: 13px; height: 13px; border-radius: 50%; display: inline-block;
  background: radial-gradient(circle, #fef08a 20%, var(--amber) 70%);
  box-shadow: 0 0 8px rgba(245,158,11,.8);
}

/* ============================================================
   路线动画（金色流动虚线）
   ============================================================ */
@keyframes routeFlow { to { stroke-dashoffset: -20; } }
.route-animated {
  stroke-dasharray: 12 8;
  stroke-dashoffset: 0;
  animation: routeFlow 0.8s linear infinite;
  filter: drop-shadow(0 0 4px rgba(251,191,36,.85));
}

/* ============================================================
   高频热点动画
   ============================================================ */
.hotspot-icon-wrapper { background: transparent; border: 0; }
.hotspot-icon {
  position: relative; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 30%, #fef3c7 0%, var(--amber) 55%, #d97706 100%);
  color: white; font-weight: 800;
  border: 2px solid rgba(255,255,255,.9);
  box-shadow: 0 0 0 3px rgba(245,158,11,.2), 0 6px 20px rgba(0,0,0,.16);
}
.hotspot-icon.flash { animation: hotspotPulse 1.6s ease-in-out infinite; }
.hotspot-rank {
  position: absolute; top: -7px; left: -5px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #7c2d12; color: white; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid white;
}
.hotspot-count { font-size: 14px; }
@keyframes hotspotPulse {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0   rgba(251,191,36,.7), 0 6px 20px rgba(0,0,0,.16); }
  65%  { transform: scale(1.07); box-shadow: 0 0 0 14px rgba(251,191,36,0), 0 6px 20px rgba(0,0,0,.16); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0   rgba(251,191,36,0), 0 6px 20px rgba(0,0,0,.16); }
}

/* ============================================================
   历史底图面板
   ============================================================ */
.panel-badge {
  padding: 1px 7px; border-radius: 6px;
  font-size: 10px; font-weight: 700;
  background: #fef3c7; color: #92400e;
  border: 1px solid #fde68a;
  text-transform: none; letter-spacing: 0;
}
.panel-desc {
  margin: 0 0 12px; font-size: 12px;
  color: var(--ink-mid); line-height: 1.7;
}
.opacity-row { margin-top: 4px; transition: opacity 0.2s; }
.opacity-row.disabled { opacity: 0.3; pointer-events: none; }
.panel-credit {
  margin: 12px 0 0; font-size: 11px;
  color: #b0a99e; line-height: 1.6;
}
.panel-credit a { color: #8b7f72; text-decoration: underline; }
.panel-credit a:hover { color: var(--ink-mid); }
.panel-historical { border-left: 3px solid var(--amber); }
.toggle-label {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px; font-size: 13px;
  color: var(--ink-mid); cursor: pointer;
}
.toggle-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--amber); }

/* ============================================================
   书生动画面板
   ============================================================ */
.panel-scholar { border-left: 3px solid var(--purple); }
.scholar-status {
  font-size: 12.5px; color: var(--ink-mid);
  line-height: 1.65; margin: 0 0 12px;
  min-height: 18px; font-weight: 500;
  padding: 8px 10px;
  background: #f7f4ff;
  border-radius: 8px;
  border: 1px solid #ede9fe;
}
.scholar-controls { display: flex; flex-direction: column; gap: 9px; }
.scholar-btn-main {
  width: 100%; padding: 10px;
  border-radius: 10px;
  background: var(--purple); color: white;
  font-size: 13px; font-weight: 600; border: 0;
  cursor: pointer; transition: background 0.15s;
}
.scholar-btn-main:hover { background: #6d28d9; }
.speed-row { display: flex; align-items: center; gap: 7px; }
.speed-label { font-size: 12px; color: var(--ink-light); flex-shrink: 0; }
.speed-btn {
  flex: 1; padding: 6px 0;
  border-radius: 8px;
  background: #f5f3ef; color: var(--ink-mid);
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.speed-btn.active { background: var(--purple); color: white; border-color: var(--purple); }
.speed-btn:hover:not(.active) { background: #ede9fe; border-color: #c4b5fd; }

/* 书生图标容器 */
.scholar-icon-wrap { background: transparent; border: 0; }

.scholar-fig {
  display: inline-block;
  position: relative; /* 供 .scholar-glow 定位 */
}

/* 整体身体重心摇摆：4帧模拟"抬腿-落脚"节律
   腿部由 SVG animateTransform 独立驱动，身体只做轻微重心转移 */
@keyframes scholarWalk {
  0%   { transform: translateY(0px)  rotate(-1.2deg) scaleY(1); }
  25%  { transform: translateY(-4px) rotate(0deg)    scaleY(1.01); }
  50%  { transform: translateY(0px)  rotate(1.2deg)  scaleY(1); }
  75%  { transform: translateY(-4px) rotate(0deg)    scaleY(1.01); }
  100% { transform: translateY(0px)  rotate(-1.2deg) scaleY(1); }
}
.scholar-walk {
  animation: scholarWalk 0.55s ease-in-out infinite;
  display: inline-block;
  transform-origin: bottom center;
}

/* 脚下金色光晕：随步频脉动，强化行走的真实感 */
@keyframes scholarGlow {
  0%, 100% { opacity: 0.55; transform: translateX(-50%) scaleX(1); }
  50%       { opacity: 0.18; transform: translateX(-50%) scaleX(0.45); }
}
.scholar-glow {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 7px;
  border-radius: 50%;
  background: rgba(251, 191, 36, 0.65);
  filter: blur(4px);
  animation: scholarGlow 0.55s ease-in-out infinite;
  pointer-events: none;
}

.scholar-year-tag {
  position: absolute; top: -4px; left: 50%;
  transform: translateX(-50%);
  background: rgba(109,40,217,0.92);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 8px;
  white-space: nowrap; pointer-events: none;
  box-shadow: 0 2px 8px rgba(109,40,217,0.35);
  letter-spacing: 0.02em;
}

/* ============================================================
   书生面板内嵌事迹列表
   ============================================================ */
.scholar-events {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #ede9fe;
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}
/* 单条事迹卡片 */
@keyframes scholarEventIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
.scholar-event-item {
  padding: 8px 10px;
  border-radius: 9px;
  background: #faf8ff;
  border: 1px solid #ede9fe;
  animation: scholarEventIn 0.28s ease both;
}
.scholar-event-meta {
  display: flex; align-items: baseline; gap: 7px;
  margin-bottom: 4px; flex-wrap: wrap;
}
.scholar-event-year {
  font-size: 11px; font-weight: 700;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.scholar-event-place {
  font-size: 12px; font-weight: 700;
  color: var(--ink);
}
.scholar-event-text {
  font-size: 12px; color: var(--ink-mid);
  line-height: 1.65;
}
.scholar-event-empty {
  font-size: 12px; color: var(--ink-light);
  text-align: center; padding: 6px 0;
}

/* ============================================================
   折叠式事件列表面板
   ============================================================ */
.panel-collapsible { padding: 12px 16px; }
.panel-collapsible details summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center;
}
.panel-collapsible details summary::-webkit-details-marker { display: none; }
/* 折叠箭头 */
.panel-collapsible details summary::after {
  content: "›";
  margin-left: auto;
  font-size: 18px; color: var(--ink-light);
  transition: transform 0.2s;
  line-height: 1;
}
.panel-collapsible details[open] summary::after {
  transform: rotate(90deg);
}
/* summary 内的 h2 去掉默认 margin/border */
.panel-h2-inline {
  margin: 0 !important;
  border-bottom: 0 !important;
  padding-bottom: 0 !important;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-light);
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 60vh; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  #map { height: 60vh; }
}
