:root {
  --bg: #1b1830;
  --panel: #24203d;
  --panel2: #2e2950;
  --line: #3b3563;
  --text: #f3effc;
  --dim: #a39cc4;
  --accent: #ffd166;
  --c0: #ff6b8b;
  --c1: #ffa94d;
  --c2: #4dd4e8;
  --c3: #b28dff;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
#app { display: flex; flex-direction: column; height: 100%;
  padding: env(safe-area-inset-top, 0px) var(--safe-r) env(safe-area-inset-bottom, 0px) var(--safe-l); }

button { font: inherit; color: inherit; }
.tb { min-height: 40px; min-width: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel2); cursor: pointer; white-space: nowrap; touch-action: manipulation; }
.tb:active { filter: brightness(1.3); }
.tb.sm { min-width: 36px; padding: 0 9px; min-height: 36px; }
.tb.tog.on { background: #4b3f8a; border-color: #7b6cd1; }
.tb.play { min-width: 56px; font-size: 18px; background: #3d8a5a; border-color: #5fc188; }
.tb.play.on { background: #a8384f; border-color: #e06179; }
.tb.accent { background: #6b4fd8; border-color: #9a84ff; }
.tb[disabled] { opacity: 0.4; }
.grp { display: flex; align-items: center; gap: 6px; }
.grp.right { margin-left: auto; }
.lbl { padding: 0 4px; }
.dim { color: var(--dim); }

#top, #barbar { display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#barbar { padding: 6px 12px; gap: 12px; }
#bSongs { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.bpm .val { display: inline-flex; flex-direction: column; align-items: center; min-width: 44px; line-height: 1; }
.bpm .val small { font-size: 10px; color: var(--dim); }
.patnum { min-width: 28px; text-align: center; font-size: 17px; }
#barLabel { min-width: 52px; text-align: center; font-weight: 600; }

#timeline { display: flex; background: #1f1b36; border-bottom: 1px solid var(--line); flex: none; }
#tlLabels { flex: none; width: 108px; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.tlLabel { height: 30px; display: flex; align-items: center; gap: 6px; padding: 0 6px 0 8px; font-size: 13px;
  border-bottom: 1px solid #2a2547; cursor: pointer; position: relative; }
.tlLabel.sel { background: var(--panel2); font-weight: 600; }
.tlLabel .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tlLabel .meter { position: absolute; left: 0; bottom: 0; height: 2px; width: 0; }
.tlLabel .mute { margin-left: auto; border: 0; background: none; font-size: 15px; padding: 4px; opacity: 0.8; }
.tlLabel.muted { opacity: 0.45; }
#tlScroll { flex: 1; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-x; }
#tlCanvas { display: block; }

#main { flex: 1; display: flex; min-height: 0; }
#roll { flex: 1; position: relative; min-width: 0; touch-action: none; }
#rollCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#rollHint { position: absolute; left: 70px; right: 12px; bottom: 10px; text-align: center; font-size: 12px;
  color: var(--dim); pointer-events: none; opacity: 0.85; }

#side { width: 320px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line);
  padding: 12px; -webkit-overflow-scrolling: touch; }
#side h3 { margin: 4px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 18px; border: 2px solid transparent; background: var(--panel2); cursor: pointer; }
.chip.sel { border-color: var(--text); }
.chip .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.row > label { width: 86px; flex: none; color: var(--dim); font-size: 13px; }
.row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 30px; }
.row .v { width: 34px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.row input[type=text], .row select, .field { flex: 1; min-width: 0; min-height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: #1d1934; color: var(--text); padding: 0 10px; font: inherit; -webkit-user-select: text; user-select: text; }
.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; min-height: 36px; border: 0; background: #1d1934; cursor: pointer; font-size: 13px; padding: 0 4px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #5a4bb0; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.sec { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.note { font-size: 12px; color: var(--dim); margin: 6px 0; }
#waveCanvas { width: 100%; height: 120px; display: block; background: #161329; border-radius: 8px; touch-action: none; border: 1px solid var(--line); }

#modal { position: fixed; inset: 0; background: rgba(8, 6, 20, 0.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal[hidden] { display: none; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(560px, 94vw);
  max-height: 86vh; overflow-y: auto; padding: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 14px; }
.item { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; background: var(--panel2); border-radius: 10px; min-height: 48px; }
.item.cur { outline: 2px solid #7b6cd1; }
.item .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--dim); font-size: 12px; font-weight: 400; display: block; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu .tb { text-align: left; min-height: 48px; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #3b3170; border: 1px solid #7b6cd1;
  padding: 10px 18px; border-radius: 12px; z-index: 20; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
#toast[hidden] { display: none; }

@media (max-width: 900px) {
  #main { flex-direction: column; }
  #side { width: auto; height: 42%; border-left: 0; border-top: 1px solid var(--line); }
  #top { gap: 8px; }
  #barbar .lbl.dim#patShared { display: none; }
}
@media (max-width: 600px) {
  #tlLabels { width: 76px; }
  .tlLabel .nmt { display: none; }
  #bFollow { display: none; }
}
