@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/DMMono-Medium.woff2') format('woff2');
}

:root {
  --bg: #080808;
  --surface: #0f0f0f;
  --border: #1e1e1e;
  --text: #b8b8b8;
  --muted: #5a5a5a;
  --accent: #b4ff00;
  --accent-glow: rgba(180,255,0,0.12);
  --key-white: #d0d0d0;
  --key-black: #0e0e0e;
  --panel-height: 300px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: var(--bg);
  font-family: 'DM Mono', monospace;
  overflow: hidden;
  color: var(--text);
}

/* ── Visualization Canvas ─────────────────────────────── */

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100vh - var(--panel-height));
  display: block;
}

/* ── Panel ────────────────────────────────────────────── */

.panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--panel-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

/* ── Keyboard Row ─────────────────────────────────────── */

.keyboard-row {
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px;
  height: 100px;
  flex-shrink: 0;
  overflow: hidden;
}

.keyboard {
  display: flex;
  align-items: flex-end;
  position: relative;
  height: 100px;
}

.white {
  background: var(--key-white);
  position: relative;
  width: 24px;
  height: 100px;
  border: 1px solid #666;
  border-top: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.05s;
}

.black {
  background: var(--key-black);
  position: absolute;
  width: 15px;
  height: 62px;
  top: 0;
  left: 15px;
  z-index: 2;
  border: 1px solid #222;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  transition: background 0.05s;
}

.playwhite {
  background: var(--accent) !important;
}

.playblack {
  background: var(--accent) !important;
}

.boardkey {
  font-size: 7px;
  color: #333;
  margin-bottom: 3px;
  letter-spacing: 0;
  user-select: none;
}

.black .boardkey {
  color: #ccc;
  font-size: 6px;
}

.playwhite > .boardkey,
.playblack > .boardkey {
  color: #000;
}

/* ── Controls Strip ───────────────────────────────────── */

