/* Fonts (see /assets/fonts/LICENSE.txt): Fira Code for code, with its
   ligatures, and IBM Plex Mono for the rest of the interface */
@font-face {
  font-family: "Fira Code";
  src: url("/assets/fonts/fira-code-latin-wght.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Fira Code";
  src: url("/assets/fonts/fira-code-latin-ext-wght.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
    U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
    U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono-latin-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono-latin-600.woff2") format("woff2");
  font-weight: 600 700;
  font-display: swap;
}

/* Theme-independent tokens */
:root {
  --font-ui: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-code: "Fira Code", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --panel-radius: 6px;
}

/* Global scrollbar styling */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
  background-color: transparent;
}

::-webkit-scrollbar-track {
  background-color: var(--color-bg-editor);
  border-radius: 6px;
}

::-webkit-scrollbar-track:horizontal {
  margin: 0 6px;
  /* Add some margin to prevent overlap with vertical scrollbar */
}

::-webkit-scrollbar-track:vertical {
  margin: 6px 0;
  /* Add some margin to prevent overlap with horizontal scrollbar */
}

::-webkit-scrollbar-thumb {
  background-color: var(--color-button-bg);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-button-hover);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-corner {
  background-color: var(--color-bg-editor);
}

/* Firefox global scrollbar styling */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-button-bg) var(--color-bg-editor);
}

/* Global visibility transitions */
*[style*="visibility"] {
  transition: visibility 0.2s ease, opacity 0.2s ease;
}

*[style*="visibility: hidden"] {
  opacity: 0;
}

*[style*="visibility: visible"] {
  opacity: 1;
}

/* Theme Variables - Default (Dark Dracula-inspired) */
:root {
  /* Base colors */
  --color-bg-primary: #1e1e1e;
  --color-bg-secondary: rgba(37, 37, 37, 0.9);
  --color-bg-secondary-rgb: 37, 37, 37;
  /* RGB values for opacity control */
  --color-bg-tertiary: rgba(60, 60, 60, 0.7);
  --color-bg-tertiary-rgb: 60, 60, 60;
  /* RGB values for opacity control */
  --color-bg-editor: rgba(40, 42, 54, 0.7);
  --color-bg-editor-rgb: 40, 42, 54;
  /* RGB values for opacity control */
  --color-text-primary: #f5f5f5;
  --color-text-secondary: #aaa;
  --color-text-editor: #f8f8f2;
  --panel-opacity: 0.9;
  /* Default panel opacity */

  /* Behind the code for a moment when it runs: the logo's violet */
  --color-flash: rgba(144, 0, 255, 0.85);

  /* UI Elements */
  --color-button-bg: #2d2d2d;
  --color-button-hover: #3d3d3d;
  --color-button-active: #4d4d4d;
  --color-panel-shadow: rgba(0, 0, 0, 0.3);
  --color-panel-blur: 5px;

  /* Notifications */
  --color-success: rgba(60, 180, 100, 0.8);
  --color-error: rgba(220, 50, 50, 0.85);

  /* Performance indicators */
  --color-perf-good: rgb(100, 255, 100);
  --color-perf-medium: rgb(255, 200, 0);
  --color-perf-poor: rgb(255, 100, 100);

  /* Optional, for light themes (the dark ones leave them unset and keep
     the fallbacks where they are used):
     --color-accent / --color-on-accent: checked boxes and slider fills
     --color-stat-value: the system panel's numbers (white)
     --color-contrast-rgb: bank dots, icons and pads drawn in white
     --color-midi-active / --color-midi-idle: the MIDI status line */
}

/* Light Theme: ink on white, with the violet of the logo as its accent */
.theme-light {
  /* Base colors */
  --color-bg-primary: #f3f2f7;
  --color-bg-secondary: rgba(250, 249, 252, 0.94);
  --color-bg-secondary-rgb: 250, 249, 252;
  /* RGB values for opacity control */
  --color-bg-tertiary: rgba(236, 234, 242, 0.96);
  --color-bg-tertiary-rgb: 236, 234, 242;
  /* RGB values for opacity control */
  --color-bg-editor: rgba(255, 255, 255, 0.7);
  --color-bg-editor-rgb: 255, 255, 255;
  /* RGB values for opacity control */
  --color-text-primary: #1c1a24;
  --color-text-secondary: #6a6679;
  --color-text-editor: #1c1a24;

  /* UI Elements */
  --color-button-bg: #dcd8e7;
  --color-button-hover: #d0cbdf;
  --color-button-active: #c3bdd5;
  --color-panel-shadow: rgba(28, 20, 60, 0.2);
  --color-panel-blur: 8px;
  --color-accent: #6d28d9;
  --color-on-accent: #ffffff;
  --color-flash: rgba(109, 40, 217, 0.3);
  --color-stat-value: #1c1a24;
  --color-contrast-rgb: 28, 26, 36;
  --color-midi-active: #15803d;
  --color-midi-idle: #6a6679;

  /* Notifications */
  --color-success: rgba(21, 128, 61, 0.95);
  --color-error: rgba(220, 38, 38, 0.95);

  /* Performance indicators */
  --color-perf-good: #15803d;
  --color-perf-medium: #b45309;
  --color-perf-poor: #dc2626;

}

