/* =========================================================================
   Typhon Editor — modern clean theme
   Light by default, .dark on <body> switches to a dark palette.
   All colour decisions flow through custom properties.
   ========================================================================= */

:root {
  /* neutral surfaces */
  --bg:        #eef1f5;
  --bg-2:      #e4e8ee;
  --surface:   #ffffff;
  --surface-2: #f7f9fc;
  --border:    #dce1e9;
  --border-2:  #c9d0db;

  /* text */
  --text:      #1b2330;
  --text-2:    #5b6573;
  --text-3:    #8a93a3;

  /* brand accent */
  --accent:     #2f6df4;
  --accent-ink: #ffffff;
  --accent-soft:#e7efff;

  --danger:  #e5484d;
  --ok:      #2b9d6b;
  --warn:    #d99311;

  /* section accents */
  --c-osc:    #3b82f6;
  --c-filter: #8b5cf6;
  --c-perf:   #6b7280;
  --c-feg:    #ec4899;
  --c-aeg:    #f97316;
  --c-fx1:    #14b8a6;
  --c-fx2:    #06b6d4;
  --c-fx3:    #0ea5e9;
  --c-mod:    #22c55e;
  --c-seq:    #eab308;
  --c-default:#64748b;

  --radius:   14px;
  --radius-sm:9px;
  --shadow:   0 1px 2px rgba(20,30,50,.06), 0 6px 20px rgba(20,30,50,.06);
  --shadow-lg:0 12px 40px rgba(20,30,50,.14);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

body.dark {
  --bg:        #0e1117;
  --bg-2:      #0a0d12;
  --surface:   #161b24;
  --surface-2: #1c222d;
  --border:    #262d3a;
  --border-2:  #333c4c;
  --text:      #e7ecf3;
  --text-2:    #9aa6b6;
  --text-3:    #6b7686;
  --accent:    #4b86ff;
  --accent-soft:#16243f;
  --shadow:   0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  --shadow-lg:0 16px 50px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.45;
}

/* ----- top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  font-size: 22px;
  color: var(--accent);
  filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--accent) 40%, transparent));
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text strong { letter-spacing: .14em; font-size: 15px; }
.brand-text small { color: var(--text-3); font-size: 11px; letter-spacing: .08em; }

.devices { display: flex; gap: 10px; flex: 1; min-width: 280px; }
.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
  flex: 1;
}
.field.narrow { flex: 0 0 86px; }
.field select {
  font-family: var(--font);
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  cursor: pointer;
  max-width: 100%;
}
.field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input[type="number"] {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  width: 100%;
}
.field input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.preset { display: flex; gap: 10px; align-items: center; }
.preset .btn {
  margin-bottom: 0;
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
}

.actions { display: flex; gap: 7px; flex-wrap: wrap; }

.btn {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border-2)); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ----- status bar ------------------------------------------------------- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  flex-wrap: wrap;
}
.statusbar .status { flex: 1 1 0; min-width: 0; }
.statusbar .leds { flex: 1 1 0; justify-content: flex-end; }

/* centered MIDI device pickers, compact inline labels */
.midi-devices {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.field-inline select {
  font-family: var(--font);
  font-size: 12.5px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  height: 32px;
  padding: 0 7px;
  cursor: pointer;
  max-width: 150px;
}
.field-inline select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-inline.narrow select { max-width: 60px; }
.field-inline input[type="number"] {
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  height: 32px;
  padding: 0 7px;
  width: 54px;
}
.field-inline input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.leds { display: flex; gap: 16px; }
.led-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
}
.led {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--border-2);
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .25);
  transition: background .07s ease, box-shadow .25s ease;
}
.led.in.lit  { background: #22c55e; box-shadow: 0 0 8px #22c55e, 0 0 2px #22c55e; }
.led.out.lit { background: #f59e0b; box-shadow: 0 0 8px #f59e0b, 0 0 2px #f59e0b; }
.status { color: var(--text-2); display: inline-flex; align-items: center; gap: 8px; }
.status::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3);
}
.status.ok::before  { background: var(--ok);  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.status.warn::before{ background: var(--warn); }
.status.err::before { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }

/* ----- out-of-sync banner (gentle, informational) ---------------------- */
.sync-banner {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 18px;
  font-size: 12px;
  color: var(--text-2);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  border-bottom: 1px solid var(--border);
}
.sync-banner.hidden { display: none; }
.sync-banner-icon {
  flex: 0 0 auto;
  width: 16px; height: 16px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; line-height: 1;
  color: var(--accent);
  border: 1.5px solid color-mix(in srgb, var(--accent) 50%, transparent);
}
.sync-banner-text { flex: 1; line-height: 1.4; }
.sync-banner-close {
  flex: 0 0 auto;
  font-family: var(--font);
  font-size: 15px; line-height: 1;
  color: var(--text-3);
  background: transparent; border: none; border-radius: 6px;
  width: 22px; height: 22px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.sync-banner-close:hover { background: var(--surface-2); color: var(--text-2); }

/* ----- tabs ------------------------------------------------------------- */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 12px 18px 0;
  flex-wrap: wrap;
}
.tab-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 550;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 9px 16px;
  cursor: pointer;
  position: relative;
  transition: color .15s ease, background .15s ease;
}
.tab-btn:hover { color: var(--text); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.tab-btn.active {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--border);
}
.tab-btn.active::after {
  content: "";
  position: absolute; left: 14px; right: 14px; top: 0; height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.tab-panels {
  flex: 1;
  padding: 18px;
  background: linear-gradient(var(--surface), var(--surface));
  border-top: 1px solid var(--border);
  margin-top: -1px;
}
.tab-panel { display: none; animation: fade .18s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ----- groups / cards --------------------------------------------------- */
.group-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); /* fallback */
}
/* Each section fills the full content width with a fixed number of boxes. */
.group-grid.cols-1 { grid-template-columns: minmax(0, 520px); }
.group-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.group-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* medium screens: a 3-up section steps down to 2-up */
@media (max-width: 1080px) {
  .group-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* small screens: multi-column sections stack vertically */
@media (max-width: 760px) {
  .group-grid.cols-2,
  .group-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}
.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.group {
  --accent-c: var(--c-default);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.group::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent-c);
  opacity: .9;
}
.group-title {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent-c);
}
.mod-sub {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 6px 0 8px;
}

