:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6a7280;
  --line: #d9e0ea;
  --line-strong: #9aa8ba;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --two-qubit: #d94682;
  --two-qubit-soft: #fce7f0;
  --gate: #ffffff;
  --gate-border: #748094;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 18px 45px rgba(24, 35, 58, 0.12);
}

.qc-symbol-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.qc-symbol-sprite text,
.gate-icon text {
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

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

.palette {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
}

.palette-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.palette-section {
  margin-top: 18px;
}

.palette-section h2 {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.saved-block-grid {
  display: grid;
  gap: 8px;
}

.gate-tile {
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--text);
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 14px;
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  --qc-accent: #2563eb;
  --qc-gate-fill: #ffffff;
}

.gate-tile:hover,
.gate-tile:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.gate-tile:active {
  cursor: pointer;
}

.gate-tile.active-tool,
.saved-block-tile.active-tool {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.gate-tile.two-qubit {
  border-color: #f0a7be;
  color: #9f1239;
  --qc-accent: #d94682;
}

.gate-tile.measurement {
  border-color: #c4b5fd;
  color: #6d28d9;
  --qc-accent: #a78bfa;
}

.gate-tile.saved-block,
.saved-block-tile {
  border-color: #99f6e4;
  color: #0f766e;
  --qc-accent: #5eead4;
}

.gate-tile.utility {
  border-color: #cbd5e1;
  color: #475569;
  --qc-accent: #64748b;
}

.saved-block-tile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid #99f6e4;
  border-radius: 7px;
  background: #f0fdfa;
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  touch-action: none;
  user-select: none;
}

.saved-block-edit {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 6px;
  background: #ffffff;
  color: #0f766e;
  cursor: pointer;
}

.saved-block-edit:hover,
.saved-block-edit:focus-visible {
  border-color: #0f766e;
  background: #ccfbf1;
  outline: none;
}

.saved-block-edit:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.small-icon {
  display: block;
  width: 14px;
  height: 14px;
}

.saved-block-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-block-arity {
  color: #64748b;
  font-size: 11px;
}

.saved-block-empty {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.gate-icon {
  display: block;
  width: 34px;
  height: 34px;
  overflow: visible;
  pointer-events: none;
  -webkit-user-drag: none;
}

.palette-icon {
  width: 32px;
  height: 32px;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.view-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.toolbar .view-toggle button {
  height: 32px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.toolbar .view-toggle button.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.toolbar button {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.toolbar button:hover {
  border-color: var(--line-strong);
}

.toolbar .icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  padding: 0;
}

.toolbar .icon-button svg {
  width: 18px;
  height: 18px;
}

.zoom-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.zoom-control input {
  width: 118px;
  accent-color: var(--accent);
}

.zoom-readout {
  width: 44px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.status {
  min-width: 180px;
  color: var(--muted);
  font-size: 13px;
}

.refresh-notice {
  border-color: #fbbf24;
  background: #fffbeb;
  color: #92400e;
}

.refresh-notice:hover,
.refresh-notice:focus-visible {
  border-color: #f59e0b;
  outline: none;
}

.presence-bar {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  margin-left: auto;
}

.presence-chip,
.presence-name-button {
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  height: 28px;
  gap: 6px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.presence-name-button {
  cursor: pointer;
}

.presence-name-button:hover,
.presence-name-button:focus-visible {
  border-color: var(--line-strong);
  outline: none;
}

.presence-chip.online-count {
  background: #eef2ff;
  color: #3730a3;
}

.presence-chip.editing,
.presence-name-button.editing {
  border-color: #99f6e4;
  background: #f0fdfa;
  color: #0f766e;
}

.presence-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.88);
}

.presence-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-mode-label {
  max-width: 240px;
  overflow: hidden;
  padding: 6px 9px;
  border: 1px solid #99f6e4;
  border-radius: 7px;
  background: #f0fdfa;
  color: #0f766e;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block-editor-mode .circuit-frame {
  border-color: #99f6e4;
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12), var(--shadow);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: stretch;
}

.circuit-frame {
  height: calc(100vh - 118px);
  min-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.connections-frame {
  height: calc(100vh - 118px);
  min-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  box-shadow: var(--shadow);
}

.connections-surface {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.connection-layer {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.connection-wire {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 2;
  stroke-linecap: round;
}

.connection-wire.shared {
  stroke: #0f766e;
}

.connection-wire.dangling {
  stroke-dasharray: 5 5;
  opacity: 0.62;
}

.connection-label {
  position: absolute;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.connection-module {
  position: absolute;
  display: grid;
  min-width: 118px;
  min-height: 58px;
  align-content: center;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: rgba(240, 253, 250, 0.92);
  color: #0f766e;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.1);
  cursor: pointer;
  z-index: 3;
}

.connection-module.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16), 0 10px 24px rgba(15, 118, 110, 0.1);
}

.connection-module-title {
  max-width: 148px;
  overflow: hidden;
  padding: 0 18px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-pin {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid #0f766e;
  border-radius: 999px;
  background: #ffffff;
  transform: translate(-50%, -50%);
}

.connection-pin.left {
  left: 0;
}

.connection-pin.right {
  left: 100%;
}

.connection-pin-label {
  position: absolute;
  top: 50%;
  color: #64748b;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  transform: translateY(-50%);
  white-space: nowrap;
  opacity: 0.82;
}

.connection-pin-label.left {
  right: calc(100% + 8px);
}

.connection-pin-label.right {
  left: calc(100% + 8px);
}

.connections-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  color: var(--muted);
  font-size: 14px;
  transform: translate(-50%, -50%);
}

.circuit-frame.panning {
  cursor: grabbing;
  user-select: none;
}

.circuit-frame.panning * {
  cursor: grabbing !important;
}

.circuit-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  cursor: pointer;
}

.circuit-surface {
  position: absolute;
  left: 0;
  top: 0;
  isolation: isolate;
  transform-origin: left top;
}

.wire {
  position: absolute;
  height: 2px;
  background: var(--line);
  transform: translateY(-1px);
  z-index: 1;
}

.top-extension-wire {
  background: repeating-linear-gradient(90deg, rgba(154, 168, 186, 0.45) 0 12px, transparent 12px 20px);
  opacity: 0.72;
}

.drop-tile-highlight {
  position: absolute;
  border: 1px solid rgba(217, 70, 130, 0.24);
  border-radius: 8px;
  background: rgba(217, 70, 130, 0.07);
  pointer-events: none;
  z-index: 3;
}

.drop-tile-highlight.blocked {
  border-color: rgba(220, 38, 38, 0.3);
  background: rgba(220, 38, 38, 0.06);
}

.selection-rectangle {
  position: absolute;
  border: 1px solid rgba(37, 99, 235, 0.58);
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.08);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.12);
  pointer-events: none;
  z-index: 30;
}

.qubit-label {
  position: absolute;
  width: 60px;
  transform: translateY(-50%);
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  z-index: 4;
}

.anchor {
  position: absolute;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: copy;
  transform: translate(-50%, -50%);
  z-index: 5;
}

.anchor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(37, 99, 235, 0.4);
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.12);
  opacity: 0.18;
  transform: translate(-50%, -50%);
  transition: opacity 140ms ease, transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.anchor.top-extension-anchor::after {
  border-color: rgba(100, 116, 139, 0.34);
  background: rgba(100, 116, 139, 0.08);
  opacity: 0.14;
}

.anchor:hover::after,
.anchor:focus-visible::after,
.anchor.drop-candidate::after,
.lock-active .anchor::after,
.target-mode .anchor.valid-target::after {
  opacity: 0.95;
  background: #ffffff;
  border-color: var(--accent);
  outline: none;
  transform: translate(-50%, -50%) scale(1.25);
}

.anchor:focus-visible {
  outline: none;
}

.target-mode .anchor.valid-target::after,
.anchor.drop-candidate::after {
  border-color: var(--two-qubit);
  box-shadow: 0 0 0 5px rgba(217, 70, 130, 0.12);
}

.target-mode .anchor.valid-target {
  z-index: 16;
}

.target-mode .anchor.valid-target::after {
  width: 16px;
  height: 16px;
  border-color: var(--two-qubit);
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(217, 70, 130, 0.14), 0 0 18px rgba(217, 70, 130, 0.22);
  opacity: 1;
}

.barrier-target-mode .anchor.valid-target::after {
  border-color: #64748b;
  box-shadow: 0 0 0 6px rgba(100, 116, 139, 0.14), 0 0 18px rgba(100, 116, 139, 0.2);
}

.anchor.pending-origin::after {
  opacity: 1;
  border-color: #172033;
  background: #172033;
  box-shadow: 0 0 0 5px rgba(23, 32, 51, 0.12);
  transform: translate(-50%, -50%) scale(1.2);
}

.target-mode .anchor:not(.valid-target):not(.pending-origin):not(.blocked-candidate)::after {
  cursor: not-allowed;
  opacity: 0.08;
}

.target-mode .anchor.drop-candidate::after,
.target-mode .anchor.valid-target.drop-candidate::after {
  width: 16px;
  height: 16px;
  border-color: var(--two-qubit);
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(217, 70, 130, 0.14), 0 0 18px rgba(217, 70, 130, 0.22);
  cursor: copy;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.25);
}