/* Dark Theme (High Contrast) */
.theme-dark {
  /* Base colors */
  --color-bg-primary: #121212;
  --color-bg-secondary: rgba(25, 25, 25, 0.9);
  --color-bg-secondary-rgb: 25, 25, 25;
  /* RGB values for opacity control */
  --color-bg-tertiary: rgba(35, 35, 35, 0.8);
  --color-bg-tertiary-rgb: 35, 35, 35;
  /* RGB values for opacity control */
  --color-bg-editor: rgba(18, 18, 18, 0.9);
  --color-bg-editor-rgb: 18, 18, 18;
  /* RGB values for opacity control */
  --color-text-primary: #ffffff;
  --color-text-secondary: #cccccc;
  --color-text-editor: #ffffff;
  --color-flash: rgba(0, 255, 83, 0.35);

  /* UI Elements */
  --color-button-bg: #1e1e1e;
  --color-button-hover: #2a2a2a;
  --color-button-active: #333333;
  --color-panel-shadow: rgba(0, 0, 0, 0.5);
  --color-panel-blur: 5px;

  /* Notifications */
  --color-success: rgba(0, 200, 83, 1);
  --color-error: rgba(255, 50, 50, 1);

  /* Performance indicators */
  --color-perf-good: rgb(0, 255, 83);
  --color-perf-medium: rgb(255, 200, 0);
  --color-perf-poor: rgb(255, 50, 50);

}

/* Neon Eighties Theme */
.theme-neon-eighties {
  /* Base colors */
  --color-bg-primary: #0b0b2b;
  --color-bg-secondary: rgba(30, 30, 60, 0.9);
  --color-bg-secondary-rgb: 30, 30, 60;
  /* RGB values for opacity control */
  --color-bg-tertiary: rgba(45, 45, 80, 0.8);
  --color-bg-tertiary-rgb: 45, 45, 80;
  /* RGB values for opacity control */
  --color-bg-editor: rgba(20, 20, 40, 0.85);
  --color-bg-editor-rgb: 20, 20, 40;
  /* RGB values for opacity control */
  --color-text-primary: #ff00ff;
  --color-text-secondary: #00ffff;
  --color-text-editor: #ffffff;
  --color-flash: rgba(255, 0, 255, 0.5);

  /* UI Elements */
  --color-button-bg: #6600cc;
  --color-button-hover: #8800ee;
  --color-button-active: #aa00ff;
  --color-panel-shadow: rgba(255, 0, 255, 0.3);
  --color-panel-blur: 8px;

  /* Notifications */
  --color-success: rgba(0, 255, 180, 0.9);
  --color-error: rgba(255, 50, 150, 0.9);

  /* Performance indicators */
  --color-perf-good: rgb(0, 255, 180);
  --color-perf-medium: rgb(255, 255, 0);
  --color-perf-poor: rgb(255, 0, 128);

}

/* Nineties Pop Theme: Memphis style, cream panels with black outlines and
   hard shadows, sunny title bars, hot pink and teal (more at the end) */