/* accent map */
.accent-osc    { --accent-c: var(--c-osc); }
.accent-filter { --accent-c: var(--c-filter); }
.accent-perf   { --accent-c: var(--c-perf); }
.accent-feg    { --accent-c: var(--c-feg); }
.accent-aeg    { --accent-c: var(--c-aeg); }
.accent-fx1    { --accent-c: var(--c-fx1); }
.accent-fx2    { --accent-c: var(--c-fx2); }
.accent-fx3    { --accent-c: var(--c-fx3); }
.accent-mod    { --accent-c: var(--c-mod); }
.accent-seq    { --accent-c: var(--c-seq); }
.accent-default{ --accent-c: var(--c-default); }

/* ----- envelope visualiser --------------------------------------------- */
.env-graph {
  margin: 0 0 14px;
  background: color-mix(in srgb, var(--accent-c) 6%, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
}
.env-svg { width: 100%; height: 70px; display: block; }
.env-base { stroke: var(--border-2); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.env-area { fill: color-mix(in srgb, var(--accent-c) 16%, transparent); stroke: none; }
.env-line {
  fill: none;
  stroke: var(--accent-c);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 1px 2px color-mix(in srgb, var(--accent-c) 35%, transparent));
}
/* envelope nodes: a coloured ring with a light core, drawn as round stroke
   caps so they stay circular no matter how the svg is stretched */
.env-dot-ring, .env-dot-core {
  fill: none;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.env-dot-ring { stroke: var(--accent-c); stroke-width: 8; }
.env-dot-core { stroke: color-mix(in srgb, var(--accent-c) 6%, var(--surface)); stroke-width: 4; }

.knob-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 12px 8px;
  justify-items: center;
}
.dest-grid { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }

/* ----- step-sequencer editor ------------------------------------------- */
.stepseq { margin: 2px 0 14px; }
.stepseq-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stepseq-head .mod-sub { margin: 0; }
.stepseq-count { display: flex; align-items: center; gap: 6px; }
.stepseq-btn {
  font-family: var(--font); font-size: 14px; line-height: 1;
  width: 22px; height: 22px; border-radius: 6px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-2);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.stepseq-btn:hover { border-color: var(--accent-c); color: var(--accent-c); }
.stepseq-num { font-family: var(--mono); font-size: 12px; min-width: 16px; text-align: center; color: var(--text-2); }

.stepseq-bars {
  display: flex; align-items: flex-end; gap: 4px;
  height: 84px; margin: 8px 0 6px; padding: 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-2); border: 1px solid var(--border);
  touch-action: none; cursor: crosshair;
}
.stepseq-bar {
  position: relative; flex: 1; height: 100%; min-width: 8px;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 4px; overflow: hidden;
}
.stepseq-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--accent-c);
  box-shadow: 0 0 6px color-mix(in srgb, var(--accent-c) 45%, transparent);
  transition: height .04s linear;
}
.stepseq-bar-idx {
  position: absolute; top: 2px; left: 0; right: 0; text-align: center;
  font-family: var(--mono); font-size: 8px; color: var(--text-3); pointer-events: none;
}
.stepseq-hint { font-size: 11px; color: var(--text-3); line-height: 1.35; }

