/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a45;
    --bg-hover: #253555;
    --bg: #16213e;
    --text-primary: #e8e8e8;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --accent: #4a90d9;
    --accent-hover: #5ba0e9;
    --border: #2d3a52;
    --person-color: #4a90d9;
    --event-color: #e8a838;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --panel-width: 260px;
    --header-height: 52px;
    --transition: 0.2s ease;
    color-scheme: dark;
}

/* ── Light Theme ──────────────────────────────────────────── */
[data-theme="light"] {
    --bg-primary: #f5f5f0;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eaeae5;
    --bg: #f5f5f0;
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --accent: #2b6cb0;
    --accent-hover: #2c5282;
    --border: #d1d5db;
    --person-color: #2b6cb0;
    --event-color: #c07d20;
    color-scheme: light;
}
[data-theme="light"] .timeline-item.selected .item-bar,
[data-theme="light"] .timeline-item.selected .item-point {
    filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.3));
    stroke: #333;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────── */
#header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 3px solid var(--period-accent, var(--accent));
    gap: 16px;
    z-index: 100;
    transition: border-color 0.5s ease;
}

.header-left {
    display: flex;
    align-items: center;
}

.header-left h1 {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--accent);
}

.header-center {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.search-container {
    position: relative;
}

#search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

#search-input:focus {
    border-color: var(--accent);
}

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

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 200;
}

.search-dropdown.hidden { display: none; }

.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.search-result-item:hover { background: var(--bg-hover); }

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

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

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right button {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.header-right button:hover { background: var(--bg-hover); }

.year-display {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 120px;
    text-align: right;
    white-space: nowrap;
}

/* ── Layout ───────────────────────────────────────────────── */
#app {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* ── Panels ───────────────────────────────────────────────── */
.panel-left, .panel-right {
    width: var(--panel-width);
    min-width: var(--panel-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: scroll;
    padding: 12px;
    flex-shrink: 0;
}

.panel-right {
    border-right: none;
    border-left: 1px solid var(--border);
    transition: width var(--transition), min-width var(--transition), padding var(--transition);
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    z-index: 50;
    overscroll-behavior: contain;
}

.panel-right.hidden {
    width: 0;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    border: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.btn-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 4px;
}
.btn-back:hover { background: var(--bg-hover); }

.panel-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 12px;
    padding: 0;
}

.btn-link:hover { color: var(--accent-hover); }

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}

.btn-close:hover { color: var(--text-primary); }

/* ── Filter Sections ──────────────────────────────────────── */
.filter-section {
    margin-bottom: 14px;
}

.filter-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.filter-section label {
    display: block;
    font-size: 13px;
    padding: 3px 0;
    cursor: pointer;
    color: var(--text-secondary);
}

.filter-section label:hover { color: var(--text-primary); }

.filter-section input[type="checkbox"],
.filter-section input[type="radio"] {
    margin-right: 6px;
    accent-color: var(--accent);
}

.filter-section select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    line-height: 1.4;
}

.filter-section select option {
    font-size: 16px;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 8px;
}

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

/* ── Toggle Groups ────────────────────────────────────────── */
.toggle-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.toggle-btn {
    flex: 1;
    padding: 5px 4px;
    border: none;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}

.toggle-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

/* ── Active Filter Chips ──────────────────────────────────── */
.active-filters {
    margin-bottom: 12px;
    padding: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.active-filters.hidden { display: none; }

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 0 0 0 4px;
    line-height: 1;
}

.chip-remove:hover {
    color: var(--text-primary);
}

.filter-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Range Slider ─────────────────────────────────────────── */
.range-slider-container {
    padding: 0 2px;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.dual-range {
    position: relative;
    height: 20px;
}

.dual-range input[type="range"] {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    height: 20px;
    margin: 0;
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    pointer-events: auto;
    margin-top: -5px;
    border: 2px solid var(--bg-secondary);
}

.dual-range input[type="range"]::-moz-range-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    border: none;
}

.dual-range input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    pointer-events: auto;
    border: 2px solid var(--bg-secondary);
}