.theme-nineties-pop {
  /* Base colors */
  --color-bg-primary: #fff3d6;
  --color-bg-secondary: rgba(255, 248, 231, 0.95);
  --color-bg-secondary-rgb: 255, 248, 231;
  /* RGB values for opacity control */
  --color-bg-tertiary: rgba(255, 214, 10, 0.96);
  --color-bg-tertiary-rgb: 255, 214, 10;
  /* RGB values for opacity control */
  --color-bg-editor: rgba(255, 255, 255, 0.6);
  --color-bg-editor-rgb: 255, 255, 255;
  /* RGB values for opacity control */
  --color-text-primary: #1a1423;
  --color-text-secondary: #5a3d70;
  --color-text-editor: #1a1423;

  /* UI Elements */
  --color-button-bg: #00c2b8;
  --color-button-hover: #2edad0;
  --color-button-active: #00a39a;
  --color-panel-shadow: rgba(26, 20, 35, 0.35);
  --color-panel-blur: 5px;
  --color-accent: #ff3d9a;
  --color-on-accent: #1a1423;
  --color-flash: rgba(255, 61, 154, 0.45);
  --color-stat-value: #1a1423;
  --color-contrast-rgb: 26, 20, 35;
  --color-midi-active: #007c80;
  --color-midi-idle: #5a3d70;
  --pop-ink: #1a1423;

  /* Notifications */
  --color-success: rgba(0, 150, 140, 0.96);
  --color-error: rgba(230, 20, 100, 0.96);

  /* Performance indicators */
  --color-perf-good: #008f7a;
  --color-perf-medium: #c77700;
  --color-perf-poor: #e0115f;

}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-ui);
  font-size: 12px;
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Form controls don't inherit the page font by default */
button,
input,
select,
textarea {
  font-family: inherit;
}

.app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.shortcut {
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: 400;
}

/* Fullscreen Hydra canvas */
.preview-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #000;
  z-index: 1;
}

/* Draggable editor modal */
.editor-container {
  position: absolute;
  top: 20px;
  left: 20px;
  /* Narrower on narrow screens (an iPad in portrait), clear of the system panel */
  width: min(680px, calc(100vw - 260px));
  height: 500px;
  background-color: rgba(var(--color-bg-secondary-rgb), var(--panel-opacity)) !important;
  border-radius: var(--panel-radius);
  z-index: 100;
  box-shadow: 0 4px 15px var(--color-panel-shadow);
  /* backdrop-filter: blur(var(--color-panel-blur)); */
  display: flex;
  flex-direction: column;
  min-width: 400px;
  min-height: 200px;
  resize: both;
}

.editor-content {
  /* CodeMirror scrolls its own code, so the cursor stays in view and the
     suggestions and the parameter hint show wherever it is */
  overflow: hidden;
  flex-grow: 1;
}

/* Resize grip in a panel's bottom-right corner. The doc panel resizes by it;
   the editor has CSS resize, and shows its grip only on touch screens (below),
   which draw no handle for CSS resize. */
.resize-grip {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  z-index: 5;
}

.editor-resize-grip {
  display: none;
}

/* Hydra Editor Styles */
.hydra-editor {
  width: 100%;
  height: 100%;
  flex: 1;
  background-color: var(--color-bg-editor);
  color: var(--color-text-editor);
  font-family: var(--font-code);
  font-size: 14px;
  padding: 8px;
  border: none;
  outline: none;
  resize: none;
  line-height: 1.4;
  letter-spacing: 0.5px;
  overflow: auto;
  caret-color: #ffffff;
}

/* Syntax Highlight Editor Container */
.hydra-editor-container {
  width: 100%;
  height: 100%;
  flex: 1;
  position: relative;
  overflow: visible !important;
}

/* Pre element for syntax highlighting */
.hydra-editor-pre {
  margin: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-bg-editor);
  color: var(--color-text-editor);
  font-family: var(--font-code);
  font-size: 14px;
  padding: 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: visible;
  outline: none;
  box-sizing: border-box;
  tab-size: 2;
  line-height: 1.5;
}

/* CodeMirror Editor Styles */
.cm-editor {
  background-color: transparent !important;
  height: 100%;
}

.cm-editor .cm-scroller {
  background-color: transparent !important;
}

.cm-editor .cm-content {
  background-color: transparent !important;
}

.cm-editor .cm-line {
  background-color: transparent !important;
}

/* Ensure CodeMirror sits properly in the container */
.editor-content .cm-editor {
  width: 100%;
  height: 100%;
}

/* Desktop app: images and videos dragged over the editor (DesktopMediaPlugin) */
.editor-content .cm-editor.cm-file-drop-target {
  outline: 2px dashed var(--color-accent, var(--color-perf-good));
  outline-offset: -4px;
}

/* The run flash (src/utils/runFlash.js): the theme's flash colour behind
   the code that just ran */
.cm-editor .cm-run-flash {
  background-color: var(--color-flash);
}

.cm-tooltip {
  z-index: 1001 !important;
  /* Ensure it's on top of other UI elements */
}

