/* ============================================================
   /aitemp hero: a prompt typed into QubiAI and the circuit it builds,
   drawn by the site's own drawer (js/circuit-draw.js) from real Qubi
   programs compiled by the simulator's engine (aitemp/hero.js).

   The card has a fixed size, so circuits of every width and height swap
   inside it without moving anything around it. The first circuit is in
   the HTML, so the first frame is already the finished card.
   ============================================================ */

.qh-hero {
    position: relative;
    min-width: 0;
}

.qh-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.qh {
    margin: 0;
    border: 1px solid var(--pp-rule);
    border-radius: 6px;
    background: var(--pp-paper-2);
    overflow: hidden;
}

/* ── Top line: name and what was built ───────────────────────────────── */

.qh-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 42px;
    padding: 0 16px;
    border-bottom: 1px solid var(--pp-rule);
    font-family: var(--pp-mono);
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    color: var(--pp-muted);
    white-space: nowrap;
}

.qh-name {
    color: var(--pp-ink-2);
}

.qh-status {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.25s ease;
}

.qh-status.is-out {
    opacity: 0;
}

/* ── The circuit ─────────────────────────────────────────────────────── */

.qh-stage {
    position: relative;
    height: 268px;
    padding: 14px 16px;
    box-sizing: border-box;
    overflow: hidden;
}

.qh-circ {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.qh-circ .cq {
    flex: 0 0 auto;
    transition: opacity 0.28s ease;
}

.qh-circ .cq.is-out {
    opacity: 0;
}

/* Column by column, left to right: a plain fade, no movement. */
.qh-circ .cq.is-revealing > * {
    transition: opacity 0.32s ease;
}

.qh-circ .cq > .is-pre {
    opacity: 0 !important;
}

/* ── The prompt line ─────────────────────────────────────────────────── */

.qh-input {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 46px;
    margin: 0 14px 14px;
    padding: 0 7px 0 14px;
    box-sizing: border-box;
    border: 1px solid var(--pp-rule-strong);
    border-radius: 6px;
    background: var(--pp-paper);
}

.qh-line {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-family: var(--pp-sans);
    font-size: 0.95rem;
    color: var(--pp-ink);
    white-space: nowrap;
}

.qh-text {
    overflow: hidden;
    text-overflow: clip;
    transition: color 0.25s ease;
}

.qh-text.is-sent {
    color: var(--pp-ink-2);
}

.qh-caret {
    flex: 0 0 auto;
    width: 1.5px;
    height: 1.15em;
    margin-left: 1px;
    background: var(--pp-accent);
}

.qh.is-blinking .qh-caret {
    animation: qh-blink 1.06s steps(1) infinite;
}

.qh.is-idle .qh-caret {
    opacity: 0;
}

@keyframes qh-blink {
    50% { opacity: 0; }
}

.qh-send {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    border: 1px solid var(--pp-rule-strong);
    color: var(--pp-muted);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.qh-send svg {
    display: block;
    width: 14px;
    height: 14px;
}

.qh-send.is-ready,
.qh-send.is-pressed {
    border-color: var(--pp-accent);
    color: var(--pp-accent);
}

.qh-send.is-pressed {
    background: var(--pp-accent);
    color: var(--pp-accent-ink);
}

/* ── The drawing's own rules ─────────────────────────────────────────────
   Copied from css/account.css and css/circuit-results.css (as
   css/assistant.css copies them, values unchanged) and scoped to the hero,
   since those sheets are far too large to load here. Labels take the
   page's ink so the drawing reads in light and dark. */

.qh .cq {
    position: relative;
    font-family: var(--pp-sans);
}

.qh .cq * {
    box-sizing: border-box;
}

.qh .cq-qlabel {
    position: absolute;
    left: 0;
    width: 30px;
    text-align: center;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--pp-muted);
    line-height: 18px;
}

.qh .cq-wire {
    position: absolute;
    height: 2px;
    background: #6b5fc7;
    opacity: 0.6;
    transform: translateY(-1px);
}

.qh .cq-bus {
    position: absolute;
    width: 4px;
    background: var(--cq-color);
}

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

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

.qh .cq-tile-sub {
    font-size: 6.7px;
    font-weight: 600;
    line-height: 1;
    opacity: 0.95;
    margin-top: 1px;
    white-space: nowrap;
}

.qh .cq-tile:has(.cq-tile-sub) .cq-tile-label {
    font-size: 11.8px;
}

.qh .cq-param {
    position: absolute;
    transform: translateX(-50%);
    font-size: 9px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
    /* On the card's colour, above the buses, as the builder sets it on
       its canvas: a line through the column passes behind the angle. */
    background: var(--pp-paper-2);
    color: var(--pp-muted);
    white-space: nowrap;
    pointer-events: none;
    z-index: 3;
}

.qh .cq-disc {
    position: absolute;
    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-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    z-index: 2;
}

.qh .cq-disc-label {
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
}

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

.qh .cq-measure-block {
    position: absolute;
    border-radius: 8px;
    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);
    z-index: 0;
}