.controls-strip {
  display: flex;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

.module {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.module:last-child {
  border-right: none;
}

.module-label {
  font-size: 8px;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 500;
}

/* ── Oscillator Modules ───────────────────────────────── */

.oscillator-controls {
  flex-direction: row;
  gap: 0;
  padding: 0;
}

.osc-module {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
}

.osc-module:last-child {
  border-right: none;
}

/* ── Wave Type Buttons ────────────────────────────────── */

.wave-grid {
  display: flex;
  gap: 4px;
}

.osc-module .wave-grid {
  margin-top: 6px;
  justify-content: space-between;
}

.osc-module .osctype {
  flex: 1;
  width: auto;
}

.osctype {
  cursor: pointer;
  width: 32px;
  height: 24px;
  border: 1px solid var(--muted);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.osctype svg {
  width: 20px;
  height: 10px;
}

.osctype:hover {
  border-color: #666;
  color: #666;
}

.osctype.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.osctype.dirty {
  border-color: #ff9900;
  color: #ff9900;
  background: rgba(255, 153, 0, 0.12);
}

/* ── Knob Row ─────────────────────────────────────────── */

.knob-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.knob-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.knob-group span {
  font-size: 8px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}

.knob-group canvas {
  cursor: ns-resize;
  display: block;
  touch-action: pan-x;
}

/* ── Envelope Module ──────────────────────────────────── */

.envelope {
  min-width: 160px;
}

/* ── LFO Section ──────────────────────────────────────── */

.lfo-section {
  flex-direction: row;
  gap: 0;
  padding: 0;
}

.lfo-group {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
}

.lfo-group:last-child {
  border-right: none;
}

/* ── Pitch Section (tune + glide + mono) ──────────────── */

.mono-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.12em;
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 2px 0;
  border-radius: 2px;
  width: 52px;
  margin-top: 4px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.mono-btn:hover {
  border-color: #666;
  color: #666;
}

.mono-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.mono-btn.dirty {
  border-color: #ff9900;
  color: #ff9900;
  background: rgba(255, 153, 0, 0.12);
}


/* ── Presets Section ──────────────────────────────────── */

.presets-section {
  flex: 1;
}

/* ── Preset Buttons ───────────────────────────────────── */

.preset-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.preset-row-builtin {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

.preset-row-user {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.preset {
  cursor: pointer;
  width: 28px;
  height: 28px;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 10px;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  user-select: none;
}

.preset:hover {
  border-color: #666;
  color: #888;
}

.preset.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.preset.dirty {
  border-color: #ff9900;
  color: #ff9900;
  background: rgba(255, 153, 0, 0.08);
}

/* ── User preset buttons ──────────────────────────────── */

.preset.user-preset {
  width: auto;
  min-width: 28px;
  padding: 0 6px;
  gap: 4px;
}

.preset-name-label {
  pointer-events: none;
  white-space: nowrap;
}

.preset-rename {
  display: none;
  font-size: 9px;
  opacity: 0.6;
  cursor: pointer;
  flex-shrink: 0;
}

.preset.user-preset:hover .preset-rename {
  display: inline;
}

.preset-delete {
  font-size: 11px;
  line-height: 1;
  opacity: 0.5;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.1s;
}

.preset-delete:hover {
  opacity: 1;
  color: #ff4444;
}

.preset-new {
  font-size: 14px;
  opacity: 0.5;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
}

.preset-new:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Preset action buttons ────────────────────────────── */

.preset-actions {
  display: flex;
  gap: 4px;
  margin-top: 5px;
}

.preset-save-btn,
.preset-reset-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.1em;
  background: none;
  border: 1px solid #ff9900;
  color: #ff9900;
  padding: 2px 6px;
  border-radius: 2px;
  transition: background 0.15s;
}

.preset-save-btn:hover {
  background: rgba(255, 153, 0, 0.15);
}

.preset-reset-btn {
  border-color: var(--muted);
  color: var(--muted);
}

.preset-reset-btn:hover {
  border-color: #888;
  color: #888;
}

/* ── Inline rename input ──────────────────────────────── */

.preset-name-input {
  width: 60px;
  background: #111;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: inherit;
  font-size: 9px;
  padding: 1px 3px;
  outline: none;
  border-radius: 1px;
}

/* ── Footer ───────────────────────────────────────────── */

footer {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.wordmark {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--text);
}

.byline {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-decoration: none;
  cursor: pointer;
}

.toggle-controls {
  cursor: pointer;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.12em;
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 2px;
  transition: border-color 0.15s, color 0.15s;
}

.toggle-controls:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Active/engaged state — same lime-fill treatment as the viz-mode pills.
   ROTATE uses this when auto-rotation is on; STUDIO uses it when studio
   mode is active. */
.toggle-controls.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.contact-link {
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.contact-link:hover {
  color: var(--text);
}

.midi-status {
  font-size: 8px;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-weight: 500;
}

/* ── Viz mode switcher (segmented control) ───────────── */

.viz-mode-group {
  display: inline-flex;
  gap: 4px;
}

.viz-seg {
  cursor: pointer;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.12em;
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 2px;
  min-width: 32px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.viz-seg:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.viz-seg.active {
  border-color: var(--accent);
  color: var(--bg);
  background: var(--accent);
}

/* ── Electron/web visibility ─────────────────────────── */

/* Shown on web only — hidden in the Electron desktop build. */
html.is-electron .electron-hide {
  display: none !important;
}

/* Shown in Electron only — hidden on the web build. `revert` restores
   the user-agent default display for the element (block for div,
   inline-block for button, etc.) so this class works on any tag. */
.electron-only {
  display: none !important;
}
html.is-electron .electron-only {
  display: revert !important;
}

/* ── Hide utility ─────────────────────────────────────── */

.hide {
  display: none !important;
}

/* ── Mobile ───────────────────────────────────────────── */

@media (pointer: coarse) {
  .boardkey {
    display: none;
  }
}

/* ── Compact layout for narrow viewports (most laptops) ─── */

@media (max-width: 1750px) {

  .knob {
    width: 44px;
    height: 44px;
  }

  .module,
  .osc-module,
  .lfo-group {
    padding: 8px 10px;
  }

  .knob-row {
    gap: 6px;
  }

  .module-label {
    margin-bottom: 6px;
  }

  .envelope {
    min-width: 0;
  }

  .envelope .knob-row,
  .vcf-section .knob-row {
    display: grid;
    grid-template-columns: repeat(2, auto);
    column-gap: 8px;
    row-gap: 4px;
  }

  .mono-btn {
    width: 44px;
  }
}

/* ── Custom confirm dialog ────────────────────────────── */

.sv-confirm {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.sv-confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 220px;
}

.sv-confirm-msg {
  font-size: 11px;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.sv-confirm-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.sv-confirm-ok,
.sv-confirm-cancel {
  cursor: pointer;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.12em;
  background: none;
  padding: 3px 10px;
  border-radius: 2px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sv-confirm-ok {
  border: 1px solid #ff4444;
  color: #ff4444;
}

.sv-confirm-ok:hover {
  background: rgba(255, 68, 68, 0.15);
}

.sv-confirm-cancel {
  border: 1px solid var(--muted);
  color: var(--muted);
}

.sv-confirm-cancel:hover {
  border-color: #888;
  color: #888;
}

/* ── Studio Mode ──────────────────────────────────────── */

/* Panel + canvas animate when --panel-height changes */
.panel {
  transition: height 250ms ease, opacity 250ms ease;
}

#canvas {
  transition: height 250ms ease;
}

body.studio-active {
  --panel-height: 0px;
}

body.studio-active .panel {
  opacity: 0;
  pointer-events: none;
}


/* HUD elements fade when mouse is idle (rec indicator stays full opacity during recording) */
body.studio-active.studio-idle .hud-btn,
body.studio-active.studio-idle .hud-hint,
body.studio-active.studio-idle .hud-divider {
  opacity: 0.15;
}

body.recording .hud-rec-indicator {
  opacity: 1 !important;
}

/* HUD button (clones .toggle-controls visual treatment) */
.hud-btn {
  background: none;
  border: 1px solid var(--muted);
  border-radius: 2px;
  color: var(--muted);
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, opacity 300ms ease;
}

.hud-btn:hover,
.hud-btn.active,
.hud-btn.flash {
  border-color: var(--accent);
  color: var(--accent);
}

.hud-btn svg {
  width: 12px;
  height: 12px;
  display: block;
}

.hud-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
  transition: opacity 300ms ease;
}

.hud-rec-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: opacity 300ms ease;
}

.hud-rec-indicator[hidden] {
  display: none;
}

.hud-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: studioPulse 1.2s ease-in-out infinite alternate;
}

@keyframes studioPulse {
  from { opacity: 0.4; }
  to   { opacity: 1; }
}

.hud-timer {
  font-family: inherit;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.hud-hint {
  font-family: inherit;
  font-size: 8px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: opacity 300ms ease;
}

/* Shutter flash for snapshot */
@keyframes snapshotFlash {
  0%   { opacity: 0; }
  30%  { opacity: 0.15; }
  100% { opacity: 0; }
}

body.snapshot-flash::after {
  content: '';
  position: fixed;
  inset: 0;
  background: #ffffff;
  pointer-events: none;
  z-index: 100;
  animation: snapshotFlash 120ms ease-out forwards;
}

/* Toast (e.g. "RECORDING UNAVAILABLE IN THIS BROWSER") */
.studio-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 2px;
  z-index: 60;
  animation: studioToast 3000ms ease-out forwards;
}

@keyframes studioToast {
  0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
  10%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  85%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Studio creative-controls panel (Electron only) ────── */

#studio-panel {
  position: fixed;
  /* Sits ABOVE the toolbar so the HUD's ▤ panel-toggle button stays clickable
     when the panel is open. 110px clears Row 1 (~50px tall + 24px bottom +
     gap); Row 2's transport/mic-strip is centered and right-aligned panel
     rarely overlaps it. */
  bottom: 110px;
  right: 24px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 14px 16px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#studio-panel[hidden] { display: none; }

body.studio-active #studio-panel:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

body.studio-active.studio-idle #studio-panel:not([hidden]) {
  opacity: 0.15;
}

.sp-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Master "RESET ALL" sits at the top of the panel — full-width pill that
   reads as the primary action above the per-section dials. */
.sp-section-master {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.sp-btn-master {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 7px 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  transition: background 120ms ease, color 120ms ease;
}
.sp-btn-master:hover {
  background: var(--accent);
  color: var(--bg);
}

.sp-section-label {
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.sp-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sp-btn {
  background: none;
  border: 1px solid var(--muted);
  border-radius: 2px;
  color: var(--muted);
  padding: 5px 9px;
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.sp-btn:hover,
.sp-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Segmented viz-mode picker inside the studio panel. The .active state
   fills with lime to match the footer switcher; non-active segments
   keep the standard sp-btn look. */
.sp-viz-group {
  display: inline-flex;
  gap: 4px;
}

.sp-viz-seg.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

/* Generic hide used by sp-btn buttons (rotate when not in 3D) and by
   sp-row containers (the SPEED slider row when rotation is off). */
.sp-hidden {
  display: none !important;
}

.sp-btn-sm {
  padding: 4px 7px;
  font-size: 8px;
}

.sp-slider-row {
  width: 100%;
}

.sp-slider {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  width: 100%;
}

.sp-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.sp-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.sp-slider-val {
  min-width: 38px;
  text-align: right;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* When background is transparent (null), show a checkerboard-style hint
   on the bg swatch so the user can see at a glance it's not painting. */
.sp-color.sp-transparent input[type="color"] {
  background:
    linear-gradient(45deg, var(--muted) 25%, transparent 25%, transparent 75%, var(--muted) 75%),
    linear-gradient(45deg, var(--muted) 25%, transparent 25%, transparent 75%, var(--muted) 75%);
  background-size: 6px 6px;
  background-position: 0 0, 3px 3px;
}

/* When the wave color is unset (null), the visualizer uses a per-note
   palette that drifts over time. Show a rainbow swatch so the user can
   tell at a glance they're in "dynamic" mode, not pinned to one color. */
.sp-color.sp-dynamic input[type="color"]::-webkit-color-swatch {
  background: linear-gradient(
    90deg,
    #ff2d2d 0%, #ffb02d 17%, #f6ff2d 34%, #2dff52 50%,
    #2dd4ff 67%, #6b2dff 84%, #ff2dd0 100%
  );
}

.sp-freeze.active {
  border-color: #ff9900;
  color: #ff9900;
}

.sp-hint {
  font-size: 8px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  opacity: 0.6;
}

.sp-color {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  cursor: pointer;
}

.sp-color input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.sp-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.sp-color input[type="color"]::-webkit-color-swatch { border: none; border-radius: 1px; }

.sp-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  cursor: pointer;
}

.sp-check input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* Shift+H blackout: hide ALL studio controls instantly (panel, floated
   viz-mode group). Lets the canvas stand on its own for screencaps /
   focused viewing. */
body.studio-hidden #studio-panel,
body.studio-hidden > .viz-mode-group,
body.studio-hidden > .rotate-toggle {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Frozen-key indicator on the keyboard */
[data-key].frozen {
  box-shadow: inset 0 0 0 2px #ff9900;
}
[data-key].black.frozen {
  box-shadow: inset 0 0 0 2px #ff9900, 0 1px 2px rgba(0,0,0,0.6);
}

/* Drag-drop target highlight on the visualizer canvas */
canvas.drag-target {
  outline: 2px dashed var(--accent, #b4ff00);
  outline-offset: -8px;
}

.studio-only { display: none; }
body.studio-active .studio-only { display: flex; }

/* Canvas stays full-viewport in studio (no top bars to push it down). */
body.studio-active #canvas {
  top: 0;
  height: 100vh;
}

/* ── Fade controls (independent synth + external viz alpha) ──────
   Compact horizontal sliders sit at the right end of the input bar.
   Both default to 100% (full opacity); pulling either down to 0
   fades that source's visualization out (the other stays full). */
#studio-fade-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
#studio-fade-controls .fade-label {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.6px;
}
#studio-fade-controls .fader {
  -webkit-appearance: none;
  appearance: none;
  width: 64px;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  outline: none;
  cursor: pointer;
  margin: 0;
}
#studio-fade-controls .fader::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
#studio-fade-controls .fader::-moz-range-thumb {
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}



/* ── Floated viz-mode group (studio mode) ─────────────────────
   .viz-mode-group normally lives in <footer> inside .panel, which is
   opacity:0 in studio mode. studio/index.ts reparents the group to
   <body> on studio enter so it escapes the opacity context. These
   styles apply only when the group is a direct child of <body>.

   Positioned at bottom: 24px, just to the RIGHT of #studio-hud
   (which is translateX(-50%)-centered) — forming a horizontal dock
   row: [INPUT] [HUD] [VIZ MODE]. */
body.studio-active > .viz-mode-group {
  position: fixed;
  bottom: 24px;
  left: calc(50% + 150px);
  right: auto;
  z-index: 50;
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0;
  /* overflow visible (was hidden): on Electron, the 4D button uses
     `display: revert` (from .electron-only) which combined with the flex
     parent + overflow:hidden could clip the rightmost segment in some
     layouts. Keep border-radius via the inner button corners instead. */
  overflow: visible;
  font-family: 'DM Mono', monospace;
  transition: opacity 200ms ease;
}
body.studio-active.studio-idle > .viz-mode-group {
  opacity: 0.15;
}
body.studio-active > .viz-mode-group:hover {
  opacity: 1;
}
body.studio-active > .viz-mode-group .viz-seg {
  /* Defensive: force inline-block on Electron's .electron-only 4D button —
     `display: revert !important` from the .electron-only rule sometimes
     resolves unexpectedly inside flex containers depending on UA. */
  display: inline-block;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 5px 11px;
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: color 120ms ease;
}
/* Belt and suspenders: explicitly show .electron-only segments inside the
   floated group on Electron. Overrides the .electron-only !important rule
   with a more specific selector (also !important) so the 4D button is
   guaranteed-visible regardless of viz mode. */
html.is-electron body.studio-active > .viz-mode-group .viz-seg.electron-only {
  display: inline-block !important;
}
body.studio-active > .viz-mode-group .viz-seg:hover {
  color: var(--accent);
}
body.studio-active > .viz-mode-group .viz-seg.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* Floated rotate-toggle (studio mode). Same escape-the-panel pattern as
   the viz-mode group. Sits in the dock row just RIGHT of the viz-mode
   pills.

   IMPORTANT: viz-mode-group spans roughly 50% + 150px → 50% + 245px
   (3 buttons × ~30px + paddings). ROTATE must start AFTER that range or
   it visually covers the 4D button when 3D is active (the only mode
   where ROTATE is exposed). The viz-mode-group also has overflow:visible
   now so trailing segments aren't clipped. */
body.studio-active > .rotate-toggle {
  position: fixed;
  bottom: 24px;
  left: calc(50% + 270px);
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--muted);
  padding: 5px 11px;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: opacity 200ms ease, color 120ms ease, border-color 120ms ease, background 120ms ease;
}
body.studio-active.studio-idle > .rotate-toggle {
  opacity: 0.15;
}
body.studio-active > .rotate-toggle:hover {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
}
body.studio-active > .rotate-toggle.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Unified studio toolbar ─────────────────────────────────────────────────
   One frame, two rows. Row 1 always visible in studio. Row 2 only when
   FILE or MIC is active; data-context drives which child is shown.
*/
#studio-toolbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 30;
  font-family: 'DM Mono', monospace;
  color: var(--text);
  /* Idle fade — match existing pattern. */
  opacity: 1;
  transition: opacity 200ms ease;
}
body.studio-active #studio-toolbar { display: flex; }
body.studio-idle  #studio-toolbar { opacity: 0.15; }
#studio-toolbar:hover { opacity: 1; }

body.studio-hidden #studio-toolbar { display: none; }

#studio-toolbar .toolbar-row {
  display: flex;
  align-items: center;
  flex-direction: row;
}
#studio-toolbar .toolbar-row-main {
  padding: 6px 12px;
  gap: 12px;
  min-height: 36px;
}
#studio-toolbar .toolbar-row-context {
  padding: 0;
  border-bottom: 1px solid var(--border);
  /* Hidden by default; shown only when data-context != "none" */
  display: none;
}
#studio-toolbar .toolbar-row-context[data-context="file"],
#studio-toolbar .toolbar-row-context[data-context="mic"] {
  display: flex;
  padding: 8px 12px;
  min-height: 40px;
}
#studio-toolbar .zone-context {
  flex: 1;
  display: flex;
  align-items: center;
}

