:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1a1e21;
  --panel-2: #20262a;
  --ink: #eef2f2;
  --muted: #9ba7a9;
  --line: #333b40;
  --line-soft: #252b2f;
  --accent: #e6b85c;
  --accent-2: #66c5c7;
  --danger: #d96356;
  --focus: #93d27f;
  --shadow: rgba(0, 0, 0, 0.24);
  --kick: #dc6559;
  --snare: #e3bb63;
  --hihat: #78c8c5;
  --bass: #86c96f;
  --chord: #b48dde;
  --melody: #ea8fb0;
  --relation-follow: #e6b85c;
  --relation-interlock: #78c8c5;
  --relation-avoid: #dc6559;
  --relation-pitched: #b48dde;
  --relation-syntax: #e6b85c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior-y: none;
}

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

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #252b2f;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #59656b;
  background: #2c3338;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  border-color: #b58b3c;
  background: #a6782a;
  color: #fff8e4;
}

button.generate-primary {
  border-color: #f0c76d;
  background: var(--accent);
  color: #17130b;
  font-weight: 750;
  box-shadow: 0 0 0 1px #5d461d, 0 3px 12px #00000040;
}

button.generate-primary:hover {
  border-color: #ffe09b;
  background: #f0c96f;
}

button.danger {
  border-color: #b24c43;
  background: #6a2925;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111518;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(102, 197, 199, 0.18);
}

input,
select {
  min-height: 34px;
  padding: 0 9px;
}

textarea {
  min-height: 112px;
  resize: vertical;
  padding: 10px;
  line-height: 1.4;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 720;
  letter-spacing: 0;
}

.author-mark {
  margin-left: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.author-logo {
  position: absolute;
  bottom: 0;
  left: calc(100% + 10px);
  z-index: 2;
  display: block;
  width: 68px;
  height: 72px;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c8d0d1;
}

.app-shell {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #15191c;
}

.topbar-left {
  display: grid;
  min-width: 370px;
  gap: 3px;
  flex: 0 0 auto;
  padding-top: 3px;
}

.topbar-tools {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  gap: 8px;
  justify-items: end;
}

.top-composition-controls {
  position: relative;
  display: grid;
  grid-template-columns: 70px 70px minmax(190px, 230px);
  align-items: end;
  gap: 7px;
  margin-top: 8px;
  justify-self: start;
}

.top-field {
  display: grid;
  min-width: 0;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
}

.top-field input,
.top-field select {
  min-height: 30px;
  padding: 0 7px;
  font-size: 12px;
}

.top-field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 12px;
}

.top-field-label .inline-lock {
  display: flex;
  gap: 3px;
  font-size: 9px;
  line-height: 1;
}

.top-field-label .inline-lock input {
  width: 11px;
  min-height: 11px;
  height: 11px;
  padding: 0;
}

.top-key-controls {
  display: grid;
  grid-template-columns: 62px minmax(140px, 1fr);
  gap: 5px;
}

.subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.transport-position {
  display: grid;
  grid-template-columns: 32px 6px 32px;
  align-items: center;
  justify-content: center;
  width: 82px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111518;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.transport-position > span {
  display: grid;
  place-items: center;
  line-height: 1;
}

.transport-position small {
  color: #748085;
  font-size: 7px;
  font-style: normal;
  font-weight: 700;
}

.transport-position strong {
  margin-top: 2px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.transport-position i {
  color: #586267;
  font-size: 13px;
  font-style: normal;
  text-align: center;
}

.transport-position.active {
  border-color: #77602f;
  background: #171812;
}

.transport-position.active strong {
  color: var(--accent);
}

.top-midi-controls {
  display: flex;
  align-items: center;
  gap: 2px 6px;
  flex-wrap: wrap;
  padding: 0 7px;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.top-midi-controls .check-label {
  min-height: 28px;
  font-size: 11px;
  white-space: nowrap;
}

.top-midi-status {
  display: grid;
  grid-template-columns: 8px minmax(100px, auto);
  align-items: center;
  column-gap: 7px;
  min-height: 34px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.top-midi-status-stack {
  display: grid;
  align-self: stretch;
  gap: 2px;
}

.top-midi-status strong {
  overflow: hidden;
  max-width: 210px;
  color: var(--ink);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-midi-status > span:last-child {
  grid-column: 2;
  white-space: nowrap;
}

.midi-status-dot {
  grid-row: 1 / 3;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #596267;
}

.midi-status-dot.connected {
  background: var(--accent-2);
}

.midi-status-dot.running {
  background: var(--focus);
  box-shadow: 0 0 0 3px rgba(147, 210, 127, 0.12);
}

.project-status {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  width: min(420px, calc(100vw - 32px));
  min-height: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #20262a;
  box-shadow: 0 8px 24px var(--shadow);
  color: var(--ink);
  font-size: 12px;
  text-align: left;
  pointer-events: none;
}

.project-status:empty {
  display: none;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 4px;
  color: var(--ink);
}

.check-label input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(460px, 1fr) minmax(260px, 330px);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.panel,
.workspace {
  min-width: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-x: hidden;
  overflow-y: auto;
}

.track-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow-x: hidden;
  overflow-y: auto;
}

.panel-header,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-header.compact {
  margin-top: 4px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-actions select {
  width: 112px;
}

.action-row {
  flex-wrap: wrap;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 54px;
}

.action-row label {
  width: 108px;
}

.loop-range-field {
  display: grid;
  gap: 5px;
  width: 126px;
  color: var(--muted);
  font-size: 12px;
}

.loop-range-inputs {
  display: flex;
  align-items: center;
  gap: 5px;
}

.loop-range-inputs input {
  width: 50px;
  min-width: 0;
  padding: 0 6px;
  text-align: center;
}

.loop-range-inputs span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.roll-timing-controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.roll-touch-mode {
  display: none;
}

.roll-snap-controls {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  flex: 0 0 auto;
}

.action-row .snap-unit-field {
  width: 66px;
}

.snap-unit-field select {
  min-width: 0;
  padding: 0 6px;
}

.roll-snap-controls .check-label {
  width: auto;
  min-height: 34px;
  padding: 0 2px;
  white-space: nowrap;
}

.action-row .view-bars-field {
  width: 82px;
}

.action-row .view-start-field {
  width: 58px;
}

.view-bars-field select,
.view-start-field input {
  min-width: 0;
  padding-right: 5px;
  padding-left: 6px;
}

.spacer {
  flex: 1 1 auto;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.field-control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
}

.parameter-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.help-tooltip {
  position: relative;
  z-index: 3;
  display: inline-grid;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 1px solid #59656b;
  border-radius: 50%;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  outline: none;
}

.help-tooltip:hover,
.help-tooltip:focus-visible {
  z-index: 40;
  border-color: var(--accent-2);
  color: var(--ink);
}

.help-tooltip::after {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  z-index: 30;
  display: none;
  width: 210px;
  padding: 8px 9px;
  border: 1px solid #4a555b;
  border-radius: 6px;
  background: #0d1113;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
  color: var(--ink);
  content: attr(data-tooltip);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  pointer-events: none;
  text-align: left;
  white-space: normal;
}

.help-tooltip.tooltip-align-right::after {
  right: 0;
  left: auto;
}

.help-tooltip.tooltip-above::after {
  top: auto;
  bottom: calc(100% + 7px);
}

.field-label-with-help,
.heading-with-help,
.syntax-slot-title {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: max-content;
}

.parameter-label .help-tooltip::after {
  top: auto;
  bottom: calc(100% + 7px);
  left: -58px;
}

.help-tooltip:hover::after,
.help-tooltip:focus-visible::after {
  display: block;
}

.shortcut-tooltip {
  position: relative;
}

.shortcut-tooltip::after {
  position: absolute;
  right: auto;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 80;
  width: max-content;
  max-width: min(250px, 75vw);
  padding: 7px 9px;
  border: 1px solid #4a555b;
  border-radius: 6px;
  background: #0d1113;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
  color: var(--ink);
  content: attr(data-shortcut-tooltip);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translate(-50%, 3px);
  transition: opacity 100ms ease, transform 100ms ease, visibility 100ms ease;
  visibility: hidden;
  white-space: normal;
}

.shortcut-tooltip:hover::after,
.shortcut-tooltip:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
}

.shortcut-tooltip.tooltip-below::after {
  top: calc(100% + 8px);
  bottom: auto;
}

.shortcut-tooltip.tooltip-align-end::after {
  right: 0;
  left: auto;
  transform: translateY(3px);
}

.shortcut-tooltip.tooltip-align-end:hover::after,
.shortcut-tooltip.tooltip-align-end:focus-visible::after {
  transform: translateY(0);
}

.shortcut-tooltip.tooltip-align-start::after {
  right: auto;
  left: 0;
  transform: translateY(3px);
}

.shortcut-tooltip.tooltip-align-start:hover::after,
.shortcut-tooltip.tooltip-align-start:focus-visible::after {
  transform: translateY(0);
}

.action-row:has(.shortcut-tooltip:focus-visible) .shortcut-tooltip:hover:not(:focus-visible)::after {
  opacity: 0;
  visibility: hidden;
}

.inline-lock {
  display: inline-flex;
  align-items: center;
  grid-auto-flow: column;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.inline-lock input {
  width: 14px;
  height: 14px;
  min-height: 14px;
  accent-color: var(--accent-2);
}

.field-span {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111518;
}

.segmented-control label {
  display: block;
  min-width: 0;
  color: var(--muted);
  cursor: pointer;
}

.segmented-control label + label {
  border-left: 1px solid var(--line);
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 0 6px;
}

.segmented-control input:checked + span {
  background: #5d4924;
  color: #fff1c5;
}

.segmented-control input:focus-visible + span {
  box-shadow: inset 0 0 0 2px var(--accent-2);
}

.control-stack {
  display: grid;
  gap: 12px;
}

.range-control {
  display: grid;
  gap: 6px;
}

.range-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.range-poles {
  display: flex;
  justify-content: space-between;
  margin-top: -5px;
  color: var(--muted);
  font-size: 10px;
}

.track-param-bass .parameter-label,
.track-param-bass .range-poles {
  color: var(--bass);
}

.track-param-bass input[type="range"] {
  accent-color: var(--bass);
}

.track-param-chord .parameter-label,
.track-param-chord .range-poles {
  color: var(--chord);
}

.track-param-chord input[type="range"] {
  accent-color: var(--chord);
}

.track-param-melody .parameter-label,
.track-param-melody .range-poles {
  color: var(--melody);
}

.track-param-melody input[type="range"] {
  accent-color: var(--melody);
}

input[type="range"] {
  height: 24px;
  padding: 0;
  accent-color: var(--accent);
  background: transparent;
}

.intent-tags {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.intent-tags button {
  min-width: 0;
  min-height: 28px;
  overflow: hidden;
  padding: 3px 7px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.intent-tags button.active {
  border-color: #7c693e;
  background: #39301f;
  color: #ffe6a8;
}

.canvas-wrap {
  flex: 1 1 auto;
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101416;
  box-shadow: 0 14px 32px var(--shadow);
  overflow: hidden;
}

#rollCanvas {
  cursor: crosshair;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.system-monitor {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.system-monitor-header,
.monitor-band-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.system-monitor-header h2,
.monitor-band-header h3 {
  margin: 0;
}

.system-monitor-header h2 {
  font-size: 14px;
}

.monitor-band-header h3 {
  font-size: 11px;
  text-transform: uppercase;
}

.monitor-band-header > span {
  color: var(--muted);
  font-size: 9px;
}

.monitor-legend,
.monitor-header-metric,
.monitor-metric-label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
}

.monitor-legend {
  gap: 9px;
  color: var(--muted);
  font-size: 9px;
}

.monitor-header-metric {
  color: var(--muted);
  font-size: 9px;
}

.monitor-metric-label {
  justify-content: flex-start;
}

.help-tooltip.monitor-help {
  width: 13px;
  height: 13px;
  border-color: #4b565c;
  font-size: 8px;
}

.help-tooltip.monitor-help::after {
  width: 225px;
}

.system-summary {
  display: flex;
  min-width: 0;
  align-items: stretch;
}

.system-summary-stat {
  display: grid;
  min-width: 84px;
  gap: 1px;
  border-left: 1px solid var(--line);
  padding: 0 10px;
  text-align: right;
}

.system-summary-stat:first-child {
  border-left: 0;
}

.system-summary-stat strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.system-summary-stat > .monitor-metric-label {
  color: var(--muted);
  font-size: 8px;
  justify-content: flex-end;
  text-transform: uppercase;
}

.monitor-band {
  min-width: 0;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

.form-monitor {
  display: grid;
  gap: 7px;
}

.state-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 5px;
}

.state-pill {
  min-width: 0;
  border: 1px solid var(--line);
  border-left: 3px solid var(--state-color, var(--muted));
  border-radius: 6px;
  padding: 6px 7px;
  background: var(--panel-2);
}

.state-stable { --state-color: var(--focus); }
.state-developing { --state-color: var(--accent-2); }
.state-unstable { --state-color: var(--accent); }
.state-collapse { --state-color: var(--danger); }
.state-recovery { --state-color: var(--chord); }

.state-pill-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.state-pill-heading strong {
  overflow: hidden;
  color: var(--state-color);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-pill-heading span {
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.state-signals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.state-signal {
  display: grid;
  grid-template-columns: 9px minmax(18px, 1fr);
  align-items: center;
  gap: 2px 4px;
  min-height: 15px;
  color: var(--muted);
  font-size: 8px;
}

.state-signal i,
.activity-meter i {
  display: block;
  height: 3px;
  background: #101416;
  overflow: hidden;
}

.state-signal i b,
.activity-meter i b {
  display: block;
  height: 100%;
}

.state-signal i b {
  background: var(--state-color);
}

.state-signal i {
  grid-column: 1 / -1;
}

.state-signal em {
  font-style: normal;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.track-activity-table {
  display: grid;
  margin-top: 7px;
}

.track-activity-row {
  display: grid;
  grid-template-columns: minmax(72px, 1.1fr) 52px 52px repeat(3, minmax(68px, 1fr));
  align-items: center;
  gap: 7px;
  min-height: 31px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 10px;
}

.track-activity-row:last-child {
  border-bottom: 0;
}

.track-activity-head {
  min-height: 24px;
  color: var(--muted);
  font-size: 8px;
  text-transform: uppercase;
}

.track-activity-head .monitor-metric-label {
  overflow: visible;
  white-space: nowrap;
}

.activity-track-name {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-track-name i {
  width: 4px;
  height: 16px;
  flex: 0 0 auto;
  background: var(--track-color);
}

.activity-number {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.activity-meter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  gap: 4px;
}

.activity-meter span {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.activity-meter i {
  height: 5px;
  border-radius: 2px;
}

.harmony-path {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 6px;
  margin-top: 9px;
}

.harmony-section {
  display: grid;
  min-width: 0;
  gap: 7px;
  border-left: 3px solid var(--state-color, var(--chord));
  padding: 7px 8px;
  background: #171b1e;
}

.harmony-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  min-width: 0;
  gap: 8px;
}

.harmony-section-header strong {
  flex: 0 0 auto;
  color: var(--state-color, var(--chord));
  font-size: 10px;
  text-transform: uppercase;
}

.harmony-section-header span {
  overflow: hidden;
  color: var(--muted);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
}

.harmony-progression {
  display: flex;
  align-items: start;
  flex-wrap: wrap;
  gap: 5px 0;
}

.harmony-step {
  position: relative;
  display: grid;
  min-width: 50px;
  gap: 1px;
  padding-right: 18px;
}

.harmony-step:last-child {
  padding-right: 0;
}

.harmony-step strong {
  color: var(--chord);
  font-size: 12px;
}

.harmony-step small {
  color: var(--muted);
  font-size: 8px;
}

.harmony-step i {
  position: absolute;
  top: 5px;
  right: 5px;
  color: var(--muted);
  font-style: normal;
}

.track-table {
  display: grid;
  gap: 8px;
}

.track-row {
  display: grid;
  grid-template-columns: minmax(58px, 1fr) 54px repeat(4, 34px);
  align-items: center;
  gap: 4px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #161b1e;
}

.track-octave-control {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 26px 30px 26px;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  border-top: 1px solid var(--line);
  padding-top: 5px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
}

.track-octave-control button {
  width: 26px;
  min-width: 26px;
  min-height: 24px;
  border-color: color-mix(in srgb, var(--track-color) 45%, var(--line));
  border-radius: 4px;
  padding: 0;
  color: var(--track-color);
  font-size: 13px;
}

.track-octave-control output {
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.track-name {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.track-test-button {
  width: 100%;
  min-height: 28px;
  justify-content: flex-start;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  padding: 0 2px;
  background: transparent;
}

.track-test-button:hover {
  border-color: transparent;
  background: #20272a;
}

.track-test-button:active {
  transform: none;
}

.track-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.track-row select {
  min-width: 0;
  padding: 0 3px;
  font-size: 10px;
}

.mini-check {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 9px;
}

.mini-check input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--accent-2);
}

.history-list {
  display: grid;
  gap: 7px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #151a1d;
  color: var(--ink);
}

.history-summary {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.history-name-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}

.history-name-input {
  width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 650;
}

.history-operation {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 10px;
  text-transform: uppercase;
}

.history-item button {
  min-height: 28px;
  padding: 0 8px;
}

.history-item .history-delete {
  border-color: #70423d;
  color: #e7aaa3;
}

.history-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px;
}

.dependency-table {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.dependency-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 7px 8px;
  border-left: 2px solid #4c5a60;
  background: #151a1d;
}

.dependency-route {
  min-width: 0;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.25;
}

.dependency-route span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.dependency-row input[type="range"] {
  width: 100%;
}

.relation-family-follow {
  border-left-color: var(--relation-follow);
}

.relation-family-follow .dependency-route span,
.relation-family-follow .dependency-route b {
  color: var(--relation-follow);
}

.relation-family-follow input[type="range"] {
  accent-color: var(--relation-follow);
}

.relation-family-interlock {
  border-left-color: var(--relation-interlock);
}

.relation-family-interlock .dependency-route span,
.relation-family-interlock .dependency-route b {
  color: var(--relation-interlock);
}

.relation-family-interlock input[type="range"] {
  accent-color: var(--relation-interlock);
}

.relation-family-avoid {
  border-left-color: var(--relation-avoid);
}

.relation-family-avoid .dependency-route span,
.relation-family-avoid .dependency-route b {
  color: var(--relation-avoid);
}

.relation-family-avoid input[type="range"] {
  accent-color: var(--relation-avoid);
}

.relation-family-pitched {
  border-left-color: var(--relation-pitched);
}

.relation-family-pitched .dependency-route span,
.relation-family-pitched .dependency-route b {
  color: var(--relation-pitched);
}

.relation-family-pitched input[type="range"] {
  accent-color: var(--relation-pitched);
}

.relation-family-syntax {
  border-left-color: var(--relation-syntax);
}

.relation-family-syntax .dependency-route span,
.relation-family-syntax .dependency-route b {
  color: var(--relation-syntax);
}

.relation-family-syntax input[type="range"] {
  accent-color: var(--relation-syntax);
}

.syntax-slot {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.relation-grid-r1c1 { grid-area: 1 / 1; }
.relation-grid-r1c2 { grid-area: 1 / 2; }
.relation-grid-r2c1 { grid-area: 2 / 1; }
.relation-grid-r2c2 { grid-area: 2 / 2; }
.relation-grid-r3c1 { grid-area: 3 / 1; }
.relation-grid-r3c2 { grid-area: 3 / 2; }
.relation-grid-r4c1 { grid-area: 4 / 1; }
.relation-grid-r4c2 { grid-area: 4 / 2; }

.syntax-slot-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--relation-syntax);
  font-size: 11px;
}

.syntax-slot-route {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 5px;
  align-items: center;
}

.syntax-slot-route-labels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 19px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1;
  text-transform: uppercase;
}

.syntax-slot-route-labels span:last-child {
  text-align: right;
}

.syntax-slot-route span {
  color: var(--muted);
  font-size: 11px;
}

.syntax-slot-route select {
  width: 100%;
  min-width: 0;
  min-height: 26px;
  border-color: #66562f;
  padding: 1px 20px 1px 5px;
  color: var(--relation-syntax);
  font-size: 10px;
}

.syntax-slot-mode {
  width: 100%;
  min-width: 0;
  min-height: 27px;
  border-color: #66562f;
  padding: 1px 22px 1px 6px;
  color: var(--relation-syntax);
  font-size: 10px;
  font-weight: 700;
}

.syntax-slot input[type="range"] {
  width: 100%;
}

.section-value,
.subtle-status {
  color: var(--muted);
  font-size: 11px;
}

.manual-download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 8px;
  background: #181d20;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
}

.manual-download-link:hover {
  border-color: #7d5ab5;
  background: #2b3035;
}

.manual-download-link:focus-visible {
  border-color: var(--accent-2);
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 197, 199, 0.18);
}

.field-block {
  display: grid;
  gap: 6px;
  width: 100%;
  color: var(--muted);
  font-size: 12px;
}

.midi-profile-manager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 6px;
  margin: 6px 0 4px;
}

.midi-profile-manager input {
  min-width: 0;
}

.midi-profile-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.midi-profile-actions button {
  min-height: 29px;
  padding: 4px 7px;
  font-size: 10px;
}

@media (max-width: 1280px) {
  .midi-profile-manager {
    grid-template-columns: 1fr;
  }
}

.midi-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  padding: 7px 0;
}

.midi-option-grid .check-label {
  justify-content: flex-start;
}

@media (max-width: 1120px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .layout {
    grid-template-columns: 300px minmax(420px, 1fr);
  }

  .track-panel {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .track-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-tools {
    flex-basis: 100%;
    justify-items: stretch;
  }

  .top-composition-controls {
    justify-self: start;
  }

}

@media (max-width: 760px) {
  html {
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
  }

  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: visible;
    overscroll-behavior-y: auto;
  }

  .app-shell {
    width: 100%;
    max-width: 100%;
  }

  .topbar {
    display: grid;
    width: 100%;
    max-width: 100%;
    align-items: flex-start;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 14px 12px;
  }

  .topbar-tools {
    width: 100%;
    min-width: 0;
  }

  .topbar-left {
    position: relative;
    width: 100%;
    min-width: 0;
    padding-right: 0;
  }

  .topbar-left h1,
  .topbar-left .subtitle {
    padding-right: 48px;
  }

  .author-logo {
    top: 0;
    right: 0;
    bottom: auto;
    left: auto;
    display: block;
    width: 40px;
    height: 42px;
  }

  .top-composition-controls {
    position: static;
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .top-key-field {
    grid-column: 1 / -1;
  }

  .top-key-controls {
    grid-template-columns: minmax(64px, 0.42fr) minmax(0, 1fr);
  }

  .transport {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }

  .transport > button,
  .transport > .check-label,
  .transport-position {
    width: 100%;
    min-width: 0;
  }

  .transport > .check-label {
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #181d20;
  }

  .top-midi-status {
    width: 100%;
    border-left: 0;
    padding-left: 0;
  }

  .top-midi-status-stack {
    grid-column: 1 / -1;
    width: 100%;
  }

  .top-midi-controls {
    display: grid;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 8px 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .top-midi-controls .check-label {
    min-width: 0;
    justify-content: flex-start;
    gap: 4px;
    padding: 0;
    font-size: 10px;
    white-space: normal;
  }

  .layout {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-direction: column;
    overflow: visible;
  }

  .panel,
  .workspace,
  .track-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
    overflow: visible;
  }

  .intent-tags button {
    min-height: 34px;
    overflow: visible;
    white-space: normal;
  }

  .action-row {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }

  .action-row > button {
    width: 100%;
    min-width: 0;
  }

  .action-row .spacer {
    display: none;
  }

  .roll-timing-controls {
    display: grid;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 8px;
    padding-top: 4px;
    border-top: 1px solid var(--line-soft);
  }

  .roll-snap-controls {
    display: grid;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .action-row .snap-unit-field,
  .action-row .view-bars-field,
  .action-row .view-start-field,
  .loop-range-field {
    width: 100%;
    min-width: 0;
  }

  .roll-touch-mode {
    display: grid;
    grid-column: 1 / -1;
    min-width: 0;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin: 0;
    border: 0;
    padding: 0;
    color: var(--muted);
    font-size: 12px;
  }

  .roll-touch-mode legend {
    display: contents;
  }

  .roll-touch-mode .segmented-control {
    min-width: 0;
  }

  .canvas-wrap {
    width: 100%;
    min-width: 0;
    min-height: 300px;
  }

  #rollCanvas {
    touch-action: pan-y;
  }

  body:has(#touchEditChoice:checked) #rollCanvas {
    touch-action: none;
  }

  .track-table {
    grid-template-columns: 1fr;
  }

  .dependency-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .syntax-slot {
    grid-column: auto;
    gap: 5px;
    padding: 7px 6px;
  }

  .syntax-slot-route {
    gap: 3px;
  }

  .syntax-slot-route-labels {
    gap: 13px;
  }

  .syntax-slot-route select,
  .syntax-slot-mode {
    font-size: 9px;
  }

  .state-strip {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  }

  .system-monitor-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .system-summary {
    width: 100%;
  }

  .system-summary-stat {
    min-width: 0;
    flex: 1 1 0;
    padding: 0 6px;
  }

  .track-activity-row {
    grid-template-columns: minmax(46px, 0.9fr) 30px 32px repeat(3, minmax(34px, 1fr));
    gap: 2px;
  }

  .track-activity-head,
  .track-activity-row {
    font-size: 8px;
  }

  .track-activity-row > * {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 360px) {
  .author-mark {
    display: none;
  }

  .syntax-slot-route-labels {
    display: none;
  }

  .syntax-slot-route {
    grid-template-columns: minmax(0, 1fr);
  }

  .syntax-slot-route::before,
  .syntax-slot-route::after {
    color: var(--muted);
    font-size: 8px;
    line-height: 1;
    text-transform: uppercase;
  }

  .syntax-slot-route::before {
    content: "Reference";
    grid-row: 1;
  }

  .syntax-slot-route > select:first-of-type {
    grid-row: 2;
  }

  .syntax-slot-route > span {
    display: grid;
    min-height: 10px;
    grid-row: 3;
    place-items: center;
    transform: rotate(90deg);
  }

  .syntax-slot-route::after {
    content: "Affected";
    grid-row: 4;
  }

  .syntax-slot-route > select:last-of-type {
    grid-row: 5;
  }
}