/* ── Checkbox Group (multi-select) ────────────────────────── */
.checkbox-group {
    max-height: 120px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px;
    background: var(--bg-card);
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 2px;
}

.checkbox-item:hover {
    background: var(--bg-hover);
}

.checkbox-item input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

/* ── Filter Tags ──────────────────────────────────────────── */
.filter-tag {
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 2px;
    background: var(--bg-hover);
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    vertical-align: middle;
    margin-left: 4px;
}

/* ── Contextual Dimming ───────────────────────────────────── */
.filter-dimmed {
    opacity: 0.35;
    pointer-events: none;
}

/* ── Legend ────────────────────────────────────────────────── */
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ── Timeline Container ──────────────────────────────────── */
#timeline-container {
    flex: 1;
    position: relative;
    overflow-x: hidden;
    overflow-y: scroll;
    background: var(--bg-primary);
    touch-action: none;
}

#timeline-svg {
    width: 100%;
    min-height: 100%;
    cursor: grab;
    display: block;
    touch-action: none;
}

#timeline-svg:active { cursor: grabbing; }

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 16px;
    text-align: center;
}

.loading-title {
    font-size: 28px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}

/* ── Skeleton Loading ─────────────────────────────────────── */
.skeleton-timeline {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
    width: 300px;
}
.skeleton-bar {
    height: 14px;
    border-radius: 7px;
    background: var(--bg-card);
}
@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}
.skeleton-pulse {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-detail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}
.skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: var(--bg-card);
}
.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 65%; }
.skeleton-line.long { width: 90%; }

/* ── Pull to Refresh ──────────────────────────────────────── */
.pull-to-refresh {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50px);
    background: var(--bg-card);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ── SVG Timeline Elements ────────────────────────────────── */
.period-band {
    opacity: 0.12;
}

.period-label {
    fill: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-anchor: middle;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.axis-line {
    stroke: var(--border);
    stroke-width: 1;
}

.tick-label {
    fill: var(--text-secondary);
    font-size: 11px;
    text-anchor: middle;
}

.timeline-item {
    cursor: pointer;
    transition: opacity 0.15s;
}

.timeline-item:hover {
    opacity: 0.85;
}

.timeline-item.selected .item-bar,
.timeline-item.selected .item-point {
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.7));
    stroke: #fff;
    stroke-width: 2;
    opacity: 1 !important;
}

.timeline-item.selected .item-label {
    fill: #fff;
    font-weight: 700 !important;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.7)); }
    50% { filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.9)); }
}

.timeline-item.selected {
    animation: pulse-glow 1.5s ease-in-out 3;
}

.item-bar {
    rx: 3;
    ry: 3;
}

.item-bar.person {
    fill: var(--person-color);
}

.item-bar.event {
    fill: var(--event-color);
}

.item-bar.approximate {
    opacity: 0.7;
    stroke-dasharray: 4 2;
    stroke-width: 1;
}

.item-bar.approximate.person {
    stroke: var(--person-color);
}

.item-bar.approximate.event {
    stroke: var(--event-color);
}

.item-label {
    fill: var(--text-primary);
    font-size: 11px;
    pointer-events: none;
    dominant-baseline: central;
}

.item-point {
    stroke-width: 2;
}

.item-point.person {
    fill: var(--person-color);
    stroke: var(--person-color);
}

.item-point.event {
    fill: var(--event-color);
    stroke: var(--event-color);
}

/* Confidence indicators */
.confidence-certain .item-bar { opacity: 1; }
.confidence-probable .item-bar { opacity: 0.85; }
.confidence-possible .item-bar { opacity: 0.65; }
.confidence-traditional .item-bar { opacity: 0.55; }

/* Significance */
.significance-major .item-bar {
    height: 20px;
}

.significance-moderate .item-bar {
    height: 17px;
}

.significance-minor .item-bar {
    height: 14px;
}

