/* Scoped styles for Affinity Explainer Animation */
:root {
    --afx-bg: #ffffff;
    --afx-text: #1e293b;
    --afx-sub: #64748b;
    --afx-fss: #3b82f6;
    --afx-explainer: #f59e0b;
    --afx-l1: #3b82f6;
    --afx-l2: #8b5cf6;
    --afx-l3: #10b981;
    --afx-hot: #ef4444;
    --afx-warm: #fca5a5;
    --afx-cold: #2563eb;
    --afx-semi-cold: #71a8e6;
    --afx-cool: #dbeafe;
    --afx-weight: #facc15;
}

/* --- OUTER CONTAINER --- */
/* This respects the parent width/padding naturally */
#affex-anim-container {
    width: 100%;
    position: relative;
    overflow: hidden;
    margin: 20px 0;
    /* Height is dynamic via JS */
}

/* --- INNER SCALER --- */
/* This div holds the fixed-size content and gets scaled */
.afx-scaler {
    width: 1100px;
    /* The fixed design width */
    height: 650px;
    /* The fixed design height */
    transform-origin: top left;
    /* Scale from top-left corner */
    position: absolute;
    top: 0;
    left: 0;
}

/* --- STAGE CONTENT --- */
/* The actual design, fixed at 1100px */
.afx-stage {
    width: 100%;
    height: 100%;
    background: var(--afx-bg);
    border-radius: 24px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 60px;
    box-sizing: border-box;
}

/* --- STANDARD COMPONENTS (Same as before) --- */
.afx-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 20;
    width: 150px;
    padding: 20px 0;
}

.afx-label {
    font-weight: 800;
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: var(--afx-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.afx-image-box {
    width: 100px;
    height: 100px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 3rem;
    overflow: hidden;
    z-index: 25;
    transition: all 0.5s;
}

.afx-roi-overlay {
    position: absolute;
    width: 60%;
    height: 60%;
    border: 3px dashed var(--afx-explainer);
    background: rgba(245, 158, 11, 0.1);
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
}

.afx-heatmap-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1s;
    mix-blend-mode: multiply;
}

.afx-heat-strong {
    background: radial-gradient(circle at 50% 50%, rgba(255, 0, 0, 0.8), transparent 70%);
}

.afx-heat-weak {
    background: radial-gradient(circle at 50% 50%, rgba(0, 0, 255, 0.6), transparent 70%);
}

.afx-mini-stack {
    margin-top: 15px;
    position: relative;
    height: 40px;
    width: 40px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s;
}

.afx-mini-layer {
    width: 30px;
    height: 30px;
    position: absolute;
    border: 1px solid #fff;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.afx-mini-layer:nth-child(1) {
    background: var(--afx-l3);
    top: 0;
    left: 0;
    z-index: 1;
}

.afx-mini-layer:nth-child(2) {
    background: var(--afx-l2);
    top: 5px;
    left: 5px;
    z-index: 2;
}

.afx-mini-layer:nth-child(3) {
    background: var(--afx-l1);
    top: 10px;
    left: 10px;
    z-index: 3;
}

.afx-process-zone {
    flex-grow: 1;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.afx-phase-container {
    position: absolute;
    top: 30px;
    left: 0;
    /* FIX: Forces alignment to the true left edge, ignoring padding */
    width: 100%;
    display: flex;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
    /* Optional: prevents blocking clicks if overlapping */
}

.afx-phase-pill {
    padding: 8px 24px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: transparent;
    color: transparent;
    border: 2px solid transparent;
    transition: all 0.5s ease;
    opacity: 0;
}

.afx-phase-fss .afx-phase-pill {
    background: #eff6ff;
    color: var(--afx-fss);
    border-color: var(--afx-fss);
    opacity: 1;
}

.afx-phase-affex .afx-phase-pill {
    background: #fffbeb;
    color: var(--afx-explainer);
    border-color: var(--afx-explainer);
    opacity: 1;
}

.afx-connector-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.afx-line {
    position: absolute;
    background: #cbd5e1;
    transition: all 0.6s ease;
}

.afx-line-main {
    height: 4px;
    top: 50%;
    left: -20px;
    width: 0;
}

.afx-line-vertical {
    width: 4px;
    left: 80px;
    top: 50.5%;
    height: 0;
    transform: translateY(-50%);
}

.afx-line-feed-top {
    height: 4px;
    width: 0;
    left: 80px;
    top: 28%;
}

.afx-line-feed-bot {
    height: 4px;
    width: 0;
    left: 80px;
    top: 72%;
}

.afx-line-right-top {
    height: 4px;
    width: 0;
    right: -20px;
    top: 28%;
    transform-origin: right;
}

.afx-line-right-bot {
    height: 4px;
    width: 0;
    right: -20px;
    top: 72%;
    transform-origin: right;
}

.afx-stack-wrapper {
    position: relative;
    height: 160px;
    width: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 30px 0;
}

.afx-stack-label {
    position: absolute;
    left: -120px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: #999;
    width: 90px;
    text-align: right;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.5s;
}

.afx-score-card {
    width: 100px;
    height: 100px;
    position: absolute;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.afx-tensor-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    border: 2px solid #ccc;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    z-index: 10;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.6s ease;
}

.afx-tensor-depth-1 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fafafa;
    border: 1px solid #ddd;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    z-index: 5;
    transition: all 0.6s ease;
    opacity: 0;
}

.afx-tensor-depth-2 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    border: 1px solid #ddd;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    z-index: 1;
    transition: all 0.6s ease;
    opacity: 0;
}

