:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1d242e;
  --line: #2b3442;
  --text: #dbe2ea;
  --muted: #8694a7;
  --accent: #4f9cff;
  --accent-2: #2c5e9e;
  --danger: #ff6b6b;
  --ok: #4cd97b;
  --node-w: 340px;
  font-size: 14px;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .modal-backdrop { display: flex }) override the
   UA's [hidden] { display: none }, so restore hidden's meaning explicitly. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font: inherit;
}
button:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent-2); border-color: var(--accent); }
.btn-danger { color: var(--danger); }

input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

kbd {
  background: var(--bg-3); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, monospace; font-size: 0.85em;
}

.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- Toolbar / statusbar ---------- */

#toolbar, #statusbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
}
#statusbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  border-bottom: none; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
/* The shortcut hints are the app's main affordance — keep them readable. */
#statusHint { color: var(--text); }
#statusHint kbd {
  color: var(--accent); border-color: var(--accent-2);
  background: rgba(79, 156, 255, 0.10);
}
#btnHelp { color: var(--accent); border-color: var(--accent-2); }
#projectName {
  width: 220px; background: transparent; border-color: transparent; font-weight: 600;
}
#projectName:hover, #projectName:focus { border-color: var(--line); background: var(--bg); }
#saveState { font-size: 12px; }

/* ---------- Canvas ---------- */

#canvas {
  position: absolute; inset: 37px 0 33px 0;
  overflow: hidden; cursor: grab;
  background:
    radial-gradient(circle, #222a36 1px, transparent 1px) 0 0 / 28px 28px;
}
#canvas.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#world.animate { transition: transform 0.18s ease-out; }
#edges { position: absolute; overflow: visible; pointer-events: none; }
#edges path { fill: none; stroke: var(--line); stroke-width: 2; }
#edges path.sel { stroke: var(--accent); }
#nodes { position: absolute; left: 0; top: 0; }

#emptyHint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  color: var(--muted); pointer-events: none;
}
#emptyHint h2 { color: var(--text); margin-bottom: 4px; }

/* ---------- Nodes ---------- */

.node {
  position: absolute; width: var(--node-w);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  user-select: none;
}
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-2), 0 4px 14px rgba(0,0,0,0.4); }

.node-head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
  font-size: 11px; color: var(--muted); cursor: move;
}
.badge {
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.badge.type-text  { color: #9ecbff; }
.badge.type-image { color: #b6f2a4; }
.badge.type-video { color: #ffb86b; }
.badge.type-audio { color: #e3a4f2; }
.badge.model { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: none; }
.node-head .gear {
  margin-left: auto; background: none; border: none; padding: 0 3px; color: var(--muted); font-size: 13px;
}
.node-head .gear:hover { color: var(--text); }

.node-head .vctl {
  display: inline-flex; align-items: center; gap: 2px;
  border: 1px solid var(--accent-2); border-radius: 4px; padding: 0 2px;
  color: var(--accent); white-space: nowrap;
}
.node-head .vctl button {
  background: none; border: none; padding: 0 3px; color: var(--accent);
  font-size: 12px; line-height: 1.2; cursor: pointer;
}
.node-head .vctl button:disabled { color: var(--muted); cursor: default; }

.node-prompt {
  padding: 8px 10px; white-space: pre-wrap; word-wrap: break-word;
  font-size: 13px; min-height: 18px; cursor: text;
}
.node-prompt.placeholder { color: var(--muted); font-style: italic; }
.node textarea {
  display: block; width: calc(100% - 12px); margin: 6px; padding: 6px;
  resize: none; min-height: 56px; font-size: 13px; line-height: 1.4;
}

.node-body { border-top: 1px dashed var(--line); padding: 8px 10px; font-size: 13px; }
.node-body:empty { display: none; }
.node-body .md { user-select: text; cursor: auto; }
.node-body img, .node-body video {
  max-width: 100%; border-radius: 6px; display: block;
}
.node-body audio { width: 100%; }

.node-body .md h1, .node-body .md h2, .node-body .md h3 { margin: 8px 0 4px; font-size: 1.05em; }
.node-body .md p { margin: 4px 0; }
.node-body .md pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; overflow-x: auto; font-size: 12px;
}
.node-body .md code { font-family: ui-monospace, monospace; background: var(--bg); padding: 0 3px; border-radius: 3px; }
.node-body .md pre code { padding: 0; background: none; }
.node-body .md ul, .node-body .md ol { margin: 4px 0; padding-left: 20px; }
.node-body .md blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.node-body .md a { color: var(--accent); }

.node-error { color: var(--danger); font-size: 12px; white-space: pre-wrap; }

.spinner {
  width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; width: 440px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
}
.modal-wide { width: 720px; }
.modal h2 { margin: 0 0 10px; font-size: 16px; }
.modal label { display: block; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.modal label input, .modal label select { display: block; width: 100%; margin-top: 3px; color: var(--text); }
.modal fieldset { border: 1px solid var(--line); border-radius: 8px; margin-top: 12px; }
.modal fieldset legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.project-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.project-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.project-row.current { border-color: var(--accent); }
.project-row .pname { font-weight: 600; }
.project-row .pmeta { font-size: 11px; color: var(--muted); }
.project-row button { padding: 3px 8px; font-size: 12px; }

.help-cols { display: flex; gap: 24px; flex-wrap: wrap; }
.help-cols table { border-collapse: collapse; font-size: 13px; flex: 1; min-width: 280px; }
.help-cols th { text-align: left; padding: 10px 0 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.help-cols td { padding: 3px 12px 3px 0; vertical-align: top; }

/* Model input + Browse button rows (settings & node settings). */
.modal label .model-row { display: flex; gap: 6px; margin-top: 3px; }
.modal label .model-row input { width: auto; flex: 1; margin-top: 0; }
.modal label .model-row .pick { padding: 4px 10px; font-size: 12px; white-space: nowrap; }

/* ---------- Model picker ---------- */

.picker-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0; }
.picker-controls #modelSearch { flex: 1; min-width: 160px; }
.picker-controls .inline {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.model-list { display: flex; flex-direction: column; gap: 4px; max-height: 52vh; overflow-y: auto; }
.model-item { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.model-item:hover { border-color: var(--accent); background: var(--bg-3); }
.model-item .mi-name { font-weight: 600; font-size: 13px; }
.model-item .mi-id { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); margin-left: 6px; }
.model-item .mi-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.version-list { display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow-y: auto; margin: 6px 0; }
.version-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px;
}
.version-row.current { border-color: var(--accent); }
.version-row .pname { font-weight: 600; }
.version-row .pmeta { font-size: 11px; color: var(--muted); }
.version-row button { padding: 2px 7px; font-size: 11px; }

/* ---------- Progress overlay ---------- */

#progress {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.progress-box {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px 28px; min-width: 260px; max-width: 80vw;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5); font-size: 13px;
}
.progress-box .spinner { width: 22px; height: 22px; }
.progress-bar {
  width: 100%; height: 6px; border-radius: 3px;
  background: var(--bg); border: 1px solid var(--line); overflow: hidden;
}
.progress-bar div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s ease-out; }

/* ---------- Toasts ---------- */

#toasts {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 200; pointer-events: none;
}
.toast {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  animation: toast-in 0.15s ease-out;
}
.toast.error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
