:root {
  --bg: #0a0b14;
  --bg-2: #11132099;
  --panel: #141627;
  --panel-2: #1b1e33;
  --border: #272a45;
  --text: #eef0fb;
  --muted: #8a8fb5;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --good: #2bd576;
  --danger: #ff5d6c;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 12% -10%, #2a1d5e55, transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, #06485a55, transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #14162799, transparent);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  font-size: 26px; width: 46px; height: 46px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 13px; box-shadow: var(--shadow);
}
.brand h1 { font-family: 'Sora', sans-serif; font-size: 20px; margin: 0; letter-spacing: -.4px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 270px 1fr 340px;
  gap: 16px; padding: 16px; align-items: start;
  max-width: 1700px; margin: 0 auto;
}
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.count {
  font-size: 12px; background: var(--panel-2); border: 1px solid var(--border);
  padding: 1px 9px; border-radius: 999px; color: var(--muted);
}

/* Sticky side panels */
.library, .editor { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; }

/* Fields */
.field-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 12px 0 6px; }
.input, .select {
  width: 100%; padding: 10px 12px; border-radius: 11px;
  background: #0e1020; border: 1px solid var(--border); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #7c5cff33; }
.input.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.select.small { width: auto; padding: 8px 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Buttons */
.btn {
  appearance: none; cursor: pointer; border: 1px solid var(--border);
  background: #1a1d33; color: var(--text); padding: 10px 14px; border-radius: 11px;
  font-size: 13px; font-weight: 600; font-family: inherit; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { background: #222648; }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; margin-top: 10px; }
.btn.subtle { background: transparent; }
.btn.ghost { background: transparent; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #9a7bff);
  border-color: transparent; box-shadow: 0 6px 20px #7c5cff44;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.mini-btn {
  cursor: pointer; border: 1px dashed var(--border); background: transparent; color: var(--muted);
  font-size: 12px; padding: 3px 9px; border-radius: 8px; font-family: inherit;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }

/* Library */
.presets { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.lib-list { display: flex; flex-direction: column; gap: 8px; min-height: 20px; }
.lib-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-radius: 11px; background: #0e1020; border: 1px solid var(--border);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.lib-item:hover { border-color: var(--accent); }
.lib-item.active { border-color: var(--accent); background: #181a30; }
.lib-item .li-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .li-sub { font-size: 11px; color: var(--muted); }
.lib-del { color: var(--muted); border: none; background: none; cursor: pointer; font-size: 15px; padding: 2px 4px; }
.lib-del:hover { color: var(--danger); }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 0; }

/* Stage */
.stage { display: flex; flex-direction: column; gap: 14px; }
.stage-toolbar { display: flex; justify-content: center; }
.orient-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: #0e1020; border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; color: var(--muted);
}

.canvas-wrap {
  position: relative; display: grid; place-items: center;
  background: repeating-conic-gradient(#0c0e1a 0% 25%, #0a0c16 0% 50%) 50% / 22px 22px;
  border-radius: 14px; border: 1px solid var(--border); padding: 14px; min-height: 320px;
}
canvas {
  max-width: 100%; max-height: 62vh; border-radius: 10px; box-shadow: var(--shadow); background: #000;
}
.rec-overlay {
  position: absolute; inset: 0; display: none; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: #060713dd; border-radius: 14px; z-index: 5;
}
.rec-overlay.show { display: flex; }
.rec-overlay p { margin: 0; font-weight: 600; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid #ffffff22; border-top-color: var(--accent-2); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 220px; height: 8px; background: #ffffff18; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .1s; }

.transport { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* JSON editor */
.json-area {
  width: 100%; min-height: 320px; resize: vertical; line-height: 1.5;
  white-space: pre; overflow-wrap: normal; overflow-x: auto; tab-size: 2;
}
.json-msg { font-size: 12px; min-height: 18px; margin: 8px 0 4px; }
.json-msg.ok { color: var(--good); }
.json-msg.err { color: var(--danger); }
.copy-btn { width: 100%; margin-top: 8px; }
.json-help { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.json-help summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.json-help summary:hover { color: var(--text); }
.schema-list { padding-left: 18px; margin: 8px 0; }
.schema-list li { margin: 3px 0; }
.note code, .schema-list code {
  background: #0a0c18; border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 5px; font-family: ui-monospace, monospace; font-size: 11px; color: var(--accent-2);
}
.code-sample {
  background: #0a0c18; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11px;
  line-height: 1.5; color: #c8cdf0; overflow-x: auto; white-space: pre; margin-top: 10px;
}

.note { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 14px; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2d4a; border-radius: 8px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .library, .editor { position: static; max-height: none; }
}
