:root {
  --bg-ivory: #FAF8F4;
  --bg-ivory-alt: #F4EFE5;
  --bg-surface: #FFFFFF;
  --bg-surface-soft: #FCFBF8;
  --border-gold: #E5DCC8;
  --border-gold-strong: #C9A96E;
  --border-slate: #CBD5E1;
  --navy: #1B365D;
  --navy-soft: #2B4C7E;
  --navy-tint: #EEF3F9;
  --gold: #B8934A;
  --gold-bright: #D4AF37;
  --gold-tint: #FBF5E6;
  --crimson: #A63D40;
  --crimson-tint: #FDF2F2;
  --plum: #8A4F67;
  --plum-tint: #F9F2F5;
  --slate-dark: #1E293B;
  --slate-body: #334155;
  --slate-muted: #64748B;
  --slate-light: #94A3B8;
  --shadow-sm: 0 2px 6px rgba(27, 54, 93, 0.06);
  --shadow-md: 0 8px 24px rgba(27, 54, 93, 0.10);
  --shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.16);
  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", "PMingLiU", Georgia, serif;
  --font-sans: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --toolbar-h: 64px;
  --drawer-w: 420px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-ivory);
  color: var(--slate-dark);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app-root {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* Custom subtle scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(184, 147, 74, 0.35);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(184, 147, 74, 0.55);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

/* ==================== TOOLBAR ==================== */
.ft-toolbar {
  min-height: var(--toolbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 16px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border-gold);
  box-shadow: 0 1px 4px rgba(27, 54, 93, 0.04);
  z-index: 40;
  position: relative;
}

.ft-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 290px;
  overflow: hidden;
  flex-shrink: 1;
}

.ft-seal {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--crimson);
  color: #FFFDF9;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1.5px rgba(255, 245, 230, 0.45), 0 2px 6px rgba(166, 61, 64, 0.25);
  letter-spacing: 0;
  user-select: none;
}

.ft-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.ft-title-input {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  border: 1px solid transparent;
  background: transparent;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  width: 100%;
  max-width: 230px;
  text-overflow: ellipsis;
  transition: border-color 0.15s, background-color 0.15s;
}
.ft-title-input:hover {
  border-color: var(--border-gold);
  background: var(--bg-surface-soft);
}
.ft-title-input:focus {
  outline: none;
  border-color: var(--gold);
  background: #FFFFFF;
}

.ft-subtitle {
  font-size: 11px;
  color: var(--slate-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}

.ft-subtitle #ft-sub-hint {
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--gold-tint);
  border: 1px solid var(--border-gold);
  color: #7D5E24;
  font-weight: 600;
  font-size: 11px;
  flex-shrink: 0;
}

/* Search Bar */
.ft-search-wrap {
  position: relative;
  flex: 1;
  max-width: 250px;
  min-width: 140px;
}

.ft-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-light);
  pointer-events: none;
  width: 15px;
  height: 15px;
}

.ft-search-input {
  width: 100%;
  height: 36px;
  padding: 0 30px 0 34px;
  border-radius: 999px;
  border: 1px solid var(--border-gold);
  background: var(--bg-surface-soft);
  color: var(--slate-dark);
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.ft-search-input:focus {
  outline: none;
  background: #FFFFFF;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(27, 54, 93, 0.10);
}
.ft-search-input::placeholder {
  color: var(--slate-light);
}

.ft-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--slate-muted);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.ft-search-clear:hover {
  background: var(--bg-ivory-alt);
  color: var(--slate-dark);
}

.ft-search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #FFFFFF;
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 60;
  padding: 4px;
}

.ft-search-item {
  width: 100%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  transition: background-color 0.12s;
}
.ft-search-item:hover,
.ft-search-item.is-active {
  background: var(--navy-tint);
}

.ft-search-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-ivory-alt);
  border: 1px solid var(--border-gold);
  color: var(--navy);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.ft-search-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ft-search-meta {
  flex: 1;
  min-width: 0;
}
.ft-search-name {
  font-weight: 600;
  color: var(--slate-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ft-search-sub {
  font-size: 11px;
  color: var(--slate-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-search-gen {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--gold-tint);
  color: #7D5E24;
  border: 1px solid var(--border-gold);
  white-space: nowrap;
}

/* Toolbar Actions */
.ft-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 1;
}

.ft-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border-gold);
  background: #FFFFFF;
  color: var(--slate-dark);
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.ft-btn:hover:not(:disabled) {
  background: var(--bg-ivory);
  border-color: var(--border-gold-strong);
}
.ft-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.ft-btn-icon {
  width: 34px;
  padding: 0;
  justify-content: center;
}

.ft-btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #FFFFFF;
}
.ft-btn-primary:hover:not(:disabled) {
  background: var(--navy-soft);
  border-color: var(--navy-soft);
}

