/* Default = light (2026 soft-neutral palette).
   Dark theme is opt-in via body.theme-dark, but we still keep all dark
   tokens defined so any element that asks for them gets a sensible value. */
:root {
  --bg:           #fafbfd;
  --bg-2:         #ffffff;
  --bg-3:         #f1f3f8;
  --bg-elev:      #ffffff;
  --fg:           #16181d;
  --fg-dim:       #6b7180;
  --accent:       #6366f1;   /* indigo */
  --accent-2:     #8b5cf6;   /* violet (gradient partner) */
  --accent-soft:  rgba(99,102,241,0.10);
  --grid:         #e7eaf1;
  --grid-strong:  #d4d8e2;
  --playhead:     #ec4899;
  --shadow-sm:    0 1px 2px rgba(15,23,42,0.06);
  --shadow-md:    0 4px 14px rgba(15,23,42,0.08);
  --shadow-glow:  0 6px 20px rgba(99,102,241,0.22);
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --tool-h:       auto;
  --voices-w:     240px;
  --mini-h:       88px;
}

body.theme-light { /* alias: light is default */ }

body.theme-dark {
  --bg:           #0e1014;
  --bg-2:         #14171f;
  --bg-3:         #1c2030;
  --bg-elev:      #1a1e2a;
  --fg:           #e8ebf2;
  --fg-dim:       #9097a7;
  --accent:       #818cf8;
  --accent-2:     #c4b5fd;
  --accent-soft:  rgba(129,140,248,0.16);
  --grid:         #242a3a;
  --grid-strong:  #353b50;
  --playhead:     #f472b6;
  --shadow-sm:    0 1px 2px rgba(0,0,0,0.40);
  --shadow-md:    0 4px 14px rgba(0,0,0,0.45);
  --shadow-glow:  0 6px 20px rgba(129,140,248,0.30);
}
/* (legacy theme-light overrides removed; light is now the default token set) */

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: var(--voices-w) 1fr;
  grid-template-rows: auto 1fr var(--mini-h);
  grid-template-areas:
    "tool tool"
    "voices stage"
    "mini  mini";
  height: 100vh;
}

/* When minimap is toggled off, collapse the bottom row entirely so the
   stage gets the full height. */
body.no-minimap {
  grid-template-rows: auto 1fr 0;
}
body.no-minimap #minimap-wrap { display: none; }

#toolbar {
  grid-area: tool;
  display: flex; flex-wrap: nowrap; align-items: center;
  gap: 8px 12px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--grid);
  min-height: 56px;
}

#toolbar .group {
  display: flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
}
#toolbar .group.grow { flex: 1 1 200px; min-width: 120px; }
@media (max-width: 1100px) {
  #toolbar { flex-wrap: wrap; }
  #toolbar .group.grow { flex-basis: 100%; order: 99; }
}
#toolbar label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-dim);
  white-space: nowrap;
}
#toolbar .readout { color: var(--fg-dim); font-variant-numeric: tabular-nums; }

#toolbar input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}
#toolbar input[type="number"]:not(.ctrl-num) {
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: 6px;
  padding: 3px 5px;
}
#toolbar select {
  background: var(--bg-3); color: var(--fg);
  border: 1px solid #000; border-radius: 4px;
  padding: 3px 5px;
}
#toolbar button[disabled] { opacity: 0.6; cursor: progress; }
#toolbar #seek { width: 100%; }

/* Generic toolbar <button> fallback (kept for any old buttons). */
#toolbar > button,
#toolbar .group > button:not(.icon-btn):not(.step-btn) {
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: 8px;
  min-width: 34px; height: 34px; padding: 0 10px;
  cursor: pointer;
}
#toolbar > button:hover { background: var(--bg-2); border-color: var(--accent); }

/* Pretty squircle transport / icon buttons */
#toolbar .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--grid-strong); border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
  transition: background 0.14s ease, transform 0.06s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}