/* ----- knob ------------------------------------------------------------- */
.knob {
  --accent-c: var(--c-default);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  position: relative;
}
.knob-dial {
  width: 56px; height: 56px;
  cursor: ns-resize;
  touch-action: none;
  border-radius: 50%;
  outline: none;
  transition: transform .08s ease;
}
.dest-grid .knob-dial { width: 46px; height: 46px; }
.knob-dial:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.knob-dial.dragging { transform: scale(1.06); }

.knob-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.knob-track {
  fill: none;
  stroke: var(--border-2);
  stroke-width: 5;
  stroke-linecap: round;
}
.knob-fill {
  fill: none;
  stroke: var(--accent-c);
  stroke-width: 5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--accent-c) 45%, transparent));
}
.knob-cap {
  fill: var(--surface);
  stroke: var(--border-2);
  stroke-width: 1;
}
body.dark .knob-cap { fill: var(--surface-2); }
.knob-pointer {
  stroke: var(--accent-c);
  stroke-width: 3;
  stroke-linecap: round;
}
.knob-cc {
  position: absolute;
  inset: 0;
  display: none;
}

.knob-name {
  font-size: 11px;
  font-weight: 550;
  color: var(--text-2);
  text-align: center;
  line-height: 1.15;
  max-width: 84px;
}
.knob-value {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 7px;
  min-width: 34px;
  text-align: center;
  cursor: text;
}
.knob-value:hover { border-color: var(--accent); }
.knob-value-input {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 1px 4px;
  width: 46px;
  text-align: center;
  outline: none;
}

/* MIDI learn states */
.knob-learn-badge {
  position: absolute;
  top: -4px; right: -2px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 6px;
  padding: 0 4px;
  pointer-events: none;
}
.knob.learned .knob-cap { stroke: var(--accent); }
.knob.armed .knob-dial { box-shadow: 0 0 0 3px var(--accent), 0 0 14px color-mix(in srgb, var(--accent) 60%, transparent); border-radius: 50%; }
body.learn-mode .knob-dial { cursor: crosshair; }
body.learn-mode .knob-dial:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent); }

