:root {
  --bg: #0a0a0a;
  --panel: rgba(12, 14, 18, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f4f5;
  --muted: #8b93a1;
  --cyan: #00f3ff;
  --magenta: #ff00aa;
  --bad: #ff4d6a;
  --ok: #2ee59d;
  --font: "Montserrat", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, Consolas, monospace;
  --rail: 176px;
  --inspect: 320px;
  --log: 52px;
  --libs: 176px;
  --top: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font: 13px/1.4 var(--font); }
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--cyan); background: var(--cyan); color: #041016; font-weight: 650; border-radius: 999px; padding: 7px 14px; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.go { background: linear-gradient(90deg, var(--cyan), var(--magenta)); border: 0; color: #041016; }
input, textarea, select {
  background: #0c0e12; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.boot {
  position: fixed; inset: 0; display: grid; place-items: center; text-align: center;
  background: #050506 url("/field.jpg") center / cover no-repeat;
}
.boot::before { content: ""; position: absolute; inset: 0; background: rgba(5,5,6,0.72); }
.boot > * { position: relative; }
.boot img { border-radius: 18px; border: 1px solid var(--line); }
.boot h1 { margin: 14px 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }
.boot p { margin: 0 0 18px; color: var(--muted); }
.bar { width: 180px; height: 3px; margin: 0 auto; background: #1a1c22; overflow: hidden; }
.bar i { display: block; height: 100%; width: 40%; background: linear-gradient(90deg, var(--cyan), var(--magenta)); animation: load 1.1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-120%); } to { transform: translateX(320%); } }

.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: var(--rail) 1fr var(--inspect);
  grid-template-rows: var(--top) 1fr var(--libs) var(--log);
  grid-template-areas:
    "top top top"
    "rail stage inspect"
    "libs libs libs"
    "log log log";
}
.top {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: rgba(10,10,10,0.82); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 8px; background: transparent; border: 0; color: var(--cyan); padding: 4px; border-radius: 10px; }
.brand img { border-radius: 8px; }
.brand span { font-weight: 800; letter-spacing: -0.03em; }
.title { max-width: 280px; background: transparent; border-color: transparent; font-weight: 650; }
.grow { flex: 1; }
.pulse { color: var(--muted); font-variant-numeric: tabular-nums; }

.rail {
  grid-area: rail; overflow: auto; padding: 10px 8px;
  border-right: 1px solid var(--line); background: rgba(8,8,10,0.7);
}
.rail h3 { margin: 0 8px 8px; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.cap {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 6px;
  background: #101318; color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; text-align: left; font-weight: 600;
}
.cap:hover { border-color: var(--cyan); color: var(--cyan); }
.cap.make { border-color: rgba(0, 243, 255, 0.35); }
.cap.make b { color: var(--cyan); }
.cap b { width: 28px; color: var(--magenta); font-size: 10px; letter-spacing: 0.04em; }

.stage { grid-area: stage; position: relative; overflow: hidden; background: #050506 url("/field.jpg") center / cover no-repeat; }
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(900px 500px at 10% 0%, rgba(0,243,255,0.08), transparent 50%),
              radial-gradient(700px 400px at 90% 100%, rgba(255,0,170,0.08), transparent 50%);
}
#field { position: absolute; inset: 0; width: 100%; height: 100%; }
#nodes { position: absolute; inset: 0; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.node {
  position: absolute; width: 180px; min-height: 72px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px 14px; backdrop-filter: blur(12px); cursor: grab; user-select: none;
}
.node.on { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }
.node.bad { border-color: var(--bad); }
.node.ok { border-color: var(--ok); }
.node .k { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cyan); }
.node h4 { margin: 2px 0 0; font-size: 13px; font-weight: 700; }
.port {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--magenta); border: 2px solid #041016; z-index: 2;
}
.port.in { left: -8px; top: 30px; }
.port.out { right: -8px; top: 30px; background: var(--cyan); }
.port::after {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 8px; letter-spacing: 0.08em; color: var(--muted); font-weight: 700;
}
.port.in::after { content: "IN"; color: var(--magenta); }
.port.out::after { content: "OUT"; color: var(--cyan); }
.hint {
  position: absolute; left: 12px; right: 12px; bottom: 10px; z-index: 3;
  pointer-events: none;
  background: rgba(10,10,10,0.78); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; color: var(--text); font-size: 12px;
}

.inspect {
  grid-area: inspect; overflow: auto; padding: 12px;
  border-left: 1px solid var(--line); background: rgba(8,8,10,0.78);
}
.inspect h2 { margin: 0 0 6px; font-size: 14px; }
.inspect label { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.inspect pre, .log {
  white-space: pre-wrap; font-family: var(--mono); font-size: 11px;
}
.preview { width: 100%; border-radius: 10px; border: 1px solid var(--line); margin-top: 8px; }

.libs {
  grid-area: libs; display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px;
  background: var(--line); border-top: 1px solid var(--line);
}
.lib {
  background: #0b0d10; padding: 6px 8px; overflow: auto; min-width: 0;
}
.lib h4 {
  margin: 0 0 6px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cyan);
}
.lib .empty { color: var(--muted); font-size: 11px; }
.lib-item {
  display: grid; grid-template-columns: 52px 1fr; gap: 6px; align-items: center;
  padding: 4px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.lib-item:hover { color: var(--cyan); }
.lib-item img { width: 52px; height: 36px; object-fit: cover; border-radius: 4px; background: #050506; }
.lib-item audio { width: 100%; height: 22px; }
.lib-item .meta { font-size: 10px; color: var(--muted); }
.lib-item .meta b { display: block; color: var(--text); font-size: 11px; font-weight: 650; }

.log {
  grid-area: log; overflow: auto; padding: 8px 12px;
  border-top: 1px solid var(--line); background: #07080a; color: #c9d2dc;
}

.spot {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%);
  width: min(520px, 92vw); z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.spot ul { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; }
.spot li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.spot li:hover, .spot li.on { background: rgba(0,243,255,0.12); color: var(--cyan); }

.modal {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50;
  background: rgba(0,0,0,0.55);
}
.sheet {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--top) 56px 1fr 160px 150px 80px;
    grid-template-areas:
      "top"
      "rail"
      "stage"
      "inspect"
      "libs"
      "log";
  }
  .rail { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail h3 { display: none; }
  .cap { width: auto; white-space: nowrap; }
}
