:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel2: #1c2330;
    --border: #30363d;
    --fg: #e6edf3;
    --dim: #8b949e;
    --accent: #58a6ff;
    --accent2: #3fb950;
    --warn: #d29922;
    --danger: #f85149;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--fg);
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #1c2330, #0d1117);
    gap: 16px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 18px;
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.button-area {
    margin-left: auto;
    text-align: right;
}

.about-dialog-body {
    font-size: 12px;
}

dialog .dialog-header,
dialog .dialog-footer {
    cursor: grab;
    touch-action: none;
    user-select: none;
}

dialog.is-dragging .dialog-header,
dialog.is-dragging .dialog-footer {
    cursor: grabbing;
}

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

.dialog-body:not(.about-dialog-body) p {
    font-size: 14px;
}

.about-website-link,
.about-website-link:hover {
    color: var(--accent);
    text-decoration: none;
}

.about-website-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.title-icon {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button-with-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.button-icon {
    display: block;
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button-icon[hidden] {
    display: none;
}

header .sub {
    color: var(--dim);
    font-size: 12px;
}

.controls {
    margin-left: auto;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.project-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.project-controls label {
    grid-column: 1 / -1;
    color: var(--dim);
    font-size: 12px;
}

.project-controls select {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 7px 10px;
    background-color: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    font: inherit;
    font-size: 13px;
}

.project-controls button {
    min-width: 0;
    padding-right: 6px;
    padding-left: 6px;
}

.project-edit-fields {
    display: grid;
    gap: 12px;
}

.project-edit-fields label {
    display: block;
    margin-bottom: 5px;
    color: var(--dim);
    font-size: 12px;
}


.project-archive-tools {
    grid-column: 1 / -1;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.project-archive-tools summary {
    color: var(--dim);
    cursor: pointer;
    font-size: 12px;
    user-select: none;
}

.project-archive-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
}

.project-archive-actions button {
    min-width: 0;
    min-height: 32px;
    padding: 5px;
    font-size: 11px;
    line-height: 1.2;
    white-space: normal;
}

button.primary {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}

button.primary:hover {
    background: #79b8ff;
}

button.success {
    background: var(--accent2);
    color: #000;
    border-color: var(--accent2);
    font-weight: 600;
}

button.success:hover {
    background: #56d364;
}

button.danger {
    border-color: var(--danger);
    color: var(--danger);
}

button.danger:hover:not(:disabled) {
    background: var(--danger);
    color: #000;
}

button.toggle-button[aria-pressed="true"] {
    background: var(--accent2);
    border-color: var(--accent2);
    color: #000;
    font-weight: 600;
}

button.toggle-button[aria-pressed="true"]:hover:not(:disabled):not(.primary):not(.success):not(.danger):not(.active):not(.icon-btn):not(.number-spinner-button):not(.preset-array-remove):not(.preset-array-add) {
    background: #56d364;
    border-color: var(--accent2);
    color: #000;
}

#btnMidiPlay {
    min-width: 85px;
}

#btnSequencerPlay {
    min-width: 85px;
}

#btnMidiControllerConnect {
    min-width: 88px;
}

#btnAutoApplyPreset {
    min-width: 120px;
}

#btnConfirmDeleteProject {
    min-width: 150px;
}

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    flex: 1;
    min-height: 0;
    height: auto;
}

aside {
    width: var(--sidebar-width);
    background: rgba(8, 13, 24, .45);
    border-right: 1px solid #1e2d4a;
    overflow-y: auto;
    padding: 12px;
}

.instrument-toolbar {
    position: sticky;
    top: -12px;
    z-index: 2;
    margin: -12px -12px 12px;
    padding: 12px;
    background: var(--bg);
    border-bottom: 1px solid #1e2d4a;
}

.instrument-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 8px;
}

.instrument-tab {
    padding: 8px 6px;
    background: var(--panel2);
}

.instrument-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.instrument-list-panel[hidden] {
    display: none;
}

.instrument-search-wrap {
    margin-bottom: 0;
}

.instrument-search-wrap .search {
    margin-bottom: 0;
}

