:root {
  --bloch-accent: #1772d0;
  --bloch-accent-2: #f09228;
  --bloch-muted: #666;
  --bloch-border: #e0e0e0;
  --bloch-card-bg: #f7f7f7;
  --bloch-text: #222;
  --bloch-radius: 8px;
}

.blochviz {
  font: inherit;
  color: var(--bloch-text);
  margin-top: 8px;
}

.blochviz * {
  box-sizing: border-box;
}

a.button-link {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--bloch-accent);
  border-radius: 999px;
  color: var(--bloch-accent);
  background: #fff;
}

a.button-link:hover,
a.button-link:focus {
  border-color: var(--bloch-accent-2);
  color: var(--bloch-accent-2);
}

.blochviz .card {
  background: var(--bloch-card-bg);
  border: 1px solid var(--bloch-border);
  border-radius: var(--bloch-radius);
  padding: 0.8rem 0.9rem;
  margin: 0 0 1rem 0;
}

.blochviz h4 {
  margin: 0 0 0.6rem 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--bloch-border);
  font-weight: 600;
}

.blochviz .explanation {
  color: var(--bloch-muted);
  margin: 0.25rem 0 0.35rem 0;
  line-height: 1.38;
}

.blochviz .param-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 0.5rem;
  margin: 0.28rem 0;
}

.blochviz .param-row label {
  color: #000;
  font-weight: 600;
  text-align: left;
}

.blochviz .control {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 0.4rem;
  align-items: center;
}

.blochviz select,
.blochviz input[type="number"] {
  font-size: 0.95em;
  border: 1px solid #cfcfcf;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

.blochviz select {
  width: 100%;
}

.blochviz input[type="number"] {
  font-family: Menlo, Consolas, ui-monospace, monospace;
  text-align: center;
}

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

.blochviz input[type=number] {
  -moz-appearance: textfield;
}

.blochviz input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(90deg, var(--bloch-accent) 0%, var(--bloch-accent) 0%) no-repeat, #e5e5e5;
  background-size: 0% 100%;
  border-radius: 999px;
  outline: none;
}

.blochviz input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid var(--bloch-accent);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  margin-top: -4px;
}

.blochviz input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid var(--bloch-accent);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

.blochviz input[type="range"].has-fill {
  background-size: var(--fill, 0%) 100%;
}

.blochviz .warn {
  color: #b00020;
  margin: 0.2rem 0 0.1rem 0;
  font-weight: 600;
}

.blochviz .info-divider {
  height: 1px;
  margin: 0.65rem 0 0.85rem 0;
  background: linear-gradient(90deg, transparent 0%, #d9d9d9 10%, #d9d9d9 90%, transparent 100%);
}

.blochviz .canvas-wrap {
  position: relative;
  margin-top: 0.2rem;
  border: 1px solid var(--bloch-border);
  border-radius: 10px;
  padding: 4px;
  background: linear-gradient(180deg, #fbfbfb 0%, #f3f3f3 100%);
}

.blochviz #bloch-canvas {
  display: block;
  width: 100%;
  height: 390px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #ececec;
  touch-action: none;
  cursor: grab;
}

.blochviz #bloch-canvas.dragging {
  cursor: grabbing;
}

.blochviz .pole-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: #555;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(220, 220, 220, 0.9);
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.1;
  font-size: 0.9em;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  white-space: nowrap;
}

.blochviz .pole-label mjx-container {
  margin: 0 !important;
}

.blochviz .diag-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0.35rem 0.8rem;
  align-items: center;
  font-size: 0.95em;
}

.blochviz .diag-grid span:nth-child(odd) {
  color: #000;
  font-weight: 600;
}

.blochviz .diag-grid span:nth-child(even) {
  font-family: Menlo, Consolas, ui-monospace, monospace;
}

.blochviz .diag-grid.wide-labels {
  grid-template-columns: minmax(185px, 260px) 1fr;
}

.blochviz .diag-grid .hidden {
  display: none !important;
}

.blochviz .legend-dot {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 0.35em;
}

.blochviz .hidden {
  display: none !important;
}

.blochviz .shared-note {
  color: var(--bloch-muted);
  margin: 0.05rem 0 0.75rem 0;
  line-height: 1.34;
}

.blochviz .controls-col {
  display: block;
}

@media (min-width: 900px) {
  .blochviz .controls-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
    align-items: start;
    margin-bottom: 0.8rem;
  }

  .blochviz .controls-col > .card {
    margin: 0;
    padding: 0.7rem 0.8rem;
  }

  .blochviz .parameters .explanation,
  .blochviz .state .explanation {
    font-size: 0.92em;
    line-height: 1.3;
    margin-bottom: 0.2rem;
  }

  .blochviz .controls-col h4 {
    margin-bottom: 0.45rem;
    padding-bottom: 0.28rem;
  }

  .blochviz .controls-col .param-row {
    grid-template-columns: 118px 1fr;
    gap: 0.4rem;
    margin: 0.22rem 0;
  }

  .blochviz .controls-col .control {
    grid-template-columns: 1fr 78px;
    gap: 0.35rem;
  }

  .blochviz .controls-col select,
  .blochviz .controls-col input[type="number"] {
    padding: 5px 7px;
    font-size: 0.92em;
  }

  .blochviz .viewer {
    margin-top: 0;
    padding: 0.65rem 0.7rem;
  }

  .blochviz #bloch-canvas {
    height: 410px;
  }
}

@media (max-width: 760px) {
  .blochviz .param-row {
    grid-template-columns: 1fr;
  }

  .blochviz .control {
    grid-template-columns: 1fr;
  }

  .blochviz .diag-grid,
  .blochviz .diag-grid.wide-labels {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .blochviz .diag-grid span:nth-child(even) {
    margin-bottom: 0.3rem;
  }

  .blochviz #bloch-canvas {
    height: 300px;
  }
}