#toolbar .icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent); color: var(--accent);
}
#toolbar .icon-btn:active { transform: translateY(1px) scale(0.97); }
#toolbar .icon-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: var(--shadow-glow), 0 1px 0 rgba(255,255,255,0.30) inset;
}
#toolbar .icon-btn.primary:hover { filter: brightness(1.06); color: #fff; }
#toolbar .icon-btn.small { width: 28px; height: 28px; border-radius: 7px; }
#toolbar .icon-btn svg { display: block; }
#btn-fit { margin-left: 4px; }
#btn-fit.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
}

.file-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev); color: var(--fg);
  padding: 0 12px; height: 34px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--grid-strong);
  box-shadow: var(--shadow-sm);
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  font-weight: 500; white-space: nowrap;
}
.file-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.file-btn input { display: none; }
@media (max-width: 1280px) {
  .file-btn span { display: none; }
  .file-btn { width: 34px; padding: 0; justify-content: center; }
}

.now-playing {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  font-size: 11.5px;
  color: var(--fg-dim, #888);
  padding: 0 6px;
  border-left: 1px solid var(--grid-strong);
  margin-left: 4px;
  font-style: italic;
}
.app-version {
  display: inline-block;
  vertical-align: middle;
  font-size: 10.5px;
  color: var(--fg-dim, #888);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  padding-left: 6px;
}
@media (max-width: 1280px) {
  .now-playing { max-width: 120px; }
  .app-version { display: none; }
}

/* ---------- Modern stepper control row ---------- */
.ctrl {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px;
  background: var(--bg-elev);
  border: 1px solid var(--grid-strong);
  border-radius: var(--radius-sm);
  height: 34px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.ctrl:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--grid-strong)); }
.ctrl:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.ctrl .ctrl-label {
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--fg-dim); padding-right: 4px; font-weight: 600;
}
.ctrl .ctrl-suffix { color: var(--fg-dim); font-size: 11px; min-width: 18px; text-align: left; }
.ctrl input[type="range"] {
  width: 86px;
  -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--grid-strong); border-radius: 999px; outline: none;
}
.ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elev);
  box-shadow: 0 0 0 1px var(--accent), 0 0 6px var(--accent-soft);
  cursor: pointer; transition: transform 0.08s ease;
}
.ctrl input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
.ctrl input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elev);
  box-shadow: 0 0 6px var(--accent-soft); cursor: pointer;
}
/* Adaptive: hide the slider thumb in narrow toolbars; the numeric input +
   stepper buttons remain. (Sidebar .ctrl-block already hides ranges.) */
@media (max-width: 1320px) {
  #toolbar .ctrl input[type="range"] { display: none; }
}
/* Permanently-compact ctrl: number-input only, no slider rail. Used in
   the top toolbar for Speed / Vol so the rest of the toolbar (Examples,
   file picker, etc.) doesn't get pushed out of view. The <input
   type="range"> still exists in the DOM (the change handlers depend
   on it) but is hidden via the inline `hidden` attribute on the input. */
