@font-face { font-family: "Source Serif 4"; font-weight: 300; src: url("vendor/fonts/source-serif-4-latin-300-normal.woff2") format("woff2"); }
@font-face { font-family: "Hanken Grotesk"; font-weight: 400; src: url("vendor/fonts/hanken-grotesk-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Hanken Grotesk"; font-weight: 600; src: url("vendor/fonts/hanken-grotesk-latin-600-normal.woff2") format("woff2"); }

:root {
  --bg: #ffffff;
  --fg: #1c2954;
  --muted: #6b7491;
  --line: #dde1ea;
  --panel: #f5f6f9;
  --accent: #f6862d;
  --rec: #d0453a;
  --dot-light: 46%;
  --font-head: "Tiempos Headline", "Source Serif 4", Georgia, serif;
  --font-body: "Founders Grotesk", "Hanken Grotesk", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --fg: #e6e8ee;
    --muted: #8d94a8;
    --line: #2a2e38;
    --panel: #1a1d23;
    --dot-light: 66%;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px 6px;
}

h1 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 300;
  font-size: 26px;
}

h2 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 300;
  font-size: 19px;
}

.eq { margin: 4px 0 0; font-family: var(--font-head); font-size: 17px; }
.eq i { font-family: var(--font-head); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- master: sound on/off and volume ---- */

.master { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }

.sound-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px 9px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  min-width: 140px;
  justify-content: center;
}
.sound-btn svg { width: 20px; height: 20px; }
.sound-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.sound-btn.nudge { border-color: var(--accent); color: var(--accent); animation: nudge 1.1s ease-out 3; }
@keyframes nudge {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 12px transparent; }
}

.master-tempo { display: flex; align-items: center; gap: 8px; width: 230px; font-size: 14px; }
.master-tempo > span { color: var(--muted); }
.master-tempo output { font-size: 13px; font-variant-numeric: tabular-nums; min-width: 58px; text-align: right; }
.rec { display: flex; align-items: center; gap: 6px; }
.rec-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px 7px 11px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
}
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rec); }
.rec-btn[aria-pressed="true"] { border-color: var(--rec); color: var(--rec); }
.rec-btn[aria-pressed="true"] .rec-dot { border-radius: 2px; animation: rec-blink 1.2s steps(2, jump-none) infinite; }
@keyframes rec-blink { 50% { opacity: 0.35; } }
.rec-kind { padding: 4px 6px; font-size: 13px; }
.rec-status { font-size: 13px; color: var(--rec); font-variant-numeric: tabular-nums; white-space: nowrap; }
.master-vol { display: flex; align-items: center; gap: 8px; width: 150px; }
.master-vol output { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

/* ---- layout ---- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 350px;
  gap: 18px;
  padding: 8px 20px 20px;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.sliders, .coupling { display: flex; flex-direction: column; gap: 8px; }
.coupling { padding-top: 12px; border-top: 1px solid var(--line); }
.note { margin: 0; font-size: 12px; color: var(--muted); }
.session { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.session-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.session .note:empty { display: none; }
.note.error { color: #d0453a; }

.row {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 8px;
}

.row > span { color: var(--muted); font-size: 14px; }
.row output { font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; }
.row sub, .row sup { font-size: 0.7em; }

input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); }

select, button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }

.small { padding: 3px 9px; font-size: 13px; }
.quiet { background: none; color: var(--muted); border-color: transparent; }
.error { color: #d0453a; }

/* ---- tracks ---- */

.tracks-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.transport { display: flex; gap: 4px; }

.track-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.track {
  --c: hsl(var(--h) 85% var(--dot-light));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.track.selected { border-color: var(--c); box-shadow: 0 0 0 1px var(--c); }

.track-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 6px 7px 8px;
  cursor: pointer;
  border-radius: 9px;
}
.track-head:hover { background: var(--panel); }
.track.selected .track-head { background: color-mix(in srgb, var(--c) 12%, transparent); border-radius: 9px 9px 0 0; }

.track-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.track-name, .summary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-name { font-weight: 600; font-size: 14px; }
.track-name .num { color: var(--c); margin-right: 6px; }
.summary { font-size: 12px; color: var(--muted); }

.icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--muted);
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:not(:disabled):hover { color: var(--fg); background: var(--panel); border-color: var(--line); }
.play-btn { width: 34px; height: 34px; border-radius: 50%; border-color: var(--c); color: var(--c); background: var(--bg); }
.play-btn svg { width: 14px; height: 14px; }
.play-btn:not(:disabled):hover { color: var(--c); border-color: var(--c); }
.play-btn[aria-pressed="true"], .play-btn[aria-pressed="true"]:not(:disabled):hover { background: var(--c); color: #fff; }

.track-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 10px 10px 6px;
  border-top: 1px solid var(--line);
}

