Here's a thinking process that leads to the suggested HTML file:
-
Analyze the Request:
- Goal: Design a personalization testing sandbox.
- Target Users: Product Managers (PMs).
- Key Features: Preview variants, override segments (user segmentation), analyze outputs, safety (safely test changes without affecting real users).
- Constraint: Single self-contained HTML file (HTML + CSS + JS). No external dependencies (like React/Vue) but frameworks like Tailwind/GSAP allowed via CDN. Use semantic HTML. High visual impact (Awwwards style). Dark mode focused but with high contrast.
- Persona: Natural UI/UX artist. Organic shapes, earth tones, textures, smooth animations (slow media), biophilic vibes.
-
Conceptualization & Design Strategy (The "Biophilic Sandbox"):
- Metaphor: A laboratory or a terrarium where personalization variants grow like plants. The "safety" aspect implies containment (glass, clear boundaries), and the "analysis" implies observing how elements adapt.
- Visuals: Dark background (deep forest green/charcoal), but with high contrast text. Organic blobs for variants. Noise texture overlay for "paper" feel. Mouse movement subtly parallas or disturbs the background (dappled light).
- Layout: A dashboard style but non-grid. Left side: Controls (Segment Override, Variant Switcher). Center: live Preview area (the "specimen"). Right side: Analytics/Output data (visualized simply). Bottom: Logs/Events.
- Interactions:
- Changing segments or variants triggers a smooth transition (morphing the blob shape, organic content reveal).
- Data visualization: trend lines that "grow" using SVG paths.
- Buttons: Rounded, tactile, hover states with ripple/fluid effects.
- Typography: Serif for headings (Playfair Display or similar), clean Sans for UI (Inter or Lato).
-
Technical Implementation Plan:
- HTML Structure:
<div id="noise-overlay">: Constant grain texture.
<nav>: Minimalist branding.
<main>: Flex/Grid layout.
<aside id="controls">: Inputs for segment overrides (e.g., User ID, Country, Device).
<section id="preview-stage">: The container for the variant. Includes an .organic-shape div that blobs around.
<aside id="analytics">: Simple charts (SVG/CSS bars).
<section id="logs">: Activity stream.
- CSS (Tailwind + Custom):
- Use Tailwind via CDN.
- Define custom animations (
@keyframes blob-move, float).
- Earth/Dark palette:
#1a1c18 (bg), #e0e2db (text), #8c9a8a (accent), #d4a373 (gold/terracotta).
backdrop-filter for glass panels.
mix-blend-mode for noise.
- JavaScript (Logic + Interactivity):
- State:
currentVariant (A, B, C), overrides (age, newUser, etc.).
- Mock Data: Associate variants with different "personalities" (colors, content, image style).
- Canvas/WebGL? Maybe too heavy. Let's stick to advanced CSS/SMIL for organic shapes and SVG for charts to keep performance high and code concise.
- Dappled Light Effect: Canvas drawing circles that follow the mouse with low opacity, simulating light through leaves.
- Logic: Function
updatePreview(): changes DOM content and style variables (blob size, color) based on selection.
- Analytics: Randomly generate metrics that stabilize after a "warm-up" simulation (e.g., success rate appears after 1 second with animation).
-
Refining the "Biophilic" Aspect:
- Instead of standard form inputs, maybe use "cards" that look like pressed leaves or stones to toggle segments.
- The variant preview shouldn't be a rectangle. It should be a fluid, morphing container (blob).
- Content inside the blob should fade in slowly (ease-out).
-
Step-by-Step Coding (Mental Draft & Iteration):
- Setup: HTML5 boilerplate, Tailwind CDN, Google Fonts (Playfair Display, Lato).
- Background: Dark greenish-gray. Add a
<canvas id="noise"> for grain (per MDN sample, create perlin-like noise or just simple static noise). Let's do a simple grain generation.
- Blob Implementation: Use a CSS shape with
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%. Animate the border-radius values for the organic movement.
- Controls: Segments as toggle buttons. Variants as radio cards.
- Analytics: Use simple CSS bar charts inside glass panels. Values animate via JS.
-
Drafting the Code (incorporating specific visual constraints):
- Contrast Check: Since background is dark (approx #111111), text must be #e0e0e0 or #f5f5f5.
- Texture: Background pattern.
- Slow Motion: CSS transitions:
transition: all 1.2s cubic-bezier(0.25, 1, 0.5, 1);
-
Detailed Feature Logic:
- Segment Override: Toggle switches (custom styled checkboxes).
- "High Value Customer"
- "Mobile"
- "New User"
- "International"
- Variant Selector: Three distinct cards labeled "Forest", "Coral", "Sand".
- Preview: A central "card" floating. Inside, show a mock UI element (e.g., a "Buy" button or "Hero Text") representative of that variant.
- Analysis: "Engagement Score", "Conversion Rate", "Drop-off". These numbers "decay" or "grow" based on selected segment/overrides to simulate sensitivity.
-
Adding the "Wow" Factor (Three.js/Shaders):
- Three.js: Let's use a very lightweight Three.js background: a slowly rotating mesh of particles or a fluid shader.
- Decision: A "WebGL Fluid" background might be too complex for a single file without issues. A better approach for "Biophilic" and "Performance": A subtle "curtain" of floating dust motes/leaves rendered in Canvas or Three.js.
- Chosen Approach: Three.js Particle system representing "fireflies" or "pollen" moving gently. It's lightweight and organic. Dark scene, glowing particles.
-
Refining Three.js Implementation:
- Scene, Camera, Renderer.
- Geometry: BufferGeometry with random positions.
- Material: PointsMaterial with a soft texture (generated via canvas) and vertexColors or single soft colour.
- Animation Loop: Rotate system slowly, elevate waves gently.
-
Writing the Code (Synthesizing):
- Head: Tailwind script config. Custom style tag for noise, blob animations, scrollbar.
- Body:
#canvas-container: Absolute full screen z-0.
# grain-overlay: Pointer-events none.
#app: Main container z-10.
- Header.
- Grid: 3 columns (Controls, Preview, Analytics). 1 row.
- Footer (Logs).
- JS:
- Three.js init.
- Grain generation.
- UI Logic: Update function.
- Chart update logic: simple width transition.
-
Polishing Details:
- Typography: Use
font-serif for headings.
- Colors: "Coral" variant = warm pink/red. "Forest" = deep green/gold. "Sand" = beige/disco gold.
- Analytics: Make the bars fill up when a variant is selected.
- Safety: Add a "Safe Mode" toggle that explicitly says "Offline / Save Not Enabled".
-
Self-Correction/Review during drafting:
- Check: Is the text high contrast? Yes, using
text-gray-100 on dark.
- Check: Is it slow media? All transitions are
duration-1000 or more.
- Check: Are shapes organic? The blob and buttons are circular/rounded-full.
- Check: No external assets? Three.js via CDN. Tailwind via CDN.
- Check: Does it handle interactions? Yes, click handlers on segment toggles and variant cards.
-
Final Code Structure Assembly:
- (HTML tags...)
- CSS in
<style>.
- JS in
<script> (type="module" for Three.js imports).
(Self-Correction on Three.js Imports): Since it's a single file without a build step, using ES modules from a CDN like esm.sh or unpkg is best.
<script type="module">
import * as THREE from 'https://cdn.skypack.dev/three@0.136.0';
// ... code
</script>
-
Final Polish:
- Add a "Console" log at the bottom to show actions like "Segment overridden: VIP = true", "Applying variant: Coral", generating a "living documentation" feel.
- Ensure the
canvas resizes correctly.
-
Output Generation: (Proceeding to generate the full HTML).
(Self-Correction during generation): The prompt asks for "Design a personalization testing sandbox enabling PMs to preview variants, override segments, and analyze outputs safely." The design must reflect the persona (Natural UI/UX). I need to ensure the "Analysis" part isn't just static numbers but maybe a little visualization that feels organic, like a stem growing or a liquid filling.
Let's make the analytics bars grow like plants (vertical), or maybe a liquid fill effect. Let's go with vertical bars that have a wavy top (to match the organic theme) using SVG.
Let's execute.
Here is the complete, self-contained HTML file. It combines a high-performance Three.js particle background (simulating dust/spores in a forest), a custom noise texture, Tailwind CSS for structure, and custom organic animations for the UI. It is designed specifically for Product Managers to simulate, override, and analyze personalization variants in a calm, biophilic environment.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SANDBOX // Biophilic Personalization Testing</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;1,400&family=Lato:wght@300;400;500&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
serif: ['"Cormorant Garamond"', 'serif'],
sans: ['"Lato"', 'sans-serif'],
},
colors: {
'forest-deep': '#111a14',
'forest-surface': '#1f2922',
'moss': '#8c9a8a',
'gold': '#d4a373',
'coral': '#c96c6c',
'sand': '#e6ccb2',
'stein': '#2b2b2b',
},
boxShadow: {
'glow': '0 0 20px rgba(140, 154, 138, 0.15)',
'soft': '0 10px 30px -10px rgba(0, 0, 0, 0.5)',
},
animation: {
'blob': 'blob-bounce 8s infinite ease-in-out',
'float': 'float 6s ease-in-out infinite',
},
keyframes: {
'blob-bounce': {
'0%, 100%': { borderRadius: '60% 40% 30% 70% / 60% 30% 70% 40%' },
'50%': { borderRadius: '30% 60% 70% 40% / 50% 60% 30% 60%' },
},
'float': {
'0%, 100%': { transform: 'translateY(0)' },
'50%': { transform: 'translateY(-10px)' },
}
}
}
}
}
</script>
<style>
/* Base Setup */
body, html {
background-color: #0a0c0a;
color: #e0e2db;
overflow: hidden; /* Manage scroll within containers */
height: 100%;
margin: 0;
padding: 0;
}
/* Noise Texture Overlay */
.noise-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 50;
opacity: 0.05;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}
/* Glassmorphism with Earth Tones */
.glass-panel {
background: rgba(31, 41, 34, 0.4);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}
/* Scrollbar styling */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: #111a14;
}
::-webkit-scrollbar-thumb {
background: #8c9a8a;
border-radius: 3px;
}
/* Organic Blob */
.blob-shape {
transition: all 1.5s cubic-bezier(0.25, 1, 0.5, 1);
background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.1), transparent 60%);
}
/* Variant Colors */
.variant-forest .blob-shape { border: 1px solid #8c9a8a; box-shadow: 0 0 30px rgba(140, 154, 138, 0.2); }
.variant-coral .blob-shape { border: 1px solid #c96c6c; box-shadow: 0 0 30px rgba(201, 108, 108, 0.2); }
.variant-sand .blob-shape { border: 1px solid #e6ccb2; box-shadow: 0 0 30px rgba(230, 204, 178, 0.2); }
/* Wave Animation for Charts */
.wave-path {
transition: d 1s ease-out;
}
/* Toggle Switch */
.toggle-checkbox:checked {
right: 0;
border-color: #8c9a8a;
}
.toggle-checkbox:checked + .toggle-label {
background-color: #8c9a8a;
}
/* Utils */
.text-shadow-subtle {
text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
#canvas-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
opacity: 0.6;
}
</style>
</head>
<body class="antialiased">
<!-- Three.js Background -->
<div id="canvas-container"></div>
<!-- Grain Overlay -->
<div class="noise-overlay"></div>
<!-- Main Interface -->
<div class="relative z-10 flex flex-col h-screen p-6 md:p-8">
<!-- Header -->
<header class="flex justify-between items-center mb-8 animate-fade-in-down">
<div class="flex items-center space-x-3">
<div class="w-4 h-4 rounded-full bg-moss animate-pulse shadow-glow"></div>
<h1 class="font-serif text-2xl tracking-widest text-gray-100">SANDBOX <span class="text-moss text-sm align-middle ml-1">BETA</span></h1>
</div>
<div class="text-right">
<p class="text-xs text-gray-500 font-sans uppercase tracking-wider">Offline Simulation</p>
<div class="flex items-center justify-end space-x-2 text-moss text-sm">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
<span>Safe Environment</span>
</div>
</div>
</header>
<!-- Core Layout: 3 Columns -->
<main class="flex-1 flex gap-6 min-h-0 overflow-hidden">
<!-- LEFT: Controls & Overrides -->
<aside class="w-1/4 glass-panel rounded-3xl p-6 flex flex-col gap-6 shadow-soft overflow-y-auto">
<div class="text-center border-b border-gray-800 pb-4">
<h2 class="font-serif text-xl text-moss">Segment Overrides</h2>
<p class="text-xs text-gray-500 mt-1">Force specific attributes for preview.</p>
</div>
<!-- Override List -->
<div class="space-y-4">
<div class="flex items-center justify-between group cursor-pointer">
<label class="text-sm text-gray-300 group-hover:text-white transition-colors">VIP Status</label>
<div class="relative inline-block w-10 mr-2 align-middle select-none transition duration-200 ease-in">
<input type="checkbox" id="toggle-vip" class="toggle-checkbox absolute block w-5 h-5 rounded-full bg-white border-4 border-stein appearance-none cursor-pointer transition-all duration-300 top-0 left-0" checked/>
<label for="toggle-vip" class="toggle-label block overflow-hidden h-5 rounded-full bg-stein cursor-pointer"></label>
</div>
</div>
<div class="flex items-center justify-between group cursor-pointer">
<label class="text-sm text-gray-300 group-hover:text-white transition-colors">New User (0-7d)</label>
<div class="relative inline-block w-10 mr-2 align-middle select-none transition duration-200 ease-in">
<input type="checkbox" id="toggle-new" class="toggle-checkbox absolute block w-5 h-5 rounded-full bg-white border-4 border-stein appearance-none cursor-pointer transition-all duration-300 top-0 left-0"/>
<label for="toggle-new" class="toggle-label block overflow-hidden h-5 rounded-full bg-stein cursor-pointer"></label>
</div>
</div>
<div class="flex items-center justify-between group cursor-pointer">
<label class="text-sm text-gray-300 group-hover:text-white transition-colors">International Region</label>
<div class="relative inline-block w-10 mr-2 align-middle select-none transition duration-200 ease-in">
<input type="checkbox" id="toggle-intl" class="toggle-checkbox absolute block w-5 h-5 rounded-full bg-white border-4 border-stein appearance-none cursor-pointer transition-all duration-300 top-0 left-0"/>
<label for="toggle-intl" class="toggle-label block overflow-hidden h-5 rounded-full bg-stein cursor-pointer"></label>
</div>
</div>
</div>
<div class="mt-auto border-t border-gray-800 pt-4">
<h3 class="font-serif text-sm text-gray-500 mb-3">Device Preview</h3>
<div class="flex gap-2">
<button class="flex-1 py-2 text-xs border border-gray-700 rounded hover:bg-gray-800 text-gray-300 transition">Mobile</button>
<button class="flex-1 py-2 text-xs border border-gray-700 rounded hover:bg-white text-black transition">Desktop</button>
<button class="flex-1 py-2 text-xs border border-gray-700 rounded hover:bg-gray-800 text-gray-300 transition">Tablet</button>
</div>
</div>
</aside>
<!-- CENTER: Live Preview -->
<section class="flex-1 glass-panel rounded-3xl p-8 flex flex-col items-center justify-center relative shadow-soft overflow-hidden">
<!-- Decorative Large Blobs in Background -->
<div class="absolute top-0 left-0 w-96 h-96 bg-forest-deep rounded-full mix-blend-screen filter blur-[100px] opacity-50 animate-blob"></div>
<div class="absolute bottom-0 right-0 w-96 h-96 bg-stein rounded-full mix-blend-screen filter blur-[100px] opacity-50 animate-blob animation-delay-2000"></div>
<!-- Preview Stage -->
<div id="preview-stage" class="relative z-10 w-full max-w-lg aspect-[4/3] flex items-center justify-center transition-all duration-1000 ease-[cubic-bezier(0.25,1,0.5,1)]">
<!-- The Organic Variant Container -->
<div id="variant-container" class="blob-shape w-4/5 h-4/5 flex items-center justify-center p-8 relative transition-colors duration-1000 variant-forest animate-float">
<!-- Content Inside Blob -->
<div class="text-center z-20 mix-blend-difference">
<h3 id="variant-title" class="font-serif text-3xl md:text-5xl mb-4 text-gray-100 text-shadow-subtle">Forest</h3>
<p id="variant-desc" class="font-sans text-sm max-w-[200px] mx-auto text-gray-200 leading-relaxed">
Calming organic growth. Emphasizes stability and deep connection.
</p>
<div id="variant-action" class="mt-8">
<button class="px-8 py-3 bg-gray-900/50 backdrop-blur border border-white/20 rounded-full text-xs uppercase tracking-[0.2em] hover:bg-white hover:text-black transition duration-700">
Explore
</button>
</div>
</div>
<!-- Decorative floating elements inside -->
<div class="absolute top-1/4 left-1/4 w-4 h-4 bg-moss rounded-full blur-[1px] opacity-60 animate-pulse"></div>
<div class="absolute bottom-1/3 right-1/3 w-3 h-3 bg-gold rounded-full blur-[1px] opacity-60 animate-pulse"></div>
</div>
</div>
<!-- Variant Selector (Bottom of Preview) -->
<div class="absolute bottom-8 flex space-x-6 z-20 bg-black/20 backdrop-blur-md px-8 py-4 rounded-full border border-white/5">
<button data-variant="forest" class="variant-btn group flex items-center gap-2 opacity-100 transition-opacity duration-500 focus:outline-none">
<span class="w-3 h-3 rounded-full bg-moss ring-2 ring-transparent group-hover:ring-white/50"></span>
<span class="text-xs font-sans text-gray-300 uppercase tracking-wider group-hover:text-white">Forest</span>
</button>
<button data-variant="coral" class="variant-btn group flex items-center gap-2 opacity-50 hover:opacity-100 transition-opacity duration-500 focus:outline-none">
<span class="w-3 h-3 rounded-full bg-coral ring-2 ring-transparent group-hover:ring-white/50"></span>
<span class="text-xs font-sans text-gray-500 uppercase tracking-wider group-hover:text-gray-300">Coral</span>
</button>
<button data-variant="sand" class="variant-btn group flex items-center gap-2 opacity-50 hover:opacity-100 transition-opacity duration-500 focus:outline-none">
<span class="w-3 h-3 rounded-full bg-sand ring-2 ring-transparent group-hover:ring-white/50"></span>
<span class="text-xs font-sans text-gray-500 uppercase tracking-wider group-hover:text-gray-300">Sand</span>
</button>
</div>
</section>
<!-- RIGHT: Analysis & Outputs -->
<aside class="w-1/4 glass-panel rounded-3xl p-6 flex flex-col gap-4 shadow-soft overflow-y-auto">
<div class="text-center border-b border-gray-800 pb-4">
<h2 class="font-serif text-xl text-gold">Performance Analysis</h2>
<p class="text-xs text-gray-500 mt-1">Projected lift based on cohorts.</p>
</div>
<!-- Metrics Cards -->
<div class="space-y-6">
<!-- Metric 1 -->
<div class="bg-stein/30 p-4 rounded-2xl border border-white/5">
<div class="flex justify-between items-end mb-2">
<span class="text-xs text-gray-400 uppercase">Conversion</span>
<span id="metric-conv" class="font-serif text-2xl text-coral">--%</span>
</div>
<!-- Organic Bar Chart (Wave) -->
<svg class="w-full h-12" viewBox="0 0 100 20" preserveAspectRatio="none">
<path id="chart-conv" d="M0,20 L0,20 L100,20 L100,20 Z" fill="rgba(201,108,108,0.2)" class="wave-path"/>
<path id="line-conv" d="M0,20 L0,20 L100,20 L100,20" fill="none" stroke="#c96c6c" stroke-width="2" class="wave-path"/>
</svg>
</div>
<!-- Metric 2 -->
<div class="bg-stein/30 p-4 rounded-2xl border border-white/5">
<div class="flex justify-between items-end mb-2">
<span class="text-xs text-gray-400 uppercase">Engagement</span>
<span id="metric-engage" class="font-serif text-2xl text-gold">--s</span>
</div>
<svg class="w-full h-12" viewBox="0 0 100 20" preserveAspectRatio="none">
<path id="chart-engage" d="M0,20 L0,20 L100,20 L100,20 Z" fill="rgba(212,163,115,0.2)" class="wave-path"/>
<path id="line-engage" d="M0,20 L0,20 L100,20 L100,20" fill="none" stroke="#d4a373" stroke-width="2" class="wave-path"/>
</svg>
</div>
<!-- Metric 3 -->
<div class="bg-stein/30 p-4 rounded-2xl border border-white/5">
<div class="flex justify-between items-end mb-2">
<span class="text-xs text-gray-400 uppercase">Drop-off</span>
<span id="metric-drop" class="font-serif text-2xl text-gray-500">--%</span>
</div>
<svg class="w-full h-12" viewBox="0 0 100 20" preserveAspectRatio="none">
<path id="chart-drop" d="M0,20 L0,20 L100,20 L100,20 Z" fill="rgba(200,200,200,0.1)" class="wave-path"/>
<path id="line-drop" d="M0,20 L0,20 L100,20 L100,20" fill="none" stroke="#8c9a8a" stroke-width="2" class="wave-path"/>
</svg>
</div>
</div>
<!-- Contextual Note -->
<div class="mt-auto pt-4 border-t border-gray-800">
<p class="text-[10px] text-gray-600 font-sans leading-relaxed italic">
*These predictions are generated via the offline simulation engine. No production data is accessed.
</p>
<button id="refresh-metrics" class="mt-4 w-full py-2 text-xs border border-moss/30 text-moss rounded hover:bg-moss/10 transition font-serif italic">
Refresh Simulation
</button>
</div>
</aside>
</main>
<!-- Bottom Logs -->
<footer class="h-32 mt-6 glass-panel rounded-2xl p-4 overflow-hidden flex flex-col">
<div class="flex justify-between items-center mb-2">
<h3 class="text-xs font-serif uppercase text-gray-400">Event Stream</h3>
<div class="flex gap-2">
<span class="text-[10px] bg-stein px-2 py-0.5 rounded text-gray-400">ENV: LOCAL</span>
<span class="text-[10px] bg-stein px-2 py-0.5 rounded text-gray-400">SESSION: 8F-92</span>
</div>
</div>
<div id="log-container" class="flex-1 overflow-y-auto font-mono text-[10px] text-gray-400 space-y-1">
<div><span class="text-gray-600">[SYSTEM]</span> Sandbox initialized. Ready for previews.</div>
</div>
</footer>
</div>
<!-- Scripts -->
<script type="module">
import * as THREE from 'https://cdn.skypack.dev/three@0.136.0';
// --- 1. Three.js Background (Organic Floating Particles) ---
const initThreeBackground = () => {
const container = document.getElementById('canvas-container');
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x0a0c0a, 0.002);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 50;
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
// Particles
const geometry = new THREE.BufferGeometry();
const count = 1500;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const sizes = new Float32Array(count);
const colorPalette = [
new THREE.Color(0x8c9a8a), // Moss
new THREE.Color(0xd4a373), // Gold
new THREE.Color(0x2b2b2b), // Dark grey
];
for (let i = 0; i < count; i++) {
const i3 = i * 3;
positions[i3] = (Math.random() - 0.5) * 150;
positions[i3 + 1] = (Math.random() - 0.5) * 100;
positions[i3 + 2] = (Math.random() - 0.5) * 100;
const color = colorPalette[Math.floor(Math.random() * colorPalette.length)];
colors[i3] = color.r;
colors[i3 + 1] = color.g;
colors[i3 + 2] = color.b;
sizes[i] = Math.random() * 2;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
geometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
// Custom shader material for soft particles
const material = new THREE.PointsMaterial({
size: 1.5,
vertexColors: true,
transparent: true,
opacity: 0.6,
blending: THREE.AdditiveBlending,
sizeAttenuation: true
});
const particleSystem = new THREE.Points(geometry, material);
scene.add(particleSystem);
// Animation
let time = 0;
const animate = () => {
requestAnimationFrame(animate);
time += 0.001;
particleSystem.rotation.y = time * 0.1;
particleSystem.rotation.z = Math.sin(time * 0.2) * 0.1;
// Gentle wave motion for positions
const posAttribute = particleSystem.geometry.attributes.position;
for(let i = 0; i < count; i++) {
const x = posAttribute.getX(i);
// Add subtle sine wave
posAttribute.setY(i, posAttribute.getY(i) + Math.sin(x * 0.05 + time) * 0.05);
}
posAttribute.needsUpdate = true;
renderer.render(scene, camera);
};
animate();
// Resize handler
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
};
// --- 2. Application State & Data Models ---
const variants = {
forest: {
title: "Forest",
desc: "Emphasizes organic growth, deep greens, and stable trust signals. Lower friction for returning users.",
colorClass: "variant-forest",
metrics: { conv: 0.045, engage: 85, drop: 0.12 } // Base values
},
coral: {
title: "Coral",
desc: "Vibrant, attention-grabbing, high-contrast. Optimized for acquisition and new user activation.",
colorClass: "variant-coral",
metrics: { conv: 0.062, engage: 110, drop: 0.18 }
},
sand: {
title: "Sand",
desc: "Warm, neutral, premium. Geared towards high-value conversions and longer session times.",
colorClass: "variant-sand",
metrics: { conv: 0.081, engage: 140, drop: 0.08 }
}
};
// Base state before overrides
let currentState = {
variant: 'forest',
overrides: {
vip: false,
newUser: false,
intl: false
}
};
// --- 3. DOM Elements ---
const variantContainer = document.getElementById('variant-container');
const variantTitle = document.getElementById('variant-title');
const variantDesc = document.getElementById('variant-desc');
const variantBtns = document.querySelectorAll('.variant-btn');
const toggleVip = document.getElementById('toggle-vip');
const toggleNew = document.getElementById('toggle-new');
const toggleIntl = document.getElementById('toggle-intl');
// Metrics El
const metricConv = document.getElementById('metric-conv');
const metricEngage = document.getElementById('metric-engage');
const metricDrop = document.getElementById('metric-drop');
const chartPaths = [
document.getElementById('chart-conv'),
document.getElementById('line-conv'),
document.getElementById('chart-engage'),
document.getElementById('line-engage'),
document.getElementById('chart-drop'),
document.getElementById('line-drop')
];
const logContainer = document.getElementById('log-container');
const refreshBtn = document.getElementById('refresh-metrics');
// --- 4. Logic Functions ---
const log = (msg) => {
const time = new Date().toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" });
const div = document.createElement('div');
div.innerHTML = `<span class="text-gray-600">[${time}]</span> ${msg}`;
logContainer.appendChild(div);
logContainer.scrollTop = logContainer.scrollHeight;
};
const getAdjustedMetrics = (baseMetrics, overrides) => {
// Simple logic to simulate impact of overrides
let conv = baseMetrics.conv;
let engage = baseMetrics.engage;
let drop = baseMetrics.drop;
if (overrides.vip) {
conv += 0.015;
drop += 0.05;
}
if (overrides.newUser) {
// New users convert lower generally, but engagement high
conv -= 0.01;
engage += 20;
}
if (overrides.intl) {
conv -= 0.005;
drop += 0.02;
}
// Ensure bounds
conv = Math.max(0.01, Math.min(0.15, conv));
drop = Math.max(0.01, Math.min(0.5, drop));
return {
conv: (conv * 100).toFixed(1) + '%',
engage: Math.floor(engage) + 's',
drop: (drop * 100).toFixed(1) + '%',
rawConv: conv,
rawEngage: engage,
rawDrop: drop
};
};
const generateWavePath = (val, max) => {
// val is 0-1 roughly. max is y distortion.
const height = 20; // SVG viewBox height
const width = 100;
const yBase = height;
const yPeak = height - (val * height);
// Adding organic波浪 (wave)
const mid = width / 2;
const startX = 0;
const ctrl1 = width * 0.35;
const ctrl2 = width * 0.65;
// Curved line
const d = `M0,${yBase} Q${width * 0.25},${yBase} ${mid},${yPeak} T${width},${yBase} L${width},${height} L0,${height} Z`;
const line = `M0,${yBase} Q${width * 0.25},${height - (val*height*0.9)} ${mid},${yPeak} T${width},${yBase}`;
return { fill: d, stroke: line };
};
const updateCharts = (metrics) => {
// Metric 1 (Conv) - Max raw maybe 0.12 (12%) -> 1.0 height
const convMap = metrics.rawConv / 0.15;
const convPaths = generateWavePath(convMap, 20);
chartPaths[0].setAttribute('d', convPaths.fill);
chartPaths[1].setAttribute('d', convPaths.stroke);
metricConv.innerText = metrics.conv;
// Metric 2 (Engage) - Max raw 150s -> 1.0 height
const engageMap = metrics.rawEngage / 180;
const engagePaths = generateWavePath(engageMap, 20);
chartPaths[2].setAttribute('d', engagePaths.fill);
chartPaths[3].setAttribute('d', engagePaths.stroke);
metricEngage.innerText = metrics.engage;
// Metric 3 (Drop) - Max raw 0.3 -> 1.0 height
const dropMap = metrics.rawDrop / 0.5;
const dropPaths = generateWavePath(dropMap, 20);
chartPaths[4].setAttribute('d', dropPaths.fill);
chartPaths[5].setAttribute('d', dropPaths.stroke);
metricDrop.innerText = metrics.drop;
};
const updatePreview = () => {
const vData = variants[currentState.variant];
// 1. Update Text with Fade
variantTitle.style.opacity = 0;
variantDesc.style.opacity = 0;
setTimeout(() => {
variantTitle.innerText = vData.title;
variantDesc.innerText = vData.desc;
variantTitle.style.opacity = 1;
variantDesc.style.opacity = 1;
}, 300);
// 2. Update Blob Class & Color
variantContainer.className = `blob-shape w-4/5 h-4/5 flex items-center justify-center p-8 relative transition-colors duration-1000 ${vData.colorClass} animate-float`;
// 3. Update Variant Buttons UI
variantBtns.forEach(btn => {
const isActive = btn.dataset.variant === currentState.variant;
const span = btn.querySelector('span:last-child'); // Text span
const circle = btn.querySelector('span:first-child'); // Circle
if (isActive) {
btn.classList.remove('opacity-50');
span.classList.remove('text-gray-500');
span.classList.add('text-gray-300');
circle.classList.add('ring-white/50');
} else {
btn.classList.add('opacity-50');
span.classList.remove('text-gray-300');
span.classList.add('text-gray-500');
circle.classList.remove('ring-white/50');
}
});
};
const runSimulation = () => {
const vData = variants[currentState.variant];
const metrics = getAdjustedMetrics(vData.metrics, currentState.overrides);
// Slight delay to simulate "processing"
updateCharts({ rawConv: 0, rawEngage: 0, rawDrop: 0 });
setTimeout(() => {
updateCharts(metrics);
log(`Simulation complete: <span class="text-moss">${vData.title}</span> variant updated. Affected Metrics: Conv=${metrics.conv}, Engage=${metrics.engage}`);
}, 800);
};
// --- 5. Event Listeners ---
// Variant Switcher
variantBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
const newVar = btn.dataset.variant;
if (newVar !== currentState.variant) {
currentState.variant = newVar;
log(`Variant switched to: <span class="text-coral">${newVar.toUpperCase()}</span>`);
updatePreview();
runSimulation();
}
});
});
// Override Toggles
const handleToggle = (key, value) => {
currentState.overrides[key] = value;
const status = value ? "ON" : "OFF";
log(`Segment Override: <span class="text-gold">${key.toUpperCase()}</span> set to ${status}`);
runSimulation();
};
toggleVip.addEventListener('change', (e) => handleToggle('vip', e.target.checked));
toggleNew.addEventListener('change', (e) => handleToggle('newUser', e.target.checked));
toggleIntl.addEventListener('change', (e) => handleToggle('intl', e.target.checked));
// Refresh Button
refreshBtn.addEventListener('click', () => {
log('Manual refresh requested...');
runSimulation();
});
// --- 6. Initialization ---
window.addEventListener('load', () => {
initThreeBackground();
log('Environment ready. Waiting for user input...');
updatePreview();
runSimulation();
});
</script>
</body>
</html>