.ft-btn-gold {
  background: var(--gold-tint);
  border-color: var(--border-gold-strong);
  color: #6B4E1B;
}
.ft-btn-gold:hover:not(:disabled) {
  background: #F4E8CA;
}

.ft-btn-danger {
  background: var(--crimson-tint);
  border-color: #E7B8B9;
  color: var(--crimson);
}
.ft-btn-danger:hover:not(:disabled) {
  background: #FBE2E2;
}

.ft-btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
  border-radius: 6px;
}

.ft-dropdown {
  position: relative;
}

.ft-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 225px;
  background: #FFFFFF;
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 60;
}

.ft-dropdown-item {
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--slate-dark);
}
.ft-dropdown-item:hover {
  background: var(--navy-tint);
}
.ft-dropdown-item strong {
  font-size: 12.5px;
  font-weight: 600;
}
.ft-dropdown-item span {
  font-size: 11px;
  color: var(--slate-muted);
}

/* ==================== WORKSPACE & CANVAS ==================== */
.ft-workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-ivory);
}

.ft-canvas-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
  background-image: radial-gradient(rgba(184, 147, 74, 0.14) 1px, transparent 1px);
  background-size: 24px 24px;
}
.ft-canvas-viewport.is-panning {
  cursor: grabbing;
}

.ft-canvas-bands-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ft-gen-band {
  position: absolute;
  left: 0;
  right: 0;
  border-bottom: 1px dashed rgba(184, 147, 74, 0.30);
}
.ft-gen-band.is-alt {
  background: rgba(244, 239, 229, 0.56);
}
.ft-gen-band-first-top {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(184, 147, 74, 0.25);
  pointer-events: none;
}

.ft-canvas-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.ft-canvas-stage.is-animating {
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.ft-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

/* Connector Styling */
.ft-conn-married {
  stroke: var(--navy);
  stroke-width: 2.2;
  fill: none;
  transition: opacity 0.18s ease, stroke 0.18s ease, stroke-width 0.18s ease;
}

.ft-conn-divorced {
  stroke: var(--crimson);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  fill: none;
  transition: opacity 0.18s ease, stroke 0.18s ease;
}

.ft-conn-unknown {
  stroke: var(--slate-light);
  stroke-width: 1.8;
  stroke-dasharray: 4 4;
  fill: none;
  transition: opacity 0.18s ease;
}

.ft-conn-offspring {
  stroke: #5A6B82;
  stroke-width: 1.85;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.18s ease, stroke 0.18s ease, stroke-width 0.18s ease;
}

.ft-conn-group.is-dimmed {
  opacity: 0.16;
}
.ft-conn-group.is-lineage .ft-conn-married,
.ft-conn-group.is-lineage .ft-conn-offspring {
  stroke: var(--gold);
  stroke-width: 2.8;
}
.ft-conn-group.is-lineage .ft-conn-divorced {
  stroke: var(--crimson);
  stroke-width: 2.6;
}

.ft-divorce-badge-bg {
  fill: #FFFFFF;
  stroke: var(--crimson);
  stroke-width: 1.3;
}
.ft-divorce-badge-text {
  fill: var(--crimson);
  font-size: 9.5px;
  font-weight: 700;
  font-family: monospace;
  text-anchor: middle;
  dominant-baseline: central;
}
.ft-union-year-text {
  fill: var(--slate-muted);
  font-size: 10px;
  font-weight: 600;
  text-anchor: middle;
}

/* Sticky Left Generation Rail */
.ft-gen-rail {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 132px;
  pointer-events: none;
  z-index: 15;
  background: linear-gradient(90deg, rgba(250, 248, 244, 0.92) 0%, rgba(250, 248, 244, 0.65) 72%, rgba(250, 248, 244, 0) 100%);
}

.ft-gen-pill {
  position: absolute;
  left: 12px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-gold);
  border-left: 3.5px solid var(--gold);
  border-radius: 8px;
  padding: 5px 9px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(4px);
  pointer-events: auto;
  max-width: 114px;
}

.ft-gen-pill-zh {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}
.ft-gen-pill-en {
  font-size: 10px;
  color: var(--slate-muted);
  font-weight: 500;
  line-height: 1.25;
  margin-top: 1px;
}

