/* Google Fonts loaded via <link> in HTML for non-blocking preload */

:root {
  /* Default fonts — system-first stack, web fonts layer on top when ready */
  --font-title: 'ZCOOL XiaoWei', 'Noto Serif SC', 'Source Han Serif SC', 'Source Han Serif CN', 'PingFang SC', 'Hiragino Sans GB', 'STSong', 'SimSun', 'Microsoft YaHei', serif;
  --font-body: 'Noto Serif SC', 'Source Han Serif SC', 'Source Han Serif CN', 'PingFang SC', 'Hiragino Sans GB', 'STSong', 'SimSun', 'Microsoft YaHei', serif;
  
  /* Default colors (red-gold theme) */
  --color-primary: #8B2500;
  --color-primary-dark: #5C1A00;
  --color-primary-light: #C75B39;
  --color-gold: #D4A017;
  --color-gold-light: #F0D58C;
  --color-cream: #FFF8EE;
  --color-parchment: #F5E6D3;
  --color-ink: #2C1810;
  --color-ink-light: #5C4033;
  --color-border: #C4A882;
  --color-shadow: rgba(44, 24, 16, 0.15);
  
  /* Dimension and spacing */
  --sidebar-width: 304px;
  --sidebar-resizer-width: 18px;
  --drawer-width: 380px;
  --header-height: 72px;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

  /* Derived alpha colors for subtle backgrounds/borders */
  --color-primary-alpha-06: rgba(139, 37, 0, 0.06);
  --color-primary-alpha-08: rgba(139, 37, 0, 0.08);
  --color-primary-alpha-10: rgba(139, 37, 0, 0.1);
  --color-primary-alpha-14: rgba(139, 37, 0, 0.14);
  --color-primary-alpha-40: rgba(139, 37, 0, 0.40);
  --color-ink-alpha-66: rgba(44, 24, 16, 0.66);
  --color-cream-alpha-88: rgba(255, 248, 238, 0.88);
  --color-cream-alpha-82: rgba(255, 248, 238, 0.82);
  --color-cream-alpha-98: rgba(255, 248, 238, 0.98);
  --color-border-alpha-45: rgba(196, 168, 130, 0.45);
  --color-border-alpha-28: rgba(196, 168, 130, 0.28);
  --color-border-alpha-32: rgba(196, 168, 130, 0.32);
  --color-border-alpha-50: rgba(196, 168, 130, 0.50);
  --color-shadow-dark: rgba(44, 24, 16, 0.18);
  --color-shadow-light: rgba(44, 24, 16, 0.10);
  --color-shadow-hover: rgba(44, 24, 16, 0.08);
}

/* ===== Header Settings (Theme & Font) ===== */
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  font-size: 15px;
  transition: var(--transition-fast);
}

.header-settings-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.header-settings-btn.is-open {
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
}

.settings-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 14px 16px;
  background: var(--color-cream);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
  z-index: 3100;
}

.settings-dropdown.active {
  display: block;
}

.settings-section + .settings-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.settings-section-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--color-ink-light);
  margin-bottom: 8px;
}

.settings-theme-grid {
  display: flex;
  gap: 8px;
}

.settings-theme-option {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: var(--transition-fast);
  flex-shrink: 0;
}

.settings-theme-option:hover {
  transform: scale(1.12);
}

.settings-theme-option.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}

.settings-theme-option.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.settings-font-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-font-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  color: var(--color-ink);
}

.settings-font-option:hover {
  background: rgba(0, 0, 0, 0.04);
}

.settings-font-option.active {
  background: rgba(var(--color-primary-rgb, 139, 37, 0), 0.08);
  border-color: rgba(var(--color-primary-rgb, 139, 37, 0), 0.2);
  font-weight: 600;
}

