:root {
  --bg: #111317; --panel: #1a1d23; --panel2: #22262e; --line: #2e333d; --text: #e4e7ec; --dim: #8b93a1;
  --accent: #f0a23b; --accent2: #5cc8c2; --danger: #e5484d; --ok: #46a758;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f3f4f6; --panel: #fff; --panel2: #f7f7f9; --line: #dfe2e7; --text: #1b1e24; --dim: #626a78;
    --accent: #c77a12; --accent2: #16837d; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, 'Segoe UI', sans-serif; }
header { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
h1 { font-size: 16px; margin: 0; letter-spacing: .02em; }
h1::before { content: '◆ '; color: var(--accent); }
h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
h2 small { text-transform: none; letter-spacing: 0; }
h3 { font-size: 12px; margin: 0 0 6px; color: var(--dim); }
.midi { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill { padding: 3px 10px; border-radius: 99px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line); }
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.off { border-color: var(--danger); color: var(--danger); }
button, .btn, select, input[type=number], input[type=search], #voiceName {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; }
button, .btn { cursor: pointer; }
button:hover, .btn:hover { border-color: var(--accent); }
button.warn { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
button.danger { border-color: color-mix(in srgb, var(--danger) 60%, var(--line)); }
button:disabled { opacity: .5; }
input[type=number] { width: 58px; }
input[type=range] { accent-color: var(--accent); }
main { display: grid; grid-template-columns: minmax(260px, 320px) 1fr minmax(280px, 340px); gap: 12px; padding: 12px 16px; align-items: start; }
@media (max-width: 1200px) { main { grid-template-columns: 1fr 1fr; } #editor { grid-column: 1 / -1; order: -1; } }
@media (max-width: 760px) { main { grid-template-columns: 1fr; padding: 12px; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row input[type=search] { flex: 1; min-width: 0; }
.chk { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.hint { color: var(--dim); font-size: 11px; margin: 0; }

.drop { border: 1.5px dashed var(--line); border-radius: 8px; padding: 10px; text-align: center; color: var(--dim); }
.drop.hot { border-color: var(--accent); color: var(--accent); }
#voiceList { list-style: none; margin: 0; padding: 0; height: 52vh; min-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; outline: none; }
#voiceList:focus { border-color: var(--accent2); }
#voiceList li { display: grid; grid-template-columns: 18px 20px 1fr auto; gap: 6px; align-items: center; padding: 3px 8px; cursor: pointer; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
#voiceList li:hover { background: var(--panel2); }
#voiceList li.sel { background: color-mix(in srgb, var(--accent) 22%, transparent); }
#voiceList li.more { display: block; color: var(--dim); cursor: default; }
#voiceList .nm { font-family: ui-monospace, Consolas, monospace; white-space: pre; overflow: hidden; }
#voiceList .bk { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.star { background: none; border: none; padding: 0; color: var(--line); font-size: 14px; }
.star.on { color: var(--accent); }
.bank-builder { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; border-top: 1px solid var(--line); }

#voiceName { font-family: ui-monospace, Consolas, monospace; font-size: 15px; width: 12ch; letter-spacing: .08em; }
.globals { display: grid; grid-template-columns: 250px 1fr; gap: 12px; }
@media (max-width: 760px) { .globals { grid-template-columns: 1fr; } }
.algo { display: flex; flex-direction: column; gap: 4px; background: var(--panel2); border-radius: 8px; padding: 8px; }
#algSvg { width: 100%; height: auto; }
#algSvg .edge { stroke: var(--dim); stroke-width: 1.5; }
#algSvg .bus { stroke: var(--accent2); stroke-width: 2; }
#algSvg .fb { fill: none; stroke: var(--accent); stroke-width: 1.5; }
#algSvg .opbox rect { fill: var(--panel); stroke: var(--dim); stroke-width: 1.5; }
#algSvg .opbox.car rect { stroke: var(--accent2); }
#algSvg .opbox.off rect { stroke-dasharray: 3 3; opacity: .5; }
#algSvg text { fill: var(--text); font-size: 12px; text-anchor: middle; font-weight: 600; }

.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 10px; }
.p { display: grid; grid-template-columns: 62px 1fr 42px; align-items: center; gap: 4px; font-size: 11px; }
.p .pl { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p input { width: 100%; margin: 0; }
.p output { text-align: right; font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; }
.ops { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 10px; }
.op { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--dim); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.op.carrier { border-left-color: var(--accent2); }
.op.muted { opacity: .45; }
.op-head { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.op-head .role { color: var(--dim); font-weight: 400; font-size: 11px; }
.op-head .freq { margin-left: auto; font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.env { width: 100%; height: 46px; background: var(--panel); border-radius: 4px; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .tools { grid-template-columns: 1fr; } }
.tool { background: var(--panel2); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.tool .row input[type=range] { flex: 1; }
.tag { font-family: ui-monospace, Consolas, monospace; color: var(--accent); min-width: 8ch; }

.fxbox { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; opacity: .7; }
.fxbox.active { opacity: 1; border-color: color-mix(in srgb, var(--accent2) 60%, var(--line)); }
.fxname { font-weight: 600; margin-bottom: 2px; }
#fx { display: flex; flex-direction: column; gap: 6px; }

#tuningRow[hidden], #tuTableWrap[hidden], #fmxPanel[hidden], #fmxPanel [hidden], #fmxOffer[hidden], #monWrap[hidden], #plMutator[hidden] { display: none; }
#plMutator input[type=number] { width: 4em; }
#plMutator input[type=range] { width: 90px; }
.fmx { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.fmx-engines { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.fmx-engines .row { gap: 6px; }
.fmx-engines .eng { font-weight: 600; min-width: 2ch; }
.fmx-engines .voice { min-width: 11ch; }
.fmx-engines input[type=number] { width: 4.5em; }
.fmx-engines input[type=range] { width: 80px; }
.fmx-room { display: flex; flex-direction: column; gap: 6px; }
.fmx-plan { width: 100%; height: 240px; background: var(--panel2); border-radius: 8px; touch-action: none; cursor: grab; }
.fmx-plan:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fmx-plan.dragging { cursor: grabbing; }
.fmx-resp { width: 100%; height: 110px; background: var(--panel2); border-radius: 8px; }
.fmx-room input[type=number] { width: 4.5em; }
.fmx-room input[type=range] { width: 90px; }
#fmxArrange { gap: 4px; }
.tu-edit { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.tu-scale { display: flex; flex-direction: column; gap: 6px; flex: 0 1 230px; min-width: 190px; }
.tu-scale input, .tu-scale textarea, #tuSpan { color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; }
.tu-scale textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }
.tu-scale input:focus, .tu-scale textarea:focus, #tuSpan:focus { outline: none; border-color: var(--accent); }
#tuRootHz { width: 84px; }
.tu-notes { display: flex; flex-direction: column; gap: 8px; flex: 1 1 420px; min-width: 0; }
.tu-error { color: var(--danger); font-size: 12px; }
.tu-ruler { width: 100%; height: 46px; background: var(--panel2); border-radius: 8px; }
.tu-table { border-collapse: collapse; font-size: 12px; width: 100%; }
.tu-table th { text-align: left; color: var(--dim); font-weight: 600; padding: 2px 8px 4px 0; }
.tu-table td { padding: 1px 8px 1px 0; font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.tu-table td button { padding: 0 6px; }
.keys { position: relative; display: flex; height: 110px; user-select: none; touch-action: none; }
.key.white { flex: 1; background: #eceef1; border: 1px solid #9aa1ad; border-radius: 0 0 5px 5px; color: #555; font-size: 10px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.key.black { width: 0; position: relative; z-index: 2; }
.key.black::after { content: ''; position: absolute; left: -9px; width: 18px; height: 66px; background: #22252b; border-radius: 0 0 4px 4px; }
.key.down.white { background: var(--accent); }
.key.down.black::after { background: var(--accent); }
#log { margin: 0; height: 140px; overflow-y: auto; font: 11px/1.4 ui-monospace, Consolas, monospace; color: var(--dim); white-space: pre-wrap; }
#log .err { color: var(--danger); }
#log .ok { color: var(--ok); }

/* ---- library row add button, category filter ---- */
#voiceList li { grid-template-columns: 18px 20px 1fr auto 22px; }
#voiceList .add { padding: 0 5px; line-height: 18px; border-radius: 4px; color: var(--accent2); visibility: hidden; }
body[data-tab="drums"] #voiceList .add, body[data-tab="player"] #voiceList .add { visibility: visible; }
#library select { flex: 1; min-width: 0; }
.dim { color: var(--dim); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -4px 4px; padding: 0 4px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 14px; color: var(--dim); font-weight: 600; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: none; flex-direction: column; gap: 10px; min-width: 0; }
.tab.on { display: flex; }
.transport { background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
button.play { min-width: 84px; font-weight: 600; }
button.play.on { background: color-mix(in srgb, var(--accent) 25%, var(--panel2)); border-color: var(--accent); }
.seg { display: inline-flex; flex-wrap: wrap; }
.seg button { border-radius: 0; margin-left: -1px; padding: 3px 9px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: color-mix(in srgb, var(--accent) 25%, var(--panel2)); border-color: var(--accent); position: relative; }

/* ---- sequencer grid ---- */
.seq-grid, .fx-lane { display: flex; flex-direction: column; gap: 3px; overflow-x: auto; touch-action: none; user-select: none; }
.trk, .fx-lane { display: grid; grid-template-columns: 150px 1fr; gap: 6px; align-items: center; }
.trk-head { display: flex; gap: 3px; min-width: 0; }
.trk-head select { width: 100%; font-size: 11px; padding: 3px 4px; }
.tname { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 6px; font-size: 12px; }
.trk.active .tname { border-color: var(--accent2); color: var(--accent2); }
.mute, .solo { padding: 3px 6px; font-size: 11px; }
.mute.on { background: color-mix(in srgb, var(--danger) 35%, var(--panel2)); }
.solo.on { background: color-mix(in srgb, var(--accent) 35%, var(--panel2)); }
.cells { display: grid; grid-template-columns: repeat(32, minmax(16px, 1fr)); gap: 2px; min-width: 560px; }
.cell { height: 26px; border-radius: 3px; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; font: 10px/24px ui-monospace, Consolas, monospace; text-align: center; color: var(--bg); overflow: hidden; position: relative; }
.cell.beat { border-color: color-mix(in srgb, var(--dim) 60%, var(--line)); }
.cell.on { background: color-mix(in srgb, var(--accent) calc(35% + var(--v, 1) * 65%), var(--panel2)); opacity: calc(.45 + var(--p, 1) * .55); }
.cell.fx.on { background: color-mix(in srgb, var(--accent2) calc(25% + var(--v, 1) * 75%), var(--panel2)); opacity: 1; }
.cell.out { opacity: .18; cursor: default; }
.cell.now { outline: 2px solid var(--text); outline-offset: -1px; }
.fx-lane { margin-top: 2px; }
.inspector { background: var(--panel2); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.inspector .iname { font: inherit; width: 12ch; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 2px 4px 2px 2px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.chip button { border: none; background: none; padding: 1px 5px; border-radius: 99px; }
.chip button:hover { background: var(--panel2); }

/* ---- player ---- */
.playhead { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-family: ui-monospace, Consolas, monospace; }
.playhead input { width: 100%; }
.roll { width: 100%; height: 120px; background: var(--panel2); border-radius: 8px; cursor: pointer; }
.chan-list { display: flex; flex-direction: column; gap: 4px; }
.chan { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 4px 8px; border-left: 4px solid var(--c); background: var(--panel2); border-radius: 6px; }
.chan.active { outline: 1px solid var(--accent2); }
.chan .cname { font-weight: 600; }
.chan .cvoice { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.chan .cinfo { font-size: 11px; }

/* ---- kits, pads, drum macros ---- */
.kitbar { background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.kitbar select { max-width: 260px; }
.pads { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.pad { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 58px; padding: 6px 8px;
  border-radius: 8px; background: var(--panel2); text-align: left; touch-action: none; user-select: none; overflow: hidden; }
.pad b { font-size: 12px; }
.pad small { font: 10px/1.2 ui-monospace, Consolas, monospace; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pad .pk { position: absolute; right: 6px; top: 4px; font-size: 10px; color: var(--dim); }
.pad.active { border-color: var(--accent2); }
.pad.hit { animation: padhit .18s ease-out; }
@keyframes padhit { from { background: color-mix(in srgb, var(--accent) 70%, var(--panel2)); } to { background: var(--panel2); } }
.chip.sel { border-color: var(--accent); }
.chip .vn { cursor: pointer; }
.macros { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.macros:empty { display: none; }
.macro-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.macro-head b { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.macro-head .mm { font-size: 11px; }
.macro-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 14px; }
.p.macro { grid-template-columns: 78px 1fr 80px; font-size: 12px; }
.p.macro output { font-size: 11px; }
button.target { border-color: var(--accent2); color: var(--accent2); }

/* ---- sequencer: accent, slide, step pick-up, bar lines ---- */
.cell.acc { box-shadow: inset 0 3px 0 var(--danger); }
.cell.slide { border-right: 3px solid var(--accent2); }
.cell.pick { outline: 2px dashed var(--accent2); outline-offset: -2px; }
.cell.bar { border-left: 2px solid var(--dim); }
/* ---- speech ---- */
#spText { font: 15px/1.4 system-ui, 'Segoe UI', sans-serif; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: vertical; width: 100%; }
#spText:focus { outline: none; border-color: var(--accent); }
.sp-knobs label { display: inline-flex; gap: 6px; align-items: center; }
.sp-knobs .tag { min-width: 5ch; }
.sp-view { height: 150px; cursor: default; }
button.on#spRec { border-color: var(--danger); color: var(--danger); }
.pill.soft { border-color: var(--accent2); color: var(--accent2); }
.sp-words { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; font-size: 14px; }
.sp-w { padding: 1px 5px; border-radius: 4px; background: color-mix(in srgb, var(--accent) calc(var(--wt, 1) * 26%), transparent); cursor: help; }
.sp-w.func { background: none; color: var(--dim); }
.sp-w.guess { outline: 1px dashed var(--danger); }
.sp-end { color: var(--accent); font-weight: 600; margin-right: 8px; }
.sp-lint { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.sp-note b { display: inline-block; min-width: 76px; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); }
.sp-note.guess b, .sp-note.style b { color: var(--danger); }
.sp-note.tone b, .sp-note.grammar b { color: var(--accent); }
.sp-note.number b, .sp-note.abbr b, .sp-note.spell b { color: var(--accent2); }
#chainSlots { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; width: 9ch; }
