/* ---------- Themes ----------
   Every surface colour in this file comes from these tokens, so switching the data-theme on <html>
   restyles the whole studio. Accent colours are darkened in the light theme so they stay readable. */
:root,
[data-theme="dark"] {
  --paper: #fff7db;
  --ink: #fffaf0;
  --muted: #bdb4a1;
  --coal: #12110f;
  --charcoal: #1d1a17;
  --panel: rgba(31, 29, 25, 0.88);
  --panel-strong: rgba(45, 39, 33, 0.95);
  --line: rgba(255, 247, 219, 0.16);
  --line-strong: rgba(255, 247, 219, 0.32);
  --grid-line: rgba(255, 247, 219, 0.035);
  --wash-1: rgba(255, 247, 219, 0.045);
  --wash-2: rgba(255, 247, 219, 0.08);
  --wash-3: rgba(255, 247, 219, 0.13);
  --wash-4: rgba(255, 247, 219, 0.22);
  --page-1: #16120f;
  --page-2: #261b1c;
  --page-3: #131716;
  --well: #100e0c;
  --well-2: #2a2622;
  --glow-a: rgba(255, 111, 135, 0.22);
  --glow-b: rgba(118, 247, 191, 0.18);
  --amber: #ffd166;
  --mint: #76f7bf;
  --cyan: #63d8ff;
  --rose: #ff6f87;
  --lime: #d4f75f;
  --violet: #9e8cff;
  --on-accent: #211608;
  --accent-2: #ff9f5a;
  --field: rgba(20, 18, 16, 0.9);
  --panel-deep: rgba(18, 17, 15, 0.82);
  --accent-wash: rgba(255, 209, 102, 0.14);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
  --instrument-color: #ffd166;
  color-scheme: dark;
}

[data-theme="grey"] {
  --paper: #f7f9fb;
  --ink: #eaeef2;
  --muted: #a7b0b8;
  --coal: #2c3035;
  --charcoal: #383d43;
  --panel: rgba(60, 66, 72, 0.9);
  --panel-strong: rgba(74, 81, 88, 0.95);
  --line: rgba(255, 255, 255, 0.17);
  --line-strong: rgba(255, 255, 255, 0.36);
  --grid-line: rgba(255, 255, 255, 0.04);
  --wash-1: rgba(255, 255, 255, 0.055);
  --wash-2: rgba(255, 255, 255, 0.1);
  --wash-3: rgba(255, 255, 255, 0.16);
  --wash-4: rgba(255, 255, 255, 0.24);
  --page-1: #343a40;
  --page-2: #2c3238;
  --page-3: #262b30;
  --well: #22262b;
  --well-2: #454c53;
  --glow-a: rgba(255, 111, 135, 0.14);
  --glow-b: rgba(118, 247, 191, 0.12);
  --amber: #ffc94d;
  --mint: #5fe3ac;
  --cyan: #59cdf5;
  --rose: #ff7d92;
  --lime: #c6ea52;
  --violet: #a596ff;
  --on-accent: #1b1508;
  --accent-2: #ff9f5a;
  --field: rgba(24, 27, 30, 0.9);
  --panel-deep: rgba(26, 29, 33, 0.82);
  --accent-wash: rgba(255, 201, 77, 0.16);
  --shadow: 0 20px 54px rgba(0, 0, 0, 0.38);
  --instrument-color: #ffc94d;
  color-scheme: dark;
}

[data-theme="light"] {
  --paper: #241f1b;
  --ink: #262220;
  --muted: #6b625a;
  --coal: #f4efe3;
  --charcoal: #e8e1d1;
  --panel: rgba(255, 253, 248, 0.94);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --line: rgba(52, 44, 38, 0.18);
  --line-strong: rgba(52, 44, 38, 0.38);
  --grid-line: rgba(52, 44, 38, 0.05);
  --wash-1: rgba(52, 44, 38, 0.05);
  --wash-2: rgba(52, 44, 38, 0.09);
  --wash-3: rgba(52, 44, 38, 0.15);
  --wash-4: rgba(52, 44, 38, 0.24);
  --page-1: #fbf7ed;
  --page-2: #f2ebdb;
  --page-3: #f7f2e7;
  --well: #ffffff;
  --well-2: #ece5d5;
  --glow-a: rgba(255, 111, 135, 0.12);
  --glow-b: rgba(118, 247, 191, 0.14);
  --amber: #a86a12;
  --mint: #0f7d5f;
  --cyan: #12708f;
  --rose: #b8354f;
  --lime: #5f7a0f;
  --violet: #5b45c4;
  --on-accent: #fff8e8;
  --accent-2: #8c4a12;
  --field: #ffffff;
  --panel-deep: rgba(238, 231, 217, 0.9);
  --accent-wash: rgba(168, 106, 18, 0.12);
  --shadow: 0 16px 40px rgba(95, 78, 52, 0.18);
  --instrument-color: #a86a12;
  color-scheme: light;
}
/* ==== end themes ==== */