/* ----- select / toggle controls ---------------------------------------- */
.ctrl-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.ctrl { --accent-c: var(--c-default); position: relative; display: flex; flex-direction: column; gap: 4px; }
.select-ctrl { flex: 1; min-width: 130px; }
.ctrl-name { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.ctrl-select {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent-c);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  cursor: pointer;
}
.ctrl-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.toggle-ctrl { min-width: 92px; }
.ctrl-toggle {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: none; cursor: pointer; padding: 3px 0;
  font-family: var(--font);
}
.toggle-track {
  width: 38px; height: 20px; border-radius: 999px;
  background: var(--border-2); position: relative; flex: 0 0 auto;
  transition: background .15s ease;
}
.toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow); transition: transform .15s ease;
}
.ctrl-toggle.on .toggle-track { background: var(--accent-c); }
.ctrl-toggle.on .toggle-knob { transform: translateX(18px); }
.toggle-state { font-size: 12px; font-weight: 600; color: var(--text-2); }
.ctrl-toggle.on .toggle-state { color: var(--accent-c); }

.ctrl.learned .ctrl-select, .ctrl.learned .ctrl-toggle .toggle-track { box-shadow: 0 0 0 1px var(--accent); }
.ctrl.armed { box-shadow: 0 0 0 2px var(--accent), 0 0 14px color-mix(in srgb, var(--accent) 50%, transparent); border-radius: var(--radius-sm); }
.ctrl .knob-learn-badge { top: -6px; right: -4px; }
body.learn-mode .ctrl-select, body.learn-mode .ctrl-toggle { cursor: crosshair; }