/* Title bar: the name, the Sketch and Setup tabs, and the hide button */
.editor-handle {
  height: 24px;
  background-color: rgba(var(--color-bg-tertiary-rgb), var(--panel-opacity));
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 0 3px 0 8px;
  cursor: move;
  flex-shrink: 0;
}

.editor-tabs {
  display: flex;
  flex: 1;
  min-width: 0;
}

.editor-tab {
  padding: 2px 8px 0;
  font-size: 11px;
  background-color: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.editor-tab:hover,
.editor-tab:active {
  background-color: transparent;
  color: var(--color-text-primary);
  transform: none;
}

.editor-tab.active {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-text-primary);
}

.editor-handle-title {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.editor-handle-controls {
  display: flex;
  align-items: center;
}

.editor-handle-controls button {
  background-color: transparent;
  padding: 1px 5px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-text-secondary);
  opacity: 0.7;
}

.editor-handle-controls button:hover {
  background-color: rgba(var(--color-bg-tertiary-rgb), 0.8);
  opacity: 1;
  transform: none;
  color: var(--color-text-primary);
  border-color: var(--color-text-primary);
}

/* Editable div for input */
.hydra-editor-editable {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  color: transparent;
  font-family: var(--font-code);
  font-size: 14px;
  padding: 8px;
  margin: 0;
  caret-color: #f8f8f2;
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-sizing: border-box;
  tab-size: 2;
  line-height: 1.5;
  z-index: 1;
}

/* Ensure content area takes available space */
.editor-content {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

button {
  background-color: var(--color-button-bg);
  color: var(--color-text-primary);
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

button:hover {
  background-color: var(--color-button-hover);
  transform: translateY(-1px);
}

button:active {
  background-color: var(--color-button-active);
  transform: translateY(1px);
}

/* Dropdowns (the breakout window size), with a chevron in the text color */
select {
  appearance: none;
  -webkit-appearance: none;
  padding: 2px 20px 2px 6px;
  border: none;
  border-radius: 4px;
  background-color: var(--color-button-bg);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%),
    linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 10px) 55%, calc(100% - 6px) 55%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
  color: var(--color-text-primary);
  font-size: 11px;
  cursor: pointer;
}

select:hover {
  background-color: var(--color-button-hover);
}

select:focus-visible {
  outline: 1px solid var(--color-text-secondary);
  outline-offset: 1px;
}

select option {
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
}

/* Saved notification */
.saved-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: var(--color-success);
  color: white;
  padding: 6px 12px;
  border-radius: var(--panel-radius);
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transition: opacity 0.5s;
}

.saved-notification.fade-out {
  opacity: 0;
}

/* A few choices to pick from, in place of window.prompt (core/choiceDialog.js) */
.choice-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-color: rgba(0, 0, 0, 0.45);
}

.choice-dialog {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(340px, 100%);
  padding: 12px;
  border-radius: var(--panel-radius);
  background-color: var(--color-bg-secondary);
  backdrop-filter: blur(var(--color-panel-blur));
  box-shadow: 0 4px 16px var(--color-panel-shadow);
  color: var(--color-text-primary);
  font-family: var(--font-ui);
}

.choice-dialog-title {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
}

.choice-dialog-option,
.choice-dialog-cancel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 7px 10px;
  text-align: left;
  font-family: inherit;
}

.choice-dialog-label {
  font-size: 12px;
  font-weight: 600;
}

.choice-dialog-danger .choice-dialog-label {
  color: var(--color-error);
}

.choice-dialog-detail {
  font-size: 11px;
  color: var(--color-text-secondary);
}

.choice-dialog-cancel {
  align-items: center;
  margin-top: 4px;
  background-color: transparent;
}

/* Error notification */
.error-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: var(--color-error);
  color: white;
  padding: 8px 12px;
  border-radius: var(--panel-radius);
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-width: 500px;
  word-break: break-word;
  transition: opacity 0.5s, transform 0.3s;
  cursor: pointer;
}

.error-notification.fade-out {
  opacity: 0;
  transform: translateY(10px);
}

.error-notification .error-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.error-notification .error-message {
  font-size: 12px;
  opacity: 0.9;
  max-height: 150px;
  overflow-y: auto;
}

/* Hide UI elements properly */
.ui-hidden .editor-container,
.ui-hidden .stats-panel,
.ui-hidden .slots-panel,
.ui-hidden .doc-panel,
.ui-hidden .tempo-panel {
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Stats Panel */
.dragging {
  opacity: 0.9;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5) !important;
}

/* Slots Panel: its width sets the size of the (square) slots, and it
   resizes by the grip in its corner */