/* ==================== MEMBER CARDS ==================== */
.ft-nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.ft-card {
  position: absolute;
  width: 168px;
  height: 156px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-gold);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 12px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, opacity 0.18s ease;
}

.ft-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--slate-light);
}
.ft-card[data-gender="male"]::before {
  background: var(--navy);
}
.ft-card[data-gender="female"]::before {
  background: var(--plum);
}

.ft-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--gold);
  z-index: 8;
}

.ft-card.is-dimmed {
  opacity: 0.24;
}

.ft-card.is-lineage {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(184, 147, 74, 0.24), var(--shadow-md);
  z-index: 6;
}

.ft-card.is-focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.45), var(--shadow-lg);
  z-index: 10;
}

@keyframes ftPulseRing {
  0% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.78), var(--shadow-lg); }
  70% { box-shadow: 0 0 0 16px rgba(212, 175, 55, 0), var(--shadow-lg); }
  100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0), var(--shadow-lg); }
}

.ft-card.is-pulse {
  animation: ftPulseRing 1.3s ease-out 2;
}

.ft-avatar-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  padding: 2px;
  border: 1.5px solid var(--border-gold-strong);
  background: #FFFFFF;
  flex-shrink: 0;
  margin-bottom: 6px;
}

.ft-avatar-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #F6EFE2 0%, #EAE0CC 100%);
  color: var(--navy);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
}
.ft-card[data-gender="female"] .ft-avatar-inner {
  background: linear-gradient(145deg, #F7EDF1 0%, #ECDCE3 100%);
  color: var(--plum);
}

.ft-avatar-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ft-card-zh {
  font-family: var(--font-serif);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--slate-dark);
  line-height: 1.2;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-card-en {
  font-size: 11px;
  font-weight: 500;
  color: var(--slate-muted);
  line-height: 1.25;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.ft-card-years {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
  font-weight: 600;
  margin-top: 3px;
}

.ft-card-title {
  font-size: 10.5px;
  color: #6B5733;
  background: var(--gold-tint);
  border: 1px solid rgba(201, 169, 110, 0.35);
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: auto;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Unknown Partner Card */
.ft-card-unknown {
  position: absolute;
  width: 168px;
  height: 156px;
  background: rgba(255, 253, 249, 0.82);
  border: 1.5px dashed var(--slate-light);
  border-radius: 12px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, opacity 0.18s;
}
.ft-card-unknown:hover {
  border-color: var(--navy);
  background: #FFFFFF;
}
.ft-card-unknown.is-dimmed {
  opacity: 0.22;
}
.ft-card-unknown.is-lineage {
  border-color: var(--gold);
  background: #FFFDF7;
}

.ft-unknown-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px dashed var(--slate-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-muted);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  background: var(--bg-ivory);
}

.ft-unknown-zh {
  font-family: var(--font-serif);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--slate-muted);
}
.ft-unknown-en {
  font-size: 11px;
  color: var(--slate-light);
  margin-top: 2px;
}
.ft-unknown-hint {
  font-size: 10px;
  color: var(--navy);
  margin-top: 8px;
  font-weight: 500;
}

/* ==================== FLOATING OVERLAYS ==================== */
/* Legend Box (top-right) */
.ft-legend {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 25;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 224px;
  overflow: hidden;
}

.ft-legend.is-collapsed {
  width: auto;
}

.ft-legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(229, 220, 200, 0.7);
  background: rgba(250, 248, 244, 0.85);
}
.ft-legend.is-collapsed .ft-legend-header {
  border-bottom: none;
}

.ft-legend-title {
  font-family: var(--font-serif);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy);
}

.ft-legend-toggle {
  border: none;
  background: transparent;
  color: var(--slate-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 5px;
}
.ft-legend-toggle:hover {
  background: var(--bg-ivory-alt);
  color: var(--slate-dark);
}

.ft-legend-body {
  padding: 9px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ft-legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11.5px;
  color: var(--slate-body);
}
.ft-legend-swatch {
  width: 44px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Lineage Summary Pill (bottom-center) */
.ft-lineage-pill {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border-gold-strong);
  border-radius: 999px;
  padding: 7px 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--slate-dark);
  white-space: nowrap;
}
.ft-lineage-pill strong {
  font-family: var(--font-serif);
  color: var(--navy);
}
.ft-lineage-pill.is-hidden {
  display: none;
}

