:root {
  --bg: #12141a;
  --panel: #1b1e27;
  --line: #383d4a;
  --text: #e8e9ee;
  --muted: #9096a6;
  --rich: #4fd68c;
  --anchor: #5b9dee;
  --vague: #a3a8b5;
  --accent: #f2b544;
  --favorite: #ffd54a;
  --ancestor: #c77dff;
  --village: #f2b544;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
.tagline { color: var(--text); font-size: 14px; margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 13px; }
.controls {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--line);
}
input#search {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 7px 10px; border-radius: 6px; font-size: 13px; width: 220px;
}
input#search:focus { outline: 1px solid var(--accent); }
.mode-toggle { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.mode-toggle button {
  background: none; border: none; color: var(--muted); font-size: 12px;
  padding: 6px 10px; border-radius: 4px; cursor: pointer; font-family: inherit;
}
.mode-toggle button.active { background: var(--line); color: var(--text); }
.mode-toggle button:hover:not(.active) { color: var(--text); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.legend-ancestor { display: none; }
.legend-village { display: none; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.legend .star { margin-right: 4px; vertical-align: middle; font-size: 13px; }
.legend .bar-swatch {
  display: inline-block; width: 16px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle;
  background: var(--village); opacity: 0.4;
}
.scale-note { font-size: 12px; color: var(--muted); margin-left: auto; }
#timeline-wrap {
  overflow-x: auto; overflow-y: hidden;
  padding: 10px 0 0;
}
svg { display: block; }
.axis-line { stroke: var(--line); stroke-width: 1.5; }
.gridline { stroke: var(--line); stroke-width: 1; opacity: 0.4; }
.tick-label { fill: var(--muted); font-size: 12px; }
.era-label { fill: var(--muted); font-size: 11px; font-style: italic; }
.stem { stroke: var(--line); stroke-width: 1.5; }
.marker { cursor: pointer; stroke-width: 1.5; }
.marker.rich { fill: var(--rich); stroke: #2c9a63; }
.marker.anchor { fill: var(--anchor); stroke: #3672b8; }
.marker.vague { fill: var(--vague); stroke: #767c8a; stroke-dasharray: 2 1.5; }
.marker.ancestor-mode { fill: var(--ancestor); stroke: #9151c4; }
.marker.ancestor-node { fill: var(--ancestor); stroke: var(--text); stroke-width: 2; }
.marker.dim { opacity: 0.12; }
.marker.hot { stroke: var(--accent); stroke-width: 3; }
.marker.favorite { stroke: var(--favorite); stroke-width: 2; }
.marker.favorite.hot { stroke: var(--accent); stroke-width: 3; }
.fallback-ring { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 2.5 2; opacity: 0.6; pointer-events: none; }
.marker.dim + .fallback-ring { opacity: 0.05; }
.trunk { stroke-width: 2; }
.branch { stroke: var(--ancestor); stroke-width: 1.2; opacity: 0.55; }
.branch.unplotted { stroke-dasharray: 2.5 2; opacity: 0.35; }
.ancestor-label { fill: var(--ancestor); font-weight: 600; }
.marker.ancestor-unplotted { fill: none; stroke: var(--ancestor); stroke-width: 1.5; stroke-dasharray: 2.5 2; opacity: 0.6; cursor: default; }
.marker-label.unplotted-label { fill: var(--muted); font-style: italic; }
.village-bar { stroke: var(--village); stroke-width: 6; stroke-linecap: round; cursor: pointer; }
.village-bar-end { fill: var(--village); opacity: 0.35; stroke: var(--village); stroke-width: 1.5; }
.marker.village-node { fill: var(--village); stroke: #b5810e; }
.village-branch { stroke: var(--village); stroke-width: 1.2; opacity: 0.55; }
.village-label { fill: var(--village); font-weight: 600; }
.marker-label {
  fill: var(--text); font-size: 10.5px; pointer-events: none;
}
.marker-label.dim { opacity: 0.12; }
#tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; max-width: 300px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: none;
}
#tooltip .name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
#tooltip .date { color: var(--accent); margin-bottom: 6px; }
#tooltip .note { color: var(--muted); line-height: 1.4; }
#detail {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 20px; overflow-y: auto; font-size: 13px; line-height: 1.5;
  transform: translateX(100%); transition: transform 0.18s ease;
  z-index: 30;
}
#detail.open { transform: translateX(0); }
#detail .close { position: absolute; top: 14px; right: 16px; cursor: pointer; color: var(--muted); font-size: 18px; background: none; border: none; }
#detail h2 { margin: 0 0 4px; font-size: 18px; }
#detail .field { margin-top: 12px; }
#detail .field-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
#detail a { color: var(--anchor); }
#undated {
  padding: 20px 24px 40px; border-top: 1px solid var(--line); margin-top: 8px;
}
#undated h3 { font-size: 14px; margin: 0 0 4px; }
#undated .sub { margin-bottom: 12px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--muted);
}