#studio-toolbar .zone {
  display: flex;
  align-items: center;
  gap: 8px;
}
#studio-toolbar .zone-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  opacity: 0.6;
}

/* ── Toolbar Row 2 contexts ─────────────────────────────────────────────── */
#studio-toolbar .toolbar-row-context {
  flex-direction: column;
  align-items: stretch;
}
#studio-toolbar .zone-context .ctx-file,
#studio-toolbar .zone-context .ctx-mic { display: none; }
#studio-toolbar .toolbar-row-context[data-context="file"] .ctx-file {
  display: flex;
  flex-direction: column;
  width: 100%;
}
#studio-toolbar .toolbar-row-context[data-context="mic"]  .ctx-mic  {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
#studio-toolbar .toolbar-row-context .transport-wave {
  width: 100%;
  height: 32px;
  margin-bottom: 4px;
}
#studio-toolbar .toolbar-row-context .transport-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* Restored: was previously scoped to old dock IDs; now lives inside toolbar zones. */

/* ── zone-input (from #studio-input-bar children) ────────────────── */
#studio-toolbar .studio-bar-label {
  font-size: 9px;
  letter-spacing: 1.2px;
  color: var(--muted);
  padding-right: 8px;
  border-right: 1px solid var(--border);
}

#studio-toolbar .toggles {
  display: flex;
  gap: 4px;
}