/* ── Tooltip ──────────────────────────────────────────────── */
.tooltip {
    position: absolute;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 150;
    max-width: 320px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.tooltip.hidden { display: none; }

.tooltip .tip-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.tooltip .tip-type {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tooltip .tip-dates {
    margin-top: 4px;
    color: var(--text-secondary);
}

.tooltip .tip-desc {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ── Detail Panel Content ─────────────────────────────────── */
@keyframes fade-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.detail-section {
    margin-bottom: 16px;
    animation: fade-slide-in 0.25s ease both;
}
.detail-section:nth-child(2) { animation-delay: 0.05s; }
.detail-section:nth-child(3) { animation-delay: 0.1s; }
.detail-section:nth-child(4) { animation-delay: 0.15s; }
.detail-section:nth-child(5) { animation-delay: 0.2s; }
.detail-section:nth-child(6) { animation-delay: 0.25s; }

.detail-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.detail-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: 13px;
}

.detail-meta dt {
    color: var(--text-muted);
}

.detail-meta dd {
    color: var(--text-primary);
}

.detail-description {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.detail-list {
    list-style: none;
}

.detail-list li {
    padding: 6px 8px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    color: var(--text-secondary);
    transition: color var(--transition), background var(--transition), transform 0.15s ease;
    border-radius: 4px;
}

.detail-list li:hover {
    color: var(--accent);
    background: var(--bg-hover);
}
.detail-list li:active {
    transform: scale(0.97);
}

.detail-list .list-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.date-uncertain {
    font-style: italic;
}

.confidence-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.confidence-badge.certain { background: #2d6a30; color: #7dd87f; }
.confidence-badge.probable { background: #5a5a2e; color: #d4d47a; }
.confidence-badge.possible { background: #5a3e2e; color: #d4a07a; }
.confidence-badge.traditional { background: #3a3a5a; color: #a0a0d4; }

/* ── Mobile Utilities ──────────────────────────────────────── */
.mobile-only { display: none; }
.mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 149;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.mobile-backdrop.visible {
    opacity: 1;
}
.mobile-backdrop.hidden { display: none; }

.btn-hamburger {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 8px;
}

.detail-drag-handle {
    display: none;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .panel-left { width: 200px; min-width: 200px; }
    :root { --panel-width: 200px; }
}

@media (max-width: 768px) {
    /* Show mobile elements */
    .mobile-only { display: flex; }

    /* Header: compact */
    #header {
        padding: 0 8px;
        gap: 8px;
        flex-wrap: nowrap;
    }
    .header-left h1 {
        font-size: 14px;
    }
    .tab-nav {
        margin-left: 8px;
        gap: 2px;
    }
    .tab-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    .header-center {
        display: none;
    }
    .header-right {
        gap: 4px;
    }
    .header-right button {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    .year-display {
        display: none;
    }

    /* Filter panel: off-canvas drawer */
    .panel-left {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: 280px;
        min-width: 280px;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        display: block;
    }
    .panel-left.drawer-open {
        transform: translateX(0);
    }

    /* Detail panel: bottom sheet */
    .panel-right {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        min-width: 100% !important;
        height: 55vh;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 12px 12px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 160;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .panel-right:not(.hidden) {
        transform: translateY(0);
    }
    .panel-right.hidden {
        width: 100% !important;
        min-width: 100% !important;
        transform: translateY(100%);
        padding: 0;
        border: none;
    }

    .detail-drag-handle {
        display: flex;
        justify-content: center;
        padding: 8px 0 4px;
        cursor: grab;
    }
    .detail-drag-handle span {
        width: 36px;
        height: 4px;
        background: var(--text-muted);
        border-radius: 2px;
    }

    /* Timeline gets full width */
    #app {
        height: calc(100vh - var(--header-height));
    }
    #timeline-container {
        width: 100%;
    }

    /* Touch-friendly targets — 16px minimum prevents iOS zoom on focus */
    .filter-section select,
    .filter-section input[type="range"] {
        min-height: 44px;
        font-size: 16px !important;
    }
    .filter-section select {
        padding: 10px 12px;
        border-radius: 6px;
        background: var(--bg-card);
        color: var(--text-primary);
        border: 1px solid var(--border);
        line-height: 1.4;
    }
    .filter-section select option {
        font-size: 16px !important;
        padding: 10px;
        background: var(--bg-card);
        color: var(--text-primary);
    }
    .checkbox-group {
        max-height: 160px;
    }
    .checkbox-item {
        font-size: 14px;
        padding: 6px 8px;
        min-height: 36px;
        align-items: center;
    }
    .filter-section label {
        font-size: 14px;
        padding: 4px 0;
    }
    .filter-section h3 {
        font-size: 13px;
        margin-bottom: 8px;
    }
    .filter-section input[type="checkbox"],
    .filter-section input[type="radio"] {
        width: 18px;
        height: 18px;
    }
    .toggle-group {
        flex-wrap: wrap;
    }
    .toggle-btn {
        min-height: 40px;
        padding: 8px 12px;
        font-size: 14px;
    }
    #map-person-select {
        font-size: 16px;
        min-height: 40px;
    }
    #lineage-search {
        font-size: 16px;
        min-height: 40px;
    }

    /* Lineage tab mobile */
    .lineage-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 8px 12px;
    }
    .lineage-picker {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }
    #lineage-search {
        width: 100%;
    }

    /* Map tab mobile */
    .map-header {
        padding: 8px 12px;
        gap: 8px;
    }
    .map-controls {
        flex-wrap: wrap;
        gap: 6px;
    }
    #map-person-select {
        width: 100%;
    }
    .map-slider-controls {
        min-width: unset;
    }
    .map-step-label {
        max-width: 140px;
    }
    .map-legend {
        display: none;
    }

    /* Search dropdown full-width on mobile */
    .search-dropdown {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        max-height: 50vh;
        border-radius: 0;
    }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 14px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 7px;
    border: 3px solid var(--bg-secondary);
}
::-webkit-scrollbar-thumb:hover { background: #718096; }

/* ── Scripture Links ──────────────────────────────────────── */
.scripture-link {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}
.scripture-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ── Scripture Accordion ──────────────────────────────────── */
.scripture-list { display: flex; flex-direction: column; gap: 6px; }
.scripture-accordion {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.scripture-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-card);
    border: none;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    gap: 8px;
}
.scripture-toggle:hover { background: var(--bg-hover); }
.scripture-ref-text { flex: 1; }
.scripture-chevron {
    font-size: 16px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}
.scripture-toggle[aria-expanded="true"] .scripture-chevron {
    transform: rotate(90deg);
}
.scripture-body {
    padding: 12px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}
.scripture-preview {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    margin: 0 0 8px;
    font-style: italic;
}
.scripture-read-more {
    display: inline-block;
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    margin-top: 4px;
}
.scripture-read-more:hover { text-decoration: underline; }

/* ── Tab Navigation ───────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 4px;
    margin-left: 16px;
}
.tab-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
}
.tab-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.tab-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.tab-content.hidden { display: none !important; }

/* ── Family Tree Tab ──────────────────────────────────────── */
#lineage-tab {
    position: absolute;
    top: var(--header-height);
    left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    z-index: 1;
}