.afx-tensor-face div,
.afx-tensor-depth-1 div,
.afx-tensor-depth-2 div {
    border: 0.5px solid #eee;
    background: #f8fafc;
    transition: background 0.5s;
}

.afx-layer-1 {
    z-index: 30;
}

.afx-layer-1 .afx-tensor-face {
    border: 2px solid var(--afx-l1);
}

.afx-layer-1 .afx-tensor-depth-1,
.afx-layer-1 .afx-tensor-depth-2 {
    border: 2px solid var(--afx-l1);
}

.afx-layer-2 {
    z-index: 20;
}

.afx-layer-2 .afx-tensor-face {
    border: 2px solid var(--afx-l2);
}

.afx-layer-2 .afx-tensor-depth-1,
.afx-layer-2 .afx-tensor-depth-2 {
    border: 2px solid var(--afx-l2);
}

.afx-layer-3 {
    z-index: 10;
}

.afx-layer-3 .afx-tensor-face {
    border: 2px solid var(--afx-l3);
}

.afx-layer-3 .afx-tensor-depth-1,
.afx-layer-3 .afx-tensor-depth-2 {
    border: 2px solid var(--afx-l3);
}

.afx-w-tag {
    position: absolute;
    right: -45px;
    top: 0px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 900;
    color: black !important;
    background-color: var(--afx-weight);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 100;
}

.afx-wt-low {
    background-color: #e2e8f0;
    color: #94a3b8 !important;
}

.afx-controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

.afx-btn {
    padding: 10px 20px;
    background: var(--afx-text);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
}

.afx-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.afx-btn.reset {
    background: #cbd5e1;
    color: #333;
}

.afx-caption {
    color: var(--afx-sub);
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.1rem;
    height: 30px;
    font-weight: 500;
    display: block;
}

/* STATES */
.afx-state-features .afx-mini-stack {
    opacity: 1;
    transform: translateY(0);
}

.afx-state-matching .afx-line-main {
    width: 100px;
}

.afx-state-matching .afx-line-vertical {
    height: 268px;
}

.afx-state-matching .afx-line-feed-top {
    width: 60px;
}

.afx-state-matching .afx-line-feed-bot {
    width: 60px;
}

.afx-state-matching .afx-line-right-top {
    width: 120px;
}

.afx-state-matching .afx-line-right-bot {
    width: 120px;
}

.afx-state-matching .afx-stack-label {
    opacity: 1;
}

.afx-state-matching .afx-score-card {
    opacity: 1;
    transform: scale(1);
}

.afx-state-matching .afx-layer-1 {
    transform: translateX(-40px) translateY(-40px);
}

.afx-state-matching .afx-layer-2 {
    transform: translateX(0px) translateY(0px);
}

.afx-state-matching .afx-layer-3 {
    transform: translateX(40px) translateY(40px);
}

.afx-state-matching .afx-tensor-depth-1 {
    opacity: 1;
    transform: translate(12px, 12px);
}

.afx-state-matching .afx-tensor-depth-2 {
    opacity: 1;
    transform: translate(24px, 24px);
}

.afx-state-average .afx-roi-overlay {
    opacity: 1;
}

.afx-state-average .afx-tensor-depth-1 {
    transform: translate(0, 0);
    opacity: 0;
}

.afx-state-average .afx-tensor-depth-2 {
    transform: translate(0, 0);
    opacity: 0;
}

.afx-state-average .afx-tensor-face {
    border-width: 3px;
}

.afx-state-softmax .afx-tensor-face div {
    background: var(--afx-cool);
}

.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(8),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(12),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(13),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(14),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(18) {
    background: var(--afx-hot);
}

.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(7),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(9),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(17),
.afx-state-softmax #afx-stack-car .afx-tensor-face div:nth-child(19) {
    background: var(--afx-warm);
}

.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(8),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(12),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(13),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(14),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(18) {
    background: var(--afx-cold);
}

.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(7),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(9),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(17),
.afx-state-softmax #afx-stack-plant .afx-tensor-face div:nth-child(19) {
    background: var(--afx-semi-cold);
}

.afx-state-weights .afx-w-tag {
    opacity: 1;
    transform: translateX(5px);
}

.afx-state-weights #afx-stack-car .afx-score-card {
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.6);
}

.afx-state-aggregate .afx-layer-2,
.afx-state-aggregate .afx-layer-3 {
    opacity: 0;
}

.afx-state-aggregate .afx-layer-1 {
    transform: translateX(0) translateY(0) scale(1.2) !important;
    z-index: 100;
}

.afx-state-aggregate .afx-layer-1 .afx-tensor-face {
    border-color: var(--afx-text);
    background: #fff;
}

.afx-state-aggregate .afx-w-tag {
    opacity: 0;
}

.afx-state-aggregate .afx-line {
    opacity: 0;
}

.afx-state-result .afx-roi-overlay {
    opacity: 0;
}

.afx-state-result #afx-stack-car {
    transform: translateX(280px) scale(0.3);
    opacity: 0;
    transition: all 0.8s ease-in;
}

.afx-state-result #afx-stack-plant {
    transform: translateX(280px) scale(0.3);
    opacity: 0;
    transition: all 0.8s ease-in;
}

.afx-state-result .afx-heat-strong {
    opacity: 1;
}

.afx-state-result .afx-heat-weak {
    opacity: 0.8;
}