.vit-workbench {
    --vit-token: #2563eb;
    --vit-attention: #f59e0b;
    --vit-cls: #7c3aed;
    --vit-green: #10b981;
}

.vit-stage-layout {
    display: grid;
    grid-template-columns: minmax(280px, 0.82fr) minmax(0, 1.18fr);
    gap: 12px;
    align-items: start;
}

.vit-visual-stack,
.vit-side-stack {
    display: contents;
}

.vit-image-panel {
    grid-column: 1;
    grid-row: 1 / span 2;
}

.vit-visual-stack > .frontier-stage-card:not(.vit-image-panel) {
    grid-column: 1;
    grid-row: 3;
}

.vit-architecture-panel {
    grid-column: 2;
    grid-row: 1;
}

.vit-token-panel {
    grid-column: 2;
    grid-row: 2;
}

.vit-attention-panel {
    grid-column: 1;
    grid-row: 4;
}

.vit-encoder-panel {
    grid-column: 2;
    grid-row: 3;
}

.vit-output-panel {
    grid-column: 2;
    grid-row: 4;
}

.vit-stage-layout > *,
.vit-visual-stack > *,
.vit-side-stack > * {
    min-width: 0;
}

.vit-image-panel .frontier-sample-frame {
    width: min(100%, 430px);
    justify-self: center;
}

.vit-patch-grid,
.vit-attention-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(var(--patch-cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--patch-cols), minmax(0, 1fr));
    pointer-events: none;
}

.vit-patch-grid {
    opacity: 0;
    transition: opacity 0.28s var(--frontier-algo-motion);
}

.vit-stage-layout[data-step="patch"] .vit-patch-grid,
.vit-stage-layout[data-step="token"] .vit-patch-grid,
.vit-stage-layout[data-step="position"] .vit-patch-grid,
.vit-stage-layout[data-step="attention"] .vit-patch-grid,
.vit-stage-layout[data-display="patch"] .vit-patch-grid,
.vit-stage-layout[data-display="attention"] .vit-patch-grid {
    opacity: 1;
}

.vit-patch-cell {
    position: relative;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.62);
    padding: 0;
    background: rgba(37, 99, 235, 0.03);
    font: inherit;
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.2s var(--frontier-algo-motion), background 0.2s var(--frontier-algo-motion), border-color 0.2s var(--frontier-algo-motion);
}

.vit-stage-layout[data-step="patch"] .vit-patch-cell,
.vit-stage-layout[data-display="patch"] .vit-patch-cell {
    animation: vitPatchDecompose 0.56s var(--frontier-algo-motion) both;
    animation-delay: var(--patch-delay, 0ms);
}

.vit-patch-cell:hover,
.vit-patch-cell.is-selected {
    z-index: 8;
    border-color: rgba(245, 158, 11, 0.96);
    background: rgba(245, 158, 11, 0.18);
    transform: scale(1.04);
}

.vit-patch-cell.is-hot {
    background: rgba(37, 99, 235, calc(0.04 + var(--attention, 0) * 0.48));
    border-color: rgba(37, 99, 235, calc(0.2 + var(--attention, 0) * 0.7));
}

.vit-attention-overlay {
    mix-blend-mode: multiply;
    pointer-events: none;
}

.vit-attention-overlay span {
    display: block;
    background:
        radial-gradient(circle, rgba(245, 158, 11, calc(var(--attention, 0) * 0.68)) 0 42%, rgba(37, 99, 235, calc(var(--attention, 0) * 0.22)) 43% 100%);
    opacity: 0;
}

.vit-stage-layout[data-step="attention"] .vit-attention-overlay span,
.vit-stage-layout[data-display="attention"] .vit-attention-overlay span {
    opacity: 1;
    animation: vitAttentionPulse 1s var(--frontier-algo-motion) infinite;
    animation-delay: var(--patch-delay, 0ms);
}

.vit-shape-readout {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 10px;
}

