:root {
  --paper: #f4ede0;
  --paper-soft: #faf5ea;
  --paper-deep: #e8ddc9;
  --paper-shadow: #d8cab2;
  --ink: #28221b;
  --ink-soft: #564c40;
  --muted: #897b68;
  --faint: #b7a892;
  --line: #d2c3ac;
  --line-soft: #e2d7c5;
  --cinnabar: #a63a2b;
  --cinnabar-deep: #7d2a20;
  --gold: #b08a4a;
  --gold-deep: #8a6936;
  --imperial: #c19a2b;
  --ui: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", serif;
  /* 人物卡字体：宋体系统的书版字，横细竖粗、字形方正，缩小后比楷体更易分辨 */
  --card-face: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC", "SimSun", "宋体", serif;
  --kai: var(--ui);
  --sidebar-width: 204px;
  --detail-width: 432px;
  --topbar-height: 76px;
  --shadow-soft: 0 18px 50px rgba(54, 40, 24, 0.14);
  --shadow-card: 0 8px 24px rgba(54, 40, 24, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--ui);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--cinnabar);
  outline-offset: 3px;
}

::selection {
  color: #fff9ee;
  background: rgba(166, 58, 43, 0.78);
}

.app {
  position: relative;
  display: flex;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */

.sidebar {
  position: relative;
  z-index: 20;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  overflow: hidden;
  border-right: 1px solid rgba(176, 153, 120, 0.4);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.32), transparent 22%),
    linear-gradient(180deg, #f2eadb 0%, #ede3d1 54%, #e7dcc8 100%);
  transition:
    width 0.38s cubic-bezier(0.22, 0.8, 0.2, 1),
    flex-basis 0.38s cubic-bezier(0.22, 0.8, 0.2, 1),
    transform 0.38s cubic-bezier(0.22, 0.8, 0.2, 1);
}

.sidebar::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.28;
  background-image: url("assets/grain.svg");
  mix-blend-mode: multiply;
}

.sidebar-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 16px 18px;
}

.app.sidebar-collapsed .sidebar {
  flex-basis: 0;
  width: 0;
  transform: translateX(-24px);
  border-right-color: transparent;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(176, 153, 120, 0.34);
}

.brand-seal {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #faeee0;
  background: var(--cinnabar);
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 244, 228, 0.76),
    inset 0 0 0 3px rgba(125, 42, 32, 0.5),
    0 3px 9px rgba(125, 42, 32, 0.2);
  font-family: var(--kai);
  font-size: 25px;
  line-height: 1;
  transform: rotate(-2deg);
}

.brand-text {
  min-width: 0;
  padding-top: 0;
}

.brand-eyebrow {
  margin: 0 0 3px;
  color: var(--gold-deep);
  font-family: "Palatino Linotype", "Baskerville", var(--serif);
  font-size: 7.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

.brand h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: 0.12em;
}

.brand-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.sidebar-section {
  padding-top: 18px;
}

.key-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding-bottom: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.24em;
}

.section-count {
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.lineage-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lineage-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 8px;
  width: 100%;
  padding: 9px 8px 9px 11px;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.lineage-item::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 2px;
  content: "";
  background: transparent;
  transition: background 0.2s ease;
}

.lineage-item:hover {
  background: rgba(255, 251, 241, 0.5);
  border-color: rgba(176, 153, 120, 0.26);
}

.lineage-item.active {
  background: rgba(255, 251, 241, 0.82);
  border-color: rgba(176, 153, 120, 0.4);
  box-shadow: 0 2px 9px rgba(73, 54, 32, 0.05);
}

.lineage-item.active::before {
  background: var(--cinnabar);
}

.lineage-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lineage-period {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 10px;
  letter-spacing: 0.03em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lineage-people {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 9px;
  letter-spacing: 0.03em;
}

.key-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.key-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  padding: 7px 6px;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 2px;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.key-item:hover {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.5);
}

.key-item.active {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.8);
}

.key-order {
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 9px;
  letter-spacing: 0.04em;
}