* {
  box-sizing: border-box;
}

/* ---------- Unified scrollbars (all scroll areas) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--wash-1);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--amber);
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

html {
  min-height: 100%;
  background: var(--coal);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", Verdana, sans-serif;
  background:
    repeating-linear-gradient(90deg, var(--grid-line) 0 1px, transparent 1px 56px),
    repeating-linear-gradient(0deg, var(--grid-line) 0 1px, transparent 1px 56px),
    linear-gradient(135deg, var(--glow-a), transparent 26%),
    linear-gradient(220deg, var(--glow-b), transparent 30%),
    linear-gradient(180deg, var(--page-1) 0%, var(--page-2) 46%, var(--page-3) 100%);
}

button,
input,
select {
  font: inherit;
}

.app-footer {
  text-align: center;
  padding: 22px 16px calc(26px + env(safe-area-inset-bottom));
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  border-top: 1px solid var(--line);
}

button {
  border: 0;
}

/* ---------- Boot screen (Music Factory Engine) ---------- */
.boot-screen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--page-1);
  background: radial-gradient(circle at 50% 40%, var(--page-2) 0%, var(--page-1) 52%, var(--page-3) 100%);
  opacity: 1;
  visibility: visible;
  transition: opacity 520ms ease, visibility 0s linear 520ms;
}

.boot-screen.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-inner {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.boot-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 26px;
  animation: bootBreathe 2.8s ease-in-out infinite;
}

@keyframes bootBreathe {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 6px 18px rgba(255, 154, 46, 0.18)); }
  50% { transform: scale(1.025); filter: drop-shadow(0 12px 32px rgba(255, 154, 46, 0.42)); }
}

.boot-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--wash-3);
  overflow: hidden;
}

.boot-fill {
  display: block;
  width: 10%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, #ff9a2e);
  box-shadow: 0 0 12px rgba(255, 154, 46, 0.55);
  transition: width 420ms ease;
}

.boot-note {
  margin: 14px 0 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .boot-logo { animation: none; }
}

.brand-mark {
  width: 40px;
  height: auto;
  margin-right: 10px;
  vertical-align: -10px;
  filter: drop-shadow(0 3px 8px rgba(255, 154, 46, 0.28));
}

.studio-shell {
  width: min(1520px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 32px;
  display: grid;
  gap: 18px;
}

.studio-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 18px;
}

.studio-deck {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
}

.fx-mixer-deck {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 18px;
}

/* Right column of the deck: piano panel with the Effects Rack stacked underneath it. */
.perf-column {
  display: grid;
  gap: 18px;
  min-width: 0;
  align-content: start;
}

.perf-column > * {
  min-width: 0;
}

/* Allow grid items to shrink so inner scroll containers (sequencer rows,
   mixer) contain their width instead of inflating the whole page. */
.studio-shell > *,
.studio-topbar > *,
.studio-deck > *,
.fx-mixer-deck > * {
  min-width: 0;
}

.brand-panel,
.transport-panel,
.rack-panel,
.performance-panel,
.sequencer-panel,
.fx-panel,
.mixer-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, var(--panel), var(--panel-deep));
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.brand-panel {
  min-height: 240px;
  padding: 26px;
  display: grid;
  grid-template-columns: minmax(240px, 0.46fr) minmax(320px, 1fr);
  align-items: end;
  gap: 22px;
  overflow: hidden;
  position: relative;
}

.brand-panel::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, var(--accent-wash), transparent 34%),
    repeating-linear-gradient(120deg, transparent 0 18px, var(--grid-line) 18px 20px);
}

.brand-panel > * {
  position: relative;
  z-index: 1;
}

.brand-copy {
  display: grid;
  gap: 12px;
}

.brand-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.help-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--accent-wash);
  color: var(--amber);
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background 160ms ease, transform 160ms ease, color 160ms ease;
}

.help-link:hover {
  background: var(--amber);
  color: var(--on-accent);
  transform: translateY(-1px);
}

.help-link i,
.help-link svg {
  width: 15px;
  height: 15px;
}

.eyebrow,
.tiny-label {
  margin: 0;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.tiny-label.muted {
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
}

h1 {
  max-width: 100%;
  margin-top: 4px;
  color: var(--paper);
  font-family: "Fraunces", Georgia, serif;
  font-size: 2.4rem;
  font-size: clamp(1.7rem, 3.4vw, 3rem);
  line-height: 0.98;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  overflow-wrap: normal;
}

.pro-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--amber), var(--accent-2));
}