.slots-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
}

.slots-resize-grip {
  width: 12px;
  height: 12px;
  background: linear-gradient(135deg,
      transparent 52%,
      var(--color-text-secondary) 52% 60%,
      transparent 60% 72%,
      var(--color-text-secondary) 72% 80%,
      transparent 80%);
  opacity: 0.7;
}

.slots-resize-grip:hover {
  opacity: 1;
}

.slot {
  transition: all 0.2s ease;
}

.slot:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}



/* Documentation Panel: the functions as a tree on the left, the picked one
   on the right with its examples and their preview (src/DocPanel.js) */
.doc-panel {
  position: absolute;
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 12px;
  color: var(--color-text-primary);
  background-color: rgba(var(--color-bg-secondary-rgb), var(--panel-opacity)) !important;
  border-radius: var(--panel-radius);
  box-shadow: 0 4px 15px var(--color-panel-shadow);
  backdrop-filter: blur(var(--color-panel-blur));
}

.doc-handle {
  height: 24px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 3px 0 8px;
  background-color: rgba(var(--color-bg-tertiary-rgb), var(--panel-opacity));
  cursor: move;
  user-select: none;
}

.doc-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
}

.doc-keys {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
}

.doc-close {
  background: none;
  border: none;
  padding: 0 6px;
  font-size: 16px;
  line-height: 1;
  color: var(--color-text-primary);
  cursor: pointer;
}

.doc-close:hover {
  background: none;
  transform: none;
}

.doc-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.doc-side {
  width: 180px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(var(--color-bg-tertiary-rgb), 0.9);
}

.doc-filter {
  margin: 6px;
  padding: 4px 6px;
  font: 12px var(--font-code);
  color: var(--color-text-primary);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(var(--color-bg-tertiary-rgb), 1);
  border-radius: 3px;
}

.doc-filter:focus {
  outline: none;
  border-color: var(--color-accent, #9000ff);
}

.doc-tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 6px;
  font-family: var(--font-code);
}

.doc-tree button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.doc-tree button:hover {
  background: rgba(var(--color-contrast-rgb, 255, 255, 255), 0.07);
  transform: none;
}

