:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ef;
  --line-strong: #bdc8d8;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --warn: #b45309;
  --danger: #b91c1c;
  --font-ui: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.45;
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.2;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--panel-soft);
}

button.active-tool {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

button.active-tool:hover {
  background: #99f6e4;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 8px;
  font-size: var(--text-md);
  line-height: 1.25;
}

select {
  min-height: 34px;
}

textarea,
pre,
#circuit {
  font-family: var(--mono);
}

textarea {
  min-height: 180px;
  resize: vertical;
  font-size: var(--text-sm);
  line-height: 1.45;
  white-space: pre;
}

pre {
  margin: 0;
  white-space: pre-wrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar button {
  min-height: 32px;
  padding: 5px 8px;
  font-size: var(--text-sm);
}

.sidebar input,
.sidebar select {
  min-height: 32px;
  padding: 6px 8px;
  font-size: var(--text-sm);
}

.sidebar input[type="number"] {
  appearance: textfield;
  font-variant-numeric: tabular-nums;
}

.sidebar input[type="number"]::-webkit-inner-spin-button,
.sidebar input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.sidebar-credits {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.sidebar-credits a { color: inherit; }




.brand-block {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-block h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.05;
}

.status-pill {
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.1;
  padding: 4px 8px;
}

.status-pill[data-tone="ok"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill[data-tone="error"] {
  background: #fee2e2;
  color: var(--danger);
}

.tool-section {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.tool-section h2,
.panel h2 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.2;
  text-transform: none;
  color: #334155;
}

.heading-link {
  color: inherit;
  text-decoration: none;
  border-radius: 4px;
}

.heading-link:hover,
.heading-link:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  outline: none;
}

.collapse-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.panel-header .collapse-heading {
  flex: 1;
}

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

.stale-hint {
  border: 1px solid #fde68a;
  border-radius: 999px;
  background: #fffbeb;
  color: #92400e;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
}

#run-circuit.needs-run {
  border-color: #d97706;
  background: #fff7ed;
  color: #9a3412;
  box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.12);
}

.collapse-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  min-height: 22px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.collapse-toggle:hover {
  border-color: var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.collapse-icon {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 120ms ease;
}

[data-collapsed="true"] .collapse-icon {
  transform: rotate(-45deg);
}

.tool-section > .collapse-heading + .collapsible-content {
  margin-top: 7px;
}

.collapsible-content[hidden] {
  display: none;
}

.collapsible-content > .field-label:first-child {
  margin-top: 0;
}

[data-collapsed="true"] > .panel-header {
  margin-bottom: 0;
}

[data-collapsed="true"] > .panel-header > button:not(.collapse-toggle) {
  display: none;
}

.field-label {
  display: block;
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.2;
}

.field-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  margin-top: 7px;
}

.field-row .field-label {
  margin: 0;
}

.qubit-count-row {
  grid-template-columns: 42px minmax(0, 1fr) 56px;
}

.build-section .button-grid,
.build-section .button-row {
  margin-top: 8px;
}

.build-section .angle-row {
  margin-top: 8px;
}

.build-section .button-row {
  padding-top: 2px;
}

.inline-fields,
.demo-loader,
.button-row,
.button-grid {
  display: grid;
  gap: 6px;
}

.demo-loader,
.inline-fields {
  grid-template-columns: 1fr 64px;
}

.button-row {
  grid-template-columns: 1fr 1fr;
}

.button-grid {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 6px;
}

.gate-grid {
  grid-template-columns: repeat(3, 1fr);
}

.two-gate-grid {
  grid-template-columns: repeat(2, 1fr);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.metric-help-wrap {
  position: relative;
}

.metric-help-popover {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 7px);
  z-index: 20;
  display: grid;
  gap: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
  color: #334155;
  padding: 9px 10px;
  font-size: var(--text-xs);
  line-height: 1.35;
}

.metric-help-popover[hidden] {
  display: none;
}

.metric-help-popover strong {
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.2;
}

.metric-help-popover a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.metric-help-popover a:hover,
.metric-help-popover a:focus-visible {
  text-decoration: underline;
  outline: none;
}

.view-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 8px;
  row-gap: 8px;
}

.check-option {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: #334155;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.25;
}

.check-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.segmented-control button {
  border: 0;
  border-radius: 0;
  min-height: 30px;
}

.segmented-control button + button {
  border-left: 1px solid var(--line);
}

.segmented-control .active {
  background: var(--accent);
  color: #fff;
}

.history-control {
  display: grid;
  gap: 6px;
}

.history-control input[type="range"] {
  appearance: none;
  height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.history-control input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: #cbd5e1;
}

.history-control input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -6px;
  border: 2px solid #64748b;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.22);
}

.history-control input[type="range"]:focus-visible {
  outline: none;
}

.history-control input[type="range"]:focus-visible::-webkit-slider-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.history-control input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: #cbd5e1;
}

.history-control input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #64748b;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.22);
}

.history-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.25;
}

.circuit-history {
  margin-bottom: 10px;
}

.circuit-panel[data-collapsed="true"] .circuit-history {
  margin: 10px 0 0;
}

.marker-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  align-items: center;
  min-height: 28px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.marker-button {
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  width: 26px;
  min-height: 26px;
  padding: 0;
  border-color: #dbe3ef;
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
}

.marker-button:hover,
.marker-button:focus-visible {
  border-color: var(--line-strong);
  background: #f8fafc;
  color: var(--text);
  outline: none;
}

.marker-button[data-status="dirty"] {
  border-color: var(--warn);
  background: #fffbeb;
  color: var(--warn);
}

.marker-button[data-status="cached"] {
  border-color: var(--accent);
  background: #f0fdfa;
  color: var(--accent);
}

.marker-button.is-active {
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.1);
  color: var(--text);
}

