:root {
    --bg-app: #1E1E2E;
    /* Mocha Base */
    --bg-panel: #181825;
    /* Mocha Mantle */
    --bg-darker: #11111B;
    /* Mocha Crust */

    --primary: #A78BFA;
    /* Purple 400 */
    --primary-hover: #8B5CF6;
    --primary-20: rgba(167, 139, 250, 0.2);

    --accent: #34D399;
    /* Emerald 400 */

    --text-main: #CDD6F4;
    --text-muted: #A6ADC8;
    --text-sub: #7F849C;

    --border: #313244;
    --border-focus: #45475A;

    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius: 8px;
    --radius-sm: 4px;

    /* AST Tokens */
    --t-node: #A78BFA;
    --t-key: #89DCEB;
    --t-string: #A6E3A1;
    --t-number: #FAB387;
    --t-boolean: #F9E2AF;
    --t-null: #F38BA8;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
}

.code-font {
    font-family: var(--font-mono);
}

.text-sm {
    font-size: 0.8125rem;
}

/* Layout Structure */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(24, 24, 37, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand .logo {
    background: var(--primary-20);
    color: var(--primary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand .logo svg {
    width: 18px;
    height: 18px;
}

.brand h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.2;
}

.brand .subtitle {
    font-size: 0.75rem;
    color: var(--text-sub);
}

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box svg {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
}

.search-box input {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.4rem 1rem 0.4rem 2.25rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    outline: none;
    width: 250px;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-20);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn.secondary {
    background: var(--bg-darker);
    border-color: var(--border);
    color: var(--text-main);
}

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

.btn.ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn.ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.btn.icon-only {
    padding: 0.45rem;
}

.btn svg {
    width: 14px;
    height: 14px;
}

/* Workspace Splitter */
.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editor-panel {
    border-right: 1px solid var(--border);
    background: var(--bg-app);
}

.tree-panel {
    background: var(--bg-panel);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-muted);
}

.badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    background: var(--primary-20);
    color: var(--primary);
    font-family: var(--font-mono);
}

.badge.error {
    background: rgba(243, 139, 168, 0.2);
    color: var(--t-null);
}

/* Red */

/* Editor area */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#code-editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 1rem;
    background: transparent;
    color: var(--text-main);
    border: none;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    z-index: 2;
    white-space: pre;
    tab-size: 2;
}

/* When focused on node selection, give a visual selection cue */
#code-editor::selection {
    background: var(--primary-20);
    color: inherit;
}

/* Tree Panel */
.tree-container {
    flex: 1;
    overflow: auto;
    padding: 1rem;
}

/* Scrollbars */
.custom-scroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.custom-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
    border: 2px solid var(--bg-panel);
}

.custom-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--border-focus);
}

/* Empty state spinner */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-sub);
    gap: 1rem;
}

.spinner {
    animation: spin 1s linear infinite;
    opacity: 0.5;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}


/* AST Node Rendering Styles */
.ast-node {
    margin-left: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
}

.ast-node::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 14px;
    bottom: 0;
    width: 1px;
    background: var(--border);
    opacity: 0.5;
    pointer-events: none;
}

.ast-node:last-child::before {
    display: none;
}

.ast-line {
    display: flex;
    align-items: baseline;
    padding: 0.15rem 0.25rem;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}

.ast-line:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ast-line.highlight {
    background: var(--primary-20);
    /* border-left: 2px solid var(--primary); */
}

.ast-line.search-match {
    box-shadow: 0 0 0 1px var(--accent);
}

.toggle {
    width: 12px;
    height: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    color: var(--text-sub);
    position: relative;
    top: 1px;
    transition: transform 0.2s;
}

.toggle svg {
    width: 10px;
    height: 10px;
}

.ast-node.collapsed>.ast-line .toggle {
    transform: rotate(-90deg);
}

.ast-node.collapsed>.ast-children {
    display: none;
}

.prop-key {
    color: var(--t-key);
    margin-right: 0.5rem;
}

.node-type {
    color: var(--t-node);
    font-weight: 600;
    margin-right: 0.5rem;
}

.v-string {
    color: var(--t-string);
}

.v-number {
    color: var(--t-number);
}

.v-boolean {
    color: var(--t-boolean);
}

.v-null {
    color: var(--t-null);
}

.v-meta {
    color: var(--text-sub);
    font-size: 0.7rem;
    margin-left: 0.5rem;
}

.ast-children {
    display: flex;
    flex-direction: column;
}

/* Top-level structure */
.ast-root>.ast-node {
    margin-left: 0;
}

.ast-root>.ast-node::before {
    display: none;
}