/* ========================================
   CSS Variables - Dark Mode (Default)
   ======================================== */
:root {
    /* Background colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --bg-card: #161b22;

    /* Text colors */
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --text-accent: #58a6ff;

    /* Border colors */
    --border-color: #30363d;
    --border-light: #484f58;

    /* Accent colors */
    --accent-primary: #3498db;
    --accent-hover: #2980b9;
    --accent-glow: rgba(52, 152, 219, 0.3);

    /* UI element colors */
    --input-bg: #161b22;
    --button-text: #ffffff;
    --card-shadow: rgba(0, 0, 0, 0.3);

    /* Tradition badge backgrounds (20% opacity) */
    --badge-bg-hermetic: rgba(80, 200, 120, 0.2);
    --badge-bg-gnostic: rgba(155, 89, 182, 0.2);
    --badge-bg-kabbalistic: rgba(255, 68, 68, 0.2);
    --badge-bg-ancient-egyptian: rgba(212, 175, 55, 0.2);
    --badge-bg-hindu: rgba(255, 85, 0, 0.2);
    --badge-bg-tibetan-buddhist: rgba(255, 20, 147, 0.2);
    --badge-bg-buddhist: rgba(152, 251, 152, 0.2);
    --badge-bg-zoroastrian: rgba(255, 107, 107, 0.2);
    --badge-bg-greek: rgba(65, 105, 225, 0.2);
    --badge-bg-western-esoteric: rgba(74, 118, 110, 0.2);
    --badge-bg-channeled-material: rgba(233, 30, 99, 0.2);
    --badge-bg-taoist: rgba(26, 188, 156, 0.2);
    --badge-bg-sufi: rgba(255, 112, 67, 0.2);
    --badge-bg-christian-mysticism: rgba(186, 85, 211, 0.2);
    --badge-bg-jewish-apocrypha: rgba(0, 206, 209, 0.2);
    --badge-bg-neoplatonic: rgba(121, 134, 203, 0.2);
}

/* Light mode variables */
html.light-mode {
    /* Background colors */
    --bg-primary: #f7f9fc;
    --bg-secondary: #eef1f5;
    --bg-tertiary: #d9e0e8;
    --bg-hover: #d3dbe5;
    --bg-card: #eef1f5;

    /* Text colors */
    --text-primary: #1a1a1a;
    --text-secondary: #5f6772;
    --text-muted: #6f7884;
    --text-accent: #3498db;

    /* Border colors */
    --border-color: #ccd4de;
    --border-light: #bec8d5;

    /* Accent colors */
    --accent-primary: #2f84c2;
    --accent-hover: #266fa4;
    --accent-glow: rgba(47, 132, 194, 0.28);

    /* UI element colors */
    --input-bg: #ffffff;
    --button-text: #ffffff;
    --card-shadow: rgba(10, 22, 40, 0.12);

    /* Tradition badge backgrounds */
    --badge-bg-hermetic: rgba(80, 200, 120, 0.2);
    --badge-bg-gnostic: rgba(155, 89, 182, 0.2);
    --badge-bg-kabbalistic: rgba(255, 68, 68, 0.2);
    --badge-bg-ancient-egyptian: rgba(212, 175, 55, 0.2);
    --badge-bg-hindu: rgba(255, 85, 0, 0.2);
    --badge-bg-tibetan-buddhist: rgba(255, 20, 147, 0.2);
    --badge-bg-buddhist: rgba(152, 251, 152, 0.2);
    --badge-bg-zoroastrian: rgba(255, 107, 107, 0.2);
    --badge-bg-greek: rgba(65, 105, 225, 0.2);
    --badge-bg-western-esoteric: rgba(74, 118, 110, 0.2);
    --badge-bg-channeled-material: rgba(233, 30, 99, 0.2);
    --badge-bg-taoist: rgba(26, 188, 156, 0.2);
    --badge-bg-sufi: rgba(255, 112, 67, 0.2);
    --badge-bg-christian-mysticism: rgba(186, 85, 211, 0.2);
    --badge-bg-jewish-apocrypha: rgba(0, 206, 209, 0.2);
    --badge-bg-neoplatonic: rgba(121, 134, 203, 0.2);
}

/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 0 20px 40px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto;
    align-items: flex-start;
}

/* Sidebar */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent-primary);
}

.concepts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.concept-section-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 12px;
    margin-bottom: 4px;
    padding-left: 4px;
}

.concept-section-header:first-child {
    margin-top: 0;
}

.concept-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 10px 16px;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    font-family: inherit;
}

