: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;
}

.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;
  overflow: visible;
}
.app-footer { display: none; }
/* Faceplate screws */
.app-header::before, .app-header::after { content: none; }

.logo {
  font-family: "Segoe UI", "Gill Sans", "Exo 2", sans-serif;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .55em;
  font-size: 17px;
  margin-right: 10px;
  color: transparent;
  background: linear-gradient(90deg, #1d1f24, #4e5463 45%, #8d94a6);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow:
    0 1px 0 #fff4,
    0 -1px 1px rgba(0,0,0,.45);
}
.logo-table {
  border-collapse: collapse;
  margin: 0;
  width: auto;
}
.logo-table td {
  padding: 0 0.6em;
  text-align: center;
  vertical-align: middle;
}
.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 .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; }
/* One-line controls row */
.controls-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; overflow: visible; }
.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; }
.panel#panelWT .pwm-row {
  width: 100%;
  display: none;
  justify-content: space-between;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  margin-bottom: 12px;
}
.panel#panelWT .pwm-row.show {
  display: flex;
}
.panel#panelWT .pwm-row .knob {
  flex: 1 1 0;
  margin: 0;
  padding: 2px 4px;
  min-width: 0;
}
.panel#panelWT .pwm-row .knob label {
  font-size: 10px;
  margin-bottom: 2px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.panel#panelWT .pwm-row .knob input {
  width: 100%;
}
.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: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  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%; }
.hint-btn {
  background: none;
  border: none;
  color: #c73636;
  font-size: 11px;
  font-weight: 700;
  margin-left: 0;
  cursor: pointer;
  position: relative;
  padding: 0;
  letter-spacing: normal;
  line-height: 1;
  pointer-events: auto;
}
.hint-btn::after {
  content: attr(data-hint);
  position: absolute;
  left: 50%;
  transform: translate(-50%, 6px);
  top: 120%;
  bottom: auto;
  background: #2b2b2f;
  color: #fff;
  font-size: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  width: max-content;
  max-width: 160px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}
