/* dnbm is drawn in greys: every colour has equal red, green and blue
   (test/grayscale.test.ts refuses any other). Brightness carries meaning:
   brighter is louder, selected, or playing. */
:root {
  color-scheme: dark;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bg: #0a0a0a;
  --panel: #0f0f0f;
  --raised: #171717;
  --hover: #202020;
  --line: #1f1f1f;
  --line-strong: #303030;
  --text: #e2e2e2;
  --muted: #8a8a8a;
  --faint: #545454;
  --bright: #ffffff;
  --cell: #171717;
  --cell-alt: #121212;
  --cell-now: #2a2a2a;
  --ghost: #575757;
  --hit: #a3a3a3;
  --accent: #f0f0f0;
  --note: #303030;
  --hold: #1e1e1e;
  --scope-line: #cfcfcf;
  --scope-axis: #242424;
  --cell-size: 22px;
  --head: 168px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 12px / 1.4 var(--mono);
  -webkit-font-smoothing: antialiased;
}

body {
  scrollbar-color: var(--line-strong) transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript {
  padding: 24px;
  color: var(--muted);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

button,
select {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--raised);
  cursor: pointer;
}

button:hover:not(:disabled),
select:hover {
  border-color: var(--faint);
  background: var(--hover);
}

button[aria-pressed="true"],
button[aria-selected="true"] {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

input {
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--bg);
}

:focus-visible {
  outline: 1px solid var(--bright);
  outline-offset: 1px;
}

/* Layout: top bar, patterns, grid, then track and mixer panels. */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(180px, 1fr) auto auto;
  height: 100dvh;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.25em;
}

.title {
  width: 22ch;
  border-color: transparent;
  background: transparent;
}

.title:hover,
.title:focus {
  border-color: var(--line-strong);
}

.transport {
  display: flex;
  gap: 10px;
  align-items: center;
}

.play {
  display: grid;
  width: 36px;
  height: 28px;
  padding: 0;
  place-items: center;
}

