:root {
  color-scheme: dark;
  --ink: #08080a;
  --ink-2: #111114;
  --panel: rgba(18, 18, 22, 0.86);
  --panel-solid: #141417;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #fafafa;
  --muted: #a1a1aa;
  --dim: #71717a;
  --gold: #10a37f;
  --gold-soft: rgba(16, 163, 127, 0.16);
  --crimson: #10a37f;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.16);
  --rail-w: 184px;
  --ruler-h: 92px;
  --sans: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'IBM Plex Mono', 'Noto Sans SC', ui-monospace, monospace;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #f4f4f6;
  --ink-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.90);
  --panel-solid: #ffffff;
  --line: rgba(24, 24, 27, 0.09);
  --line-strong: rgba(24, 24, 27, 0.20);
  --text: #09090b;
  --muted: #52525b;
  --dim: #71717a;
  --gold: #0d9488;
  --gold-soft: rgba(16, 163, 127, 0.12);
  --crimson: #10a37f;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}
button { font: inherit; color: inherit; }

/* ---------- Background ---------- */
#dust { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

/* ---------- Stage ---------- */
#stage {
  position: fixed; inset: 0; z-index: 1; overflow: hidden;
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }
#world {
  position: absolute; left: 0; top: 0;
  width: 1500px; height: 1500px;
  transform-origin: 0 0;
  will-change: transform;
  pointer-events: none;
}
#tiles { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#chart {
  display: block; width: 1500px; height: 1500px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--line), 0 36px 100px -20px rgba(0,0,0,.72);
  clip-path: inset(0 100% 0 0);
}
#sweep {
  position: absolute; top: -20px; bottom: -20px; left: 0; width: 2px;
  background: linear-gradient(180deg, transparent, var(--accent) 15%, #fff 50%, var(--accent) 85%, transparent);
  box-shadow: 0 0 20px 4px rgba(16, 163, 127, .45);
  opacity: 0; pointer-events: none;
}

/* ---------- Screen-space Overlays ---------- */
#overlay { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#bandGlow {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 1px solid rgba(16, 163, 127, 0);
  border-bottom: 1px solid rgba(16, 163, 127, 0);
  background: linear-gradient(90deg, rgba(16, 163, 127, .10), rgba(16, 163, 127, .02) 40%, transparent);
  opacity: 0; transition: opacity .3s var(--ease-out);
}
#bandGlow.on { opacity: 1; border-color: rgba(16, 163, 127, .42); }
#decade {
  position: absolute; top: 0; bottom: 0; width: 0;
  background: linear-gradient(180deg, rgba(16, 163, 127, 0), rgba(16, 163, 127, .09) 20%, rgba(16, 163, 127, .09) 80%, rgba(16, 163, 127, 0));
  opacity: 0; transition: opacity .2s;
}
#decade.on { opacity: 1; }
#needle {
  position: absolute; top: var(--ruler-h); bottom: 0; left: 0; width: 1px;
  background: linear-gradient(180deg, var(--accent), rgba(16, 163, 127, .35) 35%, rgba(16, 163, 127, .12));
  opacity: 0; transition: opacity .15s;
}
#needle.on { opacity: 1; }
#needleBadge {
  position: absolute; top: 8px; left: 10px; white-space: nowrap;
  padding: 6px 10px; border-radius: 7px;
  background: var(--panel-solid); border: 1px solid var(--line-strong);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.55);
}
#needleBadge.flip { left: auto; right: 10px; }
#needleYear { font-family: var(--mono); font-weight: 600; font-size: 12.5px; color: var(--accent); letter-spacing: .01em; }
#needleRegion { font-style: normal; font-size: 11px; color: var(--muted); }
#spot { position: absolute; inset: 0; opacity: 0; transition: opacity .5s var(--ease-out); }
#spot.on { opacity: 1; }
#spotRing { stroke: var(--accent); stroke-width: 1.5; filter: drop-shadow(0 0 8px rgba(16, 163, 127, .65)); }
#pulse {
  position: absolute; top: var(--ruler-h); bottom: 0; width: 2px; left: -10px;
  background: var(--accent); box-shadow: 0 0 28px 6px rgba(16, 163, 127, .45);
  opacity: 0;
}