.instrument-search-controls {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.instrument-search-controls .search {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
}

.instrument-preset-filter {
    flex: 0 0 84px;
    min-width: 84px;
    padding: 8px 6px;
    white-space: nowrap;
}

.instrument-tab,
.instrument-preset-filter {
    height: 31px;
    padding-top: 0;
    padding-bottom: 0;
}

.search-empty {
    margin: 6px 0 8px;
    padding: 6px 8px;
    color: var(--dim);
    background: rgba(139, 148, 158, .08);
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 11px;
    line-height: 1.4;
    text-align: center;
}

.family[hidden],
.inst[hidden] {
    display: none;
}

.search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 10px;
    font-family: inherit;
    font-size: 13px;
}

.family {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--dim);
    margin: 14px 0 6px;
    padding: 0 6px;
    font-weight: 600;
}

.inst {
    padding: 8px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 8px 3ch;
    column-gap: 8px;
    align-items: center;
    margin-bottom: 2px;
    transition: .12s;
}

.inst:hover {
    background: var(--panel2);
}

.inst.active {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

.inst .instrument-name {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1;
    min-width: 0;
}

.inst .instrument-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
}

.inst .instrument-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.inst .instrument-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inst .instrument-preset-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
}

.inst .instrument-preset-status.is-overridden {
    background: #c2185b;
}

.inst .num {
    width: 3ch;
    font-size: 11px;
    opacity: .6;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.inst.active .num {
    opacity: .75;
}

main {
    overflow-y: auto;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "instrument midi"
        "log log";
    align-content: start;
    gap: 12px;
    padding: 12px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 0;
}

.instrument-card {
    grid-area: instrument;
}

#instrument-name{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    align-items: center;
}

#instrument-name > *{
    min-width: 0;
}

#instrument-name h2,
#instrument-name .meta{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#familyLabel{
    text-align: right;
}

.midi-card {
    grid-area: midi;
}

.log-card {
    grid-area: log;
}

.instrument-card canvas {
    height: 128px;
}

.preset-editor-section {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.preset-editor-section > .meta,
.midi-card > .meta {
    margin-bottom: 8px;
}

.midi-card .actions {
    gap: 6px;
    margin-top: 8px;
}

.midi-transport-row {
    display: grid;
    grid-template-columns: minmax(100px, 1fr) minmax(0, 2.4fr);
    align-items: start;
    gap: 14px;
    margin-top: 12px;
}

.midi-volume-control,
.midi-seek-control {
    min-width: 0;
}

.midi-volume-control label,
.midi-volume-label, .midi-seek-times {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 20px;
    margin-bottom: 4px;
    color: var(--dim);
    font-size: 12px;
}

.midi-volume-control .midi-volume-icon {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
}

.midi-volume-control output {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--dim);
    font-size: 12px;
}

.midi-volume-control input,
.midi-seek-control input {
    width: 100%;
    min-width: 0;
}

.midi-seek-times {
    font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
    .midi-transport-row {
        grid-template-columns: minmax(80px, 1fr) minmax(0, 1.8fr);
        gap: 8px;
    }
}

.midi-card .field {
    margin-top: 8px;
}

.live-waveform {
    margin-top: 12px;
    margin-bottom: 12px;
}

.live-waveform h3 {
    margin: 0 0 6px;
    color: var(--dim);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.live-waveform canvas {
    width: 100%;
    height: 160px;
    display: block;
    background: #0a0e14;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.midi-mode-switch {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 10px;
}

.midi-mode-switch button {
    padding: 6px 10px;
}

.midi-mode-switch button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.midi-mode-switch button.active:hover:not(:disabled) {
    background: #79b8ff;
    border-color: #79b8ff;
    color: #000;
}

.midi-card [role="tabpanel"][hidden] {
    display: none;
}

.sequencer-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.midi-controller-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
}

.midi-controller-settings .field {
    min-width: 0;
}

.midi-controller-settings select {
    width: 100%;
    padding: 6px 32px 6px 10px;
    background-color: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    font-size: 13px;
}

.midi-controller-help {
    margin: 8px 0 0;
    color: var(--dim);
    font-size: 11px;
    line-height: 1.4;
}

.sequencer-settings input[type="number"],
.sequencer-settings input[type="range"] {
    width: 100%;
}

.sequencer-settings output {
    display: block;
    color: var(--dim);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.sequencer-actions {
    margin-top: 10px;
}

.midi-status {
    margin: 0 0 8px;
}

.card h2 {
    margin: 0 0 4px;
    font-size: 16px;
}

.card .meta {
    color: var(--dim);
    font-size: 12px;
    margin-bottom: 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 11px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 5px;
}

#presetJson {
    display: block;
    width: 100%;
    height: min(20dvh, 160px);
    min-height: 130px;
    padding: 10px;
    font: 12px/1.5 'Consolas', 'Monaco', monospace;
    tab-size: 2;
}
label[for="presetJson"] {
    display: block;
    margin-bottom: 5px;
    color: var(--dim);
    font-size: 11px;
    letter-spacing: .5px;
    text-transform: uppercase;
}