.settings-font-option .font-preview {
  font-size: 16px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.settings-font-option .font-label {
  flex: 1;
}

.settings-font-option .font-check {
  opacity: 0;
  font-size: 12px;
  color: var(--color-primary);
}

.settings-font-option.active .font-check {
  opacity: 1;
}

/* Font Classes — system-first fallback, web fonts override when loaded */
.font-serif-sc { font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Source Han Serif CN', 'PingFang SC', 'Hiragino Sans GB', 'STSong', 'SimSun', 'Microsoft YaHei', serif; }
.font-sans-sc { font-family: 'Noto Sans SC', 'Source Han Sans SC', 'Source Han Sans CN', 'PingFang SC', 'Hiragino Sans GB', 'STHeiti', 'Microsoft YaHei', sans-serif; }
.font-title { font-family: 'ZCOOL XiaoWei', 'Noto Serif SC', 'Source Han Serif SC', 'PingFang SC', 'STSong', 'SimSun', 'Microsoft YaHei', serif; }
.font-traditional { font-family: 'Noto Serif Traditional Chinese', 'Noto Serif SC', 'Source Han Serif SC', 'PingFang TC', 'PingFang SC', 'STSong', 'SimSun', 'Microsoft YaHei', serif; }

/* Themes — override :root --color-* variables for full coverage */
.theme-red-gold {
  --color-primary: #8B2500;
  --color-primary-dark: #5C1A00;
  --color-primary-light: #C75B39;
  --color-gold: #D4A017;
  --color-gold-light: #F0D58C;
  --color-cream: #FFF8EE;
  --color-parchment: #F5E6D3;
  --color-ink: #2C1810;
  --color-ink-light: #5C4033;
  --color-border: #C4A882;
  --color-shadow: rgba(44, 24, 16, 0.15);
  --theme-primary: #8B2500;
  --theme-primary-dark: #5C1A00;
  --theme-primary-light: #C75B39;
  --theme-gold: #D4A017;
  --theme-gold-light: #F0D58C;
  --theme-cream: #FFF8EE;
  --theme-parchment: #F5E6D3;
  --theme-ink: #2C1810;
  --theme-ink-light: #5C4033;
  --theme-border: #C4A882;
  --color-primary-alpha-06: rgba(139, 37, 0, 0.06);
  --color-primary-alpha-08: rgba(139, 37, 0, 0.08);
  --color-primary-alpha-10: rgba(139, 37, 0, 0.1);
  --color-primary-alpha-14: rgba(139, 37, 0, 0.14);
  --color-primary-alpha-40: rgba(139, 37, 0, 0.40);
  --color-ink-alpha-66: rgba(44, 24, 16, 0.66);
  --color-cream-alpha-88: rgba(255, 248, 238, 0.88);
  --color-cream-alpha-82: rgba(255, 248, 238, 0.82);
  --color-cream-alpha-98: rgba(255, 248, 238, 0.98);
  --color-border-alpha-45: rgba(196, 168, 130, 0.45);
  --color-border-alpha-28: rgba(196, 168, 130, 0.28);
  --color-border-alpha-32: rgba(196, 168, 130, 0.32);
  --color-border-alpha-50: rgba(196, 168, 130, 0.50);
  --color-shadow-dark: rgba(44, 24, 16, 0.18);
  --color-shadow-light: rgba(44, 24, 16, 0.10);
  --color-shadow-hover: rgba(44, 24, 16, 0.08);
}
.theme-blue-green {
  --color-primary: #006666;
  --color-primary-dark: #004040;
  --color-primary-light: #2E8B57;
  --color-gold: #CDB79E;
  --color-gold-light: #DEB887;
  --color-cream: #FDF6E3;
  --color-parchment: #F0EAD6;
  --color-ink: #2F4F4F;
  --color-ink-light: #5F9EA0;
  --color-border: #A8C686;
  --color-shadow: rgba(47, 79, 79, 0.15);
  --theme-primary: #006666;
  --theme-primary-dark: #004040;
  --theme-primary-light: #2E8B57;
  --theme-gold: #CDB79E;
  --theme-gold-light: #DEB887;
  --theme-cream: #FDF6E3;
  --theme-parchment: #F0EAD6;
  --theme-ink: #2F4F4F;
  --theme-ink-light: #5F9EA0;
  --theme-border: #A8C686;
  --theme-background: linear-gradient(180deg, #f0f4f3 0%, var(--theme-parchment) 100%);
  --color-primary-alpha-06: rgba(0, 102, 102, 0.06);
  --color-primary-alpha-08: rgba(0, 102, 102, 0.08);
  --color-primary-alpha-10: rgba(0, 102, 102, 0.1);
  --color-primary-alpha-14: rgba(0, 102, 102, 0.14);
  --color-primary-alpha-40: rgba(0, 102, 102, 0.40);
  --color-ink-alpha-66: rgba(47, 79, 79, 0.66);
  --color-cream-alpha-88: rgba(253, 246, 227, 0.88);
  --color-cream-alpha-82: rgba(253, 246, 227, 0.82);
  --color-cream-alpha-98: rgba(253, 246, 227, 0.98);
  --color-border-alpha-45: rgba(168, 198, 134, 0.45);
  --color-border-alpha-28: rgba(168, 198, 134, 0.28);
  --color-border-alpha-32: rgba(168, 198, 134, 0.32);
  --color-border-alpha-50: rgba(168, 198, 134, 0.50);
  --color-shadow-dark: rgba(47, 79, 79, 0.18);
  --color-shadow-light: rgba(47, 79, 79, 0.10);
  --color-shadow-hover: rgba(47, 79, 79, 0.08);
}
.theme-ink-wash {
  --color-primary: #555555;
  --color-primary-dark: #222222;
  --color-primary-light: #888888;
  --color-gold: #8B7355;
  --color-gold-light: #C4B89A;
  --color-cream: #FEFCF7;
  --color-parchment: #FAF7F0;
  --color-ink: #333333;
  --color-ink-light: #777777;
  --color-border: #D0C4B1;
  --color-shadow: rgba(51, 51, 51, 0.12);
  --theme-primary: #555555;
  --theme-primary-dark: #222222;
  --theme-primary-light: #888888;
  --theme-gold: #8B7355;
  --theme-gold-light: #C4B89A;
  --theme-cream: #FEFCF7;
  --theme-parchment: #FAF7F0;
  --theme-ink: #333333;
  --theme-ink-light: #777777;
  --theme-border: #D0C4B1;
  --theme-background: linear-gradient(180deg, #fdfdfe 0%, var(--theme-parchment) 100%);
  --color-primary-alpha-06: rgba(85, 85, 85, 0.06);
  --color-primary-alpha-08: rgba(85, 85, 85, 0.08);
  --color-primary-alpha-10: rgba(85, 85, 85, 0.1);
  --color-primary-alpha-14: rgba(85, 85, 85, 0.14);
  --color-primary-alpha-40: rgba(85, 85, 85, 0.40);
  --color-ink-alpha-66: rgba(51, 51, 51, 0.66);
  --color-cream-alpha-88: rgba(254, 252, 247, 0.88);
  --color-cream-alpha-82: rgba(254, 252, 247, 0.82);
  --color-cream-alpha-98: rgba(254, 252, 247, 0.98);
  --color-border-alpha-45: rgba(208, 196, 177, 0.45);
  --color-border-alpha-28: rgba(208, 196, 177, 0.28);
  --color-border-alpha-32: rgba(208, 196, 177, 0.32);
  --color-border-alpha-50: rgba(208, 196, 177, 0.50);
  --color-shadow-dark: rgba(51, 51, 51, 0.18);
  --color-shadow-light: rgba(51, 51, 51, 0.10);
  --color-shadow-hover: rgba(51, 51, 51, 0.08);
}
.theme-purple-gold {
  --color-primary: #663399;
  --color-primary-dark: #4B0082;
  --color-primary-light: #9370D8;
  --color-gold: #FFD700;
  --color-gold-light: #F0E68C;
  --color-cream: #FEF7FF;
  --color-parchment: #FBF3FC;
  --color-ink: #4B0082;
  --color-ink-light: #7B52AB;
  --color-border: #D8BFD8;
  --color-shadow: rgba(75, 0, 130, 0.12);
  --theme-primary: #663399;
  --theme-primary-dark: #4B0082;
  --theme-primary-light: #9370D8;
  --theme-gold: #FFD700;
  --theme-gold-light: #F0E68C;
  --theme-cream: #FEF7FF;
  --theme-parchment: #FBF3FC;
  --theme-ink: #4B0082;
  --theme-ink-light: #7B52AB;
  --theme-border: #D8BFD8;
  --theme-background: linear-gradient(180deg, #f5f0fc 0%, var(--theme-parchment) 100%);
  --color-primary-alpha-06: rgba(102, 51, 153, 0.06);
  --color-primary-alpha-08: rgba(102, 51, 153, 0.08);
  --color-primary-alpha-10: rgba(102, 51, 153, 0.1);
  --color-primary-alpha-14: rgba(102, 51, 153, 0.14);
  --color-primary-alpha-40: rgba(102, 51, 153, 0.40);
  --color-ink-alpha-66: rgba(75, 0, 130, 0.66);
  --color-cream-alpha-88: rgba(254, 247, 255, 0.88);
  --color-cream-alpha-82: rgba(254, 247, 255, 0.82);
  --color-cream-alpha-98: rgba(254, 247, 255, 0.98);
  --color-border-alpha-45: rgba(216, 191, 216, 0.45);
  --color-border-alpha-28: rgba(216, 191, 216, 0.28);
  --color-border-alpha-32: rgba(216, 191, 216, 0.32);
  --color-border-alpha-50: rgba(216, 191, 216, 0.50);
  --color-shadow-dark: rgba(75, 0, 130, 0.18);
  --color-shadow-light: rgba(75, 0, 130, 0.10);
  --color-shadow-hover: rgba(75, 0, 130, 0.08);
}

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

html, body {
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--theme-background, linear-gradient(180deg, #f9efe0 0%, var(--color-parchment) 100%));
  color: var(--color-ink);
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

.global-context-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--color-primary-alpha-10);
  background: var(--color-cream-alpha-88);
  position: sticky;
  top: 72px;
  z-index: 18;
  backdrop-filter: blur(4px);
}

.global-context-bar.active {
  display: flex;
}

.context-breadcrumbs,
.context-facets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.context-breadcrumbs {
  flex: 1.2;
}

.context-facets {
  flex: 1.8;
}

.context-crumb,
.context-pill {
  border-radius: 999px;
  border: 1px solid var(--color-primary-alpha-14);
  background: rgba(255,255,255,0.72);
  color: var(--theme-ink, var(--color-ink));
  padding: 6px 12px;
  font-size: 13px;
}

.context-crumb {
  cursor: pointer;
}

.context-crumb.active,
.context-pill {
  background: var(--color-primary-alpha-08);
}

.context-empty {
  color: var(--color-ink-alpha-66);
  font-size: 13px;
}

.context-actions {
  flex-shrink: 0;
}

.list-card-item.is-related,
.knowledge-char-pill.is-related,
.tree-person-card.highlighted {
  box-shadow: 0 0 0 2px rgba(212, 160, 23, 0.45);
}

.list-load-more {
  margin: 14px auto 0;
  display: block;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  background: var(--color-primary-alpha-08);
  color: var(--theme-primary, var(--color-primary));
  cursor: pointer;
}

.card-tag.family {
  appearance: none;
  cursor: pointer;
}

body.theme-red-gold {
  --theme-background: linear-gradient(180deg, #f9efe0 0%, var(--color-parchment) 100%);
}

body.theme-blue-green {
  /* background set via --theme-background in theme variables */
}

body.theme-ink-wash {
  /* background set via --theme-background in theme variables */
}

body.theme-purple-gold {
  /* background set via --theme-background in theme variables */
}

.header {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: linear-gradient(135deg, rgba(92,26,0,0.97), rgba(139,37,0,0.96), rgba(199,91,57,0.93));
  border-bottom: 1px solid rgba(240,213,140,0.4);
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  z-index: 3001;
}

/* Theme-adjusted header */
body.theme-blue-green .header {
  background: linear-gradient(135deg, rgba(0,102,102,0.97), rgba(46,139,87,0.96), rgba(78,161,129,0.93));
  border-bottom: 1px solid rgba(190,218,176,0.4);
}

body.theme-ink-wash .header {
  background: linear-gradient(135deg, rgba(51,51,51,0.97), rgba(102,102,102,0.96), rgba(130,130,130,0.93));
  border-bottom: 1px solid rgba(173,161,133,0.4);
}

body.theme-purple-gold .header {
  background: linear-gradient(135deg, rgba(102,51,153,0.97), rgba(147,112,216,0.96), rgba(201,152,245,0.93));
  border-bottom: 1px solid rgba(240,230,140,0.4);
}

.header-title {
  font-family: var(--font-title);
  color: var(--color-gold-light);
  font-size: 1.55rem;
  letter-spacing: 2px;
}

/* Theme-adjusted header title */
body.theme-red-gold .header-title { color: var(--theme-gold-light); }
body.theme-blue-green .header-title { color: var(--theme-gold-light); }
body.theme-ink-wash .header-title { color: var(--theme-gold-light); }
body.theme-purple-gold .header-title { color: var(--theme-gold-light); }

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.search-box {
  width: min(680px, 100%);
  position: relative;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  color: rgba(255,255,255,0.68);
  z-index: 2;
}

.search-input {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  color: var(--color-cream);
  padding: 12px 18px 12px 42px;
  border-radius: 999px;
  font-size: 0.92rem;
  outline: none;
  transition: var(--transition);
}

.search-input::placeholder {
  color: rgba(255,255,255,0.58);
}

.search-input:focus {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 4px rgba(212,160,23,0.12);
  background: rgba(255,255,255,0.18);
}

.search-results {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  display: none;
  border-radius: 16px;
  border: 1px solid var(--color-border-alpha-50);
  background: var(--color-cream-alpha-98);
  box-shadow: 0 16px 48px var(--color-shadow-dark);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1100;
  overscroll-behavior: contain;
}

.search-results.active {
  display: block;
}

.search-group-title {
  padding: 12px 16px 6px;
  font-size: 0.76rem;
  color: var(--color-primary);
  font-weight: 700;
  letter-spacing: 1px;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 16px;
  cursor: pointer;
  transition: var(--transition);
}

.search-result-item:hover {
  background: var(--color-primary-alpha-06);
}

.search-result-name {
  color: var(--color-primary);
  font-weight: 700;
}

.search-result-info,
.quick-card-meta,
.topic-desc,
.topic-tags,
.tip-item,
.summary-relation-desc,
.card-summary-desc,
.card-description,
.card-source-note,
.card-personality,
.card-identity,
.card-chapter-summary,
.card-alias,
.card-pinyin,
.drawer-description,
.drawer-empty {
  color: var(--color-ink-light);
  font-size: 0.84rem;
  line-height: 1.65;
}

.btn,
.primary-action,
.secondary-action,
.text-action,
.quick-card,
.topic-card,
.family-browser-item,
.recommend-pill,
.summary-relation-item,
.control-btn,
.exit-btn,
.drawer-close {
  font-family: inherit;
}

.btn {
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.12);
  color: var(--color-cream);
  border-radius: 12px;
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

.btn:hover,
.btn.is-active {
  border-color: var(--color-gold);
  background: rgba(255,255,255,0.18);
  color: var(--color-gold-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--color-cream);
  font-size: 1.45rem;
  cursor: pointer;
}

.main-container {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) var(--sidebar-resizer-width) minmax(0, 1fr);
  gap: 0;
  padding: calc(var(--header-height) + 14px) 14px 14px;
  min-height: 100vh;
  z-index: 1;
}

.sidebar,
.card-surface,
.character-card,
.detail-drawer,
.knowledge-hero,
.knowledge-sidebar,
.knowledge-results-head {
  background: var(--color-cream-alpha-82);
  backdrop-filter: blur(14px);
  border: 1px solid var(--color-border-alpha-45);
  box-shadow: 0 14px 40px var(--color-shadow-light);
}

.sidebar {
  border-radius: 24px;
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - var(--header-height) - 28px);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sidebar-resize-handle {
  position: relative;
  width: var(--sidebar-resizer-width);
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}

.sidebar-resize-handle::before {
  content: '';
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(180deg, transparent, var(--color-border-alpha-50), transparent);
  transition: var(--transition-fast);
}

.sidebar-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--color-border-alpha-32);
  box-shadow: 0 8px 18px var(--color-shadow-hover);
  opacity: 0;
  transition: var(--transition-fast);
}

.sidebar-resize-handle:hover::before,
body.sidebar-resizing .sidebar-resize-handle::before {
  background: linear-gradient(180deg, transparent, var(--color-primary-alpha-40), transparent);
}

.sidebar-resize-handle:hover::after,
body.sidebar-resizing .sidebar-resize-handle::after {
  opacity: 1;
}

body.sidebar-resizing,
body.sidebar-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.sidebar-section + .sidebar-section {
  margin-top: 12px;
}

.sidebar-priority-block {
  padding: 12px;
  border-radius: 18px;
  background: rgba(255,255,255,0.44);
  border: 1px solid var(--color-border-alpha-28);
}

.sidebar-section-title,
.detail-drawer-title,
.panel-header h3,
.summary-intro h4,
.card-section-title,
.drawer-title {
  font-family: var(--font-title);
  color: var(--color-primary);
}

.sidebar-section-title {
  font-size: 1rem;
  margin-bottom: 8px;
}

.sidebar-more-tools {
  margin-top: 14px;
  border-radius: 18px;
  border: 1px solid var(--color-border-alpha-32);
  background: rgba(255,255,255,0.34);
  overflow: hidden;
}

.sidebar-more-summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  color: var(--color-primary);
  font-family: var(--font-title);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-more-summary::-webkit-details-marker {
  display: none;
}

.sidebar-more-summary::after {
  content: '收起';
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--color-ink-light);
}

.sidebar-more-tools:not([open]) .sidebar-more-summary::after {
  content: '展开';
}

.sidebar-more-content {
  padding: 0 14px 14px;
}

.sidebar-subsection + .sidebar-subsection {
  margin-top: 12px;
}

.quick-grid,
.topic-list,
.summary-relations,
.tips-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-card,
.topic-card,
.family-browser-item,
.summary-relation-item {
  width: 100%;
  border: 1px solid var(--color-border-alpha-45);
  background: rgba(255,255,255,0.6);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.quick-card:hover,
.topic-card:hover,
.family-browser-item:hover,
.summary-relation-item:hover,
.recommend-pill:hover,
.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px var(--color-shadow-hover);
  border-color: var(--color-primary-alpha-40);
}

.quick-card-name,
.topic-title {
  display: block;
  color: var(--color-primary);
  font-weight: 700;
  margin-bottom: 4px;
}

.family-browser {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.family-browser-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legend-section {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid rgba(196,168,130,0.3);
  background: rgba(255,255,255,0.55);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 4px 0;
}

.legend-line {
  width: 20px;
  height: 3px;
  border-radius: 4px;
  background: currentColor;
}

.legend-dashed {
  height: 0;
  border-top: 2px dashed currentColor;
  background: transparent;
}

.legend-dotted {
  height: 0;
  border-top: 2px dotted currentColor;
  background: transparent;
}

.stats-section {
  border-radius: 14px;
  padding: 12px;
  background: rgba(139,37,0,0.04);
  border: 1px solid rgba(196,168,130,0.3);
}

.stat-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.86rem;
}

.stat-value {
  font-weight: 700;
  color: var(--color-primary);
}

.family-filter,
.relation-filter,
.importance-filter {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.family-filter-item,
.relation-filter-item,
.importance-filter-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.52);
  border: 1px solid var(--color-border-alpha-28);
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.family-filter-item:hover,
.relation-filter-item:hover,
.importance-filter-item:hover {
  background: rgba(255,255,255,0.7);
  border-color: var(--color-border-alpha-50);
}

.family-filter-item.active,
.relation-filter-item.active,
.importance-filter-item.active {
  background: linear-gradient(135deg, var(--color-primary), #a02800);
  color: var(--color-cream);
  border-color: var(--color-primary);
  box-shadow: 0 3px 10px rgba(139,37,0,0.25);
  transform: translateX(3px);
}

.family-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.relation-line-icon {
  width: 24px;
  height: 3px;
  border-radius: 4px;
}

.family-filter-label,
.relation-filter-label,
.importance-filter-label {
  flex: 1;
}

.importance-filter-item {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.importance-filter-desc {
  font-size: 0.75rem;
  color: var(--color-ink-light);
}

.importance-filter-item.active .importance-filter-desc {
  color: rgba(255,248,238,0.82);
}

.family-filter-count,
.relation-filter-count {
  color: var(--color-ink-light);
  font-size: 0.75rem;
}

.custom-checkbox {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(196,168,130,0.75);
  border-radius: 5px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.custom-checkbox.checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.custom-checkbox.checked::after {
  content: '✓';
  color: white;
  font-size: 0.72rem;
}

.compare-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 8px;
}

.sidebar-filter-summary {
  margin-top: 4px;
}

.filter-summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--color-border-alpha-28);
  background: linear-gradient(135deg, rgba(255,255,255,0.74), rgba(248,239,228,0.92));
}

.filter-summary-card.is-filtered {
  border-color: var(--color-primary-alpha-28);
  box-shadow: 0 8px 18px rgba(139,37,0,0.08);
}

.filter-summary-main {
  min-width: 0;
}

.filter-summary-title {
  color: var(--color-primary);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-summary-text {
  margin-top: 4px;
  color: var(--color-text);
  font-size: 0.92rem;
  font-weight: 600;
}

.filter-summary-note {
  margin-top: 4px;
  color: var(--color-ink-light);
  font-size: 0.78rem;
  line-height: 1.5;
}

.filter-summary-state {
  flex-shrink: 0;
  color: var(--color-ink-light);
  font-size: 0.78rem;
  white-space: nowrap;
}

.filter-summary-reset {
  flex-shrink: 0;
  white-space: nowrap;
}

.compare-inputs select {
  width: 100%;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 12px;
  background: rgba(255,255,255,0.72);
  color: var(--color-primary);
  padding: 10px 12px;
  font-family: inherit;
}

.compare-inputs select.is-invalid {
  border-color: rgba(192,57,43,0.72);
  box-shadow: 0 0 0 3px rgba(192,57,43,0.12);
  background: rgba(255,245,243,0.92);
}

.compare-sep {
  color: var(--color-primary);
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-compare-current {
  margin-top: 10px;
}

.content-area,
.graph-stage {
  min-width: 0;
}

.content-area {
  display: flex;
  min-width: 0;
}

.graph-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, var(--drawer-width));
  gap: 12px;
  width: 100%;
  height: calc(100vh - var(--header-height) - 28px);
  min-height: 680px;
}

.graph-stage:has(.desktop-hidden) {
  grid-template-columns: 1fr;
}

.graph-container {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.55), transparent 40%),
    linear-gradient(180deg, rgba(255,248,238,0.76), rgba(245,230,211,0.92));
  border: 1px solid var(--color-border-alpha-45);
  box-shadow: 0 18px 48px rgba(44,24,16,0.12);
  min-height: 100%;
  height: 100%;
}

