:root {
    --bg: #0d0f12;
    --panel: #14171c;
    --panel-2: #1a1e24;
    --line: #262b33;
    --text: #e6e2d8;
    --dim: #7d8590;
    --accent: #f5b54a;
    --accent-ink: #1a1204;
    --teal: #4fd1c5;
    --rose: #ff6b7a;
    --violet: #b9a3ff;
    --green: #9ad37a;
    --mono: "JetBrains Mono", ui-monospace, monospace;
    --sans: "Space Grotesk", system-ui, sans-serif;
    --code-size: 14px;
    --code-line: 22px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    display: flex;
    flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 18px; border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo { color: var(--accent); font-size: 20px; }
.name { font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.ver { font-family: var(--mono); font-size: 11px; color: var(--accent); border: 1px solid var(--accent); padding: 1px 6px; border-radius: 999px; }
.actions { display: flex; gap: 8px; align-items: center; }
select, .btn {
    font-family: var(--sans); font-size: 14px; border-radius: 8px; padding: 8px 14px;
    border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.btn.run { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.run:hover { filter: brightness(1.08); }
.btn.ghost:hover, select:hover { border-color: var(--dim); }
kbd { font-family: var(--mono); font-size: 10px; opacity: 0.6; margin-left: 6px; }

/* ---------- layout ---------- */
.workspace {
    flex: 1; min-height: 0; display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; padding: 12px;
}
.output-pane { display: grid; grid-template-rows: 1fr 1.3fr; gap: 12px; min-height: 0; }
.pane {
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pane-head {
    display: flex; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--line);
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim);
}
.pane-head span:first-child { color: var(--text); font-weight: 500; }
@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; grid-auto-rows: minmax(420px, auto); }
}

/* ---------- editor ---------- */
.editor { flex: 1; display: flex; min-height: 0; font-family: var(--mono); font-size: var(--code-size); line-height: var(--code-line); }
.gutter {
    margin: 0; padding: 14px 10px 14px 14px; color: #4a515b; text-align: right; user-select: none;
    overflow: hidden; min-width: 48px; background: var(--panel-2); border-right: 1px solid var(--line);
}
.gutter .err { color: var(--rose); font-weight: 600; }
.code-area { position: relative; flex: 1; min-width: 0; }
.highlight, #code-input {
    position: absolute; inset: 0; margin: 0; padding: 14px 16px; border: 0;
    font: inherit; line-height: inherit; white-space: pre; tab-size: 4; overflow: auto;
}
.highlight { pointer-events: none; color: var(--text); overflow: hidden; }
#code-input {
    background: transparent; color: transparent; caret-color: var(--accent); resize: none; outline: none;
}
#code-input::selection { background: rgba(245, 181, 74, 0.25); color: transparent; }
.tk-kw { color: var(--accent); font-weight: 600; }
.tk-ui { color: var(--teal); }
.tk-fn { color: var(--violet); }
.tk-str { color: var(--green); }
.tk-num { color: var(--rose); }
.tk-op { color: #c9a26b; }
.tk-com { color: #5b6370; font-style: italic; }

/* ---------- console ---------- */
.console { flex: 1; overflow: auto; padding: 10px 14px; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.console .line { white-space: pre-wrap; word-break: break-word; }
.console .line::before { content: "› "; color: var(--dim); }
.console .error { color: var(--rose); }
.console .error::before { content: "✕ "; color: var(--rose); }
.console .info { color: var(--dim); }
.console .info::before { content: "✓ "; color: var(--teal); }
.console .empty, .canvas .empty { color: var(--dim); font-style: italic; }
.console .empty::before { content: ""; }
#run-status.ok { color: var(--teal); }
#run-status.fail { color: var(--rose); }

/* ---------- live UI canvas ---------- */
.canvas {
    flex: 1; overflow: auto; padding: 20px; background: #f7f4ee; color: #1d1b17;
    font-family: var(--sans); display: flex; flex-direction: column; gap: 12px; align-items: flex-start;
}
.canvas .empty { color: #8a8478; }
.ag-layout { display: flex; gap: 12px; }
.ag-row { flex-direction: row; flex-wrap: wrap; align-items: center; }
.ag-column { flex-direction: column; align-items: flex-start; }
.ag-text { margin: 0; font-size: 16px; line-height: 1.35; }
.ag-button {
    font-family: var(--sans); font-size: 15px; font-weight: 600; padding: 10px 18px; border: 0; border-radius: 10px;
    background: #1d1b17; color: #f7f4ee; cursor: pointer; transition: transform 0.08s ease, filter 0.15s ease;
}
.ag-button:hover { filter: brightness(1.1); }
.ag-button:active { transform: scale(0.96); }
.ag-input {
    font-family: var(--sans); font-size: 15px; padding: 10px 12px; border-radius: 10px;
    border: 1.5px solid #d6cfc2; background: #fff; color: #1d1b17; min-width: 240px; outline: none;
}
.output-pane { display: flex; }
.tabs { padding: 0 8px; text-transform: none; letter-spacing: 0; }
.tab-group { display: flex; gap: 4px; }
.tab {
    background: none; border: 0; border-bottom: 2px solid transparent; color: var(--dim);
    font-family: var(--sans); font-size: 13px; padding: 10px 10px; cursor: pointer;
}
.tab em { font-style: normal; font-family: var(--mono); font-size: 11px; margin-left: 6px; opacity: 0.8; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel.hidden { display: none; }
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent);
    color: var(--accent-ink); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; z-index: 10;
}
.ag-input:focus { border-color: var(--accent); }

/* Additive workspace controls: retain the editor header's existing height. */
.file-head { padding-top: 4px; padding-bottom: 4px; align-items: center; min-height: 33px; gap: 8px; }
.file-controls { display: flex; align-items: center; gap: 4px; min-width: 0; }
#file-switcher { height: 24px; min-width: 0; width: 160px; max-width: 30vw; padding: 0 4px; border-color: transparent; font-family: var(--mono); font-size: 12px; border-radius: 4px; }
.file-icon { width: 24px; height: 24px; padding: 3px; border-radius: 4px; display: grid; place-items: center; }
.file-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
#cursor-pos { white-space: nowrap; flex-shrink: 0; }
#file-dialog { width: min(360px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 8px; padding: 24px; color: var(--text); background: var(--panel); font-family: var(--sans); }
#file-dialog::backdrop { background: var(--bg); opacity: 0.75; }
#file-dialog h2 { font-size: 18px; margin: 0 0 20px; }
#file-dialog label { display: block; font-size: 13px; color: var(--dim); margin: 12px 0 6px; }
#file-dialog input, #file-dialog select { width: 100%; padding: 9px 10px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; font: 14px var(--mono); }
#file-dialog input:focus, #file-dialog select:focus { outline: 1px solid var(--accent); }
#file-error { color: var(--rose); min-height: 18px; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