.lineage-header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.lineage-picker {
    display: flex;
    align-items: center;
    gap: 10px;
}

.lineage-picker label {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}

.lineage-autocomplete {
    position: relative;
}

#lineage-search {
    width: 300px;
    padding: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
}
#lineage-search:focus {
    outline: none;
    border-color: var(--accent);
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    margin: 2px 0 0;
    padding: 0;
    list-style: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
}
.autocomplete-list.hidden { display: none; }

.autocomplete-list li {
    padding: 6px 10px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}
.autocomplete-list li:hover,
.autocomplete-list li.active {
    background: var(--accent);
    color: #fff;
}
.autocomplete-list li .ac-dates {
    color: var(--text-secondary);
    font-size: 11px;
    margin-left: 6px;
}
.autocomplete-list li:hover .ac-dates,
.autocomplete-list li.active .ac-dates {
    color: rgba(255,255,255,0.7);
}

.lineage-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 13px;
}
.lineage-info.hidden { display: none; }

#lineage-subject-name {
    font-weight: 600;
    color: var(--accent);
    font-size: 15px;
}

#lineage-count {
    color: var(--text-muted);
}

#lineage-container {
    flex: 1;
    overflow: auto;
    position: relative;
    cursor: grab;
}

.lineage-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}
.lineage-empty p { font-size: 16px; }
.lineage-hint { font-size: 13px; max-width: 400px; }

