:root {
  --bg: #100e0b; --surface: #1a1610; --surface2: #221e18;
  --border: #2e271e; --amber: #c4935a; --amber-light: #d4a870;
  --cream: #ede5d4; --muted: #8a7a65; --muted2: #a89278;
  --male: #3a6b8a; --female: #8a3a5a; --unknown: #5a5a4a;
  --radius: 6px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--cream); font-family: 'Lora', serif; height: 100vh; height: 100dvh; overflow: hidden; }

/* ── Layout ── */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; flex-shrink: 0; z-index: 100; }
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.site-link { color: var(--amber); text-decoration: none; font-family: 'Playfair Display', serif; font-size: 0.85rem; white-space: nowrap; }
.site-link:hover { color: var(--amber-light); }
.app-title { font-family: 'Playfair Display', serif; font-size: 1.1rem; color: var(--cream); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.lang-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 0.25rem 0.6rem; border-radius: var(--radius); cursor: pointer; font-family: 'EB Garamond', serif; font-size: 0.8rem; transition: all 0.2s; }
.lang-btn.active, .lang-btn:hover { border-color: var(--amber); color: var(--amber); }
#theme-toggle { background: none; border: 1px solid var(--border); color: var(--muted); padding: 0.25rem 0.45rem; border-radius: var(--radius); cursor: pointer; font-size: 1rem; line-height: 1; transition: all 0.2s; }
#theme-toggle:hover { border-color: var(--amber); color: var(--amber); }

[data-theme="light"] {
  --bg: #f5f2eb; --surface: #e8e2d8; --surface2: #ddd8cc;
  --border: #c8c0b0; --cream: #1a150e; --muted: #6a5e50; --muted2: #8a7a6a;
}
[data-theme="light"] body { background: var(--bg); color: var(--cream); }
[data-theme="light"] .topbar { background: #ede8df; border-color: var(--border); }
[data-theme="light"] .sidebar { background: #ede8df; border-color: var(--border); }
[data-theme="light"] .search-input { background: #e5dfd4; border-color: var(--border); color: var(--cream); }
[data-theme="light"] .detail-pane { background: var(--bg); }
[data-theme="light"] .depth-select { background: var(--surface2); color: var(--cream); }

.main { flex: 1; display: grid; grid-template-columns: 320px 1fr; min-height: 0; overflow: hidden; }
@media (max-width: 768px) { .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } }

/* ── Sidebar ── */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.search-box { padding: 1rem; border-bottom: 1px solid var(--border); }
.search-input { width: 100%; background: var(--surface2); border: 1px solid var(--border); color: var(--cream); padding: 0.6rem 0.9rem; border-radius: var(--radius); font-family: 'Lora', serif; font-size: 0.9rem; outline: none; transition: border-color 0.2s; }
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--amber); }
.search-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; padding: 0 0.1rem; }
.person-list { flex: 1; overflow-y: auto; }
.person-list::-webkit-scrollbar { width: 8px; }
.person-list::-webkit-scrollbar-track { background: var(--surface); }
.person-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.person-list::-webkit-scrollbar-thumb:hover { background: var(--amber); }
.person-item { padding: 0.65rem 1rem; cursor: pointer; border-bottom: 1px solid rgba(46,39,30,0.5); transition: background 0.15s; display: flex; align-items: center; gap: 0.6rem; }
.person-item:hover { background: var(--surface2); }
.person-item.selected { background: rgba(196,147,90,0.12); border-left: 3px solid var(--amber); }
.person-sex-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-M { background: var(--male); }
.dot-F { background: var(--female); }
.dot-null { background: var(--unknown); }
.person-item-name { font-family: 'EB Garamond', serif; font-size: 0.95rem; color: var(--cream); line-height: 1.2; }
.person-item-years { font-size: 0.75rem; color: var(--muted); }

/* ── Content pane ── */
.content { overflow-y: auto; display: flex; flex-direction: column; }
.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-track { background: var(--bg); }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.content::-webkit-scrollbar-thumb:hover { background: var(--amber); }
.tree-container::-webkit-scrollbar { height: 8px; width: 8px; }
.tree-container::-webkit-scrollbar-track { background: var(--bg); }
.tree-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.tree-container::-webkit-scrollbar-thumb:hover { background: var(--amber); }

.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 2rem; text-align: center; gap: 1rem; }
.welcome-title { font-family: 'Playfair Display', serif; font-size: 2rem; color: var(--cream); }
.welcome-sub { color: var(--muted); font-family: 'EB Garamond', serif; font-size: 1rem; max-width: 400px; line-height: 1.6; }