.graph-container.view-updated {
  box-shadow: 0 0 0 2px rgba(212,160,23,0.45), 0 18px 42px rgba(44,24,16,0.14);
}

.graph-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(125deg, rgba(255,255,255,0.06), transparent 28%),
    radial-gradient(circle at 22% 18%, rgba(212,160,23,0.08), transparent 22%),
    radial-gradient(circle at 80% 80%, var(--color-primary-alpha-08), transparent 28%);
  pointer-events: none;
}

.graph-container svg {
  width: 100%;
  height: 100%;
  cursor: grab;
}

.graph-container svg:active {
  cursor: grabbing;
}

.detail-drawer {
  border-radius: var(--radius-xl);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.detail-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--color-border-alpha-28);
}

.detail-drawer-title {
  font-size: 1.28rem;
}

.drawer-eyebrow,
.summary-badge,
.card-tag-soft,
.insight-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  background: var(--color-primary-alpha-08);
  color: var(--color-primary);
}

.summary-badge.subtle {
  background: rgba(92,26,0,0.06);
  color: var(--color-ink-light);
}

.drawer-close {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--color-border-alpha-32);
  background: rgba(255,255,255,0.62);
  color: var(--color-primary);
  cursor: pointer;
}

.detail-drawer-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-hero-panel {
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(255,255,255,0.62), rgba(245,230,211,0.64));
  border: 1px solid rgba(196,168,130,0.24);
}

.drawer-title {
  font-size: 1.5rem;
  line-height: 1.35;
}

.drawer-section-title,
.summary-section-title {
  color: var(--color-primary);
  font-weight: 700;
}

.summary-topline,
.recommend-list,
.insight-tags,
.drawer-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-relation-head,
.card-summary-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 5px;
}

.summary-relation-head strong,
.card-summary-head strong,
.card-relation-name {
  color: var(--color-primary);
}

.summary-relation-head em,
.card-summary-type,
.card-relation-label {
  font-style: normal;
  font-size: 0.76rem;
  color: var(--color-ink-light);
}

.summary-relation-item.static-item {
  cursor: default;
}

.recommend-pill,
.primary-action,
.secondary-action,
.text-action,
.exit-btn,
.control-btn {
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.primary-action,
.secondary-action,
.recommend-pill {
  border-radius: 999px;
  padding: 10px 14px;
}

.primary-action {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  color: var(--color-cream);
  box-shadow: 0 10px 22px rgba(139,37,0,0.18);
}

.secondary-action {
  background: var(--color-primary-alpha-08);
  color: var(--color-primary);
}

.text-action {
  background: transparent;
  color: var(--color-primary);
  font-weight: 700;
}

.recommend-pill {
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(196,168,130,0.42);
  color: var(--color-primary);
}

.primary-action:disabled,
.secondary-action:disabled,
.text-action:disabled,
.exit-btn:disabled,
.control-btn:disabled,
.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  pointer-events: none;
}

.controls-panel {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}

.control-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(196,168,130,0.42);
  background: rgba(255,248,238,0.92);
  color: var(--color-primary);
  font-size: 1.05rem;
}

.control-btn:hover,
.control-btn.active {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  color: var(--color-gold-light);
}

.mode-indicator {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  background: rgba(92,26,0,0.92);
  color: var(--color-gold-light);
  border: 1px solid rgba(212,160,23,0.45);
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 50;
}

.mode-indicator.active {
  display: flex;
}

.exit-btn {
  background: rgba(255,255,255,0.14);
  color: var(--color-cream);
  border-radius: 999px;
  padding: 6px 10px;
}

.graph-floating-bar {
  position: absolute;
  left: 18px;
  top: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(255,248,238,0.95);
  border: 1px solid rgba(196,168,130,0.4);
  box-shadow: 0 8px 24px rgba(44,24,16,0.16);
  z-index: 70;
}