.doc-tree button:focus-visible {
  outline: 1px solid var(--color-accent, #9000ff);
  outline-offset: -1px;
}

.doc-cat {
  padding: 4px 8px;
  font-weight: 600;
}

.doc-fold {
  width: 8px;
  color: var(--color-text-secondary);
}

.doc-swatch {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 2px;
}

.doc-count {
  margin-left: auto;
  font-weight: 400;
  color: var(--color-text-secondary);
}

.doc-fn {
  padding: 2px 8px 2px 36px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.doc-tree .doc-fn.selected {
  color: var(--color-text-primary);
  background: rgba(144, 0, 255, 0.28);
  box-shadow: inset 2px 0 var(--color-accent, #9000ff);
}

.doc-empty {
  padding: 12px;
  color: var(--color-text-secondary);
}

.doc-detail {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 8px 12px 12px;
  container-type: inline-size;
}

.doc-crumb {
  font: 11px var(--font-code);
  color: var(--color-text-secondary);
}

.doc-signature {
  margin: 2px 0 4px;
  font: 600 15px var(--font-code);
  overflow-wrap: anywhere;
  border-left: 3px solid var(--doc-category);
  padding-left: 6px;
}

.doc-sig-prefix,
.doc-sig-args {
  color: var(--color-text-secondary);
  font-weight: 400;
}

.doc-description {
  margin: 6px 0 8px;
  font-size: 13px;
  line-height: 1.45;
  max-width: 70ch;
}

.doc-params {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  gap: 3px 12px;
  margin-bottom: 4px;
  font: 12px var(--font-code);
}

.doc-param-name {
  font-weight: 600;
}

.doc-param-default {
  color: var(--color-text-secondary);
}

.doc-param-text {
  font-family: var(--font-ui, inherit);
  color: var(--color-text-secondary);
}

.doc-section {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.doc-examples-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.doc-examples {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* The preview goes beside the examples once there is room, above them before,
   small enough to leave the first example in view */
.doc-preview {
  order: -1;
  width: min(100%, 240px);
}

@container (min-width: 520px) {
  .doc-examples-layout {
    grid-template-columns: minmax(0, 1fr) 200px;
    align-items: start;
  }

  .doc-preview {
    order: 0;
    width: auto;
    position: sticky;
    top: 0;
  }
}

.doc-preview-frame {
  aspect-ratio: 16 / 9;
  max-width: 320px;
  background: #000;
  border: 1px solid rgba(var(--color-bg-tertiary-rgb), 1);
}

.doc-preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.doc-preview-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  margin-top: 4px;
  font: 11px var(--font-code);
  color: var(--color-text-secondary);
}

.doc-preview-caption {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.doc-preview-caption.error {
  color: var(--color-error);
}

.doc-preview-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.doc-example {
  border: 1px solid rgba(var(--color-bg-tertiary-rgb), 1);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.doc-example.running {
  border-color: var(--color-accent, #9000ff);
}

.doc-example-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 4px 4px 4px 8px;
}

.doc-example-title {
  font-weight: 600;
}

/* What an example needs before it can show (a camera, a screen…): a tag that
   lights up red when a click couldn't start it, and holds the reason when
   run failed */
.doc-example-needs {
  padding: 0 6px;
  font-size: 11px;
  line-height: 16px;
  color: var(--color-text-primary);
  border: 1px solid var(--color-text-secondary);
  border-radius: 8px;
}

.doc-example-needs.alert,
.doc-example-needs.error {
  color: #fff;
  background: var(--color-error);
  border-color: var(--color-error);
}

.doc-example-needs.alert {
  animation: doc-needs-nudge 0.4s ease;
}

@keyframes doc-needs-nudge {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-3px);
  }

  75% {
    transform: translateX(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .doc-example-needs.alert {
    animation: none;
  }
}

.doc-example-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.doc-action {
  display: flex;
  align-items: center;
  padding: 1px 6px;
  font: 11px var(--font-code);
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid rgba(var(--color-bg-tertiary-rgb), 1);
  border-radius: 3px;
  cursor: pointer;
}

.doc-action:hover {
  color: var(--color-text-primary);
  border-color: var(--color-text-secondary);
  background: transparent;
  transform: none;
}

.doc-action.done {
  color: var(--color-text-primary);
  border-color: var(--color-success);
}

.doc-example-code {
  margin: 0;
  padding: 6px 8px;
  font: 12px/1.5 var(--font-code);
  /* Fira Code would draw => as one arrow: show what to type (after the
     font shorthand, which resets it) */
  font-variant-ligatures: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(0, 0, 0, 0.2);
  cursor: text;
  user-select: text;
}

.doc-see-also {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 12px;
  font: 12px var(--font-code);
  color: var(--color-text-secondary);
}

.doc-link {
  padding: 0;
  font: inherit;
  color: var(--color-text-primary);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.doc-link:hover {
  background: none;
  transform: none;
}

@container (max-width: 360px) {
  .doc-params {
    grid-template-columns: max-content minmax(0, 1fr);
  }

  .doc-param-text {
    grid-column: 1 / -1;
    margin-bottom: 4px;
  }
}

/* The docs button in the editor's title bar */
.editor-handle-controls {
  gap: 4px;
}

.editor-handle-controls #docs-btn {
  gap: 4px;
  color: var(--color-text-primary);
  opacity: 0.85;
}

.editor-handle-controls #docs-btn.open {
  border-color: var(--color-accent, #9000ff);
  background-color: rgba(144, 0, 255, 0.28);
  opacity: 1;
}

/* Editor footer with buttons */
.editor-footer {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 3px 0 8px;
  background-color: rgba(var(--color-bg-tertiary-rgb), var(--panel-opacity));
  flex-shrink: 0;
}

.editor-footer-left {
  display: flex;
  align-items: center;
}

.editor-footer-right {
  display: flex;
  align-items: center;
  gap: 3px;
}

.editor-footer button {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 4px;
}

.checkbox-container {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 11px;
}

.checkbox-container span {
  user-select: none;
}

.slot-index {
  color: white;
  mix-blend-mode: difference;
  vertical-align: middle;
}

/* Custom form elements styling */
/* Checkboxes */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin: 0;
  flex: none;
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-text-secondary);
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

input[type="checkbox"]:checked {
  background-color: var(--color-accent, var(--color-perf-good));
  border-color: var(--color-accent, var(--color-perf-good));
}

input[type="checkbox"]:checked::after {
  content: "✓";
  color: var(--color-on-accent, var(--color-bg-primary));
  font-size: 10px;
  font-weight: 600;
}

input[type="checkbox"]:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(var(--color-bg-secondary-rgb), 0.5);
}

/* Range sliders */
input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 16px;
  background-color: transparent;
  border-radius: 4px;
  outline: none;
  overflow: hidden;
  margin: 4px 0;
}

/* Filled part of the slider track */
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right,
      var(--color-accent, var(--color-text-secondary)) var(--range-progress, 0%),
      var(--color-bg-tertiary) var(--range-progress, 0%));
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--color-bg-tertiary);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background-color: var(--color-text-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  margin-top: -4px;
  /* Centers the thumb on the track */
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background-color: var(--color-text-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background-color: var(--color-accent, var(--color-perf-good));
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

input[type="range"]::-moz-range-thumb:hover {
  background-color: var(--color-accent, var(--color-perf-good));
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
}

input[type="range"]:active::-moz-range-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
}

.theme-neon-eighties input[type="range"]::-webkit-slider-thumb {
  background-color: var(--color-text-secondary);
}

.theme-neon-eighties input[type="checkbox"]:checked {
  background-color: var(--color-text-primary);
}

/* Light: a hairline around each panel, which bright visuals would swallow */
.theme-light .editor-container,
.theme-light .stats-panel,
.theme-light .slots-panel,
.theme-light .xy-pad-panel,
.theme-light .tempo-panel,
.theme-light .doc-panel,
.theme-light .info-panel,
.theme-light .choice-dialog {
  outline: 1px solid rgba(28, 20, 60, 0.12);
}

/* Pop 90s: black outlines, hard shadows and outlined title bars */
.theme-nineties-pop .editor-container,
.theme-nineties-pop .stats-panel,
.theme-nineties-pop .slots-panel,
.theme-nineties-pop .xy-pad-panel,
.theme-nineties-pop .tempo-panel,
.theme-nineties-pop .doc-panel,
.theme-nineties-pop .info-panel,
.theme-nineties-pop .choice-dialog {
  outline: 2px solid var(--pop-ink);
  box-shadow: 6px 6px 0 var(--pop-ink) !important;
}

.theme-nineties-pop .editor-handle,
.theme-nineties-pop .stats-handle,
.theme-nineties-pop .xy-pad-handle,
.theme-nineties-pop .tempo-handle,
.theme-nineties-pop .doc-handle,
.theme-nineties-pop .info-panel-header {
  box-shadow: inset 0 -2px 0 var(--pop-ink);
}

.theme-nineties-pop .slots-handle {
  box-shadow: inset 0 0 0 2px var(--pop-ink);
}

.theme-nineties-pop .editor-footer {
  box-shadow: inset 0 2px 0 var(--pop-ink);
}

.theme-nineties-pop .editor-tab.active {
  background-color: var(--color-accent);
  border-bottom-color: transparent;
  box-shadow: inset 2px 0 0 var(--pop-ink), inset -2px 0 0 var(--pop-ink);
}

.theme-nineties-pop input[type="checkbox"] {
  border: 2px solid var(--pop-ink);
}

.theme-nineties-pop input[type="range"]::-webkit-slider-thumb {
  background-color: #fff8e7;
  box-shadow: inset 0 0 0 2px var(--pop-ink);
}

/* Visual Code Overlay for Mobile */
.code-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2;
  font-family: var(--font-code);
  color: white;
  mix-blend-mode: difference;
  overflow: hidden;
  padding: 20px;
  margin-top: 4rem;
  box-sizing: border-box;
}

.code-overlay.visible {
  display: block;
}

.code-overlay textarea {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  color: inherit;
  line-height: 1.4;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  padding: 0;
  margin: 0;
  mix-blend-mode: inherit;
}

/* Responsive font sizing for code overlay */
@media screen and (max-width: 480px) {
  .code-overlay {
    font-size: clamp(8px, 2.5vw, 12px);
  }
}

@media screen and (min-width: 481px) and (max-width: 768px) {
  .code-overlay {
    font-size: clamp(10px, 2vw, 14px);
  }
}

@media screen and (min-width: 769px) and (max-width: 1024px) {
  .code-overlay {
    font-size: clamp(12px, 1.5vw, 16px);
  }
}

@media screen and (min-width: 1025px) {
  .code-overlay {
    font-size: clamp(14px, 1.2vw, 18px);
  }
}

/* Touch screens: iPads and other tablets get the full interface */
html {
  /* Tapping buttons in quick succession doesn't zoom the page */
  touch-action: manipulation;
}

.preview-container {
  /* Touching the visuals neither scrolls nor zooms the page */
  touch-action: none;
}

/* Safari only knows the prefixed user-select, which the panels don't set */
.editor-handle,
.stats-handle,
.slots-handle,
.xy-pad-handle,
.tempo-handle,
.doc-handle,
.info-panel-header {
  -webkit-user-select: none;
  user-select: none;
}

@media (any-pointer: coarse) {
  /* Grips big enough for a finger, and visible */
  .resize-grip {
    display: block;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg,
        transparent 55%,
        var(--color-text-secondary) 55% 61%,
        transparent 61% 71%,
        var(--color-text-secondary) 71% 77%,
        transparent 77%);
    opacity: 0.8;
  }

  /* The slots panel's grip covers less of the last slot */
  .resize-grip.slots-resize-grip {
    width: 20px;
    height: 20px;
  }

  /* Keeps the Save button clear of the editor's grip */
  .editor-footer {
    padding-right: 34px;
  }

  /* A bigger target around the XY pad's puck */
  .xy-pad-indicator::after {
    content: "";
    position: absolute;
    inset: -14px;
    border-radius: 50%;
  }
}