.vit-shape-readout div {
    display: grid;
    gap: 4px;
    min-width: 0;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px;
    background: #ffffff;
}

.vit-shape-readout span {
    color: #64748b;
    font-size: 10px;
    font-weight: 900;
}

.vit-shape-readout strong {
    color: #172554;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.vit-token-sequence {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-content: start;
    max-height: 156px;
    overflow: auto;
    padding: 10px;
    background:
        linear-gradient(90deg, rgba(219, 234, 254, 0.48) 1px, transparent 1px),
        linear-gradient(180deg, rgba(219, 234, 254, 0.48) 1px, transparent 1px),
        #f8fafc;
    background-size: 18px 18px;
}

.vit-token {
    position: relative;
    display: grid;
    min-width: 38px;
    height: 28px;
    place-items: center;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1e40af;
    background: #ffffff;
    font-size: 9px;
    font-weight: 950;
    cursor: pointer;
    transition: border-color 0.2s var(--frontier-algo-motion), background 0.2s var(--frontier-algo-motion), transform 0.2s var(--frontier-algo-motion);
}

.vit-token.is-cls {
    min-width: 48px;
    border-color: #c4b5fd;
    color: #5b21b6;
    background: #f5f3ff;
}

.vit-token.is-selected,
.vit-token:hover {
    border-color: var(--vit-attention);
    color: #92400e;
    background: #fffbeb;
    transform: translateY(-1px);
}

.vit-stage-layout[data-step="token"] .vit-token,
.vit-stage-layout[data-display="token"] .vit-token {
    animation: vitTokenExtend 0.44s var(--frontier-algo-motion) both;
    animation-delay: var(--token-delay, 0ms);
}

.vit-position-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    border-top: 1px solid #e8eef6;
    padding: 9px 10px 10px;
}

.vit-position-tags span {
    display: inline-flex;
    min-height: 23px;
    align-items: center;
    border: 1px solid #bae6fd;
    border-radius: 999px;
    padding: 0 8px;
    color: #0e7490;
    background: #ecfeff;
    font-size: 9px;
    font-weight: 900;
}

.vit-stage-layout[data-step="position"] .vit-position-tags span {
    animation: vitPositionMerge 0.54s var(--frontier-algo-motion) both;
    animation-delay: var(--token-delay, 0ms);
}

.vit-attention-layout {
    display: grid;
    grid-template-columns: minmax(150px, 0.8fr) minmax(190px, 1fr);
    gap: 10px;
    padding: 10px;
}

.vit-attention-matrix {
    display: grid;
    grid-template-columns: repeat(var(--matrix-cols), minmax(0, 1fr));
    gap: 2px;
    align-content: start;
    overflow: hidden;
    border: 1px solid #dbeafe;
    border-radius: 12px;
    padding: 7px;
    background: #f8fafc;
}

.vit-matrix-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    background:
        linear-gradient(135deg, rgba(245, 158, 11, var(--attention, 0.08)), rgba(37, 99, 235, calc(var(--attention, 0.08) * 0.72)));
    min-width: 3px;
}

.vit-stage-layout[data-step="attention"] .vit-matrix-cell,
.vit-stage-layout[data-display="attention"] .vit-matrix-cell {
    animation: vitAttentionPulse 1.05s var(--frontier-algo-motion) infinite;
    animation-delay: var(--matrix-delay, 0ms);
}

.vit-attention-detail {
    display: grid;
    align-content: start;
    gap: 8px;
}

.vit-attention-detail code,
.vit-encoder-card code,
.vit-output-vector code {
    overflow-wrap: anywhere;
    color: #1e3a8a;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    line-height: 1.45;
}

.vit-attention-detail p {
    margin: 0;
    color: #64748b;
    font-size: 11px;
    line-height: 1.45;
}

.vit-encoder-chain {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
    padding: 10px;
}

.vit-encoder-card {
    display: grid;
    gap: 5px;
    min-height: 86px;
    border: 1px solid #dbeafe;
    border-radius: 11px;
    padding: 8px;
    background: #ffffff;
    transition: transform 0.24s var(--frontier-algo-motion), border-color 0.24s var(--frontier-algo-motion), background 0.24s var(--frontier-algo-motion);
}