h2 {
  margin-top: 4px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.9rem;
  color: var(--paper);
}

.meter-cluster {
  display: grid;
  gap: 6px;
  max-width: 260px;
}

.level-meter {
  height: 8px;
  border-radius: 999px;
  background: var(--wash-2);
  overflow: hidden;
}

.level-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--amber) 70%, var(--rose));
  transition: width 90ms linear;
}

.signal-strip {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--wash-3), var(--wash-1)),
    repeating-linear-gradient(90deg, var(--wash-2) 0 1px, transparent 1px 48px);
  overflow: hidden;
}

#visualizer {
  width: 100%;
  height: 100%;
  display: block;
}

.transport-panel,
.rack-panel,
.performance-panel,
.sequencer-panel,
.fx-panel,
.mixer-panel {
  padding: 18px;
}

.transport-panel {
  display: grid;
  align-content: space-between;
  gap: 16px;
}

.transport-panel > .panel-body {
  display: grid;
  align-content: space-between;
  gap: 16px;
}

/* Collapsible areas added inside existing panels */
.keys-area {
  display: grid;
  gap: 12px;
}

.keys-area > .panel-body {
  display: grid;
  gap: 14px;
}

.scratch-head .accordion-toggle,
.sample-steps-head .accordion-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.theme-pick select {
  min-width: 92px;
}

.status-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.status-light {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--rose);
  box-shadow: 0 0 18px rgba(255, 111, 135, 0.8);
}

body.audio-ready .status-light {
  background: var(--mint);
  box-shadow: 0 0 18px rgba(118, 247, 191, 0.85);
}

body.is-loading .status-light {
  background: var(--cyan);
  animation: pulse 0.8s infinite;
}

body.is-recording .status-light {
  background: var(--rose);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.position-readout {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--wash-2);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.transport-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.transport-actions .primary {
  grid-column: span 3;
}

.command-button {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: var(--wash-2);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.command-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.4;
}

.command-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--wash-4);
}

.command-button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.command-button.primary {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--amber), var(--accent-2));
  border-color: transparent;
  font-weight: 700;
}

.command-button.ghost {
  background: rgba(255, 111, 135, 0.12);
}

.command-button.record[aria-pressed="true"] {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--rose), var(--accent-2));
  border-color: transparent;
  font-weight: 700;
}

.command-button[aria-pressed="true"]:not(.record) {
  border-color: var(--mint);
  background: rgba(118, 247, 191, 0.16);
}

.control-stack {
  display: grid;
  gap: 12px;
}

.range-control {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 62px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

output {
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}

/* Older WebKit has no accent-color, so draw the slider ourselves and make the thumb finger-sized. */
.legacy-ui input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 22px;
  background: transparent;
}

.legacy-ui input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--wash-4);
}

.legacy-ui input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border: none;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
  cursor: pointer;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-heading > span:first-child {
  color: var(--paper);
  font-size: 1.1rem;
  font-weight: 700;
}

/* ---------- Accordions ---------- */
.accordion-toggle {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.accordion-toggle:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
  border-radius: 6px;
}

.heading-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.perf-title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.seq-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.accordion-chevron {
  width: 18px;
  height: 18px;
  color: var(--amber);
  transition: transform 160ms ease;
  flex: none;
}

[data-accordion].is-collapsed .accordion-chevron {
  transform: rotate(-90deg);
}

/* A collapsed panel folds away completely: everything except the chain holding its toggle is
   hidden, and the panel shrinks to that title bar. */
[data-accordion].is-collapsed > *:not(.accordion-keep):not(.accordion-toggle),
[data-accordion].is-collapsed .accordion-keep > *:not(.accordion-keep):not(.accordion-toggle) {
  display: none;
}

[data-accordion].is-collapsed {
  min-height: 0;
  align-content: start;
}

[data-accordion].is-collapsed .panel-heading {
  margin-bottom: 0;
}

.performance-panel.is-collapsed {
  min-height: 0;
}

.panel-body {
  min-width: 0;
}

.rack-voice {
  display: flex;
  width: 100%;
  margin-top: 12px;
}

.rack-voice select {
  flex: 1;
  min-width: 0;
}