.target-mode .anchor.blocked-candidate::after,
.operation-move-mode .anchor.blocked-candidate::after {
  width: 16px;
  height: 16px;
  border-color: #dc2626;
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.12), 0 0 18px rgba(220, 38, 38, 0.18);
  cursor: not-allowed;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.25);
}

.operation-move-mode .anchor.invalid-target::after {
  cursor: not-allowed;
  opacity: 0.08;
}

.operation-move-mode.two-qubit-move-mode .anchor:not(.valid-target):not(.blocked-candidate)::after {
  opacity: 0;
  box-shadow: none;
}

.operation-move-mode.two-qubit-move-mode .anchor.invalid-target:not(.blocked-candidate)::after {
  opacity: 0;
  box-shadow: none;
}

.operation-move-mode .anchor.noop-target {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.operation-move-mode .anchor.blocked-candidate::after,
.operation-move-mode.two-qubit-move-mode .anchor.blocked-candidate::after {
  width: 16px;
  height: 16px;
  border-color: #dc2626;
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.12), 0 0 18px rgba(220, 38, 38, 0.18);
  cursor: not-allowed;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.25);
}

.target-mode.barrier-target-mode .anchor:not(.pending-origin)::after,
.target-mode.barrier-move-mode .anchor::after,
.operation-move-mode.barrier-move-mode .anchor::after,
.lock-active .barrier-palette-lock-mode .anchor::after,
.barrier-palette-lock-mode .anchor.drop-candidate::after,
.barrier-target-mode .anchor.drop-candidate::after,
.barrier-move-mode .anchor.drop-candidate::after {
  opacity: 0;
  box-shadow: none;
}