.key-name {
  overflow: hidden;
  font-family: var(--kai);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-meta {
  color: var(--faint);
  font-size: 9px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.sidebar-footer {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 15px;
  color: var(--faint);
  border-top: 1px solid rgba(176, 153, 120, 0.28);
  font-family: var(--kai);
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.sidebar-footer p {
  margin: 0 0 4px;
}

.sidebar-footer p:last-child {
  margin-bottom: 0;
}

.sidebar-scrim {
  display: none;
}

/* ------------------------------------------------------------------ */
/* Main and topbar                                                     */
/* ------------------------------------------------------------------ */

.main {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.topbar {
  position: relative;
  z-index: 12;
  display: flex;
  flex: 0 0 var(--topbar-height);
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: var(--topbar-height);
  padding: 0 24px 0 18px;
  border-bottom: 1px solid rgba(176, 153, 120, 0.34);
  background: rgba(246, 239, 226, 0.84);
  backdrop-filter: blur(10px);
}

.topbar::after {
  position: absolute;
  right: 24px;
  bottom: -1px;
  left: 24px;
  height: 1px;
  pointer-events: none;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(176, 138, 74, 0.35), transparent);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
}

.topbar-left {
  min-width: 0;
  gap: 15px;
}

.topbar-right {
  flex: 0 0 auto;
  gap: 12px;
}

.topbar-heading {
  min-width: 0;
}

.topbar-period {
  margin: 0 0 2px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title {
  margin: 0;
  overflow: hidden;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.14em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-stats {
  margin: 0;
  color: var(--muted);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 10px;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.icon-button:hover {
  background: rgba(255, 251, 241, 0.72);
  border-color: rgba(176, 153, 120, 0.35);
}

.icon-button svg,
.text-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.text-button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  height: 32px;
  padding: 0 11px;
  color: var(--ink-soft);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(176, 153, 120, 0.48);
  border-radius: 2px;
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

.text-button:hover {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.8);
  border-color: rgba(166, 58, 43, 0.4);
}

.text-button:disabled {
  cursor: default;
  opacity: 0.4;
}

/* ------------------------------------------------------------------ */
/* Canvas                                                              */
/* ------------------------------------------------------------------ */

.canvas {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #f3ecdf;
  isolation: isolate;
}

.paper {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 16% 4%, rgba(255, 253, 246, 0.82), transparent 42%),
    radial-gradient(circle at 88% 96%, rgba(176, 138, 74, 0.1), transparent 54%),
    radial-gradient(circle at 52% 42%, #f7f1e5 0%, #f1e8d7 58%, #e9ddc9 100%);
}

.paper::before {
  position: absolute;
  inset: 0;
  content: "";
  opacity: 0.4;
  background-image: url("assets/grain.svg");
  mix-blend-mode: multiply;
}

.paper::after {
  position: absolute;
  inset: 0;
  content: "";
  box-shadow:
    inset 0 0 160px rgba(105, 79, 43, 0.09),
    inset 0 0 18px rgba(105, 79, 43, 0.05);
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.stage.is-panning {
  cursor: grabbing;
}

.viewport {
  will-change: transform;
}

.layer-links,
.layer-extras {
  pointer-events: none;
}

.link-path {
  fill: none;
  stroke: #ab9678;
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
}

.link-path.tie {
  /* 婚配线：两张卡片之间的一段短横线，比血统线略轻 */
  stroke: #bda98c;
  stroke-width: 1.6;
}

.union:hover .link-path {
  stroke: var(--gold);
}

.extra-link {
  fill: none;
  stroke: var(--gold-deep);
  stroke-dasharray: 5 4;
  stroke-linecap: round;
  stroke-width: 1.1;
  opacity: 0.72;
  vector-effect: non-scaling-stroke;
}

.extra-label {
  fill: var(--gold-deep);
  font-family: var(--kai);
  font-size: 9px;
  letter-spacing: 0.12em;
  opacity: 0.92;
  paint-order: stroke;
  stroke: rgba(245, 238, 225, 0.92);
  stroke-width: 3px;
}

.node {
  cursor: pointer;
  outline: none;
}

.node-card {
  fill: rgba(252, 248, 239, 0.94);
  stroke: #d3c4ad;
  stroke-width: 1;
  rx: 3;
  filter: url("#node-shadow");
  transition:
    fill 0.22s ease,
    stroke 0.22s ease,
    stroke-width 0.22s ease;
}

.node:hover .node-card {
  fill: #fffcf4;
}

.node.selected .node-card {
  stroke: var(--gold);
  stroke-width: 2.2;
}

.node-honor-emperor .node-card {
  stroke: var(--imperial);
  stroke-width: 2.2;
}

.node-honor-other .node-card {
  stroke: var(--cinnabar);
  stroke-width: 1.25;
}

.node-honor-emperor.selected .node-card {
  stroke: var(--imperial);
  stroke-width: 2.6;
}

.node-honor-other.selected .node-card {
  stroke: var(--cinnabar);
  stroke-width: 1.8;
}

.node-halo {
  fill: none;
  stroke: var(--cinnabar);
  stroke-dasharray: 2.5 5;
  stroke-width: 1;
  opacity: 0;
  vector-effect: non-scaling-stroke;
}

.node.selected .node-halo {
  opacity: 0.6;
}

.node.just-focused .node-halo {
  animation: halo-breathe 1.5s ease-out;
}

@keyframes halo-breathe {
  0% {
    opacity: 0.9;
    stroke-dashoffset: 0;
  }
  100% {
    opacity: 0.35;
    stroke-dashoffset: -28;
  }
}

.node-portrait {
  pointer-events: none;
}

.node-name {
  fill: var(--ink);
  font-family: var(--card-face);
  font-size: 27px;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-anchor: middle;
}

.node-alias {
  fill: var(--ink-soft);
  font-family: var(--card-face);
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-anchor: middle;
}

.node-key-mark {
  pointer-events: none;
}

.node-key-mark path {
  fill: none;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.node-key-mark.key-mark-emperor path {
  stroke: var(--imperial);
}

.node-key-mark.key-mark-other path {
  stroke: var(--cinnabar);
}

.node-key .node-card {
  fill: rgba(255, 249, 237, 0.97);
}

.node:focus-visible .node-card {
  stroke: var(--cinnabar);
  stroke-width: 2;
}

.node-honor-emperor:focus-visible .node-card {
  stroke: var(--imperial);
}

/* ------------------------------------------------------------------ */
/* Left rail                                                           */
/* ------------------------------------------------------------------ */

.left-rail {
  position: absolute;
  top: 16px;
  left: 14px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  width: 132px;
  max-height: calc(100% - 116px);
  overflow: hidden;
  background: rgba(250, 245, 235, 0.8);
  border: 1px solid rgba(176, 153, 120, 0.38);
  border-radius: 3px;
  box-shadow: 0 7px 22px rgba(54, 40, 24, 0.09);
  backdrop-filter: blur(8px);
}

.generation-labels {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 156px;
  z-index: 0;
  width: 124px;
  overflow: hidden;
  pointer-events: none;
}

.generation-label {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 1px 0 1px 10px;
  border-left: 1px solid rgba(176, 138, 74, 0.42);
  will-change: transform;
  transition: opacity 0.18s ease;
}

.generation-label.active {
  border-left-color: var(--cinnabar);
}

.gen-index {
  color: var(--gold-deep);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.35;
}

.generation-label.active .gen-index {
  color: var(--cinnabar);
}

.gen-name {
  overflow: hidden;
  max-width: 108px;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 9px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gen-count {
  color: var(--faint);
  font-size: 8px;
  line-height: 1.2;
  letter-spacing: 0.03em;
}

.rail-tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid rgba(176, 153, 120, 0.26);
}

.rail-tab {
  flex: 1;
  padding: 7px 0 6px;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-align: center;
  cursor: pointer;
  background: transparent;
  border: 0;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.rail-tab:hover {
  color: var(--ink);
}

.rail-tab.active {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.72);
}

.rail-panel {
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.rail-list {
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.key-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px;
}

.key-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.key-group + .key-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(176, 153, 120, 0.22);
}

.key-group.is-empty .key-group-head {
  opacity: 0.55;
}

.key-group-head {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 3px 4px 2px;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.key-group-icon {
  display: flex;
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
}

.key-group-count {
  margin-left: auto;
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 8px;
  letter-spacing: 0;
}

.key-glyph {
  display: block;
  width: 12px;
  height: 12px;
  overflow: visible;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.key-glyph-emperor {
  stroke: var(--imperial);
}

.key-glyph-other {
  stroke: var(--cinnabar);
}

.key-item {
  display: grid;
  grid-template-columns: 13px minmax(0, 1fr);
  gap: 5px;
  align-items: center;
  width: 100%;
  padding: 6px 4px;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 2px;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.key-item:hover {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.55);
}

.key-item.active {
  color: var(--cinnabar);
  background: rgba(255, 251, 241, 0.9);
}

.key-mark {
  display: flex;
  align-items: center;
  width: 13px;
  height: 13px;
}

.key-order {
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 8px;
  letter-spacing: 0.02em;
}

.key-name {
  overflow: hidden;
  font-family: var(--kai);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-meta {
  color: var(--faint);
  font-size: 8px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* HUD                                                                 */
/* ------------------------------------------------------------------ */

.view-hint {
  position: absolute;
  top: 17px;
  left: 160px;
  z-index: 5;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 11px;
  color: var(--muted);
  background: rgba(247, 240, 227, 0.7);
  border: 1px solid rgba(176, 153, 120, 0.28);
  border-radius: 20px;
  backdrop-filter: blur(4px);
  font-family: var(--kai);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.view-hint.faded {
  opacity: 0;
}

.hint-dot {
  width: 4px;
  height: 4px;
  background: var(--cinnabar);
  border-radius: 50%;
}

.stage-tools {
  position: absolute;
  bottom: 20px;
  left: 160px;
  z-index: 7;
  display: flex;
  gap: 2px;
  align-items: center;
  height: 38px;
  padding: 3px 5px;
  background: rgba(250, 245, 235, 0.9);
  border: 1px solid rgba(176, 153, 120, 0.42);
  border-radius: 3px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(8px);
}

.tool-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 2px;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.tool-button:hover {
  color: var(--cinnabar);
  background: rgba(230, 218, 198, 0.6);
}

.tool-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.zoom-readout {
  min-width: 42px;
  color: var(--muted);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 9.5px;
  letter-spacing: 0.03em;
  text-align: center;
}

.tool-separator {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: rgba(176, 153, 120, 0.36);
}

.minimap {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 7;
  width: 186px;
  height: 126px;
  overflow: hidden;
  background: rgba(249, 243, 232, 0.92);
  border: 1px solid rgba(176, 153, 120, 0.44);
  border-radius: 3px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(6px);
  cursor: crosshair;
}

.minimap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.minimap-label {
  position: absolute;
  top: 5px;
  left: 7px;
  color: var(--faint);
  font-family: var(--kai);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  pointer-events: none;
}

.mini-node {
  fill: rgba(137, 123, 104, 0.42);
  stroke: none;
}

.mini-node.key {
  fill: rgba(166, 58, 43, 0.62);
}

.mini-node.mini-emperor {
  fill: rgba(193, 154, 43, 0.72);
}

.mini-node.mini-other {
  fill: rgba(166, 58, 43, 0.62);
}

.mini-viewport {
  fill: rgba(176, 138, 74, 0.1);
  stroke: var(--gold-deep);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

/* ------------------------------------------------------------------ */
/* Empty / loading / error                                             */
/* ------------------------------------------------------------------ */

.empty-state,
.error-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 8;
  width: min(360px, calc(100% - 48px));
  padding: 28px;
  text-align: center;
  background: rgba(250, 245, 235, 0.94);
  border: 1px solid rgba(176, 153, 120, 0.44);
  border-radius: 3px;
  box-shadow: var(--shadow-soft);
  transform: translate(-50%, -50%);
}

.empty-state[hidden],
.error-panel[hidden] {
  display: none;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 15px;
  color: var(--cinnabar);
  border: 1px solid rgba(166, 58, 43, 0.5);
  border-radius: 50%;
  font-family: var(--kai);
  font-size: 24px;
}

.empty-title,
.error-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.12em;
}

.empty-copy,
.error-copy {
  margin: 0 0 18px;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 12.5px;
  line-height: 1.8;
}

.primary-button {
  height: 34px;
  padding: 0 17px;
  color: #fbf1e2;
  font-size: 12px;
  letter-spacing: 0.1em;
  cursor: pointer;
  background: var(--cinnabar);
  border: 0;
  border-radius: 2px;
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.primary-button:hover {
  background: var(--cinnabar-deep);
  transform: translateY(-1px);
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--paper);
  font-family: var(--kai);
  font-size: 12px;
  letter-spacing: 0.2em;
  transition:
    opacity 0.4s ease,
    visibility 0.4s ease;
}

.loading.done {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-seal {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: #faeee0;
  background: var(--cinnabar);
  border-radius: 2px;
  font-family: var(--kai);
  font-size: 26px;
  animation: seal-turn 2.4s ease-in-out infinite;
}

.loading p {
  margin: 0;
}

@keyframes seal-turn {
  0%,
  100% {
    transform: rotate(-4deg) scale(1);
  }
  50% {
    transform: rotate(3deg) scale(0.94);
  }
}

/* ------------------------------------------------------------------ */
/* Detail drawer                                                       */
/* ------------------------------------------------------------------ */

.detail {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: var(--detail-width);
  max-width: 100%;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(252, 247, 238, 0.98), rgba(247, 240, 228, 0.99)),
    var(--paper);
  border-left: 1px solid rgba(176, 153, 120, 0.5);
  box-shadow: -24px 0 70px rgba(54, 40, 24, 0.18);
  transform: translateX(103%);
  transition: transform 0.42s cubic-bezier(0.22, 0.8, 0.2, 1);
}

.detail::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  content: "";
  background: linear-gradient(180deg, var(--cinnabar) 0 54px, var(--gold) 54px 100%);
  opacity: 0.82;
}

.detail.open {
  transform: translateX(0);
}

.detail-scroll {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 30px 34px 34px 32px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 12px;
  min-height: 24px;
}

.detail-kicker {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-top: 3px;
  color: var(--gold-deep);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.17em;
}

.detail-kicker .dot {
  width: 3px;
  height: 3px;
  background: var(--cinnabar);
  border-radius: 50%;
}

.detail-kicker.honor-emperor span:last-child {
  color: var(--imperial);
}

.detail-kicker.honor-other span:last-child {
  color: var(--cinnabar);
}

.detail-close {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(176, 153, 120, 0.4);
  border-radius: 50%;
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

.detail-close:hover {
  color: var(--cinnabar);
  background: rgba(255, 252, 245, 0.8);
  border-color: rgba(166, 58, 43, 0.45);
}

.detail-close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.6;
}

.detail-hero {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-top: 20px;
}

.detail-portrait {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  height: 96px;
  padding: 4px;
  background: #f8f1e2;
  border: 1px solid rgba(176, 153, 120, 0.54);
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(255, 252, 246, 0.8) inset,
    0 8px 22px rgba(54, 40, 24, 0.13);
}

.detail-portrait img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.detail-name {
  margin: 0;
  font-size: 34px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.12em;
}

.detail-aliases {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 12px;
  letter-spacing: 0.06em;
  line-height: 1.6;
}

.detail-title {
  margin: 5px 0 0;
  color: var(--cinnabar);
  font-family: var(--kai);
  font-size: 12.5px;
  letter-spacing: 0.08em;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.detail-tag {
  padding: 3px 8px;
  color: var(--ink-soft);
  background: rgba(232, 221, 201, 0.48);
  border: 1px solid rgba(176, 153, 120, 0.3);
  border-radius: 2px;
  font-family: var(--kai);
  font-size: 10.5px;
  letter-spacing: 0.06em;
}

.detail-lead {
  margin-top: 22px;
  padding: 15px 0 15px 16px;
  border-left: 2px solid rgba(166, 58, 43, 0.72);
}

.detail-lead p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--kai);
  font-size: 15px;
  line-height: 1.95;
  letter-spacing: 0.02em;
}

.detail-section {
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid rgba(176, 153, 120, 0.3);
}

.detail-section h4 {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 11px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
}

.detail-section h4::before {
  width: 12px;
  height: 1px;
  content: "";
  background: var(--cinnabar);
}

.detail-bio p {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 2.02;
  letter-spacing: 0.012em;
  text-align: justify;
}

.detail-bio p:last-child {
  margin-bottom: 0;
}

.detail-bio-standalone {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid rgba(176, 153, 120, 0.3);
}

.detail-bio p:first-child::first-letter {
  float: left;
  margin: 5px 5px 0 0;
  color: var(--cinnabar);
  font-family: var(--kai);
  font-size: 30px;
  line-height: 0.9;
}

.relation-group {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px;
  align-items: start;
  padding: 7px 0;
  border-bottom: 1px dotted rgba(176, 153, 120, 0.28);
}

.relation-group:last-child {
  border-bottom: 0;
}

.relation-label {
  padding-top: 4px;
  color: var(--muted);
  font-family: var(--kai);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  display: inline-flex;
  gap: 5px;
  align-items: baseline;
  padding: 4px 8px;
  color: var(--ink-soft);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  cursor: pointer;
  background: rgba(255, 252, 244, 0.74);
  border: 1px solid rgba(176, 153, 120, 0.42);
  border-radius: 2px;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.chip:hover {
  color: var(--cinnabar);
  background: #fffdf7;
  border-color: rgba(166, 58, 43, 0.42);
}

.chip.key {
  border-color: rgba(166, 58, 43, 0.35);
}

.chip.emperor {
  border-color: rgba(193, 154, 43, 0.6);
}

.chip.other {
  border-color: rgba(166, 58, 43, 0.5);
}

.chip small {
  color: var(--faint);
  font-size: 8.5px;
  letter-spacing: 0.02em;
}

.chip.key small {
  color: var(--cinnabar);
}

.relation-empty {
  color: var(--faint);
  font-family: var(--kai);
  font-size: 11px;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: 22px;
  border-top: 1px solid rgba(176, 153, 120, 0.3);
}

.meta-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dotted rgba(176, 153, 120, 0.26);
  font-size: 11.5px;
  line-height: 1.6;
}

.meta-label {
  color: var(--muted);
  font-family: var(--kai);
  letter-spacing: 0.08em;
}

.meta-value {
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 16px;
}

.action-button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  height: 34px;
  padding: 0 13px;
  color: var(--ink-soft);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  cursor: pointer;
  background: rgba(255, 252, 245, 0.75);
  border: 1px solid rgba(176, 153, 120, 0.48);
  border-radius: 2px;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.action-button:hover {
  color: var(--cinnabar);
  background: #fffdf7;
  border-color: rgba(166, 58, 43, 0.42);
}

.action-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.action-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.detail-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid rgba(176, 153, 120, 0.34);
}

.key-nav-button {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(176, 153, 120, 0.34);
  border-radius: 2px;
  transition:
    background 0.18s ease,
    border-color 0.18s ease;
}

.key-nav-button.next {
  text-align: right;
  align-items: flex-end;
}

.key-nav-button:hover:not(:disabled) {
  background: rgba(255, 252, 245, 0.72);
  border-color: rgba(166, 58, 43, 0.4);
}

.key-nav-button:disabled {
  cursor: default;
  opacity: 0.32;
}

.key-nav-label {
  color: var(--faint);
  font-family: "Palatino Linotype", "Baskerville", serif;
  font-size: 8.5px;
  letter-spacing: 0.12em;
}

.key-nav-name {
  overflow: hidden;
  max-width: 100%;
  color: var(--ink-soft);
  font-family: var(--kai);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Toast                                                               */
/* ------------------------------------------------------------------ */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  padding: 9px 16px;
  color: #f7eedf;
  background: rgba(40, 34, 27, 0.94);
  border: 1px solid rgba(176, 138, 74, 0.42);
  border-radius: 2px;
  box-shadow: var(--shadow-card);
  font-family: var(--kai);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--kai);
  font-size: 15px;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1100px) {
  :root {
    --sidebar-width: 196px;
  }

  .topbar-stats {
    display: none;
  }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: var(--sidebar-width);
    transform: translateX(-103%);
    box-shadow: 24px 0 60px rgba(54, 40, 24, 0.2);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-103%);
    border-right-color: rgba(176, 153, 120, 0.4);
  }

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: rgba(43, 34, 24, 0.28);
    backdrop-filter: blur(1px);
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  .topbar {
    padding-right: 14px;
    padding-left: 10px;
  }

  .topbar-title {
    font-size: 19px;
  }

  .detail {
    width: min(432px, 100%);
  }

  .minimap {
    display: none;
  }

  .left-rail {
    top: 8px;
    right: 8px;
    left: 8px;
    width: auto;
    height: 42px;
    max-height: none;
    flex-direction: row;
  }

  .generation-labels {
    display: none;
  }

  .rail-tabs {
    flex: 0 0 44px;
    flex-direction: column;
    border-right: 1px solid rgba(176, 153, 120, 0.26);
    border-bottom: 0;
  }

  .rail-tab {
    flex: 1;
    padding: 0;
    font-size: 9px;
    letter-spacing: 0;
    line-height: 1;
    white-space: nowrap;
  }

  .rail-panel {
    flex: 1 1 auto;
    min-width: 0;
  }

  .rail-list {
    display: flex;
    flex-direction: row;
    gap: 3px;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
  }

  .key-list {
    gap: 3px;
    padding: 4px;
  }

  .key-group {
    display: contents;
  }

  .key-group-head {
    display: none;
  }

  .key-item {
    display: flex;
    flex: 0 0 auto;
    gap: 5px;
    align-items: center;
    width: auto;
    padding: 4px 7px;
    border: 1px solid rgba(176, 153, 120, 0.24);
    border-radius: 2px;
  }

  .key-mark {
    width: 11px;
    height: 11px;
  }

  .key-mark .key-glyph {
    width: 11px;
    height: 11px;
  }

  .key-order {
    display: none;
  }

  .key-name {
    font-size: 11px;
  }

  .key-meta {
    font-size: 7.5px;
  }

  .generation-rail {
    gap: 3px;
    padding: 4px;
  }

  .view-hint {
    top: 58px;
    left: 12px;
  }

  .stage-tools {
    left: 12px;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-height: 64px;
  }

  .topbar {
    gap: 10px;
    padding-right: 10px;
  }

  .topbar-period {
    font-size: 9.5px;
    letter-spacing: 0.12em;
  }

  .topbar-title {
    font-size: 17px;
    letter-spacing: 0.1em;
  }

  .topbar-right {
    gap: 6px;
  }

  .text-button {
    padding: 0 8px;
    font-size: 10.5px;
  }

  .text-button svg {
    display: none;
  }

  .stage-tools {
    bottom: 14px;
    left: 12px;
  }

  .view-hint {
    display: none;
  }

  .detail-scroll {
    padding: 24px 22px 30px 22px;
  }

  .detail-name {
    font-size: 30px;
  }

  .detail-portrait {
    width: 82px;
    height: 82px;
  }

  .detail-hero {
    gap: 14px;
  }

  .detail-bio p {
    font-size: 13.5px;
  }

  .detail-lead p {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------------ */
/* Legibility pass                                                     */
/* ------------------------------------------------------------------ */

.brand h1,
.topbar-title,
.detail-name {
  font-family: var(--serif);
  font-weight: 700;
}

.brand h1 {
  font-size: 27px;
}

.brand-eyebrow {
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 0.16em;
}

.brand-note,
.sidebar-footer {
  font-family: var(--ui);
  font-size: 11.5px;
  line-height: 1.7;
}

.section-heading {
  font-size: 13.5px;
}

.section-count,
.lineage-people {
  font-family: var(--ui);
  font-size: 10px;
  font-weight: 500;
}

.lineage-name {
  font-size: 15px;
}

.lineage-period {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.key-group-head {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.key-group-icon {
  flex-basis: 14px;
  width: 14px;
  height: 14px;
}

.key-group-count {
  font-family: var(--ui);
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
}

.key-item {
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 6px;
  padding: 8px 6px;
}

.key-mark {
  width: 16px;
  height: 16px;
}

.key-glyph {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
}

.key-name {
  font-family: var(--ui);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.generation-label {
  gap: 2px;
}

.gen-index {
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.gen-name {
  max-width: 108px;
  color: var(--ink-soft);
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}

.gen-count {
  color: var(--muted);
  font-family: var(--ui);
  font-size: 10px;
  font-weight: 500;
}

.topbar-period {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.topbar-title {
  font-size: 24px;
}

.topbar-stats {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.detail-kicker {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 600;
}

.detail-name {
  font-size: 36px;
}

.detail-aliases {
  font-family: var(--ui);
  font-size: 13.5px;
  font-weight: 500;
}

.detail-title {
  font-family: var(--ui);
  font-size: 14px;
  font-weight: 600;
}

.detail-tag {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 500;
}

.detail-lead p {
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.9;
}

.detail-bio p {
  font-family: var(--ui);
  font-size: 15.5px;
  line-height: 1.95;
}

.detail-section h4 {
  font-family: var(--ui);
  font-size: 12.5px;
  font-weight: 600;
}

.relation-label,
.chip {
  font-family: var(--ui);
}

.relation-label {
  font-size: 12px;
  font-weight: 500;
}

.chip {
  font-size: 12px;
  font-weight: 500;
}

.chip small {
  font-size: 9.5px;
}

@media (max-width: 640px) {
  .detail-bio p {
    font-size: 15.5px;
  }

  .detail-lead p {
    font-size: 16px;
  }
}