.rack-songtext {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.rack-songtext[hidden] {
  display: none;
}

.rack-songtext .chip-field {
  flex: 1 1 100%;
  min-width: 0;
}

.rack-songtext .chip-field input {
  flex: 1;
  min-width: 0;
  width: 100%;
}

.rack-songtext .mini-button {
  width: 100%;
  justify-content: center;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 16px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.modal-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
}

.modal-field input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.rack-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.rack-style {
  display: flex;
  width: 100%;
  margin-bottom: 12px;
}

.rack-style select {
  flex: 1;
  min-width: 0;
}

.voice-curve {
  flex: 1 1 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.voice-curve canvas {
  width: 260px;
  height: 54px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.32);
  cursor: crosshair;
  touch-action: none;
}

.voice-curve .voice-range {
  display: inline-flex;
}

.instrument-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.instrument-card {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  position: relative;
  display: grid;
  align-content: space-between;
  color: var(--ink);
  text-align: left;
  background:
    linear-gradient(160deg, var(--wash-3), var(--grid-line)),
    var(--panel-strong);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.instrument-card:hover,
.instrument-card.is-selected {
  transform: translateY(-1px);
  border-color: var(--instrument-color);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--instrument-color) 52%, transparent), 0 14px 28px rgba(0, 0, 0, 0.24);
}

.instrument-name {
  font-weight: 700;
}

.instrument-role {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.card-rename {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.42);
  color: var(--ink);
  cursor: pointer;
  opacity: 0.82;
  transition: opacity 140ms ease, border-color 140ms ease, color 140ms ease;
}

.instrument-card:hover .card-rename,
.instrument-card:focus-within .card-rename,
.card-rename:focus-visible {
  opacity: 1;
}

.card-rename:hover {
  border-color: var(--instrument-color);
  color: var(--paper);
}

.card-rename svg {
  width: 14px;
  height: 14px;
}

.card-delete {
  position: absolute;
  top: 8px;
  right: 40px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.42);
  color: var(--ink);
  cursor: pointer;
  opacity: 0.82;
  transition: opacity 140ms ease, border-color 140ms ease, color 140ms ease;
}

.instrument-card:hover .card-delete,
.instrument-card:focus-within .card-delete,
.card-delete:focus-visible {
  opacity: 1;
}

.card-delete:hover {
  border-color: var(--rose);
  color: var(--rose);
}

.card-delete svg {
  width: 14px;
  height: 14px;
}

.preset-buttons {
  display: grid;
  gap: 8px;
}

.preset-button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  text-align: left;
  background: var(--wash-1);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.preset-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--wash-3);
}

.preset-button .preset-genre {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.performance-panel {
  min-height: 420px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.performance-panel .panel-body {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  min-height: 0;
}

.performance-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.perf-toggles {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chip-toggle {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: var(--wash-2);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.chip-toggle svg {
  width: 16px;
  height: 16px;
}

.chip-toggle[aria-pressed="true"] {
  border-color: var(--mint);
  background: rgba(118, 247, 191, 0.18);
  color: var(--paper);
}

.chip-toggle[hidden] {
  display: none;
}

.chip-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.chip-select[hidden] {
  display: none;
}

.sample-stretch input[type="range"] {
  width: 96px;
  accent-color: var(--amber);
}

.sample-stretch output {
  min-width: 46px;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.pad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 12px;
}

.play-pad {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: space-between;
  color: var(--paper);
  text-align: left;
  background: var(--wash-2); /* fallback */
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--instrument-color) 24%, transparent), var(--wash-2)),
    var(--wash-1);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: transform 120ms ease, border-color 120ms ease, filter 120ms ease;
}

.play-pad::after {
  content: "";
  width: 100%;
  height: 5px;
  position: absolute;
  left: 0;
  bottom: 0;
  background: var(--instrument-color);
  transform: scaleX(0.38);
  transform-origin: left;
  transition: transform 140ms ease;
}

.play-pad:hover,
.play-pad.is-hit {
  transform: translateY(-2px);
  border-color: var(--instrument-color);
  filter: brightness(1.08);
}

.play-pad:hover::after,
.play-pad.is-hit::after {
  transform: scaleX(1);
}

.pad-note {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.8rem;
}

.pad-name {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.vocal-pad {
  align-content: start;
  gap: 8px;
  cursor: default;
}

.vocal-pad .pad-note {
  font-size: 1.25rem;
}

.pad-text {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.9rem;
}

.pad-text::placeholder {
  color: var(--muted);
}

.pad-text:focus-visible {
  outline: 2px solid var(--instrument-color);
  outline-offset: 1px;
}

.pad-play {
  justify-self: start;
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--paper);
  font-weight: 700;
  background: var(--instrument-color); /* fallback */
  background: color-mix(in srgb, var(--instrument-color) 24%, var(--wash-2));
  cursor: pointer;
  transition: border-color 140ms ease, filter 140ms ease;
}

.pad-play svg {
  width: 15px;
  height: 15px;
}

.pad-play:hover {
  border-color: var(--instrument-color);
  filter: brightness(1.12);
}

.keyboard-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.stop-playing {
  margin-top: 10px;
  width: 100%;
  justify-content: center;
}

.stop-playing:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Sample step-sequencer (under Amp Tone) ---------- */
.sample-steps {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--wash-1);
  display: grid;
  gap: 8px;
}

