        @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Space+Grotesk:wght@400;700&display=swap');
        
        :root {
            --bg-dark: #0a0a0f;
            --panel-bg: rgba(15, 15, 25, 0.98);
            --accent-blue: #4f8cff;
            --accent-green: #22c55e;
            --accent-red: #ef4444;
            --accent-purple: #a855f7;
            --accent-amber: #f59e0b;
            --text-primary: #e0e0e0;
            --text-secondary: rgba(255,255,255,0.7);
            --text-muted: rgba(255,255,255,0.4);
            --border-color: rgba(255,255,255,0.08);
            --grid-color: #1a1a2e;
        }
        
        /* Light Theme */
        body.light-theme {
            --bg-dark: #f5f5f7;
            --panel-bg: rgba(255, 255, 255, 0.98);
            --text-primary: #1a1a1a;
            --text-secondary: rgba(0,0,0,0.7);
            --text-muted: rgba(0,0,0,0.4);
            --border-color: rgba(0,0,0,0.1);
            --grid-color: #e0e0e0;
        }
        
        body.light-theme .canvas-container {
            background: var(--bg-dark);
        }
        
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { 
            overflow: hidden; 
            background: var(--bg-dark); 
            color: var(--text-primary); 
            font-family: 'Space Grotesk', sans-serif;
            font-size: 12px;
            transition: background 0.3s, color 0.3s;
        }
        
        /* Main Layout */
        .app-container {
            display: grid;
            grid-template-rows: 40px 1fr 24px;
            grid-template-columns: 240px 1fr 200px;
            height: 100vh;
            width: 100vw;
            overflow: visible;
        }
        
        /* Top Toolbar */
        .toolbar {
            grid-column: 1 / -1;
            background: var(--panel-bg);
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            padding: 0 8px;
            gap: 2px;
            overflow: visible;
        }
        
        .toolbar-section {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 0 10px;
            height: 100%;
            border-right: 1px solid var(--border-color);
            overflow: visible;
        }
        .toolbar-section:last-child { border-right: none; }
        
        .toolbar-label {
            font-size: 9px;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            color: var(--text-muted);
            white-space: nowrap;
        }
        
        /* Bottom Status Bar */
        .statusbar {
            grid-column: 1 / -1;
            background: rgba(128,128,128,0.1);
            border-top: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            padding: 0 12px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 10px;
            color: var(--accent-amber);
        }
        
        .statusbar .legend {
            margin-left: auto;
            display: flex;
            gap: 12px;
        }
        .legend-item { display: flex; align-items: center; gap: 4px; color: var(--text-muted); font-size: 9px; }
        .dot { width: 6px; height: 6px; border-radius: 50%; }
        
        /* Left Sidebar */
        .sidebar-left {
            background: var(--panel-bg);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        
        /* Right Sidebar */
        .sidebar-right {
            background: var(--panel-bg);
            border-left: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .sidebar-copyright {
            padding: 8px 10px;
            border-top: 1px solid var(--border-color);
            font-family: 'JetBrains Mono', monospace;
            font-size: 9px;
            color: var(--text-muted);
            text-align: center;
        }
        .sidebar-copyright a {
            color: var(--text-secondary);
            text-decoration: none;
        }
        .sidebar-copyright a:hover { color: var(--accent-blue); text-decoration: underline; }

        /* Bottom action buttons (in right sidebar) */
        .sidebar-bottom-actions {
            margin-top: auto;
            display: flex;
            flex-direction: column;
            gap: 6px;
            padding: 8px 10px;
            border-top: 1px solid var(--border-color);
        }

        .cite-btn,
        .report-bug-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            padding: 6px 10px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 10px;
            border-radius: 4px;
            text-decoration: none;
            transition: background 0.15s, color 0.15s, border-color 0.15s;
        }
        .cite-btn span,
        .report-bug-btn span { font-size: 11px; }

        .cite-btn {
            background: rgba(79, 140, 255, 0.12);
            color: #93b8ff;
            border: 1px solid rgba(79, 140, 255, 0.3);
        }
        .cite-btn:hover {
            background: rgba(79, 140, 255, 0.22);
            color: #bcd2ff;
            border-color: rgba(79, 140, 255, 0.5);
        }

        .report-bug-btn {
            background: rgba(239, 68, 68, 0.15);
            color: #f87171;
            border: 1px solid rgba(239, 68, 68, 0.35);
        }
        .report-bug-btn:hover {
            background: rgba(239, 68, 68, 0.25);
            color: #fca5a5;
            border-color: rgba(239, 68, 68, 0.55);
        }

        body.light-theme .cite-btn {
            background: rgba(37, 99, 235, 0.08);
            color: #1d4ed8;
            border-color: rgba(37, 99, 235, 0.3);
        }
        body.light-theme .cite-btn:hover {
            background: rgba(37, 99, 235, 0.16);
            color: #1e40af;
            border-color: rgba(37, 99, 235, 0.5);
        }
        body.light-theme .report-bug-btn {
            background: rgba(220, 38, 38, 0.1);
            color: #b91c1c;
            border-color: rgba(220, 38, 38, 0.3);
        }
        body.light-theme .report-bug-btn:hover {
            background: rgba(220, 38, 38, 0.18);
            color: #991b1b;
            border-color: rgba(220, 38, 38, 0.5);
        }
        
        /* Canvas Container */
        .canvas-container {
            position: relative;
            overflow: hidden;
            background: var(--bg-dark);
        }
        
        canvas#mainCanvas { 
            width: 100%; 
            height: 100%; 
            cursor: crosshair; 
            display: block;
        }
        
        /* Collapsible Sections */
        .section {
            border-bottom: 1px solid var(--border-color);
        }
        
        .section-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 6px 10px;
            cursor: pointer;
            user-select: none;
            background: rgba(128,128,128,0.03);
            transition: background 0.15s;
        }
        .section-header:hover { background: rgba(128,128,128,0.08); }
        
        .section-title {
            font-family: 'JetBrains Mono', monospace;
            font-size: 9px;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        
        .section-icon { width: 6px; height: 6px; border-radius: 50%; }
        
        .section-toggle {
            font-size: 8px;
            color: var(--text-muted);
            transition: transform 0.2s;
        }
        .section.collapsed .section-toggle { transform: rotate(-90deg); }
        .section.collapsed .section-content { display: none; }
        
        .section-content {
            padding: 6px 10px 8px;
            overflow: hidden;
        }
        
        /* Compact Form Elements */
        .btn {
            padding: 4px 8px;
            font-size: 10px;
            font-weight: 600;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.15s;
            font-family: inherit;
            white-space: nowrap;
        }
        
        .btn-primary { 
            background: linear-gradient(135deg, var(--accent-blue), #3b7aeb);
            color: white;
        }
        .btn-primary:hover { filter: brightness(1.1); }
        
        .btn-secondary {
            background: rgba(128,128,128,0.15);
            color: var(--text-primary);
            border: 1px solid var(--border-color);
        }
        .btn-secondary:hover { background: rgba(128,128,128,0.25); }
        
        .btn-green { background: linear-gradient(135deg, #22c55e, #16a34a); color: white; }
        .btn-red { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; }
        .btn-purple { background: linear-gradient(135deg, #a855f7, #8b5cf6); color: white; }
        .btn-purple.active { background: linear-gradient(135deg, #dc2626, #ef4444); }
        
        .btn-group { display: flex; gap: 3px; }
        .btn-group .btn { flex: 1; }
        
        .btn-icon {
            width: 24px;
            height: 24px;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        select {
            background: rgba(128,128,128,0.15);
            color: var(--text-primary);
            padding: 3px 6px;
            border-radius: 4px;
            font-size: 10px;
            border: 1px solid var(--border-color);
            cursor: pointer;
            font-family: inherit;
        }
        select:focus { outline: none; border-color: var(--accent-blue); }
        
        .slider-row {
            display: flex;
            align-items: center;
            gap: 6px;
            margin: 3px 0;
        }
        .slider-row label {
            font-size: 9px;
            color: var(--text-muted);
            min-width: 42px;
            flex-shrink: 0;
        }
        .slider-row input[type="range"] {
            flex: 1;
            min-width: 60px;
            height: 3px;
            cursor: pointer;
            accent-color: var(--accent-blue);
        }
        .slider-row .val {
            font-family: 'JetBrains Mono', monospace;
            font-size: 9px;
            color: var(--accent-blue);
            min-width: 26px;
            flex-shrink: 0;
            text-align: right;
        }
        
        /* Toggle Rows */
        .toggle-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 2px 0;
        }
        .toggle-row span { font-size: 10px; color: var(--text-secondary); }
        
        input[type="checkbox"] {
            width: 12px;
            height: 12px;
            cursor: pointer;
            accent-color: var(--accent-blue);
        }
        
        /* Mode Badge */
        .mode-badge {
            display: inline-flex;
            align-items: center;
            padding: 2px 6px;
            font-size: 9px;
            border-radius: 3px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        .mode-draw { background: var(--accent-blue); }
        .mode-vineyard { background: var(--accent-purple); }
        
        /* Floating Plot Panels */
        .float-panel {
            position: absolute;
            background: var(--panel-bg);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.4);
            z-index: 100;
            display: none;
        }
        .float-panel.active { display: flex; flex-direction: column; }
        
        .float-panel-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 5px 10px;
            border-bottom: 1px solid var(--border-color);
            cursor: move;
            background: rgba(128,128,128,0.05);
            border-radius: 8px 8px 0 0;
        }
        
        .float-panel-title {
            font-family: 'JetBrains Mono', monospace;
            font-size: 9px;
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }
        
        .float-panel-content { flex: 1; padding: 4px; overflow: hidden; }
        
        #vineyardPanel {
            right: 210px;
            bottom: 36px;
            width: 360px;
            height: 300px;
        }
        #vineyardPanel.expanded { width: 600px; height: 480px; }
        
        #persistencePanel {
            left: 250px;
            bottom: 36px;
            width: 320px;
            height: 320px;
        }
        #persistencePanel.expanded { width: 480px; height: 460px; }
        
        #vineyardPlot, #persistencePlot { width: 100%; height: 100%; }

        /* Float panel resize handles */
        .resize-handle {
            position: absolute;
            z-index: 10;
            background: transparent;
        }
        .resize-handle.n { top: -3px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
        .resize-handle.s { bottom: -3px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
        .resize-handle.e { top: 10px; bottom: 10px; right: -3px; width: 6px; cursor: ew-resize; }
        .resize-handle.w { top: 10px; bottom: 10px; left: -3px; width: 6px; cursor: ew-resize; }
        .resize-handle.ne { top: -4px; right: -4px; width: 12px; height: 12px; cursor: nesw-resize; }
        .resize-handle.nw { top: -4px; left: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
        .resize-handle.se { bottom: -4px; right: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
        .resize-handle.sw { bottom: -4px; left: -4px; width: 12px; height: 12px; cursor: nesw-resize; }
        .float-panel.resizing { user-select: none; }
        
        /* Animation Row */
        .anim-row {
            display: flex;
            align-items: center;
            gap: 3px;
            margin: 4px 0;
        }
        .anim-row input[type="range"] { 
            flex: 1;
            min-width: 50px;
        }
        
        /* Quick Keys */
        .quick-keys {
            padding: 6px 10px;
            font-size: 9px;
            color: var(--text-muted);
            line-height: 1.5;
            border-top: 1px solid var(--border-color);
            margin-top: auto;
        }
        .quick-keys kbd {
            background: rgba(128,128,128,0.2);
            padding: 0px 3px;
            border-radius: 2px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 8px;
        }
        
        /* Curve Count Badge */
        .curve-badge {
            background: rgba(0,0,0,0.3);
            padding: 1px 5px;
            border-radius: 3px;
            font-size: 9px;
            font-family: 'JetBrains Mono', monospace;
        }
        
        /* Export Menu */
        .export-menu {
            display: none;
            position: fixed;
            background: var(--panel-bg);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.4);
            min-width: 220px;
            z-index: 9999;
            overflow: hidden;
        }
        .export-menu.active {
            display: block;
        }
        .export-menu-item {
            padding: 8px 12px;
            font-size: 11px;
            cursor: pointer;
            transition: background 0.15s;
            color: var(--text-primary);
        }
        .export-menu-item:hover {
            background: rgba(79, 140, 255, 0.2);
        }
        .export-menu-divider {
            height: 1px;
            background: var(--border-color);
            margin: 4px 0;
        }
        .export-menu-control {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 12px;
            font-size: 11px;
            color: var(--text-primary);
        }
        .export-menu-control input[type="range"] {
            flex: 1;
            accent-color: #4f8cff;
            height: 3px;
        }
        .export-menu-control span:last-child {
            font-family: 'JetBrains Mono', monospace;
            font-size: 10px;
            color: var(--text-muted);
            min-width: 28px;
            text-align: right;
        }