/* ── Person detail ── */
.person-detail { padding: 2rem; max-width: 900px; }
.detail-header { display: flex; gap: 1.5rem; align-items: flex-start; margin-bottom: 2rem; flex-wrap: wrap; }
.detail-photo { width: 100px; height: 130px; object-fit: cover; border-radius: var(--radius); border: 2px solid var(--border); flex-shrink: 0; }
.detail-photo-placeholder { width: 100px; height: 130px; background: var(--surface2); border: 2px solid var(--border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 2rem; flex-shrink: 0; }
.detail-main { flex: 1; min-width: 200px; }
.detail-name { font-family: 'Playfair Display', serif; font-size: 1.8rem; font-weight: 700; color: var(--cream); line-height: 1.2; margin-bottom: 0.4rem; }
.detail-job { font-family: 'EB Garamond', serif; font-size: 1rem; color: var(--amber); font-style: italic; margin-bottom: 0.75rem; }
.detail-facts { display: flex; flex-direction: column; gap: 0.3rem; }
.detail-fact { font-family: 'EB Garamond', serif; font-size: 0.95rem; color: var(--cream); display: flex; gap: 0.5rem; }
.fact-label { color: var(--muted); min-width: 70px; }
.detail-divider { height: 1px; background: var(--border); margin: 1.5rem 0; }
.detail-section { margin-bottom: 1.5rem; }
.detail-section-title { font-family: 'Playfair Display', serif; font-size: 0.8rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--amber); margin-bottom: 0.75rem; }
.rel-cards { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.rel-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.8rem; cursor: pointer; transition: all 0.15s; text-align: left; }
.rel-card:hover { border-color: var(--amber); background: rgba(196,147,90,0.08); }
.rel-card-name { font-family: 'EB Garamond', serif; font-size: 0.9rem; color: var(--cream); display: block; }
.rel-card-years { font-size: 0.75rem; color: var(--muted); display: block; margin-top: 0.1rem; }
.family-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.family-block-spouse { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; cursor: pointer; }
.marriage-info { font-family: 'EB Garamond', serif; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.6rem; }

/* ── Tree actions bar ── */
.tree-bar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding: 1rem 2rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.tree-btn { background: none; border: 1px solid var(--border); color: var(--muted2); padding: 0.4rem 0.9rem; border-radius: var(--radius); cursor: pointer; font-family: 'EB Garamond', serif; font-size: 0.88rem; transition: all 0.2s; white-space: nowrap; }
.tree-btn:hover, .tree-btn.active { border-color: var(--amber); color: var(--amber); background: rgba(196,147,90,0.08); }
.depth-select { background: var(--surface2); border: 1px solid var(--border); color: var(--cream); padding: 0.35rem 0.6rem; border-radius: var(--radius); font-family: 'EB Garamond', serif; font-size: 0.88rem; cursor: pointer; }
.zoom-btn { padding: 0.4rem 0.6rem; min-width: 2rem; text-align: center; font-size: 1rem; line-height: 1; }
.depth-select:focus { outline: none; border-color: var(--amber); }
.tree-label { font-family: 'EB Garamond', serif; font-size: 0.82rem; color: var(--muted); }

/* ── Tree ── */
.tree-container { padding: 2rem; overflow: auto; position: relative; height: 100%; box-sizing: border-box; }
.tree-root { display: flex; flex-direction: column; align-items: flex-start; gap: 0; }

/* Ascendant tree — horizontal pedigree layout */
.asc-tree { display: flex; flex-direction: row; gap: 2.5rem; align-items: stretch; }
.asc-gen { display: flex; flex-direction: column; justify-content: space-around; gap: 8px; padding: 0 4px; }
.asc-gen + .asc-gen { border-left: none; }

/* Descendant tree */
.desc-node { display: flex; flex-direction: column; align-items: flex-start; }
.desc-families { display: flex; flex-direction: row; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap; }
.desc-family-block { display: flex; flex-direction: column; align-items: flex-start; }
.desc-couple { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
.desc-marriage-sym { font-size: 1.4rem; color: var(--amber); line-height: 1; user-select: none; }
.desc-children { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.6rem; padding-left: 1.5rem; padding-top: 0.25rem; padding-bottom: 0.25rem; }

/* Person card in tree */
.tree-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 150px;
  max-width: 200px;
  position: relative;
}
.tree-card:hover { border-color: var(--amber); background: var(--surface2); }
.tree-card.highlight { border-color: var(--amber); background: rgba(196,147,90,0.1); }
.tree-card.sex-M { border-left: 3px solid var(--male); }
.tree-card.sex-F { border-left: 3px solid var(--female); }
.tree-card-name { font-family: 'EB Garamond', serif; font-size: 0.85rem; color: var(--cream); line-height: 1.3; font-weight: 500; }
.tree-card-years { font-size: 0.72rem; color: var(--muted); margin-top: 0.2rem; }
.tree-more { font-size: 0.7rem; color: var(--amber); margin-top: 0.15rem; }