#lineage-svg {
    display: block;
}

/* Lineage tree nodes */
.lineage-link {
    fill: none;
    stroke: var(--border);
    stroke-width: 2;
    stroke-opacity: 0.6;
}

.spouse-link {
    stroke-dasharray: 6 3;
    stroke-opacity: 0.4;
}

.spouse-connector {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 4 3;
    stroke-opacity: 0.6;
}

.lineage-card {
    fill: var(--bg-card);
    stroke: var(--border);
    stroke-width: 1.5;
}

.lineage-node.spouse .lineage-card {
    stroke-dasharray: 4 2;
}

.lineage-node:hover .lineage-card {
    fill: var(--bg-hover);
    stroke: var(--accent);
}

.lineage-node.subject .lineage-card {
    fill: var(--bg-hover);
    stroke: var(--accent);
    stroke-width: 2.5;
    filter: drop-shadow(0 0 6px rgba(74, 144, 217, 0.4));
}

.lineage-name {
    fill: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
}

.lineage-dates {
    fill: var(--text-secondary);
    font-size: 11px;
}

.lineage-role {
    fill: var(--text-muted);
    font-size: 10px;
    text-transform: capitalize;
}

/* ── Map Tab ──────────────────────────────────────────────── */
#map-tab {
    position: absolute;
    top: var(--header-height);
    left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    z-index: 10;
    overflow: hidden;
}

.map-header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.map-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.map-controls label {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}

#map-person-select {
    width: 240px;
    padding: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
}
#map-person-select:focus {
    outline: none;
    border-color: var(--accent);
}

.map-slider-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 300px;
}

.map-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    flex-shrink: 0;
}
.map-btn:hover { background: var(--bg-hover); }
.map-btn.map-speed { font-size: 12px; font-weight: 600; width: 36px; }

.map-step-label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
    flex-shrink: 1;
}

#map-year-slider {
    flex: 1;
    height: 6px;
    accent-color: var(--accent);
    cursor: pointer;
}

#map-year-label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 80px;
    text-align: right;
    white-space: nowrap;
}

.map-legend {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted);
}
.map-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255,255,255,0.3);
}

#map-container {
    flex: 1;
    z-index: 1;
}

/* Leaflet popup overrides for dark theme */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.leaflet-popup-tip { background: var(--bg-card); }
.leaflet-popup-content { margin: 10px 14px; font-size: 13px; line-height: 1.5; }

/* Map tooltip (hover label) */
.map-tooltip {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    white-space: nowrap;
}
.map-tooltip::before {
    border-top-color: var(--border) !important;
}

.map-popup strong { color: var(--text-primary); }
.map-popup-meta { color: var(--text-secondary); font-size: 12px; }
.map-popup-loc { color: var(--text-muted); font-size: 12px; }
.map-popup-cat {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: capitalize;
    margin-top: 2px;
}