.preset-json-actions {
    margin-top: 8px;
}

.preset-json-status {
    min-height: 18px;
    margin-top: 6px;
    color: var(--accent2);
    font-size: 12px;
}

.preset-json-status.error {
    color: var(--danger);
}

.midi-file-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin-bottom: 8px;
}

.midi-file-picker input[hidden] {
    display: none;
}

.midi-file-picker .meta {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.midi-file-picker .midi-instrument-progress {
    flex: 0 0 88px;
    width: 88px;
    height: 8px;
    margin-left: auto;
    border: 0;
    border-radius: 4px;
    background: var(--border);
    color: var(--accent2);
    appearance: none;
}

.midi-instrument-progress::-webkit-progress-bar {
    border-radius: 4px;
    background: var(--border);
}

.midi-instrument-progress::-webkit-progress-value {
    border-radius: 4px;
    background: var(--accent2);
}

.midi-instrument-progress::-moz-progress-bar {
    border-radius: 4px;
    background: var(--accent2);
}

.midi-file-picker button {
    flex-shrink: 0;
}

.midi-instrument-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 160px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.graphic-equalizer-button[hidden] {
    display: none;
}

.graphic-equalizer-dialog {
    width: min(820px, calc(100vw - 32px));
}

.graphic-equalizer-dialog .dialog-body {
    overflow-x: auto;
}

.graphic-equalizer-dialog .dialog-footer {
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.graphic-equalizer-transport {
    display: flex;
    flex: 1 1 220px;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.graphic-equalizer-transport[hidden],
.graphic-equalizer-transport [hidden] {
    display: none;
}

.graphic-equalizer-midi-playback {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
}

#btnGraphicEqualizerPlayback {
    width: 85px;
    flex: 0 0 85px;
}

.graphic-equalizer-seek-control {
    display: grid;
    flex: 1;
    grid-template-columns: 7ch minmax(0, 1fr) 7ch;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.graphic-equalizer-seek-control > span {
    width: 7ch;
    color: var(--dim);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#graphicEqualizerTimeCurrent {
    grid-column: 1;
    grid-row: 1;
}

#graphicEqualizerTimeTotal {
    grid-column: 3;
    grid-row: 1;
    text-align: right;
}

#graphicEqualizerSeek {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    margin: 0;
}

.graphic-equalizer-actions {
    flex: 0 0 auto;
    align-items: center;
    flex-wrap: wrap;
}

.graphic-equalizer-bands {
    --graphic-equalizer-slider-height: 150px;
    --graphic-equalizer-slider-top: 21px;
    --graphic-equalizer-thumb-half-size: 8px;
    position: relative;
    display: grid;
    grid-template-columns: repeat(10, minmax(34px, 1fr));
    gap: 8px;
    min-width: 430px;
    margin-top: 18px;
}

.graphic-equalizer-bands::before {
    position: absolute;
    top: calc(var(--graphic-equalizer-slider-top) + var(--graphic-equalizer-thumb-half-size));
    right: 0;
    left: 0;
    height: calc(var(--graphic-equalizer-slider-height) - 2 * var(--graphic-equalizer-thumb-half-size));
    background:
        linear-gradient(to right, rgba(88, 166, 255, .55), rgba(88, 166, 255, .55))
            0 50% / 100% 1px no-repeat,
        linear-gradient(to right, rgba(139, 148, 158, .36), rgba(139, 148, 158, .36))
            0 0 / 100% 1px no-repeat,
        linear-gradient(to right, rgba(139, 148, 158, .28), rgba(139, 148, 158, .28))
            0 25% / 100% 1px no-repeat,
        linear-gradient(to right, rgba(139, 148, 158, .28), rgba(139, 148, 158, .28))
            0 75% / 100% 1px no-repeat,
        linear-gradient(to right, rgba(139, 148, 158, .36), rgba(139, 148, 158, .36))
            0 100% / 100% 1px no-repeat;
    content: "";
    pointer-events: none;
}

.graphic-equalizer-band {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.graphic-equalizer-slider {
    position: relative;
    display: flex;
    flex: 0 0 150px;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 150px;
}

.graphic-equalizer-band output {
    color: var(--fg);
    font-size: 11px;
    line-height: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.graphic-equalizer-slider input[type="range"] {
    position: absolute;
    width: 150px;
    min-width: 150px;
    height: 24px;
    margin: 0;
    transform: rotate(-90deg);
    touch-action: none;
}

.graphic-equalizer-band label {
    color: var(--dim);
    font-size: 10px;
    line-height: 12px;
    white-space: nowrap;
}

@media (max-width: 520px) {
    .graphic-equalizer-transport {
        flex-basis: 100%;
    }

    .graphic-equalizer-actions {
        margin-left: auto;
    }

    .graphic-equalizer-bands {
        gap: 4px;
    }

    .graphic-equalizer-slider {
        flex-basis: 125px;
        height: 125px;
    }

    .graphic-equalizer-bands {
        --graphic-equalizer-slider-height: 125px;
    }

    .graphic-equalizer-slider input[type="range"] {
        width: 125px;
        min-width: 125px;
    }
}

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

.midi-instrument-group {
    min-width: 0;
}

.midi-instrument-group h3 {
    margin: 0 0 6px;
    color: var(--dim);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.midi-instrument-list li + li {
    border-top: 1px solid var(--border);
}

.midi-channel-list {
    display: grid;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 180px;
    overflow-y: auto;
}

.midi-channel-row {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 6px 3px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
}

.midi-channel-name {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    color: var(--fg);
    overflow: hidden;
}

.midi-channel-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.midi-channel-controls {
    display: flex;
    gap: 4px;
}

#midiMixerDialog {
    width: min(920px, calc(100vw - 32px));
}

.midi-mixer-channel-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.midi-mixer-channel {
    display: grid;
    grid-template-columns: minmax(0, 2.4fr) repeat(3, minmax(0, 1.5fr));
    align-items: center;
    column-gap: 14px;
    row-gap: 6px;
    min-width: 0;
    padding: 2px 0 2px;
    border-bottom: 1px solid var(--border);
}

.midi-mixer-channel:last-child {
    border-bottom: 0;
}

.midi-mixer-channel-info {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.midi-mixer-instrument-button {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    padding: 2px;
    color: var(--dim);
    background: transparent;
    border-color: transparent;
}

.midi-mixer-instrument-button svg {
    display: block;
    width: 18px;
    height: 18px;
}

.midi-mixer-instrument-button:hover:not(:disabled) {
    color: var(--accent);
    background: transparent;
    border-color: transparent;
}

.midi-mixer-channel label {
    min-width: 0;
    color: var(--dim);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.midi-mixer-channel-name {
    position: relative;
    top: -1px;
    min-width: 0;
    flex: 1;
    margin-left: 3px;
    color: var(--fg);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.midi-mixer-channel-toggles {
    display: flex;
    gap: 2px;
    flex: 0 0 auto;
}

.midi-mixer-channel-toggle {
    width: 20px;
    min-width: 20px;
    height: 20px;
    font-size: 10px;
}

.midi-mixer-equalizer-icon {
    display: block;
    width: 14px;
    height: 14px;
    margin: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.midi-mixer-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    align-items: center;
    gap: 2px 4px;
    min-width: 0;
}

.midi-mixer-control label {
    grid-column: 1 / -1;
    font-size: 11px;
}

.midi-mixer-control input[type="range"] {
    width: 100%;
    min-width: 0;
    height: 14px;
    margin: 0;
}

.midi-mixer-control output {
    color: var(--dim);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.midi-mixer-footer {
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.midi-mixer-transport {
    display: grid;
    grid-template-columns: auto minmax(140px, 1fr);
    align-items: center;
    gap: 14px;
    min-width: min(100%, 330px);
    flex: 1;
}

.midi-mixer-transport-buttons {
    display: flex;
    gap: 6px;
}

#btnMidiMixerPlay {
    width: 85px;
    flex: 0 0 85px;
}

.midi-mixer-seek-control {
    display: grid;
    grid-template-columns: 7ch minmax(0, 1fr) 7ch;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.midi-mixer-seek-time {
    width: 7ch;
    color: var(--dim);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#midiMixerTimeCurrent {
    grid-column: 1;
    grid-row: 1;
}

#midiMixerTimeTotal {
    grid-column: 3;
    grid-row: 1;
    text-align: right;
}

.midi-mixer-seek-control input {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    margin: 0;
}

@media (max-width: 520px) {
    .midi-mixer-channel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        column-gap: 8px;
        row-gap: 3px;
        padding: 1px 0 3px;
    }

    .midi-mixer-channel-info {
        grid-column: 1 / -1;
    }

    .midi-mixer-control {
        grid-template-columns: minmax(0, 1fr) 24px;
        gap: 3px;
    }

    .midi-mixer-control label,
    .midi-mixer-control output {
        font-size: 10px;
    }

    .midi-mixer-transport {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}
.midi-mixer-control{
    padding-bottom: 4px;
}
.dialog-content label.midi-mixer-control-label{
    margin-top: 0px;
}

.channel-toggle {
    width: 28px;
    height: 26px;
    padding: 0;
    font-size: 11px;
    font-weight: 700;
}

.channel-toggle[aria-pressed="true"][data-control="mute"] {
    background: var(--danger);
    border-color: var(--danger);
    color: #000;
}

.channel-toggle[aria-pressed="true"][data-control="solo"] {
    background: var(--accent2);
    border-color: var(--accent2);
    color: #000;
}

.channel-toggle[aria-pressed="true"][data-control="mute"]:hover:not(:disabled) {
    background: #ff8585;
    border-color: var(--danger);
    color: #000;
}

.channel-toggle[aria-pressed="true"][data-control="solo"]:hover:not(:disabled) {
    background: #56d364;
    border-color: var(--accent2);
    color: #000;
}

.midi-instrument-link {
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--fg);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    text-align: left;
    transition: opacity .16s ease, background-color .16s ease;
}

.midi-instrument-item.is-loading .midi-instrument-link {
    opacity: 0.58;
}

.midi-note-indicator {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background-color .08s, box-shadow .08s;
}

.midi-instrument-link.is-playing .midi-note-indicator {
    background: var(--accent2);
    box-shadow: 0 0 7px var(--accent2);
}

.midi-note-indicator.is-playing {
    background: var(--accent2);
    box-shadow: 0 0 7px var(--accent2);
}

.midi-instrument-name {
    min-width: 0;
}

.midi-instrument-link:hover {
    background: var(--panel2);
}

.midi-instrument-empty {
    padding: 8px 10px;
    color: var(--dim);
    font-size: 12px;
}

@media (max-width: 520px) {
    .midi-instrument-lists {
        grid-template-columns: 1fr;
    }
}

canvas {
    width: 100%;
    height: 140px;
    background: #0a0e14;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: block;
}

.actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.waveform-zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.waveform-zoom-controls span {
    color: var(--dim);
    font-size: 12px;
    min-width: 32px;
}

.log {
    margin-top: 8px;
    padding: 8px;
    background: #0a0e14;
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 11px;
    color: var(--dim);
    max-height: 42px;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.log .ok {
    color: var(--accent2);
}

.log .info {
    color: var(--accent);
}

.log .err {
    color: var(--danger);
}

.stats {
    display: flex;
    gap: 24px;
    font-size: 12px;
    color: var(--dim);
    margin-top: 8px;
    flex-wrap: wrap;
}

.stats b {
    color: var(--fg);
}

.progress {
    margin-top: 12px;
    display: none;
}

.progress.show {
    display: grid;
    gap: 6px;
}

.progress-label {
    color: var(--dim);
    font-size: 11px;
    min-height: 14px;
}

.progress-track {
    height: 6px;
    background: var(--panel2);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent2);
    width: 0%;
    transition: width .1s;
}

@media (max-width:800px) {
    body {
        height: auto;
        min-height: 100dvh;
        display: block;
    }

    .layout {
        grid-template-columns: 1fr;
        height: auto;
        flex: none;
    }

    aside {
        width: 100%;
        max-height: 280px;
    }

    .project-controls {
        width: 100%;
        margin-left: 0;
    }

    .project-controls select {
        flex: 1;
        min-width: 120px;
    }

    .instrument-search-wrap {
        grid-column: 1 / -1;
    }

    main {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "instrument"
            "preset"
            "midi"
            "log";
        overflow: visible;
        padding: 16px;
    }

    #presetJson {
        height: 200px;
    }

    .sequencer-settings {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

@media (min-width:801px) and (max-width:900px) {
    .layout {
        grid-template-columns: var(--sidebar-width-compact) minmax(0, 1fr);
    }

    aside {
        width: var(--sidebar-width-compact);
    }
}

/* ---- Preset editor tabs ---- */
.preset-editor-tabs {
    display: flex;
    gap: 4px;
    margin: 8px 0 10px;
}

.preset-editor-tabs button {
    padding: 6px 16px;
    font-size: 12px;
}

.preset-editor-tabs button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

#presetFormPanel[hidden],
#presetJsonPanel[hidden] {
    display: none;
}

/* ---- Preset form ---- */
.preset-form {
    max-height: min(50dvh, 250px);
    overflow-y: auto;
    padding: 8px 12px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
}

.preset-field {
    display: grid;
    grid-template-columns: minmax(110px, 1fr) minmax(0, 1.6fr);
    align-items: center;
    gap: 10px;
    padding: 3px 0;
}

.preset-field > label {
    color: var(--dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preset-field > input:not([type="checkbox"]),
.preset-field > select,
.preset-field > .preset-waveform-control > select,
.preset-field > .number-input-wrap {
    width: 100%;
    height: 26px;
    padding: 4px 8px;
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    font-size: 12px;
}
.preset-field > input:not([type="checkbox"]),
.preset-field > .number-input-wrap {
    background: var(--panel);
}
.preset-field > select,
.preset-field > .preset-waveform-control > select{
    background-position: right 5px center;
}

.preset-field > select,
.preset-field > .preset-waveform-control > select {
    color-scheme: dark;
}

.preset-waveform-control {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.preset-waveform-description {
    color: var(--dim);
    font-size: 11px;
    line-height: 1.35;
}

.preset-field > .number-input-wrap > input[type="number"] {
    height: 100%;
    min-height: 0;
    padding: 3px 8px;
    font: inherit;
    font-size: 12px;
}

.preset-field > .number-input-wrap {
    padding: 0;
}

.preset-field > input[type="checkbox"] {
    width: 16px;
    height: 16px;
    justify-self: start;
    accent-color: var(--accent);
}

.preset-field > input:focus-visible,
.preset-field > select:focus-visible {
    outline: none;
    border-color: var(--accent);
}

/* ---- Nested object ---- */
.preset-fieldset {
    margin: 6px 0;
    padding: 6px 10px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, .015);
}

.preset-fieldset > legend {
    padding: 0 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ---- Array items ---- */
.preset-array-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.preset-array-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, .015);
    border: 1px solid var(--border);
    border-radius: 5px;
}

.preset-array-item-body {
    flex: 1;
    min-width: 0;
}

.preset-array-item > .number-input-wrap,
.preset-array-item > input[type="number"],
.preset-array-item > input[type="text"] {
    flex: 1;
    min-width: 0;
    height: 24px;
    padding: 3px 8px;
    background: var(--panel);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    font-size: 12px;
}

.preset-array-item > .number-input-wrap {
    height: 24px;
    padding: 0;
}

.preset-array-item > .number-input-wrap > input[type="number"] {
    height: 100%;
    min-height: 0;
    padding: 3px 8px;
    font: inherit;
    font-size: 12px;
}

.preset-array-item > input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.preset-array-add {
    flex: 0 0 auto;
    padding: 2px 9px;
    font-size: 13px;
    line-height: 1;
    border-radius: 3px;
}

.preset-array-remove {
    display: grid;
    flex: 0 0 23px;
    place-items: center;
    width: 23px;
    height: 23px;
    padding: 0;
    color: var(--danger);
    border-color: var(--border);
}
.preset-array-item .preset-array-item-body{
    /*  This is a fix for the remove button being slightly misaligned with the input fields in the array item.
        The remove button is 23px tall, while the input fields are 22px tall, so we need to adjust the margin-top of the remove button to align it with the input fields.
    */
    margin-top: -3px;
}
.preset-array-remove-icon {
    display: block;
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.preset-array-add {
    margin-top: 6px;
    color: var(--accent2);
    border-color: var(--border);
    align-self: flex-start;
    padding: 4px 12px;
    font-weight: 600;
}

.preset-array-add:hover:not(:disabled) {
    background: var(--accent2);
    color: #000;
    border-color: var(--accent2);
}

@media (max-width: 520px) {
    .preset-field {
        grid-template-columns: minmax(80px, 1fr) minmax(0, 1.4fr);
        gap: 6px;
    }
    .preset-form { padding: 6px 8px 10px; }
}

#btnTogglePatchCache{
    width: 140px;
}

#btnTogglePatchCache .button-icon {
    transform: translateY(1px);
}