/* ---------- Hotspots ---------- */
#hotspots { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#hotspots.off .hs { opacity: 0 !important; pointer-events: none; transform: translate(-50%, -50%) scale(.3); }
.hs {
  position: absolute; left: 0; top: 0; width: 24px; height: 24px; margin: 0; padding: 0;
  border: 0; background: none; cursor: pointer; pointer-events: auto;
  transform: translate(-50%, -50%);
  transition: opacity .35s, transform .35s var(--ease-out);
}
.hs .core {
  position: absolute; inset: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--ink), 0 0 12px rgba(16, 163, 127, .85);
  display: grid; place-items: center;
}
.hs .ring {
  position: absolute; inset: 1px; border-radius: 50%;
  border: 1.25px solid rgba(16, 163, 127, .75);
  animation: ping 2.6s var(--ease-out) infinite;
}
.hs:nth-child(3n) .ring { animation-delay: .8s; }
.hs:nth-child(3n+1) .ring { animation-delay: 1.6s; }
@keyframes ping { 0% { transform: scale(.45); opacity: .95; } 80%, 100% { transform: scale(1.85); opacity: 0; } }
.hs .tip {
  position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translate(-50%, 6px);
  white-space: nowrap; padding: 6px 10px; border-radius: 7px;
  background: var(--panel-solid); border: 1px solid var(--line-strong);
  font: 600 12px/1.25 var(--sans); color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  opacity: 0; transition: opacity .22s, transform .3s var(--ease-out);
  pointer-events: none;
}
.hs .tip small { display: block; font: 400 10.5px var(--mono); color: var(--accent); margin-top: 2px; }
.hs:hover .tip, .hs:focus-visible .tip { opacity: 1; transform: translate(-50%, 0); }
.hs:hover .core { background: var(--text); }
.hs.active .core { background: var(--text); box-shadow: 0 0 0 2px var(--ink), 0 0 18px 3px rgba(16, 163, 127, .85); }

