:root {
  color-scheme: light;
  --bg: #ffffff;
  --sheet: #f4f4f4;
  --ink: #111111;
  --muted: #9b9b9b;
  --line: #e4e4e0;
  --plate: #6d7a86;
  --ok: #3f7a5a;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: "FamiljenGrotesk-Variable", "FamiljenGrotesk-Regular", sans-serif;
  font-size: 12px;
  line-height: 1.25;
  -webkit-font-smoothing: antialiased;
}

.sheet {
  width: min(76rem, 100%);
  margin: 0 auto;
  padding: 0.7rem 0.9rem 1.2rem;
  background: var(--sheet);
  min-height: 100svh;
}

header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 0.7rem 0.9rem;
}

h1 {
  margin: 0;
  font-family: "Array-Regular", sans-serif;
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
}

.mark {
  width: 1.15rem;
  height: 1.15rem;
  align-self: center;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  white-space: nowrap;
}

nav a:hover { text-decoration: underline; }

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  min-height: 0;
}

.status.ok { color: var(--ok); }
.status.bad { color: #8a3030; }

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.15rem;
  align-items: flex-start;
  margin: 0.45rem 0 0.4rem;
}

.transport-group > span {
  display: block;
  font-family: "Array-Regular", sans-serif;
  font-size: 0.6rem;
  color: var(--muted);
  margin-bottom: 0.18rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.icon-btn svg,
.file svg {
  width: 0.82rem;
  height: 0.82rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.22rem;
  align-items: center;
}

.row .field {
  grid-template-columns: auto 5.5rem;
  margin: 0;
  width: auto;
  gap: 0.28rem;
}

button,
select,
input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
}

button,
.file {
  padding: 0.16rem 0.42rem;
  cursor: pointer;
  font-size: 0.72rem;
}

button:hover,
.file:hover { border-color: var(--plate); }

button.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

button.active {
  border-color: var(--ok);
  color: var(--ok);
}

.file {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.file input { display: none; }

.bank {
  display: grid;
  grid-template-columns: 2.6rem repeat(4, minmax(0, 1fr));
  gap: 0.16rem;
  margin: 0 0 0.45rem;
}

.bank .role {
  font-family: "Array-Regular", sans-serif;
  font-size: 0.68rem;
  color: var(--muted);
  display: flex;
  align-items: center;
}

.slot {
  text-align: left;
  padding: 0.18rem 0.36rem;
  min-height: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 11.5rem;
  gap: 0.7rem;
}

.editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  align-items: stretch;
}

.editor > .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.5rem 0.35rem;
}

.panel h2,
.module-head h2 {
  margin: 0;
  font-family: "Array-Regular", sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--plate);
}

.panel > h2 { margin-bottom: 0.16rem; }

.module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.12rem;
}

.module-body {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.55rem;
  align-items: flex-end;
}

.module-body > .field {
  flex: 1 1 100%;
}

.knob {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  width: 3.1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.62rem;
}

.knob-dial {
  width: 2.15rem;
  height: 2.15rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  position: relative;
  cursor: ns-resize;
  touch-action: none;
}

.knob-dial::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 14%;
  width: 1.5px;
  height: 36%;
  background: var(--ink);
  transform: rotate(var(--angle, -135deg));
  transform-origin: bottom center;
}

.knob output {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-size: 0.62rem;
}

.panel.osc {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.28rem 0.4rem;
  align-items: start;
}

.panel.osc > h2,
.panel.osc > .field {
  grid-column: 1 / -1;
}

.module.off .module-body {
  opacity: 0.38;
}

.panel input[type="text"] {
  width: 100%;
  margin: 0.04rem 0 0.1rem;
  padding: 0.12rem 0.28rem;
}

label.field {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr) 2.3rem;
  gap: 0.2rem;
  align-items: center;
  margin: 0.02rem 0;
  font-size: 0.66rem;
  color: var(--muted);
}

label.field:not(:has(output)) {
  grid-template-columns: 4.2rem minmax(0, 1fr);
}

label.field.check {
  grid-template-columns: 4.2rem auto 1fr;
}

