:root {
  --bg: #0f1114;
  --panel: #171a1f;
  --panel-2: #1d2128;
  --line: #2a2f38;
  --line-2: #363c47;
  --text: #e6e8ec;
  --muted: #8b93a1;
  --dim: #5d6573;
  --accent: #ffae1a;
  --accent-2: #ff8a00;
  --accent-ink: #1a1204;
  --sel: rgba(255, 174, 26, .14);
  --danger: #ff5a5a;
  --ok: #3ad07a;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0; }

/* ---------- top bar ---------- */
.topbar { height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-size: 15px; letter-spacing: .01em; flex: none; }
.brand b { color: var(--accent); font-weight: 600; }
.doc-name { background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; min-width: 80px; width: 220px; color: var(--text); }
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 11px; cursor: pointer; white-space: nowrap; transition: border-color .12s, background .12s; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #ffbe45; }
.btn.icon { padding: 5px 9px; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.menu { position: relative; }
.menu-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 220px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 4px; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.menu-pop button:hover { background: var(--sel); color: var(--accent); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr 320px; height: calc(100% - 48px); }
.panel { background: var(--panel); overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px; }

.emitter-list { list-style: none; margin: 0 0 8px; padding: 0 6px; }
.emitter-list li { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.emitter-list li:hover { background: var(--panel-2); }
.emitter-list li.sel { background: var(--sel); border-color: rgba(255,174,26,.35); }
.emitter-list li .thumb { width: 22px; height: 22px; border-radius: 4px; background: #000; flex: none; }
.emitter-list li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emitter-list li.off .nm { color: var(--dim); text-decoration: line-through; }
.emitter-list li .ib { background: none; border: 0; padding: 2px 4px; color: var(--dim); cursor: pointer; border-radius: 4px; font-size: 12px; }
.emitter-list li .ib:hover { color: var(--text); background: var(--line); }
.emitter-list li.primary { border-color: var(--accent); }
.emitter-list li.group .nm { font-weight: 600; }
.emitter-list li .caret { width: 14px; flex: none; background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: 10px; }
.emitter-list li .caret.none { cursor: default; }
.emitter-list li .gicon { display: grid; place-items: center; background: var(--panel-2) !important; color: var(--accent); font-size: 13px; }
.emitter-list li.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.emitter-list li.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.emitter-list li.drop-inside { background: var(--sel); border-color: var(--accent); border-style: dashed; }
.emitter-list.drop-root { box-shadow: inset 0 -2px 0 var(--accent); }
.emitter-list { min-height: 40px; padding-bottom: 12px; }
.mono { font: 12px var(--mono); color: var(--text); }
.multi-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 180px; overflow-y: auto; }
.multi-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 5px; cursor: pointer; }
.multi-list li:hover { background: var(--panel-2); color: var(--accent); }
.multi-list .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); flex: none; }
.multi-list .dot.g { transform: rotate(45deg); background: none; border: 1.5px solid var(--accent); }
.vp-hint { position: absolute; left: 12px; bottom: 52px; font-size: 11px; color: var(--dim); pointer-events: none; text-shadow: 0 1px 2px #000; }

/* ---------- viewport ---------- */
.viewport { position: relative; min-width: 0; background: #0b0c0e; overflow: hidden; }
.viewport canvas { position: absolute; inset: 0 0 44px 0; width: 100%; height: calc(100% - 44px); display: block; }
#overlay { cursor: default; touch-action: none; }
#overlay.dragging { cursor: grabbing; }
#overlay.handle { cursor: move; }
.toolbar { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 2px; padding: 3px; background: rgba(23,26,31,.9); border: 1px solid var(--line-2); border-radius: 8px; z-index: 1; }
.toolbar .tool { width: 32px; height: 30px; display: grid; place-items: center; background: none; border: 0; border-radius: 5px; color: var(--muted); cursor: pointer; }
.toolbar .tool:hover { background: var(--panel-2); color: var(--text); }
.toolbar .tool.on { background: var(--sel); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(255,174,26,.45); }
#overlay.hand { cursor: grab; }
.vp-tools { position: absolute; top: 10px; left: 56px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: rgba(23,26,31,.85); backdrop-filter: blur(6px); border: 1px solid var(--line-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; user-select: none; }
.chip:hover { border-color: var(--muted); }
.chip input[type=checkbox] { accent-color: var(--accent); margin: 0; }
.chip.color input { width: 16px; height: 16px; padding: 0; border: 0; background: none; cursor: pointer; }
.vp-stats { position: absolute; top: 12px; right: 12px; font: 11px var(--mono); color: var(--muted); background: rgba(15,17,20,.7); padding: 3px 8px; border-radius: 4px; pointer-events: none; }
.timeline { position: absolute; left: 0; right: 0; bottom: 0; height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); }
.tbtn { width: 30px; height: 28px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line-2); cursor: pointer; font-size: 12px; }
.tbtn.play { color: var(--accent); }
.tbtn:hover { border-color: var(--muted); }
#scrub { flex: 1; accent-color: var(--accent); min-width: 60px; }
.tc { font: 12px var(--mono); color: var(--muted); min-width: 108px; text-align: right; }
select { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 6px; }

/* ---------- inspector ---------- */
.inspector { padding-bottom: 40px; }
.section { border-top: 1px solid var(--line); }
.section > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; font-weight: 600; font-size: 12px; user-select: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: '▸'; color: var(--dim); font-size: 10px; transition: transform .12s; }
.section[open] > summary::before { transform: rotate(90deg); }
.section > summary:hover { background: var(--panel-2); }
.fields { padding: 2px 12px 12px; display: grid; gap: 6px; }
.row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; min-height: 26px; }
.row > label, .row > .lbl { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .lbl.scrub { cursor: ew-resize; }
.row .lbl.scrub:hover { color: var(--accent); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.num { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; font: 12px var(--mono); }
.num:focus, .txt:focus, select:focus { outline: none; border-color: var(--accent); }
.num.tag { position: relative; }
.ph { position: relative; }
.ph > span { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); font: 10px var(--mono); color: var(--dim); pointer-events: none; }
.ph > .num { padding-left: 30px; }
.txt { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--bg); border: 0; padding: 3px 10px; cursor: pointer; font-size: 12px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--sel); color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); margin: 0; }
.hint { color: var(--dim); font-size: 11px; margin: 0; }

