/**
 * Quantum Gate Simulator - Bloch Sphere visualization
 * Max width 800px; Courier New; dark theme.
 */
#quantum-gate-root {
  max-width: 900px;
  margin: 0 auto;
  background: #121212;
  color: #eee;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  padding: 12px;
  box-sizing: border-box;
}

#quantum-gate-root * {
  box-sizing: border-box;
}

/* Grid: 1-qubit = Input | Gates | Output; 2-qubit = Input Q0/Q1 | Gates | Output Q0/Q1 */
.qg-app {
  display: grid;
  grid-template-columns: 1fr 150px 1fr;
  grid-template-rows: 1fr;
  gap: 10px;
  align-items: start;
  justify-items: center;
}

.qg-app.qg-mode-2qubit {
  grid-template-columns: 1fr 150px 1fr;
  grid-template-rows: 1fr 1fr;
}

.qg-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
}

.qg-column.qg-2qubit-only {
  display: none;
}
.qg-app.qg-mode-2qubit .qg-column.qg-2qubit-only {
  display: flex;
}

/* 1-qubit: Input Q1 | Gates | Output Q1 */
.qg-app > .qg-column:nth-child(1) { grid-column: 1; grid-row: 1; }
.qg-app > .qg-column:nth-child(2) { grid-column: 1; grid-row: 1; }
.qg-app > .qg-column:nth-child(3) {
  grid-column: 2;
  grid-row: 1;
  justify-content: center;
  width: 150px;
  min-width: 0;
  overflow: hidden;
}
.qg-app > .qg-column:nth-child(4) { grid-column: 3; grid-row: 1; }
.qg-app > .qg-column:nth-child(5) { grid-column: 3; grid-row: 1; }

/* 2-qubit: Input Q0/Q1 (col 1) | Gates (col 2) | Output Q0/Q1 (col 3, stacked) */
.qg-app.qg-mode-2qubit > .qg-column:nth-child(1) { grid-column: 1; grid-row: 1; }
.qg-app.qg-mode-2qubit > .qg-column:nth-child(2) { grid-column: 1; grid-row: 2; }
.qg-app.qg-mode-2qubit > .qg-column:nth-child(3) {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 150px;
  min-width: 0;
  overflow: hidden;
}
.qg-app.qg-mode-2qubit > .qg-column:nth-child(4) { grid-column: 3; grid-row: 1; }
.qg-app.qg-mode-2qubit > .qg-column:nth-child(5) { grid-column: 3; grid-row: 2; }

.qg-column h3 {
  margin: 0 0 12px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #0fa;
}

/* Sphere container - 1:1 aspect */
.qg-sphere-container {
  width: 200px;
  height: 200px;
  position: relative;
  background: #0a0a0a;
  border-radius: 4px;
}

/* Home button - top right corner */
.qg-home-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 4px;
  background: rgba(26, 26, 26, 0.85);
  color: #0fa;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
  z-index: 10;
}
.qg-home-btn:hover {
  background: rgba(0, 255, 170, 0.25);
  border-color: #0fa;
}
.qg-home-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Redo button - left of home, output sphere only */
.qg-redo-btn {
  position: absolute;
  top: 6px;
  right: 38px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 4px;
  background: rgba(26, 26, 26, 0.85);
  color: #0fa;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
  z-index: 10;
}
.qg-redo-btn:hover {
  background: rgba(0, 255, 170, 0.25);
  border-color: #0fa;
}
.qg-redo-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Dirac / state label */
.qg-label {
  margin-top: 10px;
  font-size: 11px;
  color: #0fa;
  text-align: center;
  min-height: 36px;
  word-break: break-all;
}

/* Slider group */
.qg-slider-group {
  width: 100%;
  margin-top: 12px;
}

.qg-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.qg-slider-row:first-child {
  margin-top: 0;
}

.qg-slider-label {
  flex-shrink: 0;
  font-size: 13px;
  color: #fff;
  min-width: 24px;
}