/* BPM widget (TempoPlugin, src/client/core/tempoWidget.js) */
.tempo-panel {
  position: absolute;
  /* Clear of the editor until it is moved, which it remembers */
  bottom: 20px;
  left: 20px;
  /* With the other panels, over the editor */
  z-index: 100;
  width: 176px;
  /* Once dragged it has a top as well as the bottom above: a height keeps it
     from stretching between the two */
  height: max-content;
  background-color: rgba(var(--color-bg-secondary-rgb), var(--panel-opacity));
  border-radius: var(--panel-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  font-family: var(--font-ui);
  color: var(--color-text-primary);
}

/* All of it fades together, like the other panels */
.tempo-panel {
  transition: visibility 0.2s ease, opacity 0.2s ease;
}

.tempo-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.tempo-handle {
  height: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 3px 0 8px;
  background-color: rgba(var(--color-bg-tertiary-rgb), var(--panel-opacity));
  border-radius: var(--panel-radius) var(--panel-radius) 0 0;
  cursor: move;
}

.tempo-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
}

.tempo-link-state {
  margin-left: auto;
  padding-right: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-accent, #9000ff);
}

.tempo-close {
  transition: color 0.15s ease;
  background: none;
  border: none;
  padding: 0 5px;
  font-size: 16px;
  line-height: 1;
  color: var(--color-text-primary);
  cursor: pointer;
}