.tex-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tex-grid button { aspect-ratio: 1; background: #000; border: 1px solid var(--line); border-radius: 5px; padding: 2px; cursor: pointer; display: grid; place-items: center; }
.tex-grid button canvas, .tex-grid button img { width: 100%; height: 100%; object-fit: contain; }
.tex-grid button.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tex-grid button.up { background: var(--bg); color: var(--muted); font-size: 18px; }
.tex-grid button:hover { border-color: var(--muted); }

.bursts { display: grid; gap: 4px; }
.burst { display: grid; grid-template-columns: 1fr 1fr 24px; gap: 4px; }

/* curve + gradient */
.curve { position: relative; height: 120px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.curve canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.curve .ymax { position: absolute; right: 4px; top: 4px; width: 60px; }
.grad { position: relative; height: 26px; border-radius: 5px; border: 1px solid var(--line); cursor: copy;
  background-image: linear-gradient(45deg, #333 25%, transparent 25%), linear-gradient(-45deg, #333 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #333 75%), linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; background-color: #222; }
.grad .fill { position: absolute; inset: 0; border-radius: 4px; }
.grad-stops { position: relative; height: 18px; margin-top: 2px; }
.grad-stops .stop { position: absolute; top: 0; width: 12px; height: 16px; margin-left: -6px; border: 2px solid var(--line-2); border-radius: 3px 3px 6px 6px; cursor: ew-resize; touch-action: none; }
.grad-stops .stop.on { border-color: var(--accent); }
.stop-edit { display: grid; grid-template-columns: 34px 1fr 1fr 24px; gap: 4px; align-items: center; margin-top: 4px; }
.stop-edit input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }

.empty { color: var(--dim); padding: 16px 12px; }

/* ---------- dialog ---------- */
.dlg { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.dlg::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; margin: 0; }
.dlg-head h2 { font-size: 13px; color: var(--text); }
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { padding: 16px; display: grid; gap: 12px; overflow-y: auto; max-height: calc(100vh - 170px); }
.tab-body p { margin: 0; color: var(--muted); line-height: 1.55; }
.tab-body code, .tab-body pre { font: 12px var(--mono); }
.tab-body pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow-x: auto; margin: 0; color: #cfd5df; }
.tab-body ul { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.6; }
.sheet-preview { background: repeating-conic-gradient(#222 0% 25%, #2a2a2a 0% 50%) 0 / 16px 16px; border: 1px solid var(--line); border-radius: 6px; min-height: 60px; display: grid; place-items: center; overflow: hidden; }
.sheet-preview img { max-width: 100%; max-height: 300px; display: block; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.opts label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.toast { position: fixed; left: 50%; bottom: 60px; transform: translate(-50%, 20px); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); color: #ffb3b3; }

/* ---------- narrow screens: viewport on top, panels below ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 16px; }
  .doc-name { width: 140px; }
  .actions { margin-left: 0; flex-wrap: wrap; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .viewport { order: -1; height: 56vh; min-height: 320px; }
  .panel { overflow: visible; border: 0 !important; border-top: 1px solid var(--line) !important; }
}
@media (max-width: 900px) { .vp-stats { top: auto; bottom: 52px; right: 10px; } .vp-hint { display: none; } }

/* effect settings at the top of the right panel */
.effect-section { border-top: 0; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.effect-section > summary { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; color: var(--muted); }
