/* ── Circuits in posts and on the circuit page ───────────────────────────────
   The drawing (js/circuit-draw.js) and what the circuit does
   (js/circuit-results.js), styled after the simulator's own builder and
   panels (simulator/styles/components.css) so they read as the same thing.
   Built on the forum/account tokens (--pr-*). */

/* ── The drawing: tiles, discs, buses, the measurement block ──────────────── */

.cq .cq-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    border-radius: 0.5rem;
    border: 2px solid var(--cq-edge);
    background: var(--cq-color);
    color: #fff;
    box-sizing: border-box;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.cq .cq-tile-label {
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
}

/* The other end of a swap: "↔q1" under the symbol, as on the builder's tile. */
.cq .cq-tile-sub {
    font-size: 0.42rem;
    font-weight: 600;
    line-height: 1;
    opacity: 0.95;
    margin-top: 1px;
    white-space: nowrap;
}

.cq .cq-tile:has(.cq-tile-sub) .cq-tile-label {
    font-size: 0.74rem;
}

/* The angle hangs under a rotation, grey, as the builder hangs "θ=54.0°". */
.cq .cq-param {
    position: absolute;
    transform: translateX(-50%);
    font-size: 0.56rem;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
    /* On the canvas colour, above the buses: a control or swap line running
       through the column passes behind the angle rather than through it. */
    background: #0a0a1a;
    color: var(--pr-faint);
    white-space: nowrap;
    pointer-events: none;
    z-index: 3;
}

/* A control: a disc in the gate's colour, "C" over "→q2". */
.cq .cq-disc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 2px solid var(--cq-edge);
    background: var(--cq-color);
    color: #fff;
    box-sizing: border-box;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.cq .cq-disc-label {
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
}

.cq .cq-disc-arrow {
    font-size: 0.36rem;
    font-weight: 600;
    line-height: 1;
    margin-top: 1px;
    max-width: 30px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A measurement: a green block down the column, an M on each measured wire. */
.cq .cq-measure-block {
    position: absolute;
    border-radius: 0.5rem;
    border: 2px solid #059669;
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.9), rgba(5, 150, 105, 0.9));
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    box-sizing: border-box;
    z-index: 0;
}

/* Tiles and discs sit above buses and the measurement block. */
.cq .cq-tile,
.cq .cq-disc {
    z-index: 2;
}

/* The M on a measured wire: the builder's solid green tile on the block. */
.cq .cq-tile--measure {
    background: #10b981;
    border-color: #34d399;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.cq .cq-tile--if {
    border-style: dashed;
}

.cq .cq-tile-if {
    position: absolute;
    top: -6px;
    right: -6px;
    padding: 0 3px;
    border-radius: 6px;
    background: #0ea5e9;
    color: #fff;
    font-size: 0.5rem;
    font-weight: 700;
    line-height: 11px;
    letter-spacing: 0.02em;
}

/* ── Loops, conditions, function bars, annotations ────────────────────────────
   The builder's control-flow blocks (components.css .control-flow-*), the
   function-call header bars (main.css .qubi-fn-span-bar) and the annotation
   boxes (.circuit-annotation), scaled with the tiles (50px -> 34px). */

.cq .cq-cf {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 0.5rem;
    box-sizing: border-box;
    overflow: visible;
    z-index: 1;
}

.cq .cq-cf--loop {
    background: linear-gradient(180deg, rgba(168, 85, 247, 0.9), rgba(139, 92, 246, 0.9));
    border: 2px solid #7c3aed;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.cq .cq-cf--end {
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.9), rgba(220, 38, 38, 0.9));
    border: 2px solid #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.cq .cq-cf--if {
    background: linear-gradient(180deg, rgba(14, 165, 233, 0.9), rgba(2, 132, 199, 0.9));
    border: 2px solid #0369a1;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.cq .cq-cf--else {
    background: linear-gradient(180deg, rgba(245, 158, 11, 0.9), rgba(217, 119, 6, 0.9));
    border: 2px solid #b45309;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.cq .cq-cf-symbol {
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.cq .cq-cf--if .cq-cf-symbol,
.cq .cq-cf--else .cq-cf-symbol {
    font-size: 10.5px;
    font-style: italic;
}

