:root {
    color-scheme: dark;
    --bg: #151412;
    --panel: #211f1b;
    --panel-2: #2a2823;
    --panel-3: #34312a;
    --text: #f3efe6;
    --muted: #b6afa3;
    --line: #464137;
    --grid: rgba(255, 255, 255, 0.055);
    --audio: #38aaff;
    --audio-soft: rgba(56, 170, 255, 0.18);
    --control: #51d889;
    --control-soft: rgba(81, 216, 137, 0.18);
    --amber: #f2b84b;
    --danger: #ff6f61;
    --shadow: rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

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

body {
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
}

button,
input {
    font: inherit;
}

input {
    color: inherit;
}

button {
    color: inherit;
}

.shell {
    display: grid;
    grid-template-columns: 282px minmax(420px, 1fr) 302px;
    grid-template-rows: 58px minmax(0, 1fr);
    width: 100vw;
    height: 100vh;
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 18px;
    border-bottom: 1px solid var(--line);
    background: #191815;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border: 2px solid var(--audio);
    border-radius: 8px;
    background:
        linear-gradient(90deg, transparent 46%, var(--control) 47%, var(--control) 53%, transparent 54%),
        linear-gradient(0deg, transparent 46%, var(--audio) 47%, var(--audio) 53%, transparent 54%);
    box-shadow: 0 0 18px rgba(56, 170, 255, 0.2);
}

.brand strong,
.brand span {
    display: block;
    line-height: 1.1;
    white-space: nowrap;
}

.brand strong {
    font-size: 15px;
}

.brand span {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.toolbar {
    display: flex;
    gap: 8px;
}

.preset-picker {
    position: relative;
}

.tool-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--panel-2);
    cursor: pointer;
}

.tool-button:hover {
    border-color: #665f50;
    background: #322f29;
}

.tool-button.active {
    border-color: rgba(81, 216, 137, 0.7);
    background: rgba(81, 216, 137, 0.14);
}

.tool-button.error {
    border-color: rgba(255, 111, 97, 0.72);
    background: rgba(255, 111, 97, 0.12);
}

.midi-button.active .button-icon {
    color: var(--control);
}

.button-icon {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    color: var(--amber);
    font-weight: 700;
}

.playback-icon::before {
    content: "";
    display: block;
    width: 0;
    height: 0;
    margin-left: 2px;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 9px solid var(--control);
}

.preset-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    min-width: 220px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #211f1a;
    box-shadow: 0 16px 34px var(--shadow);
}

.preset-menu-item {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.preset-menu-item:hover,
.preset-menu-item:focus-visible {
    background: #322f29;
    outline: none;
}

.playback-button.active .playback-icon::before {
    width: 10px;
    height: 10px;
    margin-left: 0;
    border: 0;
    background: var(--danger);
}

.palette,
.inspector {
    min-width: 0;
    padding: 14px;
    border-right: 1px solid var(--line);
    background: var(--panel);
    overflow: auto;
}

.inspector {
    border-right: 0;
    border-left: 1px solid var(--line);
}

.panel-title {
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.search-box {
    display: flex;
    align-items: center;
    height: 36px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #171613;
}

.search-box span {
    width: 12px;
    height: 12px;
    margin-left: 11px;
    border: 2px solid var(--muted);
    border-radius: 50%;
    position: relative;
    flex: 0 0 auto;
}

.search-box span::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 2px;
    right: -5px;
    bottom: -3px;
    background: var(--muted);
    transform: rotate(45deg);
}

.search-box input {
    min-width: 0;
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    padding: 0 12px;
    background: transparent;
    color: var(--text);
}

.palette-list {
    display: grid;
    gap: 14px;
}

.palette-group {
    display: grid;
    gap: 7px;
}

.palette-group-title {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.palette-node {
    width: 100%;
    min-height: 58px;
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    text-align: left;
    cursor: pointer;
}

.palette-node:hover {
    border-color: #6b6250;
    background: var(--panel-3);
}

.palette-node-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--amber);
}

.palette-node strong,
.palette-node small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.palette-node strong {
    font-size: 13px;
}

.palette-node small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
}

.workspace {
    position: relative;
    overflow: hidden;
    background: #12110f;
}

