:root {
    --bg:                   #050A1A;
    --surface:              rgba(5, 10, 26, 0.95);
    --border:               #1E2D5A;
    --input-bg:             #0A0F20;
    --accent:               #15dffa;
    --muted:                #5eb5c0;
    --section-label:        #50b7c5;
    --text:                 #ffffff;
    --text-dark:            #000;
    --text-guided:          #aadcf0;
    --text-desc:            #9fceda;
    --text-trl:             #9CA3AF;
    --text-conn:            #E5E7EB;
    --state-speaking:       #EF4444;
    --instructions:         #667a9b;
    --handle-label:         #667a9b;
    --toggle-hover-bg:      rgba(20, 52, 60, 0.95);
    --guided-bg:            rgba(21, 185, 250, 0.06);
    --guided-border:        rgba(21, 177, 250, 0.18);
    --guided-bg-hover:      rgba(21, 177, 250, 0.14);
    --guided-border-hover:  rgba(21, 177, 250, 0.4);
    --conn-hover-bg:        rgba(11, 151, 245, 0.08);
    --filter-active-border: rgba(255, 255, 255, 0.25);
    --node-mature:         #06B6D4;
    --node-maturing:       #10B981;
    --node-in-development: #C9A800;
    --node-early-research: #8B5CF6;
    --node-fallback:       #888888;
    --node-dim:            rgba(74,90,106,0.3);
    --edge-enables:        #7B8AD0;
    --edge-enhances:       #0D9DB8;
    --edge-competes:       #C47070;
    --edge-related:        #888888;
    --edge-dim:            rgba(74,90,106,0.15);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    overscroll-behavior: none;
}

#graph { width: 100%; height: 100vh; height: 100dvh; opacity: 0; transition: opacity 0.35s ease; }

#sidebar {
    position: absolute;
    top: 0; left: 0;
    width: 300px;
    height: 100vh;
    height: 100dvh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

#sidebar-header {
    padding: 18px 16px 12px;
    border-bottom: 1px solid var(--border);
}

#sidebar-header h1 {
    font-size: 15px;
    color: var(--accent);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#sidebar-header .subtitle {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.06em;
    margin-top: 2px;
    text-transform: uppercase;
}

#sidebar-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

#sidebar-nav a {
    font-size: 11px;
    font-weight: bold;
    color: var(--muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    transition: color 0.15s;
}

#sidebar-nav a:hover { color: var(--accent); }

#search {
    margin-top: 10px;
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

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

#filter-row {
    display: flex;
    gap: 5px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 3px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    opacity: 0.4;
    transition: opacity 0.15s;
    color: var(--text-dark);
}

.filter-btn.active { opacity: 1; border-color: var(--filter-active-border); }

.section-label { font-size: 10px; color: var(--section-label); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 5px; }
#guided-questions { margin-top: 10px; }
.guided-q {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: var(--guided-bg);
    border: 1px solid var(--guided-border);
    border-radius: 5px;
    color: var(--text-guided);
    font-size: 12px;
    font-weight: normal;
    font-family: inherit;
    padding: 6px 10px;
    text-align: left;
    cursor: pointer;
    margin-bottom: 5px;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.35;
}
.guided-q:hover { background: var(--guided-bg-hover); border-color: var(--guided-border-hover); color: var(--text); }
.guided-q:last-child { margin-bottom: 0; }
.guided-q-arrow { font-size: 10px; color: var(--accent); flex-shrink: 0; }
@media (max-width: 640px) { .guided-q-extra { display: none; } }

#sidebar-scroll {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#node-panel {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
}

#node-panel .placeholder {
    color: var(--muted);
    font-size: 13px;
    margin-top: 20px;
    text-align: center;
}

.node-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.node-meta {
    font-size: 11px;
    color: var(--accent);
    margin-bottom: 10px;
}

.maturity-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
    color: var(--text-dark);
}

.node-desc {
    font-size: 12px;
    color: var(--text-desc);
    line-height: 1.6;
    margin-bottom: 14px;
}

.trl-bar-wrap { margin-bottom: 14px; }

.trl-label {
    font-size: 11px;
    color: var(--text-trl);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
}

.trl-pips {
    display: flex;
    gap: 3px;
}

.trl-pip {
    flex: 1;
    height: 6px;
    border-radius: 2px;
    background: var(--border);
    transition: background 0.3s;
}

.node-field {
    font-size: 11px;
    color: var(--text-trl);
    margin-bottom: 6px;
}

.node-field strong { color: var(--text-desc); }

.connections-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    margin-top: 12px;
}

.conn-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 3px;
    transition: background 0.1s;
}

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