.sample-steps-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sample-steps-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.sample-steps-actions .mini-button {
  min-height: 30px;
  padding: 0 10px;
}

.sample-step-grid {
  display: grid;
  gap: 6px;
}

.seq-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.seq-row-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.seq-label-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.seq-notes {
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  background: var(--wash-1);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.seq-notes.has-notes {
  color: var(--instrument-color, var(--amber));
  border-color: var(--line-strong);
}

/* ---------- Turntable Scratching (two visual decks, above Amp Tone) ---------- */
.scratch-deck {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--wash-1);
  display: grid;
  gap: 10px;
}

.scratch-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  align-self: stretch;
}

.scratch-head #scratchGenerate {
  margin-left: auto;
}

.scratch-decks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  justify-items: center;
}

.scratch-turntable {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.deck-tag {
  letter-spacing: 0.12em;
}

.deck-track {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.deck-track input[type="range"] {
  flex: 1;
  min-width: 0;
}

.deck-time {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted);
}

.deck-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.deck-controls .mini-button.is-on {
  color: var(--coal);
  background: var(--amber);
  border-color: transparent;
}

.scratch-source {
  max-width: 100%;
}

.deck-panel {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.deck-knob {
  display: grid;
  gap: 2px;
  justify-items: center;
  min-width: 0;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.deck-knob input[type="range"] {
  width: 100%;
}

.deck-knob b {
  font-size: 10px;
  font-weight: 700;
  color: var(--paper);
  letter-spacing: 0;
  text-transform: none;
}

.scratch-mixer {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 4px 8px 2px;
}

.scratch-mixer input[type="range"] {
  width: min(320px, 70%);
  max-width: 320px;
}

.scratch-platter {
  position: relative;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  -ms-touch-action: none;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}

.scratch-platter.is-scratching { cursor: grabbing; }

.scratch-vinyl {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at 50% 50%, #0a0a0a 0 2px, #242424 2px 4px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5), inset 0 0 0 2px var(--wash-2);
  pointer-events: none;
  will-change: transform;
}

/* At speed the grooves of a real record blur into flat black. This layer fades in with the
   platter's speed so the disc reads as spinning instead of strobing. */
.scratch-smear {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at 50% 50%, #131313 0 7px, #1e1e1e 7px 14px);
  opacity: 0;
  pointer-events: none;
}

/* Light on the room reflecting off the vinyl. It stays put while the record turns underneath,
   which is what actually makes the spin visible on a real deck. */
.scratch-sheen {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 50%;
  background: linear-gradient(125deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.05) 24%, rgba(255, 255, 255, 0) 44%, rgba(255, 255, 255, 0) 56%, rgba(255, 255, 255, 0.12) 76%, rgba(255, 255, 255, 0.01) 92%, rgba(255, 255, 255, 0) 100%);
  pointer-events: none;
}

/* The spindle pokes up through the label, so it never turns. */
.scratch-spindle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: #c8ccd2;
  background: linear-gradient(145deg, #eef1f5, #7c828b);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.scratch-marker {
  position: absolute;
  top: 5px;
  left: calc(50% - 2px);
  width: 4px;
  height: 32%;
  border-radius: 2px;
  background: var(--label-color, #63d8ff);
  box-shadow: 0 0 8px var(--label-color, #63d8ff);
}

.scratch-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: var(--label-color, #63d8ff);
  color: #0c0c0c;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  padding: 6px;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.scratch-hub span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Full-screen decks. Each fullscreen pseudo-class needs its own rule: a browser that doesn't know
   one of them throws away the whole selector list, which would take the fallback overlay with it. */
.scratch-deck.is-faux-fullscreen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 120;
  margin: 0;
  padding: 24px;
  padding: clamp(16px, 4vh, 40px);
  border-radius: 0;
  background: var(--coal);
  align-content: center;
  overflow: auto;
}

.scratch-deck:-webkit-full-screen {
  margin: 0;
  padding: 24px;
  border-radius: 0;
  background: var(--coal);
  align-content: center;
  overflow: auto;
}

.scratch-deck:fullscreen {
  margin: 0;
  padding: clamp(16px, 4vh, 40px);
  border-radius: 0;
  background: var(--coal);
  align-content: center;
  overflow: auto;
}

.scratch-deck.is-faux-fullscreen .scratch-decks {
  gap: 32px;
  gap: clamp(16px, 5vw, 64px);
}

.scratch-deck:-webkit-full-screen .scratch-decks { gap: 32px; }

.scratch-deck:fullscreen .scratch-decks { gap: clamp(16px, 5vw, 64px); }

.scratch-deck.is-faux-fullscreen .scratch-platter,
.scratch-deck.is-faux-fullscreen .scratch-vinyl {
  width: min(34vw, 52vh);
  height: min(34vw, 52vh);
}

.scratch-deck:-webkit-full-screen .scratch-platter {
  width: min(34vw, 52vh);
  height: min(34vw, 52vh);
}

.scratch-deck:fullscreen .scratch-platter {
  width: min(34vw, 52vh);
  height: min(34vw, 52vh);
}

.scratch-deck.is-faux-fullscreen .scratch-head { justify-content: center; }

.scratch-deck:-webkit-full-screen .scratch-head { justify-content: center; }

.scratch-deck:fullscreen .scratch-head { justify-content: center; }

@media (max-width: 600px) {
  .scratch-decks {
    grid-template-columns: minmax(0, 1fr);
  }
}

.seq-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--row-color, var(--cyan));
  flex: none;
}

.seq-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seq-row-remove {
  margin-left: auto;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  flex: none;
}

.seq-row-remove:hover {
  border-color: var(--rose);
  color: var(--rose);
}

.seq-row-cells {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.seq-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 2px;
}

.seq-length {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.seq-length select {
  font: inherit;
  color: var(--ink);
  background: var(--wash-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}

.sample-step {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--wash-2);
  cursor: pointer;
  padding: 0;
  transition: background 120ms ease, box-shadow 120ms ease, transform 60ms ease;
}

.sample-step.beat {
  border-color: var(--line-strong);
}

.sample-step:hover {
  background: var(--wash-3);
}

.sample-step.is-on {
  background: var(--instrument-color, var(--amber));
  border-color: var(--instrument-color, var(--amber));
  box-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
}

.sample-step.is-playing {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  transform: translateY(-1px);
}

.timeline-speed {
  margin: 12px 0 4px;
}

.keyboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.piano {
  position: relative;
  height: 170px;
  height: clamp(150px, 21vh, 220px);
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -ms-touch-action: none;
  touch-action: none;
}

.key {
  position: relative;
  cursor: pointer;
}

.key.white {
  flex: 1;
  background: linear-gradient(180deg, #fdfbf3, #e7e1cf);
  border-right: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 0 0 5px 5px;
}

.key.white:last-child {
  border-right: 0;
}

.key.white.is-down {
  background: linear-gradient(180deg, var(--instrument-color), #f4d98a);
}

.key.black {
  position: absolute;
  top: 0;
  width: 3.6%;
  height: 62%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, var(--well-2), var(--well));
  border-radius: 0 0 4px 4px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.key.black.is-down {
  background: linear-gradient(180deg, var(--instrument-color), #7a6320);
}

.key .key-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  color: rgba(20, 16, 12, 0.5);
  pointer-events: none;
}

.key.black .key-hint {
  color: var(--muted);
  bottom: 6px;
}

.fx-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.knob-control {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash-1);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.knob-control input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 8px;
  height: 92px;
  accent-color: var(--instrument-color);
}

.mixer-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(64px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.mixer-channel {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash-1);
}

.channel-name {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--paper);
  text-align: center;
}

.channel-fader {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 8px;
  height: 120px;
  accent-color: var(--channel-color, var(--amber));
}

.channel-buttons {
  display: flex;
  gap: 5px;
}

.channel-buttons button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--wash-1);
  cursor: pointer;
}

.channel-buttons button.mute.is-active {
  color: var(--on-accent);
  background: var(--rose);
  border-color: transparent;
}

.channel-buttons button.solo.is-active {
  color: var(--on-accent);
  background: var(--amber);
  border-color: transparent;
}

.sequencer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.genre-tag {
  color: var(--mint);
  font-variant-numeric: tabular-nums;
}

.bars-field input[type="number"] {
  width: 62px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
}

.sample-studio {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--accent-wash);
}

