/* MaxCut compression and decode lab. All selectors stay inside .qx-app. */

.qx-app {
  --qx-blue: #50769b;
  --qx-warm: #8a5b3f;
  --qx-warm-soft: #f7eee9;
  --qx-ink-soft: #40505c;
  margin: 1.5rem 0 2.5rem;
  overflow: hidden;
  border: 1px solid var(--sq-border);
  border-top: 4px solid var(--sq-accent);
  border-radius: 8px;
  background: var(--sq-surface);
  box-shadow: var(--sq-shadow);
  color: var(--sq-text);
  font-variant-numeric: tabular-nums;
}

.qx-app *,
.qx-app *::before,
.qx-app *::after {
  box-sizing: border-box;
}

.qx-app button,
.qx-app select {
  font: inherit;
}

.qx-app button {
  min-width: 0;
  min-height: 2.65rem;
  border: 1px solid var(--sq-border);
  border-radius: 5px;
  background: var(--sq-surface);
  color: var(--sq-text);
  cursor: pointer;
}

.qx-app button:hover:not(:disabled) {
  border-color: var(--sq-accent);
  background: var(--sq-soft);
}

.qx-app button:focus-visible,
.qx-app select:focus-visible,
.qx-app [role="button"]:focus-visible {
  outline: 3px solid rgba(95, 127, 103, 0.38);
  outline-offset: 3px;
}

.qx-app button:disabled {
  cursor: default;
  opacity: 0.58;
}

.qx-app button[aria-pressed="true"] {
  border-color: var(--sq-accent-dark);
  background: var(--sq-accent-dark);
  color: #ffffff;
}

.qx-loading {
  min-height: 7rem;
  margin: 0;
  padding: 2.5rem 1rem;
  color: var(--sq-muted);
  text-align: center;
}

/* Controls */

.qx-toolbar {
  display: grid;
  grid-template-columns: minmax(190px, 0.7fr) minmax(380px, 1.6fr) auto;
  gap: 1rem;
  align-items: end;
  padding: 1rem;
  border-bottom: 1px solid var(--sq-border);
  background: var(--sq-soft);
}

.qx-graph-control,
.qx-mode-control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.qx-graph-control > span,
.qx-mode-control legend {
  display: block;
  float: none;
  width: auto;
  margin: 0 0 0.38rem;
  padding: 0;
  color: var(--sq-muted);
  font-size: 0.77rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.qx-graph-control select {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.42rem 2rem 0.42rem 0.65rem;
  border: 1px solid var(--sq-border);
  border-radius: 5px;
  background: var(--sq-surface);
  color: var(--sq-text);
}

.qx-mode-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
}

.qx-mode-picker button {
  display: flex;
  min-height: 3.35rem;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.04rem;
  padding: 0.42rem 0.35rem;
  line-height: 1.2;
}

.qx-mode-picker strong {
  color: inherit;
  font-size: 0.95rem;
  font-weight: 650;
}

.qx-mode-picker small {
  color: var(--sq-muted);
  font-size: 0.7rem;
}

.qx-mode-picker button[aria-pressed="true"] small {
  color: rgba(255, 255, 255, 0.82);
}

.qx-ideal-tag {
  display: inline-flex;
  min-height: 2.65rem;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.62rem;
  border: 1px solid rgba(95, 127, 103, 0.35);
  border-radius: 999px;
  background: var(--sq-warm);
  color: var(--sq-accent-dark);
  font-size: 0.73rem;
  font-weight: 650;
  white-space: nowrap;
}

/* Outcome summary */

.qx-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--sq-border);
}

.qx-summary > div {
  display: flex;
  min-width: 0;
  min-height: 6.4rem;
  flex-direction: column;
  justify-content: center;
  gap: 0.18rem;
  padding: 0.8rem 1rem;
}

.qx-summary > div + div {
  border-left: 1px solid var(--sq-border);
}

.qx-summary span,
.qx-summary small {
  color: var(--sq-muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

.qx-summary strong {
  overflow-wrap: anywhere;
  color: var(--sq-text);
  font-size: clamp(1.25rem, 2.3vw, 1.75rem);
  line-height: 1.15;
}

.qx-summary-primary {
  background: var(--sq-warm);
}

.qx-summary-primary > strong {
  color: var(--sq-accent-dark);
}

.qx-summary[aria-busy="true"] strong {
  color: var(--sq-muted);
}

/* Shared panels */

.qx-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  border-bottom: 1px solid var(--sq-border);
}

.qx-panel {
  min-width: 0;
  padding: 1rem;
}

.qx-main-grid > .qx-panel + .qx-panel {
  border-left: 1px solid var(--sq-border);
}

.qx-section-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.qx-section-heading h2 {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 1.12rem;
  font-weight: 500;
  line-height: 1.3;
}

.qx-section-heading > span,
.qx-section-heading > div > span {
  color: var(--sq-muted);
  font-size: 0.74rem;
}

.qx-section-heading > div > span {
  display: block;
  margin-top: 0.18rem;
}

/* Graph */

.qx-graph-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--sq-border);
  border-radius: 5px;
  background: var(--sq-soft);
  overscroll-behavior-inline: contain;
}

