*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: #0a0a0c;
  color: #e8e8ea;
  height: 100vh;
  overflow: hidden;
}

#app { height: 100vh; }

.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 1fr 380px;
  height: 100%;
  gap: 1px;
  background: #1a1a20;
}

.right-panel {
  display: grid;
  grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
  background: #0d0d12;
  overflow: hidden;
  min-height: 0;
}

.transport {
  grid-column: 1 / -1;
  background: #14141a;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  font-size: 13px;
}

.transport .file-name {
  color: #9a9aa8;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transport .time {
  font-family: ui-monospace, monospace;
  color: #9a9aa8;
  margin-left: auto;
}

.transport .error { color: #ff6b6b; font-size: 12px; }

.canvas-wrap {
  background: #07070a;
  position: relative;
  overflow: hidden;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.monitor {
  background: #0d0d12;
  overflow-y: auto;
  padding: 4px;
  min-height: 0;
}

.signal-row {
  display: grid;
  grid-template-columns: 1fr 56px;
  grid-template-rows: auto 18px;
  column-gap: 8px;
  padding: 4px 8px;
  font-size: 11px;
  border-bottom: 1px solid #16161c;
}

.signal-row .name {
  font-family: ui-monospace, monospace;
  color: #8a8a98;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signal-row.derived .name { color: #b89aff; }

.signal-row .value {
  font-family: ui-monospace, monospace;
  text-align: right;
  color: #e8e8ea;
}

.signal-row .spark {
  grid-column: 1 / -1;
  width: 100%;
  height: 18px;
}

button {
  background: #2a2a35;
  color: #e8e8ea;
  border: 1px solid #3a3a45;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

button:hover:not(:disabled) { background: #3a3a45; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input[type=file] {
  font-size: 12px;
  color: #9a9aa8;
}

input[type=file]::file-selector-button {
  background: #2a2a35;
  color: #e8e8ea;
  border: 1px solid #3a3a45;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 8px;
  font-family: inherit;
}

/* --- editor pane --- */

.editor-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  border-bottom: 1px solid #1a1a20;
  background: #0a0a0e;
}

.editor-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid #16161c;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.preset-row button {
  font-size: 11px;
  padding: 4px 8px;
  background: #1a1a22;
  border: 1px solid #25252e;
}

.preset-row button.active {
  background: #3a2a55;
  border-color: #6a4adf;
  color: #d8c5ff;
}

.preset-row button.custom-preset {
  margin-left: auto;
  border-style: dashed;
  color: #9affc5;
  border-color: #2a3a30;
}

.preset-row button.custom-preset.active {
  background: #1c3a2c;
  border-color: #4adf8a;
  color: #c5ffd8;
  border-style: solid;
}

button.apply {
  font-size: 11px;
  padding: 4px 10px;
  align-self: flex-end;
  font-family: ui-monospace, monospace;
}

button.apply.dirty {
  background: #3a2a55;
  border-color: #6a4adf;
  color: #d8c5ff;
}

textarea.scene-source {
  width: 100%;
  height: 100%;
  background: #07070a;
  color: #d0d0d8;
  border: none;
  outline: none;
  padding: 8px 10px;
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 11.5px;
  line-height: 1.45;
  resize: none;
  tab-size: 2;
}

textarea.scene-source:focus {
  background: #08080d;
}

.editor-error {
  background: #2a0a0a;
  color: #ff8888;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  padding: 6px 10px;
  border-top: 1px solid #4a1a1a;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- help button + modal --- */

.help-btn {
  background: #1a1a22;
  border: 1px solid #2a2a35;
  color: #b89aff;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  margin-left: 6px;
}

.help-btn:hover:not(:disabled) { background: #2a2a35; }

.help-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.help-card {
  background: #0f0f15;
  border: 1px solid #2a2a35;
  border-radius: 8px;
  width: min(900px, 100%);
  max-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid #1a1a22;
  background: #14141c;
}

.help-head h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #d8c5ff;
}

.help-close {
  background: transparent;
  border: none;
  color: #8a8a98;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 4px;
}

.help-close:hover { background: #1f1f28; color: #e8e8ea; }

.help-body {
  overflow-y: auto;
  padding: 20px 26px 28px;
  color: #d0d0d8;
  font-size: 13px;
  line-height: 1.55;
}

.help-body section { margin-bottom: 26px; }
.help-body section:last-child { margin-bottom: 0; }

.help-body h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b89aff;
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid #1a1a22;
}

.help-body p { margin-bottom: 8px; color: #c8c8d4; }
.help-body p.note { color: #9a9aa8; font-size: 12px; }

.help-body ul, .help-body ol { margin: 0 0 8px 18px; }
.help-body li { margin-bottom: 4px; }

.help-body code,
.help-body pre {
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 12px;
}

.help-body code {
  background: #1a1a22;
  border: 1px solid #25252e;
  padding: 1px 5px;
  border-radius: 3px;
  color: #d8c5ff;
}

.help-body pre {
  background: #07070a;
  border: 1px solid #1a1a22;
  border-radius: 4px;
  padding: 10px 12px;
  overflow-x: auto;
  color: #d0d0d8;
  margin-bottom: 8px;
  white-space: pre;
}

.help-body pre.diagram { color: #9a9aa8; }

.help-body kbd {
  background: #1f1f28;
  border: 1px solid #2a2a35;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #e8e8ea;
}

.help-body table.help-tbl,
.help-body table.help-sig {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
  font-size: 12px;
}

.help-body th,
.help-body td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid #1a1a22;
  vertical-align: top;
}

.help-body th {
  color: #8a8a98;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.help-body table.help-sig tr.raw td:first-child code { color: #d8c5ff; }
.help-body table.help-sig tr.derived td:first-child code { color: #9affc5; }
.help-body table.help-sig .expr {
  margin-top: 4px;
  font-size: 11px;
  color: #9a9aa8;
}

.help-body dl.recipes { display: grid; grid-template-columns: minmax(180px, auto) 1fr; gap: 6px 14px; }
.help-body dl.recipes dt { color: #b89aff; font-weight: 500; }
.help-body dl.recipes dd { margin: 0; color: #c8c8d4; }