.target-mode.barrier-target-mode .anchor.pending-origin::after {
  opacity: 1;
  border-color: #64748b;
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(100, 116, 139, 0.14);
}

.barrier-slot-highlight {
  position: absolute;
  width: 38px;
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 17;
}

.barrier-slot-highlight::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  border-left: 2px dashed #64748b;
  filter: drop-shadow(0 0 8px rgba(100, 116, 139, 0.24));
  transform: translateX(-50%);
}

.barrier-slot-endpoint {
  position: absolute;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid #64748b;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(100, 116, 139, 0.12);
  transform: translate(-50%, -50%);
}

.block-slot-highlight {
  position: absolute;
  display: grid;
  width: 70px;
  min-height: 44px;
  place-items: center;
  border: 2px solid #0f766e;
  border-radius: 8px;
  background: rgba(240, 253, 250, 0.72);
  color: #0f766e;
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 17;
  box-shadow: 0 0 0 6px rgba(45, 212, 191, 0.12), 0 0 18px rgba(15, 118, 110, 0.14);
}

.block-slot-highlight::before,
.block-slot-highlight::after {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  border-left: 2px solid rgba(15, 118, 110, 0.44);
}

.block-slot-highlight::before {
  left: 11px;
}

.block-slot-highlight::after {
  right: 11px;
}

