:root {
    --bg:                   #070714;
    --surface:              rgba(10, 10, 30, 0.92);
    --surface-sticky:       rgba(10, 10, 30, 0.98);
    --border:               #1e2a4a;
    --border-mid:           #2a3a5a;
    --input-bg:             #0f1428;
    --accent:               #7ec8ff;
    --accent-strong:        #4a9eff;
    --muted:                #7a9acc;
    --muted-dim:            #5a7a9a;
    --muted-faint:          #6a8aaa;
    --muted-stats:          #7a9abb;
    --text:                 #fff;
    --text-label:           #aaa;
    --text-placeholder:     #aacce0;
    --text-guided:          #c8dff8;
    --text-desc:            #e0e0e0;
    --text-conn:            #e8e8e8;
    --state-speaking:       #f39c12;
    --handle-bar:           #3a5a7a;
    --handle-bar-hover:     #6a9abb;
    --handle-label:         #4a6a8a;
    --toggle-hover-bg:      rgba(30, 60, 100, 0.95);
    --guided-bg:            rgba(74, 158, 255, 0.06);
    --guided-border:        rgba(74, 158, 255, 0.18);
    --guided-bg-hover:      rgba(74, 158, 255, 0.14);
    --guided-border-hover:  rgba(74, 158, 255, 0.4);
    --conn-hover-bg:        rgba(74, 158, 255, 0.1);
    --filter-active-border: rgba(255, 255, 255, 0.3);
    --node-theory:       #c038c0;
    --node-observation:  #3098e8;
    --node-fallback:     #888888;
    --node-dim:          rgba(74,90,106,0.3);
    --edge-verified:     #1a9878;
    --edge-supported:    #7040b8;
    --edge-speculative:  #7070a0;
    --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 */
#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-mid);
    border-radius: 5px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

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

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

.filter-btn {
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    opacity: 0.5;
    transition: opacity 0.15s;
}

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

.section-label {
    font-size: 10px;
    color: var(--muted-dim);
    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; }
@media (max-width: 640px) { .guided-q-extra { display: none; } }

.guided-q-arrow {
    font-size: 10px;
    color: var(--accent-strong);
    flex-shrink: 0;
}

#confidence-row {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-label);
}

#confidence-row input { width: 100%; margin-top: 4px; }

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

#node-panel {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#node-panel .placeholder {
    color: var(--text-placeholder);
    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;
}

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

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

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

.confidence-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

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

.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;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

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

.conn-conf {
    font-size: 10px;
    margin-left: auto;
    flex-shrink: 0;
}

.legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.legend-line { width: 24px; height: 3px; border-radius: 2px; }

#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-mid);
    color: var(--accent);
    padding: 5px 4px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    transition: border-color 0.15s, background 0.15s;
}
#btn-row button:hover { border-color: var(--accent-strong); }

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

#speak-btn {
    background: transparent;
    border: 1px solid var(--border-mid);
    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-strong); }
#speak-btn.speaking { border-color: var(--state-speaking); color: var(--state-speaking); }

#instructions {
    font-size: 10px;
    color: var(--muted-faint);
    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; }
#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(--handle-bar);
    border-radius: 2px;
    transition: background 0.2s;
}
#sheet-handle:hover #sheet-handle-bar { background: var(--handle-bar-hover); }

/* ── Mobile portrait: bottom sheet ─────────────────────────────── */
@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-mid);
        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); }
    /* Handle sticks to the top while sidebar scrolls */
    #sheet-handle {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 10px 0 8px;
        position: sticky;
        top: 0;
        background: var(--surface-sticky);
        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 gets dynamic height from JS, becomes the scrollable area */
    #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;
}