body:has(.family-tree-page) .site-main {
    padding: 0.6rem 0 0;
}

.family-tree-page {
    height: calc(100dvh - 86px);
    min-height: 28rem;
    padding: 0 1rem 0.75rem;
}

.family-tree-gate-page {
    min-height: calc(100vh - 160px);
    display: grid;
    align-items: center;
}

.family-tree-gate-card {
    max-width: 32rem;
}

.family-tree-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    border: 1px solid var(--color-border-primary);
    border-radius: 0.75rem;
    background: var(--color-bg-primary, #0d1117);
}

.family-tree-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--color-border-primary);
}

.family-tree-toolbar h1 {
    font-size: 1.15rem;
    margin: 0 0.5rem 0 0;
    white-space: nowrap;
}

.family-tree-search {
    position: relative;
    flex: 1 1 12rem;
    max-width: 28rem;
}

.family-tree-search input {
    color: var(--color-text-primary);
    background: #161b22;
    border-color: var(--color-border-primary);
}

.family-tree-search input:focus {
    color: var(--color-text-primary);
    background: #161b22;
    border-color: #72a99f;
    box-shadow: 0 0 0 2px #72a99f33;
}

.family-tree-search-results {
    position: absolute;
    z-index: 20;
    top: calc(100% + 0.4rem);
    left: 0;
    width: max(100%, 20rem);
    max-width: calc(100vw - 3rem);
    max-height: 23rem;
    overflow-y: auto;
    border: 1px solid var(--color-border-primary);
    border-radius: 0.5rem;
    background: #161b22;
    padding: 0.4rem;
    box-shadow: 0 15px 40px #0008;
}

.family-tree-search-results button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--color-text-primary);
    padding: 0.7rem;
    border-radius: 0.3rem;
}

.family-tree-search-results span {
    display: block;
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    margin-top: 0.2rem;
}

.family-tree-search-results button:hover,
.family-tree-search-results [aria-selected="true"] {
    background: #293943;
}

.family-tree-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}
.family-tree-zoom-controls {
    display: inline-flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 0.35rem;
}
.family-tree-controls button:disabled { opacity: 0.4; cursor: default; }

.family-tree-controls button,
.family-tree-controls a,
.family-tree-panel-actions button {
    border: 1px solid var(--color-border-primary);
    background: transparent;
    color: var(--color-text-primary);
    border-radius: 0.35rem;
    font-size: 0.8rem;
    padding: 0.45rem 0.65rem;
    text-decoration: none;
}

.family-tree-shell button:hover,
.family-tree-document-dialog button:hover {
    background-color: #24313b;
}

.family-tree-shell button:focus-visible,
.family-tree-document-dialog button:focus-visible,
.family-tree-shell summary:focus-visible {
    outline: 2px solid #9fd4c7;
    outline-offset: 2px;
}

.family-tree-status {
    padding: 0.4rem 1rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.family-tree-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    flex: 1;
    min-height: 0;
}

.family-tree-workspace.has-profile {
    grid-template-columns: minmax(0, 1fr) clamp(25rem, 36vw, 36rem);
}

