:root {
    /* Tree Specific Overrides */
    --bg-node: #974807;
    --bg-node-female: #60497B;
    --bg-node-deceased: #444;
    
    /* Lineage Colors (Yagati Mode) */
    --bg-node-yagati: #2e7d32; /* Rich Green */
    --bg-node-non-yagati: #455a64; /* Slate Grey */
    
    --text-male: #80ff80;
    --text-female: #ffff00;
    --line-color: #888;
    --hover-glow: rgba(255, 128, 0, 0.3);
    --accent: var(--accent-primary);
}

/* Lineage Mode Overrides */
.tree-container.mode-lineage .node-card.is-yagati,
.tree-container.mode-lineage .node-card.is-yagati.female {
    background: var(--bg-node-yagati) !important;
}

.tree-container.mode-lineage .node-card:not(.is-yagati) {
    background: var(--bg-node-non-yagati) !important;
}

/* Bloodline Filter Mode */
.tree-container.filter-bloodline li[data-bloodline="0"] {
    display: none !important;
}

.tree-container.filter-bloodline .spouse-photo-link[data-bloodline="0"],
.tree-container.filter-bloodline .spouse-name[data-bloodline="0"],
.tree-container.filter-bloodline .primary-photo-link[data-bloodline="0"],
.tree-container.filter-bloodline .primary-name[data-bloodline="0"] {
    display: none !important;
}

/* Count Toggles */
.count-bloodline { display: none; }
.tree-container.filter-bloodline .count-all { display: none; }
.tree-container.filter-bloodline .count-bloodline { display: inline; }

/* Print Styles */
@media print {
    #page-header, .controls, .legend, footer, .toggle-btn, .no-print { display: none !important; }
    body { background: white; color: black; }
    .tree-container { padding: 0; overflow: visible; }
    .tree li { page-break-inside: avoid; }
    .tree li.collapsed > ul { display: flex !important; }
    .node-card { background: #f5f5f5 !important; border: 1px solid #333 !important; }
    .name, .spouse-name { color: #333 !important; }
    .years { color: #666 !important; }
    .photo { border-color: #333 !important; }
}

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

body {
    /* Inherit from global theme */
    min-height: 100vh;
}

/* Tree Controls Override (if needed to match theme card) */
.controls {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    padding: 15px 20px;
}

/* ... existing tree styles ... */


/* Controls */
.controls {
    background: var(--bg-card);
    padding: 15px 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.controls-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.settings-toggle {
    display: none;
    padding: 8px 16px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.settings-toggle:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--text-muted);
}

.settings-toggle.active {
    background: var(--accent);
    color: var(--bg-dark);
}

.controls-settings {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-dark);
}

.btn-primary:hover {
    background: #ff9920;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #666;
}

.stats {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 14px;
}

/* Tree Container */
.tree-container {
    padding: 20px;
    overflow-x: auto;
}

/* Tree Structure */
.tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: fit-content;
}

.tree ul {
    padding-top: 20px;
    position: relative;
    transition: all 0.3s;
    display: flex;
    justify-content: center;
}

.tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.3s;
}

/* Connector Lines */
.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 3px solid var(--line-color);
    width: 50%;
    height: 20px;
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: 3px solid var(--line-color);
}

.tree li:only-child::before {
    display: none;
}

.tree li:only-child::after {
    /* Keep vertical line to parent for only-child */
    border-top: none;
}

.tree li:only-child {
    padding-top: 20px;
}

.tree li:first-child::before,
.tree li:last-child::after {
    border: 0 none;
}

.tree li:last-child::before {
    border-right: 3px solid var(--line-color);
    border-radius: 0 5px 0 0;
}

.tree li:first-child::after {
    border-radius: 5px 0 0 0;
}

/* Parent to children connector (vertical line from parent down) */
.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 3px solid var(--line-color);
    width: 0;
    height: 20px;
}

/* Node Card */
.node {
    display: inline-block;
    padding: 0;
    text-decoration: none;
    position: relative;
}

