:root {
    --bg: #0d1120;
    --panel: #121729;
    --panel-2: #171d33;
    --line: #232a3f;
    --line-2: #2d3550;
    --text: #e6e9f2;
    --muted: #8b93a7;
    --faint: #5d6681;
    --accent: #4cc9f0;
    --accent-2: #3aa8cc;
    --good: #80ed99;
    --warn: #ffb703;
    --bad: #ff5d73;
    --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
    --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --radius: 8px;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 13px/1.45 var(--sans);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---- header ------------------------------------------------------------------------------- */
.bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; letter-spacing: 0.01em; }
.brand svg { width: 26px; height: 26px; color: var(--accent); background: #1a2140; border-radius: 7px; padding: 4px; }
.brand b { font-weight: 650; }
.controls { display: flex; align-items: center; gap: 8px; margin-left: 12px; flex-wrap: wrap; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="ready"] .dot { background: var(--good); }
.status[data-state="running"] .dot { background: var(--accent); animation: pulse 0.8s infinite; }
.status[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.35; } }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #b8a1ff); transition: width 0.15s; }

button {
    display: inline-flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 12px;
    border-radius: 6px; border: 1px solid var(--line-2);
    background: var(--panel-2); cursor: pointer;
}
button:hover:not(:disabled) { border-color: #3d4766; background: #1c2340; }
button:disabled { opacity: 0.45; cursor: default; }
button svg { width: 14px; height: 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06111d; font-weight: 600; padding: 0 16px; }
button.primary:hover:not(:disabled) { background: #6ad6f5; border-color: #6ad6f5; }
button.danger { background: #3a1621; border-color: #6b2333; color: #ffb3bf; }
button.ghost { background: transparent; }
button.small { height: 26px; padding: 0 10px; font-size: 12px; }
button.icon { width: 30px; padding: 0; justify-content: center; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

select {
    height: 30px; padding: 0 28px 0 10px; border-radius: 6px;
    border: 1px solid var(--line-2); background: var(--panel-2);
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 15px) 13px, calc(100% - 10px) 13px;
    background-size: 5px 5px; background-repeat: no-repeat;
}

/* ---- layout ------------------------------------------------------------------------------- */
main { flex: 1; display: flex; min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.pane.left { flex: 0 0 38%; }
.pane.right { flex: 1; }
.splitter { flex: 0 0 5px; cursor: col-resize; background: var(--line); transition: background 0.15s; }
.splitter:hover, .splitter.dragging { background: var(--accent-2); }
.pane-head {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    border-bottom: 1px solid var(--line); min-height: 40px;
}
.deck-name { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.hint { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- editor ------------------------------------------------------------------------------- */
.editor { flex: 1; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; }
.editor .cm-editor.cm-focused { outline: none; }
/* ---- the explorer ------------------------------------------------------------------------ */
.explorer {
    flex: 0 0 232px; display: flex; flex-direction: column; min-width: 0; min-height: 0;
    background: #0d1222; border-right: 1px solid var(--line);
}
body.no-explorer .explorer { display: none; }
.x-show { display: none; }
body.no-explorer .x-show { display: inline-flex; }
.explorer-head { display: flex; align-items: center; gap: 2px; padding: 0 6px 0 12px; min-height: 40px; border-bottom: 1px solid var(--line); }
.explorer-title { flex: 1; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.explorer-head .icon, .x-show { width: 26px; height: 26px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 15px; justify-content: center; }
.explorer-head .icon svg { width: 15px; height: 15px; }
.explorer-head .icon:hover, .x-show:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.tree { flex: 1; overflow: auto; padding: 4px 0; font-size: 12.5px; scrollbar-width: thin; }
.tree.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.tree.none { flex: 0 0 auto; }
.tree-empty { flex: 1; padding: 14px; color: var(--faint); font-size: 12px; line-height: 1.5; }
.tree-row {
    display: flex; align-items: center; gap: 5px; height: 24px; padding-right: 4px; cursor: pointer;
    color: var(--muted); white-space: nowrap; user-select: none; outline: none;
}
.tree-row:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.tree-row:focus-visible { box-shadow: inset 0 0 0 1px var(--accent-2); }
.tree-row.on { background: #1d3a52; color: var(--text); }
.tree-row.drop { background: rgba(76,201,240,0.18); }
.tree-row .twisty { width: 10px; flex: 0 0 10px; color: var(--faint); font-size: 10px; text-align: center; }
.tree-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tree-row.file .name, .tree-row.run .name { font-family: var(--mono); font-size: 12px; }
.tree-row.folder .name { color: var(--text); }
.tree-row.folder.project > .name { font-weight: 600; }
.tree-row.runs .name { color: var(--faint); font-style: italic; }
.tree-row.orphan .name { opacity: 0.55; font-style: italic; }
.tree-row.binary .name { opacity: 0.45; }
.tree-row .main-mark { color: var(--warn); font-size: 11px; }
.tree-row .run-icon { color: var(--accent); font-size: 11px; }
.tree-row .size { color: var(--faint); font-size: 11px; }
.tree-row .fmark, .fmark { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; }
.fmark.warn { background: var(--warn); }
.fmark.bad { background: var(--bad); }
.tree-row .row-menu { padding: 0 5px; border-radius: 4px; color: var(--faint); opacity: 0; }
.tree-row:hover .row-menu, .tree-row.on .row-menu, .tree-row:focus .row-menu { opacity: 1; }
.tree-row .row-menu:hover { color: var(--text); background: rgba(255,255,255,0.08); }
.storage { padding: 8px 12px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11px; line-height: 1.45; }
.storage .warn { color: var(--warn); }
.file-menu {
    position: fixed; z-index: 50; min-width: 210px; padding: 4px; display: flex; flex-direction: column;
    background: #121729; border: 1px solid #2d3550; border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.file-menu button { justify-content: flex-start; border: 0; background: transparent; padding: 6px 10px; text-align: left; color: var(--text); }
.file-menu button:hover:not(:disabled), .file-menu button:focus-visible { background: #1d3a52; outline: none; }
.file-menu button:disabled { color: var(--faint); }
.file-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.welcome {
    position: absolute; inset: 41px 0 0 0; z-index: 10; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 10px; padding: 24px; background: var(--panel); text-align: center;
}
.welcome[hidden] { display: none; }
.pane.left.no-file .pane-head > :not(.x-show) { visibility: hidden; }
.welcome h2 { margin: 0; font-size: 20px; font-weight: 600; }
.welcome p { margin: 0; color: var(--muted); max-width: 420px; }
.welcome .small { font-size: 12px; color: var(--faint); }
.welcome-actions { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; width: 260px; }
.welcome-actions button { justify-content: center; }
.pane.left { position: relative; }
.drop-hint {
    display: none; position: absolute; inset: 0; z-index: 20; align-items: center; justify-content: center;
    background: rgba(13,18,34,0.82); border: 2px dashed var(--accent); color: var(--text); font-size: 15px; pointer-events: none;
}
.pane.left.drop .drop-hint { display: flex; }
.outline select { height: 26px; max-width: 170px; font-size: 12px; }
.problems { gap: 7px; white-space: nowrap; flex: 0 0 auto; }
.problems .mark { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.problems.ok .mark { background: var(--good); }
.problems.warn .mark { background: var(--warn); }
.problems.bad .mark { background: var(--bad); }
.problems.bad { border-color: #6b2333; }

.kw-card { padding: 10px 12px; width: 480px; max-width: 80vw; max-height: 70vh; font: 12px/1.45 var(--sans); }
.kw-head { display: flex; align-items: baseline; gap: 10px; }
.kw-name { font: 700 13px var(--mono); color: #4cc9f0; }
.kw-sections { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.kw-via { color: var(--faint); font-size: 11px; margin-top: 2px; }
.kw-at { margin-top: 6px; padding: 5px 8px; border-radius: 5px; background: #1d3a52; color: var(--text); }
.kw-at b { font-family: var(--mono); color: #fff; }
.kw-desc { margin: 6px 0 0; color: #c9cfdd; white-space: pre-line; }
.kw-title { margin-top: 2px; color: var(--text); font-weight: 600; }
.kw-item-desc { margin: 6px 0 0; color: #c9cfdd; }
.kw-source { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line-2); color: var(--faint); font-size: 11px; }
.kw-source a { color: var(--muted); }
.kw-meta { margin-top: 6px; color: var(--muted); font-size: 11.5px; }
.kw-items { margin-top: 8px; border-collapse: collapse; width: 100%; table-layout: fixed; font-size: 11.5px; }
.kw-items th:nth-child(2) { width: 42%; }
.kw-items th:nth-child(3) { width: 17%; }
.kw-items th:nth-child(4) { width: 13%; }
.kw-items td { overflow-wrap: anywhere; }
.kw-items th { text-align: left; color: var(--faint); font-weight: 600; padding: 2px 8px 2px 0; border-bottom: 1px solid var(--line-2); }
.kw-items td { padding: 2px 8px 2px 0; color: #c9cfdd; vertical-align: top; }
.kw-items td:nth-child(2) { font-family: var(--mono); color: var(--text); }
.kw-items td:first-child, .kw-items th:first-child { color: var(--faint); width: 2.2em; }
.kw-items tr.on td { color: #fff; background: #1d3a52; }
.kw-support { margin-top: 6px; padding: 5px 8px; border-radius: 5px; font-size: 11.5px; }
.kw-support.stop { background: #3a1621; color: #ffc2cc; }
.kw-support.ignored { background: #3a2a10; color: #ffe1a6; }
.kw-support b { display: block; }
.kw-flag { margin-left: 5px; font-size: 8px; vertical-align: middle; }
.kw-flag.stop { color: var(--bad); }
.kw-flag.ignored { color: var(--warn); }

/* ---- tabs --------------------------------------------------------------------------------- */
.tabs { display: flex; align-items: stretch; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); min-height: 40px; }
.tabs [role="tab"] {
    height: auto; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
    background: none; color: var(--muted); padding: 0 12px;
}
.tabs [role="tab"]:hover { background: none; color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab-spacer { flex: 1; }
.run-info { align-self: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.badge { min-width: 18px; padding: 0 6px; border-radius: 9px; background: #3a2a10; color: var(--warn); font-size: 11px; line-height: 18px; text-align: center; }
.badge.bad { background: #3a1621; color: #ffb3bf; }
.tab-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.toolbar input[type="range"] { accent-color: var(--accent); }
#property { max-width: 190px; }
#step { flex: 1; min-width: 80px; }
.step-label { min-width: 0; white-space: nowrap; color: var(--text); font-variant-numeric: tabular-nums; font-size: 12px; }
.z input { width: 90px; }
#zscale-label { min-width: 26px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- 3D ----------------------------------------------------------------------------------- */
/* ---- the 3D tab's control panel (like the vector list) ------------------------------------ */
.grid3d { flex: 1; display: flex; min-height: 0; }
.view-panel { flex: 0 0 230px; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); scrollbar-width: thin; }
.vp-section { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 7px; }
.vp-section h4 { margin: 0; color: var(--faint); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.vp-section h4 label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.vp-section h4 .count { color: var(--faint); font-weight: 400; letter-spacing: 0; text-transform: none; }
.vp-section select { width: 100%; }
.vp-row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.vp-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.view-panel .z input { width: auto; }
.view-panel .step-label { white-space: pre-line; color: var(--muted); }
.view-panel button.small { align-self: flex-start; }
.vp-wells { flex: 1; border-bottom: 0; min-height: 120px; }
.vp-wells input[type="search"] { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text); padding: 5px 8px; font-size: 12px; }
.well-list { display: flex; flex-direction: column; gap: 1px; }
.witem { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 5px; }
.witem:hover { background: var(--panel-2); }
.witem input { accent-color: var(--accent); margin: 0; }
.witem .swatch { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.witem .wname { font-family: var(--mono); font-size: 12px; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.witem .wname:hover { color: var(--accent); text-decoration: underline; }
.witem .wmeta { margin-left: auto; color: var(--faint); font-size: 11px; white-space: nowrap; }
.witem.off .wname, .witem.off .swatch { opacity: 0.4; }
.viewer { position: relative; flex: 1; min-height: 0; background: radial-gradient(ellipse at 50% 35%, #1a2140 0%, #0d1120 75%); }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* The canvas is appended after the overlays: keep legend, tooltip and empty state above it. */
.viewer .legend, .viewer .tip, .viewer .empty { z-index: 2; }
.empty { display: grid; place-items: center; height: 100%; color: var(--faint); padding: 24px; text-align: center; }
.empty.small { height: auto; padding: 12px; }
.viewer .empty { position: absolute; inset: 0; }
.legend {
    position: absolute; left: 14px; bottom: 14px; width: 260px; padding: 10px 12px;
    background: rgba(13, 17, 32, 0.82); border: 1px solid var(--line-2); border-radius: var(--radius);
    backdrop-filter: blur(6px);
}
.legend-title { font-size: 12px; margin-bottom: 6px; }
.well-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.well-legend span { display: inline-flex; align-items: center; gap: 5px; }
.well-legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.tip .well-name { font-family: var(--mono); }
.legend-bar { height: 10px; border-radius: 3px; }
.legend-ticks { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tip {
    position: absolute; pointer-events: none; padding: 6px 9px;
    background: rgba(13, 17, 32, 0.92); border: 1px solid var(--line-2); border-radius: 6px;
    font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tip b { color: var(--accent); font-weight: 600; }

/* ---- vectors ------------------------------------------------------------------------------ */
.vectors { flex: 1; display: flex; min-height: 0; }
.vector-list { flex: 0 0 230px; display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.vector-list input[type="search"] {
    margin: 10px; height: 30px; padding: 0 10px; border-radius: 6px;
    border: 1px solid var(--line-2); background: var(--panel-2);
}
.vector-groups { flex: 1; overflow: auto; padding: 0 6px 10px; }
.vgroup h4 { margin: 10px 6px 4px; color: var(--faint); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.vitem { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 5px; cursor: pointer; font-family: var(--mono); font-size: 12px; }
.vitem:hover { background: var(--panel-2); }
.vitem input { accent-color: var(--accent); margin: 0; }
.vitem .unit { margin-left: auto; color: var(--faint); font-family: var(--sans); font-size: 11px; }
.plots { flex: 1; overflow: auto; padding: 10px 4px 10px 8px; min-width: 0; }
.chart { margin-bottom: 10px; }
.uplot { font-family: var(--sans); }
.u-legend { font-size: 12px; color: var(--muted); }
.u-legend .u-series th { font-family: var(--mono); font-weight: 500; }
.u-legend .u-value { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- log ---------------------------------------------------------------------------------- */
.log { flex: 1; overflow: auto; padding: 6px 0; font: 12px/1.5 var(--mono); }
.check { gap: 6px !important; }
.check input { accent-color: var(--accent); margin: 0; }
.msg { display: flex; gap: 10px; padding: 4px 14px; border-bottom: 1px solid #171d30; white-space: pre-wrap; word-break: break-word; }
.msg .lvl { flex: 0 0 64px; font-family: var(--sans); font-size: 11px; font-weight: 600; text-transform: uppercase; padding-top: 1px; }
.msg.error .lvl, .msg.bug .lvl { color: var(--bad); }
.msg.problem .lvl, .msg.warning .lvl { color: var(--warn); }
.msg.info .lvl, .msg.note .lvl { color: var(--accent); }
.msg.terminal { color: var(--muted); padding-top: 1px; padding-bottom: 1px; border: 0; }
.msg.terminal .lvl { color: var(--faint); }
.msg a { color: var(--accent); cursor: pointer; }
.msg .repeat { margin-left: auto; flex: 0 0 auto; align-self: flex-start; padding: 0 7px; border-radius: 9px; background: var(--panel-2); color: var(--muted); font: 600 11px/18px var(--sans); }

@media (max-width: 900px) {
    main { flex-direction: column; }
    .pane.left { flex: 0 0 45%; }
    .grid3d { flex-direction: column; }
    .view-panel { flex: 0 0 auto; max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--line); }
    .explorer { flex: 0 0 auto; max-height: 28vh; border-right: 0; border-bottom: 1px solid var(--line); }
    .splitter { display: none; }
    .hint { display: none; }
}