label.field input[type="range"] { width: 100%; }
label.field output { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
label.field select { min-width: 0; width: 100%; padding: 0.08rem 0.12rem; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0.18rem 0 0.06rem;
  font-size: 0.66rem;
  color: var(--muted);
}

.switch input {
  appearance: none;
  width: 1.45rem;
  height: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fff;
  position: relative;
  cursor: pointer;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 50%;
  background: var(--muted);
}

.switch input:checked {
  background: var(--ink);
  border-color: var(--ink);
}

.switch input:checked::after {
  left: 0.68rem;
  background: #fff;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0.1rem 0 0;
  font-size: 0.66rem;
  color: var(--muted);
}

.stepper div {
  display: flex;
  gap: 0.12rem;
}

.stepper button {
  min-width: 1.4rem;
  padding: 0.12rem 0.28rem;
}

.adsr {
  display: block;
  width: 100%;
  flex: 1 1 0;
  min-height: 5.6rem;
  margin: 0;
  touch-action: none;
  overflow: visible;
}

.adsr-fill { fill: #ecece8; }
.adsr-line { fill: none; stroke: var(--ink); stroke-width: 1.6; }

.adsr-hit {
  fill: transparent;
  stroke: none;
}

.adsr-handle {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.5;
}

.adsr-handle-group.dragging .adsr-handle,
.adsr-handle-group:hover .adsr-handle {
  fill: var(--ink);
}

.adsr-readout {
  fill: var(--muted);
  font-size: 7px;
  letter-spacing: 0.04em;
  font-family: "FamiljenGrotesk-Variable", "FamiljenGrotesk-Regular", sans-serif;
}

.editor > .panel.envelope > h2,
.editor > .module .module-head { flex: none; }

.editor > .module .module-body {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.12rem 0.18rem;
  justify-items: center;
  align-content: start;
  flex: 1 1 0;
}

.editor > .module .module-body > .field {
  grid-column: 1 / -1;
  flex: none;
}

.editor > .module .knob {
  width: auto;
}

.editor > .module .knob-dial {
  width: 1.85rem;
  height: 1.85rem;
}

.editor > .panel.body {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.18rem 0;
  align-items: stretch;
}

.editor > .panel.body > h2 { grid-column: 1 / -1; }

.panel.body .knob { width: 2.05rem; }

.panel.body .knob-dial {
  width: 1.7rem;
  height: 1.7rem;
}

.feature {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.08rem;
  min-width: 0;
  padding: 0 0.4rem;
}

.feature:first-of-type { padding-left: 0; }
.feature:last-of-type { padding-right: 0; }

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

.feature-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.2rem;
  font-size: 0.66rem;
  color: var(--muted);
}

.feature-head .switch { margin: 0; }

.feature-knobs {
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 0.12rem;
}

.feature.off .feature-knobs { opacity: 0.38; }

.color-wrap {
  grid-column: 1 / -1;
}

.color-wrap > h2 {
  margin: 0 0 0.28rem;
  font-family: "Array-Regular", sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--plate);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.color-grid .module-body {
  justify-content: flex-start;
}

.components {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.piano {
  display: flex;
  height: 3.1rem;
  margin-top: 0.4rem;
  user-select: none;
}

.key {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
}

.key.black {
  background: #111;
  flex: 0.58;
  margin: 0 -0.32%;
  height: 58%;
  z-index: 1;
}

.key.on { background: var(--ok); }
.key.black.on { background: #6fa98a; }

.history {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.4rem 0.45rem;
}

.history h2 {
  margin: 0 0 0.28rem;
  font-family: "Array-Regular", sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--plate);
}

.history ol {
  list-style: none;
  margin: 0.28rem 0 0;
  padding: 0;
  max-height: 22rem;
  overflow: auto;
}

.history li {
  display: flex;
  justify-content: space-between;
  gap: 0.3rem;
  padding: 0.22rem 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.68rem;
}

.history li:first-child { border-top: 0; }

.muted { color: var(--muted); font-size: 0.62rem; }

footer {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.62rem;
  max-width: 42rem;
}

footer p { margin: 0; }
footer a { color: inherit; }

@media (max-width: 980px) {
  header { grid-template-columns: auto 1fr auto; }
  header .status { grid-column: 1 / -1; }
  .layout,
  .editor,
  .components,
  .color-grid { grid-template-columns: 1fr; }
  label.field { grid-template-columns: 4.2rem minmax(0, 1fr) 2.2rem; }
}