.cq .cq-cf-label {
    font-size: 9px;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: rgba(0, 0, 0, 0.2);
    padding: 1px 4px;
    border-radius: 3px;
    max-width: 44px;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.cq .cq-cf-end {
    font-size: 7px;
    font-weight: 500;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    max-width: 31px;
    overflow-wrap: break-word;
}

.cq .cq-cf-cond {
    font-size: 7px;
    font-weight: 600;
    line-height: 1.15;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(0, 0, 0, 0.2);
    padding: 1px 3px;
    border-radius: 3px;
    text-align: center;
    max-width: 31px;
    overflow-wrap: break-word;
}

.cq .cq-fn {
    position: absolute;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0 5px;
    border-radius: 4px;
    color: #fff;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
    z-index: 4;
}

.cq .cq-fn-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cq .cq-ann {
    position: absolute;
    box-sizing: border-box;
    padding: 1px 5px;
    border-radius: 3px;
    /* components.css: the primary colour 18% over the surface, border 42%. */
    background: #2a2b51;
    border: 1px solid #3b3c80;
    color: #e2e8f0;
    font-size: 8px;
    line-height: 13px;
    overflow: hidden;
    white-space: nowrap;
    z-index: 4;
}

.cq .cq-ann--error {
    background: #593534;
    border-color: #91333a;
    color: #fecaca;
}

.cq .cq-ann-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A LABEL name in place of q[n]. */
.cq .cq-qlabel--custom {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A branch that does not run, as the builder's .reality-inactive. */
.cq .cq-dim {
    opacity: 0.28;
    filter: grayscale(1);
}

/* ── The results ─────────────────────────────────────────────────────────── */

.cr {
    display: grid;
    gap: 16px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--pr-line);
}

/* Result blocks are sections, but not the page's big sections. */
.ac-main .cr-block,
.cr .cr-block {
    padding: 0;
    margin: 0;
    min-width: 0;
}

.cr-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 8px;
}

.cr-title {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--pr-muted);
}

.cr-sub {
    color: var(--pr-faint);
    font-size: 0.76rem;
}

.cr-note {
    margin: 8px 0 0;
    color: var(--pr-muted);
    font-size: 0.8rem;
}

/* The basis chip: |101⟩ in a mono face on a purple wash, as the builder's. */
.qr-basis {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(107, 95, 199, 0.22);
    color: var(--pr-ink);
    font-family: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Probabilities list */
.qr-list {
    display: grid;
    gap: 4px;
    max-width: 480px;
}

.qr-row {
    display: grid;
    grid-template-columns: minmax(64px, auto) 1fr 60px;
    align-items: center;
    gap: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--fm-hover, rgba(148, 163, 184, 0.1));
}