/* ---------- Top Ruler (Dual-Track: Chinese Dynastic Axis + Gregorian + Global Eras) ---------- */
#ruler {
  position: fixed; left: 0; right: 0; top: 0; height: var(--ruler-h); z-index: 5;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.brand {
  position: absolute; left: 0; top: 0; bottom: 0; width: var(--rail-w);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  border-right: 1px solid var(--line); z-index: 2; background: var(--panel-solid);
  cursor: pointer;
}
.brand strong { display: block; font: 600 16px/1.1 var(--sans); letter-spacing: -.02em; color: var(--text); }
.brand span { display: block; font-size: 10.5px; color: var(--muted); margin-top: 3px; line-height: 1.2; }
.compass { width: 26px; height: 26px; flex: none; color: var(--text); }
#rulerCanvas {
  position: absolute; left: var(--rail-w); right: 0; top: 0;
  height: 64px; width: calc(100% - var(--rail-w));
  cursor: ew-resize; display: block;
}
#eras {
  position: absolute; left: var(--rail-w); right: 0; bottom: 0;
  height: 28px; overflow: hidden;
  border-top: 1px solid var(--line);
}
.era {
  position: absolute; top: 2px; bottom: 2px; padding: 0 8px;
  display: flex; align-items: center; overflow: hidden;
  font: 500 10.5px/1 var(--sans); letter-spacing: .02em;
  color: var(--muted); white-space: nowrap; cursor: pointer;
  border-left: 1px solid var(--line-strong);
  background: linear-gradient(90deg, rgba(255,255,255,.025), transparent);
  transition: color .2s, background .25s;
}
.era:hover { color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), transparent); }
.era.cur { color: var(--text); font-weight: 600; }
.era span { display: inline-block; will-change: transform; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Left Region Rail ---------- */
#rail {
  position: fixed; left: 0; top: var(--ruler-h); bottom: 0; width: var(--rail-w); z-index: 4;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
}
.band {
  position: absolute; left: 0; right: 0; border-top: 1px solid var(--line);
  cursor: pointer; padding: 0; background: none; border-left: 0; border-right: 0; border-bottom: 0;
  text-align: left; transition: background .25s;
}
.band::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--muted); opacity: .35; transition: opacity .25s, width .25s var(--ease-out), background .25s;
}
.band:hover, .band.cur { background: linear-gradient(90deg, var(--accent-soft), transparent); }
.band.cur::before, .band:hover::before { opacity: 1; width: 3px; background: var(--accent); }
.band .lbl {
  position: absolute; left: 12px; right: 8px; top: 0;
  font: 600 13px/1.18 var(--sans); letter-spacing: -.01em; color: var(--text);
  transition: color .2s;
  pointer-events: none;
}
.band .lbl small {
  display: block; font: 400 10px/1.2 var(--mono); color: var(--dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.band.cur .lbl { color: var(--accent); }
.band .lbl .f, .band .lbl .s { display: inline-block; }
.band .lbl .s { display: none; }
.band.tiny .lbl small { display: none; }

/* ---------- Search ---------- */
#search {
  position: fixed; top: calc(var(--ruler-h) + 12px); right: 16px; z-index: 6;
  width: min(340px, calc(100vw - var(--rail-w) - 32px));
  display: flex; align-items: center; gap: 8px; padding: 0 10px 0 12px; height: 40px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 32px -12px rgba(0,0,0,.55);
  transition: border-color .2s, box-shadow .25s;
}
#search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), 0 12px 32px -12px rgba(0,0,0,.6); }
#search svg { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
#q { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: 400 13px var(--sans); user-select: text; -webkit-user-select: text; }
#q::placeholder { color: var(--dim); }
#search kbd { font: 500 10.5px var(--mono); color: var(--dim); border: 1px solid var(--line-strong); border-radius: 4px; padding: 2px 5px; }
#results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 5px; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 8px;
  box-shadow: 0 20px 50px -16px rgba(0,0,0,.75);
  max-height: 50vh; overflow: auto; display: none;
}
#results.open { display: block; animation: drop .22s var(--ease-out); }
@keyframes drop { from { opacity: 0; transform: translateY(-5px); } }
#results li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px;
}
#results li small { font: 400 10.5px var(--mono); color: var(--dim); white-space: nowrap; }
#results li.sel, #results li:hover { background: var(--accent-soft); }
#results li.sel small { color: var(--accent); }
#results li .k {
  font: 600 9.5px var(--sans); letter-spacing: .06em;
  color: var(--accent); background: var(--accent-soft);
  padding: 1px 5px; border-radius: 4px; margin-right: 7px;
}

/* ---------- Controls ---------- */
#controls {
  position: fixed; left: calc(var(--rail-w) + 14px); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 6;
  display: flex; align-items: center; gap: 2px; padding: 4px;
  max-width: calc(100vw - var(--rail-w) - 14px - 180px); flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 32px -12px rgba(0,0,0,.55);
}
#controls button {
  width: 34px; height: 34px; border-radius: 7px; border: 0; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: background .15s, color .15s, transform .15s var(--ease-out);
  color: var(--text);
}
#controls button.ctrl-btn {
  width: auto; padding: 0 6px;
  font: 500 11.5px/1 var(--sans);
  letter-spacing: .01em;
  white-space: nowrap;
}
#controls button.ctrl-btn svg {
  width: 15px; height: 15px; flex: none;
}
#controls button:hover { background: rgba(255,255,255,.08); color: var(--accent); }
:root[data-theme="light"] #controls button:hover { background: rgba(0,0,0,.06); }
#controls button:active { transform: scale(.96); }
#controls button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#controls button.accent { background: var(--accent); color: #fff; }
#controls button.accent svg { fill: #fff; stroke: #fff; }
#controls button.accent:hover { background: #0d9488; color: #fff; }
#controls button.on { background: var(--accent-soft); color: var(--accent); }
#controls button[data-act="pins"]:not(.on) svg,
#controls button[data-act="events"]:not(.on) svg,
#controls button[data-act="bilingual"]:not(.on) svg { stroke: var(--dim); }
#controls button.txt-btn {
  width: auto; padding: 0 9px;
  font: 500 11.5px/1 var(--sans);
}
#controls .sep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 3px; }
/* Ruler and language switchers (S5): native selects styled like the text buttons, without the native arrow
   (its ~20px kept the zh-CN toolbar from fitting one row at 1280px). With the language select (ENR: two released
   locales) the gap, the text-button padding (9 -> 6px, as on phones) and the select padding (6 -> 4px) are tighter,
   so / and /en/ each fit one row at 1280px (natural width about 858 / 877px of 902px). */