.graph-scroll {
    position: absolute;
    inset: 0;
    overflow: auto;
    cursor: default;
    scrollbar-color: #5b5549 #191815;
    scrollbar-width: thin;
}

.graph-scroll.panning {
    cursor: grabbing;
}

.graph-content {
    position: relative;
    width: 6000px;
    height: 4000px;
}

.graph-transform {
    position: relative;
    width: 6000px;
    height: 4000px;
    transform-origin: 0 0;
    background:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px),
        #12110f;
    background-size: 28px 28px;
}

.wire-layer,
.canvas-layer {
    position: absolute;
    left: 0;
    top: 0;
    width: 6000px;
    height: 4000px;
}

.wire-layer {
    pointer-events: none;
    z-index: 1;
}

.canvas-layer {
    z-index: 2;
}

.selection-box {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
    pointer-events: none;
    border: 1px solid rgba(242, 184, 75, 0.82);
    border-radius: 6px;
    background: rgba(242, 184, 75, 0.12);
    box-shadow: inset 0 0 0 1px rgba(242, 184, 75, 0.12);
}

.zoom-controls {
    position: absolute;
    right: 14px;
    bottom: 14px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(33, 31, 27, 0.94);
    box-shadow: 0 12px 26px var(--shadow);
}

.zoom-button,
.zoom-value {
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
}

.zoom-button {
    width: 28px;
    padding: 0;
    font-weight: 700;
}

.zoom-value {
    min-width: 54px;
    padding: 0 8px;
    color: var(--muted);
    font-size: 12px;
}

.zoom-button:hover,
.zoom-value:hover {
    border-color: #665f50;
    background: #322f29;
}

.wire {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.95;
}

.wire.audio {
    stroke: var(--audio);
    filter: drop-shadow(0 0 5px rgba(56, 170, 255, 0.38));
}

.wire.control {
    stroke: var(--control);
    filter: drop-shadow(0 0 5px rgba(81, 216, 137, 0.34));
}

.wire.mixed {
    stroke: var(--audio);
    filter: drop-shadow(0 0 5px rgba(56, 170, 255, 0.28)) drop-shadow(0 0 5px rgba(81, 216, 137, 0.2));
}

.wire.pending {
    stroke-dasharray: 7 7;
    opacity: 0.82;
}

.node {
    position: absolute;
    width: 286px;
    min-height: 146px;
    border: 1px solid #5a5346;
    border-radius: 8px;
    background: #25221d;
    box-shadow: 0 18px 34px var(--shadow);
    user-select: none;
}

.node.selected {
    border-color: var(--amber);
    box-shadow: 0 0 0 2px rgba(242, 184, 75, 0.18), 0 18px 34px var(--shadow);
}

.node.audition {
    border-color: var(--amber);
    box-shadow: 0 0 0 2px rgba(242, 184, 75, 0.14), 0 0 24px rgba(242, 184, 75, 0.18), 0 18px 34px var(--shadow);
}

.port-row.audition .port-main {
    color: var(--amber);
}

.node.output-node {
    border-color: rgba(56, 170, 255, 0.78);
}

.node-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    min-height: 42px;
    padding: 9px 11px;
    border-bottom: 1px solid var(--line);
    cursor: grab;
}

.node-header:active {
    cursor: grabbing;
}

.node-title {
    min-width: 0;
}

.node-title strong,
.node-title span {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-title strong {
    font-size: 13px;
}

.node-title span {
    color: var(--muted);
    font-size: 11px;
    margin-top: 2px;
}

.node-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.delete-node,
.collapse-node {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #201e1a;
    color: var(--muted);
    cursor: pointer;
}

.collapse-node::before {
    content: "";
    width: 8px;
    height: 8px;
    margin-top: 4px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-135deg);
}

.node.collapsed .collapse-node::before {
    margin-top: -3px;
    transform: rotate(45deg);
}

.collapse-node:hover {
    color: #fff;
    border-color: var(--audio);
    background: rgba(56, 170, 255, 0.14);
}

.delete-node {
    color: var(--danger);
    border-color: rgba(255, 111, 97, 0.48);
    background: rgba(255, 111, 97, 0.08);
}