#toolbar .ctrl-compact { padding: 0 6px; gap: 2px; }
#toolbar .ctrl-compact .ctrl-label { padding-right: 2px; }
#toolbar .ctrl-compact .ctrl-num   { width: 42px; }
#toolbar .ctrl-compact .ctrl-suffix{ min-width: 12px; }
.ctrl .ctrl-num {
  width: 56px; text-align: right;
  background: transparent; color: var(--fg);
  border: none; outline: none;
  font-variant-numeric: tabular-nums; font-size: 12px;
  -moz-appearance: textfield;
}
.ctrl .ctrl-num::-webkit-outer-spin-button,
.ctrl .ctrl-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ctrl .ctrl-num:focus { background: var(--bg-2); border-radius: 4px; }
.ctrl .step-btn {
  width: 22px; height: 22px; min-width: 0; padding: 0;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--fg-dim);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, transform 0.06s ease;
}
.ctrl .step-btn:hover { background: var(--accent); color: #fff; }
.ctrl .step-btn:active { transform: scale(0.92); }
.ctrl .step-btn svg { display: block; }
.ctrl .icon-btn.ghost { width: 26px; height: 26px; border: 1px solid transparent; background: transparent; box-shadow: none; }
.ctrl .icon-btn.ghost:hover { background: var(--accent); color: #fff; border-color: transparent; }

/* Block (full-width) variant for the sidebar. */
.ctrl-block {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto auto;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 32px;
  margin: 4px 0;
}
.ctrl-block .ctrl-label { padding-right: 0; }
.ctrl-block input[type="range"] { display: none; }   /* sidebar uses number+stepper */
.ctrl-block .ctrl-num { width: 52px; }

body:not(.theme-dark) .ctrl { background: var(--bg-elev); border-color: var(--grid-strong); }
body:not(.theme-dark) .ctrl input[type="range"] { background: var(--grid-strong); }
body:not(.theme-dark) .ctrl .step-btn { background: var(--accent-soft); }

/* ---------- Modern checkboxes (layers / voices) ---------- */
#voices-panel input[type="checkbox"],
#layers-list input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 16px; border-radius: 999px;
  background: var(--grid-strong);
  position: relative; cursor: pointer; outline: none;
  transition: background 0.18s ease;
  flex-shrink: 0;
}
#voices-panel input[type="checkbox"]::after,
#layers-list input[type="checkbox"]::after {
  content: ""; position: absolute;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px;
  transition: left 0.18s ease, background 0.18s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
#voices-panel input[type="checkbox"]:checked,
#layers-list input[type="checkbox"]:checked {
  background: var(--accent);
}
#voices-panel input[type="checkbox"]:checked::after,
#layers-list input[type="checkbox"]:checked::after {
  left: 16px;
}

/* ---------- Modern selects ---------- */
#sidebar select, #toolbar select {
  -webkit-appearance: none; appearance: none;
  background-color: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: var(--radius-sm);
  padding: 4px 24px 4px 10px;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-dim) 50%),
                    linear-gradient(135deg, var(--fg-dim) 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
#sidebar select:focus, #toolbar select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#voices-panel {
  grid-area: voices;
  background: var(--bg-2);
  border-right: 1px solid var(--grid);
  overflow: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--grid-strong) transparent;
}
/* Slim webkit scrollbar for the sidebar (and any overflowing inner element). */
#voices-panel::-webkit-scrollbar,
#voices-panel *::-webkit-scrollbar { width: 6px; height: 6px; }
#voices-panel::-webkit-scrollbar-track,
#voices-panel *::-webkit-scrollbar-track { background: transparent; }
#voices-panel::-webkit-scrollbar-thumb,
#voices-panel *::-webkit-scrollbar-thumb {
  background: var(--grid-strong);
  border-radius: 3px;
}
#voices-panel::-webkit-scrollbar-thumb:hover,
#voices-panel *::-webkit-scrollbar-thumb:hover { background: var(--accent); }
#voices-panel h3 {
  margin: 10px 0 6px; font-size: 11px; text-transform: uppercase;
  color: var(--fg-dim); letter-spacing: 0.08em;
}
#voices-panel h3:first-child { margin-top: 0; }

/* Collapsible sidebar sections */
#voices-panel .panel {
  border-top: 1px solid var(--grid-strong);
  padding: 6px 0;
}
#voices-panel .panel:first-of-type { border-top: 0; padding-top: 0; }
#voices-panel .panel > summary {
  list-style: none;
  cursor: pointer;
  font-size: 11px; text-transform: uppercase;
  color: var(--fg-dim); letter-spacing: 0.08em;
  padding: 6px 4px;
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
  font-weight: 600;
}
#voices-panel .panel > summary::-webkit-details-marker { display: none; }
#voices-panel .panel > summary:hover { color: var(--fg); }
#voices-panel .panel > summary .caret {
  transition: transform 0.18s ease;
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 5px;
  font-size: 0; color: var(--fg-dim);
  background: var(--accent-soft);
}
#voices-panel .panel > summary .caret::before {
  content: ""; display: block;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