.concept-btn:hover {
    border-radius: 4px;
    background: var(--accent-primary);
    color: var(--button-text);
    border-color: var(--accent-primary);
    transform: translateX(4px);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.concept-btn.active {
    border-radius: 4px;
    background: var(--accent-primary);
    color: var(--button-text);
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* Main content */
.main-content {
    flex: 1;
    min-width: 0;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Search section */
.search-section {
    max-width: 1100px;
    margin: 0 auto 16px;
}

/* Search input */
.search-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-input-group input {
    flex: 1;
    padding: 12px 16px;
    font-size: 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--input-bg);
    color: var(--text-primary);
}

.search-input-group input:focus {
    border-color: var(--accent-primary);
}

html.light-mode .search-input-group input {
    color: var(--text-primary);
}

html.light-mode .search-input-group input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.search-input-group button {
    padding: 12px 24px;
    font-size: 16px;
    background: var(--accent-primary);
    color: var(--button-text);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-input-group button:hover {
    background: var(--accent-hover);
}

/* Options section */
.options {
    background: var(--bg-card);
    padding: 16px 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.search-modes,
.tradition-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.tradition-filters {
    gap: 8px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-bottom: 0;
}

.tradition-filter-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.search-tradition-filters .tradition-filter-controls {
    width: auto;
}

.search-tradition-filters .filter-source-heading {
    width: 100%;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.search-tradition-filters .source-filter-inline {
    margin-left: 10px;
}

/* Keep tradition filter vertical metrics identical across Search and Browse */
.search-tradition-filters .filter-source-heading,
.search-tradition-filters .tradition-pill-list {
    margin-top: 0;
    margin-bottom: 0;
}

.search-tradition-filters .tradition-filter-controls,
.search-tradition-filters .source-filter-inline {
    min-height: 24px;
}

.search-tradition-filters .tradition-filter-controls .tradition-toggle-btn,
.search-tradition-filters .source-filter-inline .tradition-toggle-btn,
.search-tradition-filters .source-filter-inline select {
    box-sizing: border-box;
    height: 24px;
    line-height: 1;
}

.search-tradition-filters .source-filter-inline select {
    padding-top: 0;
    padding-bottom: 0;
}

/* Prevent hidden tradition inputs from creating an extra grid row on Search */
.search-tradition-filters #tradition-hidden-inputs {
    display: none;
}

.tradition-filter-controls .label {
    margin-right: 4px;
}

.traditions-mobile-toggle {
    display: none;
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.traditions-mobile-toggle:hover {
    border-color: #58a6ff;
    color: #58a6ff;
}

.tradition-checkbox-list {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.tradition-checkbox-list .checkbox-label {
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.tradition-pill-list {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* Tradition pills and badges - gradient rect style */
.tradition-card-pill,
.tradition-filter-pill,
.tradition-pill {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 4px !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    border: 0.5px solid rgba(var(--tradition-rgb), 0.35);
    background: linear-gradient(
        to top right,
        rgba(var(--tradition-rgb), 0.72) 0%,
        rgba(var(--tradition-rgb), 0.38) 22%,
        rgba(var(--tradition-rgb), 0.10) 55%,
        rgba(var(--tradition-rgb), 0.00) 100%
    );
    text-shadow: 0 1px 3px rgba(0,0,0,0.55), 0 0 6px rgba(0,0,0,0.3);
    color: var(--tradition-color) !important;
}

.tradition-pill:hover {
    opacity: 1;
    filter: none;
    transform: translateY(-1px);
}

.tradition-pill.inactive {
    background: var(--bg-card) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-light);
    box-shadow: none;
    opacity: 0.85;
    filter: saturate(0);
}

/* Light mode overrides */
html.light-mode .tradition-card-pill,
html.light-mode .tradition-filter-pill,
html.light-mode .tradition-pill {
    border-color: rgba(var(--tradition-rgb), 0.40);
    background: linear-gradient(
        to top right,
        rgba(var(--tradition-rgb), 0.75) 0%,
        rgba(var(--tradition-rgb), 0.32) 22%,
        rgba(var(--tradition-rgb), 0.07) 55%,
        rgba(var(--tradition-rgb), 0.00) 100%
    );
    text-shadow: 0 1px 2px rgba(0,0,0,0.175), 0 0 4px rgba(0,0,0,0.08);
    color: #000000 !important;
}

.concepts-mobile-toggle {
    display: none;
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    margin-bottom: 10px;
}

.concepts-mobile-toggle:hover {
    border-color: #58a6ff;
    color: #58a6ff;
}

@media (min-width: 769px) {
    .search-tradition-filters {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
    }

    .search-tradition-filters .filter-source-heading {
        flex-shrink: 0;
        width: auto;
    }

    .search-tradition-filters .tradition-filter-controls {
        display: flex;
        flex-wrap: nowrap;
        flex-shrink: 0;
        width: max-content;
        gap: 8px;
    }

    .search-tradition-filters .source-filter-inline {
        flex-shrink: 0;
        width: fit-content;
        margin-left: 0;
    }

    .search-tradition-filters .tradition-pill-list {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 12px 16px;
        justify-content: flex-start;
    }

    .browse-filter-heading {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 12px;
    }
}

.label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.radio-label,
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
    color: var(--text-primary);
}

.radio-label input,
.checkbox-label input {
    cursor: pointer;
}

/* Source filter dropdown */
.search-modes select,
.source-filter-inline select {
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    min-width: 200px;
}

.source-filter-inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-filter-inline .tradition-toggle-btn {
    padding: 3px 10px;
    font-size: 0.8rem;
    border-radius: 4px;
}

.source-filter-inline select {
    min-width: 180px;
    padding: 3px 10px;
    font-size: 0.8rem;
    border-radius: 4px;
}

.search-modes select:focus,
.source-filter-inline select:focus {
    border-color: var(--accent-primary);
}

.search-modes optgroup,
.source-filter-inline optgroup {
    font-weight: 600;
    color: var(--text-secondary);
    font-style: normal;
}

.search-modes option,
.source-filter-inline option {
    font-weight: normal;
    color: var(--text-primary);
}

/* Tradition All/Clear toggle buttons */
.tradition-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    height: 24px;
    line-height: 1;
    padding: 2px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tradition-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Tradition checkbox label colors */
.checkbox-label.tradition-hermetic {
    color: #50C878;
}

.checkbox-label.tradition-gnostic {
    color: #9B59B6;
}

.checkbox-label.tradition-kabbalistic {
    color: #E05555;
}

.checkbox-label.tradition-ancient-egyptian {
    color: #D4AF37;
}

.checkbox-label.tradition-hindu {
    color: #FF9933;
}

.checkbox-label.tradition-tibetan-buddhist {
    color: #8B2252;
}

.checkbox-label.tradition-buddhist {
    color: #C07090;
}

.checkbox-label.tradition-zoroastrian {
    color: #F4511E;
}

.checkbox-label.tradition-greek {
    color: #C1694F;
}

.checkbox-label.tradition-western-esoteric {
    color: #607D8B;
}

.checkbox-label.tradition-channeled-material {
    color: #8B5CF6;
}

.checkbox-label.tradition-taoist {
    color: #1ABC9C;
}

.checkbox-label.tradition-sufi {
    color: #E67E22;
}

.checkbox-label.tradition-christian-mysticism {
    color: #2B6CB0;
}

.checkbox-label.tradition-jewish-apocrypha {
    color: #0E86AB;
}

.checkbox-label.tradition-neoplatonic {
    color: #6D7FCB;
}

.checkbox-label.tradition-mesopotamian {
    color: #CD7F32;
}

.checkbox-label.tradition-rosicrucian {
    color: #E74C3C;
}

.checkbox-label.tradition-alchemical {
    color: #8B4513;
}

.checkbox-label.tradition-nordic {
    color: #2C3E50;
}

.checkbox-label.tradition-alchemical {
    color: #795548;
}

.checkbox-label.tradition-nordic {
    color: #37474F;
}

/* Results */
.message {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 12px 16px;
    border-radius: 10px;
    text-align: center;
}

.results-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 15px;
    padding-left: 5px;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s, background-color 0.3s ease;
}

.card:hover {
    box-shadow: 0 4px 12px var(--accent-glow);
    border-color: var(--accent-primary);
}

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

/* Favourite star button */
.favourite-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    cursor: pointer;
    padding: 0;
    color: var(--text-secondary);
    line-height: 1;
    flex-shrink: 0;
    text-decoration: none;
    transition: all 0.2s ease;
}

.favourite-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

.favourite-btn.favourited {
    color: #e3b341;
    border-color: var(--border-light);
    background: var(--bg-card);
}

.favourite-btn.favourited .star-icon polygon {
    fill: #e3b341;
    stroke: #e3b341;
}

.score {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 0.95rem;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.tradition-pill {
    letter-spacing: 0.04em;
}

/* Tradition badge colors */
.badge-hermetic {
    background: #e8f4f8;
    color: #2980b9;
}

.badge-gnostic {
    background: #f5e6f0;
    color: #8e44ad;
}

.badge-kabbalistic {
    background: #f4efe8;
    color: #d35400;
}

.badge-ancient-egyptian {
    background: #e8f0e8;
    color: #27ae60;
}

.badge-hindu {
    background: #fef5e8;
    color: #e67e22;
}

.badge-tibetan-buddhist {
    background: #f5e8f0;
    color: #c0392b;
}

.badge-buddhist {
    background: #fef5e8;
    color: #d68910;
}

.badge-zoroastrian {
    background: #ffe8e8;
    color: #e74c3c;
}

.badge-greek {
    background: #e8f0f5;
    color: #16a085;
}

.badge-western-esoteric {
    background: #faf5e8;
    color: #b8956e;
}

.badge-channeled-material {
    background: #f5e6f0;
    color: #8e44ad;
}

.badge-taoist {
    background: #e8f8f5;
    color: #16a085;
}

.badge-sufi {
    background: #fef5e8;
    color: #d35400;
}

.badge-christian-mysticism {
    background: #ecf0f1;
    color: #2c3e50;
}

.badge-jewish-apocrypha {
    background: #f5e6f0;
    color: #8E44AD;
}

.badge-buddhist {
    background: #fef5e8;
    color: #d68910;
}

.badge-zoroastrian {
    background: #ffe8e8;
    color: #e74c3c;
}

.card-source {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.card-source-links {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.see-all-link {
    font-size: 0.8rem;
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.2s;
}

.see-all-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.card-reference {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 10px;
    font-style: italic;
}

.card-text {
    color: var(--text-primary);
    line-height: 1.6;
}

.card-text-snippet {
    color: var(--text-secondary);
    font-style: italic;
}

.browse-link {
    display: inline-block;
    color: var(--accent-primary);
    font-size: 0.8rem;
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.2s;
}

.browse-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.card-full-text {
    color: var(--text-primary);
    line-height: 1.6;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

/* Search term highlighting */
/* Preview highlight - shows where user was reading in expanded card */
.preview-highlight {
    background: rgba(100, 149, 237, 0.3);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 2px 4px;
    border-radius: 4px;
    border-left: 2px solid rgba(100, 149, 237, 0.5);
    display: inline;
}

/* Concept tags on cards */
.card-concepts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

/* Concept tags - neutral, non-tradition-colored */
.concept-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 400;
    padding: 2px 9px;
    border-radius: 4px;
    white-space: nowrap;
    background: rgba(139, 148, 158, 0.12);
    color: #8b949e;
    border: 0.5px solid rgba(139, 148, 158, 0.20);
}

body.light-mode .concept-badge {
    background: rgba(101, 109, 118, 0.08);
    color: #57606a;
    border-color: rgba(101, 109, 118, 0.18);
}

.concepts-loading {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.loading-concepts {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 10px;
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: block;
}

.htmx-request.htmx-indicator {
    display: block;
}

.search-loading-indicator {
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.9rem;
    width: fit-content;
}

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

.dot {
    animation: dot-pulse 1.4s infinite ease-in-out;
    animation-fill-mode: both;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

/* Results info and pagination */
.results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.pagination-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    min-width: 36px;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: var(--button-text);
    border-color: var(--accent-primary);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-current {
    background: var(--accent-primary);
    color: var(--button-text);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 36px;
    text-align: center;
}

.pagination-ellipsis {
    color: var(--text-secondary);
    padding: 0 4px;
}

.pagination-bottom {
    display: flex;
    justify-content: center;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 800px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: static;
    }

    .concepts-list {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .concept-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 140px;
        text-align: center;
    }
}

@media (max-width: 600px) {
    header h1 {
        font-size: 2rem;
    }

    .search-input-group {
        flex-direction: column;
    }

    .search-input-group button {
        width: 100%;
    }

    .options {
        padding: 12px 16px;
    }

    .concept-btn {
        flex: 1 1 100%;
    }
}

/* ========================================
   Theme Toggle Button
   ======================================== */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 2px 8px var(--card-shadow);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.theme-toggle svg {
    width: 22px;
    height: 22px;
    fill: var(--text-primary);
    transition: fill 0.3s ease;
}

/* Show/hide icons based on theme */
.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

html.light-mode .theme-toggle .sun-icon {
    display: block;
}

html.light-mode .theme-toggle .moon-icon {
    display: none;
}

/* Nav bar container - aligns buttons with main content */
.nav-bar {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    position: relative;
}

/* Left side nav buttons container */
.nav-buttons-left {
    display: flex;
    gap: 10px;
}

/* Right side theme toggle container */
.nav-buttons-right {
    display: flex;
}

/* Placeholder nav buttons (Library, Favourites) */
.nav-placeholder-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: default;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--card-shadow);
    opacity: 0.6;
}

.nav-placeholder-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-color);
    transform: none;
}

.nav-placeholder-btn svg {
    width: 22px;
    height: 22px;
    fill: var(--text-primary);
    transition: fill 0.3s ease;
}

.nav-placeholder-btn.favourites-btn svg {
    fill: #FFD700;
}

/* Theme toggle button - no longer fixed */
.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--card-shadow);
    margin-right: 60px;
}

/* Adjust header to account for fixed toggle button */
header {
    position: relative;
}

/* ========================================
   Passage HTML Styling
   ======================================== */
.passage-html {
    color: var(--text-primary);
    line-height: 1.8;
}

.passage-html p {
    margin-top: 0 !important;
    margin-bottom: 0.6em !important;
}

.passage-html h4 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    font-style: italic;
}

.passage-html em {
    display: block;
    text-align: center;
    font-style: italic;
    margin: 1.2em 2em;
    color: var(--text-accent);
}

.passage-html blockquote {
    margin-left: 2em;
    margin-top: 0.8em;
    margin-bottom: 0.8em;
    color: var(--text-accent);
}

.passage-html blockquote em {
    color: #8b949e;
}

.passage-html ol {
    padding-left: 2em;
    list-style-position: outside;
    margin: 1em 0;
}

.passage-html ol li {
    margin-bottom: 0.4em;
    padding-left: 0.3em;
}

@media (max-width: 768px) {
    .search-section .search-input-group {
        width: 100%;
        max-width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
        gap: 10px;
        align-items: center;
    }

    .search-section .search-input-group input {
        grid-column: 1 / 3;
        min-width: 0;
    }

    .search-section .search-input-group button {
        grid-column: 3;
        justify-self: start;
        white-space: nowrap;
    }

    .tradition-filters {
        align-items: stretch;
    }

    .search-tradition-filters {
        display: grid;
        grid-template-columns: max-content minmax(0, 1fr);
        justify-content: stretch;
        align-items: stretch;
        column-gap: 16px;
        row-gap: 8px;
    }

    .search-tradition-filters .filter-source-heading {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .traditions-mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: fit-content;
        grid-column: 1;
        grid-row: 3;
        align-self: center;
    }

    .tradition-checkbox-list {
        display: none;
        width: 100%;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
    }

    .tradition-pill-list {
        display: none;
        width: 100%;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
    }

    .tradition-filters.traditions-expanded .tradition-checkbox-list {
        display: flex;
    }

    .tradition-filters.traditions-expanded .tradition-pill-list {
        display: flex;
    }

    /* Row 2 stays full width; row 3 puts Traditions toggle left and All/Clear right */
    .search-tradition-filters .tradition-filter-controls {
        display: flex;
        flex-wrap: nowrap;
        width: auto;
        grid-column: 2;
        grid-row: 3;
        margin-left: 0;
        justify-self: start;
        justify-content: flex-end;
        align-items: center;
        gap: 6px;
    }

    .search-tradition-filters .source-filter-inline {
        grid-column: 1 / -1;
        grid-row: 2;
        order: unset;
        margin-top: 0;
        margin-left: 0;
        display: flex;
        width: 100%;
        justify-self: stretch;
    }

    .search-tradition-filters .source-filter-inline select {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .search-tradition-filters {
        margin-bottom: 0;
    }

    .search-tradition-filters .tradition-pill-list {
        grid-column: 1 / -1;
        grid-row: 4;
        justify-content: flex-start;
        margin-top: 4px;
    }

    /* Search home only: exact 3-row mobile filter stack */
    .search-page .search-tradition-filters {
        grid-template-columns: minmax(0, 1fr) max-content;
        justify-content: start;
        column-gap: 12px;
        width: 100%;
        max-width: 100%;
    }

    .search-page .search-tradition-filters .filter-source-heading {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .search-page .search-tradition-filters .source-filter-inline {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .search-page .search-tradition-filters .traditions-mobile-toggle {
        grid-column: 1;
        grid-row: 3;
        justify-self: start;
        margin-left: 0;
    }

    .search-page .search-tradition-filters .tradition-filter-controls {
        grid-column: 2;
        grid-row: 3;
        width: max-content;
        justify-self: start;
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 6px;
    }

    .search-page .search-tradition-filters .tradition-pill-list {
        grid-column: 1 / -1;
        grid-row: 4;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .source-filter-inline {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .source-filter-inline select {
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }

    .search-page .concepts-mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: fit-content;
        margin-top: 0;
        margin-bottom: 0;
        position: static;
        background: var(--bg-primary);
    }

    .search-page .concepts-sidebar {
        width: 100%;
        padding: 0;
        background: transparent;
        border: none;
        position: sticky;
        top: 56px;
        z-index: 100;
    }

    .search-page .concepts-sidebar .concepts-content {
        display: none;
    }

    .search-page .concepts-sidebar.concepts-expanded .concepts-content {
        display: block;
        position: fixed;
        top: 96px;
        left: 0;
        right: 0;
        max-height: calc(100vh - 112px);
        max-height: calc(100dvh - 112px);
        overflow-y: auto;
        z-index: 99;
        background: var(--bg-primary);
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
        padding: 16px 20px;
    }

    .search-page .concepts-sidebar .concepts-list {
        flex-direction: column;
        flex-wrap: nowrap;
    }

    .search-page .concepts-sidebar .concept-btn {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
    }


    /* Prevent mobile overflow in search/find-similar result cards */
    #results,
    .results-info,
    .results-count,
    .card,
    .card-header,
    .card-source,
    .card-reference,
    .card-text,
    .card-full-text,
    .card-concepts,
    .concept-tags {
        max-width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .card-source {
        flex-wrap: wrap;
        min-width: 0;
    }

    .card-text,
    .card-full-text,
    .card-reference {
        min-width: 0;
    }

    .see-all-link {
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* ========================================
   App Navigation
   ======================================== */
.app-nav {
    margin: 0 -20px 16px;
    padding: 0 20px;
    background: #080f1a;
    border-bottom: 1px solid #253246;
}

.app-nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-nav-left {
    display: inline-flex;
    align-items: center;
    gap: 16px;
}

.app-nav-links {
    display: inline-flex;
    align-items: center;
    gap: 14px;
}

.app-nav-brand,
.app-nav-link {
    color: #e6edf3;
    text-decoration: none;
    font-size: 0.95rem;
}

.app-nav-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.app-nav-logo-box {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #202a38;
    background: #05090f;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-nav-logo-box svg {
    width: 28px;
    height: 28px;
}

.app-nav-link {
    color: #8b949e;
}

.app-nav-link-disabled {
    opacity: 0.7;
    pointer-events: none;
    cursor: default;
}

.app-nav-link:hover,
.app-nav-link.active {
    color: #e6edf3;
}

.app-nav-right {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nav-display-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.nav-auth-link {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: color 0.15s, border-color 0.15s;
}

.nav-auth-link:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.nav-version {
    color: #8b949e;
    font-size: 0.75rem;
    opacity: 0.7;
}

.nav-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #161b22;
    color: #8b949e;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-icon-btn:hover {
    color: #f0f6fc;
    border-color: #58a6ff;
    background: #30363d;
}

.nav-icon-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    stroke: none;
}

.nav-bookmark-btn {
    color: #d4af37;
}

.nav-bookmark-btn .star-icon {
    fill: none;
    stroke: currentColor;
}

.nav-bookmark-btn .star-icon polygon {
    fill: currentColor;
}

.nav-theme-toggle {
    color: #e6edf3;
}

.nav-theme-toggle:hover {
    color: #ffffff;
}

.nav-theme-toggle .sun-icon * {
    stroke: currentColor;
}

.nav-theme-toggle .sun-icon {
    display: none;
}

.nav-theme-toggle .moon-icon {
    display: block;
}

html.light-mode .nav-theme-toggle .sun-icon {
    display: block;
}

html.light-mode .nav-theme-toggle .moon-icon {
    display: none;
}

/* Back to top button */
.back-to-top-btn {
    position: fixed;
    right: 16px;
    bottom: 24px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, color 0.2s ease;
    z-index: 120;
}

.back-to-top-btn:hover {
    color: var(--text-primary);
}

.back-to-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.copy-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1000;
}

.copy-toast.show {
    opacity: 1;
}

.share-sidebar-entry {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.share-link-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.collection-picker {
    position: absolute;
    min-width: 220px;
    max-width: 280px;
    padding: 8px 0;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    z-index: 1100;
}

.collection-picker-header {
    padding: 8px 14px 10px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #e6edf3;
    border-bottom: 1px solid #30363d;
}

.collection-picker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    color: #e6edf3;
    font-size: 0.92rem;
    cursor: pointer;
}

.collection-picker-item:hover {
    background: #21262d;
}

.collection-picker-item input[type="checkbox"] {
    margin: 0;
    accent-color: #7b2fbe;
}

.collection-picker-count {
    color: #8b949e;
    font-size: 0.88rem;
}

.collection-picker-footer {
    margin-top: 6px;
    padding: 8px 14px 0;
    border-top: 1px solid #30363d;
}

.collection-picker-footer button {
    width: 100%;
    border: 1px solid #30363d;
    border-radius: 8px;
    background: #0d1117;
    color: #e6edf3;
    padding: 8px 10px;
    font-size: 0.9rem;
    cursor: pointer;
}

.collection-picker-footer button:hover {
    border-color: #7b2fbe;
    color: #7b2fbe;
    background: #161b22;
}

/* Empty state for favourites page */
.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 48px 24px;
    font-size: 0.95rem;
}

/* ========================================
   Browse Groups
   ======================================== */
.browse-group-header {
    width: 100%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: inherit;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    text-align: left;
    cursor: pointer;
    margin: 0;
}

.browse-group-header:hover {
    background: var(--bg-card);
}

.browse-group-header-main {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    min-width: 0;
}

.browse-group-copy {
    min-width: 0;
}

.browse-group-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.browse-group-summary {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.browse-group-toggle-copy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-primary);
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.browse-group-chevron {
    transition: transform 0.2s ease;
}

.browse-group.is-expanded .browse-group-chevron {
    transform: rotate(180deg);
}

.browse-group.is-expanded .browse-group-toggle-label {
    visibility: hidden;
    position: relative;
}

.browse-group.is-expanded .browse-group-toggle-label::after {
    content: "Collapse";
    visibility: visible;
    position: absolute;
    left: 0;
    top: 0;
}

.browse-group-children {
    padding: 12px 0 0;
    grid-column: 1 / -1;
}

.browse-group-children-grid {
    border-left: 2px solid color-mix(in srgb, var(--tradition-color, var(--accent-primary)) 35%, var(--border-color));
    padding-left: 16px;
}

/* ========================================
   Browse Grid
   ======================================== */
.browse-grid-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0;
}

.browse-grid-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0 0 14px;
    letter-spacing: 0.02em;
}

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

.browse-grid-group {
    display: contents;
}

.browse-grid-group-children {
    padding-top: 12px;
}

.browse-grid-page .text-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 14px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    display: block;
}

.browse-grid-page .text-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
    border-color: var(--accent-primary);
}

.browse-grid-page .text-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.3;
}

