:root {
  --bg-0: #07060a;
  --bg-1: #0d0b14;
  --panel: #14111e;
  --panel-2: #1b1729;
  --metal-a: #2a2636;
  --metal-b: #16131f;
  --line: #322c44;
  --text: #f2eefc;
  --text-dim: #9089ab;
  --accent: #ff2e9a;
  --accent-2: #34e2ff;
  --ok: #38ffab;
  --danger: #ff4d5e;
  --radius: 18px;
  font-size: clamp(14px, 1.05vw + 0.4vh, 19px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(1200px 700px at 15% -10%, #241a3a 0%, transparent 55%),
              radial-gradient(1000px 600px at 110% 10%, #1a2f3a 0%, transparent 50%),
              var(--bg-0);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  height: 100vh;
  /* 100vh is a snapshot of the *largest* possible viewport and doesn't track the browser's
     own UI (toolbar, gesture bar) settling after a fresh navigation -- on Android that can
     leave body taller than what's actually visible right after a reload, with `overflow:
     hidden` above clipping the footer (build-version text) off the bottom entirely. 100dvh
     tracks the actual current visible viewport instead; kept 100vh above as a fallback for
     browsers that don't support dvh. */
  height: 100dvh;
}

button { font-family: inherit; cursor: pointer; }
select { font-family: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.2rem;
  background: linear-gradient(180deg, #171225, #0e0b18);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand-mark {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(255, 46, 154, 0.35));
}
.brand-sub { font-size: 0.62rem; letter-spacing: 0.18em; color: var(--text-dim); font-weight: 600; }

.conn-controls { display: flex; gap: 0.6rem; align-items: center; }

.transport-select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.connect-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  padding: 0.55rem 1.1rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, color 0.2s;
}
.connect-btn:active { transform: scale(0.96); }
.connect-btn.connected { border-color: var(--ok); color: var(--ok); box-shadow: 0 0 14px rgba(56, 255, 171, 0.25); text-shadow: 0 0 8px rgba(56,255,171,0.5); }

.led {
  width: 0.6rem; height: 0.6rem; border-radius: 50%;
  background: #4a4560; box-shadow: inset 0 0 3px #000;
}
.led.on { background: var(--ok); box-shadow: 0 0 8px var(--ok), 0 0 18px var(--ok); }

.log-toggle {
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  transition: border-color 0.15s, color 0.15s;
}
.log-toggle.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 12px rgba(255,46,154,0.3); }

.icon-btn {
  flex: 0 0 auto;
  width: 2.5rem; height: 2.5rem;
  display: flex; align-items: center; justify-content: center;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  border-radius: 10px;
  transition: border-color 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn.active { border-color: var(--accent-2); color: var(--accent-2); box-shadow: 0 0 12px rgba(52,226,255,0.3); }
.icon-btn svg { width: 1.3rem; height: 1.3rem; display: block; }

/* ---------- MIDI raw monitor ---------- */
.midi-log {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: min(50vh, 22rem);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-top: 4px solid var(--line);
  box-shadow: 0 -12px 40px rgba(0,0,0,0.6);
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 55;
  display: flex;
  flex-direction: column;
}
.midi-log.show { transform: translateY(0); }
.midi-log-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.1rem;
  border-bottom: 3px solid var(--line);
}
.midi-log-head h2 { margin: 0; font-size: 1.1rem; letter-spacing: 0.06em; }
.midi-log-actions { display: flex; gap: 0.6rem; align-items: center; }
.log-clear-btn {
  background: #0a0812; border: 1.5px solid #3a3550; color: var(--text-dim);
  padding: 0.4rem 0.8rem; border-radius: 8px; font-weight: 800; font-size: 0.75rem;
}
.midi-log-body {
  flex: 1; overflow-y: auto; padding: 0.6rem 1.1rem;
  font-family: 'Consolas', monospace;
  font-size: 0.85rem;
}
.midi-log-empty { color: var(--text-dim); font-family: inherit; }
.midi-log-row {
  display: flex; gap: 0.8rem; padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  white-space: nowrap;
}
.midi-log-time { color: #5c5674; flex: 0 0 auto; }
.midi-log-port { color: var(--accent-2); flex: 0 0 auto; font-weight: 700; overflow: hidden; text-overflow: ellipsis; max-width: 9em; }
.midi-log-bytes { color: var(--text); flex: 0 0 auto; }
.midi-log-decoded { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }

/* ---------- Console log viewer ---------- */
.log-row {
  display: flex; gap: 0.8rem; padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  white-space: pre-wrap; word-break: break-word;
}
.log-time { color: #5c5674; flex: 0 0 auto; font-family: 'Consolas', monospace; font-size: 0.8rem; }
.log-level { flex: 0 0 auto; font-weight: 700; font-family: 'Consolas', monospace; font-size: 0.8rem; }
.log-msg { flex: 1; overflow-wrap: break-word; font-family: 'Consolas', monospace; font-size: 0.8rem; }
.log-log { color: var(--text); }
.log-log .log-level { color: #5c5674; }
.log-info { color: var(--accent-2); }
.log-info .log-level { color: var(--accent-2); }
.log-warn { color: #ffce3d; }
.log-warn .log-level { color: #ffce3d; }
.log-error { color: var(--danger); }
.log-error .log-level { color: var(--danger); }

/* ---------- Patch strip ---------- */
.patch-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1.2rem;
}

.patch-nav {
  flex: 0 0 auto;
  width: 2.8rem; height: 2.8rem;
  border-radius: 50%;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  font-size: 1rem;
  font-weight: 700;
  transition: border-color 0.15s, color 0.15s, transform 0.1s;
}
.patch-nav:active:not(:disabled) { transform: scale(0.92); }
.patch-nav:not(:disabled):hover { border-color: var(--accent-2); color: var(--accent-2); }
.patch-nav:disabled { opacity: 0.3; }

.patch-lcd {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  border-radius: 12px;
  padding: 0.55rem 1.2rem;
}
.patch-lcd:disabled { opacity: 0.55; }
.lcd-num {
  font-weight: 900;
  font-size: 1.6rem;
  color: var(--accent-2);
  text-shadow: 0 0 12px rgba(52,226,255,0.55);
  flex: 0 0 auto;
  letter-spacing: 0.02em;
}
.lcd-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 10px rgba(242,238,252,0.25);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.tuner-btn {
  flex: 0 0 auto;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  transition: border-color 0.15s, color 0.15s;
}
.tuner-btn.on { color: #ffce3d; border-color: #ffce3d; box-shadow: 0 0 14px rgba(255,206,61,0.35); text-shadow: 0 0 8px rgba(255,206,61,0.5); }

.save-btn {
  flex: 0 0 auto;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  color: var(--text-dim);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.save-btn:disabled { opacity: 0.3; }
.save-btn:active:not(:disabled) { transform: scale(0.96); }
.save-btn.saved { color: var(--ok); border-color: var(--ok); box-shadow: 0 0 14px rgba(56,255,171,0.4); }
.tuner-btn:disabled { opacity: 0.3; }

.master-vol {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0a0812;
  border: 1.5px solid #3a3550;
  padding: 0.45rem 0.9rem;
  border-radius: 10px;
}
.master-vol.disabled { opacity: 0.35; }
.mv-label { font-size: 0.7rem; font-weight: 700; color: var(--text-dim); }
.mv-value { font-size: 0.75rem; font-weight: 700; width: 1.8em; text-align: right; }
#masterVol { width: 6rem; accent-color: var(--accent-2); }

/* ---------- Pedalboard ---------- */
.pedalboard {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0.9rem;
  padding: 0.3rem 1.2rem 1rem;
}

.pedal {
  --hue: 200;
  --off: #4a4560;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 4px solid var(--off);
  border-radius: 14px;
  background: #0a0812;
  color: var(--text);
  padding: 0.4rem 0.3rem;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.pedal:disabled { opacity: 0.45; }
.pedal:active:not(:disabled) { transform: scale(0.96); }

.pedal.on {
  background: linear-gradient(160deg, hsl(var(--hue), 78%, 42%), hsl(var(--hue), 82%, 22%));
  border-color: hsl(var(--hue), 90%, 68%);
  box-shadow: 0 0 24px hsla(var(--hue), 85%, 55%, 0.6), inset 0 1px 0 rgba(255,255,255,0.18), inset 0 -14px 22px rgba(0,0,0,0.25);
}

/* Idle sparkle for bypassed pedals: every off pedal flashes together, each in its own
   hue, on a shared beat (no per-card delay — a staggered "wave" version of this looked
   out of sync in practice). */
@keyframes pedal-blink {
  0%   { box-shadow: none; border-color: var(--off); }
  8%   { box-shadow: 0 0 22px 2px hsla(var(--hue), 85%, 58%, 0.65); border-color: hsl(var(--hue), 85%, 62%); }
  22%  { box-shadow: none; border-color: var(--off); }
  100% { box-shadow: none; border-color: var(--off); }
}
.pedal:not(.on) { animation: pedal-blink 2.5s ease-in-out infinite; }

.pedal-icon {
  width: 3.4rem; height: 3.4rem;
  color: var(--off);
  transition: color 0.2s, filter 0.2s;
}
.pedal-icon svg { width: 100%; height: 100%; display: block; }
.pedal.on .pedal-icon { color: #fff; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.45)); }

.pedal-label {
  font-weight: 900; letter-spacing: 0.05em; font-size: 1.3rem;
  color: var(--text-dim);
  transition: color 0.2s;
}
.pedal.on .pedal-label { color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,0.5); }

.pedal-effect {
  font-size: 0.82rem; color: #6c6690; font-weight: 700;
  max-width: 94%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pedal.on .pedal-effect { color: rgba(255,255,255,0.88); text-shadow: 0 1px 3px rgba(0,0,0,0.4); }

/* ---------- Status bar ---------- */
.status-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 1.2rem;
  border-top: 1px solid var(--line);
  background: rgba(10,8,16,0.85);
  font-size: 0.72rem;
  color: var(--text-dim);
}
.status-text.error { color: var(--danger); }
.status-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner {
  width: 0.85rem; height: 0.85rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  display: none;
  animation: spin 0.8s linear infinite;
}
.spinner.active { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.build-version { flex: 0 0 auto; font-family: 'Consolas', monospace; font-size: 0.68rem; color: #5c5674; letter-spacing: 0.02em; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 4.6rem; transform: translate(-50%, -0.6rem);
  max-width: min(28rem, 88vw);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1.5px solid var(--line);
  border-left: 5px solid var(--accent-2);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  z-index: 80;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-left-color: var(--danger); }

/* ---------- Connecting overlay ---------- */
.connect-overlay {
  position: fixed; inset: 0;
  background: rgba(4,3,8,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.connect-overlay.show { opacity: 1; pointer-events: auto; }
.connect-overlay-box {
  display: flex; flex-direction: column; align-items: center; gap: 1.1rem;
  width: min(20rem, 80vw);
}
.connect-bar {
  width: 100%; height: 0.5rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  overflow: hidden;
}
.connect-bar-fill {
  height: 100%; width: 40%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(255,46,154,0.5);
  animation: connect-bar-slide 1.1s ease-in-out infinite;
}
@keyframes connect-bar-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
#connectOverlayText {
  margin: 0;
  color: var(--text); font-weight: 800; font-size: 0.95rem; letter-spacing: 0.03em;
  text-shadow: 0 2px 10px rgba(0,0,0,0.7);
}

/* ---------- Scrim ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(4,3,8,0.75);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------- Drawer ---------- */
.drawer {
  --hue: 200;
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(30rem, 92vw);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-left: 4px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,0.6);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 4px solid var(--line);
  background: linear-gradient(90deg, hsla(var(--hue), 70%, 50%, 0.18), transparent);
}
.drawer-head h2 { margin: 0; font-size: 1.6rem; font-weight: 900; display: flex; align-items: center; gap: 0.7rem; }
.drawer-title-icon {
  width: 2.2rem; height: 2.2rem; flex: 0 0 auto;
  color: hsl(var(--hue), 85%, 62%);
  filter: drop-shadow(0 0 6px hsla(var(--hue), 90%, 60%, 0.6));
}
.drawer-title-icon svg { width: 100%; height: 100%; display: block; }
.drawer-close {
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  background: var(--danger); border: none; color: white; font-size: 1.5rem; line-height: 1;
  font-weight: 900;
}

.drawer-body { padding: 1.1rem 1.2rem; overflow-y: auto; }

.field { margin-bottom: 1.1rem; }
.field-label { display: block; font-size: 1rem; letter-spacing: 0.07em; color: var(--text-dim); margin-bottom: 0.5rem; font-weight: 800; }

.effect-select {
  width: 100%;
  background: #0a0812;
  border: 3px solid var(--line);
  color: var(--text);
  padding: 0.8rem 0.9rem;
  border-radius: 10px;
  font-size: 1.2rem;
  font-weight: 700;
}
.effect-select:disabled { opacity: 0.5; }

.custom-select-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  cursor: pointer;
}
.custom-select-caret { color: var(--text-dim); font-size: 0.9rem; flex: 0 0 auto; transition: transform 0.15s; }
.custom-select-trigger.open .custom-select-caret { transform: rotate(180deg); }

.custom-select-menu {
  position: fixed;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 3px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  overflow-y: auto;
  z-index: 200;
  padding: 0.4rem;
}
.custom-select-option {
  width: 100%; display: block; text-align: left; white-space: nowrap;
  background: transparent; border: none; color: var(--text);
  padding: 0.65rem 0.7rem; border-radius: 8px; font-size: 1.05rem; font-weight: 700;
}
.custom-select-option:active { background: rgba(255,255,255,0.06); }
.custom-select-option.selected { background: rgba(52, 226, 255, 0.12); color: var(--accent-2); }

.toggle-field { display: flex; align-items: center; gap: 0.8rem; }
.switch { position: relative; width: 3.8rem; height: 2.1rem; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: #2b2640; border: 3px solid var(--line); border-radius: 999px; transition: 0.25s;
}
.switch-track::before {
  content: ''; position: absolute; width: 1.5rem; height: 1.5rem; left: 0.15rem; top: 0.15rem;
  background: #eee; border-radius: 50%; transition: 0.25s;
}
.switch input:checked + .switch-track { background: hsl(var(--hue), 80%, 45%); border-color: hsl(var(--hue), 80%, 60%); }
.switch input:checked + .switch-track::before { transform: translateX(1.65rem); }
.switch-text { font-weight: 900; font-size: 1.2rem; }

.drawer-hint {
  font-size: 1rem; color: var(--text-dim); font-weight: 700;
  background: rgba(255,255,255,0.03);
  border: 3px dashed var(--line);
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  display: none;
}

.knobs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 1.4rem 0.6rem;
  margin-top: 1.2rem;
}

.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.knob {
  --hue: inherit;
  width: 5.2rem; height: 5.2rem; border-radius: 50%;
  background: #0a0812;
  border: 4px solid #3a3550;
  position: relative;
  touch-action: none;
  outline: none;
}
.knob:focus-visible { box-shadow: 0 0 0 3px var(--accent-2); }
.knob.disabled { opacity: 0.35; touch-action: auto; }
.knob.dragging { box-shadow: 0 0 0 4px hsla(var(--hue), 80%, 60%, 0.4), 0 4px 10px rgba(0,0,0,0.5); }
.knob-arc {
  position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(from 225deg, hsl(var(--hue), 85%, 60%) 0deg, hsl(var(--hue), 85%, 60%) 270deg, transparent 270deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
  opacity: 0.8;
}
.knob-dial {
  position: absolute; inset: 0.55rem; border-radius: 50%;
  transition: transform 0.05s linear;
}
.knob-dial span {
  position: absolute; top: 6%; left: 50%; width: 5px; height: 32%;
  background: hsl(var(--hue), 90%, 70%);
  box-shadow: 0 0 6px hsl(var(--hue), 90%, 65%);
  transform: translateX(-50%);
  border-radius: 3px;
}
.tap-tempo { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.3rem; }
.tap-tempo-btn {
  background: #0a0812; border: 2px solid #3a3550; color: var(--text-dim);
  padding: 0.25rem 0.7rem; border-radius: 999px;
  font-weight: 900; font-size: 0.75rem; letter-spacing: 0.05em;
  transition: border-color 0.1s, color 0.1s, box-shadow 0.1s;
}
.tap-tempo-btn.pulse { border-color: var(--accent-2); color: var(--accent-2); box-shadow: 0 0 14px rgba(52,226,255,0.5); }
.tap-bpm { font-size: 0.78rem; font-weight: 700; color: var(--text-dim); font-family: 'Consolas', monospace; }

.knob-name { font-size: 0.95rem; font-weight: 800; color: var(--text); text-align: center; }
.knob-value {
  font-family: 'Consolas', monospace; font-size: 0.95rem; font-weight: 700; color: var(--accent-2);
  background: rgba(255,255,255,0.04); border: 2px solid rgba(255,255,255,0.08);
  padding: 0.1rem 0.6rem; border-radius: 999px;
  min-width: 2.4em; text-align: center;
}

/* Binary params (Trail, +3dB, Bright, Mode, ...) get a toggle switch instead of a knob;
   the fixed height matches the knob's footprint so it doesn't collapse the grid row. */
.toggle-param-wrap { justify-content: center; min-height: 5.2rem; }
.toggle-param-switch { width: 3.4rem; height: 1.9rem; }
.toggle-param-switch .switch-track::before { width: 1.35rem; height: 1.35rem; }
.toggle-param-switch input:checked + .switch-track::before { transform: translateX(1.45rem); }

/* ---------- Patch list modal ---------- */
.patch-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -48%) scale(0.96);
  width: min(30rem, 90vw); max-height: 78vh;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  z-index: 60;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.patch-modal.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.patch-modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--line);
}
.patch-modal-head h2 { margin: 0; font-size: 1rem; letter-spacing: 0.08em; flex: 1 0 auto; }
.patch-modal-body { overflow-y: auto; padding: 0.6rem; }
.patch-scan-status {
  margin: 0; padding: 0.5rem 1.2rem; font-size: 0.78rem; color: var(--text-dim);
  border-bottom: 1px solid var(--line);
}

.patch-row {
  width: 100%;
  display: flex; align-items: center; gap: 0.8rem;
  background: transparent; border: none; color: var(--text);
  padding: 0.65rem 0.7rem; border-radius: 10px; font-size: 0.9rem; text-align: left;
}
.patch-row:active { background: rgba(255,255,255,0.06); }
.patch-row.current { background: rgba(52, 226, 255, 0.12); color: var(--accent-2); font-weight: 700; }
.patch-row-num {
  font-family: 'Consolas', monospace; font-weight: 700; color: var(--text-dim);
  width: 2.2em; flex: 0 0 auto;
}
.patch-row.current .patch-row-num { color: var(--accent-2); }

/* ---------- Save-as modal ---------- */
/* Anchored near the top instead of vertically centered like .patch-modal, so the
   on-screen keyboard (which covers the bottom of the screen) never has to move or
   resize this modal -- it just sits still above where the keyboard shows up. */
.save-modal {
  top: 8vh;
  max-height: 80vh;
  transform: translateX(-50%) scale(0.96);
}
.save-modal.show { transform: translateX(-50%) scale(1); }
.save-modal-body { display: flex; flex-direction: column; gap: 1.1rem; }
.save-modal-input {
  width: 100%;
  background: #0a0812;
  border: 3px solid var(--line);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
}
.save-modal-input:focus { outline: none; border-color: var(--accent-2); }
.save-modal-confirm { align-self: stretch; padding: 0.8rem; font-size: 0.95rem; }

/* ---------- AI tone maker (natural-language preset generator) ---------- */
.tone-toggle { border-color: rgba(255,46,154,0.5); color: var(--accent); box-shadow: 0 0 12px rgba(255,46,154,0.2); }
.tone-toggle:active { transform: scale(0.96); }

.tone-screen {
  position: fixed; inset: 0;
  background: radial-gradient(1200px 700px at 15% -10%, #241a3a 0%, transparent 55%),
              radial-gradient(1000px 600px at 110% 10%, #1a2f3a 0%, transparent 50%),
              var(--bg-0);
  z-index: 90;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.tone-screen.show { transform: translateY(0); }

.tone-screen-head {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.9rem 1.2rem;
  background: linear-gradient(180deg, #171225, #0e0b18);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.tone-screen-head h1 {
  flex: 1; margin: 0; font-size: 1.1rem; font-weight: 900; letter-spacing: 0.05em; text-align: center;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tone-back-btn {
  background: #0a0812; border: 1.5px solid #3a3550; color: var(--text-dim);
  padding: 0.5rem 0.9rem; border-radius: 10px; font-weight: 800; font-size: 0.8rem;
}
.tone-screen-spacer { width: 4.6rem; flex: 0 0 auto; } /* balances the back button so the title stays centered */

.tone-screen-body { flex: 1; overflow-y: auto; padding: 1.2rem 1.4rem 2rem; max-width: 44rem; margin: 0 auto; width: 100%; }

.tone-conn-banner {
  background: rgba(255,77,94,0.12); border: 1.5px solid var(--danger); color: var(--danger);
  padding: 0.6rem 0.9rem; border-radius: 10px; font-size: 0.82rem; font-weight: 700; margin: 0 0 1rem;
}

.tone-intro { color: var(--text-dim); font-size: 0.88rem; line-height: 1.5; margin: 0 0 1rem; }

.tone-input {
  width: 100%; resize: vertical; min-height: 5rem;
  background: #0a0812; border: 3px solid var(--line); color: var(--text);
  padding: 0.9rem 1rem; border-radius: 12px; font-size: 1.05rem; font-family: inherit;
}
.tone-input:focus { outline: none; border-color: var(--accent-2); }

.tone-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.9rem 0; }
.tone-chip {
  background: var(--panel-2); border: 1.5px solid var(--line); color: var(--text-dim);
  padding: 0.45rem 0.8rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700;
}
.tone-chip:active { border-color: var(--accent-2); color: var(--accent-2); }

.tone-generate-btn {
  width: 100%; padding: 0.9rem; border-radius: 12px; border: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #0a0812;
  font-weight: 900; font-size: 1rem; letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(255,46,154,0.25);
}
.tone-generate-btn:active { transform: scale(0.98); }

.tone-import-row {
  display: flex; align-items: center; gap: 0.7rem; margin: 0.9rem 0 0.2rem;
}
.tone-import-divider {
  color: var(--text-dim); font-size: 0.75rem; font-weight: 700; flex: 0 0 auto;
}
.tone-import-btn {
  flex: 1 1 auto; text-align: center; cursor: pointer;
  padding: 0.7rem 0.9rem; border-radius: 12px; border: 1.5px dashed var(--line);
  color: var(--text-dim); font-weight: 700; font-size: 0.85rem;
}
.tone-import-btn:active { border-color: var(--accent-2); color: var(--accent-2); }

.tone-result { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.tone-result-head { margin-bottom: 1rem; }
.tone-result-tag {
  display: inline-block; background: rgba(52,226,255,0.12); color: var(--accent-2);
  padding: 0.3rem 0.8rem; border-radius: 999px; font-weight: 900; font-size: 0.85rem;
}
.tone-result-desc { color: var(--text); font-size: 0.92rem; line-height: 1.5; margin: 0.6rem 0 0; }

.tone-result-blocks { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.8rem; }
.tone-block-row {
  display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.5rem 0.7rem; font-size: 0.82rem; opacity: 0.55;
}
.tone-block-row.on { opacity: 1; border-color: rgba(52,226,255,0.3); }
.tone-block-name { font-weight: 900; color: var(--accent-2); min-width: 3em; }
.tone-block-detail { font-weight: 700; }
.tone-block-params { color: var(--text-dim); font-family: 'Consolas', monospace; font-size: 0.76rem; }

.tone-apply-hint { color: var(--text-dim); font-size: 0.78rem; margin: 0 0 0.8rem; min-height: 1em; }

.tone-apply-btn {
  width: 100%; padding: 0.9rem; border-radius: 12px; border: none;
  background: var(--ok); color: #06120c; font-weight: 900; font-size: 1rem;
}
.tone-apply-btn:active { transform: scale(0.98); }
.tone-apply-btn:disabled { opacity: 0.5; }

/* ---------- Narrow / portrait fallback ---------- */
@media (max-width: 820px), (max-height: 480px) {
  .pedalboard { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(2, 1fr); gap: 0.5rem; padding: 0.3rem 0.6rem 0.6rem; }
  .patch-strip { flex-wrap: wrap; padding: 0.5rem 0.6rem; }
  .master-vol { order: 10; width: 100%; }
  .topbar { padding: 0.5rem 0.8rem; }
}