#voices-panel .panel[open] > summary .caret { transform: rotate(180deg); color: var(--accent); }
#voices-panel .panel[open] > summary { color: var(--fg); }
#voices-panel .panel-body { padding: 4px 0 6px; }
#voices-panel .panel-hint {
  margin: 0 0 8px; font-size: 11px; color: var(--fg-dim); line-height: 1.4;
}
.subpanel { margin: 4px 0; }
.subpanel > summary {
  list-style: none; cursor: pointer; font-size: 11px; color: var(--fg-dim);
  padding: 4px 6px; user-select: none;
  display: flex; align-items: center; gap: 6px;
  border-radius: 6px;
}
.subpanel > summary:hover { background: var(--accent-soft); color: var(--fg); }
.subpanel > summary::-webkit-details-marker { display: none; }
.subpanel > summary .caret { transition: transform 0.15s ease; font-size: 10px; line-height: 1; opacity: 0.7; }
.subpanel > summary .caret:empty::before { content: "▾"; }
.subpanel[open] > summary .caret { transform: rotate(180deg); }
.subpanel > summary .sub-title { font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; font-size: 10px; }
.subpanel-list { list-style: none; padding: 4px 0 6px 14px; margin: 0; display: grid; gap: 4px; }
.subpanel-list li { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--fg); }
.subpanel-list input { accent-color: var(--accent); }
.cols-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px;
  font-size: 11px; padding: 4px 0;
}
.cols-list label {
  display: flex; align-items: center; gap: 4px;
  color: var(--fg); cursor: pointer;
}
.cols-list input { accent-color: var(--accent); }

#layers-list { list-style: none; padding: 0; margin: 0 0 10px; }
#layers-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 4px; font-size: 12px;
}
#layers-list input { accent-color: var(--accent); }

/* Left-panel field rows (sliders / number inputs with label above) */
#voices-panel .field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--fg-dim);
  margin: 4px 0 10px;
}
#voices-panel .field .row {
  display: flex; align-items: center; gap: 6px;
}
#voices-panel .field input[type="range"] { flex: 1; accent-color: var(--accent); }
#voices-panel .field input[type="number"],
#voices-panel .field select {
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: var(--radius-sm);
  padding: 4px 8px; font-size: 12px; width: 100%;
}
#voices-panel .field .num {
  min-width: 26px; text-align: right;
  color: var(--fg); font-variant-numeric: tabular-nums;
}
#voices-panel #preset {
  width: 100%;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px; font-size: 12px;
  margin-bottom: 8px;
}
.export-panel { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field.row-inline { flex-direction: row; align-items: center; gap: 6px; }
.export-panel #btn-export,
.export-panel #btn-data-export {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 8px 12px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: filter 0.12s ease, transform 0.06s ease;
}
.export-panel #btn-export:hover,
.export-panel #btn-data-export:hover { filter: brightness(1.05); }
.export-panel #btn-export:active,
.export-panel #btn-data-export:active { transform: translateY(1px); }
.export-panel #btn-export[disabled],
.export-panel #btn-data-export[disabled] { opacity: 0.6; cursor: progress; }
body:not(.theme-dark) .export-panel #btn-export,
body:not(.theme-dark) .export-panel #btn-data-export { color: #ffffff; }
.status-note {
  font-size: 11px; color: var(--fg-dim);
  margin: 2px 0 10px; min-height: 14px;
  font-style: italic;
}

#preset select {
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 12px;
}
#voices-list { list-style: none; padding: 0; margin: 0; }
#voices-list li {
  display: grid;
  /* swatch | name | mute | solo | chord-source (♪) | timbre picker.
     All controls fit on one line; the name column flexes. */
  grid-template-columns: 14px minmax(0, 1fr) auto auto auto auto;
  gap: 6px 6px; align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--grid);
  font-size: 12px;
  flex-wrap: nowrap;
  position: relative;
}
#voices-list li.voice-row-dim { opacity: 0.45; }
#voices-list li.voice-row-dim .name { font-style: italic; }
/* Compact icon-button + popup menu for the per-voice instrument bank.
   The <details> trick gives us a click-to-open dropdown without any
   third-party UI library. */