.play.active {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.segmented {
  display: inline-flex;
}

.segmented button {
  border-radius: 0;
}

.segmented button + button {
  margin-left: -1px;
}

.segmented button:first-child {
  border-radius: 3px 0 0 3px;
}

.segmented button:last-child {
  border-radius: 0 3px 3px 0;
}

.bpm-field {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  color: var(--muted);
}

.bpm {
  width: 7ch;
  text-align: right;
}

.position {
  min-width: 17ch;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.scope {
  flex: none;
  width: 168px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
}

.files {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

/* Knobs and faders. */
.control {
  /* Contains the fader's visually hidden label, which would otherwise escape the
     mixer's scroller and widen the page. */
  position: relative;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.control:focus-visible {
  outline-offset: 2px;
}

.knob {
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  width: 46px;
}

.knob-dial {
  width: 28px;
  height: 28px;
}

.knob-track,
.knob-fill {
  fill: none;
  stroke-linecap: round;
  stroke-width: 3;
}

.knob-track {
  stroke: var(--line-strong);
}

.knob-fill {
  stroke: var(--text);
}

.knob-pointer {
  stroke: var(--bright);
  stroke-linecap: round;
  stroke-width: 2;
}

.control-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: lowercase;
  white-space: nowrap;
}

.control-value {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.transport .knob {
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  justify-items: start;
  width: auto;
}

.transport .knob-dial {
  grid-row: span 2;
  width: 24px;
  height: 24px;
}

.fader {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  width: 36px;
}

.fader-track {
  position: relative;
  flex: 1;
  width: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--raised);
}

.fader-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 3px;
  background: var(--line-strong);
}

.fader-thumb {
  position: absolute;
  left: 50%;
  width: 24px;
  height: 8px;
  border-radius: 2px;
  background: var(--text);
  transform: translate(-50%, 50%);
}

.fader:focus-visible .fader-thumb {
  background: var(--bright);
}

/* Patterns and arrangement. */
.patterns {
  display: grid;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.pattern-row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.section-label {
  flex: none;
  width: 8ch;
  color: var(--faint);
}

.tabs,
.chips {
  display: flex;
  flex: 1;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab,
.chip {
  flex: none;
}

.chip {
  height: 22px;
  padding: 0 6px;
  color: var(--muted);
}

.chip.start {
  border-color: var(--muted);
  color: var(--text);
}

.chip.now {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.arrangement-input {
  flex: 1;
  min-width: 0;
}

.pattern-actions {
  display: flex;
  flex: none;
  gap: 4px;
}

/* The step grid. */
.editor {
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.grid-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.grid-scroll {
  flex: 1;
  padding: 8px 12px;
  overflow: auto;
}

.ruler {
  display: grid;
  grid-template-columns: var(--head) repeat(var(--steps), var(--cell-size));
  column-gap: 2px;
  width: max-content;
  margin-bottom: 4px;
  color: var(--faint);
  font-size: 10px;
}

.ruler-head {
  margin-right: 6px;
}

.ruler-step {
  text-align: center;
}

.ruler-step.bar {
  color: var(--muted);
}

.ruler-step.now {
  color: var(--bright);
}

.grid {
  width: max-content;
}

.grid:focus-visible {
  outline: none;
}

.grid-row {
  display: flex;
  gap: 8px;
  margin-bottom: 3px;
}

.track-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 4px;
  align-items: center;
  width: var(--head);
  height: var(--cell-size);
  padding-right: 2px;
  border-radius: 3px;
}

.track-head.selected {
  background: var(--raised);
}

.track-name {
  overflow: hidden;
  height: 20px;
  padding: 0 4px;
  border: none;
  background: none;
  text-align: left;
  text-overflow: ellipsis;
}

.track-head.selected .track-name {
  color: var(--bright);
  font-weight: 700;
}

.track-kind {
  color: var(--faint);
  font-size: 10px;
}

.mini {
  width: 20px;
  height: 18px;
  padding: 0;
  font-size: 10px;
}

.cells {
  display: grid;
  grid-template-columns: repeat(var(--steps), var(--cell-size));
  gap: 2px;
}

.cell {
  position: relative;
  overflow: hidden;
  height: var(--cell-size);
  border-radius: 2px;
  background: var(--cell);
  font-size: 9px;
  line-height: var(--cell-size);
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}

/* Beats 2 and 4 of each bar sit a shade darker. */
.cell:is(.rest, .hold):nth-child(8n + 5),
.cell:is(.rest, .hold):nth-child(8n + 6),
.cell:is(.rest, .hold):nth-child(8n + 7),
.cell:is(.rest, .hold):nth-child(8n + 8) {
  background: var(--cell-alt);
}

.cell.ghost {
  background: var(--ghost);
}

.cell.hit {
  background: var(--hit);
}

.cell.accent {
  background: var(--accent);
}

.cell.note {
  overflow: visible;
  border-left: 2px solid var(--muted);
  background: var(--note);
  color: var(--bright);
}

/* A held note draws as a line from the note through each step it holds. */
.cell.hold::after {
  position: absolute;
  top: 50%;
  right: 0;
  left: -2px;
  height: 2px;
  margin-top: -1px;
  background: var(--faint);
  content: "";
}

.cell.rest.now,
.cell.hold.now {
  background: var(--cell-now);
}

.cell.now:is(.ghost, .hit, .accent, .note) {
  box-shadow: inset 0 0 0 2px var(--bright);
}

.cell.cursor {
  outline: 1px solid var(--bright);
  outline-offset: -1px;
}

.grid-footer {
  padding: 4px 12px 8px;
}

/* Track panel and mixer. */
.lower {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  height: 340px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.device {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.device-header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.device-name {
  width: 13ch;
  font-weight: 700;
}

.device-actions {
  display: flex;
  gap: 4px;
}

.device-description {
  margin: 10px 0;
  color: var(--muted);
  font-size: 11px;
}

.knobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 10px 4px;
}

/* Track strips scroll; the sends and master stay pinned on the right. */
.mixer {
  display: flex;
  gap: 6px;
  min-width: 0;
  padding: 10px 12px;
}

.strips {
  display: flex;
  flex: 1;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.strip {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: 100px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}

.strip.selected {
  border-color: var(--muted);
}

.strip-name {
  overflow: hidden;
  width: 100%;
  height: 20px;
  border: none;
  background: none;
  text-overflow: ellipsis;
}

.strip.selected .strip-name {
  color: var(--bright);
  font-weight: 700;
}

.strip-title {
  grid-column: 1 / -1;
  color: var(--muted);
}

.strip-knobs {
  display: grid;
  grid-template-columns: repeat(2, 46px);
  gap: 4px 0;
}

.strip .knob-dial {
  width: 24px;
  height: 24px;
}

.strip-fader {
  display: flex;
  flex: 1;
  gap: 4px;
  justify-content: center;
  min-height: 90px;
}

.strip-buttons {
  display: flex;
  gap: 4px;
}

.strip.fx,
.strip.master {
  width: auto;
}

.fx-group {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  gap: 4px 0;
  justify-items: center;
}

.meter {
  position: relative;
  width: 5px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--raised);
}

.meter-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--muted);
}

.meter.hot .meter-fill {
  background: var(--bright);
}

.statusbar {
  display: flex;
  gap: 16px;
  overflow: hidden;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.status-message.error {
  color: var(--bright);
  font-weight: 700;
}

.status-message.error::before {
  content: "! ";
}

.status-help {
  overflow: hidden;
  margin-left: auto;
  color: var(--faint);
  text-overflow: ellipsis;
}

@media (max-width: 900px) {
  .app {
    grid-template-rows: auto;
    height: auto;
  }

  .editor {
    min-height: 320px;
  }

  .lower {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .device {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .transport,
  .mixer {
    flex-wrap: wrap;
  }

  .strips {
    flex-basis: 100%;
  }

  .pattern-row {
    flex-wrap: wrap;
  }

  .tabs,
  .chips {
    flex-basis: calc(100% - 9ch);
  }

  :root {
    --head: 116px;
  }

  .track-kind {
    display: none;
  }

  .files {
    margin-left: 0;
  }

  .status-help {
    display: none;
  }
}