#controls select {
  height: 34px; padding: 0 4px; border: 0; border-radius: 7px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  font: 500 11.5px/1 var(--sans); color: var(--text); background: transparent;
  transition: background .15s, color .15s;
}
#controls select:hover { background: rgba(255,255,255,.08); color: var(--accent); }
:root[data-theme="light"] #controls select:hover { background: rgba(0,0,0,.06); }
#zoomLevel { font: 500 11px var(--mono); color: var(--muted); min-width: 44px; text-align: center; }

/* ---------- Minimap ---------- */
#minimap {
  position: fixed; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 6;
  width: 148px; height: 148px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 32px -12px rgba(0,0,0,.65);
  cursor: crosshair; background: var(--panel-solid);
}
#minimap img { width: 100%; height: 100%; display: block; opacity: .92; }
#mmView {
  position: absolute; border: 1.5px solid var(--accent); border-radius: 2px;
  background: rgba(16, 163, 127, .12); box-shadow: 0 0 0 9999px rgba(8, 8, 10, .42), 0 0 10px rgba(16, 163, 127, .45);
  pointer-events: none;
}

/* ---------- Tour Card ---------- */
#card {
  position: fixed; right: 16px; top: calc(var(--ruler-h) + 64px); z-index: 19;
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100vh - var(--ruler-h) - 235px);
  padding: 16px 18px 14px; border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  box-shadow: 0 24px 64px -20px rgba(0,0,0,.75);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  visibility: hidden; opacity: 0; transform: translateX(30px);
  overflow-y: auto;
}
#card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--accent);
}
.card-top { display: flex; justify-content: space-between; align-items: center; }
#cardIndex { font: 500 11px var(--mono); color: var(--dim); letter-spacing: .08em; }
#cardClose { width: 26px; height: 26px; border-radius: 6px; border: 0; background: rgba(255,255,255,.05); cursor: pointer; font-size: 17px; line-height: 1; color: var(--muted); }
#cardClose:hover { background: var(--line-strong); color: var(--text); }
#card .region { margin: 8px 0 2px; font: 600 11px var(--sans); letter-spacing: .06em; color: var(--accent); }
#card h2 { margin: 0; font: 600 22px/1.22 var(--sans); letter-spacing: -.015em; color: var(--text); }
#card .en-sub { margin: 2px 0 0; font: 400 11.5px var(--mono); color: var(--dim); }
#card .years { margin: 5px 0 0; font: 500 11.5px var(--mono); color: var(--muted); }
#card .text { margin: 10px 0 10px; font-size: 13px; line-height: 1.62; color: var(--text); opacity: .94; }
#cardBasis {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text);
}
#cardBasis strong { color: var(--accent); font-weight: 600; }
#card .split { display: inline-block; }
#card .word { white-space: nowrap; }
.card-nav { display: flex; align-items: center; gap: 6px; }
.card-nav button {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line-strong); background: rgba(255,255,255,.03);
  cursor: pointer; font-size: 13px; transition: background .15s, border-color .15s;
}
.card-nav button:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#play.on { background: var(--accent); color: #fff; border-color: var(--accent); }
#dots { flex: 1; display: flex; gap: 4px; align-items: center; justify-content: center; flex-wrap: wrap; }
#dots i { width: 5px; height: 5px; border-radius: 3px; background: var(--line-strong); cursor: pointer; transition: width .3s var(--ease-out), background .25s; }
#dots i.on { width: 14px; background: var(--accent); }
#cardProgress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; }
#cardProgress i { display: block; height: 100%; width: 0; background: var(--accent); opacity: .85; }

