/* ============================================================
   QubiAI panel (home page, Technology section).

   Takes the place of the old Tools / Hardware / Learning list. One example
   request at a time: what was asked, the Qubi that came back, the circuit it
   draws (js/circuit-draw.js, from diagrams the simulator's own engine laid
   out) and what the engine says it does. Below it, QubiBench v3 and the way
   in. Uses the Technology section's tokens (--tk-*) from css/tech.css.
   ============================================================ */

/* ── Layout: a wider right column than the old list had ─────────────────── */

/* The QubiAI panel is the narrower column, so the cards' one-line captions fit beside it. */
.tk-layout.tk-layout--ai {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
}

@media (min-width: 1280px) and (max-width: 1399.98px) {
    .tk-layout--ai .tk-card-inner {
        grid-template-columns: 210px minmax(0, 1fr);
    }

    .tk-layout--ai .tk-card--art-right .tk-card-inner {
        grid-template-columns: minmax(0, 1fr) 210px;
    }
}

@media (min-width: 1400px) {
    .tk-layout--ai .tk-card-inner {
        grid-template-columns: 250px minmax(0, 1fr);
    }

    .tk-layout--ai .tk-card--art-right .tk-card-inner {
        grid-template-columns: minmax(0, 1fr) 250px;
    }
}

@media (max-width: 1279.98px) {
    .tk-layout.tk-layout--ai {
        grid-template-columns: minmax(0, 1fr);
    }

    .tk-layout--ai .tk-cards {
        grid-template-rows: auto;
    }

    .tk-layout--ai .tk-cards > .tk-card,
    .tk-layout--ai .tk-cards > .tk-stack,
    .tk-layout--ai .tk-stack > .tk-card,
    .tk-layout--ai .tk-card-inner {
        height: auto;
    }
}

/* ── The panel: same chamfered edge as the cards ─────────────────────────── */

#Tech .tk-ai {
    --ai-win: #0b0d1f;
    --ai-win-edge: rgba(139, 124, 246, 0.42);
    --ai-win-rule: rgba(139, 124, 246, 0.22);
    --ai-code-bg: rgba(255, 255, 255, 0.025);
    --ai-stage: #0a0a1a;
    --ai-ink: #e2e8f0;
    --ai-dim: rgba(199, 210, 254, 0.62);
    --ai-faint: rgba(199, 210, 254, 0.4);
    --ai-on: rgba(167, 139, 250, 0.16);
    --ai-ok: #34d399;
    --ai-accent: #8b7cf6;
    --ai-accent-2: rgba(167, 175, 214, 0.45);
    --ai-tab-on: rgba(167, 139, 250, 0.22);
    --ai-tab-on-text: #f1f4ff;
    /* Code, coloured like the builder's tiles for the same gates. */
    --ai-c-h: #c084fc;
    --ai-c-x: #f87171;
    --ai-c-y: #4ade80;
    --ai-c-z: #60a5fa;
    --ai-c-m: #34d399;
    --ai-c-num: #fcd34d;
    --ai-c-kw: #7dd3fc;
    --ai-c-punct: rgba(199, 210, 254, 0.55);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

html[data-theme="light"] #Tech .tk-ai {
    --ai-win: #ffffff;
    --ai-win-edge: rgba(76, 64, 160, 0.28);
    --ai-win-rule: rgba(76, 64, 160, 0.14);
    --ai-code-bg: #f7f8fd;
    --ai-stage: #ffffff;
    --ai-ink: #1e293b;
    --ai-dim: #5b6285;
    --ai-faint: #8a90ad;
    --ai-on: rgba(109, 92, 232, 0.1);
    --ai-ok: #059669;
    --ai-accent: #6d5ce8;
    --ai-accent-2: rgba(40, 50, 120, 0.28);
    --ai-tab-on: #1e2748;
    --ai-tab-on-text: #ffffff;
    --ai-c-h: #9333ea;
    --ai-c-x: #dc2626;
    --ai-c-y: #15803d;
    --ai-c-z: #2563eb;
    --ai-c-m: #047857;
    --ai-c-num: #b45309;
    --ai-c-kw: #0369a1;
    --ai-c-punct: #64748b;
}

.tk-ai-panel {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    padding: 1px;
    background: var(--tk-edge);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 26px), calc(100% - 26px) 100%, 0 100%);
}

.tk-ai-inner {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px 22px;
    background: linear-gradient(170deg, var(--tk-card) 0%, var(--tk-card-2) 100%);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 26px), calc(100% - 26px) 100%, 0 100%);
}

/* ── Heading ─────────────────────────────────────────────────────────────── */

