/* 中国朝代跨度图 —— 古卷纸质感 */

:root {
  --paper: #f4ecd6;
  --paper-deep: #ece1c3;
  --ink: #453723;
  --ink-2: #6f5f43;
  --ink-3: #9d8d6d;
  --line: rgba(84, 66, 37, 0.10);
  --line-strong: rgba(84, 66, 37, 0.22);
  --era: rgba(150, 60, 30, 0.38);
  --accent: #a4501f;
  --card: #fbf6e8;
  --shadow: rgba(60, 40, 10, 0.18);
  --sep: rgba(84, 66, 37, 0.16);
  --nofill: rgba(84, 66, 37, 0.05);
}
:root[data-theme="dark"] {
  --paper: #262019;
  --paper-deep: #2e2820;
  --ink: #e2d5b5;
  --ink-2: #b3a483;
  --ink-3: #83755a;
  --line: rgba(226, 213, 181, 0.08);
  --line-strong: rgba(226, 213, 181, 0.18);
  --era: rgba(235, 140, 90, 0.42);
  --accent: #e08b4e;
  --card: #322b21;
  --shadow: rgba(0, 0, 0, 0.5);
  --sep: rgba(226, 213, 181, 0.14);
  --nofill: rgba(226, 213, 181, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #262019; --paper-deep: #2e2820;
    --ink: #e2d5b5; --ink-2: #b3a483; --ink-3: #83755a;
    --line: rgba(226, 213, 181, 0.08); --line-strong: rgba(226, 213, 181, 0.18);
    --era: rgba(235, 140, 90, 0.42); --accent: #e08b4e;
    --card: #322b21; --shadow: rgba(0, 0, 0, 0.5);
    --sep: rgba(226, 213, 181, 0.14); --nofill: rgba(226, 213, 181, 0.06);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

/* ------- 工具栏 ------- */
#toolbar {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 14px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line-strong);
}
#title {
  font-size: 19px; font-weight: 700; letter-spacing: 2px; white-space: nowrap;
}
#searchbox input {
  width: 150px; padding: 5px 10px;
  font: 13px/1.4 inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 15px;
  outline: none;
}
#searchbox input:focus { border-color: var(--accent); }
#eranav {
  flex: 1; display: flex; gap: 1px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#eranav::-webkit-scrollbar { display: none; }
#eranav button {
  flex-shrink: 0; padding: 4px 8px;
  font: 13px/1 inherit; color: var(--ink-2);
  background: none; border: none; border-radius: 12px; cursor: pointer;
  white-space: nowrap;
}
#eranav button:hover { color: var(--accent); background: var(--paper-deep); }
#eranav button.active { color: var(--accent); font-weight: 700; background: var(--paper-deep); }
#controls { display: flex; gap: 5px; }
#controls button {
  width: 30px; height: 30px;
  font-size: 15px; color: var(--ink-2);
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 8px;
  cursor: pointer;
}
#controls button:hover { color: var(--accent); border-color: var(--accent); }

/* ------- 滚动画布 ------- */
#scroller {
  position: fixed; inset: 52px 0 0 0;
  overflow: auto;
}
#canvas { display: grid; position: relative; width: max-content; }
#corner-l, #corner-r, #colhead { position: sticky; top: 0; z-index: 20; background: var(--paper); }
#corner-l { left: 0; z-index: 21; grid-area: 1 / 1; }
#corner-r { right: 0; z-index: 21; grid-area: 1 / 3; }
#colhead {
  grid-area: 1 / 2; position: sticky; position: -webkit-sticky;
  border-bottom: 1px solid var(--line-strong);
}
#colhead .region {
  position: absolute; top: 0; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; letter-spacing: 4px; color: var(--ink-2);
  border-left: 1px solid var(--sep);
  overflow: hidden; white-space: nowrap;
}
#colhead .region:first-child { border-left: none; }
#colhead .region.alt { background: var(--nofill); }