.block-slot-highlight.blocked {
  border-color: #dc2626;
  background: rgba(254, 242, 242, 0.74);
  color: #991b1b;
  box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.12), 0 0 18px rgba(220, 38, 38, 0.18);
}

.block-slot-highlight.blocked::before,
.block-slot-highlight.blocked::after {
  border-left-color: rgba(220, 38, 38, 0.45);
}

.block-slot-label {
  max-width: 48px;
  overflow: hidden;
  padding: 2px 4px;
  border-radius: 5px;
  background: #ffffff;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1;
}

.gate-node {
  position: absolute;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
  transform: translate(-50%, -50%);
  touch-action: none;
  user-select: none;
  z-index: 10;
  --qc-accent: #2563eb;
  --qc-gate-fill: #ffffff;
}

.gate-node .gate-icon {
  width: 48px;
  height: 48px;
  filter: drop-shadow(0 7px 12px rgba(16, 24, 40, 0.13));
}

.gate-node.rotation {
  color: #047857;
  --qc-accent: #10b981;
}

.gate-node.two-qubit {
  color: #9f1239;
  --qc-accent: #d94682;
}

.gate-node.measurement {
  color: #6d28d9;
  --qc-accent: #a78bfa;
}

.gate-node.saved-block {
  color: #0f766e;
  --qc-accent: #5eead4;
}

.gate-node.utility {
  color: #475569;
  --qc-accent: #64748b;
}

.block-node {
  position: absolute;
  display: grid;
  width: 66px;
  min-height: 44px;
  place-items: center;
  border: 2px solid #0f766e;
  border-radius: 8px;
  background: rgba(240, 253, 250, 0.92);
  color: #0f766e;
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  transform: translateX(-50%);
  touch-action: none;
  user-select: none;
  z-index: 10;
  box-shadow: 0 8px 16px rgba(15, 118, 110, 0.12);
}

.block-node::before,
.block-node::after {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  border-left: 2px solid rgba(15, 118, 110, 0.42);
}

.block-node::before {
  left: 11px;
}

.block-node::after {
  right: 11px;
}

.block-node.selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16), 0 8px 16px rgba(15, 118, 110, 0.12);
}

.block-node-label {
  max-width: 46px;
  overflow: hidden;
  padding: 2px 4px;
  border-radius: 5px;
  background: #ffffff;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1;
}

.block-expanded-node {
  position: absolute;
  overflow: hidden;
  border: 2px solid #0f766e;
  border-radius: 8px;
  background: rgba(240, 253, 250, 0.92);
  color: #0f766e;
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  touch-action: none;
  user-select: none;
  z-index: 10;
  box-shadow: 0 8px 16px rgba(15, 118, 110, 0.12);
}

.block-expanded-node.selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16), 0 8px 16px rgba(15, 118, 110, 0.12);
}

.block-expanded-label {
  position: absolute;
  left: 50%;
  top: 4px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  padding: 1px 5px;
  border-radius: 5px;
  background: #ffffff;
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 2;
}

.block-internal-wire,
.block-internal-connector,
.block-internal-barrier,
.block-internal-block,
.block-internal-control,
.block-internal-gate {
  position: absolute;
  pointer-events: none;
}

.block-internal-wire {
  height: 1px;
  background: rgba(15, 118, 110, 0.22);
  transform: translateY(-0.5px);
}

.block-internal-connector {
  border-left: 2px solid rgba(15, 118, 110, 0.5);
  transform: translateX(-1px);
}

.block-internal-barrier {
  border-left: 2px dashed rgba(15, 118, 110, 0.58);
  transform: translateX(-1px);
}

.block-internal-block {
  display: grid;
  width: 34px;
  min-height: 22px;
  place-items: center;
  border: 1.5px solid #0f766e;
  border-radius: 6px;
  background: rgba(240, 253, 250, 0.88);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.08);
  transform: translateX(-50%);
  z-index: 1;
}

.block-internal-block::before,
.block-internal-block::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  border-left: 1px solid rgba(15, 118, 110, 0.36);
}