.browse-grid-page .text-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.browse-grid-page .text-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.browse-grid-page .text-meta-count {
    font-weight: 600;
    color: var(--accent-primary);
}

.browse-grid-page .text-translator {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

.browse-grid-tile {
    aspect-ratio: 1;
    min-height: 150px;
    border: 2px solid;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: inset 0 0 20px var(--tile-glow, rgba(240, 246, 252, 0.05));
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.browse-grid-tile:hover {
    border-color: var(--tradition-color);
    transform: scale(1.03);
}

html.light-mode .browse-grid-tile {
    background: color-mix(in srgb, var(--bg-card) 82%, var(--tradition-color) 18%) !important;
    box-shadow: inset 0 0 22px color-mix(in srgb, var(--tradition-color) 26%, transparent);
}

.browse-grid-tile-title {
    font-size: 14px;
    line-height: 1.35;
    font-weight: 500;
    overflow-wrap: break-word;
    word-break: normal;
}

.browse-grid-empty {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Reader template hardcoded dark values (light-mode corrections) */
html.light-mode .chapters-mobile-toggle {
    border-color: var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
}

@media (max-width: 768px) {
    html.light-mode .chapters-mobile-toggle {
        background: var(--bg-card);
    }

    html.light-mode .reader-container.chapters-expanded .chapter-nav {
        background: var(--bg-primary);
        border-bottom-color: var(--border-color);
    }
}

@media (max-width: 600px) {
    .browse-group-header {
        gap: 10px;
        flex-direction: column;
    }

    .browse-group-header-main {
        width: 100%;
        gap: 10px;
    }

    .browse-group-toggle-copy {
        width: 100%;
        justify-content: space-between;
    }

    .browse-group-children {
        padding: 10px 0 0;
    }

    .browse-group-children-grid {
        padding-left: 12px;
    }

    .browse-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }

    .browse-grid-tile {
        min-height: 0;
        padding: 4px;
    }

    .browse-grid-tile-title {
        font-size: 11px;
        line-height: 1.25;
    }

    .browse-grid-page .text-card {
        padding: 12px 12px 10px;
    }

    .browse-grid-page .text-title {
        font-size: 1rem;
        margin-bottom: 6px;
    }

    .browse-grid-page .text-meta,
    .browse-group-summary,
    .browse-grid-page .text-translator {
        font-size: 0.8rem;
    }

    /* Keep nav/search color treatment consistent with desktop on mobile */
    .app-nav {
        background: #080f1a;
        border-bottom-color: #253246;
    }

    .app-nav-logo-box {
        background: #05090f;
        border-color: #202a38;
    }

    .search-input-group input {
        background: var(--input-bg);
    }

    .app-nav {
        position: relative;
    }

    .app-nav-inner {
        gap: 8px;
        min-height: 56px;
    }

    .app-nav-left {
        gap: 8px;
        min-width: 0;
        flex: 1;
    }

    .app-nav-brand {
        font-size: 0.9rem;
    }

    .app-nav-links {
        display: none;
        position: absolute;
        left: 20px;
        right: 20px;
        top: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin-top: 0;
        padding: 4px 0;
        background: #080f1a;
        border-top: 1px solid #253246;
        border-bottom: 1px solid #253246;
        z-index: 200;
    }

    .app-nav.menu-open .app-nav-links {
        display: flex;
    }

    .app-nav-links .app-nav-link,
    .app-nav-links .app-nav-link-disabled {
        display: inline-flex;
        align-items: center;
        width: 100%;
        min-height: 44px;
        padding: 10px 14px;
        font-size: 15px;
    }

    .app-nav-link-label {
        display: inline-flex;
        align-items: center;
        min-height: 24px;
    }

    .app-nav-right {
        gap: 4px;
        flex-shrink: 0;
    }

    .nav-display-name {
        display: none;
    }

    .nav-version {
        display: none;
    }

    .nav-icon-btn {
        width: 32px;
        height: 32px;
    }

    .nav-icon-btn svg {
        width: 16px;
        height: 16px;
    }

    .app-nav-menu-toggle {
        display: inline-flex !important;
        width: 32px;
        height: 32px;
        border-radius: 8px;
        border: 1px solid #30363d;
        background: #161b22;
        color: #e6edf3;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 18px;
        line-height: 1;
        padding: 0;
    }

    .app-nav-menu-toggle:hover {
        border-color: #58a6ff;
        background: #30363d;
    }
}

/* Explore passage modal */
.explore-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}
.explore-modal-overlay.hidden {
  display: none !important;
}
.explore-modal-overlay.position-bottomleft .explore-modal-card {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: min(720px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  pointer-events: all;
  border-radius: 8px;
}
.explore-modal-overlay.position-above-drawer .explore-modal-card {
  position: fixed;
  bottom: calc(var(--drawer-height, 30vh) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, 92vw);
  max-height: 60vh;
  overflow-y: auto;
  pointer-events: all;
  border-radius: 8px;
}
.explore-modal-close {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary, #21262d);
  border: 1px solid var(--border-light, #484f58);
  border-radius: 4px;
  cursor: pointer;
  font-size: 8px;
  color: #e5534b;
  z-index: 1;
  transition: all 0.15s ease;
}
.explore-modal-close:hover {
  background: var(--bg-hover, #30363d);
  border-color: var(--accent-primary, #3498db);
  color: #ff7b72;
}

.card-header-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-header-meta { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.concept-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.passage-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.passage-action-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border-light, #484f58); color: #8b949e; text-decoration: none; background: var(--bg-card, #161b22); cursor: pointer; padding: 0; transition: all 0.2s ease; }
.passage-action-btn:hover { color: var(--accent-primary, #3498db); border-color: var(--accent-primary, #3498db); background: var(--bg-hover, #30363d); }
.collection-action-btn svg { width: 14px; height: 14px; }
.collection-action-btn .collection-grid-cell { fill: #5f6670; opacity: 0.75; }
.collection-action-btn.collected .collection-grid-cell-primary { fill: #7B2FBE; opacity: 1; }
.explore-passage-item { padding: 10px 12px; border-bottom: 1px solid var(--border-light, #30363d); cursor: pointer; transition: background 0.15s; }
.explore-passage-item:hover { background: var(--bg-hover, #30363d); }
.explore-passage-item-source { font-size: 0.75rem; color: var(--text-muted, #8b949e); margin-bottom: 2px; }
.explore-passage-item-ref { font-size: 0.82rem; color: var(--accent-primary, #3498db); margin-bottom: 4px; }
.explore-passage-item-preview { font-size: 0.82rem; color: var(--text-secondary, #c9d1d9); line-height: 1.4; }

#left-drawer,
#right-drawer {
  position: fixed;
  top: 64px;
  height: calc(100vh - 64px);
  transition: transform 0.25s ease;
  z-index: 20;
}

#left-drawer {
  left: 0;
}

#right-drawer {
  right: 0;
}

#left-drawer.collapsed {
  transform: translateX(calc(-100% + 18px));
}

#right-drawer.collapsed {
  transform: translateX(calc(100% - 18px));
}

#left-drawer-tab,
#right-drawer-tab {
  position: absolute;
  top: 12px;
  width: 18px;
  height: 48px;
  background: color-mix(in srgb, var(--bg-card) 90%, transparent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 21;
}

#left-drawer-tab {
  right: 0;
  border-left: none;
  border-radius: 0 4px 4px 0;
}

#right-drawer-tab {
  left: 0;
  border-right: none;
  border-radius: 4px 0 0 4px;
}

#left-drawer-tab:focus-visible,
#right-drawer-tab:focus-visible {
  outline: none;
  color: var(--text-primary);
}

.branch-link {
  fill: none;
  stroke: rgba(255, 255, 255, 0.65);
  stroke-width: 1.5px;
}

.branch-link-active {
  fill: none;
  stroke: #d4af37;
  stroke-width: 2px;
}

.branch-link-hover {
  fill: none;
  stroke: #58a6ff;
  stroke-width: 1.5px;
}

.branch-link-child {
  fill: none;
  stroke: #58a6ff;
  stroke-width: 1.5px;
}

.branch-node-label {
  fill: #ffffff;
}

#branch-empty-state,
#source-empty-state,
#plane-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
}

.source-text-node {
  cursor: pointer;
}

#plane-mode-toggle {
  position: fixed;
  top: 114px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--bg-card) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 0 0 8px 8px;
  border-top: none;
  white-space: nowrap;
  z-index: 29;
}

#plane-mode-toggle button {
  padding: 3px 11px;
  font-size: 0.78rem;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

#plane-mode-toggle button:hover {
  color: var(--text-primary);
  border-color: var(--accent-primary, #58a6ff);
}

#plane-mode-toggle button.active {
  color: var(--accent-primary, #58a6ff);
  border-color: var(--accent-primary, #58a6ff);
  background: rgba(88, 166, 255, 0.1);
}