.trow {
  display: grid;
  grid-template-columns: 22px 62px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 6px;
}
.trow > select, .trow > .coords, .trow > .pair, .trow > .mono-check { grid-column: 3 / 5; }
/* the settings, two to a row where there's room */
.tgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 7px 18px; }
.tgrid > .notes-editor { grid-column: 1 / -1; }
.pair { display: flex; gap: 4px; min-width: 0; }
.pair select { flex: 1 1 0; min-width: 0; }
.trow .lbl { color: var(--muted); font-size: 13px; }
.rate-row.custom > select { grid-column: 3; }
.rate-row input[type="text"] {
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 3px 6px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: right;
}
.rate-row input.invalid { border-color: #d0453a; color: #d0453a; }
.trow output { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.trow select { padding: 4px 6px; font-size: 13px; min-width: 0; }
.trow select:disabled { opacity: 0.45; }
.trow input[type="range"] { accent-color: var(--c); }
.trow.na > :not(.link) { opacity: 0.4; }
.coords { font-size: 13px; font-variant-numeric: tabular-nums; }
.coords em { color: var(--muted); }

.link {
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  border: none;
  background: none;
  color: var(--muted);
  opacity: 0.6;
}
.link svg { width: 15px; height: 15px; }
.link:hover { opacity: 1; }
.link[aria-pressed="true"] { color: var(--accent); opacity: 1; }


.link-note { display: flex; align-items: center; gap: 5px; margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.link-note svg { width: 13px; height: 13px; flex: none; color: var(--accent); }

.add-track {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  padding: 9px;
}
.add-track:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

.sf-lib {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.sf-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sf-label { color: var(--muted); }
.sf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sf-list:empty, .sf-lib .note:empty { display: none; }
.sf-list li { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 2px 0 2px 2px; }
.sf-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sf-info { flex: 1 0 auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.sf-list .quiet { padding: 0 6px; }

/* ---- plot ---- */

.plot-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

#plot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hint {
  position: absolute;
  top: 8px;
  left: 60px;
  right: 16px;
  width: fit-content;
  margin: 0;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

@media (max-width: 1180px) {
  html, body { height: auto; }
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
  .plot-wrap { grid-column: 1 / -1; order: -1; height: min(72vh, 680px); }
  .panel { overflow: visible; }
}

@media (max-width: 760px) {
  header.top { flex-wrap: wrap; padding: 12px 16px 4px; }
  h1 { font-size: 22px; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 8px 16px 16px; }
  .plot-wrap { height: min(90vw, 70vh); }
  .tracks-panel { order: -1; }
  .plot-wrap { order: -2; }
}

/* ---- custom notes ---- */

.notes-editor { display: flex; flex-direction: column; gap: 6px; padding-left: 28px; }
.piano {
  position: relative;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
}
.piano button {
  position: absolute;
  top: 0;
  padding: 0;
  border-radius: 0 0 3px 3px;
  cursor: pointer;
}
.piano .wk {
  width: calc(100% / var(--w));
  height: 100%;
  background: #fff;
  border: none;
  border-right: 1px solid #c9ced9;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.piano .wk span { font-size: 8px; color: #8a90a2; padding-bottom: 2px; pointer-events: none; }
.piano .bk {
  z-index: 1;
  width: calc(100% / var(--w) * 0.62);
  height: 60%;
  transform: translateX(-50%);
  background: #2b2f38;
  border: 1px solid #1a1d23;
}
.piano .wk:hover { background: color-mix(in srgb, var(--c) 18%, #fff); }
.piano .bk:hover { background: color-mix(in srgb, var(--c) 35%, #2b2f38); }
.piano .echo.wk { background: color-mix(in srgb, var(--c) 30%, #fff); }
.piano .echo.bk { background: color-mix(in srgb, var(--c) 45%, #2b2f38); }
.piano .on { background: var(--c) !important; }
.piano .on span { color: #fff; }
.piano .down { box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.35); }

.notes-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.notes-bar button { padding: 3px 8px; font-size: 12px; }
.midi-btn { display: inline-flex; align-items: center; gap: 5px; }
.midi-btn svg { width: 15px; height: 15px; }
.midi-btn[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }
.notes-bar .check { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }
.notes-bar .check input { accent-color: var(--c); margin: 0; }
.mono-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.mono-check input { accent-color: var(--c); margin: 0; }
.notes-bar .quiet { margin-left: auto; }
.notes-msg { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.notes-msg .note-names { color: var(--fg); font-variant-numeric: tabular-nums; }
.piano .wk.on { border-right-color: rgb(0 0 0 / 0.3); }

/* ---- MIDI knobs ---- */

.eqn-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
#knobs[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.knob-msg { line-height: 1.45; }
.link-btn { padding: 0; border: none; background: none; color: var(--accent); font-size: inherit; text-decoration: underline; cursor: pointer; }
.knob { display: none; }
.knobs-on .row { grid-template-columns: 56px minmax(0, 1fr) 56px 44px; }
.knobs-on .knob {
  display: block;
  padding: 2px 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: none;
  white-space: nowrap;
}
.knobs-on .knob:hover { color: var(--accent); border-color: var(--accent); }
.knobs-on .knob.set { color: var(--fg); border-style: solid; background: var(--panel); }
.knobs-on .knob.learning { color: #fff; background: var(--accent); border: 1px solid var(--accent); animation: knob-pulse 1s ease-in-out infinite; }
@keyframes knob-pulse { 50% { opacity: 0.55; } }
.row.turned input[type="range"] { filter: brightness(1.25) saturate(1.3); }
.row.turned .knob.set { border-color: var(--accent); color: var(--accent); }