.block-internal-block::before {
  left: 7px;
}

.block-internal-block::after {
  right: 7px;
}

.block-internal-block span {
  max-width: 25px;
  overflow: hidden;
  padding: 1px 2px;
  border-radius: 4px;
  background: #ffffff;
  font-size: 8px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1;
}

.block-internal-control {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #0f766e;
  transform: translate(-50%, -50%);
}

.block-internal-control.open-control {
  border: 1.5px solid #0f766e;
  background: #ffffff;
}

.block-internal-gate {
  display: grid;
  width: 24px;
  height: 20px;
  place-items: center;
  border: 1.5px solid #0f766e;
  border-radius: 5px;
  background: #ffffff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.block-internal-gate.target {
  border-color: #9f1239;
  color: #9f1239;
}

.gate-node.selected {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16);
}

.param-badge {
  position: absolute;
  left: 50%;
  bottom: 0;
  min-width: 30px;
  padding: 1px 4px;
  border: 1px solid rgba(4, 120, 87, 0.22);
  border-radius: 999px;
  background: #ffffff;
  color: #047857;
  font-size: 10px;
  line-height: 1.1;
  transform: translate(-50%, 30%);
  box-shadow: 0 2px 5px rgba(16, 24, 40, 0.09);
}

.control-dot {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--connector-color, #172033);
  border: 2px solid var(--connector-color, #172033);
  transform: translate(-50%, -50%);
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 0 0 5px var(--connector-soft, rgba(23, 32, 51, 0.08));
  z-index: 9;
}

.control-dot.open-control {
  background: #ffffff;
}

.control-dot:hover {
  box-shadow: 0 0 0 7px var(--connector-soft, rgba(217, 70, 130, 0.15));
}

.control-dot.selected {
  box-shadow: 0 0 0 7px rgba(37, 99, 235, 0.18);
}

.barrier-node {
  position: absolute;
  width: 44px;
  min-height: 48px;
  color: #475569;
  cursor: default;
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 8;
}

.barrier-stem {
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: 8px;
  border-left: 2px dashed currentColor;
  transform: translateX(-50%);
}

.barrier-node.selected .barrier-stem {
  border-left-color: #2563eb;
  filter: drop-shadow(0 0 5px rgba(37, 99, 235, 0.28));
}

.barrier-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #64748b;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  transform: translate(-50%, -50%);
  touch-action: none;
  z-index: 11;
}

.barrier-handle.selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.15);
}