/* Zoom Controls (bottom-right) */
.ft-zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 25;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 3px;
  gap: 2px;
}

.ft-zoom-btn {
  border: none;
  background: transparent;
  color: var(--slate-dark);
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ft-zoom-btn:hover {
  background: var(--bg-ivory-alt);
}

.ft-zoom-pct {
  min-width: 46px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--slate-muted);
  font-variant-numeric: tabular-nums;
}

.ft-zoom-divider {
  width: 1px;
  height: 18px;
  background: var(--border-gold);
  margin: 0 2px;
}

/* ==================== EDIT DRAWER ==================== */
.ft-drawer {
  position: fixed;
  top: var(--toolbar-h);
  right: 0;
  bottom: 0;
  width: var(--drawer-w);
  max-width: 96vw;
  background: #FFFFFF;
  border-left: 1px solid var(--border-gold);
  box-shadow: var(--shadow-lg);
  z-index: 45;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.ft-drawer.is-open {
  transform: translateX(0);
}

.ft-drawer-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-gold);
  background: var(--bg-surface-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ft-drawer-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}

.ft-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.ft-section {
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  padding: 12px 13px;
  background: var(--bg-surface-soft);
}

.ft-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.ft-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
}

/* Photo Editor */
.ft-photo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ft-photo-preview {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid var(--border-gold-strong);
  background: var(--bg-ivory-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  flex-shrink: 0;
}
.ft-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Forms */
.ft-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ft-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ft-field.is-full {
  grid-column: 1 / -1;
}

.ft-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--slate-body);
}

.ft-input, .ft-select, .ft-textarea {
  width: 100%;
  border: 1px solid var(--border-slate);
  border-radius: 7px;
  background: #FFFFFF;
  color: var(--slate-dark);
  padding: 6px 9px;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ft-input:focus, .ft-select:focus, .ft-textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 2.5px rgba(27, 54, 93, 0.10);
}
.ft-textarea {
  resize: vertical;
  min-height: 60px;
}

.ft-rel-card {
  background: #FFFFFF;
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 8px;
}
.ft-rel-card:last-child {
  margin-bottom: 0;
}

.ft-rel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ft-link-btn {
  border: none;
  background: transparent;
  padding: 0;
  color: var(--navy);
  font-weight: 600;
  text-align: left;
  font-size: 13px;
}
.ft-link-btn:hover {
  text-decoration: underline;
}

.ft-seg-toggle {
  display: inline-flex;
  border: 1px solid var(--border-gold);
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg-ivory);
}
.ft-seg-btn {
  border: none;
  background: transparent;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--slate-muted);
}
.ft-seg-btn.is-active-married {
  background: var(--navy);
  color: #FFFFFF;
}
.ft-seg-btn.is-active-divorced {
  background: var(--crimson);
  color: #FFFFFF;
}

.ft-inline-form {
  background: #FFFFFF;
  border: 1px dashed var(--border-gold-strong);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ft-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ft-chip {
  border: 1px solid var(--border-gold);
  background: #FFFFFF;
  color: var(--navy);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ft-chip:hover {
  background: var(--navy-tint);
  border-color: var(--navy);
}

/* ==================== MODALS ==================== */
.ft-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ft-modal-backdrop.is-hidden {
  display: none;
}

.ft-modal {
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  background: #FFFFFF;
  border: 1px solid var(--border-gold);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ft-modal.is-narrow {
  max-width: 460px;
}

.ft-modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-gold);
  background: var(--bg-surface-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ft-modal-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.ft-modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ft-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-gold);
  background: var(--bg-surface-soft);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.ft-dropzone {
  border: 2px dashed var(--border-gold-strong);
  border-radius: 12px;
  padding: 26px 18px;
  text-align: center;
  background: var(--bg-surface-soft);
  transition: background-color 0.15s, border-color 0.15s;
}
.ft-dropzone.is-dragover {
  background: var(--gold-tint);
  border-color: var(--navy);
}

.ft-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-gold);
  padding-bottom: 10px;
}
.ft-tab {
  border: 1px solid var(--border-gold);
  background: var(--bg-surface-soft);
  color: var(--slate-body);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}
.ft-tab.is-active {
  background: var(--navy);
  border-color: var(--navy);
  color: #FFFFFF;
}