/* ----- MIDI panel / monitor -------------------------------------------- */
.midi-panel {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}
.hint-text { color: var(--text-2); font-size: 12.5px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.monitor { display: flex; flex-direction: column; gap: 8px; }
.monitor-bar { display: flex; gap: 8px; align-items: center; }
.monitor-bar select { padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); }
.monitor-count { margin-left: auto; color: var(--text-3); font-size: 12px; font-family: var(--mono); }
.monitor-list {
  font-family: var(--mono);
  font-size: 12px;
  height: 360px;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
}
.mon-row {
  display: grid;
  grid-template-columns: 36px 44px 88px 1fr;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 5px;
  align-items: baseline;
}
.mon-row:nth-child(even) { background: color-mix(in srgb, var(--surface) 55%, transparent); }
.mon-dir { font-weight: 700; font-size: 10px; }
.mon-dir-in  .mon-dir { color: #22c55e; }
.mon-dir-out .mon-dir { color: #f59e0b; }
.mon-ch { color: var(--text-3); }
.mon-type { color: var(--accent); font-weight: 600; }
.mon-detail { color: var(--text); }
.mon-param { color: var(--c-mod); }
.mon-noteon .mon-type { color: var(--c-aeg); }
.mon-noteoff .mon-type { color: var(--text-3); }
.mon-pitchbend .mon-type { color: var(--c-filter); }

/* ----- keyboard --------------------------------------------------------- */
.keyboard-host {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  bottom: 0;
  z-index: 40;
}
.keyboard-host.hidden { display: none; }

.keyboard { display: flex; align-items: stretch; gap: 14px; padding: 12px 18px; }

.kb-perf { display: flex; gap: 12px; }
.kb-strip { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.kb-strip-track {
  width: 26px; height: 96px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 13px;
  position: relative;
  cursor: ns-resize;
  touch-action: none;
}
.kb-strip-thumb {
  position: absolute;
  left: 2px; right: 2px;
  height: 22px;
  bottom: 0;
  background: var(--accent);
  border-radius: 11px;
  box-shadow: var(--shadow);
}
.kb-strip-label { font-size: 10px; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }

.kb-ctrls { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.kb-oct {
  font-family: var(--font); font-size: 12px; font-weight: 550;
  background: var(--surface); border: 1px solid var(--border-2);
  color: var(--text); border-radius: var(--radius-sm); padding: 5px 9px; cursor: pointer;
}
.kb-oct:hover { border-color: var(--accent); }
.kb-octlabel { font-family: var(--mono); font-size: 11px; color: var(--text-2); text-align: center; }
.kb-vel { font-size: 10px; color: var(--text-3); display: flex; flex-direction: column; gap: 2px; }
.kb-vel input { width: 90px; accent-color: var(--accent); }

.kb-keys-wrap { flex: 1; overflow-x: auto; }
.kb-keys {
  position: relative;
  display: flex;
  height: 120px;
  min-width: 420px;
  user-select: none;
}
.kb-key {
  position: relative;
  touch-action: none;
}
.kb-key.white {
  flex: 1;
  background: linear-gradient(var(--surface), #f1f4f9);
  border: 1px solid var(--border-2);
  border-radius: 0 0 6px 6px;
  margin-right: -1px;
}
body.dark .kb-key.white { background: linear-gradient(#e9edf3, #cdd4df); }
.kb-key.white.on, .kb-key.white.ext {
  background: linear-gradient(color-mix(in srgb, var(--accent) 30%, #fff), color-mix(in srgb, var(--accent) 50%, #fff));
}
.kb-key.black {
  position: absolute;
  top: 0;
  height: 64%;
  background: linear-gradient(#3a4150, #11161f);
  border-radius: 0 0 5px 5px;
  z-index: 2;
  box-shadow: 0 3px 6px rgba(0,0,0,.35);
}
.kb-key.black.on, .kb-key.black.ext {
  background: linear-gradient(color-mix(in srgb, var(--accent) 60%, #222), var(--accent));
}
.kb-key-label {
  position: absolute;
  bottom: 5px; left: 0; right: 0;
  text-align: center;
  font-size: 9px;
  color: var(--text-3);
  pointer-events: none;
}

/* ----- toast ------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 168px;
  transform: translate(-50%, 16px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ----- modal (draggable floating panel) -------------------------------- */
.modal {
  position: fixed;
  z-index: 200;
  width: 360px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in .16s ease;
}
.modal.hidden { display: none; }
@keyframes modal-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
/* the randomizer is wider so its section locks fit in two columns */
#random-modal { width: 520px; }

.modal-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.modal-head.dragging { cursor: grabbing; }
.modal-grip { color: var(--text-3); font-size: 13px; letter-spacing: -2px; }
.modal-title {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  flex: 1;
}
.modal-close {
  font-family: var(--font);
  font-size: 18px;
  line-height: 1;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: 7px;
  width: 26px; height: 26px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.modal-close:hover { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.modal-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-field { display: flex; flex-direction: column; gap: 7px; }
.modal-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3);
}
.modal-strength-val { font-family: var(--mono); font-size: 13px; color: var(--accent); font-weight: 700; }
.modal-range { width: 100%; accent-color: var(--accent); cursor: pointer; }
.modal-hint { margin: 0; font-size: 11.5px; color: var(--text-3); line-height: 1.45; }
.modal-hint code { font-family: var(--mono); font-size: 11px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.modal-input {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
}
.modal-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.modal-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); font-weight: 600;
}
.modal-section-head small { text-transform: none; letter-spacing: 0; color: var(--text-3); font-weight: 400; }
.modal-section-actions { display: flex; gap: 6px; }
.btn-mini { padding: 4px 8px; font-size: 11px; }

.modal-sections { column-count: 2; column-gap: 20px; }
.modal-sec-col { display: flex; flex-direction: column; gap: 1px; break-inside: avoid; margin-bottom: 14px; }
.modal-sec-tab {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3);
  margin-bottom: 3px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.modal-lock {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 6px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.modal-lock:hover { background: var(--surface-2); }
.modal-lock input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; flex: 0 0 auto; }
.modal-lock-name { color: var(--text); }
.modal-lock input:checked + .modal-lock-name { color: var(--text-3); text-decoration: line-through; }
.modal-lock-sub { padding-left: 20px; }
.modal-lock-sub .modal-lock-name { font-size: 12px; color: var(--text-2); }

.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.modal-foot-hint { font-size: 11.5px; color: var(--text-3); }

/* ----- responsive ------------------------------------------------------- */
@media (max-width: 760px) {
  .topbar { gap: 10px; }
  .devices { order: 3; min-width: 100%; }
  .midi-panel { grid-template-columns: 1fr; }
  .actions .btn { padding: 8px 10px; }
}

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { height: 10px; width: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; }