.qg-slider-input {
  flex: 1;
  min-width: 0;
  accent-color: #0fa;
}

.qg-slider-value {
  flex-shrink: 0;
  font-size: 11px;
  color: #0fa;
  min-width: 72px;
  text-align: right;
}

/* Gate dropdown */
.qg-gate-select {
  width: 100%;
  padding: 8px 6px;
  margin-bottom: 10px;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  cursor: pointer;
  accent-color: #0fa;
}
.qg-gate-select:hover,
.qg-gate-select:focus {
  border-color: #0fa;
  outline: none;
}

/* Gate matrix 2x2 */
.qg-gate-matrix {
  margin: 8px 0 12px 0;
  padding: 8px;
  background: #111;
  border: 1px solid #333;
  border-radius: 4px;
}
.qg-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  color: #0fa;
}
.qg-matrix-cell {
  padding: 4px 6px;
  text-align: center;
  border: 1px solid #333;
  min-width: 48px;
}

/* Gamma (rotation angle) slider for parametric gates - value on next line, expanded slider */
.qg-gamma-group {
  margin: 6px 0;
  padding: 6px 4px;
  background: #1a1a2a;
  border: 1px solid #444;
  border-radius: 4px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.qg-gamma-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qg-gamma-label {
  flex-shrink: 0;
  font-size: 11px;
  color: #fff;
  min-width: 18px;
}
.qg-gamma-slider {
  flex: 1;
  min-width: 0;
  accent-color: #0fa;
}
.qg-gamma-value {
  font-size: 10px;
  color: #0fa;
  text-align: center;
  margin-top: 4px;
}

/* Gate buttons */
.qg-gate-btn {
  width: 100%;
  padding: 8px 6px;
  margin: 4px 0;
  cursor: pointer;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  transition: 0.2s;
}

.qg-gate-btn:hover {
  background: #0fa;
  color: #000;
  border-color: #0fa;
}

.qg-gate-btn[title] {
  cursor: help;
}

.qg-reset-btn {
  margin-top: 12px;
  background: #442222 !important;
  border-color: #663333 !important;
}

.qg-reset-btn:hover {
  background: #663333 !important;
  color: #fff !important;
}

/* 4-component state vector */
.qg-state-4vec {
  font-size: 9px;
  color: #0fa;
  margin: 4px 0;
  padding: 4px 6px;
  background: #111;
  border-radius: 4px;
  word-break: break-all;
  line-height: 1.3;
}

/* Entanglement warning */
.qg-entangled-warning {
  font-size: 10px;
  color: #a020f0;
  margin: 6px 0;
  text-align: center;
  padding: 4px 6px;
  background: rgba(160, 32, 240, 0.15);
  border-radius: 4px;
}

/* 4x4 matrix cells */
.qg-matrix-4x4 .qg-matrix-cell {
  min-width: 28px;
  font-size: 11px;
}

/* Probability histogram */
.qg-histogram-container {
  padding: 16px 20px;
  margin-top: 12px;
  border-top: 1px solid #333;
  width: 100%;
  max-width: 900px;
  box-sizing: border-box;
}
.qg-histogram-title {
  text-align: center;
  color: #888;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 0 0 12px 0;
}
.qg-hist-bars {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  height: 100px;
  gap: 8px;
}
.qg-bar-wrapper {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.qg-bar {
  width: 36px;
  min-height: 2px;
  background: #0fa;
  transition: height 0.3s ease;
  border-radius: 4px 4px 0 0;
}
.qg-bar-label {
  font-size: 10px;
  margin-top: 6px;
  color: #0fa;
}
.qg-bar-val {
  font-size: 10px;
  color: #888;
  margin-top: 2px;
}

/* Measure and Reset Simulation buttons */
.qg-measure-btn {
  background: #2a2a4a !important;
  border-color: #444466 !important;
}
.qg-measure-btn:hover {
  background: #3a3a6a !important;
  border-color: #0fa !important;
}
.qg-reset-sim-btn {
  background: #2a2a2a !important;
  border-color: #444 !important;
}
