/* ============================================================
   orOS Studio — App stylesheet
   Inherits the shell palette (inheritPalette + watchPalette).
   Toolbar, chip, dialog and toast styles follow the Ringtone Composer.
   Sections:
     1. Palette fallback + reset + toolbar
     2. Transport
     3. Timeline: sheet, ruler, tracks, lanes
     4. Clips
     5. Clip bar
     6. Dialogs
     7. Toast, busy, screen-reader helper
     8. Phone (360 px and up) + touch
     9. Reduced motion
   ============================================================ */

/* ---------- 1. Palette fallback + reset ---------- */
:root {
  --bg:           #1b1b1b;
  --bg-desktop:   #232225;
  --bar-bg:       rgba(48, 48, 51, 0.95);
  --text:         #ffffff;
  --text-dim:     #a8a8ac;
  --accent:       #3584e4;
  --accent-hover: #62a0ea;
  --accent-soft:  rgba(53, 132, 228, 0.22);
  --panel-bg:     #2a2a2e;
  --border:       #3a3a3f;
  --shadow:       rgba(0, 0, 0, 0.55);
  --danger:       #e06c75;
  --rec:          #e01b24;
  --head-w:       210px;
  --lane-h:       84px;
  --ruler-h:      28px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
ul { list-style: none; }
select, input[type="number"], input[type="text"] {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 34px;
  padding: 4px 8px;
}
select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="range"] { accent-color: var(--accent); }

.spacer { flex: 1 1 0; min-width: 0; }

#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 54px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  flex: 0 1 auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 2px 6px;
  text-align: left;
}
.title:hover { border-color: var(--border); }
.title:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.title-main { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.title-sub { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:disabled:hover { color: var(--text-dim); border-color: transparent; background: transparent; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 34px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.primary:hover { background: var(--accent-hover); color: #fff; }
.chip.danger { color: var(--danger); }
.chip.danger:hover { border-color: var(--danger); }
.chip:disabled { opacity: 0.45; cursor: default; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-btn { background: transparent; border: none; color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 2px; min-height: 32px; }
.link-btn:disabled { opacity: 0.4; cursor: default; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }
.hint { color: var(--text-dim); font-size: 13px; }
.hint.small { font-size: 12px; }

/* ---------- 2. Transport ---------- */
#transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 10px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tp-keys, .tp-opts, .tp-master { display: flex; align-items: center; gap: 6px; }
.tp-master { margin-left: auto; }
.tbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.tbtn svg { width: 18px; height: 18px; }
.tbtn:hover { border-color: var(--accent); }
.tbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn.rec { color: var(--rec); }
.tbtn.rec.on { background: var(--rec); border-color: var(--rec); color: #fff; animation: rec-pulse 1s ease-in-out infinite; }
.tbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@keyframes rec-pulse { 50% { opacity: 0.65; } }
.clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font: 700 17px/1 ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", monospace;
  font-variant-numeric: tabular-nums;
  min-width: 150px;
}
#clock-bar { font-size: 12px; font-weight: 400; color: var(--text-dim); }
.tp-field { display: inline-flex; align-items: center; gap: 4px; }
#bpm-in { width: 64px; }
.unit { font-size: 11px; color: var(--text-dim); }
.tp-lbl { font-size: 12px; color: var(--text-dim); }
#master-in { width: 96px; }
#meter { width: 80px; height: 10px; border-radius: 3px; }

/* ---------- 3. Timeline ---------- */
#view {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  position: relative;
  scrollbar-width: thin;
  background: var(--bg);
  outline: none;
}
#view.drop { box-shadow: inset 0 0 0 3px var(--accent); }
#sheet {
  position: relative;
  width: calc(var(--head-w) + var(--tl-w, 1000px));
  min-height: 100%;
}
.row { display: flex; }
.row.top { position: sticky; top: 0; z-index: 4; }
.head {
  position: sticky;
  left: 0;
  z-index: 3;
  flex: 0 0 var(--head-w);
  width: var(--head-w);
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
}
#corner {
  height: var(--ruler-h);
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.ruler {
  position: relative;
  flex: 0 0 var(--tl-w, 1000px);
  height: var(--ruler-h);
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.ruler:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tick {
  position: absolute;
  top: 0;
  bottom: 0;
  padding: 7px 0 0 4px;
  border-left: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
}
.ruler .loop {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-soft);
  border-left: 2px solid var(--text-dim);
  border-right: 2px solid var(--text-dim);
  opacity: 0.6;
  pointer-events: none;
}
.ruler .loop.on { border-color: var(--accent); opacity: 1; }

.row.track { height: var(--lane-h); border-bottom: 1px solid var(--border); }
.row.track .head { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; }
.row.track.sel .head { background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--panel-bg); }
.h-top { display: flex; align-items: center; gap: 4px; min-width: 0; }
.h-name {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  font-weight: 700;
  font-size: 13px;
  text-align: left;
  padding: 2px 0;
}
.h-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }
.h-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 3px; background: var(--tc); }
.h-btns { display: flex; gap: 4px; }
.ms {
  width: 28px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
}
.ms:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ms.m.on { background: #c64600; border-color: #c64600; color: #fff; }
.ms.s.on { background: #e5a50a; border-color: #e5a50a; color: #111; }
.ms.r.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.h-vol { width: 100%; height: 16px; }
.row.silent .lane { opacity: 0.45; }

.lane {
  position: relative;
  flex: 0 0 var(--tl-w, 1000px);
  height: 100%;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(var(--bar-w, 120px) - 1px), var(--border) calc(var(--bar-w, 120px) - 1px) var(--bar-w, 120px));
  touch-action: pan-y pan-x;
}
.row.track.sel .lane { background-color: rgba(127, 127, 127, 0.05); }
.empty { padding: 24px calc(var(--head-w) + 16px); }
#playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  box-shadow: 0 0 4px var(--shadow);
  pointer-events: none;
  z-index: 2;
  will-change: transform;
}
body.is-rec #playhead { background: var(--rec); }