.delete-node .fa-solid {
    font-size: 12px;
    line-height: 1;
    pointer-events: none;
}

.delete-node:hover {
    color: #fff;
    border-color: var(--danger);
    background: rgba(255, 111, 97, 0.24);
}

.node.collapsed {
    min-height: 0;
}

.collapsed-node-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    min-height: 40px;
    padding: 8px 11px 10px;
}

.collapsed-port-slot {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 22px;
}

.collapsed-port-slot.outputs {
    justify-content: flex-end;
}

.collapsed-port-summary {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: #12110f;
}

.collapsed-port-summary.audio {
    color: var(--audio);
    box-shadow: 0 0 0 4px var(--audio-soft);
}

.collapsed-port-summary.control {
    color: var(--control);
    box-shadow: 0 0 0 4px var(--control-soft);
}

.collapsed-port-summary.mixed {
    border-color: transparent;
    background:
        linear-gradient(135deg, var(--audio) 0 50%, var(--control) 50% 100%);
    box-shadow: 0 0 0 4px rgba(56, 170, 255, 0.12), 0 0 0 7px rgba(81, 216, 137, 0.08);
}

.collapsed-port-summary.connected:not(.mixed) {
    background: currentColor;
}

.node-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 9px;
}

.node-body.input-only,
.node-body.output-only,
.node-body.no-ports {
    grid-template-columns: 1fr;
}

.node-parameters {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
    gap: 6px;
    padding-bottom: 2px;
}

.port-column {
    display: grid;
    align-content: start;
    gap: 7px;
    min-width: 0;
}

.port-column-title {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.port-row {
    position: relative;
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 7px;
    align-items: center;
    min-height: 34px;
}

.port-row.output {
    grid-template-columns: minmax(0, 1fr) 14px;
}

.port-main {
    min-width: 0;
    display: grid;
    gap: 5px;
}

.port-name {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #ddd7cc;
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
}

.port-row.output .port-name {
    text-align: right;
}

.jack {
    width: 14px;
    height: 14px;
    padding: 0;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: #12110f;
    cursor: crosshair;
}

.jack.audio {
    color: var(--audio);
    box-shadow: 0 0 0 4px var(--audio-soft);
}

.jack.control {
    color: var(--control);
    box-shadow: 0 0 0 4px var(--control-soft);
}

.jack.mixed {
    border-color: transparent;
    background:
        linear-gradient(135deg, var(--audio) 0 50%, var(--control) 50% 100%);
    box-shadow: 0 0 0 4px rgba(56, 170, 255, 0.12), 0 0 0 7px rgba(81, 216, 137, 0.08);
}

.jack.compatible {
    background: currentColor;
}

.jack.audition {
    border-color: var(--amber);
    box-shadow: 0 0 0 4px rgba(242, 184, 75, 0.18), 0 0 18px rgba(242, 184, 75, 0.3);
}

.jack.mixed.compatible {
    background:
        linear-gradient(135deg, #78c8ff 0 50%, #7ef0aa 50% 100%);
}

.signal-scope {
    width: 82px;
    height: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 5px;
    background: #12110f;
}

.port-row.output .signal-scope {
    justify-self: end;
}

.default-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 46px;
    gap: 5px;
    align-items: center;
    width: 100%;
}

.default-slider {
    width: 100%;
    min-width: 0;
    accent-color: var(--control);
}

.default-number {
    width: 46px;
    min-width: 0;
    height: 22px;
    border: 1px solid rgba(81, 216, 137, 0.42);
    border-radius: 5px;
    background: #151410;
    color: var(--text);
    font-size: 10px;
    line-height: 1;
    padding: 0 4px;
}

.default-number:focus {
    border-color: var(--control);
    outline: 2px solid var(--control-soft);
}

.parameter-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(76px, 112px);
    gap: 6px;
    align-items: center;
    min-width: 0;
}

.parameter-control.compact {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
}

.parameter-control.boolean {
    grid-template-columns: minmax(0, 1fr) 18px;
}

.parameter-slider-control {
    grid-template-columns: minmax(0, 1fr);
}

.parameter-slider-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 52px;
    gap: 6px;
    align-items: center;
    min-width: 0;
}

