:root {
  --bg: #161618;
  --panel: #1f1f22;
  --panel2: #26262a;
  --panel3: #2e2e33;
  --line: #0d0d0e;
  --line2: #36363c;
  --text: #cfcfd3;
  --dim: #85858c;
  --accent: #e8a33d;
  --red: #ff4b3e;
  --green: #4cd27a;
  --blue: #4fa3e0;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
button, select, input {
  font: inherit; color: var(--text);
  background: var(--panel3); border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 9px; outline: none;
}
button { cursor: pointer; }
button:hover { background: #3a3a40; }
button.accent { background: var(--accent); color: #1a1205; font-weight: 600; border-color: #9a6a20; }
button.accent:hover { background: #f4b555; }
select { padding: 4px 6px; }
input:focus, select:focus { border-color: var(--accent); }
kbd { background: var(--panel3); border: 1px solid var(--line2); border-radius: 3px; padding: 0 4px; font-size: 11px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 6px 12px;
  background: linear-gradient(#232327, #1b1b1e); border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; font-size: 15px; letter-spacing: .3px; white-space: nowrap; }
.logo small { color: var(--dim); font-weight: 400; }
.logo-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: conic-gradient(#ff4b3e, #e8a33d, #4cd27a, #4fa3e0, #b56ce0, #ff4b3e);
  box-shadow: 0 0 10px rgba(232,163,61,.35);
}
.menu { display: flex; gap: 4px; }
.projname {
  flex: 1; min-width: 80px; max-width: 360px; margin: 0 auto; text-align: center;
  background: transparent; border: 1px solid transparent; color: var(--text); font-size: 14px;
}
.projname:hover { border-color: var(--line2); }
#scope { background: #0f0f11; border: 1px solid var(--line); border-radius: 4px; }

/* transport */
.transport {
  display: flex; align-items: center; gap: 16px; padding: 6px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.seg button:last-child { border-radius: 0 4px 4px 0; }
.seg button.on { background: #4a4a52; color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.tbtns { display: flex; gap: 4px; }
.tbtns button { width: 40px; height: 32px; font-size: 15px; padding: 0; }
.tbtns .play.on { background: #2c5a3a; color: #8ff0ae; }
.tbtns .rec { color: #a55; }
.tbtns .rec.on { background: #6a1f1a; color: var(--red); box-shadow: 0 0 8px rgba(255,75,62,.5); }
.lcd {
  background: #0b0b0c; border: 1px solid #000; border-radius: 4px; padding: 3px 12px;
  font-family: "SF Mono", Menlo, Consolas, monospace; text-align: center; min-width: 170px;
}
.lcd .tc { font-size: 19px; color: #e9e9ec; letter-spacing: 1px; }
.lcd .bbs { font-size: 11px; color: var(--accent); }
.field { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.field > label { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; }
.bpm { display: flex; }
.bpm input { width: 54px; text-align: center; border-radius: 0; -moz-appearance: textfield; appearance: textfield; }
.bpm input::-webkit-inner-spin-button { -webkit-appearance: none; }
.bpm button { padding: 3px 7px; }
.bpm button:first-child { border-radius: 4px 0 0 4px; }
.bpm button:last-child { border-radius: 0 4px 4px 0; }
.toggle.on { background: var(--accent); color: #1a1205; }
.spacer { flex: 1; }
.undo button { font-size: 16px; padding: 2px 10px; }

/* pages */
main { flex: 1; position: relative; min-height: 0; }
.page { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; }
.page.on { display: flex; }

.patbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--panel2); border-bottom: 1px solid var(--line);
}
.patbar .lab { color: var(--dim); font-size: 11px; text-transform: uppercase; margin-right: 4px; }
.patbtn {
  width: 38px; height: 30px; font-weight: 700; font-size: 14px; position: relative; padding: 0;
}
.patbtn.used::after {
  content: ""; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: currentColor; opacity: .7;
}
.patbtn.on { color: #111; }
.patbar .sep { width: 1px; height: 22px; background: var(--line2); margin: 0 6px; }

.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .title, .tl-tools .title { font-weight: 600; margin-right: 8px; }
.toolbar .lbl { color: var(--dim); font-size: 11px; margin-left: 6px; }
.hint { color: var(--dim); font-size: 11.5px; margin-left: 8px; }

/* drum grid */
.drumwrap { flex: 1; overflow: auto; padding: 14px 12px; }
.drumgrid { display: flex; flex-direction: column; gap: 5px; min-width: max-content; }
.drow { display: flex; align-items: center; gap: 8px; }
.dname {
  width: 92px; height: 36px; text-align: left; font-weight: 600; flex: none;
  border-left: 4px solid var(--accent);
}
.dname:active { background: #4a4a52; }
.dknobs { display: flex; gap: 4px; flex: none; }
.dcells { display: flex; gap: 3px; }
.cell {
  width: 30px; height: 36px; border-radius: 3px; background: #2b2b30; border: 1px solid #111;
  cursor: pointer; flex: none;
}
.cell.beat { background: #34343a; }
.cell.gap { margin-left: 6px; }
.cell.barStart { margin-left: 14px; }
.cell.on { background: var(--accent); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.cell.acc { background: #ffd27a; box-shadow: 0 0 8px rgba(255,200,100,.6), inset 0 0 0 1px #fff; }
.cell.play { outline: 2px solid rgba(255,255,255,.55); outline-offset: -1px; }
.cell.on.play { filter: brightness(1.35); }
.drumgrid.compact .cell { width: 18px; }
.drumgrid.tiny .cell { width: 11px; }
.steprow { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.steprow .pad { width: 92px; flex: none; }
.steprow .padk { flex: none; }
.lamp { width: 30px; height: 6px; border-radius: 3px; background: #2a2a2e; flex: none; }
.lamp.on { background: var(--red); box-shadow: 0 0 6px var(--red); }
.drumgrid.compact .lamp { width: 18px; }
.drumgrid.tiny .lamp { width: 11px; }

/* knobs */
.knob { display: flex; flex-direction: column; align-items: center; width: 46px; cursor: ns-resize; }
.knob .kl { font-size: 9.5px; color: var(--dim); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.knob .kv { font-size: 10px; color: var(--text); font-family: Menlo, Consolas, monospace; white-space: nowrap; }
.knob svg { width: 30px; height: 30px; display: block; }
.knob.sm { width: 34px; }
.knob.wide { width: auto; min-width: 90px; cursor: default; }
.knob.wide select { margin-top: 4px; }
.knob.sm svg { width: 24px; height: 24px; }
.knob.sm .kl { font-size: 8.5px; }

/* piano roll */
.rollscroll { flex: 1; overflow-y: auto; overflow-x: hidden; background: #141416; min-height: 120px; }
#roll { display: block; cursor: crosshair; }
.synthpanel {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex-wrap: wrap;
  background: var(--panel2); border-top: 1px solid var(--line);
}
.synthpanel .sname { font-weight: 700; display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.synthpanel .sname small { color: var(--dim); font-weight: 400; }
.synthpanel .grp { display: flex; gap: 4px; padding: 0 8px; border-left: 1px solid var(--line2); align-items: center; }
.synthpanel .grp .gl { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 9px; color: var(--dim); text-transform: uppercase; }

/* arrangement */
.edit-layout { display: flex; flex: 1; min-height: 0; }
.pool { width: 190px; background: var(--panel2); border-right: 1px solid var(--line); padding: 10px; overflow-y: auto; flex: none; }
.pool-h { font-weight: 600; margin-bottom: 8px; }
.pool-h small { display: block; color: var(--dim); font-weight: 400; font-size: 11px; }
.poolitem {
  display: flex; align-items: center; gap: 8px; padding: 5px; margin-bottom: 5px; border-radius: 5px;
  background: var(--panel3); border: 1px solid var(--line); cursor: pointer;
}
.poolitem.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.poolitem .pl { width: 26px; height: 26px; border-radius: 4px; display: grid; place-items: center; font-weight: 800; color: #111; flex: none; }
.poolitem canvas { flex: 1; height: 26px; width: 100%; min-width: 0; background: #18181b; border-radius: 3px; }
.poolitem .pb { font-size: 10px; color: var(--dim); }
.pool-help { margin-top: 12px; color: var(--dim); font-size: 11.5px; }
.pool-help p { margin: 3px 0; }
.timeline { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tl-tools { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tl-body { flex: 1; display: flex; min-height: 0; overflow-y: auto; }
.lanehdrs { width: 150px; flex: none; background: var(--panel2); border-right: 1px solid var(--line); }
.lanehdrs .rh { height: 28px; border-bottom: 1px solid var(--line); font-size: 10px; color: var(--dim); padding: 8px; }
.lanehdr {
  height: 72px; border-bottom: 1px solid var(--line); padding: 8px 8px 8px 12px; position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
}
.lanehdr::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.lanehdr .ln { font-weight: 600; }
.lanehdr .lb { display: flex; gap: 4px; }
.ms { width: 24px; height: 20px; padding: 0; font-size: 11px; font-weight: 700; }
.ms.m.on { background: #3a6ed8; color: #fff; }
.ms.s.on { background: #e0b830; color: #111; }
.arrscroll { flex: 1; overflow-x: auto; overflow-y: hidden; min-width: 0; background: #151517; }
#arr { display: block; }

/* mixer */
#page-mix { overflow: auto; }
.mixer { display: flex; gap: 6px; padding: 12px; align-items: stretch; flex: 1; min-height: 360px; }
.strip {
  width: 104px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; padding: 8px 4px; gap: 6px; position: relative;
}
.strip .sn { font-weight: 700; font-size: 12px; text-align: center; width: 100%; padding-bottom: 5px; border-bottom: 3px solid var(--c, var(--line2)); }
.strip .kr { display: flex; gap: 0; justify-content: center; flex-wrap: wrap; }
.strip .fz { flex: 1; display: flex; gap: 8px; align-items: stretch; min-height: 140px; width: 100%; justify-content: center; }
.strip canvas.meter { width: 14px; height: 100%; background: #0c0c0d; border-radius: 2px; }
.strip input[type=range].fader {
  writing-mode: vertical-lr; direction: rtl; width: 30px; height: 100%; margin: 0; padding: 0;
  background: transparent; border: none; cursor: pointer; accent-color: var(--accent);
}
.strip .db { font-family: Menlo, Consolas, monospace; font-size: 11px; color: var(--dim); }
.strip .msr { display: flex; gap: 4px; }
.strip.fx { background: #222229; }
.strip.master { width: 128px; background: #29261f; }
.strip select { font-size: 11px; padding: 2px; width: 88px; }
.mixer .gapcol { width: 10px; }
#spectrum { width: calc(100% - 24px); margin: 0 12px 12px; background: #0c0c0e; border: 1px solid var(--line); border-radius: 6px; flex: none; }

/* page bar */
.pagebar {
  display: flex; justify-content: center; gap: 4px; padding: 4px; background: linear-gradient(#1d1d20, #151517);
  border-top: 1px solid var(--line);
}
.pagebar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; background: transparent; border: none;
  padding: 4px 22px; color: var(--dim); border-radius: 5px; font-size: 11px;
}
.pagebar button:hover { color: var(--text); background: #232327; }
.pagebar button.on { color: var(--accent); }
.pagebar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pagebar svg .f { fill: currentColor; }

.toast {
  position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #333338; border: 1px solid var(--line2); padding: 8px 16px; border-radius: 6px; pointer-events: none;
  transition: .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 60; }
.modal[hidden] { display: none; }
.modal .box { background: var(--panel2); padding: 24px 36px; border-radius: 8px; text-align: center; border: 1px solid var(--line2); }
.spin { width: 34px; height: 34px; border: 3px solid #444; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 10px; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .hint { display: none; }
  .menu button { padding: 4px 6px; }
  #scope { display: none; }
  .transport { flex-wrap: wrap; gap: 8px; }
  .pool { width: 130px; }
  .lanehdrs { width: 100px; }
}
