:root {
    --bg: #0b1020;
    --panel: #0f152b;
    --text: #e8ebf3;
    --muted: #a6b0cf;
    --user: #2a6dfc10;
    /* translucent blue */
    --assistant: #7c3aed10;
    /* translucent purple */
    --accent: #2a6dfc;
    --accent-2: #7c3aed;
    --link: #374151;
}

html,
body {
    margin: 0;
    height: 100%;
    background: radial-gradient(1200px 800px at 10% 0%, #0a0f23, #060914 60%);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
    overflow: hidden;
}

#main-header {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    flex-wrap: wrap;
    background: color-mix(in oklab, var(--panel) 80%, transparent);
    border: 1px solid #1f2a44;
    padding: 10px 12px;
    border-radius: 12px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, .25);
    z-index: 10;
}

#main-header>.title {
    font-weight: 700;
    letter-spacing: .3px;
}

#main-header>button {
    appearance: none;
    border: 1px solid #263253;
    background: #121a36;
    color: var(--text);
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

#main-header>button:hover {
    filter: brightness(1.15);
}

#chart {
    position: absolute;
    inset: 0;
    top: 64px;
    /* leave space for header */
}

/* SVG link styling */
.link {
    fill: none;
    stroke: var(--link);
    stroke-width: 1.5px;
    opacity: .7;
}

/* Card nodes rendered via foreignObject > div */
.node-card {
    gap: 6px;
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid #253258;
    background: #0e1531;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
    height: inherit;
    box-sizing: border-box;
}

.node-card.meta {
    background: color-mix(in oklab, var(--user) 100%, #313337 80%);
    border-color: #434346;
}

.node-card.user {
    background: color-mix(in oklab, var(--user) 100%, #0e1531 80%);
    border-color: #26407a;
}

.node-card.assistant {
    background: color-mix(in oklab, var(--assistant) 100%, #0e1531 80%);
    border-color: #4e2b8c;
}

.node-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.badge {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .3px;
    text-transform: uppercase;
    opacity: .9;
}

.badge.meta {
    color: rgb(119, 107, 90);
}

.badge.user {
    color: #8cb2ff;
}

.badge.assistant {
    color: #c6a4ff;
}

.timestamp {
    color: var(--muted);
    font-size: 11px;
    opacity: .9;
}

.node-text {
    color: var(--text);
    line-height: 1.25;
    font-size: 13.5px;
    display: -webkit-box;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    font-size: 13.5px;
    -webkit-box-orient: vertical;
    white-space: pre-wrap;
    /* preserve newlines */
    margin-bottom: auto;
}

.node-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.node-btn {
    border: 1px solid #2a355e;
    background: #0f1736;
    color: #cdd7ff;
    padding: 4px 6px;
    font-size: 11.5px;
    border-radius: 8px;
    cursor: pointer;
}

.node-hover {
    transition: transform .1s ease-out, box-shadow .15s ease-out;
}

.node-hover:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

/* Subtle focus ring when a node is clicked */
.node-focused {
    outline: 2px solid color-mix(in oklab, var(--accent) 70%, transparent);
    outline-offset: 2px;
    border-radius: 16px;
}

#minimap {
    position: fixed;
    bottom: 12px;
    width: 100%;
    height: 160px;
    border: 1px solid #263253;
    background: rgba(15, 23, 54, 0.8);
    backdrop-filter: blur(2px);
    z-index: 30;
}

#minimap .viewbox {
    fill: none;
    stroke: #8cb2ff;
    stroke-width: 1.5;
    vector-effect: non-scaling-stroke;
}

.header-spacer {
    flex: 1 1 auto;
}

/* pushes stats to the right */
.header-stats {
    margin-left: auto;
    display: flex;
    gap: 14px;
    align-items: baseline;
    font-size: 12px;
    opacity: 0.9;
    white-space: nowrap;
    flex-wrap: wrap;
}

.header-stats b {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    margin-right: 4px;
}

/* Side panel */
#sidebox {
    position: fixed;
    top: 64px;
    right: 12px;
    bottom: 12px;
    width: 420px;
    display: none;
    flex-direction: column;
    gap: 10px;
    background: #0f152b;
    border: 1px solid #263253;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
    z-index: 40;
}

#sidebox.open {
    display: flex;
}

#sidebox header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 1em 1em 0 1em;
    /* padding: 10px 12px; */
}

#sidebox .title {
    font-weight: 800;
    letter-spacing: .2px;
}

#sidebox .time {
    margin-left: auto;
    font-size: 12px;
    opacity: .8;
}

#sidebox .body {
    padding: 0 12px 12px;
    overflow: auto;
    line-height: 1.45;
    white-space: pre-wrap;
}

#sidebox .nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 0 12px 12px;
}

#sidebox .nav button {
    border: 1px solid #2a355e;
    background: #0f1736;
    color: #cdd7ff;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
}

#sidebox .nav button:last-child {
    width: 100%;
}

#sidebox .list {
    padding: 0 12px 12px;
    display: grid;
    gap: 6px;
    overflow: auto;
    max-height: 50%;
}

#sidebox .item {
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
}

#sidebox .textbox {
    max-height: 50%;
    font-size: 14px;
    padding: 0 1em;
    overflow-y: auto;
    white-space: pre-wrap;
}

@media only screen and (max-width: 600px) {
    #sidebox {
        top: unset;
        right: 0;
        bottom: 0;
        height: 70vh;
        width: 100vw;
    }
}

.markdown-sidebar :first-child {
    margin-top: 0;
}

/* Compact Markdown Sidebar Styles */
#sidebox .textbox.markdown-sidebar {
    white-space: normal;
}

.markdown-sidebar h1,
.markdown-sidebar h2,
.markdown-sidebar h3,
.markdown-sidebar h4,
.markdown-sidebar h5,
.markdown-sidebar h6 {
    /* margin: 0.6em 0 0.3em; */
    margin: 1em 0;
    font-weight: 600;
    line-height: 1.2;
}

.markdown-sidebar h1 {
    font-size: 1.2rem;
}

.markdown-sidebar h2 {
    font-size: 1.1rem;
}

.markdown-sidebar h3 {
    font-size: 1rem;
}

.markdown-sidebar h4,
.markdown-sidebar h5,
.markdown-sidebar h6 {
    font-size: 0.9rem;
}

.markdown-sidebar p {
    margin: 1em 0;
}

.markdown-sidebar a {
    color: #0366d6;
    text-decoration: none;
}

.markdown-sidebar a:hover {
    text-decoration: underline;
}

.markdown-sidebar ul,
.markdown-sidebar ol {
    margin: 0.3em 0 0.3em 1.2em;
    padding: 0;
}

.markdown-sidebar li {
    margin: 0.2em 0;
}

.markdown-sidebar table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin: 0.5em 0;
}

.markdown-sidebar th,
.markdown-sidebar td {
    border: 1px solid #999;
    padding: 0.3em 0.6em;
    text-align: left;
}

.markdown-sidebar th {
    /*   background: #f0f0f0; */
    font-weight: 600;
}

.markdown-sidebar code {
    background: #232e57;
    padding: 0.1em 0.3em;
    border-radius: 4px;
    font-size: 0.9em;
}

.markdown-sidebar pre {
    background: #232e57;
    padding: 0.4em;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85em;
    margin: 0.5em 0;
}

.markdown-sidebar blockquote {
    border-left: 3px solid #ccc;
    margin: 0.5em 0;
    padding-left: 0.6em;
    /*   color: #555; */
    /*   font-style: italic; */
    font-size: 0.95em;
}

.long-button {
    grid-column: span 2;
}