#voices-list .timbre-picker { position: relative; }
#voices-list .timbre-picker > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 22px; font-size: 14px; line-height: 1;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: 5px;
}
#voices-list .timbre-picker > summary::-webkit-details-marker { display: none; }
#voices-list .timbre-picker > summary:hover { border-color: var(--accent); }
#voices-list .timbre-picker[open] > summary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
}
#voices-list .timbre-picker-menu {
  position: absolute; right: 0; top: 100%;
  margin-top: 4px; padding: 4px;
  min-width: 160px; max-height: 320px; overflow-y: auto;
  background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--grid-strong); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  z-index: 50;
}
#voices-list .timbre-picker-family {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--fg-dim); padding: 4px 6px 2px;
}
#voices-list .timbre-picker-item {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 4px 6px; font-size: 11px; text-align: left;
  background: transparent; color: var(--fg);
  border: 0; border-radius: 4px; cursor: pointer;
}
#voices-list .timbre-picker-item:hover { background: var(--bg-3); }
#voices-list .timbre-picker-item.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
#voices-list .timbre-picker-item .ti-icon { width: 16px; text-align: center; }
#voices-list .swatch {
  width: 12px; height: 12px; border-radius: 3px;
}
#voices-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#voices-list button {
  font-size: 10px; padding: 2px 7px;
  background: var(--bg-3); color: var(--fg-dim);
  border: 1px solid var(--grid-strong); border-radius: 5px; cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
#voices-list button:hover { color: var(--fg); border-color: var(--accent); }
#voices-list button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
#canvas {
  display: block; width: 100%; height: 100%;
  cursor: crosshair;
}

#tooltip {
  position: fixed;
  background: var(--bg-2);
  color: var(--fg);
  padding: 4px 8px; border-radius: 4px;
  font-size: 11px; pointer-events: none;
  white-space: nowrap;
  border: 1px solid var(--grid-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  z-index: 9999;
}
body.theme-dark #tooltip { background: rgba(0,0,0,0.85); }

#minimap-wrap {
  grid-area: mini;
  background: var(--bg-2);
  border-top: 1px solid var(--grid);
}
#minimap {
  display: block; width: 100%; height: 100%;
  cursor: pointer;
}

#dropzone[hidden] { display: none !important; }
#dropzone {
  position: fixed; inset: 0;
  background: rgba(20,22,27,0.85);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--accent);
  z-index: 10;
  pointer-events: auto;
  border: 4px dashed var(--accent);
}