#history-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#history-count {
  font-variant-numeric: tabular-nums;
}


.reference-link {
  display: block;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  color: var(--accent);
  font-weight: 600;
}
.reference-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1.5fr) minmax(300px, 0.9fr);
  grid-template-areas:
    "circuit circuit"
    "graph metric"
    "graph states"
    "qasm qasm"
    "statevector statevector";
  grid-auto-rows: min-content;
  gap: 18px;
  padding: 16px;
}

.workspace:has(.metric-panel[hidden]):has(.states-panel[hidden]) {
  grid-template-areas:
    "circuit circuit"
    "graph graph"
    "qasm qasm"
    "statevector statevector";
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.circuit-panel {
  background: #fbfdff;
}

.graph-panel {
  grid-area: graph;
}

.metric-panel {
  grid-area: metric;
}

.states-panel {
  grid-area: states;
}

.statevector-panel {
  grid-area: statevector;
}

.circuit-panel {
  grid-area: circuit;
}

.qasm-panel {
  grid-area: qasm;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.muted,
.stats-line {
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.35;
}

#graph {
  min-height: 520px;
  position: relative;
}

#graph svg {
  display: block;
  width: 100%;
  height: 520px;
}

#graph.is-empty::after {
  content: "Graph unavailable.";
  display: block;
  color: var(--muted);
  padding: 16px 0;
}

.link {
  opacity: 0.85;
}

.node {
  stroke-width: 2px;
}

.node-group {
  cursor: pointer;
  outline: none;
}

#graph.placement-active .node-group {
  cursor: copy;
}

#graph.placement-active::after {
  content: attr(data-placement-label);
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 6px;
  background: rgba(240, 253, 250, 0.96);
  color: var(--accent);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  padding: 7px 9px;
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-group.placement-target .node {
  stroke: var(--accent);
  stroke-dasharray: 5 4;
  stroke-width: 3px;
}

.node-group.placement-target:hover .node,
.node-group.placement-target:focus-visible .node {
  fill: var(--accent-soft) !important;
  filter: drop-shadow(0 0 10px rgba(15, 118, 110, 0.28));
}

.node-group.pending-origin {
  cursor: not-allowed;
}

.node-group.pending-origin .node {
  fill: #fef3c7 !important;
  stroke: #d97706;
  stroke-dasharray: none;
  stroke-width: 3px;
}

.node-group:focus-visible .node {
  stroke: var(--accent);
  stroke-width: 3px;
  filter: drop-shadow(0 0 8px rgba(15, 118, 110, 0.24));
}

.node-label {
  fill: #0f172a;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

#basis-grid {
  display: grid;
  gap: 6px;
  max-height: 340px;
  overflow: auto;
}

.basis-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 46px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: var(--mono);
  line-height: 1.25;
}

.basis-cell span {
  color: var(--muted);
  font-size: 11px;
}

.basis-cell strong {
  font-size: var(--text-sm);
}

#metric-matrix {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stats-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: var(--text-xs);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
}

#statevector,
#circuit {
  max-height: 320px;
  overflow: auto;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 16px;
  font-size: var(--text-sm);
  line-height: 1.45;
}


#circuit {
  max-height: 380px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

#circuit svg {
  display: block;
  min-width: 100%;
}

.circuit-label,
.circuit-gate-label {
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 700;
  fill: var(--muted);
}

.circuit-wire {
  stroke: #8fa2bb;
  stroke-width: 1.5;
}

.circuit-connector {
  stroke: #334155;
  stroke-width: 2;
}

.circuit-gate {
  fill: #ffffff;
  stroke: #26364b;
  stroke-width: 1.4;
}

.circuit-gate-label {
  fill: #0f172a;
  text-anchor: middle;
}

.circuit-control {
  fill: #334155;
}

.circuit-swap {
  fill: #334155;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  text-anchor: middle;
}

.circuit-marker {
  color: #b8c5d6;
  cursor: pointer;
  outline: none;
}

.circuit-marker-hit {
  stroke: transparent;
  stroke-width: 18;
  pointer-events: stroke;
}

.circuit-marker-line {
  stroke: currentColor;
  stroke-dasharray: 4 5;
  stroke-width: 1.5;
  opacity: 0.22;
}

.circuit-marker-dot {
  fill: #ffffff;
  stroke: currentColor;
  stroke-width: 1.5;
  opacity: 0.5;
}

.circuit-marker:hover .circuit-marker-line,
.circuit-marker:focus-visible .circuit-marker-line,
.circuit-marker.is-hovered .circuit-marker-line,
.circuit-marker.is-active .circuit-marker-line,
.circuit-marker[data-status="dirty"] .circuit-marker-line,
.circuit-marker[data-status="cached"] .circuit-marker-line {
  opacity: 0.7;
}

.circuit-marker.is-hovered .circuit-marker-line {
  stroke-width: 2.25;
}

.circuit-marker.is-hovered .circuit-marker-dot {
  opacity: 1;
}

.circuit-marker.is-active .circuit-marker-dot {
  opacity: 1;
}

.circuit-marker[data-status="dirty"] {
  color: #d97706;
}

.circuit-marker[data-status="cached"] {
  color: var(--accent);
}

.operations-list {
  display: none;
  flex-wrap: nowrap;
  gap: 6px;
  min-height: 28px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  color: var(--muted);
  font-size: var(--text-xs);
}

.operation-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #334155;
  font-family: var(--mono);
  padding: 4px 8px;
}

.quiet-button {
  min-height: 30px;
  padding: 4px 9px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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


  

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "circuit"
      "graph"
      "metric"
      "states"
      "statevector"
      "qasm";
  }

  .graph-panel,
  .qasm-panel {
    grid-column: auto;
    grid-row: auto;
  }
}
