:root {
  color-scheme: light;
  --ink: #15171a;
  --muted: #68707c;
  --line: #d9dde3;
  --panel: #ffffff;
  --soft: #f4f6f8;
  --field: #fbfcfd;
  --brand: #126c6f;
  --brand-ink: #083d40;
  --accent: #c5542d;
  --focus: #2e7dd1;
  --ok: #237a48;
  --danger: #b53632;
  --shadow: 0 18px 45px rgba(22, 29, 37, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 246, 248, 0.96)),
    repeating-linear-gradient(
      90deg,
      rgba(18, 108, 111, 0.08) 0,
      rgba(18, 108, 111, 0.08) 1px,
      transparent 1px,
      transparent 72px
    );
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.splash {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 42px;
  align-items: center;
  padding: 44px clamp(22px, 6vw, 82px);
}

.splash-title {
  max-width: 780px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--brand-ink);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 8vw, 7.25rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.splash-title p {
  margin: 24px 0 0;
  max-width: 620px;
  color: #404852;
  font-size: 1.1rem;
  line-height: 1.6;
}

.splash-panel,
.panel,
.rack-card,
.channel-table,
.library-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.splash-panel {
  padding: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
}

.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.project-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 22px;
}

.project-button {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  background: var(--soft);
  border: 1px solid transparent;
  border-radius: 6px;
}

.project-button:hover,
.project-button:focus {
  border-color: var(--brand);
  outline: none;
}

.project-name {
  font-weight: 800;
}

.project-meta,
.small-copy {
  color: var(--muted);
  font-size: 0.88rem;
}

.new-project-form,
.import-project-form {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.import-project-form {
  margin-top: 16px;
}

.toolbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--brand);
  border-radius: 8px;
  font-weight: 900;
}

.project-title {
  margin: 0;
  font-size: 1rem;
}

.save-state {
  color: var(--muted);
  font-size: 0.84rem;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 22px 0;
  overflow-x: auto;
  background: #fff;
}

.tab {
  padding: 11px 14px;
  color: #3d4651;
  background: transparent;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.tab.active {
  color: var(--brand-ink);
  border-color: var(--accent);
  font-weight: 800;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
  flex: 1;
}

.panel {
  padding: 22px;
}

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

.field {
  display: grid;
  gap: 7px;
}

label {
  color: #333a43;
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--field);
  border: 1px solid #cfd5dc;
  border-radius: 6px;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(46, 125, 209, 0.28);
  border-color: var(--focus);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  color: #fff;
  background: var(--brand);
  border-radius: 6px;
  font-weight: 800;
}

.button.secondary {
  color: var(--brand-ink);
  background: #e8f2f2;
}

.button.warning {
  color: #fff;
  background: var(--danger);
}

.compact-button {
  justify-self: start;
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.84rem;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  color: #3c4652;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 900;
}

.icon-button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.icon-button.connect {
  color: var(--brand-ink);
  background: #e8f2f2;
}

.icon-button.connect.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.icon-button.mini {
  width: 24px;
  height: 24px;
  min-height: 24px;
  font-size: 0.72rem;
}

.system-map {
  position: relative;
}

.connection-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.connection-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
}

.connection-canvas marker path {
  fill: var(--accent);
}

.connection-label {
  fill: var(--brand-ink);
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  text-anchor: middle;
  font-size: 0.78rem;
  font-weight: 900;
}

.config-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.system-column {
  min-width: 0;
}

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

.add-system-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.rack-card {
  padding: 16px;
  box-shadow: none;
}

.system-node-card {
  position: relative;
  z-index: 2;
  min-height: 250px;
}

.system-node-card.connecting {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(197, 84, 45, 0.16);
}

.connection-controls {
  display: grid;
  gap: 8px;
}