.qh .cq-tile--measure {
    background: #10b981;
    border-color: #34d399;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

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

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

.qh .cq-more {
    position: absolute;
    color: var(--pp-muted);
    font-size: 17.6px;
    line-height: 20px;
}

.qh .cq-x { --cq-color: #ef4444; --cq-edge: #dc2626; }
.qh .cq-y { --cq-color: #22c55e; --cq-edge: #16a34a; }
.qh .cq-z { --cq-color: #3b82f6; --cq-edge: #2563eb; }
.qh .cq-h { --cq-color: #a855f7; --cq-edge: #9333ea; }
.qh .cq-phase { --cq-color: #06b6d4; --cq-edge: #0891b2; }
.qh .cq-swap { --cq-color: #f97316; --cq-edge: #ea580c; }
.qh .cq-measure { --cq-color: #10b981; --cq-edge: #059669; }
.qh .cq-default { --cq-color: #6b5fc7; --cq-edge: #554a9e; }

/* Loops, function bars and annotations (Grover, QFT). */

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

.qh .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);
}

.qh .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);
}

.qh .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);
}

.qh .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);
}

.qh .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);
}

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

.qh .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;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.qh .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;
}

.qh .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;
}

.qh .cq-fn {
    position: absolute;
    display: flex;
    align-items: center;
    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;
}

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

.qh .cq-ann {
    position: absolute;
    padding: 1px 5px;
    border-radius: 3px;
    background: color-mix(in srgb, #6b5fc7 18%, var(--pp-paper-2));
    border: 1px solid color-mix(in srgb, #6b5fc7 42%, var(--pp-paper-2));
    color: var(--pp-ink-2);
    font-size: 8px;
    line-height: 13px;
    overflow: hidden;
    white-space: nowrap;
    z-index: 4;
}

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

.qh .cq-qlabel--custom {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Narrow ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    .qh-stage {
        height: 252px;
        padding: 12px 10px;
    }
    .qh-input {
        margin: 0 10px 10px;
    }
    .qh-bar {
        padding: 0 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .qh *,
    .qh .cq,
    .qh .cq > * {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Circuits drawn like the home page's (js/viz-circuit.js) ────────────── */

.qh-stage {
    padding: 10px 12px;
}

.qh-circ .viz-circuit {
    display: block;
    width: 100%;
    height: 100%;
    transition: opacity 0.26s ease;
}

.qh-circ .viz-circuit.is-out {
    opacity: 0;
}

/* Column by column, left to right: a plain fade, no movement. */
.qh-circ .viz-circuit.is-revealing .viz-gate {
    transition: opacity 0.32s ease;
}

.qh-circ .viz-gate.is-pre {
    opacity: 0;
}

html[data-theme="light"] .qh .viz-wire { stroke: rgba(76, 64, 160, 0.5); }
html[data-theme="light"] .qh .viz-label { fill: #334155; }
html[data-theme="light"] .qh .viz-ctrl { stroke: #f4f5fc; }
html[data-theme="light"] .qh .viz-meas { stroke: #fff; }
html[data-theme="light"] .qh .viz-if { stroke: #f4f5fc; }
html[data-theme="light"] .qh .viz-param { fill: #475569; }