.qr-track {
    display: block;
    height: 5px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.qr-fill {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #14b8a6, #6b5fc7);
}

.qr-pct {
    text-align: right;
    color: var(--pr-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.qr-singles {
    margin-top: 12px;
    font-size: 0.8rem;
    display: grid;
    gap: 4px;
}

.qr-singles-title {
    color: var(--pr-muted);
    font-size: 0.72rem;
}

.qr-single {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;
}

.qr-single-q {
    color: #8b7cf6;
    min-width: 24px;
}

.qr-single-v {
    color: var(--pr-ink);
}

.qs-na {
    color: var(--pr-faint);
}

/* Bar chart */
.qr-chart {
    margin-top: 14px;
    max-width: 480px;
}

.qr-bars {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    height: 120px;
    padding: 0 6px;
    border-radius: 8px;
    background: var(--fm-hover, rgba(148, 163, 184, 0.1));
    box-sizing: border-box;
}

.qr-bar-wrap {
    display: flex;
    align-items: flex-end;
    flex: 1 1 0;
    max-width: 44px;
    height: 100%;
}

.qr-bar {
    width: 100%;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, var(--c), color-mix(in srgb, var(--c) 60%, #fff 0%));
    background: linear-gradient(180deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
    box-shadow: 0 -2px 8px color-mix(in srgb, var(--c) 40%, transparent);
}

.qr-bar-labels {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 4px 6px 0;
}

.qr-bar-label {
    flex: 1 1 0;
    max-width: 44px;
    text-align: center;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.6rem;
    color: var(--pr-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qr-chart-note {
    text-align: center;
    color: var(--pr-muted);
    font-size: 0.74rem;
    margin-top: 4px;
}

/* Bloch spheres */
.qb-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.qb-card {
    margin: 0;
    display: grid;
    justify-items: center;
    gap: 4px;
    width: 174px;
    padding: 8px 8px 10px;
    border-radius: 10px;
    background: var(--fm-hover, rgba(148, 163, 184, 0.1));
}

.qb-tab {
    justify-self: stretch;
    text-align: center;
    padding-bottom: 4px;
    border-bottom: 2px solid #8b7cf6;
    color: #8b7cf6;
    font-size: 0.78rem;
    font-weight: 700;
}

.qb-mesh path {
    fill: none;
    stroke: #6b5fc7;
    stroke-width: 0.6;
    opacity: 0.55;
}

.qb-outline {
    fill: rgba(107, 95, 199, 0.08);
    stroke: #7c6cf3;
    stroke-width: 1;
}

.qb-axis {
    stroke-width: 1.2;
}

.qb-axis-z { stroke: #3b82f6; }
.qb-axis-x { stroke: #ef4444; }
.qb-axis-y { stroke: #22c55e; }

.qb-lab {
    font-size: 9px;
    font-weight: 600;
}

.qb-lab-z { fill: #60a5fa; }
.qb-lab-x { fill: #f87171; }
.qb-lab-y { fill: #4ade80; }
.qb-lab-far { opacity: 0.45; font-size: 7px; }

.qb-state-line {
    stroke: #f59e0b;
    stroke-width: 1.5;
}

.qb-state {
    fill: #f59e0b;
    stroke: #fde68a;
    stroke-width: 1;
}

.qb-bars {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    margin-top: 2px;
}

.qb-bar-col {
    display: grid;
    justify-items: center;
    gap: 3px;
    font-size: 0.7rem;
}

.qb-bar-ket {
    color: var(--pr-muted);
}

.qb-track {
    display: block;
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.qb-fill {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #a855f7, #6366f1);
}

.qb-bar-pct {
    color: var(--pr-ink);
    font-variant-numeric: tabular-nums;
}

.qb-mixed {
    color: var(--pr-faint);
    font-size: 0.7rem;
}

/* State vector */
.qs-psi {
    font-family: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;
    font-size: 0.82rem;
    display: grid;
    gap: 4px;
}

.qs-lhs {
    color: var(--pr-muted);
}

.qs-term {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
}

.qs-amp {
    color: var(--pr-ink);
    white-space: nowrap;
}

.qs-plus {
    color: var(--pr-muted);
}

/* Unitary grid */
.cr-matrix {
    display: grid;
    gap: 2px;
    max-width: 640px;
    overflow-x: auto;
}

.cr-cell {
    min-width: 0;
    padding: 4px 3px;
    border-radius: 4px;
    background: var(--fm-hover, rgba(148, 163, 184, 0.1));
    color: var(--pr-ink);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.68rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cr-cell.is-zero {
    color: var(--pr-faint);
}

.cr-matrix--heat .cr-cell {
    aspect-ratio: 1;
    padding: 0;
    background: color-mix(in srgb, #6b5fc7 calc(var(--m, 0) * 100%), var(--fm-hover, rgba(148, 163, 184, 0.1)));
}
