:root {
  --bg: #0b0b0b;
  --panel: #161616;
  --panel-2: #1d1d1d;
  --line: #2c2c2c;
  --line-2: #444;
  --dim: #7a7a7a;
  --text: #d8d8d8;
  --bright: #fafafa;
  --rec: #e8231c;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); height: 100%; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 14px; height: 36px; cursor: pointer; letter-spacing: .04em; }
button:hover { border-color: #666; }
button:focus-visible, [role=slider]:focus-visible { outline: 1px solid var(--bright); outline-offset: 2px; }

#app { display: flex; flex-direction: column; min-height: 100dvh; max-width: 1600px; margin: 0 auto; padding: 0 16px; padding-bottom: env(safe-area-inset-bottom); }

/* header */
header { display: grid; grid-template-columns: auto 1fr auto; gap: 24px; align-items: center; padding: 18px 0 14px; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 18px; align-items: center; min-width: 0; }
.logo { width: 38px; height: 38px; border: 1px solid #999; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 5px; flex: none; }
.logo i { border: 1.5px solid #ddd; position: relative; }
.logo i.on::after { content: ""; position: absolute; inset: 2px; background: #ddd; }
h1 { margin: 0; font-weight: 400; font-size: 30px; letter-spacing: .01em; color: var(--bright); }
.sub { display: none; color: var(--dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 48px; margin: 0; min-width: 0; }
.meta div { min-width: 0; }
.meta dt { font-size: 11px; color: var(--dim); letter-spacing: .05em; margin-bottom: 4px; }
.meta dd { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--bright); }
.m-name { flex: 1; }
.views { display: flex; gap: 8px; }
.views button { width: 150px; border-radius: 2px; color: var(--dim); background: transparent; }
.views button.on { color: var(--bright); border-color: #bbb; background: #0e0e0e; }

/* waveform */
#wave { position: relative; height: clamp(180px, 36vh, 440px); margin: 14px 0; user-select: none; touch-action: none; }
#waveCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#winLayer { position: absolute; inset: 0; }
.win { position: absolute; top: 6px; bottom: 6px; border: 1px solid #aaa; background: rgba(255,255,255,.035); cursor: grab; }
.win.sel { border: 3px solid var(--bright); background: rgba(255,255,255,.08); }
.win.bypassed { border-style: dashed; border-color: #555; background: transparent; opacity: .55; }
.win .num { position: absolute; left: 0; top: 0; min-width: 20px; height: 22px; padding: 0 5px; background: #bbb; color: #111; font-size: 12px; display: grid; place-items: center; }
.win.sel .num { background: #111; color: var(--bright); border: 1px solid var(--bright); }
.win .spd { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font-size: 14px; color: var(--bright); pointer-events: none; }
.win .head { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--bright); pointer-events: none; }
.win .head::before { content: ""; position: absolute; top: -1px; left: -4px; border: 5px solid transparent; border-top: 6px solid var(--bright); }
.win .edge { position: absolute; top: 0; bottom: 0; width: 14px; cursor: ew-resize; }
.win .edge.l { left: -8px; } .win .edge.r { right: -8px; }
#dropHint { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.75); border: 1px dashed #888; font-size: 18px; }
#dropHint[hidden] { display: none; }

/* window tabs */
#wtabs { display: none; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
#wtabs button { height: 52px; font-size: 20px; border-radius: 2px; background: #0e0e0e; color: var(--dim); border-color: #333; }
#wtabs button.on { color: var(--bright); border: 2px solid #888; }
#wtabs button.bypassed { color: #4a4a4a; }

/* panels */
#panel { flex: 1; display: grid; gap: 12px; grid-template-columns: repeat(4, 1fr); padding: 12px; background: #121212; border-radius: 2px; align-content: start; }
.strip { background: var(--panel); border: 1px solid var(--line); padding: 0 14px 14px; min-width: 0; }
.strip.sel { border-color: #ddd; }
.strip-h { display: flex; align-items: center; gap: 12px; height: 54px; border-bottom: 1px solid var(--line); margin: 0 -14px 10px; padding: 0 14px; font-size: 14px; }
.strip-h .act { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; height: auto; letter-spacing: .04em; }
.strip-h .act i { width: 12px; height: 12px; background: var(--bright); display: block; }
.strip.byp .strip-h .act { color: var(--dim); } .strip.byp .strip-h .act i { background: #555; }
.strip.byp .rows { opacity: .45; }
.strip-h .solo { margin-left: auto; width: 38px; padding: 0; height: 32px; }
.strip-h .solo.on { background: var(--bright); color: #111; border-color: var(--bright); }
.row { display: grid; grid-template-columns: 62px 1fr 64px; align-items: center; gap: 12px; min-height: 48px; font-size: 13px; }
.row .lbl { letter-spacing: .03em; }
.row .val { text-align: right; font-variant-numeric: tabular-nums; }

.slider { position: relative; height: 32px; cursor: pointer; touch-action: none; }
.slider .track { position: absolute; left: 0; right: 0; top: 50%; height: 3px; margin-top: -1.5px; background: #3a3a3a; }
.slider .fill { position: absolute; left: 0; top: 50%; height: 3px; margin-top: -1.5px; background: #e8e8e8; }
.slider .thumb { position: absolute; top: 50%; width: 8px; height: 20px; margin: -10px 0 0 -4px; background: #e8e8e8; border-radius: 2px; box-shadow: 0 0 0 2px #161616; }
.slider .ghost { position: absolute; top: 50%; width: 2px; height: 12px; margin: -6px 0 0 -1px; background: #9a9a9a; display: none; }
.slider.modded .ghost { display: block; }
.seg { display: flex; height: 34px; border: 1px solid var(--line-2); }
.seg button { flex: 1; border: 0; border-radius: 0; height: 100%; padding: 0; font-size: 13px; background: transparent; color: #666; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: #2b2b2b; color: var(--bright); }

/* patchbay */
.pb-title { grid-column: 1 / -1; font-size: 16px; padding: 4px 4px 0; letter-spacing: .03em; }
#panel.patch { grid-template-columns: repeat(3, 1fr); }
.lfo { background: var(--panel); border: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.lfo-h { display: flex; align-items: center; gap: 16px; }
.lfo-h .name { font-size: 17px; width: 50px; }
.lfo-h .onoff { width: 80px; color: var(--dim); border-radius: 2px; }
.lfo-h .onoff.on { color: var(--bright); border-color: #ddd; background: #2b2b2b; }
.lfo-h .shape { margin-left: auto; width: 88px; border-color: #ccc; border-radius: 2px; }
.lfo canvas { width: 100%; height: 110px; display: block; border: 1px solid var(--line); background: #121212; }
.lfo.off canvas { opacity: .35; }
.lfo .row { grid-template-columns: 52px 1fr 72px; min-height: 40px; }
.targets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.targets button { padding: 0; height: 40px; color: #666; background: #141414; border-color: #333; border-radius: 2px; font-size: 13px; }
.targets button.on { color: #111; background: #e8e8e8; border-color: #e8e8e8; }

/* footer */
footer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 16px 0; border-top: 1px solid var(--line); margin-top: 14px; }
footer .left { display: flex; align-items: center; gap: 8px; min-width: 0; }
footer .right { display: flex; justify-content: flex-end; }
footer button { height: 44px; font-size: 16px; }
.icon { width: 44px; padding: 0; display: grid; place-items: center; }
.icon svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.6; }
#btnPlay svg { fill: var(--bright); stroke: none; }
#btnPlay .stop { display: none; } #btnPlay.on .play { display: none; } #btnPlay.on .stop { display: block; }
.fname { color: var(--dim); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 10px; }
.transport { display: flex; align-items: center; gap: 8px; }
.rec span { width: 16px; height: 16px; border-radius: 50%; background: var(--rec); }
.rec.on { border-color: var(--rec); }
.rec.on span { animation: blink 1s steps(2) infinite; }
.rectime { color: var(--rec); font-variant-numeric: tabular-nums; min-width: 44px; font-size: 14px; }
@keyframes blink { 50% { opacity: .25; } }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid #555; border-radius: 4px; width: min(560px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
dialog h2 { margin: 0 0 6px; font-weight: 400; font-size: 20px; }
dialog .hint { color: var(--dim); font-size: 13px; margin: 0 0 14px; }
#spliceList { list-style: none; padding: 0; margin: 0 0 14px; counter-reset: s; max-height: 40vh; overflow: auto; }
#spliceList li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; counter-increment: s; }
#spliceList li::before { content: counter(s, decimal-leading-zero); color: var(--dim); width: 24px; }
#spliceList li .n { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#spliceList li .d { color: var(--dim); font-variant-numeric: tabular-nums; }
#spliceList li button { height: 28px; width: 30px; padding: 0; }
dialog .row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 8px; grid-template-columns: none; }
dialog .row.end { justify-content: flex-end; }
dialog label { display: flex; gap: 8px; align-items: center; font-size: 13px; }
dialog output { width: 56px; text-align: right; }
button.primary { background: var(--bright); color: #111; border-color: var(--bright); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #eee; color: #111; padding: 10px 16px; border-radius: 3px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

/* narrow layouts: one window at a time, selected via tabs */
body.narrow #wtabs { display: grid; }
body.narrow #panel { grid-template-columns: 1fr; }
body.narrow .strip { display: none; } body.narrow .strip.sel { display: block; }
body.patch-view #wtabs { display: grid; }
@media (max-width: 1100px) {
  .meta { display: none; }
  header { grid-template-columns: 1fr auto; }
  .sub { display: block; }
  .views button { width: 130px; }
  #panel.patch { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  header { grid-template-columns: 1fr; gap: 12px; }
  .views button { flex: 1; width: auto; }
  h1 { font-size: 26px; }
  #wave { height: 30vh; min-height: 160px; }
  #panel { padding: 8px; }
  .row { grid-template-columns: 56px 1fr 60px; min-height: 46px; }
  .fname { display: none; }
  footer button { font-size: 15px; }
  #btnSplice { padding: 0 12px; }
  .lfo canvas { height: 80px; }
  .targets { gap: 6px; }
}