.qx-graph {
  display: block;
  width: 100%;
  min-width: 440px;
  height: auto;
  aspect-ratio: 700 / 420;
}

.qx-edge {
  fill: none;
  stroke: var(--sq-graph-edge);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.qx-edge.is-cut {
  stroke: var(--sq-accent-dark);
  stroke-width: 3;
}

.qx-edge.is-intra {
  stroke: var(--qx-warm);
  stroke-dasharray: 7 5;
}

.qx-edge.is-intra.is-cut {
  stroke: var(--sq-accent-dark);
}

.qx-node {
  cursor: pointer;
}

.qx-node-halo {
  fill: var(--sq-surface);
  stroke: var(--block-color, var(--qx-blue));
  stroke-width: 6;
  vector-effect: non-scaling-stroke;
}

.qx-node-core {
  fill: #e5eaed;
  stroke: #6f8190;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.qx-node.is-one .qx-node-core {
  fill: var(--sq-accent);
  stroke: var(--sq-accent-dark);
}

.qx-node.is-selected .qx-node-halo {
  fill: var(--qx-warm-soft);
  stroke: var(--qx-warm);
  stroke-width: 9;
}

.qx-node:focus-visible .qx-node-halo {
  stroke: var(--sq-accent-dark);
  stroke-width: 9;
}

.qx-node-id,
.qx-node-slot {
  fill: var(--sq-text);
  font-family: "Open Sans", Arial, sans-serif;
  text-anchor: middle;
  pointer-events: none;
}

.qx-node.is-one .qx-node-id,
.qx-node.is-one .qx-node-slot {
  fill: #ffffff;
}

.qx-node-id {
  font-size: 14px;
  font-weight: 650;
}

.qx-node-slot {
  fill: var(--qx-ink-soft);
  font-size: 9px;
}

.qx-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.9rem;
  margin-top: 0.55rem;
  color: var(--sq-muted);
  font-size: 0.75rem;
}

.qx-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

.qx-line-key {
  display: inline-block;
  width: 1.5rem;
  height: 0;
  border-top: 3px solid var(--sq-graph-edge);
}

.qx-line-key.is-intra {
  border-top: 2px dashed var(--qx-warm);
}

.qx-line-key.is-cut {
  border-top-color: var(--sq-accent-dark);
}

.qx-graph-note,
.qx-packing-note,
.qx-state-note,
.qx-diagnostic,
.qx-placeholder {
  min-height: 1.35rem;
  margin: 0.55rem 0 0;
  color: var(--sq-muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* Decoded distribution */

.qx-distribution,
.qx-basis-list {
  display: grid;
  gap: 0.42rem;
}

.qx-distribution-row,
.qx-basis-row {
  display: grid;
  grid-template-columns: minmax(4.2rem, auto) minmax(70px, 1fr) minmax(4rem, auto);
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  font-size: 0.78rem;
}

.qx-distribution-row code,
.qx-basis-row code {
  overflow: hidden;
  background: transparent;
  color: var(--sq-text);
  font-size: 0.76rem;
  text-overflow: ellipsis;
}

.qx-probability-track,
.qx-basis-track {
  height: 0.48rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e1e5e2;
}

.qx-probability-track > i,
.qx-basis-track > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--qx-blue);
}

.qx-distribution-row.is-optimal .qx-probability-track > i {
  background: var(--sq-accent);
}

.qx-distribution-row > strong,
.qx-basis-row > strong {
  justify-self: end;
  color: var(--qx-ink-soft);
  font-size: 0.78rem;
  white-space: nowrap;
}

.qx-distribution-row > small {
  grid-column: 1 / -1;
  margin-top: -0.28rem;
  color: var(--sq-accent-dark);
  font-size: 0.68rem;
  font-weight: 650;
}

.qx-map-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 0.65rem;
  margin-top: 0.9rem;
  padding: 0.7rem 0.75rem;
  border-left: 3px solid var(--sq-accent);
  background: var(--sq-soft);
}

.qx-map-result > span,
.qx-map-result > small {
  color: var(--sq-muted);
  font-size: 0.71rem;
}

.qx-map-result > code {
  overflow: hidden;
  background: transparent;
  color: var(--sq-text);
  font-size: 0.78rem;
  text-overflow: ellipsis;
}

.qx-map-result > strong {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--sq-accent-dark);
  font-size: 1.05rem;
}

.qx-map-result > small {
  grid-column: 1 / -1;
}

/* Packing */

.qx-packing-panel {
  border-bottom: 1px solid var(--sq-border);
}