.graph-floating-bar.active {
  padding: 16px 20px;
  background: var(--color-cream-alpha-98);
  box-shadow: 0 12px 32px rgba(44,24,16,0.22);
}

.graph-search-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 600px;
}

.graph-search-box {
  position: relative;
  flex: 1;
}

.graph-search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  color: rgba(92,26,0,0.5);
  font-size: 0.95rem;
}

.graph-search-input {
  width: 100%;
  border: 1px solid var(--color-border-alpha-50);
  background: rgba(255,255,255,0.85);
  color: var(--color-primary);
  padding: 10px 14px 10px 38px;
  border-radius: 12px;
  font-size: 0.92rem;
  outline: none;
  transition: var(--transition);
}

.graph-search-input::placeholder {
  color: rgba(92,26,0,0.45);
}

.graph-search-input:focus {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.15);
  background: rgba(255,255,255,0.95);
}

.graph-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 380px;
  overflow-y: auto;
  border-radius: 12px;
  background: var(--color-cream-alpha-98);
  border: 1px solid rgba(196,168,130,0.4);
  box-shadow: 0 12px 32px var(--color-shadow-dark);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.graph-search-results.active {
  opacity: 1;
  visibility: visible;
}

.graph-action-btn {
  border: 1px solid var(--color-border-alpha-50);
  background: rgba(255,255,255,0.8);
  color: var(--color-primary);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.graph-action-btn:hover {
  background: rgba(255,255,255,0.95);
  border-color: var(--color-gold);
}

.graph-action-btn.hidden {
  display: none;
}

.graph-floating-info {
  display: flex;
  align-items: center;
}

.graph-floating-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.graph-floating-label {
  color: var(--color-primary);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.node-group {
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.node-group.dimmed {
  opacity: 0.1;
}

.node-group.highlighted {
  opacity: 1;
}

.node-circle {
  stroke: rgba(255,255,255,0.9);
  stroke-width: 2px;
  transition: stroke-width 0.2s ease;
}

.node-group:hover .node-circle {
  stroke-width: 3px;
}

.node-circle.selected {
  stroke: var(--color-gold);
  stroke-width: 4px;
}

.node-label {
  font-size: 11px;
  fill: var(--color-ink);
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  text-shadow:
    -1px -1px 0 rgba(255,248,238,0.95),
    1px -1px 0 rgba(255,248,238,0.95),
    -1px 1px 0 rgba(255,248,238,0.95),
    1px 1px 0 rgba(255,248,238,0.95);
}

.node-label.importance-5 { font-size: 13px; }
.node-label.importance-4 { font-size: 12px; }

.link-line {
  opacity: 0.38;
  transition: opacity 0.25s ease, stroke-width 0.25s ease;
}

.link-line.dimmed {
  opacity: 0.06;
}

.link-line.highlighted {
  opacity: 0.88;
  stroke-width: 3px !important;
}

.link-label {
  font-size: 9px;
  fill: var(--color-ink-light);
  text-anchor: middle;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.link-label.visible {
  opacity: 1;
}

.character-card-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: rgba(44,24,16,0.42);
  backdrop-filter: blur(6px);
  padding: calc(var(--header-height) + 18px) 16px 24px;
  overflow-y: auto;
  z-index: 4000;
}

.character-card-overlay.active {
  display: flex;
}

.character-card {
  position: relative;
  width: min(760px, 92vw);
  max-height: calc(100vh - var(--header-height) - 42px);
  border-radius: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.card-close-btn {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary-alpha-08);
  color: var(--color-primary);
  font-size: 1.15rem;
  cursor: pointer;
  z-index: 2;
}

.card-header {
  display: flex;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid rgba(196,168,130,0.3);
}

.card-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
  border: 3px solid rgba(255,255,255,0.85);
  box-shadow: 0 10px 22px rgba(44,24,16,0.16);
}

.card-avatar-text,
.card-name,
.card-chapter-number,
.card-chapter-title {
  font-family: var(--font-title);
}

.card-name {
  font-size: 1.6rem;
  color: var(--color-primary);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.card-tag {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.card-tag.gender-male {
  background: rgba(41,128,185,0.1);
  color: #2980B9;
}

.card-tag.gender-female {
  background: rgba(233,30,140,0.1);
  color: #E91E8C;
}

.card-body {
  padding: 22px 24px 26px;
}

.card-section + .card-section {
  margin-top: 16px;
}

.card-highlight-box {
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(135deg, var(--color-primary-alpha-06), rgba(212,160,23,0.08));
  border: 1px solid rgba(196,168,130,0.35);
}

.card-summary-list,
.card-relations,
.card-chapters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-summary-item,
.card-relation-item,
.card-chapter-item,
.card-quote {
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.68);
  border: 1px solid rgba(196,168,130,0.26);
}

.card-summary-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.card-summary-type,
.card-relation-type {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  color: white;
  padding: 4px 10px;
  font-size: 0.72rem;
}

.card-events {
  list-style: none;
  display: grid;
  gap: 8px;
}

.card-events li {
  padding-left: 16px;
  position: relative;
  color: var(--color-ink-light);
  line-height: 1.7;
}

.card-events li::before {
  content: '◇';
  position: absolute;
  left: 0;
  color: var(--color-gold);
}

.card-quote {
  font-style: italic;
  line-height: 1.8;
}

.card-chapter-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.card-chapter-number {
  font-size: 0.76rem;
  color: white;
  background: var(--color-primary);
  padding: 4px 8px;
  border-radius: 999px;
}

.card-chapter-title {
  color: var(--color-primary);
  font-size: 0.88rem;
}

.card-relations .card-relation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.card-relation-label {
  margin-left: auto;
}

.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(44,24,16,0.92);
  color: var(--color-cream);
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1600;
  max-width: 220px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
  will-change: transform;
}

.tooltip.visible {
  opacity: 1;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fbf3e4 0%, #f4e4cb 100%);
  z-index: 9999;
  transition: opacity 0.4s ease;
}

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

.loading-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 2.1rem;
  letter-spacing: 6px;
  margin-bottom: 8px;
}

.loading-subtitle {
  color: var(--color-ink-light);
  font-size: 0.92rem;
  margin-bottom: 24px;
}

.loading-spinner {
  width: 46px;
  height: 46px;
  border: 3px solid var(--color-border-alpha-45);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-thumb {
  background: rgba(139,37,0,0.3);
  border-radius: 999px;
}

.sidebar-backdrop {
  display: none;
}

body.fullscreen {
  overflow: hidden;
}

body.fullscreen .header,
body.fullscreen .sidebar,
body.fullscreen .sidebar-backdrop,
body.fullscreen .detail-drawer {
  display: none !important;
}

body.fullscreen .main-container {
  grid-template-columns: 1fr;
  padding: 0;
  gap: 0;
}

body.fullscreen .graph-stage {
  height: 100vh;
  min-height: 100vh;
  grid-template-columns: 1fr;
  gap: 0;
}

body.fullscreen .graph-container {
  position: fixed;
  inset: 0;
  border-radius: 0;
  z-index: 1500;
}

body.fullscreen .controls-panel {
  bottom: 24px;
  right: 24px;
}

body.fullscreen .graph-floating-bar {
  display: flex;
}

@media (max-width: 1180px) {
  .graph-stage {
    grid-template-columns: 1fr 340px;
  }
}

@media (max-width: 1024px) {
  .main-container {
    grid-template-columns: 1fr;
  }

  .sidebar-resize-handle {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: calc(var(--header-height) + 8px);
    left: 8px;
    bottom: 8px;
    width: min(88vw, var(--sidebar-width));
    transform: translateX(calc(-100% - 20px));
    transition: transform 0.28s ease;
    z-index: 900;
  }

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

  .sidebar-backdrop {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(0,0,0,0.25);
    z-index: 800;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .btn-sidebar-toggle {
    display: block;
  }

  .graph-stage {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - var(--header-height) - 28px);
  }

  .graph-container {
    min-height: 58vh;
  }

  .detail-drawer {
    position: fixed;
    top: calc(var(--header-height) + 8px);
    right: 8px;
    bottom: 8px;
    width: min(92vw, 400px);
    transform: translateX(calc(100% + 24px));
    transition: transform 0.28s ease;
    z-index: 950;
  }

  .detail-drawer.active {
    transform: translateX(0);
  }
}

@media (min-width: 1025px) {
  .detail-drawer {
    transform: translateX(0);
  }

  .detail-drawer.desktop-hidden {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  .header {
    padding: 0 12px;
    gap: 10px;
  }

  .header-title {
    font-size: 1.1rem;
    letter-spacing: 1px;
  }

  .header-subtitle {
    display: none;
  }

  .header-settings-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }

  .settings-dropdown {
    right: -8px;
    min-width: 200px;
    padding: 12px 14px;
  }

  .search-input {
    font-size: 0.86rem;
    padding: 10px 16px 10px 38px;
  }

  .main-container {
    padding: calc(var(--header-height) + 8px) 8px 8px;
    gap: 8px;
  }

  .graph-container {
    border-radius: 18px;
    min-height: 55vh;
  }

  .compare-inputs,
  .compare-inputs-sidebar {
    grid-template-columns: 1fr;
  }

  .compare-sep {
    display: none;
  }

  .family-browser {
    grid-template-columns: 1fr;
  }

  .detail-drawer {
    width: calc(100vw - 16px);
    right: 8px;
    left: 8px;
    bottom: 8px;
    top: calc(var(--header-height) + 8px);
  }

  .character-card {
    width: 96vw;
    max-height: 92vh;
    border-radius: 18px;
  }

  .card-header {
    padding: 16px;
    gap: 12px;
  }

  .card-body {
    padding: 14px 16px 20px;
  }

  .card-avatar {
    width: 64px;
    height: 64px;
    font-size: 1.6rem;
  }

  .card-name {
    font-size: 1.3rem;
  }

  .controls-panel {
    right: 12px;
    bottom: 12px;
    gap: 6px;
  }

  .control-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 0.95rem;
  }

  .mode-indicator {
    top: 10px;
    padding: 6px 12px;
    font-size: 0.85rem;
  }

  .sidebar {
    top: calc(var(--header-height) + 6px);
    left: 6px;
    bottom: 6px;
  }

  .sidebar-section-title {
    font-size: 0.92rem;
  }

  .quick-card,
  .topic-card,
  .family-browser-item,
  .summary-relation-item {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .drawer-hero-panel {
    padding: 12px;
    border-radius: 16px;
  }

  .drawer-title {
    font-size: 1.25rem;
  }

  .detail-drawer-title {
    font-size: 1.1rem;
  }

  .primary-action,
  .secondary-action,
  .recommend-pill {
    padding: 8px 12px;
    font-size: 0.86rem;
  }

  .search-results {
    border-radius: 12px;
    max-height: 260px;
  }

  .search-result-item {
    padding: 10px 14px;
  }
}

@media (max-width: 560px) {
  :root {
    --header-height: 52px;
  }

  .header-center {
    display: none;
  }

  .main-container {
    padding: calc(var(--header-height) + 6px) 6px 6px;
    gap: 6px;
  }

  .graph-container {
    min-height: 52vh;
    border-radius: 14px;
  }

  .controls-panel {
    right: 10px;
    bottom: 10px;
  }

  .control-btn {
    width: 38px;
    height: 38px;
  }

  .detail-drawer {
    width: calc(100vw - 12px);
    left: 6px;
    right: 6px;
    bottom: 6px;
    top: calc(var(--header-height) + 6px);
    border-radius: 18px;
  }

  .character-card {
    width: 98vw;
    max-height: 94vh;
    border-radius: 16px;
  }

  .card-header {
    padding: 14px;
    gap: 10px;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .card-tags {
    justify-content: center;
  }

  .card-body {
    padding: 12px 14px 18px;
  }

  .card-avatar {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
  }

  .card-name {
    font-size: 1.2rem;
  }

  .card-section-title {
    font-size: 0.92rem;
  }

  .sidebar {
    width: calc(100vw - 16px);
    left: 6px;
    right: 6px;
    top: calc(var(--header-height) + 6px);
    bottom: 6px;
  }

  .drawer-actions-row {
    flex-direction: column;
  }

  .drawer-actions-row .primary-action,
  .drawer-actions-row .secondary-action {
    width: 100%;
    text-align: center;
  }
}

.btn-back.hidden {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

/* Touch-friendly targets */
@media (pointer: coarse) {
  .quick-card,
  .topic-card,
  .family-browser-item,
  .summary-relation-item,
  .family-filter-item,
  .relation-filter-item,
  .importance-filter-item {
    min-height: 44px;
  }

  .control-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .btn,
  .drawer-close,
  .card-close-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .recommend-pill,
  .primary-action,
  .secondary-action {
    min-height: 44px;
  }

  .search-result-item {
    min-height: 48px;
  }

  .card-relation-item {
    min-height: 44px;
  }
}

/* ============================================================
   View Navigation Tabs
   ============================================================ */

.view-nav {
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.18);
  border-radius: 999px;
  padding: 4px;
}

.view-nav-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: rgba(255,248,238,0.68);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.view-nav-tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s;
}

.view-nav-tab:hover::before {
  left: 100%;
}

.view-nav-tab:hover {
  color: var(--color-cream);
  background: rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.view-nav-tab.active {
  background: linear-gradient(135deg, var(--color-gold), #c4a020);
  color: var(--color-primary);
  box-shadow: 0 4px 16px rgba(212,160,23,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
  transform: scale(1.05);
  font-weight: 600;
}

.view-nav-icon {
  font-size: 1rem;
  line-height: 1;
}

/* ============================================================
   View Panel Switching
   ============================================================ */

.view-panel {
  display: none;
  width: 100%;
}

.view-panel.active {
  display: grid;
}

#view-tree.active,
#view-list.active,
#view-chapter.active,
#view-knowledge.active {
  display: block;
}

/* Hide sidebar for non-graph views */
body.view-tree .sidebar,
body.view-list .sidebar,
body.view-chapter .sidebar,
body.view-knowledge .sidebar,
body.view-tree .sidebar-resize-handle,
body.view-list .sidebar-resize-handle,
body.view-chapter .sidebar-resize-handle,
body.view-knowledge .sidebar-resize-handle,
body.view-tree .sidebar-backdrop,
body.view-list .sidebar-backdrop,
body.view-chapter .sidebar-backdrop,
body.view-knowledge .sidebar-backdrop {
  display: none !important;
}

body.view-tree .btn-sidebar-toggle,
body.view-list .btn-sidebar-toggle,
body.view-chapter .btn-sidebar-toggle,
body.view-knowledge .btn-sidebar-toggle {
  display: none !important;
}

body.view-tree .main-container,
body.view-list .main-container,
body.view-chapter .main-container,
body.view-knowledge .main-container {
  grid-template-columns: 1fr;
}

/* Content containers for non-graph views */
.tree-container,
.list-container,
.chapter-container,
.knowledge-container {
  width: 100%;
  min-height: calc(100vh - var(--header-height) - 28px);
}

/* ============================================================
   Tree View Styles
   ============================================================ */

.tree-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0;
}

.tree-family-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tree-family-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 999px;
  background: rgba(255,255,255,0.6);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.tree-family-tab:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha-06);
}

.tree-family-tab.active {
  background: var(--color-primary);
  color: var(--color-cream);
  border-color: var(--color-primary);
}

.tree-family-tab.active .tree-tab-dot {
  background: var(--color-gold-light) !important;
}

.tree-tab-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.tree-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--color-ink-light);
}