#studio-toolbar .toggles button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
#studio-toolbar .toggles button:hover {
  color: var(--accent);
  border-color: var(--accent);
}
#studio-toolbar .toggles button.on {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

#studio-toolbar .file-name-display {
  color: var(--text);
  font-size: 10px;
  opacity: 0.7;
}

#studio-toolbar .hint {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 9px;
  color: var(--muted);
}

#studio-toolbar .spacer { flex: 1; }

/* ── ctx-file (from #studio-transport-bar children) ──────────────── */
#studio-toolbar .transport-wave {
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
#studio-toolbar .transport-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--text);
}
#studio-toolbar .transport-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
}
/* Scrub: 14px tall hit target, 2px visible track centered inside. The old
   2px-tall scrub was nearly impossible to click on Retina; this gives a
   comfortable click+drag area without making the visible track thicker. */
#studio-toolbar .scrub {
  flex: 1;
  height: 14px;
  background: transparent;
  position: relative;
  cursor: pointer;
}
#studio-toolbar .scrub::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  transform: translateY(-50%);
}
#studio-toolbar .scrub-fill {
  position: absolute;
  left: 0; top: 50%;
  height: 2px;
  width: 0%;
  background: var(--accent);
  border-radius: 1px;
  transform: translateY(-50%);
}
#studio-toolbar .scrub-thumb {
  position: absolute;
  left: 0; top: 50%;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
  pointer-events: none;  /* let the track receive the mouse, thumb just floats */
}
#studio-toolbar .pill {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 9px;
  letter-spacing: 0.5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  transition: color 120ms ease, border-color 120ms ease;
}
#studio-toolbar .pill:hover {
  color: var(--accent);
}
#studio-toolbar .pill.on {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── ctx-mic (from #studio-mic-strip children) ───────────────────── */
#studio-toolbar .level-meter {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
}
#studio-toolbar .level-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #fffba1);
  transition: width 60ms linear;
}
#studio-toolbar .mic-error {
  color: #ff7070;
  font-size: 9px;
}