.conn-arrow { font-size: 10px; color: var(--muted); }

.conn-type {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.conn-name { font-size: 12px; color: var(--text-conn); }

.legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.legend-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-line { width: 24px; height: 3px; border-radius: 2px; flex-shrink: 0; }

#sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px 16px 16px;
    flex-shrink: 0;
}

#btn-row {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

#btn-row button {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 5px 4px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    transition: border-color 0.15s;
}
#btn-row button:hover { border-color: var(--accent); }

#stats {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 12px;
}

#speak-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    padding: 3px 7px;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;
}
#speak-btn:hover { border-color: var(--accent); }
#speak-btn.speaking { border-color: var(--state-speaking); color: var(--state-speaking); }

#instructions {
    font-size: 10px;
    color: var(--instructions);
    line-height: 1.7;
    margin-bottom: 12px;
}
.instr-mobile { display: none; }
@media (max-width: 640px) {
    .instr-desktop { display: none; }
    .instr-mobile { display: block; }
}

#legend { font-size: 11px; color: var(--text-trl); }
#legend h4 {
    color: var(--muted);
    margin-bottom: 6px;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 10px;
}
#legend h4:first-child { margin-top: 0; }

/* ── Desktop sidebar slide toggle ──────────────────────────────── */
#sidebar {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
#sidebar.collapsed {
    transform: translateX(-300px);
}
#sidebar-toggle {
    position: fixed;
    top: 50%;
    left: 300px;
    transform: translateY(-50%);
    width: 20px;
    height: 50px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 101;
    transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s, background 0.15s;
    user-select: none;
}
#sidebar-toggle:hover { color: var(--text); background: var(--toggle-hover-bg); }
@media (max-width: 640px) { #sidebar-toggle { display: none; } }

/* ── Sheet handle (hidden on desktop) ──────────────────────────── */
#sheet-handle {
    display: none;
    justify-content: center;
    align-items: center;
    padding: 12px 0 8px;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: none;
    user-select: none;
}
#sheet-handle-bar {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.2s;
}
#sheet-handle:hover #sheet-handle-bar { background: var(--accent); }

@media (max-width: 640px) {
    #sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 82vh;
        height: 82svh;
        border-right: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        transform: translateY(calc(100% - 48px));
        transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
        will-change: transform;
        z-index: 200;
        overflow: hidden;
    }
    #sidebar.sheet-open          { transform: translateY(0); }
    #sidebar.sheet-three-quarter { transform: translateY(20.5vh); transform: translateY(20.5svh); }
    #sidebar.sheet-half          { transform: translateY(41vh); transform: translateY(41svh); }
    #sheet-handle {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 10px 0 8px;
        position: sticky;
        top: 0;
        background: var(--surface);
        z-index: 1;
    }
    #sheet-handle-bar { width: 40px; }
    #sheet-handle-label {
        font-size: 10px;
        color: var(--handle-label);
        letter-spacing: 0.06em;
        text-transform: uppercase;
    }
    #sidebar-scroll {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scrollbar-width: none;
        flex: none;
    }
    #sidebar-scroll::-webkit-scrollbar { display: none; }
    #node-panel {
        flex: 0 0 auto;
        overflow-y: visible;
    }
    #sidebar-footer {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* Search suggestions */
#search.has-suggestions { border-radius: 5px 5px 0 0; }
#search-suggestions { display: none; background: var(--input-bg); border: 1px solid var(--border-mid, var(--border)); border-top: none; border-radius: 0 0 5px 5px; max-height: 180px; overflow-y: auto; scrollbar-width: thin; }
.search-suggestion { padding: 6px 10px; font-size: 13px; color: var(--text); cursor: pointer; display: flex; align-items: center; gap: 6px; transition: background 0.1s; }
.search-suggestion:hover { background: var(--conn-hover-bg); color: var(--accent); }
.sug-cat { font-size: 10px; color: var(--muted); flex-shrink: 0; }

/* Node browse dropdown */
#node-select { width: 100%; background: var(--input-bg); border: 1px solid var(--border-mid, var(--border)); border-radius: 5px; padding: 7px 10px; color: var(--text); font-size: 13px; outline: none; cursor: pointer; appearance: none; -webkit-appearance: none; }
#node-select:focus { border-color: var(--accent-strong, var(--accent)); }
#node-select option { background: var(--input-bg); }

.breadcrumb {
    font-size: 13px;
    letter-spacing: 0.08em;
    color: #909090;
    margin-bottom: 10px;
}
.breadcrumb a {
    color: #909090;
    text-decoration: none;
}
.breadcrumb a:hover {
    color: #d0d0d0;
}