/* ---------- Transport panel (BAR / BEAT / TEMPO / KEY / TIME) ---------- */
.transport {
  display: inline-flex; align-items: stretch;
  background: var(--bg-elev);
  border: 1px solid var(--grid-strong);
  border-radius: var(--radius-md);
  padding: 0 4px;
  height: 44px;
  box-shadow: var(--shadow-sm);
  font-variant-numeric: tabular-nums;
}
.transport .t-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 11px; min-width: 52px;
}
.transport .t-num {
  font-size: 20px; line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  font-weight: 600; letter-spacing: 0.01em;
  font-feature-settings: "tnum" 1;
}
.transport .t-num.small {
  font-size: 13px; font-weight: 500;
  background: none; -webkit-text-fill-color: var(--fg); color: var(--fg);
}
.transport .t-lab {
  margin-top: 2px; font-size: 9px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--fg-dim); font-weight: 600;
}
.transport .t-sep {
  width: 1px; margin: 8px 4px;
  background: var(--grid-strong);
}
.transport .t-time .t-num {
  background: none; -webkit-text-fill-color: var(--fg); color: var(--fg);
  font-weight: 500;
}
body.theme-dark .transport { background: linear-gradient(180deg, #11131c, #181c2a); }
@media (max-width: 1280px) {
  .transport { height: 38px; }
  .transport .t-cell { padding: 0 8px; min-width: 42px; }
  .transport .t-num { font-size: 17px; }
  .transport .t-num.small { font-size: 12px; }
  .transport .t-lab { font-size: 8px; letter-spacing: 0.12em; }
}
/* Compact transport: combines BAR+BEAT into one bar.beat cell and
   shrinks the TEMPO/TS/KEY trio so the toolbar still fits the
   Speed/Volume/Zoom controls + Open MIDI button on a 100% Mac display. */
@media (max-width: 1480px) {
  .transport.compact .t-bar .t-lab::after { content: ".BEAT"; }
  .transport.compact .t-beat { display: none; }
  .transport.compact .t-sep:first-of-type { display: none; }
  .transport.compact .t-cell { padding: 0 6px; min-width: 36px; }
  .transport.compact .t-num { font-size: 15px; }
  .transport.compact .t-num.small { font-size: 11px; }
  .transport.compact .t-lab { font-size: 7.5px; letter-spacing: 0.10em; }
  /* Tighten Speed/Volume/Zoom: hide the labels, keep slider + number. */
  #toolbar .ctrl .ctrl-label { display: none; }
  #toolbar .ctrl input[type="range"] { width: 90px; }
}
@media (max-width: 1000px) {
  .transport .t-time { display: none; }   /* keep BAR/BEAT/TEMPO/TS/KEY only */
}
@media (max-width: 760px) {
  .transport .t-sep { display: none; }
  .transport .t-cell { padding: 0 6px; min-width: 36px; }
}

/* ---------- Modern seek bar with progress fill ---------- */
.seek-wrap {
  position: relative; flex: 1 1 auto;
  height: 18px;
  display: flex; align-items: center;
}
.seek-wrap::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%;
  height: 5px; transform: translateY(-50%);
  background: var(--grid); border-radius: 999px;
}
.seek-wrap .seek-fill {
  position: absolute; left: 0; top: 50%;
  height: 5px; transform: translateY(-50%);
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  box-shadow: 0 0 8px var(--accent-soft);
  pointer-events: none;
  transition: width 0.06s linear;
}
.seek-wrap input[type="range"] {
  position: relative;
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; margin: 0;
  background: transparent; outline: none;
}
.seek-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; background: transparent;
}
.seek-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -4.5px;
  border-radius: 50%; background: var(--bg-elev);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform 0.08s ease;
}
.seek-wrap input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
.seek-wrap input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-elev); border: 2px solid var(--accent);
  box-shadow: var(--shadow-sm); cursor: pointer;
}

/* Toolbar transport group keeps a tighter gap than other groups. */
#toolbar .transport-group { gap: 6px; }

/* =====================================================================
   AI insights plugin — scoped under #panel-ai and #ai-settings-dialog.
   Nothing here should affect any other panel.
   ===================================================================== */