.node-card {
    background: var(--bg-node);
    border-radius: 8px;
    padding: 10px;
    min-width: 140px;
    max-width: 180px;
    transition: all 0.3s;
    border: 2px solid transparent;
    position: relative;
}

.node-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px var(--hover-glow);
    border-color: var(--accent);
}

.node-card.female {
    background: var(--bg-node-female);
}

.node-card.deceased {
    opacity: 0.7;
}

.node-card.deceased::after {
    content: '✝';
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.photos {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 8px;
}

.photo {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--text-male);
}

.photo.female {
    border-color: var(--text-female);
}

.photo-placeholder {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--border-color);
}

.names {
    text-align: center;
}

.name {
    font-size: 12px;
    font-weight: 600;
    display: block;
    color: var(--text-male);
    text-decoration: none;
    margin-bottom: 2px;
}

.name:hover {
    text-decoration: underline;
}

.name.female {
    color: var(--text-female);
}

.spouse-name {
    font-size: 11px;
    color: var(--text-female);
    display: block;
}

.spouse-name.male {
    color: var(--text-male);
}

.years {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Toggle Button - CIRCLE */
.toggle-btn {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    max-width: 24px;
    max-height: 24px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg-dark);
    border: 2px solid var(--bg-dark);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
    line-height: normal; /* Better for vertical centering with flex */
    padding: 0;
    margin: 0; /* reset margin just in case */
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box; /* Explicitly set */
}

.toggle-btn:hover {
    background: #ff9920;
    transform: translateX(-50%) scale(1.1);
}

.toggle-btn.collapsed {
    background: var(--border-color);
}

/* Collapsed State */
.tree li.collapsed > ul {
    display: none;
}

.tree li.collapsed > .node .toggle-btn {
    background: var(--border-color);
}

/* Children Count Badge - TOP RIGHT */
.children-count {
    position: absolute;
    top: -10px;
    right: -10px;
    background: var(--accent);
    color: var(--bg-dark);
    font-size: 11px;
    font-weight: bold;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-dark);
}

/* Legend */
.legend {
    display: flex;
    gap: 20px;
    justify-content: center;
    padding: 15px;
    flex-wrap: wrap;
    font-size: 13px;
}

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

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: 30px;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    nav {
        justify-content: center;
    }
    
    .controls-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .search-box {
        flex: 1;
        max-width: calc(100% - 110px);
    }
    
    .settings-toggle {
        display: flex !important;
        margin-left: auto;
    }
    
    .controls-settings {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        background: rgba(0,0,0,0.3);
        padding: 15px;
        border-radius: 12px;
        margin-top: 10px;
        gap: 15px;
        border: 1px solid var(--border-color);
        order: 10;
    }
    
    .controls-settings.active {
        display: flex;
    }

    .gen-filter {
        justify-content: space-between;
    }
    
    .view-toggle, .tree-actions {
        justify-content: center;
        width: 100%;
    }

    .theme-toggle-container .btn-minimal {
        width: 100%;
        justify-content: center;
    }

    .stats {
        width: 100%;
        text-align: center;
        order: 11;
        margin-top: 5px;
    }
    
    .tree li {
        padding: 15px 3px 0 3px;
    }
    
    .node-card {
        min-width: 100px;
        padding: 8px;
    }
    
    .photo {
        width: 35px;
        height: 35px;
    }
    
    .name {
        font-size: 10px;
    }
    
    .spouse-name {
        font-size: 9px;
    }
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* View Toggle */
/* View Toggle & Tree Actions Boxes */
.view-toggle,
.tree-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-dark);
    padding: 6px 12px;
    border-radius: 30px; /* Pill shape */
    border: 1px solid var(--border-color);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.view-toggle button,
.tree-actions button {
    padding: 6px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px; /* Rounded rectangle / Pill shape */
    cursor: pointer;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.05); /* Subtle background to define shape */
    color: var(--text-muted);
    transition: all 0.2s;
    white-space: nowrap;
}



.view-toggle button.active {
    background: var(--accent);
    color: var(--bg-dark); /* Ensure text is readable on accent bg */
}