/* ---------- Help & Scholarly Lexicon Modals ---------- */
#help, #lexicon {
  position: fixed; inset: 0; z-index: 26; display: none; place-items: center;
  background: rgba(8, 8, 10, .72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#help.open, #lexicon.open { display: grid; animation: fade .22s; }
@keyframes fade { from { opacity: 0; } }
.help-box {
  width: min(480px, calc(100vw - 32px)); padding: 24px 26px; border-radius: 12px;
  max-height: calc(100% - 32px); overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain;
  background: var(--panel-solid); border: 1px solid var(--line-strong); animation: rise .35s var(--ease-out);
  box-shadow: 0 30px 80px rgba(0,0,0,.65);
}
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.help-box h3 { margin: 0 0 14px; font: 600 20px var(--sans); letter-spacing: -.02em; }
.help-box dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
.help-box dt { font: 500 11.5px var(--mono); color: var(--accent); }
.help-box dd { margin: 0; color: var(--muted); }
.help-box .credit { margin: 16px 0 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--dim); line-height: 1.55; }
#helpClose, .modal-btn {
  padding: 9px 18px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
#helpClose:hover, .modal-btn:hover { background: #0d9488; }

.lex-box {
  width: min(900px, 94vw);
  height: min(680px, 86vh);
  display: flex; flex-direction: column;
  padding: 20px 22px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: 0 32px 90px rgba(0,0,0,.75);
  animation: rise .3s var(--ease-out);
}
.lex-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.lex-head h3 { margin: 0; font: 600 18px var(--sans); letter-spacing: -.02em; color: var(--text); }
.lex-head span { display: block; margin-top: 3px; font: 400 11.5px var(--mono); color: var(--accent); }
.lex-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
#lexSearch {
  flex: 1; min-width: 220px; padding: 8px 12px;
  background: var(--ink); border: 1px solid var(--line-strong); border-radius: 7px;
  color: var(--text); font: 400 12.5px var(--sans); outline: none;
  user-select: text; -webkit-user-select: text;
}
#lexSearch:focus { border-color: var(--accent); }
.lex-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.lex-tab {
  padding: 6px 10px; border: 1px solid var(--line); background: transparent;
  border-radius: 6px; font: 500 11.5px var(--sans); color: var(--muted); cursor: pointer;
}
.lex-tab.on, .lex-tab:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
#lexBody {
  flex: 1; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px;
  background: var(--ink); padding: 6px;
}
.lex-item {
  padding: 10px 12px; border-bottom: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; transition: background .15s;
}
.lex-item:last-child { border-bottom: 0; }
.lex-item:hover { background: var(--accent-soft); }
.lex-item-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.lex-zh { font-size: 13.5px; font-weight: 600; color: var(--text); }
.lex-en { font: 400 11.5px var(--mono); color: var(--accent); }
.lex-cat { margin-left: auto; font: 400 10.5px var(--mono); color: var(--dim); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); }
.lex-basis { margin-top: 5px; font-size: 12px; line-height: 1.55; color: var(--muted); }
.lex-basis strong { color: var(--text); font-weight: 600; }

/* ---------- Intro ---------- */
#intro {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: radial-gradient(900px 600px at 50% 45%, #16161a, #08080a 70%);
}
.intro-inner { text-align: center; padding: 0 24px; }
.kicker { margin: 0 0 18px; font: 500 11.5px var(--mono); letter-spacing: .24em; text-transform: uppercase; color: var(--accent); }
#introTitle { margin: 0; font: 600 clamp(44px, 8vw, 96px)/1.05 var(--sans); letter-spacing: -.03em; }
#introTitle .ch { display: inline-block; will-change: transform, opacity, filter; }
.counter { margin-top: 20px; font: 500 clamp(17px, 2.2vw, 24px) var(--mono); color: var(--muted); height: 1.4em; }
.intro-line { margin: 24px auto 0; width: min(460px, 75vw); height: 1px; background: var(--line); position: relative; overflow: hidden; }
.intro-line i { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: var(--accent); }
#skip { margin-top: 34px; padding: 8px 18px; border-radius: 999px; border: 1px solid var(--line-strong); background: none; color: var(--muted); font: 500 12px var(--mono); letter-spacing: .06em; cursor: pointer; }
#skip:hover { color: var(--text); border-color: var(--accent); }