.tree-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tree-legend-icon {
  font-size: 0.9rem;
}

.tree-legend-icon.male { color: #2980B9; }
.tree-legend-icon.female { color: #E91E8C; }

.tree-legend-line.dashed {
  border-bottom: 2px dashed #E74C3C;
  padding-bottom: 2px;
}

.tree-canvas {
  width: 100%;
  min-height: 500px;
  border-radius: var(--radius-xl);
  background: rgba(255,248,238,0.72);
  border: 1px solid rgba(196,168,130,0.38);
  box-shadow: 0 14px 40px var(--color-shadow-hover);
  overflow: hidden;
}

.tree-svg {
  display: block;
  min-height: 500px;
}

.tree-link {
  stroke-linecap: round;
}

.tree-node-bg {
  fill: rgba(255,248,238,0.92);
  stroke: var(--color-border-alpha-50);
  stroke-width: 1.5;
  transition: all 0.2s ease;
}

.tree-node-bg.hovered,
.tree-node-bg.highlighted {
  fill: var(--color-primary-alpha-08);
  stroke: var(--color-primary);
  stroke-width: 2;
}

.tree-node-name {
  font-family: var(--font-title);
  font-size: 13px;
  font-weight: 700;
  fill: var(--color-primary);
}

.tree-node-identity {
  font-size: 9px;
  fill: var(--color-ink-light);
}

.tree-gender-dot.male { fill: #2980B9; }
.tree-gender-dot.female { fill: #E91E8C; }

.tree-spouse-label {
  font-size: 9px;
  fill: #E74C3C;
  font-style: italic;
}

/* Tree generation grid fallback */
.tree-generation-grid {
  padding: 20px;
}

.tree-gen-section {
  margin-bottom: 24px;
}

.tree-gen-label {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.1rem;
  padding: 8px 0;
  margin-bottom: 10px;
  border-bottom: 2px solid rgba(139,37,0,0.15);
}

.tree-gen-chars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.tree-char-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 14px;
  background: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  font-family: inherit;
}

.tree-char-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px var(--color-shadow-hover);
  border-color: var(--color-primary);
}

.tree-char-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  font-family: var(--font-title);
  flex-shrink: 0;
}

.tree-char-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tree-char-name {
  font-weight: 700;
  color: var(--color-primary);
  font-size: 0.92rem;
}

.tree-char-identity {
  font-size: 0.78rem;
  color: var(--color-ink-light);
}

.tree-char-spouse {
  margin-left: auto;
  font-size: 0.76rem;
  color: #E74C3C;
  font-style: italic;
}

.tree-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-ink-light);
  font-size: 1rem;
}

/* ============================================================
   Tree View — Enhanced Outline Styles
   ============================================================ */

.tree-shell {
  width: 100%;
  position: relative;
  font-family: var(--font-body);
}

.tree-toolbar {
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 16px;
  background: var(--color-cream-alpha-82);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(196,168,130,0.38);
  box-shadow: 0 8px 32px var(--color-shadow-hover);
  position: relative;
  overflow: hidden;
}

.tree-toolbar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(139,37,0,0.2), transparent);
}

.tree-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.tree-toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tree-action-btn {
  padding: 8px 18px;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 12px;
  background: rgba(255,255,255,0.65);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.tree-action-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s;
  z-index: -1;
}

.tree-action-btn:hover::before {
  left: 100%;
}

.tree-action-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha-06);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--color-primary-alpha-10);
}

.tree-action-btn:active {
  transform: translateY(0);
}

.tree-toolbar-bottom {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tree-search-box {
  position: relative;
  width: min(480px, 100%);
}

.tree-search-icon {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--color-ink-light);
  pointer-events: none;
}

.tree-search-input {
  width: 100%;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 12px;
  padding: 12px 16px 12px 44px;
  font-size: 0.92rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.75);
  color: var(--color-ink);
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.tree-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(139,37,0,0.15), inset 0 2px 4px rgba(0,0,0,0.05);
  background: rgba(255,255,255,0.9);
  transform: translateY(-1px);
}

.tree-summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.tree-summary-card {
  padding: 16px 20px;
  border-radius: 16px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--color-border-alpha-32);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.tree-summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--color-primary), #E74C3C);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.tree-summary-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(44,24,16,0.1);
  border-color: var(--color-border-alpha-45);
}

.tree-summary-card:hover::before {
  opacity: 1;
}

.tree-summary-card.accent {
  background: linear-gradient(135deg, var(--color-primary-alpha-08), rgba(212,160,23,0.1));
  border-color: var(--color-border-alpha-45);
}

.tree-summary-card strong {
  font-family: var(--font-title);
  color: var(--color-primary-dark);
  font-size: 1.35rem;
  font-weight: 700;
  transition: all 0.3s ease;
}

.tree-summary-card:hover strong {
  color: var(--color-primary);
}

.tree-summary-card span {
  font-size: 0.84rem;
  color: var(--color-ink-light);
}