.view-toggle button:hover:not(.active),
.tree-actions button:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--text-muted);
}

/* Vertical Tree Styles */
.tree-container.vertical {
    max-width: 900px;
    margin: 0 auto;
}

.tree-container.vertical .tree {
    flex-direction: column;
    align-items: flex-start;
    padding-left: 20px;
}

.tree-container.vertical .tree ul {
    flex-direction: column;
    align-items: flex-start;
    padding-top: 0;
    padding-left: 50px;
    margin-top: 25px;
    position: relative;
}

/* Note: Parent-to-children connector is now handled by first-child::after extending up */
.tree-container.vertical .tree ul ul::before {
    display: none;
}

.tree-container.vertical .tree > ul {
    padding-left: 0;
}

.tree-container.vertical .tree li {
    display: flex;
    flex-direction: column;
    padding: 15px 0 15px 40px;
    position: relative;
}

/* Horizontal connector from vertical line to node */
.tree-container.vertical .tree li::before {
    content: '';
    position: absolute;
    top: 35px;
    left: 0;
    width: 40px;
    height: 0;
    border-top: 3px solid var(--line-color);
    border-left: none;
    border-right: none;
}

/* Vertical line alongside siblings */
.tree-container.vertical .tree li::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    border-top: none;
    border-left: 3px solid var(--line-color);
}

/* Last child - vertical line stops at connector */
.tree-container.vertical .tree li:last-child::after {
    height: 35px;
}

/* Only child still needs connectors */
.tree-container.vertical .tree li:only-child::before,
.tree-container.vertical .tree li:only-child::after {
    display: block !important;
}

/* Remove horizontal tree corner artifacts */
.tree-container.vertical .tree li:last-child::before {
    border-right: none;
    border-radius: 0;
}

/* First child - extend vertical line UP to parent node */
.tree-container.vertical .tree li:first-child::after {
    border-radius: 0;
    top: -25px;
    height: calc(100% + 25px);
}

/* Only child - vertical line connects to parent only */
.tree-container.vertical .tree li:first-child:last-child::after {
    height: 60px;
    top: -25px;
}

/* Root level - no connectors */
/* Root level - no connectors */
.tree-container.vertical .tree > ul > li::before,
.tree-container.vertical .tree > ul > li::after,
.tree-container.vertical .tree > ul > li:first-child::before,
.tree-container.vertical .tree > ul > li:first-child::after,
.tree-container.vertical .tree > ul > li:only-child::before,
.tree-container.vertical .tree > ul > li:only-child::after {
    display: none !important;
}

.tree-container.vertical .tree > ul > li {
    padding-left: 0;
}

.tree-container.vertical .node {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tree-container.vertical .node-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    min-width: 200px;
    max-width: 350px;
}

.tree-container.vertical .photos {
    margin-bottom: 0;
    flex-shrink: 0;
}

.tree-container.vertical .names {
    text-align: left;
}

.tree-container.vertical .toggle-btn {
    position: static;
    transform: none;
    margin-left: 5px;
    flex-shrink: 0;
}

.tree-container.vertical .children-count {
    top: -10px;
    right: -10px;
    transform: none;
}

/* Loading animation */
.loading {
    text-align: center;
    padding: 50px;
    font-size: 18px;
    color: var(--text-muted);
}

/* Search Box */
.search-box {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 10px 40px 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--hover-glow);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box .clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    display: none;
}

.search-box .clear-btn.visible {
    display: block;
}

/* Highlight search result */
.node-card.highlight {
    border: 3px solid #00ff00 !important;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5) !important;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 5px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

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

.search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.search-result-item:hover {
    background: rgba(255, 128, 0, 0.2);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item .member-name {
    font-weight: 600;
    color: var(--text-primary);
}

.search-result-item .member-name.male { color: var(--text-male); }
.search-result-item .member-name.female { color: var(--text-female); }

.search-result-item .member-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Generation Filter */
.gen-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gen-filter label {
    color: var(--text-muted);
    font-size: 14px;
}

.gen-filter select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
}

.gen-filter select:focus {
    border-color: var(--accent);
}
    
