:root {
  color-scheme: dark;
  --bg: #2e2e2e;
  --panel: #3b3b3b;
  --well: #1e1e1e;
  --line: #565656;
  --text: #e4e4e4;
  --muted: #a3a3a3;
  --accent: #ffb02e;
  --hot: #5fe3ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button { font: inherit; color: inherit; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--hot); outline-offset: 2px; }

#boot {
  position: fixed; inset: 0; z-index: 2;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity .25s;
}
#boot.done { opacity: 0; pointer-events: none; }
#boot.error .boot-bar { display: none; }
#boot.error #boot-text { color: var(--accent); }
.boot-inner { width: min(280px, 100vw - 32px); text-align: center; }
.boot-title { font-size: 20px; font-weight: 600; letter-spacing: .08em; }
.boot-bar { height: 3px; margin: 14px 0 10px; background: var(--well); overflow: hidden; }
.boot-bar span { display: block; width: 40%; height: 100%; background: var(--accent); animation: slide 1s ease-in-out infinite alternate; }
#boot-text { color: var(--muted); }
@keyframes slide { from { transform: translateX(-20%); } to { transform: translateX(170%); } }

main {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 20px 16px 28px;
  display: grid;
  gap: 18px;
}

header { display: flex; align-items: center; gap: 14px; }
h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .08em; }
#status { margin: 0 auto 0 0; color: var(--muted); }
.init { display: flex; align-items: center; gap: 7px; }

.label { color: var(--muted); font-size: 12px; }
.value { font-variant-numeric: tabular-nums; }
.label output { font-variant-numeric: tabular-nums; }
.control { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.controls {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: 18px 24px;
}
.toggles { display: flex; gap: 14px; }

.x {
  width: 96px; height: 96px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.x svg { display: block; width: 100%; height: 100%; }
.x path { fill: none; stroke: #5e5e5e; stroke-width: 5; stroke-linecap: round; }
.x[aria-pressed="true"] { background: #4a3c20; border-color: var(--accent); }
.x[aria-pressed="true"] path { stroke: var(--accent); }

.bang {
  width: 26px; height: 26px;
  background: var(--well);
  border: 3px solid #8a8a8a;
  border-radius: 50%;
}
.bang.flash { background: var(--accent); border-color: var(--accent); }

.fader {
  position: relative;
  width: 56px; height: 140px;
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  cursor: ns-resize;
  touch-action: none;
}
.fader .fill { position: absolute; inset: auto 0 0; min-height: 3px; background: var(--accent); }
.gain .fader { width: 40px; }
.gain .fader .fill { background: #8fd18c; }

.dac {
  width: 96px; height: 96px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
}
.dac svg { display: block; width: 70%; margin: auto; }
.dac .cone { fill: #6a6a6a; }
.dac .wave { fill: none; stroke: #6a6a6a; stroke-width: 4; stroke-linecap: round; }
.dac[aria-pressed="true"] { background: #4a3c20; border-color: var(--accent); }
.dac[aria-pressed="true"] .cone { fill: var(--accent); }
.dac[aria-pressed="true"] .wave { stroke: var(--accent); }

.keys-wrap { overflow-x: auto; }
.keys {
  position: relative;
  min-width: 620px;
  height: 104px;
  background: var(--well);
  border: 1px solid var(--line);
}
.key {
  position: absolute; top: 0; bottom: 0;
  border: 0; border-radius: 0 0 3px 3px;
}
.key.white {
  background: #e9e9e9;
  box-shadow: inset -1px 0 0 #8d8d8d;
  color: #666;
  font-size: 10px;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 4px;
}
.key.black { bottom: 38%; background: #222; z-index: 1; }
.key[aria-pressed="true"] { background: var(--accent); color: #2c2000; }
.key.playing { background: var(--hot); color: #00303c; }

.env {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.dials { display: grid; grid-template-columns: repeat(2, 56px); gap: 12px 16px; }
.dial { width: 52px; height: 52px; cursor: ns-resize; touch-action: none; border-radius: 50%; }
.dial svg { display: block; width: 100%; height: 100%; }
.dial .track, .dial .arc { fill: none; stroke-width: 6; stroke-linecap: round; }
.dial .track { stroke: var(--well); }
.dial .arc { stroke: var(--accent); }

.graph { display: grid; gap: 6px; min-width: 0; }
#adsr {
  display: block; width: 100%; height: auto;
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 4px;
  touch-action: none;
}
#adsr .shape { fill: rgba(255, 176, 46, .16); stroke: var(--accent); stroke-width: 2; }
#adsr .handle { fill: var(--text); stroke: var(--well); stroke-width: 2; cursor: grab; }
#adsr .slope { fill: var(--muted); cursor: ns-resize; }
#env-readout { color: var(--muted); }

@media (max-width: 640px) {
  .env { grid-template-columns: minmax(0, 1fr); }
  .dials { grid-template-columns: repeat(4, 56px); justify-content: space-between; }
  .controls { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .boot-bar span { animation: none; width: 100%; }
}
