/* TOP FX – dark node-based UI */
:root {
  --bg: #08090c;
  --panel: #0f1115;
  --panel-2: #13161b;
  --card: #171a20;
  --card-2: #1e222a;
  --line: #22262e;
  --line-2: #303541;
  --text: #e9ebf0;
  --muted: #8b91a1;
  --dim: #5d6474;
  --accent: #7c8cff;
  --accent-2: #b38cff;
  --accent-grad: linear-gradient(135deg, #7c8cff, #b38cff);
  --danger: #ff6b7a;
  --radius: 10px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  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(--font);
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
kbd { font: 11px ui-monospace, Menlo, monospace; background: var(--card-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

/* ---------- top bar ---------- */
#topbar {
  height: 50px; flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .1em; margin-right: 14px; display: flex; align-items: center; gap: 9px; font-size: 14px; }
.brand span:not(.logo) { color: var(--accent); }
.logo { width: 18px; height: 18px; border-radius: 5px; background: var(--accent-grad); box-shadow: 0 0 14px #7c8cff66; }
.sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 6px; }
#srcInfo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; font-size: 12px; }

/* ---------- buttons ---------- */
.btn {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 7px; padding: 6px 13px; font: inherit; cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover:not(:disabled) { background: #272c36; border-color: #3c4250; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: default; }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #0a0d1c; font-weight: 650; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent-grad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 4px 9px; min-width: 34px; }
.btn.active { background: #343b66; border-color: var(--accent); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #3a1f26; border-color: var(--danger); color: #ffb3bb; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: flex; }
#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#viewport {
  flex: 1; min-height: 120px; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #15181f, #08090c 75%);
}
#glcanvas { display: block; box-shadow: 0 10px 50px #000a, 0 0 0 1px #ffffff10; border-radius: 3px; }
#glcanvas.picking { cursor: crosshair; outline: 2px solid var(--accent-2); }
#glcanvas.empty { visibility: hidden; }
#dropHint { position: absolute; text-align: center; pointer-events: none; }
#dropHint .link { pointer-events: auto; }
.drop-title { font-size: 18px; margin-bottom: 6px; }
#viewChip {
  position: absolute; left: 14px; top: 12px; display: flex; align-items: center; gap: 6px;
  background: #1d2140e6; border: 1px solid var(--accent); color: #dfe3ff;
  padding: 4px 6px 4px 12px; border-radius: 999px; font-size: 12px; backdrop-filter: blur(6px);
}
#viewChip button { background: none; border: 0; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; }
#viewChip button:hover { background: #ffffff22; }

#videobar, #exportProgress {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 7px 16px; background: var(--panel); border-top: 1px solid var(--line);
}
#scrub { flex: 1; }
#timeLbl { min-width: 90px; text-align: right; }
.bar { flex: 1; height: 8px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
#exportFill { height: 100%; width: 0; background: var(--accent-grad); transition: width .15s; }

/* ---------- splitter ---------- */
#splitter { flex: none; height: 9px; cursor: row-resize; background: var(--panel); border-top: 1px solid var(--line); display: grid; place-items: center; touch-action: none; }
#splitter span { width: 44px; height: 3px; border-radius: 2px; background: var(--line-2); transition: background .12s; }
#splitter:hover span, #splitter.active span { background: var(--accent); }

/* ---------- node editor ---------- */
#graphPanel { flex: none; height: 46%; min-height: 170px; display: flex; flex-direction: column; background: var(--panel-2); }
#graphBar { flex: none; display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-bottom: 1px solid var(--line); }
#graphBar select { width: 190px; padding: 4px 8px; font-size: 12px; }
#graph {
  flex: 1; min-height: 0; position: relative; overflow: hidden; cursor: default; touch-action: none;
  background-color: #0c0e12;
  background-image: radial-gradient(circle, #ffffff14 1px, transparent 1.4px);
  background-size: 24px 24px;
}
#graph.panning { cursor: grabbing; }
#graph.wiring { cursor: crosshair; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#wires { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.graph-ui { position: absolute; pointer-events: none; color: var(--dim); font-size: 11.5px; }
#graphHint { left: 12px; bottom: 8px; }
#graphEmpty { left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 13px; color: var(--muted); }

.wire-g { pointer-events: auto; cursor: pointer; }
.wire { fill: none; stroke: var(--cat); stroke-width: 2.5; stroke-linecap: round; opacity: .75; transition: stroke-width .1s, opacity .1s; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 14; }
.wire-g:hover .wire, .wire-g.hl .wire { stroke-width: 3.5; opacity: 1; }
#tempWire { fill: none; stroke: var(--cat, var(--accent)); stroke-width: 2.5; stroke-dasharray: 6 5; stroke-linecap: round; }

.node {
  position: absolute; background: var(--card); border: 1px solid var(--line-2); border-radius: 11px;
  box-shadow: 0 6px 20px #0008; user-select: none; pointer-events: auto;
  transition: box-shadow .12s, border-color .12s;
}
.node:hover { border-color: #444b5b; }
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 24px #7c8cff33, 0 8px 24px #000a; }
.node.dragging { box-shadow: 0 14px 34px #000c; z-index: 5; }
.node.viewing::after { content: ""; position: absolute; inset: -4px; border-radius: 14px; border: 1.5px dashed var(--accent-2); pointer-events: none; }
.node.has-err { border-color: var(--danger); }
.node-head {
  height: 34px; display: flex; align-items: center; gap: 7px; padding: 0 6px 0 11px; cursor: grab;
  border-radius: 10px 10px 0 0; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, color-mix(in srgb, var(--cat) 20%, transparent), transparent 75%);
}
.node.dragging .node-head { cursor: grabbing; }
.node-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat); flex: none; box-shadow: 0 0 8px var(--cat); }
.node-title { flex: 1; font-weight: 620; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node.off .node-title { color: var(--dim); text-decoration: line-through; }
.node.off { opacity: .7; }
.node-btn {
  width: 22px; height: 22px; padding: 0; display: grid; place-items: center; flex: none;
  background: transparent; border: 0; border-radius: 6px; color: var(--dim); cursor: pointer; font-size: 12px;
}
.node-btn:hover { background: #ffffff14; color: var(--text); }
.node.off .node-btn.bypass { color: var(--danger); }
.node.viewing .node-btn.view { color: var(--accent-2); }
.node-row { position: relative; height: 24px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; font-size: 11.5px; color: var(--muted); }
.node-row:last-child { margin-bottom: 4px; }
.row-l, .row-r { pointer-events: none; }

.port {
  position: absolute; top: 5px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--dim); cursor: crosshair; transition: transform .1s, background .1s, border-color .1s;
}
.port::after { content: ""; position: absolute; inset: -6px; }
.port.in { left: -7px; }
.port.out { right: -7px; }
.port.on { border-color: var(--cat); background: var(--cat); }
.port:hover, .port.hot { transform: scale(1.3); border-color: #fff; }
.port.hot { background: #fff; }

/* ---------- inspector ---------- */
#inspector { width: 330px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.insp-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); border-top: 3px solid var(--cat); background: linear-gradient(180deg, color-mix(in srgb, var(--cat) 9%, transparent), transparent 90px); }
.insp-title-row { display: flex; align-items: center; gap: 9px; }
.insp-title-row h2 { margin: 0; font-size: 16px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 10.5px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.insp-desc { color: var(--muted); margin: 6px 0 12px; font-size: 12.5px; }
.insp-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.insp-actions .btn { white-space: nowrap; }
.byp { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; cursor: pointer; }
.insp-sec { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 13px; }
.insp-sec-title { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--dim); font-weight: 650; margin-bottom: -2px; }
.insp-empty { padding: 28px 22px; }
.insp-empty-title { font-size: 15px; font-weight: 650; margin-bottom: 8px; }
.insp-empty p { margin: 0 0 10px; }
.conn-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.conn-name { color: var(--muted); width: 64px; flex: none; }
.conn-val { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-val.empty { color: var(--dim); font-style: italic; }
.err { color: var(--danger); font-size: 12px; white-space: pre-wrap; padding: 0 16px 14px; }
.mini {
  width: 22px; height: 22px; display: grid; place-items: center; padding: 0; flex: none;
  background: transparent; border: 1px solid transparent; border-radius: 5px;
  color: var(--muted); cursor: pointer; font-size: 12px;
}
.mini:hover:not(:disabled) { background: var(--card-2); color: var(--text); }
.mini:disabled { opacity: .25; cursor: default; }

/* on/off switch */
.switch { position: relative; width: 30px; height: 17px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; inset: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #363c48; border-radius: 9px; transition: background .12s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .12s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); }

/* ---------- controls ---------- */
.ctl-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.ctl-head label { color: var(--muted); cursor: default; }
.ctl-head .val { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--text); }
.ctl.inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ctl.inline label { color: var(--muted); }
.ctl.note { color: var(--dim); font-size: 12px; line-height: 1.5; }
select, input[type=text] {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 7px; padding: 6px 9px; font: inherit; width: 100%;
}
.ctl select { padding: 5px 8px; }
input[type=color] { width: 46px; height: 26px; padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--card-2); cursor: pointer; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 4px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: transparent; margin: 0; cursor: pointer;
  --pct: 50%;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) var(--pct), #343a47 var(--pct)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; margin-top: -5px; border: 0; box-shadow: 0 1px 4px #0008; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #343a47; }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }

.grad-bar { height: 20px; border-radius: 6px; border: 1px solid var(--line-2); margin-bottom: 8px; }
.grad-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.grad-row input[type=range] { flex: 1; }

/* ---------- add-node menu ---------- */
#addMenu {
  position: fixed; z-index: 70; width: 320px; max-height: min(460px, 80vh); display: flex; flex-direction: column;
  background: #14171dF2; backdrop-filter: blur(14px); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 20px 60px #000c; overflow: hidden;
}
#menuSearch { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 12px 14px; font-size: 13.5px; }
#menuSearch:focus-visible { outline: none; }
#menuList { overflow-y: auto; padding: 4px 6px 8px; }
.menu-cat { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--dim); font-weight: 650; padding: 10px 8px 4px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.menu-item.active { background: #262b3a; }
.menu-txt { flex: 1; min-width: 0; }
.menu-name { font-weight: 600; font-size: 12.5px; }
.menu-desc { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; color: var(--accent-2); border: 1px solid #b38cff55; border-radius: 999px; padding: 0 7px; flex: none; }
.menu-empty { padding: 20px; text-align: center; color: var(--muted); }

/* ---------- overlays ---------- */
#dropOverlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: #0a0b10cc; border: 3px dashed var(--accent); font-size: 26px; pointer-events: none;
}
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1d212b; border: 1px solid var(--line-2); border-left: 3px solid var(--accent); padding: 9px 14px; border-radius: 8px; max-width: min(560px, 90vw); box-shadow: 0 8px 28px #000a; }
.toast.error { border-left-color: var(--danger); }

/* ---------- small screens: inspector goes under the stage ---------- */
@media (max-width: 900px) {
  main { flex-direction: column; overflow-y: auto; }
  #stage { min-height: 100vh; flex: none; }
  #inspector { width: auto; border-left: 0; border-top: 1px solid var(--line); flex: none; }
  #srcInfo { display: none; }
}