/* Ascendant tree couple connector */
.tree-connector { display: flex; align-items: center; }
.asc-tree .tree-couple { display: flex; flex-direction: column; gap: 4px; position: relative; }
.asc-tree .tree-couple::after {
  content: '';
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 2px;
  background: var(--border);
}
.tree-plus { font-size: 0.65rem; color: var(--muted); text-align: center; padding: 1px 0; }

/* Loading/empty states */
.state-msg { padding: 3rem 2rem; text-align: center; color: var(--muted); font-family: 'EB Garamond', serif; font-size: 1rem; }

/* ── Stats modal ── */
.stats-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.72); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.stats-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; max-width: 680px; width: 100%; max-height: 88vh; overflow-y: auto; display: flex; flex-direction: column; }
.stats-panel::-webkit-scrollbar { width: 6px; }
.stats-panel::-webkit-scrollbar-track { background: var(--surface); }
.stats-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.stats-header { padding: 1.4rem 1.5rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.stats-title { font-family: 'Playfair Display', serif; font-size: 1.25rem; color: var(--cream); margin: 0; }
.stats-subtitle { font-family: 'EB Garamond', serif; font-size: 0.88rem; color: var(--muted); margin-top: 0.3rem; }
.stats-close { background: none; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; line-height: 1; padding: 0; flex-shrink: 0; transition: color 0.15s; }
.stats-close:hover { color: var(--cream); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); }
.stat-card { background: var(--bg); padding: 1.1rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.stat-icon { font-size: 1.25rem; line-height: 1; margin-bottom: 0.25rem; }
.stat-value { font-family: 'Playfair Display', serif; font-size: 1.35rem; color: var(--amber); font-weight: 700; line-height: 1.15; }
.stat-label { font-family: 'EB Garamond', serif; font-size: 0.82rem; color: var(--cream); font-weight: 500; }
.stat-sub { font-family: 'EB Garamond', serif; font-size: 0.74rem; color: var(--muted); font-style: italic; margin-top: 0.15rem; line-height: 1.35; }
.stats-section { padding: 1rem 1.5rem; border-top: 1px solid var(--border); }
.stats-section-title { font-family: 'Playfair Display', serif; font-size: 0.72rem; letter-spacing: 0.13em; text-transform: uppercase; color: var(--amber); margin-bottom: 0.75rem; }
.stats-lex-entry { margin-bottom: 0.65rem; }
.stats-lex-term { font-family: 'EB Garamond', serif; font-size: 0.88rem; color: var(--cream); font-weight: 600; }
.stats-lex-def { font-family: 'EB Garamond', serif; font-size: 0.83rem; color: var(--muted); font-style: italic; line-height: 1.5; margin-top: 0.1rem; }

/* ── Kinship path view ── */
.path-container { padding: 1.5rem 2rem 2rem; overflow: auto; height: 100%; box-sizing: border-box; }
.path-layout { display: flex; flex-direction: column; gap: 0.6rem; }
.path-branch { display: flex; flex-direction: row; align-items: center; flex-wrap: nowrap; overflow-x: auto; gap: 0; }
.path-branch-connector { display: flex; align-items: center; gap: 0.75rem; padding: 0.1rem 0; }
.path-branch-connector::before,
.path-branch-connector::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.path-branch-connector-text { font-family: 'EB Garamond', serif; font-size: 0.72rem; color: var(--muted); font-style: italic; white-space: nowrap; }
.path-pivot-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.15rem 0; }
.path-pivot-badge { font-family: 'Playfair Display', serif; font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--amber); white-space: nowrap; flex-shrink: 0; }
.path-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.55rem 0.8rem; cursor: pointer; min-width: 130px; max-width: 190px;
  flex-shrink: 0; transition: all 0.15s;
}
.path-card:hover { border-color: var(--amber); background: var(--surface2); }
.path-card.highlight { border-color: var(--amber); background: rgba(196,147,90,0.1); }
.path-card.sex-M { border-left: 3px solid var(--male); }
.path-card.sex-F { border-left: 3px solid var(--female); }
.path-card-name { font-family: 'EB Garamond', serif; font-size: 0.85rem; color: var(--cream); line-height: 1.3; font-weight: 500; }
.path-card-life { font-size: 0.7rem; color: var(--muted); margin-top: 0.15rem; }
.path-arrow { display: flex; flex-direction: column; align-items: center; padding: 0 0.5rem; flex-shrink: 0; min-width: 60px; }
.path-arrow-label { font-family: 'EB Garamond', serif; font-size: 0.7rem; color: var(--muted); white-space: nowrap; font-style: italic; }
.path-arrow-sym { color: var(--amber); font-size: 1rem; margin-top: 0.1rem; }
.path-kinship-title { font-family: 'Playfair Display', serif; font-size: 0.92rem; color: var(--amber); font-style: italic; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); margin-bottom: 0.2rem; }
.path-summary { margin-top: 1.5rem; font-family: 'EB Garamond', serif; font-size: 0.83rem; color: var(--muted); font-style: italic; }