.family-tree-viewport {
    overflow: auto;
    min-height: 0;
    overscroll-behavior: contain;
    cursor: grab;
    background: radial-gradient(circle at top, #24383844, transparent 50%), #10161d;
}

.family-tree-viewport.is-panning {
    cursor: grabbing;
    user-select: none;
}

.family-tree-stage,
.family-tree-canvas {
    position: relative;
}

.family-tree-canvas {
    transform-origin: 0 0;
}

.family-tree-connectors,
.family-tree-rows {
    position: absolute;
    inset: 0;
}

.family-tree-connectors {
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.family-tree-connectors line {
    stroke: #677583;
    stroke-width: 2;
    fill: none;
}

.family-tree-connectors .is-on-path {
    stroke: #d9b87b;
    stroke-width: 4;
}

.family-tree-rows { z-index: 1; }

.family-node {
    position: absolute;
    height: 100px;
    border: 1px solid #52606d;
    border-left: 4px solid #52606d;
    border-radius: 0.6rem;
    background: #1a232d;
    color: var(--color-text-primary);
    padding: 0.8rem;
    text-align: left;
    box-shadow: 0 4px 12px #0003;
}

.family-node[data-branch="maternal"] { border-left-color: #83b2a5; }
.family-node[data-branch="paternal"] { border-left-color: #8caaca; }
.family-node.is-on-path { border-color: #c2a578; }
.family-node.is-selected { outline: 3px solid #e1c38c; outline-offset: 3px; }

.family-node-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 650;
    line-height: 1.2;
}

.family-node-meta {
    display: block;
    color: var(--color-text-secondary);
    margin-top: 0.35rem;
    font-size: 0.8rem;
}

.family-node-image {
    float: right;
    width: 36px;
    height: 36px;
    margin: 0 0 0.3rem 0.5rem;
    border-radius: 50%;
    object-fit: cover;
    object-position: top;
}

.family-tree-panel {
    overflow-y: auto;
    overscroll-behavior: contain;
    min-height: 0;
    border-left: 1px solid var(--color-border-primary);
    background: #11171e;
    scrollbar-gutter: stable;
}

.family-tree-panel-actions {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #11171ef5;
    border-bottom: 1px solid var(--color-border-primary);
    z-index: 2;
}

.family-tree-panel-content { padding: 1.25rem 1.5rem 3rem; }
.family-tree-panel-content section { margin-bottom: 1.8rem; }
.family-tree-panel-content h2 { font-size: 1.6rem; line-height: 1.2; }
.family-tree-panel-content h3 { font-size: 1.05rem; margin-bottom: 0.9rem; }
.family-tree-panel-content h4 { font-size: 0.9rem; }
.family-tree-panel-content p { line-height: 1.65; }
.family-tree-section-label { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.65rem; color: #9bc8ba; }
#familyTreePanelSubtitle { font-size: 0.85rem; color: var(--color-text-secondary); }
#familyTreePanelSummary { font-size: 0.95rem; }
.family-tree-panel-image-wrap { float: right; margin: 0 0 1rem 1rem; }
.family-tree-panel-image { width: 80px; height: 95px; object-fit: cover; border-radius: 0.5rem; }
#familyTreePanelFamily { display: grid; gap: 0.8rem; }
#familyTreePanelFamily h4 { color: var(--color-text-secondary); font-size: 0.75rem; margin: 0 0 0.4rem; }
#familyTreePanelFamily button {
    display: block;
    width: 100%;
    text-align: left;
    margin-top: 0.3rem;
    border: 1px solid #33424d;
    border-radius: 0.4rem;
    background: #1a232d;
    color: var(--color-text-primary);
    font-size: 0.85rem;
    padding: 0.65rem;
}

.family-tree-events { list-style: none; margin: 0; padding: 0 0 0 0.9rem; border-left: 1px solid #40594f; }
.family-tree-events li { margin-bottom: 1rem; position: relative; }
.family-tree-events li::before { content: ""; position: absolute; top: 0.4rem; left: -1.15rem; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: #9bc8ba; }
.family-tree-event-year { font-size: 0.7rem; color: #9bc8ba; }
.family-tree-events p, #familyTreePanelNotes p { font-size: 0.9rem; margin-bottom: 0.2rem; }
.family-tree-citations { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.72rem; }
.family-tree-citations a { color: #91b5cc; text-decoration-color: #91b5cc55; }
.family-tree-attribution { color: #a5b4bf; font-size: 0.8rem; }
#familyTreePanelStories { font-family: Georgia, serif; font-size: 1rem; }
#familyTreePanelStories p { white-space: pre-line; line-height: 1.8; }
.family-tree-documents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.family-tree-documents button { padding: 0; border: 1px solid #33424d; border-radius: 0.4rem; background: #1a232d; color: var(--color-text-primary); text-align: left; overflow: hidden; }
.family-tree-documents img { width: 100%; height: 105px; object-fit: cover; object-position: top; }
.family-tree-documents span { display: block; padding: 0.6rem; font-size: 0.75rem; line-height: 1.4; }
.family-tree-documents strong { display: block; padding: 0.6rem 0.6rem 0; font-size: 0.85rem; }
#familyTreeDocumentCaption { color: var(--color-text-secondary); font-size: 0.85rem; }
.family-tree-panel-content details { padding: 1rem 0; border-top: 1px solid var(--color-border-primary); }
.family-tree-panel-content summary { cursor: pointer; font-size: 0.9rem; }
.family-tree-panel-content details ul { padding-left: 1rem; margin-top: 1rem; }
.family-tree-panel-content details li { margin-bottom: 0.9rem; font-size: 0.85rem; }
.family-tree-document-dialog { width: 94vw; height: 94dvh; max-width: 1500px; max-height: 96dvh; padding: 0; border: 1px solid #52606d; border-radius: 0.6rem; background: #11171e; color: var(--color-text-primary); }
.family-tree-document-dialog[open] { display: flex; flex-direction: column; }
.family-tree-document-dialog::backdrop { background: #000c; }
.family-tree-document-dialog header { padding: 1rem; border-bottom: 1px solid #33424d; }
.family-tree-document-dialog h2 { font-size: 1rem; margin-bottom: 0.75rem; }
.family-tree-document-viewport { overflow: auto; flex: 1; min-height: 0; }
.family-tree-document-viewport img { display: block; width: 100%; max-width: none; height: auto; }
.family-tree-error { padding: 1rem; color: #efa797; }
.family-tree-feedback {
    position: sticky;
    top: 1rem;
    left: 1rem;
    z-index: 3;
    max-width: 32rem;
    margin: 1rem;
    padding: 1rem;
    border: 1px solid #b49b70;
    border-radius: 0.5rem;
    background: #1a232d;
    color: var(--color-text-primary);
}
.family-tree-feedback p { margin-bottom: 0.5rem; }
.family-tree-feedback a { color: #9fd4c7; }
.family-tree-shell [hidden] { display: none !important; }

@media (max-width: 767px) {
    .family-tree-page { padding: 0 0.4rem 0.4rem; height: calc(100dvh - 100px); }
    .family-tree-toolbar { padding: 0.6rem; gap: 0.6rem; }
    .family-tree-toolbar h1 { font-size: 1rem; }
    .family-tree-search { max-width: none; }
    .family-tree-controls { width: 100%; }
    .family-tree-workspace.has-profile { grid-template-columns: minmax(0, 1fr); }
    .family-tree-panel { position: fixed; inset: 0; z-index: 1100; height: 100dvh; border: 0; }
    .family-tree-panel-content { padding: 1rem 1.25rem 3rem; }
    body.family-profile-open { overflow: hidden; }
    .family-tree-panel-actions { padding-top: max(0.75rem, env(safe-area-inset-top)); }
    .family-tree-panel-actions button { min-height: 44px; }
    .family-tree-document-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; border: 0; border-radius: 0; }
}