.sample-studio > .tiny-label:first-child {
  color: var(--amber);
  letter-spacing: 0.04em;
}

.sequencer-transport {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.sequencer-transport .command-button {
  min-width: 150px;
}

.transport-extra {
  max-width: 560px;
  margin: 16px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.mini-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: var(--wash-2);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.mini-button svg {
  width: 15px;
  height: 15px;
}

.mini-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--wash-3);
}

.mini-button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.mini-button.primary {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--amber), var(--accent-2));
  border-color: transparent;
  font-weight: 700;
}

.sequencer-builder {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash-1);
}

.sequencer-builder select {
  min-width: 132px;
}

.sequencer-builder #bandHint {
  margin-left: auto;
}

.sequencer-builder.note-hidden #noteSelectWrap {
  display: none;
}

#lyricsWrap {
  display: none;
}

.sequencer-builder.vocals-mode #lyricsWrap {
  display: inline-flex;
}

.chip-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.chip-field input {
  min-width: 240px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
}

.chip-field input::placeholder {
  color: var(--muted);
  text-transform: none;
  font-weight: 400;
}

#vocalSettings {
  display: none;
}

#testVoice {
  display: none;
}

.add-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.song-text-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.sequencer-builder.vocals-mode #testVoice {
  display: inline-flex;
}

