:root {
  color-scheme: dark;
  font-family: "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  background: #171925;
  color: #cbd3ff;
  --surface: #1b1e2b;
  --surface-raised: #242838;
  --border: #3b4058;
  --border-soft: #2c3042;
  --muted: #929abf;
  --lane-a: #ff9b76;
  --lane-b: #59c8ee;
  --ready: #8bd450;
  --danger: #ff6288;
  --yellow: #ecb153;
  --violet: #b792ef;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #171925;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #171925;
  color: #cbd3ff;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select,
input[type="range"] {
  accent-color: var(--accent, var(--lane-a));
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent, var(--lane-a));
  outline-offset: 2px;
}

.terminal-bar {
  height: 30px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  border-bottom: 1px solid #394058;
  background: #111e2a;
  color: #a8b2da;
  font-size: 11px;
}

.window-lights {
  display: flex;
  gap: 7px;
}

.window-lights span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.window-lights span:nth-child(2) { background: var(--yellow); }
.window-lights span:nth-child(3) { background: var(--ready); }

.terminal-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ansi-palette {
  height: 12px;
  display: flex;
}

.ansi-palette span {
  width: 22px;
  background: var(--danger);
}

.ansi-palette span:nth-child(2) { background: var(--yellow); }
.ansi-palette span:nth-child(3) { background: var(--ready); }
.ansi-palette span:nth-child(4) { background: var(--lane-b); }
.ansi-palette span:nth-child(5) { background: var(--violet); }
.ansi-palette span:nth-child(6) { background: #aab6e8; }

.app-bar {
  min-height: 68px;
  padding: 12px 24px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: #181b28;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-block {
  display: block;
  min-width: 0;
}

.brand-block h1,
.lane-heading h2,
.section-heading h2,
.lane-section h3,
.matrix-group h3 {
  margin: 0;
}

.brand-block h1 {
  margin-top: 3px;
  font-size: 16px;
  line-height: 1;
  font-weight: 760;
}

.section-index,
.lane-number {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.shell-prompt {
  display: block;
  color: var(--ready);
  font-size: 10px;
  font-weight: 700;
}

.transport-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.transport-status strong {
  color: #dbe1ff;
  font-variant-numeric: tabular-nums;
}

.status-light {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #69708e;
  box-shadow: 0 0 0 3px rgba(105, 112, 142, 0.15);
}

.status-light.online {
  background: var(--ready);
  box-shadow: 0 0 0 3px rgba(101, 199, 121, 0.16);
}

.status-light.error {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(228, 109, 100, 0.16);
}

.divider {
  width: 1px;
  height: 16px;
  margin: 0 4px;
  background: var(--border);
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.command-button {
  min-width: 72px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-raised);
  color: #dbe1ff;
  cursor: pointer;
}

.command-button:hover {
  border-color: #697174;
  background: #2c3143;
}

.command-button.danger {
  border-color: rgba(228, 109, 100, 0.58);
  color: #ff9aae;
}

main {
  width: min(1600px, 100%);
  margin: 0 auto;
}

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

.lane-panel {
  --accent: var(--lane-a);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
}

.lane-panel[data-lane="1"] {
  --accent: var(--lane-b);
}

.lane-heading {
  min-height: 64px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.lane-number {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
}

.lane-heading h2 {
  font-size: 18px;
  line-height: 1.1;
}

.bypass-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.bypass-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 34px;
  height: 18px;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #545c5f;
  border-radius: 9px;
  background: #252a2d;
  transition: background 120ms ease, border-color 120ms ease;
}

.switch-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #a4abad;
  transform: translateX(0);
  transition: transform 120ms ease, background 120ms ease;
}

.bypass-control input:checked + .switch-track {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 24%, #252a2d);
}

.bypass-control input:checked + .switch-track .switch-thumb {
  transform: translateX(16px);
  background: var(--accent);
}

.primary-controls {
  min-height: 86px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1.2fr);
  gap: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.field-control {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.field-control select {
  width: 100%;
  height: 36px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #24282b;
  color: #dbe1ff;
}

.range-line {
  min-width: 0;
  height: 36px;
  display: grid;
  grid-template-columns: minmax(80px, 1fr) 48px;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  margin: 0;
}

output,
.matrix-value {
  color: #dbe1ff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.lane-section {
  padding: 14px 16px 16px;
}

.lane-section + .lane-section {
  border-top: 1px solid var(--border-soft);
}

.lane-section h3,
.matrix-group h3 {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
  text-transform: uppercase;
}

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

.parameter-control {
  min-width: 0;
  height: 34px;
  display: grid;
  grid-template-columns: 28px minmax(40px, 1fr) 42px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #252a2d;
}

.parameter-control label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

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

.toggle-button {
  height: 36px;
  min-width: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #222629;
  color: var(--muted);
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
}

.toggle-button::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #62696c;
}

.toggle-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: #dbe1ff;
  background: color-mix(in srgb, var(--accent) 12%, #222629);
}

.toggle-button[aria-pressed="true"]::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.routing-band {
  padding: 22px 20px 30px;
  border-top: 1px solid var(--border);
  background: #181b28;
}

.section-heading {
  min-height: 50px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin-top: 3px;
  font-size: 18px;
}

.request-state {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

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

.matrix-group {
  min-width: 0;
}

.crosspoint-matrix {
  --matrix-accent: var(--lane-a);
  width: max-content;
  max-width: 100%;
  display: grid;
  grid-template-columns: 82px repeat(var(--matrix-columns), 64px);
  grid-template-rows: 28px repeat(var(--matrix-rows), 58px);
  align-items: stretch;
}

.matrix-group:nth-child(2) .crosspoint-matrix {
  --matrix-accent: var(--lane-b);
}

.matrix-group:nth-child(3) .crosspoint-matrix {
  --matrix-accent: var(--ready);
}

.matrix-corner,
.matrix-column-label,
.matrix-row-label {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.matrix-corner {
  color: #68708e;
  font-size: 9px;
}

.matrix-column-label {
  justify-content: center;
  color: var(--matrix-accent);
}

.matrix-row-label {
  justify-content: flex-end;
  padding-right: 14px;
}

.crosspoint-cell {
  position: relative;
  display: grid;
  place-items: center;
}

.crosspoint-cell::before,
.crosspoint-cell::after {
  content: "";
  position: absolute;
  background: #3c4259;
}

.crosspoint-cell::before {
  width: 100%;
  height: 1px;
  top: 50%;
  left: 0;
}

.crosspoint-cell::after {
  width: 1px;
  height: 100%;
  top: 0;
  left: 50%;
}

.crosspoint-button {
  position: relative;
  z-index: 1;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid #555d78;
  border-radius: 4px;
  background: #181b28;
  color: #727a99;
  cursor: pointer;
}

.crosspoint-button::before {
  content: "+";
  font-size: 16px;
  line-height: 1;
}

.crosspoint-button:hover {
  border-color: var(--matrix-accent);
}

.crosspoint-button[aria-pressed="true"] {
  border-color: var(--matrix-accent);
  background: var(--matrix-accent);
  color: #171925;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--matrix-accent) 16%, transparent);
}

.crosspoint-button[aria-pressed="true"]::before {
  content: "x";
  font-weight: 900;
}

@media (max-width: 1050px) {
  .app-bar {
    grid-template-columns: 1fr auto;
  }

  .transport-status {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  .lane-grid {
    grid-template-columns: 1fr;
  }

  .routing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .output-group {
    grid-column: 1 / -1;
  }

}

@media (max-width: 640px) {
  .terminal-bar {
    grid-template-columns: 72px 1fr;
  }

  .ansi-palette {
    display: none;
  }

  .app-bar {
    padding: 12px 14px;
    gap: 12px;
  }

  .brand-block span {
    display: none;
  }

  .header-actions {
    gap: 6px;
  }

  .command-button {
    min-width: 60px;
    padding: 0 10px;
  }

  .lane-grid,
  .routing-band {
    padding-left: 10px;
    padding-right: 10px;
  }

  .primary-controls,
  .parameter-grid,
  .routing-grid {
    grid-template-columns: 1fr;
  }

  .toggle-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .output-group {
    grid-column: auto;
  }
}