.ft-match-card {
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--bg-surface-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ft-match-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.ft-match-person {
  background: #FFFFFF;
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 8px 10px;
}

.ft-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
}
.ft-badge-exact {
  background: #DCFCE7;
  color: #166534;
}
.ft-badge-high {
  background: var(--gold-tint);
  color: #7D5E24;
  border: 1px solid var(--border-gold-strong);
}
.ft-badge-medium {
  background: var(--navy-tint);
  color: var(--navy);
}
.ft-badge-low {
  background: #F1F5F9;
  color: var(--slate-muted);
}

.ft-banner-info {
  background: var(--navy-tint);
  border: 1px solid #C5D5EA;
  color: var(--navy);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
}

.ft-banner-warn {
  background: var(--gold-tint);
  border: 1px solid var(--border-gold-strong);
  color: #6B4E1B;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
}

/* ==================== TOAST ==================== */
.ft-toast {
  position: fixed;
  bottom: 22px;
  left: 22px;
  z-index: 95;
  background: var(--navy);
  color: #FFFFFF;
  padding: 9px 15px;
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  font-weight: 500;
  border-left: 3.5px solid var(--gold-bright);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.ft-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==================== PRINT STYLES ==================== */
@media print {
  @page {
    size: landscape;
    margin: 10mm;
  }
  html, body, #app-root, .ft-workspace, .ft-canvas-viewport {
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    background: #FFFFFF !important;
  }
  .ft-toolbar,
  .ft-zoom-controls,
  .ft-lineage-pill,
  .ft-drawer,
  .ft-modal-backdrop,
  .ft-toast,
  .ft-legend-toggle {
    display: none !important;
  }
  .ft-canvas-stage {
    position: relative !important;
    transform: none !important;
  }
  .ft-gen-rail {
    position: absolute !important;
    background: transparent !important;
  }
  .ft-card, .ft-card-unknown {
    box-shadow: none !important;
    break-inside: avoid;
  }
}


/* ==================== PHASE 2: ARCHIVE, TIMELINE & BADGES ==================== */
.ft-doc-badge {
  position: absolute;
  top: 8px;
  right: 7px;
  font-size: 10px;
  font-weight: 700;
  background: var(--gold-tint);
  border: 1px solid var(--border-gold-strong);
  color: #7D5E24;
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.3;
}

.ft-modal-wide {
  max-width: 960px;
  height: 84vh;
}

.ft-archive-grid {
  display: grid;
  grid-template-columns: 275px 1fr;
  gap: 14px;
  min-height: 0;
  flex: 1;
}

.ft-archive-list {
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  background: var(--bg-surface-soft);
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ft-doc-item {
  width: 100%;
  border: 1px solid transparent;
  background: #FFFFFF;
  border-radius: 8px;
  padding: 9px 10px;
  text-align: left;
  transition: border-color 0.15s, background-color 0.15s;
}
.ft-doc-item:hover {
  border-color: var(--border-gold-strong);
}
.ft-doc-item.is-active {
  border-color: var(--navy);
  background: var(--navy-tint);
}
.ft-doc-item-title {
  font-weight: 700;
  color: var(--slate-dark);
  font-size: 12.5px;
  margin-bottom: 4px;
}
.ft-doc-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--slate-muted);
}

.ft-archive-pane {
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  background: #FFFFFF;
  overflow-y: auto;
  padding: 16px;
}

.ft-doc-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ft-doc-img-wrap {
  background: var(--bg-ivory);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.ft-doc-img {
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 6px;
  cursor: zoom-in;
  box-shadow: var(--shadow-sm);
}

.ft-lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(10, 15, 28, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.ft-lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.ft-lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
}

.ft-person-picker {
  max-height: 150px;
  overflow-y: auto;
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 5px;
  background: var(--bg-surface-soft);
}
.ft-picker-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  cursor: pointer;
}