.sequencer-builder.vocals-mode #vocalSettings {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.voice-range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.voice-range input[type="range"] {
  width: 108px;
  accent-color: var(--rose);
}

.voice-range output {
  min-width: 42px;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.builder-sep {
  width: 1px;
  align-self: stretch;
  min-height: 26px;
  background: var(--line);
  margin: 0 2px;
}

.sequencer-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.step-labels,
.sequence-row {
  width: max-content;
  display: grid;
  gap: 6px;
  align-items: center;
}

.step-labels {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.step-labels span.beat {
  color: var(--amber);
}

.step-labels span.bar-start {
  color: var(--paper);
  font-weight: 700;
}

.sequence-grid {
  display: grid;
  gap: 8px;
}

.track-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--paper);
  font-size: 0.82rem;
  font-weight: 700;
  overflow: hidden;
}

.track-name .track-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-name .track-sub {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.track-remove {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--wash-1);
  cursor: pointer;
  line-height: 1;
}

.track-remove:hover {
  color: var(--on-accent);
  background: var(--rose);
  border-color: transparent;
}

.track-copy {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--wash-1);
  cursor: pointer;
  line-height: 1;
}

.track-copy:hover {
  color: var(--on-accent);
  background: var(--amber);
  border-color: transparent;
}

.sequence-row.is-selected .track-name {
  box-shadow: -3px 0 0 var(--amber);
  padding-left: 4px;
}

.sequence-row.is-selected .region-body,
.sequence-row.is-selected .region-outline {
  box-shadow: 0 0 0 2px var(--amber);
}

.track-tempo {
  flex: none;
  width: 46px;
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--field);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.track-tempo:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.track-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--track-color);
}

.step-cell {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--wash-1);
  cursor: pointer;
  position: relative;
}

.step-cell.beat {
  background: var(--wash-3);
}

.step-cell.bar-start {
  border-left: 2px solid var(--line-strong);
}

.step-cell::after {
  content: "";
  width: 44%;
  height: 44%;
  border-radius: 999px;
  position: absolute;
  top: 28%;
  right: 28%;
  bottom: 28%;
  left: 28%;
  background: var(--track-color);
  opacity: 0;
  transform: scale(0.55);
  transition: opacity 120ms ease, transform 120ms ease;
}

.step-cell.is-active::after {
  opacity: 1;
  transform: scale(1);
}

.step-cell.is-current {
  border-color: var(--paper);
  box-shadow: 0 0 0 1px var(--line-strong), 0 0 18px color-mix(in srgb, var(--track-color) 34%, transparent);
}

.step-cell.in-region {
  background: var(--track-color); /* fallback */
  background: color-mix(in srgb, var(--track-color) 24%, var(--wash-1));
  border-color: var(--line-strong); /* fallback */
  border-color: color-mix(in srgb, var(--track-color) 42%, var(--line));
}

.step-cell.out-region {
  opacity: 0.3;
  filter: grayscale(0.5);
}

.region-handle {
  position: absolute;
  top: 0;
  width: 18px;
  height: 100%;
  z-index: 5;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.region-handle::before {
  content: "";
  width: 6px;
  height: 68%;
  border-radius: 3px;
  background: var(--track-color); /* fallback */
  background: color-mix(in srgb, var(--track-color) 82%, #ffffff);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.region-handle:hover::before,
.region-handle:active::before {
  background: var(--paper);
  height: 88%;
  width: 7px;
}

/* Non-interactive outline showing each plain track's adjustable window (trim/expand region). */
.region-outline {
  position: absolute;
  top: 2px;
  height: calc(100% - 4px);
  z-index: 3;
  pointer-events: none;
  border: 1.5px dashed var(--line-strong); /* fallback */
  border: 1.5px dashed color-mix(in srgb, var(--track-color) 60%, transparent);
  border-radius: 7px;
  background: var(--track-color); /* fallback */
  background: color-mix(in srgb, var(--track-color) 7%, transparent);
}

/* Soundtrap-style draggable "move" header at the top of a plain track's block. */
.region-move {
  position: absolute;
  top: 0;
  height: 12px;
  z-index: 4;
  cursor: grab;
  touch-action: none;
  border-radius: 6px 6px 0 0;
  background: var(--track-color); /* fallback */
  background: color-mix(in srgb, var(--track-color) 42%, transparent);
  border: 1px solid var(--line-strong); /* fallback */
  border: 1px solid color-mix(in srgb, var(--track-color) 62%, transparent);
  border-bottom: none;
}

.region-move:hover {
  background: var(--track-color); /* fallback */
  background: color-mix(in srgb, var(--track-color) 62%, transparent);
}

.region-move.is-grabbing {
  cursor: grabbing;
}

.region-body {
  position: absolute;
  top: 0;
  height: 100%;
  z-index: 4;
  cursor: grab;
  touch-action: none;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--track-color) 38%, transparent);
}

.region-body:hover {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--track-color) 66%, transparent);
}