/* ── Transport speed widget ───────────────────────────────────────── */
#studio-toolbar #transport-speed {
  font-family: 'DM Mono', monospace;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  cursor: ew-resize;
  user-select: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  min-width: 56px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.4px;
}
#studio-toolbar #transport-speed:hover { border-color: var(--accent); }
#studio-toolbar #transport-speed.dragging { color: var(--accent); border-color: var(--accent); }

/* ── Toolbar TARGET zone ──────────────────────────────────────────────────
   Three letter pills [M][S][E] that select the active source for drag-
   rotate and wheel-zoom gestures. Active pill: lime fill.
*/
#studio-toolbar .zone-target .target-group {
  display: inline-flex;
  gap: 4px;
}
#studio-toolbar .target-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 2px;
  cursor: pointer;
  min-width: 24px;
  transition: border-color 120ms, color 120ms, background 120ms;
}
#studio-toolbar .target-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#studio-toolbar .target-pill.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ── Controls-panel tab strip ─────────────────────────────────────────── */
#studio-panel .sp-tab-strip {
  display: flex;
  gap: 4px;
  margin: 6px 0 10px;
}
#studio-panel .sp-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 2px;
  cursor: pointer;
  transition: border-color 120ms, color 120ms, background 120ms;
}
#studio-panel .sp-tab:hover { border-color: var(--accent); color: var(--accent); }
#studio-panel .sp-tab.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ── Override pills (per-row on SYNTH/EXTERNAL tabs) ─────────────────── */
#studio-panel .sp-override-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 2px;
  cursor: pointer;
  margin-right: 6px;
  min-width: 56px;
  text-align: center;
}
#studio-panel .sp-override-pill:hover { border-color: var(--accent); color: var(--accent); }
#studio-panel .sp-override-pill.on {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Grey-out a row's control(s) when override is OFF (master in effect) */
#studio-panel .sp-row.sp-row-master input,
#studio-panel .sp-row.sp-row-master .sp-btn,
#studio-panel .sp-row.sp-row-master .sp-slider {
  opacity: 0.45;
  pointer-events: none;
}
