:root {
  /* App backdrop */
  --bg: #131316;
  --fg: #1f2329;
  --muted: #5a606d;
  --accent: #22cc88;
  --grid: #b6bbc6;

  /* 303 faceplate look */
  --face: #d7d9df;
  --face-2: #cfd2d8;
  --face-edge: #b9bdc7;
  --text: #222428;
  --led-off: #2b2b2b;
  --led-on: #ff5a3d;
  --btn-start: #e8832b;
  --btn-stop: #e0463a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(#0f1013, #171821);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.default-kit-prompt {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: rgba(3, 5, 12, 0.85);
  backdrop-filter: blur(6px);
  z-index: 1100;
}
.default-kit-prompt[hidden] {
  display: none;
}
.default-kit-panel {
  width: min(460px, 90vw);
  padding: 28px 24px;
  background: linear-gradient(180deg, #f4f5fb, #dfe2ee);
  border-radius: 16px;
  border: 1px solid #aeb6c2;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
  color: #202336;
  font-size: 14px;
  line-height: 1.55;
}
.default-kit-actions {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.default-kit-actions .subtle {
  background: linear-gradient(180deg, #11181f, #0b0f12);
  border-color: #333;
  color: #f6f6fc;
}
.default-kit-progress {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #333;
}
.default-kit-progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e3e5ef;
  overflow: hidden;
}
.default-kit-progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #8ee3dc, #3caabd);
  transition: width 0.2s ease;
}
.default-kit-progress[data-indeterminate] .default-kit-progress-bar span {
  animation: progress-indeterminate 1.4s linear infinite;
}
.default-kit-progress-label {
  margin: 0;
}
/* New waveform action button */
.sample-actions .reverse-sample {
  min-width: 44px;
}
@keyframes progress-indeterminate {
  0% { margin-left: -100%; width: 40%; }
  50% { margin-left: 20%; width: 60%; }
  100% { margin-left: 100%; width: 40%; }
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: linear-gradient(180deg, #e7eaef, #cfd4dc);
  border-bottom: 1px solid #b3b9c4;
  box-shadow: inset 0 1px 0 #ffffffb3, inset 0 -1px 0 #00000012;
  position: relative;
}
.app-footer { display: none; }
/* Faceplate screws */
.app-header::before, .app-header::after { content: none; }

.transport { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; flex-wrap: nowrap; }
.tr-group { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px; background: linear-gradient(180deg,#eef2f7,#d5dbe3); border: 1px solid #b7bcc6; border-radius: 6px; box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011; }
.tr-transport { gap: 6px; background: none; border: none; border-radius: 0; box-shadow: none; padding: 0; }
.tr-sliders label { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: #444; }
.tr-sync { gap: 10px; }
.tr-sync label { display: inline-flex; align-items: center; gap: 6px; }
.sync-badge {
  margin-left: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 4px;
  border: 1px solid #b3b9c4;
  background: #eff2f7;
  color: #445;
  min-width: 90px;
  text-align: center;
  box-shadow: inset 0 1px 0 #ffffffc4, inset 0 -1px 0 #00000014;
  cursor: pointer;
}
.sync-badge.state-wait { background: #fff1b5; border-color: #d7b356; color: #6b4b00; }
.sync-badge.state-error { background: #ffd6d2; border-color: #e49992; color: #7b1f12; }
.sync-badge.state-follow { background: #d6f6ff; border-color: #82c1d8; color: #0b546f; }
.sync-badge.state-master { background: #e0ffdd; border-color: #75c163; color: #1e5c23; }
.tr-oct { gap: 6px; font-size: 11px; color: #444; }
.transport .tempo { font-size: 11px; }
.transport .master { font-size: 11px; }
.transport #tempoVal { cursor: pointer; display: inline-block; min-width: 28px; text-align: center; }
.transport #tempoVal .tempo-edit { width: 48px; padding: 0 4px; font-size: 11px; }
.tr-patterns label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #444; }
.tr-patterns select { min-width: 160px; }
.tr-patterns { display: none !important; }
.badge { padding: 2px 6px; font-size: 11px; border-radius: 4px; background: #ffe7a6; color: #6b4b00; border: 1px solid #d7b56a; box-shadow: inset 0 1px 0 #fff6; }
.transpose { display: inline-flex; align-items: center; gap: 6px; }
.transport input[type="range"] { vertical-align: middle; }

/* Start/Stop metallic buttons */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; border: none; background: radial-gradient(circle at 30% 30%, #f5f6f9, #c7ccd6); color: #2b2f39; box-shadow: inset 0 1px 0 #ffffffaa; cursor: pointer; }
.icon-btn:disabled { opacity: .6; cursor: default; }
.icon-btn.btn-start { box-shadow: inset 0 1px 0 #ffffffaa; color: #1e7b3d; }
.icon-btn.btn-stop { box-shadow: inset 0 1px 0 #ffffffaa; color: #7b2a1e; }
.icon-btn:active { transform: translateY(1px); }

/* Meter compact styling */

.level .label-vert { display: inline-flex; flex-direction: column; line-height: 1.05; }
.level .label-vert span { font-size: 11px; color: #444; }
.level .meter {
  position: relative;
  width: 140px;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(180deg, #dfe4ea, #c9d0d9);
  border: 1px solid #aeb6c2;
  box-shadow: inset 0 2px 2px #ffffffaa, inset 0 -1px 1px #00000010, 0 1px 1px rgba(0,0,0,.12);
  overflow: hidden;
}
/* Segment grid */
.level .meter::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to right,
    rgba(0,0,0,.18) 0 12px,
    rgba(0,0,0,.28) 12px 14px
  );
  opacity: .45;
  pointer-events: none;
}
/* Glass glare */
.level .meter::after {
  content: "";
  position: absolute; left: 0; right: 0; top: 0; height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0));
  pointer-events: none;
}
.level #meterFill {
  height: 100%;
  background: linear-gradient(90deg, #1fc659 0%, #36f07f 100%);
  box-shadow: 0 0 10px rgba(47,208,103,.35);
  -webkit-mask-image: repeating-linear-gradient(to right, #000 0 12px, transparent 12px 14px);
  mask-image: repeating-linear-gradient(to right, #000 0 12px, transparent 12px 14px);
  transition: box-shadow .15s linear, width .08s linear;
}
.level #meterFill.vu-mid {
  background: linear-gradient(90deg, #f7c948 0%, #ff9b2a 100%);
  box-shadow: 0 0 12px rgba(255, 159, 41, .55);
}
.level #meterFill.vu-high {
  background: linear-gradient(90deg, #ff6a00 0%, #ff3d2e 45%, #ff0a0a 100%);
  box-shadow: 0 0 14px rgba(255, 61, 46, .6);
}
/* Custom dark-grey sliders for Master and Tempo (no page-wide fills) */
#master, #tempo {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  /* Top layer: dark fill + light track (6px tall) */
  background:
    linear-gradient(to right,
      #8a94a6 0%, #8a94a6 var(--p,0%),
      #d0d3d9 var(--p,0%), #d0d3d9 100%) no-repeat,
    /* Bottom layer: pill backplate (curved background lines) */
    linear-gradient(180deg, #f4f6fa, #cfd4dc) no-repeat;
  background-position: center, center;
  background-size: 100% 6px, 100% 100%;
  border: 1px solid #aab0bb;
  border-radius: 10px;
  outline: none;
}
#master::-webkit-slider-runnable-track,
#tempo::-webkit-slider-runnable-track { height: 6px; background: transparent; border-radius: 3px; }
#master::-webkit-slider-thumb,
#tempo::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #6b7380; /* lighter grey */
  border: 1px solid #a7adb8;
  margin-top: -2.5px; /* center on 6px track */
}
#master:focus, #tempo:focus { box-shadow: 0 0 0 2px rgba(0,0,0,.06); }

/* Firefox */
#master::-moz-range-track,
#tempo::-moz-range-track { height: 6px; background: #d0d3d9; border-radius: 3px; }
#master::-moz-range-progress,
#tempo::-moz-range-progress { height: 6px; background: #8a94a6; border-radius: 3px; }
#master::-moz-range-thumb,
#tempo::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: #6b7380; border: 1px solid #a7adb8; }

.app-main { padding: 12px 16px; color: var(--text); flex: 1; overflow-x: hidden; overflow-y: auto; }

/* Layout: left (controls + sequencer) and right (tool panels) */
.ui-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 230px);
  column-gap: clamp(6px, 1vw, 12px);
  row-gap: 12px;
  align-items: start;
  min-height: 0;
}
@media (max-width: 1120px) {
  .ui-grid {
    grid-template-columns: 1fr;
  }
}
.left {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0;
  min-height: 0;
  min-width: 0;
}
.right {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
  min-width: 0;
}
/* Visually merge the top control panels into one block */
.left .panel:nth-of-type(1) { border-bottom: none; border-radius: 8px 8px 0 0; }
.left .panel:nth-of-type(2) { border-top: none; border-radius: 0 0 8px 8px; }
.left .panel:nth-of-type(n+2) h3 { display: none; }
/* Ensure right panels never overflow their track */
.right .panel { max-width: none; overflow: hidden; }
.right, .right .panel, .controls-row, .panel .buttons { min-width: 0; }

.panel { background: linear-gradient(180deg, var(--face), var(--face-2)); border: 1px solid var(--face-edge); border-radius: 8px; box-shadow: inset 0 1px 0 #fff6, inset 0 -1px 0 #0002; padding: 8px; }
.panel h3 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #4b4f58; }
.panel-headline { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.panel-headline p { margin: 0; font-size: 12px; color: #5f6168; }
.panel .group { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.panel .buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.panel .controls { background: none; border: 0; box-shadow: none; padding: 0; }
.drum-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.drum-card {
  border: 1px solid var(--face-edge);
  border-radius: 8px;
  padding: 8px;
  background: linear-gradient(180deg, #fbfcff, #e9edf5);
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.drum-card h4 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #30323a;
  display: flex;
  align-items: center;
  gap: 8px;
}
.drum-card h4 .voice-badge {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  border: none;
  background: #343844;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  font-family: inherit;
  appearance: none;
  box-shadow: inset 0 1px 0 #ffffff55, inset 0 -1px 0 #00000022;
  transition: transform .1s ease, box-shadow .15s ease;
}
.drum-card h4 .voice-badge:hover {
  transform: translateY(-1px);
}
.drum-card h4 .voice-badge:focus-visible {
  outline: 2px solid #8fb5ff;
  outline-offset: 1px;
}
.drum-card h4 .voice-badge.muted {
  box-shadow: inset 0 1px 0 #ffffff22, inset 0 -1px 0 #00000033;
  color: #d6dae4;
}
.drum-card h4 .voice-name {
  flex: 1;
}
.sample-card .sample-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sample-card.has-sample {
  border-color: #6cc68c;
  box-shadow: 0 0 0 1px #6cc68c33 inset;
}
.sample-info {
  flex: 1 1 160px;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px dashed #c9ced8;
  background: #f9fbff;
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #2c2f37;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  font-family: inherit;
  appearance: none;
}
.sample-info.empty {
  color: #6b6f7a;
  border-color: #d8dde8;
  background: #f4f6fa;
}
.sample-info:hover,
.sample-info:focus-visible {
  border-color: #7b8cff;
  background: #fff;
  outline: none;
}
.waveform-wrap {
  position: relative;
  width: 100%;
  min-height: 52px;
  background: #1f2230;
  border-radius: 6px;
  overflow: hidden;
  cursor: default;
}
.waveform-wrap canvas {
  width: 100%;
  height: 48px;
  display: block;
}
.wave-handle {
  position: absolute;
  top: 0;
  width: 3px;
  height: 100%;
  background: #ffdf5c;
  border-radius: 2px;
  cursor: ew-resize;
  transform: translateX(-50%);
  box-shadow: 0 0 4px rgba(0,0,0,0.35);
}
.wave-handle.start {
  background: #ffc930;
}
.wave-handle.end {
  background: #ffe88c;
}
.wave-play-zone {
  position: absolute;
  top: 0;
  height: 100%;
  border: none;
  background: rgba(255,255,255,0.05);
  cursor: pointer;
  padding: 0;
  margin: 0;
  outline: none;
}
.wave-play-zone:focus-visible {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.4) inset;
}
.sample-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  margin-top: 4px;
}
.sample-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.btn-ghost {
  background: transparent;
  border: 1px solid #6e7385;
  color: #d3d6e0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-ghost:hover,
.btn-ghost:focus-visible {
  border-color: #9cb7ff;
  color: #ffffff;
}
/* reuse same color for both actions; only border changes */
.btn-ghost.danger {
  border-color: #d97777;
}
.btn-ghost.danger:hover,
.btn-ghost.danger:focus-visible {
  border-color: #ff8c8c;
  color: #6c0a0a;
}
.sample-status {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #6f7382;
}
.drum-card .knob { margin: 0; }
.drum-card .voice-knobs {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: stretch;
}
.drum-card .voice-knobs .knob {
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
}
.drum-card .voice-knobs .knob label {
  font-size: 9px;
  letter-spacing: .05em;
  margin-bottom: 2px;
}
.drum-card .voice-knobs .knob input[type="range"] {
  height: 14px;
}
/* One-line controls row */
.controls-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; overflow: hidden; }
.controls-row .knob { flex: 0 1 auto; min-width: 0; }
.tidy-row .ctl-group { flex: 0 1 auto; min-width: 0; }
.controls-row.one-line { flex-wrap: nowrap; gap: 6px; }
/* Reserve-space hidden state (keeps layout width stable without showing content) */
.hidden-reserve { visibility: hidden; pointer-events: none; }
/* Fix widths for PWM knobs so layout width stays constant */
.knob.pwm { flex: 0 0 92px; min-width: 92px; }
body.compact .knob.pwm { flex-basis: 84px; min-width: 84px; }

/* Prevent overlap on narrower screens: allow control strip to wrap if needed */
@media (max-width: 1280px) {
  #controlStrip .controls-row.one-line { flex-wrap: wrap; }
}

/* PWM secondary row */
.pwm-row { display: none; gap: 8px; align-items: center; margin-top: 4px; }
.pwm-row.show { display: flex; }
body.compact .pwm-row { gap: 6px; }
.controls-row.one-line .knob { min-width: 72px; }
.controls-row.one-line select { width: 100px; }
/* Tidy control strip groups */
.tidy-row .ctl-group { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; background: linear-gradient(180deg, #f4f6fa, #e6e9f1); border: 1px solid var(--face-edge); border-radius: 8px; box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011; }
.tidy-row .ctl-group + .ctl-group { margin-left: 8px; }
.tidy-row .group-wave select { width: 120px; }
.tidy-row .group-filter .knob, .tidy-row .group-fx .knob { min-width: 72px; }
body.compact .tidy-row .ctl-group { padding: 4px 6px; border-radius: 6px; }
.controls-row .knob { min-width: 80px; }
.controls-row select { width: 110px; }
/* Inline rows for grouped buttons (e.g., Shift left/right) */
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls-row { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; }
.controls-row .knob { min-width: 90px; }
.controls-row select { width: 110px; }

.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; background: none; padding: 0; border: 0; box-shadow: none; }
.knob { text-align: center; }
.knob label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .08em; }
.knob input[type="range"] { width: 100%; }
.knob select { width: 100%; }

/* Sequencer Tools toolbar (single line at typical widths) */
#seqToolsBottom .buttons { display: none; }
#seqToolsBottom .controls-row { display: none; }
.tools-bar { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; overflow: visible; }
.tools-bar .group { display: inline-flex; align-items: center; gap: 6px; }
.tools-bar input[type="text"] { width: 180px; max-width: 30vw; }
.btn-sm { padding: 3px 6px; font-size: 11px; }
.btn-xs { padding: 2px 4px; font-size: 10px; line-height: 1.1; }
.btn.active { filter: brightness(1.05); box-shadow: inset 0 1px 0 #fff8, 0 0 0 2px rgba(34,204,136,.18); }
/* Highlighted arrangement area */
.tools-bar .arr-group {
  background: linear-gradient(180deg, #f4f6fa, #e6e9f1);
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  padding: 4px 6px;
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011;
}
.tools-bar .arr-group label { margin-right: 2px; }

/* TB-303 styled dropdowns (silver face, custom arrow) */
.transport select,
.panel select,
.knob select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  color: #333;
  background:
    linear-gradient(180deg, #eef1f5, #cbd0d8) padding-box,
    linear-gradient(180deg, #ffffffaa, #00000011) border-box;
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011, 0 1px 1px rgba(0,0,0,.1);
  outline: none;
  cursor: pointer;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px 14px;
}
.transport select:hover,
.panel select:hover,
.knob select:hover { filter: brightness(1.02); }
.transport select:focus,
.panel select:focus,
.knob select:focus { box-shadow: 0 0 0 2px rgba(34, 204, 136, .25), inset 0 1px 0 #fff; }
.transport select:disabled,
.panel select:disabled,
.knob select:disabled { opacity: .6; cursor: default; }

/* Compact tweaks for dropdowns */
body.compact .transport select,
body.compact .panel select,
body.compact .knob select { padding: 4px 24px 4px 8px; font-size: 11px; }

/* TB-303 style rotary knobs */
.dial { display: none; }
.dial .cap { display: none; }
.dial .marker { display: none; }
.dial .ticks, .dial .tick { display: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.sequencer {
  margin-top: 5px;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  overflow-x: auto;
  max-width: 100%;
}

/* Space between sequencer and tools panel */
#seqToolsBottom { margin-top: 5px; }
/* Flat top, rounded bottom for Sequencer Tools panel */
#seqToolsBottom.panel {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

/* Tweak step minimum width as screen narrows */
@media (max-width: 1200px) {
  .sequencer { grid-template-columns: repeat(6, minmax(120px, 1fr)); }
}
@media (max-width: 900px) {
  .sequencer { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
  .step { padding: 6px 4px 6px; }
  .pbtn { padding: 5px 4px; font-size: 9px; }
  .pitch .mini, .oct .mini { padding: 3px; font-size: 9px; }
}
@media (max-width: 600px) {
  .sequencer { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
  .step header { font-size: 10px; }
}

.step {
  background: linear-gradient(180deg, var(--face), var(--face-2));
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  padding: 6px 6px 8px;
  display: grid;
  gap: 6px;
  box-shadow: inset 0 1px 0 #fff6, inset 0 -1px 0 #0002;
}
.step { min-width: 90px; }
.step.active { outline: 2px solid rgba(34,204,136,.35); }
.step[draggable="true"] { cursor: grab; }
.step.dragging { opacity: .6; cursor: grabbing; }
.step.drag-over { outline: 2px dashed var(--accent); }
.step.drag-over::after { content: ""; display: block; height: 0; }
.step header { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); gap: 4px; flex-direction: column; }
.step header .led { width: 14px; height: 14px; border-radius: 50%; background: #5b1f1f; border: 1px solid #7a3a3a; box-shadow: inset 0 -2px 3px rgba(0,0,0,.6); display: inline-block; }
.step header .led.lit { background: var(--led-on); box-shadow: 0 0 8px var(--led-on), inset 0 -1px 2px rgba(0,0,0,.6); border-color: #b83a2a; }
.step .index { font-size: 10px; color: #777; letter-spacing: .06em; }
.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
  gap: 4px;
}
.step .voice-btn {
  font-size: 9px;
  padding: 4px;
  border-color: rgba(0,0,0,.1);
}
.step .voice-btn.active {
  color: #fff;
  background: var(--voice-color, var(--accent));
  border-color: var(--voice-color, var(--accent));
  box-shadow: 0 0 6px rgba(0,0,0,.2);
}
.row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.row.toggles { display: flex; gap: 4px; }
.row.toggles.single { display: flex; }
.row.toggles.single .pbtn { flex: 1; }
.row.toggles.duo { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.pitch.row, .oct.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 4px 0;
}
.pitch-label {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: #444;
}
.pitch.row .pbtn.mini,
.oct.row .pbtn.mini {
  flex: 0 0 28px;
  padding: 4px;
}
.row select, .row input[type="checkbox"] { width: 100%; }
/* Hide legacy form controls inside steps; replaced by TB-style buttons */
.row.toggles label, .row.toggles input[type="checkbox"] { display: none; }
.row select { display: none; }

/* TB-303 like push buttons for sequencer */
.pbtn {
  background: linear-gradient(#eef1f5, #cbd0d8);
  border: 1px solid var(--face-edge);
  border-radius: 4px;
  padding: 6px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #333;
  box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 #0001, 0 1px 1px rgba(0,0,0,.15);
  cursor: pointer;
}
.pbtn.active { background: linear-gradient(#e4d6ff, #c2a9ff); border-color: #9c85db; color: #3d2f70; }
.pbtn:active { transform: translateY(1px); }

.led2 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 22px;
  margin-right: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  color: #ff3b30;
  background: #0a0a0c;
  border: 1px solid #2a2a2f;
  border-radius: 4px;
  box-shadow: inset 0 0 6px rgba(255,0,0,.15), inset 0 -2px 4px rgba(0,0,0,.5);
  text-shadow: 0 0 6px rgba(255,0,0,.5);
}

.pitch { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; }
.pitch .mini { padding: 4px; font-size: 10px; }
.pitch .label { font-size: 11px; text-align: center; color: #444; }
.oct { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.oct .mini { padding: 4px; font-size: 10px; }

button,
.btn {
  background: linear-gradient(#e8e8ee, #cfd2d8);
  color: var(--text);
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 #fff8;
}
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { display: block; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:hover:not(:disabled) { filter: brightness(1.03); }
.btn.btn-start { background: linear-gradient(#ffb27c, var(--btn-start)); color: #fff; border-color: #ce6a16; }
.btn.btn-stop { background: linear-gradient(#ff8e86, var(--btn-stop)); color: #fff; border-color: #c22f25; }
.btn.btn-small { padding: 4px 8px; font-size: 12px; }
.btn-rec { background: linear-gradient(#2b6fb8, #1a57a0); color: #fff; border-color: #164c8c; }
.btn-rec.active { filter: none; box-shadow: 0 0 0 2px rgba(43,111,184,.28); }
.btn-rec.recording { background: linear-gradient(#1f7d4f, #175b3a); border-color: #134b30; }
.btn-del { background: linear-gradient(#b83b3b, #962b2b); color: #fff; border-color: #7f2323; }

/* Arrangement blocks (drag reorder) */
/* Octave button press feedback */
.btn.btn-small.oct-active-1 { background: linear-gradient(#e3d2ff, #c0a0ff); color: #352964; border-color: #9f8ad8; box-shadow: 0 0 0 2px rgba(159,138,216,.28) inset; }
.btn.btn-small.oct-active-2 { background: linear-gradient(#d9c4ff, #b48cff); color: #2c2156; border-color: #9277d1; box-shadow: 0 0 0 2px rgba(146,119,209,.38) inset; }

/* Metallic TB-303 style for transport icons */
.btn.icon-btn,
.btn.btn-start.icon-btn,
.btn.btn-stop.icon-btn {
  background: radial-gradient(circle at 30% 30%, #f4f5f7, #c6c9cf);
  border: 1px solid #aab0bb;
  color: #333;
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,.15),
    inset 0 -2px 3px rgba(255,255,255,.4),
    0 1px 2px rgba(0,0,0,.15);
}
.btn.icon-btn svg { color: currentColor; }
.btn.icon-btn:hover:not(:disabled) {
  filter: none;
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,.18),
    inset 0 -2px 3px rgba(255,255,255,.5),
    0 2px 3px rgba(0,0,0,.2);
}
.btn.icon-btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 3px 6px rgba(0,0,0,.25),
    inset 0 -1px 2px rgba(255,255,255,.45),
    0 1px 1px rgba(0,0,0,.1);
}

input[type="file"] { color: var(--muted); }

/* Additions: hint, level meter, status */
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }

.status { margin-top: 8px; color: #364; background: #eaf7ef; border: 1px solid #b7e1c2; padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.status.error { color: #632; background: #fbeeed; border-color: #f1c4c0; }

/* Drag-to-DAW handles */

/* SVG knob skin */
.k {
  width: 34px;
  height: 34px;
  position: relative;
  margin: 0 auto 4px;
  cursor: grab;
  touch-action: none;
}
.k.dragging { cursor: grabbing; }
.k-svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.k:hover { filter: brightness(1.04); }
.k-plate { fill: #bfc5cf; stroke: #9ba2b0; stroke-width: 1.4; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.k-ring { fill: none; stroke: rgba(255,255,255,.35); stroke-width: 2; }
.k-knurl { fill: none; stroke: #8d93a2; stroke-width: 8; stroke-dasharray: 3 6; opacity: .55; }
.k-face { stroke: #8e94a2; stroke-width: 1.2; }
.k-highlight { fill: none; stroke: rgba(255,255,255,.55); stroke-width: 3; stroke-linecap: round; }
.k-tick { stroke: rgba(0,0,0,.25); stroke-width: 1.4; stroke-linecap: round; }
.k-pointer { stroke: #1f2024; stroke-width: 2.6; stroke-linecap: round; }
.k-pointer-dot { fill: #1f2024; }
.k-cap { stroke: #7d838f; stroke-width: 1; }
.k-value {
  font-size: 10px;
  color: #333;
  min-height: 12px;
  line-height: 12px;
  letter-spacing: .04em;
}
body.compact .k { width: 26px; height: 26px; }

/* Ultra-compact layout to fit everything on one screen */
.compact-grid { display: grid; grid-template-rows: auto auto 1fr; gap: 8px; height: 100%; }
body.compact .panel { padding: 6px; }
body.compact .panel h3 { font-size: 10px; margin-bottom: 4px; }
body.compact .panel .group { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
body.compact .panel .buttons { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
body.compact .dial { width: 36px; height: 36px; }
body.compact .dial .cap { width: 20px; height: 20px; }
body.compact .dial .marker { height: 13px; transform-origin: 50% 13px; transform: translate(-50%, -13px) rotate(0deg); }
body.compact .dial .tick { height: 3px; transform-origin: 50% 14px; }
body.compact .knob label { font-size: 10px; }
body.compact .btn, body.compact button { padding: 4px 6px; font-size: 12px; }
body.compact .icon-btn { width: 36px; height: 36px; }
body.compact .sequencer { grid-template-columns: repeat(8, minmax(100px, 1fr)); gap: 6px; }
body.compact .step { padding: 4px; }
/* In compact mode, keep note and octave controls visible */
body.compact .row.pitch, body.compact .row.oct { display: grid; }
body.compact .pbtn { padding: 4px 3px; font-size: 9px; }

/* --- Right-side 303-styled modules --- */
.panel-303 { padding: 6px; }
.panel-303 h3 { margin: 0 0 6px; padding: 4px 6px; font-size: 10px; letter-spacing: .14em; color: #555b66; background: linear-gradient(180deg, #e9edf3, #cfd4dc); border: 1px solid #b7bcc6; border-radius: 4px; box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011; display: inline-block; }
.panel-303 .mod-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; align-items: center; }
/* Make randomize buttons fit on one line */
#panelRandom .mod-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
#panelRandom .mod-body .btn-303 { white-space: normal; width: 100%; justify-self: stretch; padding: 6px 8px; }
#panelRandom #randomizePattern.btn-dark { background: linear-gradient(#d5d9df, #b9bec7); border-color: #aab0bb; color: #222; }

#randomizePattern {
  position: relative;
  overflow: hidden;
  z-index: 0;
}

#randomizePattern::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 8px;
  background: linear-gradient(120deg, #ff007a, #ffae00, #00e1ff, #9d00ff, #ff007a);
  background-size: 300% 300%;
  animation: rainbowPulse 3s ease infinite;
  z-index: -1;
  filter: blur(6px);
  opacity: 0.6;
}

#randomizePattern:focus-visible::after,
#randomizePattern:hover::after {
  opacity: 0.85;
}

@keyframes rainbowPulse {
  0% { transform: scale(0.95); background-position: 0% 50%; }
  50% { transform: scale(1.05); background-position: 100% 50%; }
  100% { transform: scale(0.95); background-position: 0% 50%; }
}

/* 303-style compact buttons */
.btn-303 { background: linear-gradient(#eef1f5, #cbd0d8); border: 1px solid var(--face-edge); border-radius: 6px; box-shadow: inset 0 1px 0 #fff8, 0 1px 1px rgba(0,0,0,.12); font-size: 12px; padding: 6px 8px; }
.btn-303:active { transform: translateY(1px); }
.btn-303.btn-sm { padding: 4px 6px; font-size: 11px; }

/* Improved drag handles */
/* drag handles removed */


/* Recent menu popover */
.recent-wrap { position: relative; display: inline-block; }
.recent-menu {
  position: fixed; /* overlay above panels; positioned via JS */
  z-index: 10000;
  min-width: 260px;
  max-width: 340px;
  max-height: 240px;
  overflow: auto;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25), inset 0 1px 0 #fff6, inset 0 -1px 0 #0002;
  padding: 6px;
}
.recent-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.recent-item:hover { background: rgba(0,0,0,.06); }
.recent-name { font-size: 12px; color: #222; }
.recent-time { font-size: 11px; color: #666; }
.recent-empty { font-size: 12px; color: #666; padding: 6px; }
/* LCD-like status */
.status.lcd { background: linear-gradient(180deg, #1c2b22, #16251d); color: #8ff0a4; border-color: #2f4a3c; box-shadow: inset 0 1px 2px rgba(0,0,0,.4); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
/* FILE panel 303 styling */
#panelFile .file-rows { display: grid; grid-template-columns: 1fr; gap: 0; }
#panelFile .mod-body.file-rows { grid-template-columns: 1fr !important; }
#panelFile .file-row.meta { grid-column: 1; }
#panelFile .file-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; align-items: center; }
#panelFile .btn-303 { justify-content: center; display: inline-flex; align-items: center; padding: 4px; font-size: 10px; width: 100%; }
#panelFile .btn-303.btn-wide { min-width: 0; }
#panelFile .recent-wrap { position: relative; display: inline-flex; }
#panelFile .recent-wrap .btn-303 { width: 100%; }
#panelFile .btn-303 .btn-ico { margin-right: 6px; vertical-align: -2px; display: inline-block; width: 14px; height: 14px; flex: 0 0 auto; }
#panelFile .btn-303 svg { display: inline-block; width: 14px; height: 14px; margin-right: 6px; }
#panelFile .recent-wrap { flex: 1 1 0; min-width: 0; }
#panelFile .file-row.meta {
  display: block;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--face-edge);
}
#panelFile .badge-plate {
  display: inline-block;
  padding: 4px 8px;
  font-size: 11px;
  color: #3c4250;
  background: linear-gradient(180deg, #eef1f5, #cbd0d8);
  border: 1px solid var(--face-edge);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011;
  white-space: nowrap;
}
#panelFile .wt-label {
  display: block;
  padding: 6px 8px;
  background: #f3f6fa;
  border: 1px dashed var(--face-edge);
  border-radius: 6px;
}

/* Separate Wavetable panel styling */
#panelWT .wt-body { display: grid; grid-template-columns: 1fr; gap: 8px; }
#panelWT .wt-label { display: block; padding: 8px; background: #f3f6fa; border: 1px dashed var(--face-edge); border-radius: 6px; }
#panelWT .wt-help { font-size: 11px; color: #555; }

#panelWT .panel-desc { font-size: 11px; color: #555; margin: 6px 0 8px; }

.arr-inline {
  background: linear-gradient(180deg, #f4f6fa, #e6e9f1);
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  padding: 4px 6px;
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000011;
  gap: 6px;
}
.arr-inline-track {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 160px;
  max-width: 240px;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 6px;
  cursor: pointer;
}
.arr-inline-track:active { cursor: grabbing; }
.arr-inline-track::-webkit-scrollbar { height: 4px; }
.arr-inline-track::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 4px; }
.arr-inline-actions { display: inline-flex; gap: 4px; }
.arr-label { font-size: 11px; color: #555; text-transform: uppercase; letter-spacing: .08em; }
.arr-block {
  min-width: 28px;
  padding: 3px 4px;
  border-radius: 6px;
  border: 1px solid #a7aebc;
  background: linear-gradient(180deg, #f8f9fd, #dfe4ee);
  font-size: 11px;
  font-weight: 600;
  color: #4c5466;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(12,15,22,.2);
}
.arr-block.playing { border-color: #22cc88; box-shadow: 0 0 0 2px rgba(34,204,136,.25); }
.arr-block.active-edit { background: linear-gradient(180deg, #f4fffb, #d7f7eb); }
.arr-block.selected-remove { outline: 1px solid #d94b4b; }
.arr-block.drag-over { outline: 1px dashed rgba(76,84,102,.5); }


/* Render panel: keep three buttons on one line */
#panelRender .mod-body { display: flex; gap: 6px; align-items: stretch; flex-wrap: wrap; }
#panelRender .mod-body .btn-303 { flex: 1 1 120px; min-width: 0; white-space: normal; }
#panelRender .render-progress {
  position: relative;
  width: 100%;
  margin-top: 8px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #dfe4ee, #c6ccd9);
  box-shadow: inset 0 1px 0 #ffffffb3, inset 0 -1px 0 #0000001a;
  overflow: hidden;
  font-size: 10px;
  color: #333;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
#panelRender .render-progress[hidden] { display: none; }
.render-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #26c46d, #1ba1f2);
  transition: width 0.15s ease;
}
#renderProgressLabel {
  position: relative;
  padding: 0 6px;
  font-weight: 600;
}