.axis { position: relative; z-index: 15; background: var(--paper); font-size: 10px; }
#axis-l { grid-area: 2 / 1; position: sticky; left: 0; border-right: 1px solid var(--line-strong); }
#axis-r { grid-area: 2 / 3; position: sticky; right: 0; border-left: 1px solid var(--line-strong); }
.axis .tick {
  position: absolute; right: 4px; left: 4px;
  transform: translateY(-50%);
  color: var(--ink-3); text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
#axis-r .tick { text-align: left; }
.axis .tick.major { color: var(--ink-2); font-weight: 700; }
.axis .tick.now { color: var(--accent); font-size: 12px; }
.axis .era-tick {
  position: absolute; right: 4px; left: 4px;
  transform: translateY(2px);
  color: var(--era); text-align: right; font-size: 9px; letter-spacing: 1px;
}
#axis-r .era-tick { text-align: left; }

#chart-wrap { grid-area: 2 / 2; position: relative; }
#chart-wrap svg { display: block; }

/* ------- SVG 图层 ------- */
.region-shade { fill: var(--nofill); }
.region-sep { stroke: var(--sep); stroke-width: 1; stroke-dasharray: 1 3; }
.gridline { stroke: var(--line); stroke-width: 1; }
.gridline.major { stroke: var(--line-strong); }
.era-line { stroke: var(--era); stroke-width: 1; stroke-dasharray: 5 4; }
.era-line.now { stroke: var(--accent); stroke-dasharray: none; stroke-width: 1.5; opacity: 0.7; }

g.polity { cursor: pointer; transition: opacity 0.18s ease; }
g.polity path {
  stroke-width: 1;
  fill-opacity: 0.88;
  transition: fill-opacity 0.18s ease, filter 0.18s ease;
}
g.polity.nofill path {
  fill: var(--nofill);
  stroke: var(--ink-3);
  stroke-dasharray: 3 3;
}
svg.hovering g.polity:not(.hot):not(.selected) { opacity: 0.55; }
g.polity.hot path, g.polity.selected path {
  fill-opacity: 1;
  stroke-width: 1.6;
  filter: drop-shadow(0 1px 4px var(--shadow));
}
g.polity.flash path { animation: flash 0.7s ease 3; }
@keyframes flash {
  50% { fill-opacity: 0.35; }
}

text.lbl {
  fill: #3a2f1c;
  paint-order: stroke;
  stroke: rgba(255, 252, 240, 0.72);
  stroke-width: 2.6px;
  stroke-linejoin: round;
  text-anchor: middle;
  font-family: inherit;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
}
:root[data-theme="dark"] text.lbl { fill: #2b2213; }

/* ------- 悬浮提示 ------- */
#tooltip {
  position: fixed; z-index: 40; max-width: 260px;
  padding: 8px 12px;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  font-size: 12px; line-height: 1.6;
  pointer-events: none;
}
#tooltip b { display: block; font-size: 15px; letter-spacing: 1px; }
#tooltip span { display: block; color: var(--ink-2); }

/* ------- 年代指示器 ------- */
#year-pill {
  position: fixed; z-index: 25; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  padding: 5px 16px;
  background: color-mix(in srgb, var(--ink) 82%, transparent);
  color: var(--paper);
  border-radius: 16px;
  font-size: 13px; letter-spacing: 2px;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ------- 页脚 ------- */
#site-footer {
  position: fixed; z-index: 22; left: 10px; bottom: 8px;
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-3);
  pointer-events: none;
}
#site-footer a { color: inherit; text-decoration: none; pointer-events: auto; }
#site-footer a:hover { color: var(--accent); text-decoration: underline; }

/* ------- 详情面板 ------- */
#panel {
  position: fixed; z-index: 35; top: 62px; right: 12px; bottom: 12px;
  width: 300px;
  background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  overflow-y: auto;
}
@media (min-width: 701px) {
  /* 点击右侧色块时浮层改开在左边，避免盖住刚点的地方 */
  #panel.panel-left { right: auto; left: 12px; }
}
#panel-close {
  position: absolute; top: 8px; right: 10px;
  width: 26px; height: 26px;
  font-size: 16px; color: var(--ink-2);
  background: none; border: none; border-radius: 50%; cursor: pointer;
}
#panel-close:hover { background: var(--paper-deep); }
#panel-body { padding: 18px; font-size: 13px; line-height: 1.75; }
#panel-body h2 {
  font-size: 21px; letter-spacing: 2px; margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
#panel-body .swatch {
  width: 15px; height: 15px; flex-shrink: 0;
  border-radius: 4px; border: 1px solid var(--line-strong);
}
#panel-body .raw { color: var(--ink-3); font-size: 12px; }
#panel-body .years { color: var(--ink-2); margin: 6px 0; }
#panel-body .years em { font-style: normal; color: var(--ink-3); margin-left: 8px; font-size: 12px; }
#panel-body .chips span {
  display: inline-block; margin: 0 4px 4px 0; padding: 1px 8px;
  font-size: 11px; color: var(--ink-2);
  background: var(--paper-deep); border-radius: 9px;
}
#panel-body .intro { margin: 10px 0; }
#panel-body .note {
  margin: 10px 0; padding: 8px 10px;
  font-size: 12px; color: var(--ink-2);
  background: var(--paper-deep); border-radius: 8px;
}
#panel-body h3 {
  margin: 14px 0 6px; font-size: 13px; color: var(--ink-2);
  border-top: 1px solid var(--line); padding-top: 10px;
}
.concurrent { list-style: none; }
.concurrent li {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 6px; border-radius: 6px; cursor: pointer;
}
.concurrent li:hover { background: var(--paper-deep); }
.concurrent li i {
  width: 10px; height: 10px; flex-shrink: 0;
  border-radius: 3px; border: 1px solid var(--line-strong);
}
.concurrent li small { margin-left: auto; color: var(--ink-3); font-size: 11px; }
.search-results { margin-top: 10px; }

/* ------- 移动端 ------- */
@media (max-width: 700px) {
  #toolbar { flex-wrap: wrap; height: 84px; padding: 6px 10px; row-gap: 2px; }
  #title { font-size: 15px; letter-spacing: 1px; }
  #searchbox input { width: 110px; }
  #eranav { order: 3; flex-basis: 100%; }
  #scroller { inset: 84px 0 0 0; }
  #panel {
    top: auto; right: 0; left: 0; bottom: 0;
    width: auto; max-height: 52vh;
    border-radius: 14px 14px 0 0;
  }
  #year-pill { bottom: 10px; }
  #colhead .region { font-size: 11px; letter-spacing: 1px; }
}
