:root {
    --bg-canvas: #0d1117;
    --bg-surface: #161b22;
    --bg-elevated: #21262d;
    --border-subtle: #30363d;
    --border-active: #58a6ff;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent-blue: #2f81f7;
    --accent-blue-hover: #388bfd;
    --accent-green: #238636;
    --accent-amber: #d29922;
    --accent-red: #da3633;
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --radius-sm: 6px;
    --radius-md: 10px;
}

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

body {
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Header */
.app-header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.85rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.badge {
    font-size: 0.72rem;
    font-family: var(--font-mono);
    background-color: rgba(47, 129, 247, 0.15);
    color: var(--border-active);
    border: 1px solid rgba(47, 129, 247, 0.4);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

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

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons & Form Controls */
.btn {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
}

.btn-secondary {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

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

.btn-danger {
    background-color: transparent;
    color: #f85149;
    border-color: rgba(218, 54, 51, 0.4);
}

.btn-danger:hover {
    background-color: rgba(218, 54, 51, 0.15);
}

/* Main Workspace Layout */
.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 390px;
    gap: 1rem;
    padding: 1rem 1.5rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* Left Panel: Interaction */
.interaction-panel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 95px);
    min-height: 500px;
}

.stream-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stream-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.status-indicator {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: #3fb950;
}

.chat-stream {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.message {
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-canvas);
    max-width: 88%;
}

.message.user {
    align-self: flex-end;
    background-color: rgba(47, 129, 247, 0.1);
    border-color: rgba(47, 129, 247, 0.35);
}

.message.ai {
    align-self: flex-start;
    background-color: var(--bg-elevated);
}

.message.curiosity {
    align-self: flex-start;
    background-color: rgba(210, 153, 34, 0.1);
    border-color: rgba(210, 153, 34, 0.45);
}

.message.system {
    align-self: stretch;
    max-width: 100%;
    border-style: dashed;
    color: var(--text-secondary);
}

.msg-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.message p {
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.message code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background-color: var(--bg-elevated);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    color: #79c0ff;
}

.message pre {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

/* Input Area */
.interaction-form {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.form-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

select, textarea {
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    padding: 0.45rem 0.65rem;
}

select:focus, textarea:focus {
    outline: none;
    border-color: var(--border-active);
}

.input-row {
    display: flex;
    gap: 0.6rem;
}

.input-row textarea {
    flex: 1;
    resize: vertical;
    min-height: 44px;
    max-height: 160px;
}

/* Right Panel: Brain Visualiser */
.brain-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: calc(100vh - 95px);
    overflow-y: auto;
}

.metrics-card, .visualiser-card, .memory-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}

.metrics-card h2, .visualiser-card h2, .memory-card h2 {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.metric-item {
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 1.05rem;
    color: var(--text-primary);
}

.energy-bar-wrapper {
    height: 6px;
    background-color: var(--bg-canvas);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.energy-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-amber), var(--accent-red));
    transition: width 0.3s ease;
}

/* Reasoning Trace Graph */
.logic-visualiser {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.trace-step {
    background-color: var(--bg-canvas);
    border-left: 3px solid var(--accent-blue);
    padding: 0.5rem 0.65rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.trace-step.curiosity {
    border-left-color: var(--accent-amber);
}

.trace-relation {
    color: #79c0ff;
    font-weight: 600;
}

/* Node List */
.node-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    max-height: 260px;
    overflow-y: auto;
}

.node-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-subtle);
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.node-domain {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-secondary);
    background-color: var(--bg-elevated);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.empty-state {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-style: italic;
}

@media (max-width: 960px) {
    .workspace {
        grid-template-columns: 1fr;
    }
    .interaction-panel, .brain-panel {
        height: auto;
    }
}