.tree-summary-label {
  font-size: 0.76rem;
  color: var(--color-ink-light);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.8;
}

.tree-hint-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 0;
}

.tree-hint-pill {
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 0.8rem;
  color: var(--color-ink-light);
  background: rgba(196,168,130,0.16);
  border: 1px solid rgba(196,168,130,0.24);
  transition: all 0.3s ease;
  cursor: default;
}

.tree-hint-pill:hover {
  background: rgba(196,168,130,0.22);
  border-color: var(--color-border-alpha-32);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(196,168,130,0.15);
}

.tree-outline {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tree-section {
  border-radius: 20px;
  background: rgba(255,248,238,0.68);
  border: 1px solid rgba(196,168,130,0.38);
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(44,24,16,0.06);
}

.tree-section:hover {
  box-shadow: 0 6px 24px rgba(44,24,16,0.1);
  transform: translateY(-2px);
}

.tree-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--color-primary-alpha-06), rgba(212,160,23,0.05));
  border-bottom: 1px solid rgba(196,168,130,0.25);
  cursor: default;
}

.tree-section-title {
  font-family: var(--font-title);
  color: var(--color-primary-dark);
  font-size: 1.2rem;
  font-weight: 700;
  position: relative;
  display: inline-block;
}

.tree-section-title::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 40px;
  height: 2px;
  background: linear-gradient(to right, var(--color-primary), #E74C3C);
}

.tree-section-meta {
  display: flex;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--color-ink-light);
  margin-top: 4px;
}

.tree-section-meta span + span::before {
  content: '·';
  margin-right: 14px;
  opacity: 0.6;
}

.tree-section-jump {
  padding: 8px 18px;
  border: 1px solid rgba(139,37,0,0.28);
  border-radius: 14px;
  background: var(--color-primary-alpha-08);
  color: var(--color-primary);
  font-size: 0.84rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.tree-section-jump::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s;
  z-index: -1;
}

.tree-section-jump:hover {
  background: linear-gradient(135deg, var(--color-primary), #b02e00);
  color: var(--color-cream);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(139,37,0,0.25);
  z-index: 2;
}

.tree-section-jump:hover::before {
  left: 100%;
}

.tree-section-jump:active {
  transform: translateY(0);
}

.tree-section-body {
  padding: 12px 16px 16px;
}

.tree-item {
  border-radius: 12px;
  margin: 2px 0;
  transition: all 0.2s ease;
  position: relative;
}

.tree-item:hover {
  background: rgba(255,255,255,0.3);
}

.tree-item.level-0 { padding-left: 0; }
.tree-item.level-1 { padding-left: 28px; }
.tree-item.level-2 { padding-left: 56px; }
.tree-item.level-3 { padding-left: 84px; }
.tree-item.level-4 { padding-left: 112px; }
.tree-item.level-5 { padding-left: 140px; }

.tree-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  position: relative;
}

.tree-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(196,168,130,0.2);
  border-radius: 1px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: -1;
}

.tree-item:hover::before {
  opacity: 1;
}

.tree-item-toggle {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--color-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  z-index: 1;
  margin-right: 4px;
}

.tree-item-toggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
  z-index: -1;
}

.tree-item-toggle:hover:not(:disabled)::before {
  left: 100%;
}

.tree-item-toggle:hover:not(:disabled) {
  background: var(--color-primary-alpha-10);
  color: var(--color-primary-dark);
  transform: scale(1.1);
}

.tree-item-toggle:active:not(:disabled) {
  transform: scale(0.95);
}

.tree-item-toggle.is-leaf {
  color: var(--color-ink-light);
  opacity: 0.5;
  cursor: default;
  transform: scale(0.85);
  background: transparent;
}

.tree-person-card {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  padding: 10px 16px;
  border: 1px solid rgba(196,168,130,0.25);
  border-radius: 14px;
  background: rgba(255,255,255,0.5);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.tree-person-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(139,37,0,0.05), transparent);
  transition: left 0.7s;
  z-index: -1;
}

.tree-person-card:hover::before {
  left: 100%;
}

.tree-person-card:hover {
  background: var(--color-primary-alpha-08);
  border-color: var(--color-primary-alpha-40);
  box-shadow: 0 6px 16px rgba(44,24,16,0.1);
  transform: translateY(-2px);
}

.tree-person-card.highlighted {
  background: linear-gradient(135deg, rgba(139,37,0,0.12), rgba(212,160,23,0.1));
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(139,37,0,0.15);
  transform: scale(1.02);
  z-index: 2;
}

.tree-person-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  font-family: var(--font-title);
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--color-shadow-dark);
  background: #C0392B;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree-person-card:hover .tree-person-avatar {
  transform: scale(1.15) rotate(5deg);
  box-shadow: 0 6px 16px rgba(44,24,16,0.25);
}

.tree-person-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.tree-person-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tree-person-name {
  font-weight: 700;
  color: var(--color-primary-dark);
  font-size: 0.96rem;
  transition: all 0.3s ease;
}

.tree-person-card:hover .tree-person-name {
  color: var(--color-primary);
}

.tree-person-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid currentColor;
  background: transparent;
}

.tree-person-badge.male {
  color: #2980B9;
  border-color: rgba(41,128,185,0.3);
}

.tree-person-badge.female {
  color: #E91E8C;
  border-color: rgba(233,30,140,0.3);
}

.tree-person-badge.mainline {
  background: rgba(212,160,23,0.15);
  color: #9A7D1A;
  border-color: rgba(212,160,23,0.35);
}

.tree-person-identity {
  font-size: 0.82rem;
  color: var(--color-ink-light);
  line-height: 1.45;
  opacity: 0.9;
}

.tree-person-meta {
  display: flex;
  gap: 10px;
  font-size: 0.74rem;
  color: var(--color-ink-light);
  flex-wrap: wrap;
  margin-top: 2px;
}

.tree-person-meta span + span::before {
  content: '·';
  margin-right: 10px;
  opacity: 0.6;
}

.tree-spouse-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0 8px 42px;
}

.tree-spouse-pill {
  padding: 5px 16px;
  border: 1px dashed #E74C3C;
  border-radius: 20px;
  background: rgba(231,76,60,0.05);
  color: #C0392B;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 1;
}

.tree-spouse-pill::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(231,76,60,0.1), transparent);
  transition: left 0.6s;
  z-index: -1;
}

.tree-spouse-pill:hover::before {
  left: 100%;
}

.tree-spouse-pill:hover {
  background: rgba(231,76,60,0.1);
  border-style: solid;
  border-color: #C0392B;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(231,76,60,0.15);
}

.tree-item-children {
  border-left: 2px solid var(--color-border-alpha-32);
  margin-left: 18px;
  padding-left: 10px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Smooth animation for expanding/collapsing branches */
.tree-item-children:not(.visible) {
  display: none;
  opacity: 0;
  transform: scaleY(0);
  transform-origin: top;
  transition: all 0.3s ease;
  max-height: 0;
}

.tree-item-children.visible {
  display: block;
  opacity: 1;
  transform: scaleY(1);
  transition: all 0.3s ease;
  max-height: unset;
}

/* Transition for the toggle button when expanded */
.tree-item-toggle.expanded {
  transform: rotate(90deg);
  transition: transform 0.3s ease;
}

/* Tree item expansion transitions */
.tree-item.level-1 .tree-item-children,
.tree-item.level-2 .tree-item-children,
.tree-item.level-3 .tree-item-children,
.tree-item.level-4 .tree-item-children,
.tree-item.level-5 .tree-item-children {
  transition: all 0.3s ease;
  overflow: hidden;
}

/* ============================================================
   List View Styles
   ============================================================ */

.list-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0;
}

.list-controls-left,
.list-controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.list-search-box {
  position: relative;
}

.list-search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
}

.list-search-input {
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 12px;
  padding: 9px 14px 9px 36px;
  font-size: 0.88rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.72);
  color: var(--color-ink);
  outline: none;
  width: 200px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.list-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(139,37,0,0.15), inset 0 2px 4px rgba(0,0,0,0.05);
  width: 260px;
  background: rgba(255,255,255,0.9);
  transform: translateY(-1px);
}

.list-filter-select,
.list-sort-select {
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.86rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.72);
  color: var(--color-ink);
  cursor: pointer;
  outline: none;
}

.list-view-toggle {
  display: flex;
  gap: 2px;
  background: rgba(196,168,130,0.2);
  border-radius: 10px;
  padding: 2px;
}

.list-view-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--color-ink-light);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.list-view-btn:hover {
  background: rgba(196,168,130,0.3);
  color: var(--color-ink);
}

.list-view-btn.active {
  background: linear-gradient(135deg, var(--color-primary), #b02e00);
  color: var(--color-cream);
  box-shadow: 0 4px 12px rgba(139,37,0,0.2);
}

.list-content {
  padding-bottom: 24px;
}

.list-stats {
  font-size: 0.84rem;
  color: var(--color-ink-light);
  margin-bottom: 12px;
}

.list-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.list-card-item {
  display: flex;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 18px;
  background: var(--color-cream-alpha-82);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.list-card-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--color-primary), #E74C3C);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.list-card-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(44,24,16,0.12);
  border-color: var(--color-primary);
}

.list-card-item:hover::before {
  opacity: 1;
}

.list-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  font-family: var(--font-title);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(44,24,16,0.15);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.list-card-item:hover .list-card-avatar {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 6px 16px rgba(44,24,16,0.2);
}

.list-card-body {
  flex: 1;
  min-width: 0;
}

.list-card-name {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.05rem;
  font-weight: 700;
}

.list-card-pinyin {
  font-size: 0.78rem;
  color: var(--color-ink-light);
  margin-left: 6px;
  font-family: var(--font-body);
  font-weight: 400;
}

.list-card-identity {
  font-size: 0.82rem;
  color: var(--color-ink-light);
  margin-top: 2px;
}

.list-card-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.list-card-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid currentColor;
  background: transparent;
}

.list-card-tag.female {
  color: #E91E8C;
  border-color: rgba(233,30,140,0.3);
}

.list-card-tag.male {
  color: #2980B9;
  border-color: rgba(41,128,185,0.3);
}

.list-card-tag.soft {
  color: var(--color-ink-light);
  border-color: rgba(196,168,130,0.4);
}

