:root {
  --fog: #e8ecf1;
  --paper: #f7f8fa;
  --ink: #141a26;
  --ink-2: #4a5468;
  --line: #d3d9e2;
  --signal: #3340ff;
  --signal-ink: #ffffff;
  --stage: #0c1017;
  --warn: #b25e00;
  --bad: #c2303a;
  --ok: #157a52;
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Instrument Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  --display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--fog); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); margin: 0; }

.app { display: grid; grid-template-columns: 380px minmax(0, 1fr) 500px; height: 100vh; }

/* ---------- rail ---------- */
.rail { background: var(--paper); border-right: 1px solid var(--line); padding: 18px 18px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--ink-2); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; position: relative; flex: none; }
.brand-mark span { position: absolute; inset: 0; border: 2.5px solid var(--signal); border-radius: 50%; }
.brand-mark span:nth-child(2) { inset: 6px; border-color: var(--ink); }
.brand-mark span:nth-child(3) { inset: 13px; background: var(--signal); border: 0; }
.icon-btn { margin-left: auto; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px; }
.icon-btn:hover { border-color: var(--ink); }

.tabs { display: flex; gap: 4px; background: var(--fog); padding: 4px; border-radius: 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.tab.is-active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(20,26,38,.12); }
.tabs.small .tab { font-size: 12.5px; padding: 7px 4px; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 3px; }

.panel, .ipanel { display: none; }
.panel.is-active { display: flex; flex-direction: column; gap: 12px; }
.ipanel.is-active { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-weight: 600; font-size: 12.5px; }
.field.grow { flex: 1; }
textarea, input[type=text], input[type=number], input[type=password], input:not([type]), select {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 9px 10px; width: 100%;
}
textarea { resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--signal); outline-offset: 0; border-color: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 12px; }
.chip:hover { border-color: var(--signal); color: var(--signal); }

.drop { border: 1.5px dashed var(--ink-2); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; background: #fff; }
.drop:hover, .drop.over { border-color: var(--signal); background: #f0f2ff; }
.drop small { color: var(--ink-2); }
.frames { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.frames img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 4px; background: var(--fog); }

.opts { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.opts legend { font-weight: 600; font-size: 12.5px; padding: 0 4px; }
.radio { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.radio input { margin-top: 4px; }
.radio b { display: block; font-size: 13px; }
.radio em { display: block; font-style: normal; color: var(--ink-2); font-size: 12px; }

.specs { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 10px 12px; }
.specs summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.specs[open] summary { margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; margin-top: 8px; }
.check.small { margin: 0; font-size: 12px; }
.libs { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; margin-top: 8px; }
.libs > span { font-weight: 600; font-size: 12.5px; margin-top: 8px; }

.cta { display: flex; gap: 8px; }
.btn { border: 1px solid var(--line); background: #fff; padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); flex: 1; }
.btn.primary:hover:not(:disabled) { background: #2230e0; border-color: #2230e0; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.status { min-height: 18px; font-size: 12.5px; color: var(--ink-2); }
.status.err { color: var(--bad); }
.status.ok { color: var(--ok); }
.hint { color: var(--ink-2); font-size: 12.5px; margin: 0; }
.muted { color: var(--ink-2); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.end { justify-content: flex-end; }

/* ---------- stage ---------- */
.stage-col { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px; gap: 10px; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.seg { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.seg button.is-active { background: var(--ink); color: #fff; }
.meta-line { font-size: 12px; color: var(--ink-2); font-family: var(--mono); text-align: right; }

.stage { position: relative; flex: 1; min-height: 240px; border-radius: 14px; overflow: hidden; background: var(--stage); display: grid; place-items: center; }
.stage[data-bg=checker] { background-color: #2a303c; background-image:
  linear-gradient(45deg, #3a4150 25%, transparent 25%, transparent 75%, #3a4150 75%),
  linear-gradient(45deg, #3a4150 25%, transparent 25%, transparent 75%, #3a4150 75%);
  background-size: 28px 28px; background-position: 0 0, 14px 14px; }
.stage[data-bg=green] { background: #00ff00; }
.stage[data-bg=white] { background: #ffffff; }
.stage[data-bg=black] { background: #000000; }
.viewport { position: absolute; left: 50%; top: 50%; transform-origin: 0 0; }
.viewport iframe { border: 0; display: block; background: transparent; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #c9d0dd; padding: 30px; gap: 6px; background: rgba(12,16,23,.78); }
.empty h2 { font-size: 22px; color: #fff; }
.empty p { margin: 0; max-width: 420px; }
.busy { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(12,16,23,.86); color: #fff; }
.busy[hidden] { display: none; }
.spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; animation: sp 0.9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }

.transport { display: flex; align-items: center; gap: 10px; }
.transport input[type=range] { flex: 1; accent-color: var(--signal); padding: 0; }
.time { font-family: var(--mono); font-size: 12px; color: var(--ink-2); min-width: 120px; text-align: right; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- inspector ---------- */
.inspector { background: var(--paper); border-left: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: hidden; }
.code-tools { display: flex; justify-content: space-between; align-items: center; }
#code { flex: 1; min-height: 0; font-family: var(--mono); font-size: 12px; line-height: 1.5; white-space: pre; tab-size: 2; resize: none; overflow: auto; background: #0f141d; color: #d8deea; border-color: #0f141d; }
.ipanel[data-ipanel=check], .ipanel[data-ipanel=meta], .ipanel[data-ipanel=render] { overflow-y: auto; }

.checklist { display: flex; flex-direction: column; gap: 6px; }
.ck { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 8px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--line); font-size: 12.5px; }
.ck b { font-size: 11.5px; }
.ck.error b { color: var(--bad); } .ck.warn b { color: var(--warn); } .ck.ok b { color: var(--ok); }

.metabox h3 { font-size: 13px; margin: 10px 0 4px; }
.metabox .val { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; word-break: break-word; }
.kw { display: flex; flex-wrap: wrap; gap: 4px; }
.kw span { background: var(--fog); border-radius: 6px; padding: 2px 7px; font-size: 12px; }
.cmd { background: #0f141d; color: #d8deea; border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-all; margin: 0; }
.steps { padding-left: 18px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.rules { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.rules h3 { font-size: 13px; }
.rules ul { margin: 6px 0; padding-left: 18px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, 92vw); box-shadow: 0 20px 60px rgba(12,16,23,.35); }
dialog::backdrop { background: rgba(12,16,23,.5); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { font-size: 20px; }

@media (max-width: 1280px) { .app { grid-template-columns: 340px minmax(0,1fr) 420px; } }
@media (max-width: 1020px) {
  .app { display: flex; flex-direction: column; height: auto; }
  .rail, .inspector { border: 0; overflow: visible; }
  .stage { min-height: 320px; flex: none; }
  #code { min-height: 420px; }
  .inspector { max-height: none; }
}