/* ── Path search sidebar ── */
.path-search-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.path-header-label { font-family: 'Playfair Display', serif; font-size: 0.68rem; letter-spacing: 0.13em; text-transform: uppercase; color: var(--amber); margin-bottom: 0.3rem; }
.path-person1-name { font-family: 'EB Garamond', serif; font-size: 0.9rem; color: var(--cream); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Mobile landscape: restore side-by-side layout, compact topbar height ── */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar { padding: 0.3rem 0.75rem; flex-wrap: nowrap; }
  .site-link, .topbar-sep { display: none; }
  .app-title { font-size: 0.85rem; }
  #zoom-label { display: none; }
  .lang-btn { padding: 0.18rem 0.38rem; font-size: 0.73rem; }
  #theme-toggle { padding: 0.18rem 0.32rem; font-size: 0.88rem; }
  .tree-btn.zoom-btn { padding: 0.22rem 0.45rem; }

  /* Restore 2-column layout with narrower sidebar */
  .main { grid-template-columns: 200px 1fr; grid-template-rows: unset; }
  .sidebar { max-height: none; border-right: 1px solid var(--border); border-bottom: none; }

  /* Compact tree bar */
  .tree-bar { padding: 0.3rem 0.6rem; gap: 0.3rem; }
  .tree-btn { padding: 0.25rem 0.45rem; font-size: 0.78rem; }
  .tree-bar .tree-label { display: none; }
  .depth-select { padding: 0.22rem 0.3rem; font-size: 0.78rem; }

  /* Tighter cards */
  .tree-card { min-width: 100px; max-width: 150px; padding: 0.3rem 0.45rem; }
  .tree-card-name { font-size: 0.78rem; }

  /* Detail pane */
  .person-detail { padding: 0.75rem; }
  .detail-name { font-size: 1.3rem; }
}

/* ── Mobile portrait ── */
@media (max-width: 600px) {
  /* Topbar: one compact row */
  .topbar { padding: 0.45rem 0.75rem; gap: 0.4rem; flex-wrap: nowrap; }
  .site-link, .topbar-sep { display: none; }
  .app-title { font-size: 0.88rem; }
  #zoom-label { display: none; }
  .lang-btn { padding: 0.2rem 0.4rem; font-size: 0.75rem; }
  #theme-toggle { padding: 0.2rem 0.35rem; font-size: 0.9rem; }
  .tree-btn.zoom-btn { padding: 0.25rem 0.5rem; font-size: 0.95rem; }

  /* Sidebar: cap height so content area dominates */
  .sidebar { max-height: 36vh; min-height: 110px; }

  /* Tree bar: compact, hide depth label text */
  .tree-bar { padding: 0.4rem 0.6rem; gap: 0.3rem; }
  .tree-btn { padding: 0.3rem 0.5rem; font-size: 0.78rem; }
  .tree-bar .tree-label { display: none; }
  .depth-select { padding: 0.25rem 0.3rem; font-size: 0.78rem; }

  /* Tree cards: tighter */
  .tree-card { min-width: 110px; max-width: 160px; padding: 0.35rem 0.5rem; }
  .tree-card-name { font-size: 0.8rem; }

  /* Detail pane: less padding */
  .person-detail { padding: 1rem; }
  .detail-name { font-size: 1.4rem; }
}
