:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel-2: #1b202b;
  --line: #262c3a;
  --text: #e6e9f0;
  --muted: #8a93a8;
  --accent: #ff5c8a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; user-select: none; -webkit-user-select: none; }
body { display: grid; grid-template-rows: auto auto 1fr auto; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 16px; background: linear-gradient(180deg, #171b25, #12151d);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 0.5px; font-size: 18px; display: flex; align-items: center; gap: 8px; margin-right: 6px; }
.logo { color: var(--accent); font-size: 14px; }
.group { display: flex; align-items: center; gap: 12px; padding: 4px 14px; border-left: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.field.small { margin-top: 6px; }

select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 8px; font-size: 13px; outline: none; cursor: pointer;
}
select:focus { border-color: var(--accent); }

.tempo-row { display: flex; align-items: center; gap: 8px; }
.readout { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; min-width: 32px; text-align: right; }
.unit { font-size: 10px; color: var(--muted); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 130px; height: 4px; background: var(--line); border-radius: 4px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--text); cursor: pointer; border: none; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); cursor: pointer; border: none; }

.scale-info { display: flex; flex-direction: column; gap: 3px; min-width: 210px; }
.scale-notes { display: flex; gap: 4px; }
.scale-notes span { font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); }
.scale-notes span.root { background: var(--accent); border-color: var(--accent); color: #111; }
.mode-desc { font-size: 11px; color: var(--muted); }

.ctx { display: none; gap: 10px; align-items: center; }
.ctx.show { display: flex; }
input[type=range].short { width: 80px; }
.readout.sm { font-size: 13px; min-width: 34px; }
.rate-sel select { padding: 4px 6px; font-size: 12px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 11px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #232937; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn.tool.on { background: var(--accent); color: #111; border-color: var(--accent); }
.btn.danger:hover { border-color: #ff5555; color: #ff7777; }
.btn.play { width: 46px; height: 46px; border-radius: 50%; justify-content: center; padding: 0; background: var(--accent); color: #111; border: none; box-shadow: 0 0 18px -4px var(--accent); }
.btn.play svg { width: 22px; height: 22px; }
.btn.play .i-stop { display: none; }
.btn.play.playing .i-play { display: none; }
.btn.play.playing .i-stop { display: block; }

/* ---------- Workspace ---------- */
.workspace { display: grid; grid-template-columns: 210px 1fr; min-height: 0; }
.tracks { background: var(--panel); border-right: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.track {
  --c: #fff;
  display: grid; grid-template-columns: 6px 1fr auto auto; align-items: center; gap: 8px;
  padding: 8px 8px 8px 0; border-radius: 9px; background: var(--panel-2); border: 1px solid transparent;
  cursor: pointer; position: relative; overflow: hidden; transition: border-color .12s, background .12s;
}
.track:hover { background: #20263302; border-color: var(--line); }
.track .bar { width: 6px; height: 100%; background: var(--c); border-radius: 0 3px 3px 0; opacity: .55; }
.track.selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--panel-2)); }
.track.selected .bar { opacity: 1; }
.track .tname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .tnum { font-size: 10px; color: var(--muted); display: block; font-weight: 500; }
.track .meter { position: absolute; inset: 0; background: var(--c); opacity: 0; pointer-events: none; transition: opacity .25s; }
.track .ms { width: 22px; height: 22px; font-size: 10px; font-weight: 700; border-radius: 5px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; padding: 0; }
.track .ms.m.on { background: #e2b33b; color: #111; border-color: #e2b33b; }
.track .ms.s.on { background: #3bc6e2; color: #111; border-color: #3bc6e2; }
.track.muted .tname { opacity: .45; }

.canvas-wrap { position: relative; min-width: 0; min-height: 0; }
#roll {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M3 21l3.8-1 11-11-2.8-2.8-11 11L3 21z' fill='white' stroke='black' stroke-width='1'/%3E%3C/svg%3E") 2 22, crosshair;
}
#roll.erasing { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Crect x='4' y='8' width='14' height='9' rx='2' transform='rotate(-35 11 12)' fill='%23ffb3c6' stroke='black'/%3E%3C/svg%3E") 6 18, cell; }
.hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center;
  color: var(--muted); font-size: 15px; line-height: 1.7; pointer-events: none; transition: opacity .3s;
  background: rgba(13,15,20,.7); padding: 16px 24px; border-radius: 12px; border: 1px dashed var(--line);
}
.hint.hidden { opacity: 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 12px; }

/* ---------- Synth panel ---------- */
.synth {
  display: flex; gap: 10px; padding: 12px 14px; background: var(--panel); border-top: 1px solid var(--line);
  overflow-x: auto; align-items: stretch;
}
.synth-title { display: flex; align-items: center; gap: 10px; min-width: 130px; padding-right: 6px; }
.synth-title .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.synth-name { font-weight: 800; font-size: 15px; }
.synth-sub { font-size: 11px; color: var(--muted); }
.module { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px 6px; display: flex; flex-direction: column; gap: 4px; }
.module h3 { margin: 0; font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--accent); font-weight: 700; }
.module.master h3 { color: var(--text); }
.module.master { --accent: #c9d1e3; }
.knobs { display: flex; gap: 4px; }
#envView { width: 160px; height: 44px; border-radius: 6px; background: #10131a; align-self: center; }
.module#modEnv { align-items: stretch; }

.waves { display: flex; gap: 4px; }
.wave-btn { flex: 1; height: 26px; background: #10131a; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; padding: 3px; color: var(--muted); }
.wave-btn svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.wave-btn.on { color: var(--accent); border-color: var(--accent); }

.knob { width: 54px; display: flex; flex-direction: column; align-items: center; cursor: ns-resize; touch-action: none; }
.knob svg { width: 44px; height: 44px; }
.k-track { fill: none; stroke: #2a3040; stroke-width: 3.5; stroke-linecap: round; }
.k-fill { fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round; }
.k-body { fill: #262c3a; stroke: #343b4d; stroke-width: 1; }
.k-ptr { stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; }
.knob.active .k-body { fill: #2e3546; }
.k-val { font-size: 10px; font-variant-numeric: tabular-nums; color: var(--text); margin-top: -2px; }
.k-label { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }

/* ---------- Mode bar (tracking) ---------- */
.modebar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 7px 16px; background: #10131a; border-bottom: 1px solid var(--line); min-height: 52px;
}
.modebar #trackMode { min-width: 210px; font-weight: 600; }
.modebar .ctx .field { min-width: 0; }
.mctl-btn { padding: 5px 10px; font-size: 12px; align-self: flex-end; }
.mctl-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; padding-top: 12px; }
.mctl-toggle input { accent-color: var(--accent); }
.mode-info { display: flex; flex-direction: column; gap: 2px; margin-left: auto; max-width: 460px; }
.mode-desc2 { font-size: 12px; color: var(--muted); line-height: 1.35; }
.mode-status { font-size: 12px; color: #ffb547; }
.mode-status:empty { display: none; }
#roll.hand { cursor: grab; }
#roll.hand:active { cursor: grabbing; }
