:root {
    --bg:                   #060a0e;
    --surface:              rgba(16, 12, 6, 0.93);
    --surface-sticky:       rgba(16, 12, 6, 0.98);
    --border:               #471c10;
    --border-mid:           #3a1608;
    --input-bg:             #0a1418;
    --accent:               #ee904a;
    --accent-strong:        #ee8844;
    --muted:                #d8915b;
    --muted-mid:            #d48a60;
    --section-label:        #f7913d;
    --toggle-color:         #a55619;
    --instructions:         #da8748;
    --text:                 #fff;
    --text-label:           #ccc;
    --text-placeholder:     #e8b390;
    --text-guided:          #f8d1b7;
    --text-desc:            #e0ccbe;
    --text-conn:            #e8e8e8;
    --state-speaking:       #f37f12;
    --handle-bar:           #582f13;
    --handle-bar-hover:     #c9592d;
    --handle-label:         #794325;
    --toggle-hover-bg:      rgba(40, 18, 5, 0.95);
    --guided-bg:            rgba(107, 49, 18, 0.14);
    --guided-border:        rgba(200, 91, 40, 0.20);
    --guided-bg-hover:      rgba(200, 99, 40, 0.1);
    --guided-border-hover:  rgba(200, 91, 40, 0.4);
    --conn-hover-bg:        rgba(200, 104, 40, 0.1);
    --filter-active-border: rgba(255, 255, 255, 0.3);
    --node-claim:        #e87050;
    --node-evidence:     #30c888;
    --node-fallback:     #888888;
    --node-dim:          rgba(74,90,106,0.3);
    --edge-verified:     #1a9878;
    --edge-supported:    #b07040;
    --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(--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-strong); flex-shrink: 0; }
@media (max-width: 640px) { .guided-q-extra { display: none; } }

#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;
}

#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-mid);
    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-mid); }

.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-mid);
    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(--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; }
#legend h4 { color: var(--muted-mid); 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(--toggle-color);
    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);
        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 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;
}