#panel-ai .panel-body { display: flex; flex-direction: column; gap: 6px; }
.ai-banner {
  background: var(--accent-soft); color: var(--fg);
  padding: 6px 8px; border-radius: var(--radius-sm);
  font-size: 11.5px; line-height: 1.4;
}
.ai-banner:empty { display: none; }
.ai-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ai-row-end { justify-content: flex-end; }
.ai-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ai-actions .ai-primary { grid-column: 1 / -1; }
.ai-btn {
  appearance: none; background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--grid); border-radius: var(--radius-sm);
  padding: 6px 10px; font: inherit; font-size: 12px;
  cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease;
}
.ai-btn:hover { background: var(--bg-elev); border-color: var(--grid-strong); }
.ai-btn-mini { padding: 4px 8px; font-size: 11.5px; }
.ai-btn.ai-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: var(--shadow-glow);
}
.ai-btn.ai-primary:hover { filter: brightness(1.05); }
.ai-mini-label { color: var(--fg-dim); font-size: 11.5px; }
.ai-num {
  width: 56px; padding: 3px 5px; font: inherit; font-size: 12px;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid); border-radius: 6px;
}
.ai-text-input {
  flex: 1 1 auto; min-width: 0;
  padding: 5px 8px; font: inherit; font-size: 12px;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid); border-radius: 6px;
}
.ai-text-input:focus { outline: none; border-color: var(--accent); }
.ai-output {
  margin-top: 4px; padding: 8px 10px;
  background: var(--bg-elev); border: 1px solid var(--grid);
  border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.55;
  max-height: 320px; overflow: auto;
}
.ai-output h1, .ai-output h2, .ai-output h3, .ai-output h4 {
  margin: 0.6em 0 0.3em; line-height: 1.25;
}
.ai-output h3 { font-size: 13px; color: var(--accent); }
.ai-output p { margin: 0.4em 0; }
.ai-output ul, .ai-output ol { margin: 0.3em 0 0.3em 1.2em; padding: 0; }
.ai-output code {
  background: var(--bg-3); padding: 1px 5px;
  border-radius: 4px; font-size: 11.5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.ai-output pre {
  background: var(--bg-3); padding: 8px; border-radius: 6px;
  overflow: auto; font-size: 11.5px; margin: 0.5em 0;
}
.ai-output pre code { background: transparent; padding: 0; }
.ai-empty { color: var(--fg-dim); font-style: italic; }
.ai-busy { color: var(--fg-dim); }
.ai-error { color: #dc2626; }
body.theme-dark .ai-error { color: #f87171; }
.ai-bar-link {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px dashed var(--accent); cursor: pointer;
}
.ai-bar-link:hover { background: var(--accent-soft); border-radius: 3px; }

.ai-sections-wrap {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 360px; overflow: auto;
}
.ai-section-card {
  border: 1px solid var(--grid); border-radius: var(--radius-sm);
  background: var(--bg-elev); padding: 6px 8px;
  font-size: 12px; line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ai-section-card.ai-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.ai-section-head {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.ai-section-jump {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  text-decoration: none; font-size: 10px;
}
.ai-section-jump:hover { background: var(--accent); color: #fff; }
.ai-section-label {
  background: var(--accent); color: #fff;
  padding: 1px 6px; border-radius: 4px;
  font-size: 10.5px; font-weight: 700;
}
.ai-section-title { font-weight: 600; }
.ai-section-bars { color: var(--fg-dim); font-size: 11px; margin-left: auto; }
.ai-section-desc { color: var(--fg-dim); font-size: 11.5px; margin-top: 3px; }
.ai-section-guide { margin-top: 4px; }
.ai-section-guide p { margin: 0.25em 0; }

.ai-chat-log {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 220px; overflow: auto;
  margin: 4px 0; padding: 4px;
  background: var(--bg-3); border-radius: 6px;
}
.ai-chat-log:empty { display: none; }
.ai-bubble {
  padding: 5px 8px; border-radius: 8px; font-size: 12px;
  line-height: 1.45; max-width: 95%;
}
.ai-bubble.ai-user {
  background: var(--accent-soft); color: var(--fg); align-self: flex-end;
}
.ai-bubble.ai-assistant {
  background: var(--bg-elev); border: 1px solid var(--grid);
  color: var(--fg); align-self: flex-start;
}
.ai-bubble p { margin: 0.2em 0; }

/* settings dialog */
#ai-settings-dialog {
  border: 1px solid var(--grid); border-radius: var(--radius-md);
  background: var(--bg-2); color: var(--fg);
  box-shadow: var(--shadow-md);
  padding: 0; min-width: 460px; max-width: 92vw;
}
#ai-settings-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.ai-settings-form {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px 18px;
}
.ai-settings-form h3 { margin: 0 0 4px; font-size: 14px; color: var(--accent); }
.ai-settings-form .field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--fg-dim); }
.ai-settings-form input, .ai-settings-form select {
  padding: 5px 8px; font: inherit; font-size: 12.5px;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--grid); border-radius: 6px;
}
.ai-settings-form input:focus, .ai-settings-form select:focus { outline: none; border-color: var(--accent); }
.ai-hint { font-size: 11px; color: var(--fg-dim); margin: -2px 0 4px; line-height: 1.4; }
.ai-hint code { background: var(--bg-3); padding: 0 4px; border-radius: 3px; font-size: 11px; }
.ai-set-status:empty { display: none; }