.vit-encoder-card span {
    color: #0891b2;
    font-size: 9px;
    font-weight: 950;
    text-transform: uppercase;
}

.vit-encoder-card strong {
    color: #172554;
    font-size: 11px;
    line-height: 1.25;
}

.vit-stage-layout[data-step="encoder"] .vit-encoder-card {
    animation: vitTokenExtend 0.48s var(--frontier-algo-motion) both;
    animation-delay: var(--encoder-delay, 0ms);
}

.vit-encoder-card.is-active {
    border-color: #7c3aed;
    background: #f5f3ff;
    transform: translateY(-2px);
}

.vit-output-grid {
    display: grid;
    grid-template-columns: minmax(160px, 0.7fr) minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
}

.vit-output-vector {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 10px;
    min-height: 168px;
}

.vit-cls-node {
    display: grid;
    width: 92px;
    height: 92px;
    place-items: center;
    border: 2px solid #c4b5fd;
    border-radius: 999px;
    color: #5b21b6;
    background:
        radial-gradient(circle at 50% 50%, #ffffff 0 32%, rgba(124, 58, 237, 0.16) 33% 100%);
    font-size: 18px;
    font-weight: 950;
    box-shadow: 0 16px 30px rgba(124, 58, 237, 0.13);
}

.vit-stage-layout[data-step="cls"] .vit-cls-node,
.vit-stage-layout[data-display="cls"] .vit-cls-node {
    animation: vitClsMerge 1.1s var(--frontier-algo-motion) infinite;
}

.vit-predictions {
    display: grid;
    gap: 8px;
}

.vit-predictions article {
    display: grid;
    grid-template-columns: minmax(86px, 0.62fr) minmax(0, 1fr) 42px;
    align-items: center;
    gap: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 7px 9px;
    background: #ffffff;
}

.vit-predictions span {
    min-width: 0;
    overflow: hidden;
    color: #334155;
    font-size: 11px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vit-predictions i {
    display: block;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #dbeafe;
}

.vit-predictions b {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #7c3aed, #10b981);
}

.vit-predictions strong {
    color: #1e40af;
    font-size: 10px;
    font-weight: 950;
    text-align: right;
}

@keyframes vitPatchDecompose {
    from {
        opacity: 0.1;
        transform: translate(0, 0) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(var(--patch-shift-x, 0), var(--patch-shift-y, 0)) scale(0.96);
    }
}

@keyframes vitTokenExtend {
    from {
        opacity: 0;
        transform: translateX(-10px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes vitPositionMerge {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes vitAttentionPulse {
    0%, 100% {
        filter: saturate(1);
        opacity: 0.86;
    }
    50% {
        filter: saturate(1.38);
        opacity: 1;
    }
}

@keyframes vitClsMerge {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 16px 30px rgba(124, 58, 237, 0.13);
    }
    50% {
        transform: scale(1.06);
        box-shadow: 0 20px 38px rgba(124, 58, 237, 0.22);
    }
}

@media (max-width: 1080px) {
    .vit-stage-layout,
    .vit-output-grid,
    .vit-attention-layout {
        grid-template-columns: 1fr;
    }

    .vit-image-panel,
    .vit-visual-stack > .frontier-stage-card:not(.vit-image-panel),
    .vit-architecture-panel,
    .vit-token-panel,
    .vit-attention-panel,
    .vit-encoder-panel,
    .vit-output-panel {
        grid-column: auto;
        grid-row: auto;
    }

    .vit-visual-stack,
    .vit-side-stack {
        display: grid;
        gap: 12px;
    }

    .vit-encoder-chain {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .vit-shape-readout,
    .vit-encoder-chain,
    .vit-predictions article {
        grid-template-columns: 1fr;
    }

    .vit-predictions strong {
        text-align: left;
    }
}