.region-body.is-grabbing {
  cursor: grabbing;
}

.region-handle-left,
.region-handle-right {
  cursor: col-resize;
}

@media (max-width: 1200px) {
  .studio-topbar,
  .studio-deck,
  .fx-mixer-deck,
  .brand-panel {
    grid-template-columns: 1fr;
  }

  h1 {
    max-width: 100%;
    font-size: 3rem;
  }
}

@media (max-width: 760px) {
  .studio-shell {
    width: min(100% - 20px, 1520px);
    padding: 10px 0 24px;
  }

  .brand-panel,
  .transport-panel,
  .rack-panel,
  .performance-panel,
  .sequencer-panel,
  .fx-panel,
  .mixer-panel {
    padding: 14px;
  }

  h1 {
    font-size: 2.4rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .transport-actions,
  .instrument-grid,
  .pad-grid,
  .fx-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .transport-actions .primary {
    grid-column: span 2;
  }

  .piano {
    height: 120px;
  }

  .range-control {
    grid-template-columns: 60px minmax(0, 1fr) 58px;
  }
}

/* ---------- Touch & responsive enhancements ---------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

button,
select,
.chip-toggle,
.instrument-card,
.play-pad,
.preset-button,
.step-cell,
.channel-buttons button,
.track-remove {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.piano,
.key {
  touch-action: none;
}

.studio-shell {
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
}

/* Bigger hit targets on touch/pen devices */
@media (pointer: coarse) {
  .mini-button,
  .chip-toggle,
  .command-button {
    min-height: 44px;
  }

  input[type="range"] {
    height: 30px;
  }

  .channel-fader,
  .knob-control input[type="range"] {
    width: 22px;
  }

  .step-cell {
    min-height: 40px;
  }

  .channel-buttons button {
    width: 32px;
    height: 32px;
  }
}

/* Tablet */
@media (min-width: 761px) and (max-width: 1024px) {
  .fx-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  h1 {
    font-size: 2.8rem;
  }
}

/* Large phones */
@media (max-width: 600px) {
  .studio-shell {
    width: min(100% - 16px, 1520px);
    gap: 12px;
  }

  .panel-heading > span:first-child {
    font-size: 1rem;
  }

  .sequencer-tools,
  .sequencer-builder {
    gap: 8px;
  }

  .sequencer-tools .chip-select,
  .sequencer-tools .chip-select select,
  .sequencer-builder .chip-select,
  .sequencer-builder .chip-select select,
  .chip-field,
  .chip-field input {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
  }

  .fx-grid,
  .instrument-grid,
  .pad-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sequencer-transport {
    flex-wrap: wrap;
  }

  .sequencer-transport .command-button {
    flex: 1 1 40%;
    min-width: 120px;
  }

  .signal-strip {
    min-height: 130px;
  }

  .voice-range {
    flex: 1 1 46%;
  }

  .voice-range input[type="range"] {
    width: 100%;
  }
}

/* Small phones */
@media (max-width: 430px) {
  h1 {
    font-size: 2rem;
  }

  .pad-grid,
  .instrument-grid,
  .fx-grid,
  .transport-actions {
    grid-template-columns: 1fr 1fr;
  }

  .play-pad {
    min-height: 84px;
  }

  .perf-toggles {
    width: 100%;
  }
}

/* ---------- Download modal ---------- */
.modal-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 6, 5, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(440px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 22px;
  background: linear-gradient(150deg, var(--panel-strong), var(--panel-deep));
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.5rem;
  color: var(--paper);
}

.modal-close {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--wash-2);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-sub {
  margin: 12px 0 16px;
  color: var(--muted);
  font-weight: 700;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

@media (max-width: 480px) {
  .modal-actions {
    grid-template-columns: 1fr;
  }
}