/* initial hidden UI (animated in) */
.pre #ruler { transform: translateY(-100%); }
.pre #rail { transform: translateX(-100%); }
.pre #controls, .pre #minimap, .pre #search { opacity: 0; transform: translateY(16px); }

/* ---------- Touch & drag behavior ---------- */
body { -webkit-touch-callout: none; }
img, canvas { -webkit-user-drag: none; user-select: none; -webkit-user-select: none; }
#minimap img { pointer-events: none; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --rail-w: 68px; }
  .brand { padding: 0 8px; justify-content: center; }
  .brand > div { display: none; }
  .band .lbl { left: 6px; right: 4px; font-size: 11.5px; line-height: 1.15; overflow: hidden; }
  .band .lbl .f, .band .lbl small { display: none; }
  .band .lbl .s { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #search { top: calc(var(--ruler-h) + 8px); bottom: auto; right: 8px; left: calc(var(--rail-w) + 8px); width: auto; }
  #results { top: calc(100% + 6px); bottom: auto; }
  #search kbd { display: none; }
  #controls {
    left: 8px; right: 8px; bottom: 8px; max-width: none;
    flex-wrap: wrap; justify-content: center; gap: 3px; padding: 5px 6px;
  }
  #controls button { width: 28px; height: 28px; }
  #controls button.ctrl-btn { width: auto; height: 28px; padding: 0 6px; font-size: 11px; }
  #controls .sep { display: none; }
  #controls select { height: 28px; font-size: 11px; }
  #zoomLevel { min-width: 38px; font-size: 10.5px; }
  #minimap { display: none; }
  #card { top: auto; bottom: 118px; right: 8px; left: calc(var(--rail-w) + 8px); width: auto; padding: 12px 14px; }
  #card h2 { font-size: 18px; }
  #card .text { font-size: 12px; margin: 6px 0 8px; }
  .era { font-size: 9px; padding: 0 3px; }
}

@media (prefers-reduced-motion: reduce) {
  .hs .ring, .compass { animation: none; }
}

/* ---------- 3D Historical Globe Panel (Dock / Split / Full Atlas Modal) ---------- */
#controls button.accent-globe {
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #38bdf8;
}
:root[data-theme="light"] #controls button.accent-globe,
body.light-theme #controls button.accent-globe {
  border-color: rgba(2, 132, 199, 0.35);
  color: #0284c7;
}
#controls button.accent-globe.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
:root[data-theme="light"] #controls button.accent-globe.on,
body.light-theme #controls button.accent-globe.on {
  border-color: var(--accent);
  color: #ffffff;
}

#globePanel {
  position: fixed;
  z-index: 18;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
  transition: width 0.25s ease, height 0.25s ease, right 0.25s ease, bottom 0.25s ease;
}
#globePanel[hidden] {
  display: none !important;
}

/* Mode 1: Floating Dock (Bottom-right) */
#globePanel.mode-dock {
  right: 14px;
  bottom: 178px;
  width: min(500px, calc(100vw - var(--rail-w) - 24px));
  height: min(640px, calc(100vh - var(--ruler-h) - 242px));
}
#globePanel.mode-dock .globe-side-col {
  display: none;
}
#globePanel.mode-dock .globe-summary {
  max-height: 34px;
  padding: 4px 10px;
  font-size: 10.5px;
  line-height: 1.38;
}
#globePanel.mode-dock .globe-controls-strip {
  padding: 5px 10px;
  gap: 5px;
}
#globePanel.mode-dock .globe-epoch-bar {
  padding: 5px 8px;
}

