:root {
  --ink: #2b2620; --muted: #7d7466; --line: #e4dccb; --card: rgba(255, 253, 248, .94);
  --accent: #b23a2e; --sea: #dbe6e8; --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
#map { position: absolute; inset: 0; background: var(--sea); }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; }
button:hover { border-color: var(--muted); }
h3 { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .1em; }
h3 small { font-weight: 400; letter-spacing: 0; }

#panel, #bar, #layers > * { background: var(--card); backdrop-filter: blur(6px); box-shadow: 0 1px 8px rgba(60, 50, 30, .18); }
#panel { position: absolute; z-index: 1000; top: 12px; left: 12px; width: 300px; max-height: calc(100% - 150px); display: flex; flex-direction: column; border-radius: 10px; }
#panel header { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px 8px; }
#year { font: 700 26px/1.1 var(--serif); }
#dynasty { flex: 1; font: 600 16px var(--serif); color: var(--accent); }
#fold { width: 28px; height: 28px; align-self: center; line-height: 1; }
#body { padding: 0 14px 12px; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
#panel.folded #body { display: none; }
#caption { margin: 0 0 10px; color: #4d463b; font-size: 13px; }

#searchbox { position: relative; }
#search { width: 100%; padding: 6px 10px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: #fff; outline: none; }
#search:focus { border-color: var(--accent); }
#results { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none; max-height: 260px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px rgba(60, 50, 30, .2); }
#results li { padding: 5px 8px; border-radius: 4px; cursor: pointer; font-size: 13px; }
#results li:hover { background: #f4eee0; }
#results small { color: var(--muted); }

#legend { display: flex; flex-wrap: wrap; gap: 5px; }
#legend button { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px; font-size: 13px; border-radius: 12px; }
#legend i { width: 10px; height: 10px; border-radius: 50%; }

#events { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 90px; flex: 1; }
#events li { display: flex; gap: 8px; padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--muted); border-left: 2px solid transparent; }
#events li:hover { background: #f4eee0; }
#events li b { flex: none; width: 46px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
#events li.on { color: var(--ink); }
#events li.now { color: var(--accent); border-left-color: var(--accent); background: #faf0e6; }

#layers { position: absolute; z-index: 1000; top: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#layersbtn { padding: 5px 12px; }
#layerlist { padding: 8px 12px; border-radius: 8px; }
#layerlist:not([hidden]) { display: grid; gap: 4px; }
#layerlist label { cursor: pointer; white-space: nowrap; }

#bar { position: absolute; z-index: 1000; left: 12px; right: 12px; bottom: 12px; padding: 8px 12px 6px; border-radius: 10px; }
#chips { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
#chips button { flex: 1 0 auto; padding: 3px 6px; font: 600 13px var(--serif); color: #fff; border: 0; opacity: .55; white-space: nowrap; }
#chips button:hover { opacity: .85; }
#chips button.on { opacity: 1; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .35); }
#controls { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#controls button { width: 30px; height: 28px; font-size: 16px; line-height: 1; flex: none; }
#from, #to { flex: none; min-width: 52px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#to { text-align: right; }
#track { position: relative; flex: 1; height: 28px; }
#slider { position: absolute; inset: 0; width: 100%; margin: 0; accent-color: var(--accent); background: transparent; }
#ticks { position: absolute; left: 8px; right: 8px; top: 0; bottom: 0; pointer-events: none; }
#ticks i { position: absolute; top: 3px; width: 2px; height: 6px; margin-left: -1px; background: var(--muted); border-radius: 1px; }
#credit { margin-top: 2px; font-size: 11px; color: var(--muted); text-align: center; }
#credit a { color: inherit; }

.lb { width: 0 !important; height: 0 !important; overflow: visible; pointer-events: none; }
.lb > span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-family: var(--serif); text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff; }
.lb-main > span { font-size: 22px; font-weight: 700; letter-spacing: .25em; }
.lb-rival > span { font-size: 15px; font-weight: 700; letter-spacing: .1em; }
.lb-protectorate > span { font-size: 12px; font-weight: 600; }
.lb-neighbor > span { font-size: 11px; color: #8d8474; }
.lb-region > span { font-size: 12px; color: #5d5547; letter-spacing: .15em; }
.lb-water > span, .lb-land > span { font-size: 11px; font-style: italic; color: #4f86a3; text-shadow: none; }
.lb-land > span { color: #9a8767; letter-spacing: .3em; }
.lb-corridor > span { font-size: 11px; color: #7a5b3a; }
.z-lt4 .lb-neighbor, .z-lt5 .lb-region, .z-lt5 .lb-water, .z-lt5 .lb-land, .z-lt5 .lb-corridor, .z-lt5 .lb-protectorate { display: none; }

.city { width: 0 !important; height: 0 !important; overflow: visible; cursor: pointer; }
.city i { position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%; background: #fff; border: 1.5px solid var(--ink); }
.city span { position: absolute; left: 6px; top: -9px; white-space: nowrap; font-size: 12px; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff; }
.city.capital i { left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 2px; background: var(--accent); border-color: #fff; box-shadow: 0 0 0 1px var(--accent); transform: rotate(45deg); }
.city.capital span { left: 9px; font-weight: 700; font-size: 13px; }
.z-lt5 .city.t0 span, .z-lt6 .city.t1, .z-lt7 .city.t2 { display: none; }

.event { width: 0 !important; height: 0 !important; overflow: visible; cursor: pointer; }
.event i { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: .8; border: 1.5px solid #fff; }
.event.now i { left: -7px; top: -7px; width: 14px; height: 14px; opacity: 1; box-shadow: 0 0 0 4px rgba(178, 58, 46, .25); }

.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 14px; line-height: 1.55; }
.leaflet-popup-content b { font-family: var(--serif); font-size: 15px; }
.leaflet-popup-content small { color: var(--muted); }
.leaflet-control-zoom { margin: 0 12px 150px 0 !important; border: 0 !important; box-shadow: 0 1px 8px rgba(60, 50, 30, .18) !important; }

@media (max-width: 700px) {
  #panel { width: auto; right: 80px; max-height: 55%; }
  #credit { display: none; }
  .leaflet-control-zoom { display: none; }
}