.tk-ai-title {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 2.2vw, 2.4rem);
    font-weight: 700;
    line-height: 1.02;
    letter-spacing: 0.01em;
    color: var(--tk-text);
    margin: 0 0 4px;
}

.tk-ai-sub {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1.3;
    color: var(--tk-muted);
    margin: 0;
}

/* ── The example window ──────────────────────────────────────────────────── */

.tk-ai-win {
    container-type: inline-size;
    border: 1px solid var(--ai-win-edge);
    border-radius: 10px;
    background: var(--ai-win);
    color: var(--ai-ink);
    overflow: hidden;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.32);
}

html[data-theme="light"] .tk-ai-win {
    box-shadow: 0 10px 22px rgba(40, 50, 100, 0.1);
}

.tk-ai-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 6px 0 12px;
    border-bottom: 1px solid var(--ai-win-rule);
}

.tk-ai-dots {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.tk-ai-dots i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f87171;
}

.tk-ai-dots i:nth-child(2) { background: #fbbf24; }
.tk-ai-dots i:nth-child(3) { background: #34d399; }

.tk-ai-bar-label {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.72rem;
    color: var(--ai-dim);
    white-space: nowrap;
}

.tk-ai-tabs {
    margin-left: auto;
    display: flex;
    gap: 2px;
}

.tk-ai-tab {
    appearance: none;
    border: 0;
    margin: 0;
    padding: 4px 10px;
    border-radius: 6px;
    background: transparent;
    color: var(--ai-dim);
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.tk-ai-tab:hover {
    color: var(--ai-ink);
    background: var(--ai-on);
}

.tk-ai-tab:focus-visible {
    outline: 2px solid var(--ai-accent);
    outline-offset: 1px;
}

.tk-ai-tab[aria-selected="true"] {
    background: var(--ai-tab-on);
    color: var(--ai-tab-on-text);
}

/* What was asked. Two lines are reserved where it can wrap, so typing the
   next request never moves anything below it. */
.tk-ai-ask {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 11px 14px 10px;
    min-height: 44px;
    border-bottom: 1px solid var(--ai-win-rule);
    font-family: var(--font-display);
    font-size: 1.12rem;
    line-height: 1.3;
    color: var(--ai-ink);
}

.tk-ai-ask-tag {
    flex-shrink: 0;
    margin-top: 1px;
    padding: 1px 7px;
    border-radius: 5px;
    border: 1px solid var(--ai-win-rule);
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ai-dim);
}

.tk-ai-ask-text.is-typing::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -0.12em;
    background: var(--ai-accent);
}

/* Qubi on the left, the circuit on the right; stacked in a narrow window. */
.tk-ai-work {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    transition: opacity 0.16s ease;
}

.tk-ai-work.is-swapping {
    opacity: 0;
}

.tk-ai-code {
    margin: 0;
    padding: 12px 0;
    min-height: 184px;
    background: var(--ai-code-bg);
    border-right: 1px solid var(--ai-win-rule);
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    line-height: 20px;
    color: var(--ai-ink);
    overflow: hidden;
    white-space: pre;
}

.tk-ai-line {
    display: block;
    padding: 0 12px;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.tk-ai-code .k-h { color: var(--ai-c-h); font-weight: 600; }
.tk-ai-code .k-x { color: var(--ai-c-x); font-weight: 600; }
.tk-ai-code .k-y { color: var(--ai-c-y); font-weight: 600; }
.tk-ai-code .k-z { color: var(--ai-c-z); font-weight: 600; }
.tk-ai-code .k-m { color: var(--ai-c-m); font-weight: 600; }
.tk-ai-code .k-num { color: var(--ai-c-num); }
.tk-ai-code .k-kw { color: var(--ai-c-kw); }
.tk-ai-code .k-p { color: var(--ai-c-punct); }

.tk-ai-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 184px;
    padding: 10px 8px;
    background: var(--ai-stage);
    overflow: hidden;
}

/* The drawing's own styles are css/account.css and css/circuit-results.css;
   only what sits on the window's colour changes here. */
.tk-ai-stage .cq {
    flex: 0 0 auto;
}

.tk-ai-stage .cq .cq-param {
    background: var(--ai-stage);
    color: var(--ai-faint);
}

html[data-theme="light"] .tk-ai-stage .cq-qlabel {
    color: #64748b;
}

html[data-theme="light"] .tk-ai-stage .cq .cq-tile,
html[data-theme="light"] .tk-ai-stage .cq .cq-disc {
    box-shadow: 0 1px 4px rgba(30, 41, 80, 0.18);
}

/* The engine stepping through the program: one column at a time, with the
   lines that put gates in it. */
.tk-ai-stage .cq > * {
    transition: opacity 0.2s ease;
}

.tk-ai-work.is-walking .cq > [data-col]:not(.is-on) {
    opacity: 0.28;
}

.tk-ai-work.is-walking .tk-ai-line:not(.is-on) {
    opacity: 0.45;
}

.tk-ai-line.is-on {
    background: var(--ai-on);
}

.tk-ai-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 36px;
    padding: 7px 14px;
    border-top: 1px solid var(--ai-win-rule);
    font-family: var(--font-display);
    font-size: 1rem;
    line-height: 1.2;
}