.parameter-name {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.parameter-select,
.parameter-slider,
.parameter-number,
.parameter-text {
    width: 100%;
    min-width: 0;
}

.parameter-select,
.parameter-number,
.parameter-text {
    height: 26px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    background: #151410;
    color: var(--text);
    font-size: 11px;
}

.parameter-select {
    padding: 0 6px;
}

.parameter-number,
.parameter-text {
    padding: 0 5px;
}

.parameter-slider {
    accent-color: var(--amber);
}

.sample-path-parameter {
    grid-template-columns: minmax(0, 1fr);
}

.sample-path-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px;
    min-width: 0;
}

.sample-browse-button {
    display: inline-grid;
    place-items: center;
    height: 26px;
    padding: 0 8px;
    border: 1px solid rgba(242, 184, 75, 0.42);
    border-radius: 6px;
    background: #201e1a;
    color: var(--text);
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.sample-browse-button:hover {
    border-color: var(--amber);
    background: rgba(242, 184, 75, 0.13);
}

.sample-file-input {
    display: none;
}

.parameter-toggle {
    width: 18px;
    height: 18px;
    accent-color: var(--amber);
}

.parameter-select:focus,
.parameter-slider:focus,
.parameter-number:focus,
.parameter-text:focus,
.parameter-toggle:focus {
    border-color: var(--amber);
    outline: 2px solid rgba(242, 184, 75, 0.18);
}

.inspector-content {
    min-height: 210px;
    display: grid;
    gap: 12px;
}

.inspector-empty {
    color: var(--muted);
    line-height: 1.45;
}

.inspector-card {
    display: grid;
    gap: 12px;
}

.inspector-heading {
    display: grid;
    gap: 8px;
}

.node-name-control {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.node-name-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.node-title-input,
.node-name-static {
    width: 100%;
    min-width: 0;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    background: #151410;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    padding: 0 9px;
}

.node-name-static {
    display: flex;
    align-items: center;
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--muted);
}

.node-title-input:focus {
    border-color: var(--amber);
    outline: 2px solid rgba(242, 184, 75, 0.18);
}

.inspector-description {
    display: block;
    color: var(--muted);
    line-height: 1.35;
}

.port-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 12px;
}

.port-chip::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.port-chip.audio::before {
    background: var(--audio);
}

.port-chip.control::before {
    background: var(--control);
}

.port-chip.mixed::before {
    background: linear-gradient(135deg, var(--audio) 0 50%, var(--control) 50% 100%);
}

.inspector-port-section {
    display: grid;
    gap: 12px;
}

.inspector-port-group {
    display: grid;
    gap: 8px;
}

.inspector-port-list {
    display: grid;
    gap: 9px;
}

.inspector-port-row {
    display: grid;
    gap: 7px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #1b1a16;
}

.inspector-port-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.inspector-port-heading .port-chip {
    padding: 4px 6px;
    font-size: 11px;
}

.inspector-port-meta {
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}

.inspector-scope {
    width: 100%;
    height: 36px;
}

.node-analyzer {
    grid-column: 1 / -1;
    min-width: 0;
}

.fft-scope {
    width: 100%;
    height: 88px;
    display: block;
    border: 1px solid rgba(56, 170, 255, 0.22);
    border-radius: 6px;
    background: #12110f;
}

.inspector-fft-scope {
    height: 128px;
}

.parameter-section {
    display: grid;
    gap: 8px;
}

.parameter-section-title {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

.toast {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    max-width: min(520px, calc(100% - 32px));
    padding: 10px 14px;
    border: 1px solid #655b47;
    border-radius: 8px;
    background: #29241b;
    color: var(--text);
    box-shadow: 0 18px 34px var(--shadow);
    pointer-events: none;
}

@media (max-width: 980px) {
    body {
        overflow: auto;
    }

    .shell {
        min-height: 100vh;
        height: auto;
        grid-template-columns: 1fr;
        grid-template-rows: 58px auto 70vh auto;
    }

    .topbar,
    .palette,
    .workspace,
    .inspector {
        grid-column: 1;
    }

    .palette,
    .inspector {
        border-left: 0;
        border-right: 0;
    }

    .workspace {
        min-height: 70vh;
    }
}