.multi-line {
  position: absolute;
  width: 0;
  border-left: 2px var(--connector-style, solid) var(--connector-color, #172033);
  transform: translateX(-50%);
  box-shadow: 0 0 0 2px var(--connector-soft, transparent);
  z-index: 8;
}

.multi-line.selected {
  width: 0;
  border-left: 3px solid #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12), 0 0 8px rgba(37, 99, 235, 0.28);
}

.connector-stub {
  position: absolute;
  height: 0;
  border-top: 2px var(--connector-style, solid) var(--connector-color, #172033);
  transform: translateY(-50%);
  box-shadow: 0 0 0 2px var(--connector-soft, transparent);
  z-index: 8;
}

.connector-stub.selected {
  height: 0;
  border-top: 3px solid #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12), 0 0 8px rgba(37, 99, 235, 0.28);
}

.barrier-stub {
  position: absolute;
  height: 0;
  border-top: 2px dashed #64748b;
  transform: translateY(-50%);
  z-index: 8;
}

.pending-layer,
.floating-guide {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 12;
}

.pending-guide-line,
.floating-guide-line {
  stroke: var(--two-qubit);
  stroke-width: 3;
  stroke-dasharray: 8 7;
  stroke-linecap: round;
}

.pending-guide-line.blocked-target {
  stroke: #dc2626;
}

.pending-origin-ring {
  fill: rgba(217, 70, 130, 0.08);
  stroke: var(--two-qubit);
  stroke-width: 2;
  transform-origin: center;
  animation: pending-pulse 1.2s ease-in-out infinite;
}

.pending-guide-cursor,
.floating-guide-cursor {
  fill: var(--two-qubit);
}

.pending-guide-cursor.blocked-target {
  fill: #ffffff;
  stroke: #dc2626;
  stroke-width: 3;
}

.floating-guide-fixed {
  fill: #172033;
}

.floating-lock-preview {
  position: fixed;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 1000;
}

.floating-lock-preview[hidden] {
  display: none;
}

.pending-gate-stub {
  position: absolute;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #9f1239;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
  transform: translate(-50%, -50%);
  --qc-accent: #d94682;
  --qc-gate-fill: #ffffff;
  filter: drop-shadow(0 0 6px rgba(217, 70, 130, 0.26));
  cursor: pointer;
  pointer-events: auto;
  z-index: 14;
}

.pending-gate-stub:hover {
  filter: drop-shadow(0 0 8px rgba(217, 70, 130, 0.34));
}

@keyframes pending-pulse {
  0%,
  100% {
    opacity: 0.55;
    r: 15;
  }
  50% {
    opacity: 1;
    r: 20;
  }
}

.trash-zone {
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px dashed #ef9a9a;
  border-radius: 8px;
  background: rgba(254, 242, 242, 0.72);
  color: #991b1b;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.trash-zone:not(:disabled):hover,
.trash-zone:not(:disabled):focus-visible {
  border-color: var(--danger);
  background: var(--danger-soft);
  outline: none;
  transform: translateY(-1px);
}

.trash-zone:disabled {
  border-color: var(--line);
  background: #f8fafc;
  color: #94a3b8;
  cursor: default;
}

.trash-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
}

.gate-inspector {
  min-height: 560px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 26px rgba(24, 35, 58, 0.08);
}

.inspector-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.inspector-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.inspector-preview {
  display: grid;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  place-items: center;
  color: var(--text);
  --qc-accent: #2563eb;
  --qc-gate-fill: #ffffff;
}

.inspector-preview.rotation {
  color: #047857;
  --qc-accent: #10b981;
}

.inspector-preview.two-qubit {
  color: #9f1239;
  --qc-accent: #d94682;
}

.inspector-preview.measurement {
  color: #6d28d9;
  --qc-accent: #a78bfa;
}

.inspector-preview.saved-block {
  color: #0f766e;
  --qc-accent: #5eead4;
}

.inspector-preview.utility {
  color: #475569;
  --qc-accent: #64748b;
}

.inspector-preview .gate-icon {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 6px 10px rgba(16, 24, 40, 0.12));
}

.inspector-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inspector-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.inspector-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.inspector-section {
  padding-top: 16px;
}

.inspector-section h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

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

.inspector-action-button {
  min-height: 34px;
  border: 1px solid #99f6e4;
  border-radius: 7px;
  background: #f0fdfa;
  color: #0f766e;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.inspector-action-button:hover {
  border-color: #0f766e;
  background: #ccfbf1;
}

.inspector-action-button.secondary {
  border-color: var(--line);
  background: #ffffff;
  color: var(--muted);
}

.inspector-action-button.secondary:hover {
  border-color: var(--line-strong);
  background: #f8fafc;
  color: var(--text);
}

.meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.meta-row span:first-child {
  color: var(--muted);
}

.meta-row span:last-child {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 600;
}

.param-field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.param-field:first-child {
  margin-top: 0;
}

.param-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.param-label-row label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.param-readout {
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
}

.param-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 8px;
  align-items: center;
}

.param-input-row input[type="range"] {
  width: 100%;
}

.param-input-row input[type="number"],
.param-number {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--text);
  font-size: 13px;
}

.affix-input {
  position: relative;
}

.affix-input input {
  padding-right: 22px;
}

.affix-input span {
  position: absolute;
  right: 8px;
  top: 50%;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  transform: translateY(-50%);
  pointer-events: none;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.segment-button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
}

.segment-button.active {
  background: #ffffff;
  color: #172033;
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.12);
}

.param-placeholder {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

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

  .gate-grid {
    grid-template-columns: repeat(6, minmax(42px, 1fr));
  }

  .toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .gate-inspector {
    min-height: 0;
  }
}