/* ---------- 4. Clips ---------- */
.clip {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border-radius: 7px;
  overflow: hidden;
  background: color-mix(in srgb, var(--tc) 38%, var(--bg));
  border: 1px solid var(--tc);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.clip.sel { box-shadow: 0 0 0 2px var(--text); z-index: 1; }
.clip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.c-name {
  position: absolute;
  left: 6px;
  top: 2px;
  right: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  color: #fff;
  pointer-events: none;
}
.c-wave {
  position: absolute;
  left: 0;
  right: 0;
  top: 16px;
  bottom: 2px;
  width: 100%;
  height: calc(100% - 18px);
  pointer-events: none;
}
.c-state { position: absolute; left: 6px; top: 22px; right: 6px; font-size: 11px; color: var(--text-dim); pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip.missing, .clip.bad {
  background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(127, 127, 127, 0.18) 6px 12px), color-mix(in srgb, var(--tc) 18%, var(--bg));
  border-style: dashed;
}
.c-fade { position: absolute; top: 0; bottom: 0; pointer-events: none; }
.c-fade.in { left: 0; background: linear-gradient(to top right, transparent 49%, rgba(0, 0, 0, 0.35) 51%); }
.c-fade.out { right: 0; background: linear-gradient(to top left, transparent 49%, rgba(0, 0, 0, 0.35) 51%); }
.c-edge { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.c-edge.l { left: 0; }
.c-edge.r { right: 0; }
.clip.sel .c-edge { background: rgba(255, 255, 255, 0.18); }

/* ---------- 5. Clip bar ---------- */
#clipbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  flex-shrink: 0;
}
.clip-name { font-weight: 800; font-size: 13px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.cb-field input { width: 110px; }
.cb-field output { min-width: 52px; color: var(--text); font-variant-numeric: tabular-nums; }
#clip-close { margin-left: auto; }

/* ---------- 6. Dialogs ---------- */
dialog {
  margin: auto;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  padding: 16px 18px 18px;
  box-shadow: 0 10px 40px var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { font-size: 15px; }
dialog h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 16px 0 8px; }
dialog select, dialog input[type="text"] { width: 100%; }
dialog input[type="range"] { width: 100%; min-height: 32px; }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.dlg-actions.spread { justify-content: flex-start; }
#name-form h2 { margin-bottom: 10px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin-top: 10px; }
.field output { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.row-item { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 10px; padding: 4px 4px 4px 10px; }
.row-item.on { border-color: var(--accent); }
.row-open { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: transparent; border: none; text-align: left; padding: 6px 0; min-height: 40px; }
.row-title { font-size: 14px; font-weight: 700; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item.on .row-title { color: var(--accent); }
.row-desc { font-size: 12px; color: var(--text-dim); }
.del-btn:hover { color: var(--danger); border-color: var(--danger); background: transparent; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.swatch { width: 34px; padding: 0; border: 2px solid transparent; }
.chip.swatch.on { border-color: var(--text); }
#proj-new { margin-bottom: 4px; }
#oros-sec { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 4px; }
.oros-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.oros-row .chip { max-width: 100%; white-space: normal; text-align: start; }

/* ---------- 7. Toast, busy, screen reader ---------- */
#toast {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  transform: translateY(-8px);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  padding: 9px 14px;
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0.3s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; visibility: visible; transform: translateY(0); transition: opacity 0.3s ease, transform 0.3s ease; }
#toast button { min-height: 32px; background: transparent; border: none; color: var(--accent); font-weight: 700; font-size: 13px; padding: 2px 6px; pointer-events: auto; }
#busy {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
#busy-text { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; font-size: 14px; max-width: calc(100vw - 48px); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 7b. Effects ---------- */
.ms.fx { width: auto; padding: 0 6px; letter-spacing: 0.04em; }
.ms.fx.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#master-fx { height: 24px; }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
.tbtn.small { width: 36px; height: 32px; flex: 0 0 auto; }
#fx-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fx-slot { border: 1px solid var(--border); border-radius: 12px; background: var(--panel-bg, var(--bg)); }
.fx-slot.off .fx-label, .fx-slot.unknown .fx-label { color: var(--text-dim); text-decoration: line-through; }
.fx-head { display: flex; align-items: center; gap: 4px; padding: 4px; }
.fx-pw {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center;
}
.fx-pw svg { width: 16px; height: 16px; }
.fx-pw.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.fx-pw:focus-visible, .fx-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fx-name {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 8px;
  background: transparent; border: none; color: var(--text); text-align: left; padding: 6px 4px; border-radius: 6px;
}
.fx-label { flex: 0 1 auto; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the category gives way first, so the effect's name stays readable */
.fx-cat { flex: 0 1000 auto; min-width: 0; font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-body { padding: 0 10px 10px; }
.fx-gfx { display: block; width: 100%; max-width: 720px; margin: 0 auto 8px; border-radius: 8px; background: #1b1a18; cursor: default; }
.fx-ctl summary { cursor: pointer; font-size: 13px; color: var(--text-dim); padding: 6px 0; }
.fx-ctl summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.fx-row select { width: 100%; margin-top: 4px; }
.fx-row .chip { margin-top: 6px; }
.fx-row .field output { max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fx-pick, #ruf-pick { margin-top: 12px; }
#fx-search, #ruf-search { width: 100%; }
.fx-picks { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.fx-picks .chip.has-gfx::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.fx-credit { margin-top: 14px; }

/* ---------- 7d. Automation lanes ---------- */
.ms.au.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ms.au.has:not(.on) { border-color: var(--accent); color: var(--accent); }
.h-vol.auto { opacity: 0.45; }
.row.auto { height: var(--auto-h, 64px); border-bottom: 1px solid var(--border); }
.a-head { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 4px 8px; border-left: 4px solid var(--tc); }
.a-sel { width: 100%; font-size: 12px; padding: 2px 4px; min-height: 24px; }
.a-btns { display: flex; gap: 4px; }
.a-btns .ms { display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.a-btns .ms svg { width: 14px; height: 14px; }
.a-btns .ms:disabled { opacity: 0.4; cursor: default; }
.a-btns .ms.a-on.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.a-lane {
  position: relative;
  flex: 0 0 var(--tl-w, 1000px);
  height: 100%;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(var(--bar-w, 120px) - 1px), var(--border) calc(var(--bar-w, 120px) - 1px) var(--bar-w, 120px)),
    rgba(127, 127, 127, 0.06);
  cursor: crosshair;
  touch-action: pan-x pan-y;
  user-select: none;
  overflow: hidden;
}
.a-svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.a-line { fill: none; stroke: var(--tc); stroke-width: 2; }
.a-line.static { stroke-dasharray: 4 4; opacity: 0.55; stroke-width: 1.5; }
.a-fill { fill: var(--tc); opacity: 0.14; }
.a-lane.off .a-line, .a-lane.off .a-pt { opacity: 0.35; }
.a-pt {
  position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--tc); cursor: grab; touch-action: none; z-index: 1;
}
.a-pt::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.a-pt.sel { background: var(--tc); box-shadow: 0 0 0 2px var(--text); }
.a-pt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.a-tip {
  position: absolute; transform: translateX(-50%); z-index: 2; pointer-events: none; white-space: nowrap;
  font-size: 11px; font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 4px;
  background: var(--panel-bg); border: 1px solid var(--border); color: var(--text);
}
.a-hint { position: sticky; left: calc(var(--head-w) + 8px); display: inline-block; margin: 8px 0 0 8px; font-size: 12px; color: var(--text-dim); pointer-events: none; }

/* ---------- 7e. Keyboard (MIDI + synth) ---------- */
#keys { flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--panel-bg); border-top: 1px solid var(--border); }
#keys[hidden] { display: none; }
.kb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.kb-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
#kb-snd { max-width: 160px; }
#kb-vol { width: 96px; }
.kb-oct { display: inline-flex; align-items: center; gap: 4px; }
#kb-oct { min-width: 64px; text-align: center; }
#kb-close { margin-left: auto; }
.kb-note { margin: 0; }
.kb-keys { position: relative; height: 92px; user-select: none; touch-action: none; }
.kb-key { position: absolute; top: 0; padding: 0; border: 1px solid #3a3a3f; border-radius: 0 0 6px 6px; }
.kb-key.w { height: 100%; background: #f2f2f2; z-index: 1; }
.kb-key.b { height: 58%; background: #222; border-color: #111; z-index: 2; }
.kb-key.on.w { background: #9fc3f0; }
.kb-key.on.b { background: var(--accent); }
.kb-key:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.kb-c { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-size: 10px; color: #555; pointer-events: none; }

/* ---------- 7f. Instrument tracks, piano roll, loops ---------- */
.row.track.inst .dot { border-radius: 50%; }
.clip.midi { background: color-mix(in srgb, var(--tc) 26%, var(--bg)); }
.lane-hint { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text-dim); pointer-events: none; white-space: nowrap; }
.row.track.drop .lane { outline: 2px dashed var(--accent); outline-offset: -3px; }
.kb-target { font-size: 12px; font-weight: 700; color: var(--accent); }

dialog.full { width: calc(100vw - 16px); max-width: none; height: calc(100dvh - 16px); max-height: none; padding: 10px 12px 8px; overflow: hidden; }
dialog.full[open] { display: flex; flex-direction: column; }
dialog.full .dlg-head { margin-bottom: 6px; flex-shrink: 0; }
#pr-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 8px; flex-shrink: 0; }
.pr-mode { gap: 4px; }
.pr-mode .chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; }
.pr-mode .chip svg { width: 16px; height: 16px; }
dialog #pr-vel { width: 96px; min-height: 0; }
#pr-vel-out { min-width: 26px; font-variant-numeric: tabular-nums; }
dialog #pr-grid-sel { width: auto; }
.pr-icons { display: inline-flex; flex-wrap: wrap; gap: 2px; }
.pr-scroll {
  --pr-white: var(--bg);
  --pr-black: color-mix(in srgb, var(--text) 7%, var(--bg));
  --pr-row: color-mix(in srgb, var(--text) 7%, transparent);
  --pr-bar: color-mix(in srgb, var(--text) 38%, transparent);
  --pr-beat: color-mix(in srgb, var(--text) 17%, transparent);
  --pr-sub: color-mix(in srgb, var(--text) 8%, transparent);
  flex: 1 1 auto; min-height: 120px; overflow: auto; position: relative; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: 8px 8px 0 0; background: var(--bg);
}
.pr-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pr-inner { display: grid; position: relative; }
.pr-corner { position: sticky; top: 0; left: 0; z-index: 4; background: var(--panel-bg); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.pr-ruler { position: sticky; top: 0; z-index: 3; background: var(--panel-bg); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; }
.pr-tick { position: absolute; top: 0; bottom: 0; padding: 3px 0 0 4px; border-left: 1px solid var(--border); font-size: 11px; color: var(--text-dim); pointer-events: none; }
.pr-end { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--tc); pointer-events: none; }
.pr-keys { position: sticky; left: 0; z-index: 2; background: var(--panel-bg); border-right: 1px solid var(--border); }
.pr-key { position: absolute; left: 0; right: 0; padding: 0 4px; border: none; border-bottom: 1px solid rgba(0, 0, 0, 0.18); background: #ededed; color: #333; text-align: right; overflow: hidden; }
.pr-key.b { right: 34%; background: #26262a; color: #ddd; z-index: 1; }
.pr-keys.drums .pr-key.b { right: 0; }
.pr-kl { display: block; font-size: 9px; line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.pr-key:active { background: var(--accent); color: #fff; }
.pr-grid { position: relative; touch-action: pan-x pan-y; cursor: crosshair; user-select: none; }
.pr-grid.select { cursor: default; }
.pr-note {
  position: absolute; box-sizing: border-box; border-radius: 3px; overflow: hidden;
  background: var(--tc); border: 1px solid rgba(0, 0, 0, 0.4); opacity: var(--v, 1);
  touch-action: none; cursor: grab;
}
.pr-note::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 5px; background: rgba(255, 255, 255, 0.28); cursor: ew-resize; }
.pr-note.sel { opacity: 1; outline: 2px solid var(--text); outline-offset: 0; z-index: 1; }
.pr-note.out { opacity: 0.3; }
.pr-nl { display: block; padding-left: 3px; font-size: 9px; line-height: 12px; color: #fff; text-shadow: 0 0 2px #000; white-space: nowrap; pointer-events: none; }
.pr-out { position: absolute; top: 0; bottom: 0; background: rgba(0, 0, 0, 0.22); pointer-events: none; }
.pr-ph { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; margin-left: -1px; background: var(--text); pointer-events: none; z-index: 2; will-change: transform; }
.pr-marq { position: absolute; border: 1px dashed var(--accent); background: var(--accent-soft); pointer-events: none; z-index: 3; }
.pr-vscroll { flex: 0 0 64px; overflow: hidden; border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; background: var(--bg); }
.pr-vrow { display: flex; height: 100%; width: max-content; }
.pr-vlabel { flex: 0 0 auto; position: sticky; left: 0; z-index: 1; padding: 4px; font-size: 10px; color: var(--text-dim); background: var(--panel-bg); border-right: 1px solid var(--border); overflow: hidden; }
.pr-vstems { position: relative; height: 100%; touch-action: none; cursor: ns-resize; }
.pr-stem { position: absolute; bottom: 0; width: 4px; border-radius: 2px 2px 0 0; background: var(--tc); opacity: 0.85; pointer-events: none; }
.pr-stem.sel { background: var(--text); opacity: 1; }
.pr-foot { margin-top: 6px; flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; }

#loops { flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--panel-bg); border-top: 1px solid var(--border); }
#loops[hidden] { display: none; }
.lp-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.lp-title { font-size: 14px; }
.lp-kind { gap: 4px; }
.lp-kind .chip { min-height: 30px; padding: 2px 10px; }
#lp-close { margin-left: auto; }
.lp-hint { margin: 0; }
.lp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; max-height: 172px; overflow-y: auto; overscroll-behavior: contain; }
.lp-item { display: flex; align-items: center; gap: 4px; min-width: 0; padding: 2px 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); user-select: none; cursor: grab; }
.lp-grip { flex: 0 0 26px; height: 38px; display: flex; align-items: center; justify-content: center; color: var(--text-dim); touch-action: none; cursor: grab; }
.lp-grip svg { width: 18px; height: 18px; }
.lp-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.lp-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-play.on { color: var(--accent); border-color: var(--accent); }
.lp-ghost { position: fixed; left: 0; top: 0; z-index: 1300; pointer-events: none; padding: 6px 10px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; box-shadow: 0 4px 16px var(--shadow); white-space: nowrap; }
#add-insts { margin-bottom: 4px; }

/* ---------- 8. Phone + touch ---------- */
/* ---------- 7c. Remote control (remote.js) ---------- */
.remote-ind.on { color: var(--accent); }
.rm-pair { text-align: center; }
.rm-code { font: 700 40px/1.2 ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: 0.08em; margin: 12px 0 8px; }
.rm-qr { display: block; margin: 0 auto; width: 200px; height: 200px; image-rendering: pixelated; border-radius: 8px; }
.rm-qr[hidden] { display: none; }
.rm-url { word-break: break-all; margin-top: 6px; }
.rm-status { font-weight: 700; margin: 12px 0 4px; min-height: 1.3em; }
.rm-ask { border: 2px solid var(--accent, #c33); border-radius: 10px; padding: 10px 12px; margin: 12px 0 4px; }
.rm-ask p { margin: 0 0 8px; font-weight: 700; }
.rj-code { font: 700 24px ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: 0.15em; width: 9ch; padding: 6px 10px; flex: 1 1 auto; }

body.remote-on > :not(#remote-ui):not(dialog):not(#toast):not(#live) { display: none !important; }
#remote-ui { display: none; }
body.remote-on #remote-ui { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)); gap: 8px; }
.ru-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ru-name { font-size: 16px; font-weight: 700; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ru-link { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.ru-link.ok { color: #33d17a; border-color: #33d17a; }
.ru-link.via { color: #f6d32d; border-color: #f6d32d; }
.ru-link.lost { color: var(--danger); border-color: var(--danger); }
.ru-clock { font: 700 15px ui-monospace, "Cascadia Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.ru-tp { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ru-tp .tbtn { width: 52px; height: 44px; }
.ru-tp .tbtn svg { width: 22px; height: 22px; }
.ru-tp #ru-bpm { width: 64px; }
.ru-pos { width: 100%; height: 32px; accent-color: var(--accent); }
.ru-empty { text-align: center; }
.ru-strips { flex: 1 1 auto; min-height: 220px; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; overscroll-behavior-x: contain; }
.ru-strip { flex: 0 0 96px; display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 6px; border-radius: 10px;
  background: var(--panel-bg); border: 1px solid var(--border); border-top: 4px solid var(--tc, var(--border)); min-height: 0; }
.ru-strip.master { margin-left: auto; border-top-color: var(--accent); position: sticky; right: 0; box-shadow: -6px 0 12px var(--shadow); }
.ru-sname { font-size: 13px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ru-fxo { font-size: 12px; font-weight: 700; min-height: 32px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); cursor: pointer; }
.ru-fxo:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ru-fx { display: flex; flex-direction: column; gap: 4px; max-height: 96px; overflow-y: auto; }
.ru-fxb { font-size: 11px; padding: 4px 6px; min-height: 32px; border-radius: 6px; border: 1px solid var(--border); background: transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: line-through; color: var(--text-dim); }
.ru-fxb.on { text-decoration: none; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.ru-pan { width: 100%; height: 32px; accent-color: var(--accent); }
.ru-body { flex: 1 1 auto; min-height: 120px; display: flex; justify-content: center; gap: 8px; }
.ru-fader { position: relative; width: 44px; touch-action: none; cursor: ns-resize; border-radius: 8px; }
.ru-fader:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ru-track { position: absolute; left: 50%; top: 14px; bottom: 14px; width: 6px; margin-left: -3px; border-radius: 3px; background: var(--border); }
.ru-knob { position: absolute; left: 2px; right: 2px; height: 28px; border-radius: 6px; background: linear-gradient(#e6e6e6, #a9a9a9);
  border: 1px solid #555; box-shadow: 0 2px 6px var(--shadow); }
.ru-knob::after { content: ""; position: absolute; left: 4px; right: 4px; top: 13px; height: 2px; background: #333; }
.ru-fader.drag .ru-knob { background: linear-gradient(#fff, #c8c8c8); }
.ru-meter { width: 10px; height: 100%; border-radius: 3px; }
.ru-db { font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.ru-ms { display: flex; gap: 4px; justify-content: center; }
.ru-b { flex: 1 1 0; min-width: 32px; height: 36px; border-radius: 6px; border: 1px solid var(--border); background: transparent; font-weight: 800; font-size: 13px; }
.ru-b.m.on { background: #f6d32d; border-color: #f6d32d; color: #000; }
.ru-b.s.on { background: #33d17a; border-color: #33d17a; color: #000; }
.ru-b.r.on { background: var(--rec); border-color: var(--rec); color: #fff; }

@media (max-width: 760px) {
  .ru-strip { flex-basis: 116px; padding: 6px 4px; }
  .ru-tp .tbtn { width: 46px; }
  .ru-fader { width: 38px; }
  .rm-code { font-size: 34px; }
  :root { --head-w: 118px; --lane-h: 76px; }
  #transport { order: 3; border-top: 1px solid var(--border); border-bottom: none; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); gap: 8px; }
  #clipbar { order: 2; }
  #view { order: 1; }
  #toolbar { order: 0; }
  .tp-keys { order: 2; width: 100%; justify-content: space-between; }
  .tbtn { width: 48px; height: 44px; }
  .clock { order: 1; min-width: 0; font-size: 15px; }
  .tp-opts { order: 1; flex-wrap: wrap; }
  .tp-master { display: none; }
  #zoom-in, #zoom-out { display: none; }
  .h-vol { display: none; }
  .h-btns .ms.fx, .h-btns .ms.au { display: none; }
  #keys { order: 2; }
  .a-head { padding: 3px 5px; }
  .kb-keys { height: 104px; }
  #kb-snd { max-width: 130px; }
  dialog.wide { width: calc(100vw - 16px); padding: 12px 10px 14px; }
  .row.track .head { padding: 5px 6px; }
  .ms { width: 30px; height: 28px; }
  .clip-name { max-width: 100%; flex: 1 1 100%; }
  .cb-field input { width: 90px; }
  #clip-close { position: absolute; right: 8px; }
  #clipbar { position: relative; padding-right: 44px; }
}
@media (max-width: 420px) {
  #toolbar { gap: 0; padding-left: 4px; padding-right: 4px; }
  #toolbar .icon-btn { width: 40px; }
  .tp-opts .tp-lbl { display: none; }
  #snap-in { max-width: 120px; }
  .tp-opts .unit { display: none; }
}
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .ms { width: 36px; height: 32px; }
  .ms.fx { width: auto; }
  .fx-pw { width: 40px; height: 40px; }
  .fx-name { min-height: 40px; align-items: center; }
  .h-name { min-height: 32px; }
  .icon-btn.small { width: 40px; height: 40px; }
  .chip, .row-open { min-height: 44px; }
  .c-edge { width: 14px; }
  #toast button { min-height: 44px; }
}

/* ---------- 9. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .icon-btn { transition: none !important; }
  .tbtn.rec.on { animation: none; }
}

[hidden] { display: none !important; }
/* the tablet / phone Effects window: on a phone the name needs the room */
@media (max-width: 420px) { #ruf-list .fx-cat { display: none; } }
/* instrument tracks, piano roll and loops on a phone */
@media (max-width: 760px) {
  #loops { order: 2; }
  .lp-list { max-height: 150px; grid-template-columns: 1fr; }
  .tp-keys .tbtn { width: 44px; }
  .pr-hint { display: none; }
  .pr-tools { gap: 4px 6px; }
  dialog #pr-vel { width: 72px; }
  dialog.full { width: 100vw; height: 100dvh; border-radius: 0; padding: 8px 6px 6px; }
}
@media (max-width: 760px) {
  .pr-mode .chip span, .pr-tools .kb-field > span:first-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #pr-import, #pr-export { min-height: 32px; padding: 2px 10px; font-size: 12px; }
}
@media (pointer: coarse) {
  .pr-note::after { width: 10px; }
  .lp-grip { flex-basis: 36px; height: 44px; }
}