.tk-ai-ok {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--ai-ok);
    font-weight: 600;
    white-space: nowrap;
}

/* A check mark, drawn: two borders of a rotated box. */
.tk-ai-ok::before {
    content: '';
    width: 5px;
    height: 10px;
    margin: -3px 2px 0 3px;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.tk-ai-result {
    min-width: 0;
    color: var(--ai-dim);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tk-ai-result b {
    color: var(--ai-ink);
    font-weight: 600;
}

@container (max-width: 459.98px) {
    .tk-ai-work {
        grid-template-columns: minmax(0, 1fr);
    }

    .tk-ai-code {
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--ai-win-rule);
    }

    .tk-ai-stage {
        min-height: 0;
    }

    .tk-ai-ask {
        min-height: 66px;
    }

    .tk-ai-bar-label {
        display: none;
    }

    .tk-ai-status {
        flex-direction: column;
        align-items: flex-start;
        gap: 3px;
    }

    .tk-ai-result {
        text-align: left;
        white-space: normal;
    }
}

/* ── QubiBench v3 ────────────────────────────────────────────────────────── */

.tk-ai-bench-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    margin-bottom: 7px;
    font-family: var(--font-display);
    line-height: 1.2;
}

.tk-ai-bench-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--tk-text);
}

.tk-ai-bench-note {
    font-size: 1rem;
    color: var(--tk-muted);
}

.tk-ai-bars {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 5px;
}

.tk-ai-row {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr) 48px;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-size: 1.04rem;
    line-height: 1.2;
}

.tk-ai-row-name {
    color: var(--tk-text);
    white-space: nowrap;
}

.tk-ai-row-name span {
    color: var(--tk-muted);
}

.tk-ai-track {
    height: 8px;
    border-radius: 4px;
    background: var(--tk-tile);
    border: 1px solid var(--tk-line);
    overflow: hidden;
}

.tk-ai-fill {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--ai-accent);
}

.tk-ai-row--old .tk-ai-fill {
    background: var(--ai-accent-2);
}

.tk-ai-val {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--tk-text);
}

.tk-ai-row--old .tk-ai-val,
.tk-ai-row--old .tk-ai-row-name {
    color: var(--tk-muted);
}

.tk-ai-note {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.04rem;
    line-height: 1.3;
    color: var(--tk-muted);
}

.tk-ai-note b {
    color: var(--tk-text);
    font-weight: 600;
}

.tk-ai .tk-actions {
    margin-top: auto;
}

/* ── Full-width row (tablets, small laptops): the example on the left,
   the numbers and the way in beside it. ────────────────────────────────── */

@media (min-width: 992px) and (max-width: 1199.98px) {
    .tk-ai-inner {
        display: grid;
        grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
        grid-template-areas:
            "head head"
            "win bench"
            "win note"
            "win actions";
        grid-template-rows: auto auto auto 1fr;
        column-gap: 24px;
        row-gap: 14px;
    }

    .tk-ai-head { grid-area: head; }
    .tk-ai-win { grid-area: win; align-self: start; }
    .tk-ai-bench { grid-area: bench; }
    .tk-ai-note { grid-area: note; }
    .tk-ai .tk-actions { grid-area: actions; align-self: end; }

    .tk-ai-row {
        grid-template-columns: 112px minmax(0, 1fr) 46px;
        gap: 8px;
    }
}

/* ── Phones ──────────────────────────────────────────────────────────────── */

@media (max-width: 767.98px) {
    .tk-ai-inner {
        padding: 16px 14px 34px;
    }

    .tk-ai-sub {
        font-size: 1.1rem;
    }

    .tk-ai-tab {
        padding: 4px 8px;
    }

    .tk-ai-row {
        grid-template-columns: 112px minmax(0, 1fr) 44px;
        gap: 8px;
        font-size: 1rem;
    }

    .tk-ai .tk-actions .tk-btn {
        flex: 1 1 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tk-ai-work,
    .tk-ai-line,
    .tk-ai-stage .cq > *,
    .tk-ai-tab {
        transition: none;
    }
}

/* Model names never split across lines ("Fermi / 1.0"). */
.tk-ai-note b {
    white-space: nowrap;
}