/* Interactive Historical Timeline Bar */
.ft-timeline-bar {
  position: absolute;
  left: 146px;
  right: 256px;
  bottom: 16px;
  z-index: 24;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-gold-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ft-timeline-bar.is-hidden {
  display: none;
}

.ft-tl-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ft-tl-track {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.ft-tl-node {
  flex: 0 0 auto;
  min-width: 155px;
  max-width: 210px;
  border: 1px solid var(--border-gold);
  border-top: 3px solid var(--gold);
  background: var(--bg-surface-soft);
  border-radius: 8px;
  padding: 6px 9px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.15s, background-color 0.15s;
}
.ft-tl-node:hover {
  border-color: var(--navy);
  background: #FFFFFF;
}
.ft-tl-node.is-active {
  border-color: var(--navy);
  border-top-color: var(--crimson);
  background: var(--navy-tint);
}
.ft-tl-year {
  font-weight: 700;
  color: var(--navy);
  font-size: 13px;
}
.ft-tl-dynasty {
  font-size: 10.5px;
  color: #7D5E24;
  font-weight: 600;
}
.ft-tl-title {
  font-size: 11.5px;
  color: var(--slate-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-tl-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(229, 220, 200, 0.8);
  padding-top: 7px;
}

@media (max-width: 820px) {
  .ft-archive-grid {
    grid-template-columns: 1fr;
  }
  .ft-timeline-bar {
    left: 12px;
    right: 12px;
    bottom: 62px;
  }
}


/* ==================== PHASE 4: ELDERLY-FRIENDLY, PHOTO TAGGING & MOBILE ==================== */
.ft-btn-save {
  background: #1B6B46;
  border-color: #16593A;
  color: #FFFFFF;
  font-weight: 700;
}
.ft-btn-save:hover:not(:disabled) {
  background: #155839;
  border-color: #11472E;
}
.ft-btn-save.is-dirty {
  box-shadow: 0 0 0 3px rgba(27, 107, 70, 0.25);
}

.ft-drawer-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-gold);
  background: #FFFFFF;
  flex-shrink: 0;
}

.ft-input, .ft-select, .ft-textarea {
  min-height: 40px;
  font-size: 14.5px;
}

/* Personal photo gallery inside EditDrawer */
.ft-person-photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ft-person-photo-thumb {
  border: 1px solid var(--border-gold);
  background: #FFFFFF;
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ft-person-photo-thumb:hover {
  border-color: var(--navy);
  box-shadow: var(--shadow-sm);
}
.ft-person-photo-thumb img {
  width: 100%;
  height: 92px;
  object-fit: cover;
  display: block;
}
.ft-thumb-cap {
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--slate-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Photo Tagging Stage & Pins */
.ft-tag-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
.ft-tag-stage.is-tagging .ft-doc-img {
  cursor: crosshair;
  outline: 2.5px dashed var(--gold-bright);
  outline-offset: 2px;
}

.ft-photo-pin {
  position: absolute;
  transform: translate(-50%, -18%);
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}

.ft-pin-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.ft-pin-label {
  border: 1px solid var(--gold-bright);
  background: rgba(27, 54, 93, 0.92);
  color: #FFFDF7;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.ft-pin-label:hover {
  background: var(--navy);
  border-color: #FFFFFF;
}

.ft-pin-del {
  border: 1px solid #FFFFFF;
  background: var(--crimson);
  color: #FFFFFF;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.ft-tag-picker {
  position: absolute;
  transform: translate(-50%, -10%);
  z-index: 25;
  width: 230px;
  max-width: 85vw;
  background: #FFFFFF;
  border: 1.5px solid var(--navy);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 10px;
  line-height: 1.35;
  text-align: left;
}

.ft-tag-picker-list {
  max-height: 165px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ft-tag-pick-btn {
  width: 100%;
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  text-align: left;
  color: var(--slate-dark);
}
.ft-tag-pick-btn:hover {
  background: var(--navy-tint);
}

/* ==================== MOBILE & TABLET RESPONSIVENESS ==================== */
@media (max-width: 960px) {
  .ft-toolbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }
  .ft-brand {
    flex: 1 1 100%;
  }
  .ft-title-input {
    max-width: 76vw;
    width: auto;
  }
  .ft-search-wrap {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }
  .ft-actions {
    order: 2;
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .ft-drawer {
    top: 0;
    width: 100vw;
    max-width: 100vw;
    z-index: 75;
  }
}

@media (max-width: 640px) {
  .ft-subtitle #ft-sub-hint {
    display: none;
  }
  .ft-seal {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }
  .ft-title-input {
    font-size: 14.5px;
  }
  .ft-btn {
    min-height: 38px;
    padding: 0 9px;
    font-size: 12px;
  }
  .ft-gen-rail {
    width: 96px;
  }
  .ft-gen-pill {
    left: 6px;
    padding: 3px 6px;
    max-width: 88px;
  }
  .ft-gen-pill-zh {
    font-size: 11.5px;
  }
  .ft-gen-pill-en {
    font-size: 9px;
  }
  .ft-zoom-controls {
    bottom: 10px;
    right: 10px;
  }
  .ft-lineage-pill {
    bottom: 58px;
    max-width: 94vw;
    overflow-x: auto;
  }
  .ft-modal-wide {
    height: 92vh;
  }
  .ft-archive-list {
    max-height: 150px;
  }
}