.list-card-tag.knowledge {
  color: #8B2500;
  border-color: rgba(212,160,23,0.35);
  background: rgba(212,160,23,0.12);
}

.list-card-outcome {
  font-size: 0.8rem;
  color: var(--color-ink-light);
  margin-top: 6px;
  font-style: italic;
}

/* List compact mode */
.list-compact-table {
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 18px;
  overflow: hidden;
  background: var(--color-cream-alpha-82);
}

.list-compact-row {
  display: grid;
  grid-template-columns: 32px 80px 60px 1fr 50px 40px;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(196,168,130,0.2);
  cursor: pointer;
  transition: var(--transition);
}

.list-compact-row:last-child {
  border-bottom: none;
}

.list-compact-row:hover {
  background: rgba(139,37,0,0.04);
}

.list-compact-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  font-family: var(--font-title);
}

.list-compact-name {
  font-weight: 700;
  color: var(--color-primary);
  font-size: 0.9rem;
}

.list-compact-family {
  font-size: 0.78rem;
  font-weight: 600;
}

.list-compact-identity {
  font-size: 0.8rem;
  color: var(--color-ink-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-compact-importance {
  font-size: 0.78rem;
  color: var(--color-gold);
  font-weight: 700;
}

.list-compact-gender {
  font-size: 0.78rem;
  font-weight: 600;
}

.list-compact-gender.female { color: #E91E8C; }
.list-compact-gender.male { color: #2980B9; }

.list-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-ink-light);
  font-size: 1rem;
}

/* ============================================================
   Knowledge View Styles
   ============================================================ */

.knowledge-controls {
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.knowledge-search-box {
  position: relative;
  width: min(480px, 100%);
}

.knowledge-search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}

.knowledge-search-input {
  width: 100%;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 999px;
  padding: 10px 16px 10px 40px;
  font-size: 0.9rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.72);
  color: var(--color-ink);
  outline: none;
  transition: var(--transition);
}

.knowledge-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-alpha-10);
}

.knowledge-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.knowledge-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 12px;
  background: rgba(255,255,255,0.6);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.knowledge-tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s;
}

.knowledge-tab:hover::before {
  left: 100%;
}

.knowledge-tab:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha-06);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--color-primary-alpha-08);
}

.knowledge-tab.active {
  background: linear-gradient(135deg, var(--color-primary), #b02e00);
  color: var(--color-cream);
  border-color: var(--color-primary);
  box-shadow: 0 4px 14px rgba(139,37,0,0.3);
  transform: translateX(4px);
  font-weight: 600;
}

.knowledge-tab-count {
  font-size: 0.72rem;
  opacity: 0.7;
  margin-left: 2px;
}

.knowledge-items {
  padding-bottom: 24px;
}

.knowledge-stats {
  font-size: 0.84rem;
  color: var(--color-ink-light);
  margin-bottom: 12px;
}

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}

.knowledge-card {
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 20px;
  padding: 20px;
  background: var(--color-cream-alpha-88);
  backdrop-filter: blur(8px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.knowledge-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--color-primary), #E74C3C);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.knowledge-card:hover {
  box-shadow: 0 16px 40px rgba(44,24,16,0.12);
  border-color: rgba(139,37,0,0.3);
  transform: translateY(-3px);
}

.knowledge-card:hover::before {
  opacity: 1;
}

.knowledge-card-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.knowledge-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.knowledge-card-title-group {
  flex: 1;
  min-width: 0;
}

.knowledge-card-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
}

.knowledge-card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.knowledge-card-category {
  font-size: 0.78rem;
  font-weight: 700;
}

.knowledge-card-chapter {
  font-size: 0.76rem;
  color: var(--color-ink-light);
  background: rgba(196,168,130,0.2);
  padding: 2px 8px;
  border-radius: 999px;
}

.knowledge-card-content {
  font-size: 0.92rem;
  line-height: 1.85;
  color: var(--color-ink);
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255,255,255,0.5), rgba(245,230,211,0.4));
  border: 1px solid rgba(196,168,130,0.2);
  font-family: var(--font-title);
  margin-bottom: 10px;
  position: relative;
  transition: all 0.3s ease;
}

.knowledge-card:hover .knowledge-card-content {
  background: linear-gradient(145deg, rgba(255,255,255,0.6), rgba(245,230,211,0.5));
  border-color: rgba(196,168,130,0.3);
}

.knowledge-card-version {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(196,168,130,0.12);
  border: 1px solid rgba(196,168,130,0.22);
  color: var(--color-ink-light);
  font-size: 0.78rem;
  line-height: 1.6;
}

.knowledge-card-analysis {
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--color-ink-light);
  display: none;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(139,37,0,0.04);
  border-left: 3px solid var(--color-primary);
}

.knowledge-card.expanded .knowledge-card-analysis {
  display: block;
}

.knowledge-card-chars {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.knowledge-char-pill {
  padding: 4px 10px;
  border: 1px solid rgba(139,37,0,0.25);
  border-radius: 12px;
  background: var(--color-primary-alpha-06);
  color: var(--color-primary);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.knowledge-char-pill:hover {
  background: var(--color-primary);
  color: var(--color-cream);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139,37,0,0.15);
}

.knowledge-card-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.knowledge-tag {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(196,168,130,0.18);
  color: var(--color-ink-light);
}

.knowledge-card-expand {
  border: none;
  background: transparent;
  color: var(--color-primary);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
  font-family: var(--font-body);
}

.knowledge-card-expand:hover {
  text-decoration: underline;
}

.knowledge-card-analysis.visible {
  display: block;
}

.knowledge-shell {
  width: 100%;
}

.chapter-shell {
  width: 100%;
}

.chapter-hero,
.chapter-sidebar,
.chapter-focus,
.chapter-section {
  border-radius: var(--radius-xl);
}

.chapter-hero {
  padding: 28px 24px;
  margin-bottom: 18px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.chapter-hero-copy {
  flex: 1;
  min-width: 300px;
}

.chapter-hero-eyebrow {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: rgba(39,174,96,0.12);
  color: #237A57;
  margin-bottom: 10px;
}

.chapter-hero-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.38rem;
  line-height: 1.4;
  margin-bottom: 8px;
}

.chapter-hero-desc {
  font-size: 0.9rem;
  color: var(--color-ink-light);
  line-height: 1.75;
}

.chapter-hero-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(84px, 1fr));
  gap: 10px;
  min-width: 340px;
}

.chapter-stat-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--color-border-alpha-28);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.chapter-stat-card span {
  font-size: 0.72rem;
  color: var(--color-ink-light);
}

.chapter-stat-card strong {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.24rem;
}

.chapter-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.chapter-sidebar {
  padding: 18px;
  position: sticky;
  top: calc(var(--header-height) + 14px);
  max-height: calc(100vh - var(--header-height) - 28px);
  overflow-y: auto;
}

.chapter-sidebar-section + .chapter-sidebar-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(196,168,130,0.22);
}

.chapter-sidebar-title {
  font-size: 0.84rem;
  color: var(--color-ink-light);
  margin-bottom: 10px;
  font-weight: 700;
}

.chapter-search-box {
  position: relative;
}

.chapter-search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}

.chapter-search-input {
  width: 100%;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: 999px;
  padding: 10px 16px 10px 40px;
  font-size: 0.9rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.72);
  color: var(--color-ink);
  outline: none;
}

.chapter-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-alpha-10);
}

.chapter-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chapter-filter-chip,
.chapter-point-chip,
.chapter-nav-btn,
.chapter-text-action,
.chapter-inline-link {
  font-family: var(--font-body);
}

.chapter-filter-chip {
  border: 1px solid rgba(196,168,130,0.36);
  border-radius: 999px;
  background: rgba(255,255,255,0.65);
  color: var(--color-ink);
  padding: 7px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: var(--transition);
}

.chapter-filter-chip.active,
.chapter-filter-chip:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-cream);
}

.chapter-directory {
  display: grid;
  gap: 8px;
}

.chapter-directory-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(196,168,130,0.28);
  border-radius: 16px;
  background: rgba(255,255,255,0.55);
  padding: 12px 14px;
  display: grid;
  gap: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.chapter-directory-item:hover,
.chapter-directory-item.active {
  transform: translateY(-1px);
  border-color: rgba(139,37,0,0.32);
  box-shadow: 0 10px 22px rgba(44,24,16,0.08);
}

.chapter-directory-item.active {
  background: linear-gradient(135deg, rgba(192,57,43,0.1), rgba(255,248,238,0.92));
}

.chapter-directory-number {
  font-size: 0.74rem;
  color: var(--color-primary);
  font-weight: 700;
}

.chapter-directory-title {
  color: var(--color-ink);
  font-weight: 700;
  line-height: 1.45;
}

.chapter-directory-meta,
.chapter-section-subtitle,
.chapter-character-identity,
.chapter-character-meta,
.chapter-knowledge-meta,
.chapter-knowledge-snippet,
.chapter-muted,
.chapter-directory-empty,
.chapter-empty-desc {
  font-size: 0.8rem;
  color: var(--color-ink-light);
  line-height: 1.65;
}

.chapter-main {
  display: grid;
  gap: 16px;
}

.chapter-focus,
.chapter-section,
.chapter-empty {
  padding: 22px;
}

.chapter-focus-head,
.chapter-section-head,
.chapter-character-top,
.chapter-knowledge-head,
.chapter-knowledge-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chapter-focus-eyebrow {
  color: #237A57;
  font-size: 0.76rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.chapter-focus-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.3rem;
  line-height: 1.45;
}

.chapter-focus-desc,
.chapter-interpretation {
  color: var(--color-ink-light);
  line-height: 1.8;
  font-size: 0.88rem;
}

.chapter-focus-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chapter-nav-btn,
.chapter-text-action,
.chapter-inline-link,
.chapter-point-chip {
  border: 1px solid rgba(196,168,130,0.36);
  background: rgba(255,255,255,0.62);
  color: var(--color-ink);
  border-radius: 12px;
  padding: 8px 14px;
  cursor: pointer;
  transition: var(--transition);
}

.chapter-nav-btn.primary,
.chapter-nav-btn:hover,
.chapter-text-action:hover,
.chapter-inline-link:hover,
.chapter-point-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-alpha-06);
}