.endpoint-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.endpoint-status {
  color: var(--brand-ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.endpoint-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.endpoint-status-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.endpoint-port-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.endpoint-port {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.endpoint-port strong,
.endpoint-port .small-copy {
  display: block;
}

.rack-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.rack-card-head strong {
  display: block;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.channel-table {
  overflow: hidden;
  box-shadow: none;
}

.patch-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.subtab {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 800;
  cursor: pointer;
}

.subtab.active {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
  color: #ffffff;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #3a414b;
  background: #eef2f4;
  font-size: 0.8rem;
  text-transform: uppercase;
}

td.channel-number {
  width: 70px;
  color: var(--brand-ink);
  font-weight: 900;
}

.compact-input {
  min-height: 36px;
}

.patch-mixer-select {
  min-width: 240px;
}

.io-inventory-table table {
  min-width: 760px;
}

.patch-block-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
}

.patch-block-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(320px, 380px);
  gap: 14px;
  align-items: start;
  width: max-content;
  min-width: 100%;
}

.mixer-channel-grid {
  grid-auto-columns: minmax(380px, 460px);
}

.patch-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  --patch-tint: #eef2f4;
  --patch-tint-strong: #dfe7eb;
}

.patch-block-title {
  min-height: 36px;
  padding: 9px 11px;
  background: var(--patch-tint-strong);
  color: var(--brand-ink);
  font-weight: 900;
  font-size: 0.92rem;
}

.patch-block-subtitle {
  padding: 7px 11px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.patch-tone-0 {
  --patch-tint: #f3f7fb;
  --patch-tint-strong: #dfeaf5;
}

.patch-tone-1 {
  --patch-tint: #f4f8f1;
  --patch-tint-strong: #e2eed9;
}

.patch-tone-2 {
  --patch-tint: #fbf5ef;
  --patch-tint-strong: #f1e2d2;
}

.patch-tone-3 {
  --patch-tint: #f7f3fb;
  --patch-tint-strong: #e8def3;
}

.patch-tone-4 {
  --patch-tint: #f1f8f8;
  --patch-tint-strong: #d9eeee;
}

.patch-tone-5 {
  --patch-tint: #faf5f6;
  --patch-tint-strong: #efdfe4;
}

.patch-mini-table {
  min-width: 0;
  table-layout: fixed;
}

.patch-mini-table th,
.patch-mini-table td {
  padding: 5px;
  font-size: 0.82rem;
}

.patch-mini-table th:first-child,
.patch-mini-table td:first-child {
  width: calc(6ch + 10px);
  max-width: calc(6ch + 10px);
  text-align: center;
  white-space: nowrap;
}

.patch-mini-table th:nth-child(3),
.patch-mini-table td:nth-child(3) {
  width: 52px;
}

.patch-mini-table .compact-input {
  min-height: 30px;
  font-size: 0.82rem;
  padding: 5px 7px;
}

.patch-picker-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 4px;
  align-items: stretch;
}

.patch-picker-control:has(.patch-picker-value:only-child) {
  grid-template-columns: minmax(0, 1fr);
}

.patch-picker-value,
.patch-picker-clear {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.78rem;
}

.patch-picker-value {
  overflow: hidden;
  padding: 5px 7px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patch-picker-value.empty {
  color: var(--muted);
}

.patch-picker-clear {
  padding: 0;
  color: var(--muted);
  font-weight: 900;
}

.patch-picker-value:hover,
.patch-picker-value:focus,
.patch-picker-clear:hover,
.patch-picker-clear:focus {
  border-color: var(--brand-ink);
  outline: none;
}

.picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(27, 35, 43, 0.34);
  overflow: hidden;
  overscroll-behavior: contain;
}

.picker-panel {
  width: min(860px, calc(100vw - 32px));
  height: min(680px, calc(100dvh - 32px));
  min-height: min(520px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
  overscroll-behavior: contain;
}

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

.picker-head h3,
.picker-head p {
  margin: 0;
}

.picker-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.picker-list {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
  padding-right: 4px;
}

.picker-group {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.picker-group-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: #eef2f4;
  color: var(--brand-ink);
  font-size: 0.8rem;
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.picker-group-title::-webkit-details-marker {
  display: none;
}

.picker-group-title::before {
  content: "+";
  width: 18px;
  color: var(--brand-ink);
  font-weight: 900;
}

.picker-group[open] > .picker-group-title::before {
  content: "-";
}

.picker-group-title > span {
  min-width: 0;
  display: grid;
  gap: 2px;
  margin-right: auto;
}

.picker-group-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-group-title small {
  color: var(--muted);
  font-weight: 800;
}

.picker-option {
  width: 100%;
  display: grid;
  grid-template-columns: calc(6ch + 10px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
}

.picker-option:hover,
.picker-option:focus {
  background: var(--soft);
  outline: none;
}

.picker-option-channel {
  color: var(--brand-ink);
  font-weight: 900;
  text-align: center;
}

.picker-option strong,
.picker-option small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-option small {
  margin-top: 2px;
  color: var(--muted);
}

.patch-source-row td {
  background: var(--patch-tint);
  color: var(--brand-ink);
  font-weight: 900;
  letter-spacing: 0;
  font-size: 0.74rem;
}

.patch-source-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-weight: inherit;
}

.patch-source-title {
  display: block;
  text-transform: uppercase;
}

.patch-source-subtitle {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 800;
  text-transform: none;
  text-align: center;
}

.io-name-input,
.io-mic-input {
  min-width: 0;
}

.route-source-label {
  color: var(--brand-ink);
  font-weight: 800;
  margin-bottom: 4px;
}

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

.requirements-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.requirements-list,
.requirements-card,
.requirements-section,
.requirements-rack,
.requirements-summary-grid {
  display: grid;
  gap: 12px;
}

.requirements-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: none;
}

.requirements-card.compact {
  gap: 10px;
}

.requirements-card h3 {
  margin: 0;
  color: var(--brand-ink);
}

.requirements-rack {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.requirements-list-compact {
  margin: 0;
  padding-left: 18px;
  color: #2f3944;
}

.requirements-table {
  min-width: 0;
}

.requirements-table th,
.requirements-table td {
  padding: 7px 8px;
}

.requirements-table th:last-child,
.requirements-table td:last-child {
  width: 64px;
  text-align: right;
}

.library-card {
  padding: 16px;
  box-shadow: none;
}

.library-list {
  display: grid;
  gap: 10px;
}

.library-instructions {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.notice {
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 800;
}

.notice.success {
  color: #123f28;
  background: #dff3e8;
  border: 1px solid #a7d9bd;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 13px 15px;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(16, 24, 32, 0.18);
  font-weight: 900;
}

.toast.success {
  color: #123f28;
  background: #dff3e8;
  border: 1px solid #8dccaa;
}

.system-builder {
  display: grid;
  gap: 14px;
}

.io-builder {
  display: grid;
  gap: 8px;
}

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

.io-row-list {
  display: grid;
  gap: 8px;
}

.io-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 110px 38px;
  gap: 8px;
  align-items: center;
}

.library-path,
.schema-sample {
  overflow-x: auto;
  padding: 12px;
  color: #23303b;
  background: #eef2f4;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.schema-sample {
  margin: 16px 0 0;
  line-height: 1.45;
  white-space: pre;
}

.library-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.library-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.library-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.library-actions .icon-button {
  width: 34px;
  height: 34px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 3px 8px;
  color: #2f3a44;
  background: #e7ecef;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 170px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  box-shadow: none;
}

@media (max-width: 900px) {
  .splash,
  .config-layout,
  .add-system-row,
  .library-grid,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    padding: 16px;
  }
}

@media (max-width: 560px) {
  .splash {
    padding: 24px 16px;
  }

  .splash-panel,
  .panel {
    padding: 16px;
  }

  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .button-row > * {
    width: 100%;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}