/* Mode 2: Split-Screen Dual View (Left 2D Timeline | Right 3D Globe) */
body.globe-split-active #stage {
  right: 44vw;
}
body.globe-split-active #search,
body.globe-split-active #card {
  right: calc(44vw + 16px);
}
body.globe-split-active #minimap {
  right: calc(44vw + 14px);
  bottom: 98px;
  width: 96px;
  height: 96px;
}
body.globe-split-active .chrono-toast {
  left: calc(var(--rail-w) + 14px) !important;
  bottom: 100px !important;
  transform: none !important;
  max-width: calc(56vw - var(--rail-w) - 130px) !important;
}
body.globe-split-active #controls {
  left: calc(var(--rail-w) + 12px);
  right: calc(44vw + 12px);
  bottom: 12px;
  transform: none;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 4px;
  column-gap: 4px;
  padding: 6px 10px;
  border-radius: 14px;
  max-width: calc(56vw - var(--rail-w) - 24px);
  overflow: visible;
}
body.globe-split-active #controls button.ctrl-btn {
  height: 28px;
  padding: 0 7px;
  font-size: 11px;
}
#globePanel.mode-split {
  top: var(--ruler-h);
  right: 0;
  bottom: 0;
  width: 44vw;
  height: calc(100vh - var(--ruler-h));
  border-radius: 0;
  border-right: none;
  border-bottom: none;
}
#globePanel.mode-split .globe-side-col {
  display: none;
}

/* Mode 3: Full-Modal 3D Historical Atlas Theater */
#globePanel.mode-modal {
  top: calc(var(--ruler-h) + 12px);
  left: calc(var(--rail-w) + 14px);
  right: 14px;
  bottom: 64px;
  width: auto;
  height: auto;
  z-index: 24;
}

.globe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 163, 127, 0.06);
}
.globe-title-wrap {
  min-width: 0;
  flex: 1;
}
.globe-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
}
.globe-kicker {
  font: 600 10px var(--mono);
  letter-spacing: 0.06em;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.globe-year-pill {
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(16, 163, 127, 0.16);
  border: 1px solid rgba(16, 163, 127, 0.38);
  font: 600 11px var(--mono);
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}
.globe-climate-pill {
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.42);
  font: 600 10.5px var(--sans);
  color: #fbbf24;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.globe-climate-pill.cold {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.42);
  color: #38bdf8;
}
body.theme-light .globe-climate-pill {
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
}
body.theme-light .globe-climate-pill.cold {
  color: #0369a1;
  background: rgba(56, 189, 248, 0.12);
}
#globePanel.mode-dock .globe-kicker {
  display: none;
}
.globe-climate-note {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
  color: var(--text);
  font-size: 10.5px;
}
.globe-climate-note strong {
  color: var(--accent);
}
#globeEpochTitle {
  margin: 0;
  font: 600 13.5px/1.3 var(--sans);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.globe-mode-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.gmode-btn {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font: 500 11px var(--sans);
  cursor: pointer;
}
.gmode-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.gmode-btn.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.globe-close {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.globe-close:hover {
  color: var(--text);
  border-color: var(--accent);
}

.globe-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.globe-stage-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.globe-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  overflow: hidden;
}
#globeCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#globeCanvas:active {
  cursor: grabbing;
}

/* Yadong Xie Signature Tilt-Shift Miniature Lens Blur (Top & Bottom Edge Blur Masks) */
.globe-tilt-shift {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.25s ease;
}
.globe-canvas-wrap.tilt-off .globe-tilt-shift {
  opacity: 0;
}
.globe-tilt-top {
  top: 0;
  height: 18%;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.38) 52%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.38) 52%, rgba(0,0,0,0) 100%);
}
.globe-tilt-bottom {
  bottom: 22px;
  height: 16%;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  -webkit-mask-image: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.38) 52%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.38) 52%, rgba(0,0,0,0) 100%);
}

/* Pixel Singapore–Style Top-Left Pixel Watermark */
.globe-pixel-watermark {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 3;
  pointer-events: none;
  user-select: none;
}
.mode-dock .globe-pixel-watermark {
  display: none;
}
.gpw-title {
  font: 800 17px/1.1 "JetBrains Mono", "Noto Sans SC", monospace;
  letter-spacing: 0.03em;
  color: #ffffff;
  text-shadow:
    2px 2px 0 #090d14,
    -1px -1px 0 #090d14,
    1px -1px 0 #090d14,
    -1px 1px 0 #090d14;
}
.gpw-sub {
  margin-top: 3px;
  font: 600 10.5px/1.2 "JetBrains Mono", "Noto Sans SC", monospace;
  color: #d1fae5;
  text-shadow:
    1px 1px 0 #090d14,
    -1px -1px 0 #090d14,
    1px -1px 0 #090d14,
    -1px 1px 0 #090d14;
}

