<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bot Defense Platform | Natural Explainability</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=Lora:ital,wght@0,400;0,600;1,400&family=Playfair+Display:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Configure Tailwind with custom theme -->
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
serif: ['"Playfair Display"', 'serif'],
body: ['"Lora"', 'serif'],
},
colors: {
sage: {
50: '#F2F6F0',
100: '#DCE4D8',
200: '#B8C9B0',
300: '#9AB08E',
400: '#7A9971',
500: '#5F7B58',
600: '#4A6144',
},
terracotta: {
50: '#F4EBE6',
100: '#E0CDBE',
200: '#C6A391',
300: '#A87C65',
400: '#905F4A',
500: '#754C3E',
},
stone: {
50: '#F5F1E8',
100: '#EDE6DE',
200: '#DED4C7',
300: '#C9B8A6',
400: '#B59C86',
500: '#A18069',
900: '#433D38',
}
},
boxShadow: {
'soft': '0 20px 60px -12px rgba(75, 85, 99, 0.15)',
'glow': '0 0 30px rgba(167, 139, 111, 0.3)',
},
animation: {
'float': 'float 10s ease-in-out infinite',
},
keyframes: {
float: {
'0%, 100%': { transform: 'translateY(0) rotate(0deg)' },
'50%': { transform: 'translateY(-20px) rotate(1deg)' },
}
}
}
}
}
</script>
<style>
/* Global Styles & Resets */
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow-x: hidden;
background-color: #F5F1E8;
color: #433D38;
}
/* Noise Texture Overlay */
.noise-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 50;
opacity: 0.4;
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.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}
/* Organic Blob Shapes */
.blob-shape {
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
animation: blob-morph 12s ease-in-out infinite alternate;
}
.blob-shape-2 {
border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
animation: blob-morph 15s ease-in-out infinite alternate-reverse;
}
@keyframes blob-morph {
0% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; transform: scale(1); }
50% { border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%; transform: scale(1.02); }
100% { border-radius: 50% 40% 60% 50% / 40% 30% 50% 60%; transform: scale(0.98); }
}
/* Smooth Transitions */
.smooth-transition {
transition: all 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}
/* Custom Scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #F5F1E8;
}
::-webkit-scrollbar-thumb {
background: #B59C86;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #9C826B;
}
/* Glass Card Effect */
.glass-card {
background: rgba(255, 253, 249, 0.75);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.6);
box-shadow: 0 8px 32px 0 rgba(75, 85, 99, 0.1);
}
/* Interactive Element Focus */
button:focus, div[role="button"]:focus {
outline: none;
box-shadow: 0 0 0 4px rgba(126, 139, 114, 0.4);
}
/* Leaf SVG styling */
.leaf-vein {
stroke: #A18069;
stroke-width: 1;
fill: none;
opacity: 0.6;
}
</style>
</head>
<body class="antialiased selection:bg-sage-300 selection:text-stone-900">
<!-- Noise Overlay -->
<div class="noise-overlay"></div>
<!-- Background Canvas for Organic Fluids -->
<canvas id="fluidCanvas" class="fixed top-0 left-0 w-full h-full -z-10"></canvas>
<!-- Main App Container -->
<div class="relative min-h-screen flex flex-col items-center justify-center p-4 md:p-8">
<!-- Header -->
<header class="w-full max-w-6xl flex justify-between items-center mb-12 smooth-transition opacity-0" id="header">
<div class="flex items-center gap-4">
<div class="w-12 h-12 bg-stone-200 rounded-full flex items-center justify-center overflow-hidden blob-shape shadow-sm border border-stone-300">
<svg viewBox="0 0 24 24" class="w-6 h-6 text-stone-600" fill="none" stroke="currentColor" stroke-width="1.5">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
</div>
<div>
<h1 class="font-serif text-2xl font-bold text-stone-900 tracking-wide">Veridian Shield</h1>
<p class="text-xs text-stone-500 tracking-widest uppercase mt-0.5">Bot Defense & Explainability</p>
</div>
</div>
<div class="flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-sage-500 animate-pulse"></span>
<span class="text-xs text-stone-500 font-serif italic">System Operational</span>
</div>
</header>
<!-- Introduction Overlay (Initially Visible) -->
<div id="intro-overlay" class="fixed inset-0 z-40 flex flex-col items-center justify-center bg-stone-50/90 backdrop-blur-sm smooth-transition opacity-100 pointer-events-auto">
<div class="text-center max-w-2xl px-6">
<h2 class="font-serif text-4xl md:text-5xl text-stone-900 mb-6 leading-tight">
A Natural Approach to <span class="text-terracotta-400">Digital Safety</span>.
</h2>
<p class="font-body text-lg text-stone-600 mb-10 leading-relaxed">
We use behavioral biometrics, client-side challenges, and device fingerprinting
to distinguish humans from bots. Every decision is explained with clarity.
</p>
<button onclick="app.startAudit()" class="group relative px-10 py-4 bg-stone-900 text-stone-100 font-serif tracking-wider rounded-full transition-all duration-500 hover:bg-stone-800 hover:scale-105 hover:shadow-glow active:scale-95">
<span class="relative z-10">Begin Security Audit</span>
<div class="absolute inset-0 rounded-full bg-stone-800 opacity-0 group-hover:opacity-20 transition-opacity"></div>
</button>
<p class="mt-6 text-sm text-stone-400 font-serif italic">No data is sent to any server. Everything runs locally in your browser.</p>
</div>
</div>
<!-- Main Dashboard Grid (Hidden Initially) -->
<main id="dashboard" class="w-full max-w-6xl grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8 opacity-0 pointer-events-none smooth-transition duration-1000">
<!-- Column 1: Behavioral & Fingerprint -->
<div class="flex flex-col gap-8">
<!-- Behavioral Analytics Panel -->
<section class="glass-card rounded-[2rem] p-8 relative overflow-hidden group">
<div class="absolute -right-10 -top-10 w-40 h-40 bg-sage-200 rounded-full blur-3xl opacity-50 group-hover:opacity-70 transition-opacity duration-700"></div>
<h3 class="font-serif text-xl text-stone-700 mb-4 flex items-center gap-2">
<svg class="w-5 h-5 text-sage-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 15l-2 5L9 9l11 4-5 2zm0 0l5 5M7.188 2.239l.777 2.897M5.136 7.965l-2.898-.777M13.95 4.05l-2.122 2.122m-5.657 5.656l-2.12 2.122"></path></svg>
Behavioral Analytics
</h3>
<p class="text-sm text-stone-500 mb-6 font-body">Move your mouse randomly. We analyze the natural "wobble" of human movement.</p>
<div class="relative bg-stone-50/50 rounded-xl border border-stone-200 p-2 h-48 mb-4">
<canvas id="behaviorCanvas" class="w-full h-full rounded-lg"></canvas>
<!-- Overlay SVG for decoration -->
<svg class="absolute top-4 right-4 w-8 h-8 text-stone-300" viewBox="0 0 24 24" fill="currentColor"><path d="M12,2C6.48,2,2,6.48,2,12s4.48,10,10,10s10-4.48,10-10S17.52,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/><path d="M12,6c-3.31,0-6,2.69-6,6s2.69,6,6,6s6-2.69,6-6S15.31,6,12,6z M12,16c-2.21,0-4-1.79-4-4s1.79-4,4-4s4,1.79,4,4 S14.21,16,12,16z"/></svg>
</div>
<div class="flex justify-between items-end">
<div>
<span class="text-xs uppercase tracking-wider text-stone-400">Humanity Score</span>
<div class="text-2xl font-serif font-bold text-sage-700" id="humanityScore">--%</div>
</div>
<div class="text-xs text-stone-400 font-body" id="behaviorStatus">Waiting for input...</div>
</div>
</section>
<!-- Device Fingerprint Panel -->
<section class="glass-card rounded-[2rem] p-8 relative">
<h3 class="font-serif text-xl text-stone-700 mb-4 flex items-center gap-2">
<svg class="w-5 h-5 text-terracotta-400" 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>
Device Fingerprint
</h3>
<p class="text-sm text-stone-500 mb-6 font-body">A unique, privacy-preserving hash derived from your browser's innate properties.</p>
<div class="grid grid-cols-2 gap-4 mb-6 text-sm">
<div class="bg-stone-100/50 p-3 rounded-xl">
<span class="block text-xs text-stone-400 uppercase">User Agent</span>
<span class="block font-mono text-xs text-stone-700 truncate" id="fp-ua">Analyzing...</span>
</div>
<div class="bg-stone-100/50 p-3 rounded-xl">
<span class="block text-xs text-stone-400 uppercase">Resolution</span>
<span class="block font-mono text-xs text-stone-700" id="fp-res">--</span>
</div>
<div class="bg-stone-100/50 p-3 rounded-xl">
<span class="block text-xs text-stone-400 uppercase">Language</span>
<span class="block font-mono text-xs text-stone-700" id="fp-lang">--</span>
</div>
<div class="bg-stone-100/50 p-3 rounded-xl">
<span class="block text-xs text-stone-400 uppercase">Timezone</span>
<span class="block font-mono text-xs text-stone-700" id="fp-tz">--</span>
</div>
</div>
<div class="border-t border-stone-200 pt-4">
<div class="flex items-center justify-between mb-2">
<span class="text-xs uppercase tracking-wider text-stone-400">Fingerprint Hash</span>
<svg class="w-4 h-4 text-stone-400 cursor-help" title="A SHA-256 like visual representation"><use href="#info-circle"/></svg>
</div>
<div class="flex items-center gap-3 bg-stone-100 p-3 rounded-xl border border-stone-200">
<!-- Organic Leaf ID Visualization -->
<svg id="leafViz" width="40" height="40" viewBox="0 0 40 40" class="flex-shrink-0">
<!-- Leaf path generated by JS -->
</svg>
<code class="font-mono text-xs md:text-sm text-stone-700 break-all" id="fp-hash">...</code>
</div>
</div>
</section>
</div>
<!-- Column 2: Challenge & Explainability -->
<div class="flex flex-col gap-8">
<!-- JavaScript Challenge -->
<section class="glass-card rounded-[2rem] p-8 relative">
<h3 class="font-serif text-xl text-stone-700 mb-4 flex items-center gap-2">
<svg class="w-5 h-5 text-sage-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
Active Challenge
</h3>
<p class="text-sm text-stone-500 mb-6 font-body">Bots cannot mimic the subtle tremor and duration of a human press. Hold the button steady.</p>
<div class="flex flex-col items-center justify-center h-48 bg-stone-50/50 rounded-xl border border-stone-200 relative">
<!-- Challenge Button -->
<div id="challengeBtn" class="relative group cursor-pointer transition-transform duration-200 hover:scale-105 active:scale-95" onclick="challenge.startHold(event)">
<div class="absolute inset-0 bg-terracotta-300 rounded-full blur-md opacity-60 group-hover:opacity-80 transition-opacity"></div>
<div id="challengeCore" class="relative w-32 h-32 bg-white rounded-full border-4 border-terracotta-200 shadow-lg flex items-center justify-center overflow-hidden transition-colors duration-300">
<span id="challengeText" class="font-serif text-stone-600 text-center px-4">Hold to Verify<br><span class="text-xs font-sans text-stone-400">2 Seconds</span></span>
<!-- Progress Ring -->
<svg class="absolute inset-0 w-full h-full transform -rotate-90 pointer-events-none" id="challengeRing">
<circle cx="50%" cy="50%" r="60%" fill="transparent" stroke="#E0CDBE" stroke-width="4"></circle>
<circle id="challengeProgress" cx="50%" cy="50%" r="60%" fill="transparent" stroke="#A87C65" stroke-width="4" stroke-dasharray="377" stroke-dashoffset="377" class="transition-all duration-100 ease-linear"></circle>
</svg>
</div>
</div>
<div id="challengeStatus" class="mt-6 text-xs font-mono text-stone-500 h-4"></div>
</div>
</section>
<!-- Explainability Engine -->
<section class="glass-card rounded-[2rem] p-8 relative bg-stone-50/30">
<div class="absolute right-6 top-6">
<span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-bold bg-sage-100 text-sage-700 border border-sage-200">
<span class="w-2 h-2 rounded-full bg-sage-500 animate-pulse"></span>
AI Verdict
</span>
</div>
<h3 class="font-serif text-xl text-stone-800 mb-6">Decision Explainability</h3>
<!-- Verdict Display -->
<div id="verdictContainer" class="text-center py-8 opacity-50 transition-opacity duration-700">
<div class="text-stone-400 font-serif italic text-lg mb-2">Awaiting complete analysis...</div>
<div class="w-24 h-1 bg-stone-200 rounded-full mx-auto"></div>
</div>
<!-- Detailed Breakdown (Initially Hidden) -->
<div id="breakdown" class="hidden space-y-6">
<!-- Overall Score -->
<div class="bg-white/60 p-5 rounded-2xl shadow-sm border border-stone-100">
<div class="flex justify-between items-center mb-3">
<span class="font-serif font-bold text-stone-700">Overall Human Probability</span>
<span id="finalScore" class="text-3xl font-serif font-bold text-sage-600">0%</span>
</div>
<div class="h-3 bg-stone-100 rounded-full overflow-hidden">
<div id="scoreBar" class="h-full bg-sage-500 w-0 rounded-full transition-all duration-1000 ease-out-cubic shadow-sm"></div>
</div>
</div>
<!-- Metrics -->
<div class="grid grid-cols-2 gap-4">
<div class="metric-card bg-white/50 p-4 rounded-xl border border-stone-100 hover:shadow-md transition-shadow">
<span class="block text-xs text-stone-400 uppercase mb-1">Behavioral Entropy</span>
<div class="flex items-baseline gap-2">
<span id="metric-behavior" class="text-lg font-serif text-stone-800">--</span>
<span class="text-xs text-sage-600">+</span>
</div>
<p class="text-[10px] text-stone-500 mt-1">Mouse path irregularity</p>
</div>
<div class="metric-card bg-white/50 p-4 rounded-xl border border-stone-100 hover:shadow-md transition-shadow">
<span class="block text-xs text-stone-400 uppercase mb-1">Challenge Success</span>
<div class="flex items-baseline gap-2">
<span id="metric-challenge" class="text-lg font-serif text-stone-800">--</span>
<span class="text-xs text-sage-600">✓</span>
</div>
<p class="text-[10px] text-stone-500 mt-1">Hold time & steadiness</p>
</div>
<div class="metric-card bg-white/50 p-4 rounded-xl border border-stone-100 hover:shadow-md transition-shadow">
<span class="block text-xs text-stone-400 uppercase mb-1">Fingerprint Uniqueness</span>
<div class="flex items-baseline gap-2">
<span id="metric-fingerprint" class="text-lg font-serif text-stone-800">--</span>
<span class="text-xs text-sage-600">●</span>
</div>
<p class="text-[10px] text-stone-500 mt-1">Browser configuration hash</p>
</div>
<div class="metric-card bg-white/50 p-4 rounded-xl border border-stone-100 hover:shadow-md transition-shadow">
<span class="block text-xs text-stone-400 uppercase mb-1">Risk Vector</span>
<div id="metric-risk" class="text-lg font-serif text-stone-800">Low</div>
<p class="text-[10px] text-stone-500 mt-1">AI confidence level</p>
</div>
</div>
<!-- Explanation Text -->
<div class="bg-sage-50/50 p-5 rounded-2xl border border-sage-100">
<h4 class="font-serif font-bold text-sage-800 mb-2 text-sm">AI Reasoning</h4>
<p id="explanationText" class="font-body text-sm text-stone-600 leading-relaxed">
<!-- Populated by JS -->
</p>
</div>
</div>
</section>
</div>
</main>
<!-- Footer -->
<footer class="w-full max-w-6xl mt-12 text-center text-stone-400 text-xs font-serif flex justify-between">
<span>© 2024 Veridian Shield Labs.</span>
<span>Designed with Biophilic Principles.</span>
</footer>
</div>
<!-- Icons SVG Links -->
<svg style="display: none;">
<symbol id="info-circle" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
</symbol>
</svg>
<!-- JavaScript Application Logic -->
<script>
/**
* 1. Background Fluid Animation (Canvas)
* Creates drifting, soft organic shapes that blend.
*/
class FluidBackground {
constructor() {
this.canvas = document.getElementById('fluidCanvas');
this.ctx = this.canvas.getContext('2d');
this.blobs = [];
this.resize();
window.addEventListener('resize', () => this.resize());
this.initBlobs(6);
this.animate();
}
resize() {
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
}
initBlobs(count) {
for (let i = 0; i < count; i++) {
this.blobs.push({
x: Math.random() * this.canvas.width,
y: Math.random() * this.canvas.height,
radius: Math.random() * 150 + 100,
dx: (Math.random() - 0.5) * 0.4,
dy: (Math.random() - 0.5) * 0.4,
color: i % 2 === 0 ? 'rgba(212, 165, 116, 0.15)' : 'rgba(184, 201, 176, 0.15)' // Terracotta or Sage
});
}
}
animate() {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
// Create gradient mesh feel by drawing many large radial gradients
this.blobs.forEach(blob => {
blob.x += blob.dx;
blob.y += blob.dy;
// Bounce gently off edges
if (blob.x < -blob.radius) blob.x = this.canvas.width + blob.radius;
if (blob.x > this.canvas.width + blob.radius) blob.x = -blob.radius;
if (blob.y < -blob.radius) blob.y = this.canvas.height + blob.radius;
if (blob.y > this.canvas.height + blob.radius) blob.y = -blob.radius;
const gradient = this.ctx.createRadialGradient(blob.x, blob.y, 0, blob.x, blob.y, blob.radius);
gradient.addColorStop(0, blob.color);
gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
this.ctx.fillStyle = gradient;
this.ctx.beginPath();
this.ctx.arc(blob.x, blob.y, blob.radius, 0, Math.PI * 2);
this.ctx.fill();
});
requestAnimationFrame(() => this.animate());
}
}
/**
* 2. Behavioral Analytics Module
* Tracks mouse movement, calculates "wobble" to estimate humanity.
*/
class BehavioralMonitor {
constructor() {
this.canvas = document.getElementById('behaviorCanvas');
this.ctx = this.canvas.getContext('2d');
this.points = [];
this.maxPoints = 100;
this.score = 50; // Start neutral
this.totalDistance = 0;
this.lastPoint = null;
this.isActive = false;
this.uiScore = document.getElementById('humanityScore');
this.uiStatus = document.getElementById('behaviorStatus');
this.resize();
window.addEventListener('resize', () => this.resize());
// Interaction
this.canvas.addEventListener('mousemove', (e) => this.handleMove(e));
this.canvas.addEventListener('mouseenter', () => { this.isActive = true; this.points = []; this.totalDistance = 0; });
this.canvas.addEventListener('mouseleave', () => this.isActive = false);
}
resize() {
const rect = this.canvas.parentElement.getBoundingClientRect();
this.canvas.width = rect.width;
this.canvas.height = rect.height;
}
handleMove(e) {
if (!this.isActive) return;
const rect = this.canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
this.points.push({x, y, time: Date.now()});
if (this.points.length > this.maxPoints) this.points.shift();
// Calculate distance from last point
if (this.lastPoint) {
const dist = Math.hypot(x - this.lastPoint.x, y - this.lastPoint.y);
this.totalDistance += dist;
}
this.lastPoint = {x, y};
// Simple heuristic: Human movement is relatively fast but not perfectly straight.
// We calculate "efficiency". Straight line distance vs actual path length.
// Actually for a simple demo, we'll just calculate variance in angle.
if (this.points.length > 10) {
this.calculateWobble();
}
this.draw();
this.updateUI();
}
calculateWobble() {
// Calculate angular variance (turns)
let angles = [];
for (let i = 2; i < this.points.length; i++) {
const p1 = this.points[i-2];
const p2 = this.points[i-1];
const p3 = this.points[i];
const v1 = {x: p2.x - p1.x, y: p2.y - p1.y};
const v2 = {x: p3.x - p2.x, y: p3.y - p2.y};
let dot = v1.x*v2.x + v1.y*v2.y;
let det = v1.x*v2.y - v1.y*v2.x;
let angle = Math.atan2(det, dot);
angles.push(angle);
}
// Variance of angles - humans have higher variance
const mean = angles.reduce((a,b)=>a+b,0) / angles.length;
const variance = angles.reduce((a,b)=>a + (b-mean)**2, 0) / angles.length;
// Normalize variance to a 0-100 scale (empirical)
// Typical human tilt var around 0.1 - 0.3. Bot near 0.
let wobbleScore = Math.min(100, Math.max(0, variance * 500));
// Incorporate speed variance
this.score = wobbleScore;
}
draw() {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
if (this.points.length < 2) return;
this.ctx.beginPath();
this.ctx.strokeStyle = '#7A9971'; // Sage 400
this.ctx.lineWidth = 2;
this.ctx.lineCap = 'round';
this.ctx.lineJoin = 'round';
this.ctx.moveTo(this.points[0].x, this.points[0].y);
for (let i = 1; i < this.points.length; i++) {
this.ctx.lineTo(this.points[i].x, this.points[i].y);
}
this.ctx.stroke();
// Draw trail dots
this.points.forEach((p, i) => {
this.ctx.beginPath();
this.ctx.fillStyle = `rgba(113, 153, 113, ${i/this.points.length})`;
this.ctx.arc(p.x, p.y, 2, 0, Math.PI*2);
this.ctx.fill();
});
}
updateUI() {
this.uiScore.textContent = Math.round(this.score) + '%';
this.uiScore.style.opacity = Math.min(1, this.score/50);
if (this.isActive) {
this.uiStatus.textContent = "Analyzing movement patterns...";
}
}
getFinalScore() {
return Math.round(this.score);
}
}
/**
* 3. Interactive Challenge
* Hold button for 2 seconds without moving mouse > 10px.
*/
class Challenge {
constructor() {
this.btn = document.getElementById('challengeBtn');
this.core = document.getElementById('challengeCore');
this.text = document.getElementById('challengeText');
this.progress = document.getElementById('challengeProgress');
this.status = document.getElementById('challengeStatus');
this.radius = 60 * 2 * Math.PI; // Circumference approx (r=60% of square? We'll approximate)
// The SVG circle r=60% of 40px box = 24px radius. Circumference = 2*PI*24 ≈ 150.7
this.circumference = 2 * Math.PI * 24;
this.progress.style.strokeDasharray = `${this.circumference} ${this.circumference}`;
this.isHolding = false;
this.startTime = 0;
this.baseX = 0;
this.baseY = 0;
this.requiredTime = 2000; // ms
this.failThreshold = 15; // px
this.success = false;
this.completed = false;
}
reset() {
this.completed = false;
this.success = false;
this.core.style.transform = 'scale(1)';
this.core.style.backgroundColor = 'white';
this.core.style.borderColor = '#E0CDBE';
this.text.innerHTML = 'Hold to Verify<br><span class="text-xs font-sans text-stone-400">2 Seconds</span>';
this.progress.style.strokeDashoffset = this.circumference;
this.status.textContent = "";
}
startHold(e) {
if (this.completed) {
// If already successful, reset if clicked again? For demo flow, let's not allow reset after success.
return;
}
e.preventDefault(); // prevent text selection
const rect = this.btn.getBoundingClientRect();
this.baseX = e.clientX;
this.baseY = e.clientY;
this.isHolding = true;
this.startTime = Date.now();
this.status.textContent = "Hold steady...";
this.loop();
}
endHold(success) {
this.isHolding = false;
if (success) {
this.completed = true;
this.success = true;
this.core.style.backgroundColor = '#DCE4D8'; // Sage 100
this.core.style.borderColor = '#7A9971';
this.text.innerHTML = 'Verified<br><span class="text-xs font-serif text-sage-700">Human</span>';
this.status.textContent = "Challenge passed.";
if (window.app) window.app.checkCompletion();
} else {
this.core.style.transform = 'scale(0.95)';
this.text.innerHTML = 'Failed<br><span class="text-xs font-sans text-stone-400">Try again</span>';
this.status.textContent = "Movement too large.";
setTimeout(() => this.reset(), 1000);
}
}
loop() {
if (!this.isHolding) return;
// We rely on global mousemove to detect movement blurring,
// but it's easier to capture movement during the hold via a separate listener.
// For simplicity, we'll check in the global app's mousemove handler, or attach here.
// Let's use a one-time mousemove listener for this hold.
// But we need to check duration
const now = Date.now();
const elapsed = now - this.startTime;
const progress = Math.min(elapsed / this.requiredTime, 1);
// Update ring
const offset = this.circumference - (progress * this.circumference);
this.progress.style.strokeDashoffset = offset;
if (elapsed >= this.requiredTime) {
this.endHold(true);
} else {
requestAnimationFrame(() => this.loop());
}
}
registerMoveHandler(e) {
if (!this.isHolding || this.completed) return;
// Calculate distance from origin of press
// Note: e.client might be relative to viewport. We need to calculate relative to button's initial rect?
// Actually we just care about total movement.
// We don't have original rect easily now if mouse leaves button area.
// Better: store the initial clientX/Y and just compute Euclidean distance between current and initial.
const dx = e.clientX - this.baseX;
const dy = e.clientY - this.baseY;
const dist = Math.hypot(dx, dy);
if (dist > this.failThreshold) {
this.endHold(false);
}
}
getScore() {
return this.success ? 1.0 : 0.0;
}
}
/**
* 4. Fingerprinter
* Collects data, generates a hash and a leaf visualization.
*/
class Fingerprinter {
constructor() {
this.data = {};
this.hash = '';
this.ui = {
ua: document.getElementById('fp-ua'),
res: document.getElementById('fp-res'),
lang: document.getElementById('fp-lang'),
tz: document.getElementById('fp-tz'),
hash: document.getElementById('fp-hash'),
leaf: document.getElementById('leafViz')
};
}
collect() {
const nav = navigator;
this.data = {
ua: nav.userAgent.substring(0, 30) + '...', // truncate
res: `${window.screen.width}x${window.screen.height}`,
lang: nav.language,
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
hw: nav.hardwareConcurrency || 'unknown',
vendor: nav.vendor
};
}
// Simple hash function (djb2)
hashString(str) {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i); /* hash * 33 + c */
}
return hash >>> 0; // Ensure unsigned
}
generateLeafPath(seed) {
// Deterministic leaf generation using seed
// Simple logic: start bottom center, curve to top, vertex control points based on seed, then mirror.
const width = 40;
const height = 40;
const bottom = height - 2;
const top = 2;
const left = 2;
const right = width - 2;
// Use seed to control asymmetry and curvature
const r1 = (seed % 100) / 100; // 0-1
const r2 = ((seed >> 8) % 100) / 100;
const r3 = ((seed >> 16) % 100) / 100;
const r4 = ((seed >> 24) % 100) / 100;
// Control points for the right half (Bézier)
// Start point: (width/2, bottom)
const startX = width / 2;
const startY = bottom;
// End point (tip): (width/2, top) - but shift horizontally based on seed for asymmetry
const tipX = width/2 + (r1 - 0.5) * 10;
const tipY = top;
// Control point 1 (along right edge near bottom): (right * multiplier, bottom * dec)
const cp1x = (width/2) + r2 * (right - width/2);
const cp1y = bottom - r3 * (bottom - top) * 0.5;
// Control point 2 (near tip): (width/2 + shift, top + padding)
const cp2x = tipX + r4 * 5; // slightly further out
const cp2y = tipY + (height/2 - top) * 0.3;
// Construct path
// M start
// C cp1x cp1y, cp2x cp2y, tipX tipY
// Then we mirror this for left half:
// From tip, use symmetrical control points (negate x offset relative to center) back to start.
const centerX = width/2;
// Mirror function: x' = centerX - (x - centerX)
const mirror = (x) => 2*centerX - x;
const d = `
M ${startX} ${startY}
C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${tipX} ${tipY}
C ${mirror(cp2x)} ${cp2y}, ${mirror(cp1x)} ${cp1y}, ${startX} ${startY}
Z
`;
return d.trim().replace(/\s+/g, ' ');
}
render() {
this.collect();
// Combine fields for hash
const rawString = JSON.stringify(this.data);
const seed = this.hashString(rawString + 'veridian_salt');
this.hash = seed.toString(16).toUpperCase().padStart(8, '0');
// Update UI text
this.ui.ua.textContent = this.data.ua;
this.ui.res.textContent = this.data.res;
this.ui.lang.textContent = this.data.lang;
this.ui.tz.textContent = this.data.tz;
this.ui.hash.textContent = `0x${this.hash}`;
// Draw Leaf
const pathData = this.generateLeafPath(seed);
this.ui.leaf.innerHTML = `
<path d="${pathData}" fill="none" stroke="#A18069" stroke-width="1.5" class="leaf-vein" />
<path d="${pathData}" fill="#DCE4D8" opacity="0.6" />
`;
}
getUniquenessScore() {
// Simulate a score: if we got a hash, it's unique. Pretend to compare to known bot fingerprints.
// For demo, return random between 85-99 based on hash parity to show variation.
return 85 + (this.hash.charCodeAt(0) % 14);
}
}
/**
* 5. Explainability / Dashboard Orchestrator
* Manages the flow and final verdict.
*/
class App {
constructor() {
this.behavior = new BehavioralMonitor();
this.challenge = new Challenge();
this.fingerprinter = new Fingerprinter();
this.ui = {
header: document.getElementById('header'),
dashboard: document.getElementById('dashboard'),
intro: document.getElementById('intro-overlay'),
verdictContainer: document.getElementById('verdictContainer'),
breakdown: document.getElementById('breakdown'),
finalScore: document.getElementById('finalScore'),
scoreBar: document.getElementById('scoreBar'),
metricBehavior: document.getElementById('metric-behavior'),
metricChallenge: document.getElementById('metric-challenge'),
metricFingerprint: document.getElementById('metric-fingerprint'),
metricRisk: document.getElementById('metric-risk'),
explanation: document.getElementById('explanationText')
};
// Bind challenge movement to global mouse
document.addEventListener('mousemove', (e) => this.challenge.registerMoveHandler(e));
}
startAudit() {
// Hide intro
this.ui.intro.classList.remove('opacity-100', 'pointer-events-auto');
this.ui.intro.classList.add('opacity-0', 'pointer-events-none');
// Show dashboard and header
this.ui.dashboard.classList.remove('opacity-0', 'pointer-events-none');
this.ui.header.classList.remove('opacity-0');
// Start Fingerprinting immediately
this.fingerprinter.render();
// Wait a moment, then prompt user to interact with behavioral canvas
setTimeout(() => {
this.ui.behaviorStatus.textContent = "Please move your mouse in the box above.";
}, 1000);
}
checkCompletion() {
// Check if all conditions met
// 1. Behavioral score exists (non-zero)
// 2. Challenge success
if (this.challenge.success) {
this.generateReport();
} else {
this.ui.verdictContainer.innerHTML = `<div class="text-stone-400 font-serif italic">Waiting for challenge completion...</div>`;
}
}
generateReport() {
const behaviorScore = this.behavior.getFinalScore();
const challengeScore = 100;
const fingerprintScore = this.fingerprinter.getUniquenessScore();
// Weighted average
const totalScore = Math.round(behaviorScore * 0.4 + challengeScore * 0.3 + fingerprintScore * 0.3);
// Explainability text logic
let reason = "";
if (behaviorScore < 50) {
reason = "Your mouse movements exhibited an unnaturally low level of entropy (micro-tremors). This is typical of automated scripts.";
} else if (behaviorScore > 90) {
reason = "The fluidity and irregularity of your cursor movement are indistinguishable from a human user.";
} else {
reason = "Your movement patterns show signs of deliberate control, but fall within acceptable human variance.";
}
if (this.challenge.success) {
reason += " The interactive challenge was completed successfully with appropriate hold duration and stability.";
}
reason += ` Device fingerprinting confirms a consistent browser configuration with ${fingerprintScore}% uniqueness score against known bot clusters.`;
// DOM Updates
this.ui.verdictContainer.classList.add('opacity-0'); // fade out "awaiting"
setTimeout(() => {
this.ui.verdictContainer.classList.add('hidden');
this.ui.breakdown.classList.remove('hidden');
this.ui.breakdown.classList.add('opacity-100');
// Animate score
setTimeout(() => {
this.ui.finalScore.textContent = `${totalScore}%`;
this.ui.scoreBar.style.width = `${totalScore}%`;
// Update metrics
this.ui.metricBehavior.textContent = `${behaviorScore}%`;
this.ui.metricChallenge.textContent = `${challengeScore}%`;
this.ui.metricFingerprint.textContent = `${fingerprintScore}%`;
this.ui.metricRisk.textContent = totalScore > 85 ? "Low" : (totalScore > 60 ? "Medium" : "High");
this.ui.metricRisk.className = `text-lg font-serif ${
totalScore > 85 ? 'text-sage-600' : (totalScore > 60 ? 'text-yellow-600' : 'text-red-600')
}`;
this.ui.explanation.textContent = reason;
}, 300);
}, 500);
}
}
// Initialize App on Load
window.addEventListener('DOMContentLoaded', () => {
const fluid = new FluidBackground();
window.app = new App();
});
</script>
</body>
</html>