.qx-packing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.qx-packing-actions button {
  padding: 0.42rem 0.7rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.qx-blocks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.qx-block {
  min-width: 0;
  padding: 0.62rem;
  border: 1px solid var(--sq-border);
  border-top: 4px solid var(--block-color, var(--qx-blue));
  border-radius: 5px;
  background: var(--sq-surface);
}

.qx-block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  color: var(--qx-ink-soft);
  font-size: 0.79rem;
  font-weight: 650;
}

.qx-block-title i {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: var(--block-color, var(--qx-blue));
}

.qx-slots {
  display: grid;
  gap: 0.3rem;
}

.qx-slots .qx-slot {
  display: grid;
  grid-template-columns: minmax(1.9rem, auto) minmax(0, 1fr) auto;
  gap: 0.4rem;
  align-items: center;
  width: 100%;
  min-height: 2.4rem;
  padding: 0.32rem 0.45rem;
  text-align: left;
}

.qx-slot > span {
  color: var(--sq-accent-dark);
  font-size: 0.73rem;
  font-weight: 650;
}

.qx-slot > strong {
  color: inherit;
  font-size: 0.81rem;
}

.qx-slot > small {
  color: inherit;
  font-size: 0.64rem;
}

.qx-app .qx-slot.is-selected,
.qx-app .qx-slot[aria-pressed="true"] {
  border-color: var(--qx-warm);
  background: var(--qx-warm-soft);
  color: #5f3d2b;
}

/* Maximum-eigenspace state */

.qx-state-panel {
  border: 0;
  background: var(--sq-surface);
}

.qx-state-panel > summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  cursor: pointer;
  list-style: none;
}

.qx-state-panel > summary::-webkit-details-marker {
  display: none;
}

.qx-state-panel > summary::marker {
  content: "";
}

.qx-state-panel > summary:focus-visible {
  outline: 3px solid rgba(95, 127, 103, 0.38);
  outline-offset: -3px;
}

.qx-state-panel > summary::after {
  content: "+";
  color: var(--sq-accent-dark);
  font-size: 1.15rem;
  line-height: 1;
}

.qx-state-panel[open] > summary::after {
  content: "−";
}

.qx-state-panel > summary:hover {
  background: var(--sq-soft);
}

.qx-state-panel > summary > span {
  color: var(--sq-text);
  font-family: "Josefin Sans", Arial, sans-serif;
  font-size: 1.1rem;
  font-weight: 400;
}

.qx-state-panel > summary > small {
  margin-left: auto;
  color: var(--sq-muted);
  font-size: 0.74rem;
}

.qx-state-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--sq-border);
}

.qx-state-body > h3 {
  margin: 1rem 0 0.65rem;
  padding: 0;
  border: 0;
  font-size: 1rem;
  font-weight: 500;
}

.qx-state-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.qx-state-metrics > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--sq-border);
}

.qx-state-metrics > div + div {
  border-left: 1px solid var(--sq-border);
}

.qx-state-metrics span {
  color: var(--sq-muted);
  font-size: 0.72rem;
}

.qx-state-metrics strong {
  overflow-wrap: anywhere;
  color: var(--sq-text);
  font-size: 0.94rem;
}

.qx-working {
  display: none;
  min-height: 2.6rem;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--sq-border);
  background: var(--sq-soft);
  color: var(--sq-muted);
  font-size: 0.78rem;
  text-align: center;
}

.qx-working.is-visible {
  display: flex;
}

.qx-working.is-error {
  color: #6f4729;
}

.qx-working button {
  min-height: 2rem;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
}

/* Responsive layout */

@media (max-width: 900px) {
  .qx-toolbar {
    grid-template-columns: 1fr;
  }

  .qx-ideal-tag {
    justify-self: start;
  }

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

  .qx-summary > div:nth-child(3) {
    border-top: 1px solid var(--sq-border);
    border-left: 0;
  }

  .qx-summary > div:nth-child(4) {
    border-top: 1px solid var(--sq-border);
  }

  .qx-main-grid {
    grid-template-columns: 1fr;
  }

  .qx-main-grid > .qx-panel + .qx-panel {
    border-top: 1px solid var(--sq-border);
    border-left: 0;
  }
}

@media (max-width: 650px) {
  .qx-mode-picker,
  .qx-blocks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .qx-graph {
    width: 560px;
    min-width: 560px;
  }

  .qx-state-metrics {
    grid-template-columns: 1fr;
  }

  .qx-state-metrics > div + div {
    border-left: 0;
  }
}

@media (max-width: 430px) {
  .qx-toolbar,
  .qx-panel {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .qx-summary > div {
    min-height: 5.8rem;
    padding-right: 0.7rem;
    padding-left: 0.7rem;
  }

  .qx-summary strong {
    font-size: 1.22rem;
  }

  .qx-distribution-row,
  .qx-basis-row {
    grid-template-columns: minmax(3.5rem, auto) minmax(50px, 1fr) minmax(3.8rem, auto);
    gap: 0.35rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qx-app *,
  .qx-app *::before,
  .qx-app *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