.globe-region-Overlay {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 163, 127, 0.03);
  flex-shrink: 0;
}
.globe-region-Overlay button {
  padding: 2.5px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--muted);
  font: 500 10.5px var(--sans);
  cursor: pointer;
}
.globe-region-Overlay button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.globe-tooltip {
  position: absolute;
  z-index: 10;
  width: max-content;
  max-width: min(260px, calc(100% - 20px));
  max-height: calc(100% - 20px);
  overflow: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  font-size: 11.5px;
}
.globe-tooltip .gt-title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.globe-tooltip .gt-title span {
  color: var(--accent);
  font-weight: 600;
}
.globe-tooltip .gt-sub {
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.globe-tooltip .gt-overlap { margin-bottom:8px; }
.globe-tooltip .gt-overlap-title { font-weight:700; }
.globe-tooltip .gt-overlap-notice { margin:4px 0 6px; line-height:1.4; }
.globe-tooltip .gt-choice, .globe-tooltip .gt-clear {
  display:block; width:100%; margin-top:4px; padding:6px;
  color:inherit; background:transparent; border:1px solid var(--accent);
  border-radius:4px; font:inherit; text-align:left; white-space:normal;
  overflow-wrap:anywhere; cursor:pointer;
}
.globe-tooltip .gt-choice[aria-pressed="true"] { font-weight:700; border-width:2px; }
.globe-tooltip button:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
.globe-tooltip .gt-basis {
  overflow-wrap: anywhere;
  font-size: 10px;
  line-height: 1.4;
  color: var(--muted);
}

.globe-controls-strip {
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.globe-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gs-bound {
  font: 500 10.5px var(--mono);
  color: var(--muted);
}
#globeYearSlider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.globe-layer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.gtoggle-btn {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font: 500 10.5px var(--sans);
  cursor: pointer;
}
.gtoggle-btn.on {
  background: rgba(16, 163, 127, 0.16);
  border-color: var(--accent);
  color: var(--text);
}

.globe-summary {
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  max-height: 44px;
  overflow-y: auto;
}

.globe-epoch-bar {
  display: flex;
  gap: 5px;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
}
.globe-epoch-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.globe-epoch-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.globe-epoch-chip.on {
  background: rgba(16, 163, 127, 0.18);
  border-color: var(--accent);
  color: var(--text);
}
.globe-epoch-chip .ge-yr {
  font: 700 10.5px var(--mono);
  color: var(--accent);
}
.globe-epoch-chip .ge-name {
  font: 500 10.5px var(--sans);
  white-space: nowrap;
}

.globe-side-col {
  width: 330px;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.globe-side-head {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.globe-side-head h4 {
  margin: 0 0 2px;
  font: 600 12.5px var(--sans);
  color: var(--text);
}
.globe-side-head span {
  font-size: 10.5px;
  color: var(--muted);
}
.globe-polity-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.globe-polity-item {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.globe-polity-item:hover {
  border-color: var(--accent);
  background: rgba(16, 163, 127, 0.07);
}
.gp-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
}
.gp-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border: 1.5px solid;
  flex-shrink: 0;
}
.gp-tag {
  margin-left: auto;
  font: 500 9.5px var(--mono);
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(16, 163, 127, 0.12);
  color: var(--accent);
}
.gp-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}
.gp-cap {
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--text);
}
.gp-cap span {
  color: var(--accent);
}
.gp-basis {
  overflow-wrap: anywhere;
  margin-top: 4px;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
}

@media (max-width: 760px) {
  #globePanel.mode-dock, #globePanel.mode-split, #globePanel.mode-modal {
    top: var(--ruler-h); left: 0; right: 0; bottom: 0;
    width: auto; height: auto; border-radius: 0; z-index: 24;
  }
  #globePanel .globe-side-col { display: none; }
  body.globe-split-active #stage { right: 0; }
  .gmode-btn[data-gmode="split"] { display: none; }
  .globe-header { flex-wrap: wrap; }
}