/* Journey step labels */
.journey-step-label {
    background: transparent !important;
    border: none !important;
}
.journey-step-label span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Journey pulse marker */
.journey-pulse {
    background: transparent !important;
    border: none !important;
}
.journey-pulse::before {
    content: '';
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.5;
    animation: pulse-ring 1.5s ease-out infinite;
}
@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* Detail panel mini-map */
.detail-mini-map {
    width: 100%;
    height: 180px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

/* Leaflet dark theme container */
.leaflet-container {
    background: var(--bg-primary);
}

/* ── Bottom Navigation Bar ──────────────────────────────────── */
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 200;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .bottom-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 10px;
        font-family: var(--font-family);
        cursor: pointer;
        padding: 6px 0;
        position: relative;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.2s ease, transform 0.1s ease;
    }
    .bottom-nav-btn:active {
        transform: scale(0.9);
    }
    .bottom-nav-btn svg {
        width: 22px;
        height: 22px;
    }
    .bottom-nav-btn.active {
        color: var(--accent);
    }
    .bottom-nav-btn.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background: var(--accent);
        border-radius: 0 0 3px 3px;
    }

    /* Hide header tab nav on mobile, show bottom nav instead */
    .tab-nav { display: none !important; }

    /* Account for bottom nav in layouts */
    :root { --bottom-nav-height: 60px; }
    #app { height: calc(100vh - var(--header-height) - var(--bottom-nav-height)); }
    #lineage-tab { bottom: var(--bottom-nav-height); }
    #map-tab { bottom: var(--bottom-nav-height); }
    #saved-tab { bottom: var(--bottom-nav-height); }
    .search-overlay { bottom: var(--bottom-nav-height); }

    /* Compact map header on mobile */
    .map-header {
        padding: 6px 10px;
        gap: 6px;
    }
    .map-slider-controls {
        min-width: 0;
        gap: 6px;
    }
    .map-legend { display: none; }
    #map-person-select { width: 100%; }
    .panel-right:not(.hidden) {
        bottom: var(--bottom-nav-height);
        height: calc(55vh - var(--bottom-nav-height) / 2);
    }
    .panel-left { bottom: var(--bottom-nav-height); }
}

/* ── Mobile Search Overlay ────────────────────────────────── */
.search-overlay {
    position: fixed;
    top: 0; left: 0; right: 0;
    bottom: var(--bottom-nav-height, 0px);
    background: var(--bg-primary);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.search-overlay.hidden {
    display: none;
}
.search-overlay-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.search-overlay-header input {
    flex: 1;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-family);
    outline: none;
}
.search-overlay-header input:focus {
    border-color: var(--accent);
}
.search-overlay-header .btn-close {
    width: 44px;
    height: 44px;
    font-size: 24px;
}
.mobile-search-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
}
.mobile-search-results .search-result-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.mobile-search-results .search-result-item:active {
    background: var(--bg-hover);
}
.recent-searches {
    padding: 16px;
}
.recent-searches h3 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.recent-searches ul {
    list-style: none;
}
.recent-searches li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
}
.recent-searches li:active {
    color: var(--accent);
}

/* ── Saved / Bookmarks ───────────────────────────────────── */
#saved-tab {
    position: absolute;
    top: var(--header-height);
    left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    z-index: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.saved-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.saved-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.saved-list {
    list-style: none;
    padding: 0;
}
.saved-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.saved-item:active {
    background: var(--bg-hover);
}
.saved-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.saved-item-icon.person { background: rgba(74, 144, 217, 0.2); color: var(--person-color); }
.saved-item-icon.event { background: rgba(232, 168, 56, 0.2); color: var(--event-color); }
.saved-item-info {
    flex: 1;
    min-width: 0;
}
.saved-item-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.saved-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
}
.saved-item-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
}
.saved-item-remove:hover { color: #e53e3e; }

/* Bookmark button in detail panel */
.btn-bookmark {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
}
.btn-bookmark.bookmarked {
    color: var(--accent);
    border-color: var(--accent);
}
.btn-bookmark:hover { color: var(--accent); }

/* ── Theme Toggle ─────────────────────────────────────────── */
.btn-theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}
.btn-theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Era Scrubber ─────────────────────────────────────────── */
.era-scrubber {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    z-index: 40;
    padding: 4px 0;
    background: rgba(22, 33, 62, 0.85);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.era-scrubber-item {
    padding: 3px 6px;
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    letter-spacing: 0.5px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
    user-select: none;
}
.era-scrubber-item.active {
    color: var(--accent);
}
.era-scrubber-item:active {
    transform: scale(1.3);
}