.tempo-close:hover {
  color: var(--color-error);
}

.tempo-readout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px 2px;
}

.tempo-bpm {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.45;
}

.tempo-panel.is-locked .tempo-bpm {
  opacity: 1;
}

.tempo-beats {
  display: flex;
  gap: 5px;
}

.tempo-beat {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-bg-tertiary);
}

.tempo-beat.is-on {
  background-color: var(--color-text-primary);
}

.tempo-beat:first-child.is-on {
  background-color: var(--color-accent, #9000ff);
}

.tempo-adjust,
.tempo-play {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
}

.tempo-play {
  padding-bottom: 8px;
}

.tempo-panel button:not(.tempo-close) {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 4px;
  padding: 3px 0;
  font-family: inherit;
  font-size: 11px;
  color: var(--color-text-primary);
  background-color: var(--color-bg-tertiary);
  cursor: pointer;
  /* Not the global "all", which would fade each button out on its own when
     the panel hides, and blur the tap flash */
  transition: background-color 0.08s ease;
  transform: none;
}

.tempo-panel button:not(.tempo-close):hover {
  background-color: var(--color-button-hover);
}

.tempo-panel .tempo-tap {
  flex: 2;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.tempo-panel .tempo-tap.is-hit {
  background-color: var(--color-accent, #9000ff);
  color: var(--color-on-accent, #fff);
}

.tempo-panel .tempo-lock[aria-pressed="true"],
.tempo-panel .tempo-link[aria-pressed="true"] {
  background-color: var(--color-accent, #9000ff);
  color: var(--color-on-accent, #fff);
}

/* The SYSTEM panel's button that shows and hides the widget */
.tempo-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  opacity: 0.7;
  cursor: pointer;
}

.tempo-toggle:hover,
.tempo-toggle.is-active {
  opacity: 1;
  color: var(--color-text-primary);
}

@media (any-pointer: coarse) {
  .tempo-panel {
    width: 220px;
  }

  .tempo-panel .tempo-tap {
    padding: 18px 0;
  }

  .tempo-panel button:not(.tempo-close) {
    padding: 8px 0;
  }
}