.hint-btn::before {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 110%;
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-bottom-color: #2b2b2f;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.hint-btn:hover::after,
.hint-btn:hover::before,
.hint-btn:focus-visible::after,
.hint-btn:focus-visible::before,
.hint-btn:active::after,
.hint-btn:active::before {
  opacity: 1;
  transform: translate(-50%, 8px);
}

/* 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: flex;
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
  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 */
.roll-area {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.roll-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.roll-vert-nav {
  width: 34px;
  border: 1px solid var(--face-edge);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  box-shadow: inset 0 1px 0 #fff8, inset 0 -1px 0 #0001;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.roll-vert-label {
  font-size: 11px;
  font-weight: 600;
  color: #4b5160;
  display: none;
}
.roll-vert-track {
  flex: 1;
  width: 100%;
  border-radius: 999px;
  border: 1px solid #c4cad9;
  background: linear-gradient(180deg, #f3f5fb, #dfe4f1);
  position: relative;
  padding: 4px 0;
  overflow: hidden;
}
.roll-vert-handle {
  position: absolute;
  left: 50%;
  width: 46px;
  margin-left: -23px;
  height: 38px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #dce3f3);
  border: 1px solid #9fa8c3;
  box-shadow: 0 2px 6px rgba(23, 34, 68, .15), inset 0 1px 0 #fff;
  transform: translateY(-50%);
  cursor: grab;
  transition: background 0.15s ease;
}
.roll-vert-handle.dragging {
  cursor: grabbing;
  background: linear-gradient(180deg, #f4f7ff, #cbd6f3);
}
.roll-horiz-nav {
  min-height: 32px;
  border: 1px solid var(--face-edge);
  border-radius: 999px;
  padding: 4px 12px;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  box-shadow: inset 0 1px 0 #fff6, inset 0 -1px 0 #0001;
  display: flex;
  align-items: center;
  gap: 12px;
}
.roll-horiz-nav.is-disabled {
  opacity: 0.55;
}
.roll-horiz-label {
  font-size: 11px;
  font-weight: 600;
  color: #4c566d;
  min-width: 70px;
  display: none;
}
.roll-horiz-track {
  flex: 1;
  position: relative;
  height: 12px;
  border-radius: 999px;
  border: 1px solid #c4cad9;
  background: linear-gradient(180deg, #f3f5fb, #dfe4f1);
  margin-left: 35px;
  margin-right: 35px;
  overflow: hidden;
}
.roll-horiz-handle {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 48px;
  border-radius: 20px;
  border: 1px solid #9fa8c3;
  background: linear-gradient(180deg, #ffffff, #dce3f3);
  box-shadow: 0 2px 6px rgba(23, 34, 68, .15), inset 0 1px 0 #fff;
  transform: translate(-50%, -50%);
  cursor: grab;
  transition: background 0.15s ease;
}
.roll-horiz-handle.dragging {
  cursor: grabbing;
  background: linear-gradient(180deg, #f4f7ff, #cbd6f3);
}
.piano-roll {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--face-edge);
  border-radius: 8px;
  background: linear-gradient(180deg, #fdfdff, #e7ebf5);
  box-shadow: inset 0 1px 0 #ffffffaa, inset 0 -1px 0 #00000015;
  overflow-x: hidden;
}
.roll-inner {
  width: 100%;
}
.piano-roll::-webkit-scrollbar { height: 10px; }
.piano-roll::-webkit-scrollbar-track { background: transparent; }
.piano-roll::-webkit-scrollbar-thumb { background: rgba(80,90,120,0.4); border-radius: 6px; }
.roll-grid {
  display: flex;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  flex: 1 1 auto;
}
.roll-labels {
  flex: 0 0 58px;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 2px 4px;
  border: 1px solid var(--face-edge);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  box-shadow: inset 0 1px 0 #fff6, inset 0 -1px 0 #0001;
}
.roll-label {
  text-align: right;
  font-size: 11px;
  color: #555;
  font-weight: 500;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 4px 0 0;
}
.roll-row {
  display: flex;
  align-items: center;
  padding: 2px 6px 2px 4px;
  position: relative;
  width: 100%;
}
.roll-row-overlay {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
}
.roll-row-overlay .note-span {
  position: absolute;
  top: 2px;
  bottom: 2px;
  background: #20c37f;
  border-radius: 0;
  box-shadow: inset 0 0 0 1px #149a57;
}
.roll-row-overlay .note-span.round-left {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}
.roll-row-overlay .note-span.round-right {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}
.roll-cells {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  position: relative;
  z-index: 1;
}
.roll-cell {
  border: 1px solid #c8cdda;
  border-radius: 3px;
  height: 20px;
  background: linear-gradient(180deg, #f6f8fd, #dfe3f0);
  cursor: pointer;
  transition: none;
  will-change: background-color;
  touch-action: none;
  position: relative;
  overflow: visible;
}
.roll-cell.sharp {
  background: linear-gradient(180deg, #e6e9f3, #d4d8e4);
}
.roll-cell {
  background-clip: padding-box;
  position: relative;
}
.roll-cell.active {
  background: transparent;
  border-color: transparent;
}
.roll-controls {
  display: grid;
  grid-template-columns: repeat(16, minmax(38px, 1fr));
  gap: 6px;
}
.roll-step {
  background: linear-gradient(180deg, var(--face), var(--face-2));
  border: 1px solid var(--face-edge);
  border-radius: 8px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: inset 0 1px 0 #fff6, inset 0 -1px 0 #0002;
}
.roll-step.selected {
  box-shadow: 0 0 0 2px rgba(34,204,136,.45), inset 0 1px 0 #fff6, inset 0 -1px 0 #0002;
}
.roll-step.drag-over {
  outline: 2px dashed var(--accent);
}
.roll-handle {
  width: 100%;
  border: none;
  background: none;
  font-size: 11px;
  font-weight: 600;
  color: #4f5662;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  touch-action: none;
}
.roll-handle .led {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #5b1f1f;
  border: 1px solid #7a3a3a;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.6);
}
.roll-handle .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;
}
.roll-toggle-row {
  width: 100%;
  display: flex;
  gap: 4px;
}
.roll-toggle {
  flex: 1 1 0;
  border: 1px solid #b2b8c3;
  border-radius: 4px;
  padding: 4px 2px;
  font-size: 9px;
  text-transform: uppercase;
  background: linear-gradient(180deg, #f8f9fc, #e0e4ef);
  cursor: pointer;
}
.roll-toggle.active {
  background: var(--accent);
  border-color: #179e63;
  color: #10261d;
  box-shadow: 0 0 6px rgba(23, 158, 99, 0.4);
}

@media (max-width: 900px) {
  .roll-label { width: 34px; font-size: 10px; }
  .roll-cells { grid-template-columns: repeat(16, minmax(18px, 1fr)); }
  .roll-controls { grid-template-columns: repeat(16, minmax(32px, 1fr)); }
}
@media (max-width: 600px) {
  .roll-label { width: 30px; font-size: 9px; }
  .roll-cells { grid-template-columns: repeat(16, minmax(14px, 1fr)); }
  .roll-toggle { font-size: 8px; padding: 3px 1px; }
}

.row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.row.toggles { display: flex; gap: 4px; }
.row.toggles.single { display: flex; }
  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; }
.logo { font-weight: 700; letter-spacing: 0.5px; font-size: 14px; }
.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;
}

.logo a.logo-link {
  color: inherit;
  text-decoration: none;
}
.logo a.logo-link:hover {
  text-decoration: underline;
}


.logo a.logo-link.subtle {
  font-size: 0.85em;
  color: rgba(255,255,255,0.85);
}

.knob.phaser-knob {
  display: none;
}