.chapter-focus-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.chapter-summary-card {
  border-radius: 18px;
  border: 1px solid rgba(196,168,130,0.24);
  background: rgba(255,255,255,0.48);
  padding: 18px;
}

.chapter-summary-card.emphasis {
  background: linear-gradient(145deg, rgba(192,57,43,0.08), rgba(255,248,238,0.82));
}

.chapter-section-title {
  font-family: var(--font-title);
  font-size: 1rem;
  color: var(--color-primary);
  margin-bottom: 6px;
}

.chapter-summary-lines {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.chapter-summary-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
  color: var(--color-ink);
}

.chapter-summary-label {
  color: var(--color-ink-light);
}

.chapter-point-group,
.chapter-evidence-group,
.chapter-knowledge-chars {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chapter-point-chip {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
}

.chapter-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.chapter-kpi-item {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.52);
  border: 1px solid rgba(196,168,130,0.22);
  text-align: center;
}

.chapter-kpi-item strong {
  display: block;
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.18rem;
}

.chapter-kpi-item span {
  font-size: 0.76rem;
  color: var(--color-ink-light);
}

.chapter-character-grid,
.chapter-related-grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.chapter-character-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.chapter-related-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.chapter-character-card,
.chapter-knowledge-card {
  border: 1px solid rgba(196,168,130,0.28);
  border-radius: 18px;
  background: rgba(255,255,255,0.58);
  padding: 16px;
  transition: var(--transition);
}

.chapter-character-card {
  text-align: left;
  cursor: pointer;
}

.chapter-character-card:hover,
.chapter-character-card.is-related,
.chapter-knowledge-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(44,24,16,0.08);
  border-color: rgba(139,37,0,0.3);
}

.chapter-character-card.is-related,
.chapter-inline-pill.is-related {
  background: rgba(192,57,43,0.1);
}

.chapter-character-name,
.chapter-knowledge-title {
  font-weight: 700;
  color: var(--color-primary);
}

.chapter-character-score {
  font-size: 0.76rem;
  color: #237A57;
  font-weight: 700;
}

.chapter-evidence-chip,
.chapter-inline-pill {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  border: 1px solid rgba(196,168,130,0.24);
  background: rgba(255,248,238,0.8);
  color: var(--color-ink-light);
}

.chapter-inline-pill {
  cursor: pointer;
}

.chapter-knowledge-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.chapter-empty-block,
.chapter-empty {
  text-align: center;
  color: var(--color-ink-light);
}

.chapter-empty-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.06rem;
  margin-bottom: 8px;
}

.knowledge-hero {
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  margin-bottom: 18px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.knowledge-hero-copy {
  flex: 1;
  min-width: 280px;
}

.knowledge-hero-eyebrow {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  background: var(--color-primary-alpha-08);
  color: var(--color-primary);
  margin-bottom: 10px;
}

.knowledge-hero-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.35rem;
  line-height: 1.4;
  margin-bottom: 8px;
}

.knowledge-hero-desc {
  font-size: 0.88rem;
  color: var(--color-ink-light);
  line-height: 1.7;
}

.knowledge-hero-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  min-width: 320px;
}

.knowledge-stat-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--color-border-alpha-28);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.knowledge-stat-card span {
  font-size: 0.72rem;
  color: var(--color-ink-light);
}

.knowledge-stat-card strong {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.25rem;
}

.knowledge-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.knowledge-sidebar {
  border-radius: var(--radius-xl);
  padding: 18px;
  position: sticky;
  top: calc(var(--header-height) + 14px);
  max-height: calc(100vh - var(--header-height) - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.knowledge-sidebar-section + .knowledge-sidebar-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(196,168,130,0.22);
}

.knowledge-sidebar-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.knowledge-tabs-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.knowledge-tabs-block .knowledge-tab {
  width: 100%;
  justify-content: space-between;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.knowledge-chip-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.knowledge-chip {
  padding: 5px 12px;
  border: 1px solid rgba(196,168,130,0.38);
  border-radius: 999px;
  background: rgba(255,255,255,0.6);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.knowledge-chip:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha-06);
}

.knowledge-chip.active {
  background: linear-gradient(135deg, var(--color-primary), #a02800);
  color: var(--color-cream);
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(139,37,0,0.25);
  transform: scale(1.02);
}

.knowledge-chip span {
  font-size: 0.68rem;
  opacity: 0.7;
  margin-left: 3px;
}

.knowledge-select {
  width: 100%;
  border: 1px solid rgba(196,168,130,0.42);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.86rem;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.72);
  color: var(--color-ink);
  cursor: pointer;
  outline: none;
}

.knowledge-muted {
  font-size: 0.8rem;
  color: var(--color-ink-light);
  font-style: italic;
}

.knowledge-main {
  min-width: 0;
}

.knowledge-results-head {
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.knowledge-results-title {
  font-family: var(--font-title);
  color: var(--color-primary);
  font-size: 1.05rem;
  font-weight: 700;
}

.knowledge-results-subtitle {
  font-size: 0.82rem;
  color: var(--color-ink-light);
  margin-top: 2px;
}

.knowledge-clear-btn {
  padding: 7px 14px;
  border: 1px solid rgba(139,37,0,0.25);
  border-radius: 999px;
  background: var(--color-primary-alpha-06);
  color: var(--color-primary);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.knowledge-clear-btn:hover {
  background: var(--color-primary);
  color: var(--color-cream);
}

.knowledge-card-subcategory {
  font-size: 0.74rem;
  color: var(--color-ink-light);
  background: rgba(196,168,130,0.15);
  padding: 2px 8px;
  border-radius: 999px;
}

.knowledge-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(196,168,130,0.18);
  margin-top: 10px;
}

.knowledge-card-related-events {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.knowledge-card-related-events span {
  font-size: 0.72rem;
  color: var(--color-ink-light);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(196,168,130,0.12);
}

.knowledge-info-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.knowledge-info-label {
  font-size: 0.74rem;
  color: var(--color-ink-light);
  font-weight: 600;
  white-space: nowrap;
  padding-top: 4px;
  min-width: 60px;
}

.knowledge-tag.place {
  background: rgba(35,122,87,0.1);
  color: #237A57;
}

.knowledge-tag[data-tag] {
  cursor: pointer;
  transition: var(--transition);
}

.knowledge-tag[data-tag]:hover {
  background: rgba(139,37,0,0.12);
  color: var(--color-primary);
}

.note-box {
  background: rgba(212,160,23,0.06);
  border-left-color: var(--color-gold);
}

.card-source-note {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(196,168,130,0.12);
  border: 1px solid rgba(196,168,130,0.22);
}

.card-version-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.card-version-row + .card-version-row {
  margin-top: 8px;
}

.card-version-row strong {
  flex-shrink: 0;
  color: var(--color-primary);
  font-size: 0.78rem;
}

.knowledge-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-ink-light);
  font-size: 1rem;
}

.knowledge-load-more {
  display: block;
  width: 100%;
  padding: 14px 0;
  margin-top: 8px;
  background: var(--color-parchment);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  grid-column: 1 / -1;
}

.knowledge-load-more:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* ============================================================
   Responsive: View Nav & New Views
   ============================================================ */

@media (max-width: 768px) {
  .view-nav {
    gap: 2px;
    padding: 3px;
  }

  .view-nav-tab {
    padding: 6px 10px;
    font-size: 0.8rem;
    gap: 4px;
  }

  .view-nav-label {
    display: none;
  }

  .view-nav-icon {
    font-size: 1.15rem;
  }

  .tree-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .list-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .list-controls-left,
  .list-controls-right {
    flex-wrap: wrap;
  }

  .list-search-input {
    width: 100%;
  }

  .list-search-input:focus {
    width: 100%;
  }

  .list-card-grid {
    grid-template-columns: 1fr;
  }

  .list-compact-row {
    grid-template-columns: 28px 70px 50px 1fr 40px 32px;
    gap: 6px;
    padding: 8px 12px;
  }

  .knowledge-grid {
    grid-template-columns: 1fr;
  }

  .knowledge-layout {
    grid-template-columns: 1fr;
  }

  .knowledge-sidebar {
    position: static;
    max-height: none;
  }

  .knowledge-hero {
    flex-direction: column;
  }

  .knowledge-hero-stats {
    min-width: 0;
    grid-template-columns: repeat(2, 1fr);
  }

  .knowledge-tabs-block {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .knowledge-tabs-block .knowledge-tab {
    width: auto;
  }

  .tree-summary-strip {
    grid-template-columns: 1fr;
  }

  .tree-toolbar-top {
    flex-direction: column;
    align-items: stretch;
  }

  .tree-section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .tree-item.level-1 { padding-left: 16px; }
  .tree-item.level-2 { padding-left: 32px; }
  .tree-item.level-3 { padding-left: 48px; }
  .tree-item.level-4 { padding-left: 60px; }
  .tree-item.level-5 { padding-left: 72px; }

  .tree-gen-chars {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .view-nav {
    gap: 1px;
    padding: 2px;
  }

  .view-nav-tab {
    padding: 5px 8px;
  }

  /* Override the default 560px rule that hides header-center */
  .header-center {
    display: flex !important;
  }

  .list-compact-row {
    grid-template-columns: 28px 1fr 40px;
  }

  .list-compact-family,
  .list-compact-identity,
  .list-compact-gender {
    display: none;
  }
}

/* Focus-visible styles for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

button:focus-visible,
.view-nav-tab:focus-visible,
.tree-family-tab:focus-visible,
.knowledge-tab:focus-visible,
.card-close-btn:focus-visible,
.recommend-pill:focus-visible,
.card-relation-item:focus-visible,
.quick-card:focus-visible,
.topic-card:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

.character-card:focus-visible {
  outline: none;
}

/* Preview highlight styles for cross-view hover */
.preview-highlight {
  box-shadow: 0 0 0 3px var(--color-gold) !important;
  transform: scale(1.02);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.node-group.preview-dimmed {
  opacity: 0.25;
  transition: opacity 0.2s ease;
}

.link-line.preview-dimmed {
  opacity: 0.15;
  transition: opacity 0.2s ease;
}

.list-card-item.preview-highlight,
.list-compact-row.preview-highlight {
  box-shadow: 0 0 0 2px var(--color-gold);
  background: var(--color-gold-light, #fffbe6);
}
