web3district commited on
Commit
5ccbd28
·
verified ·
1 Parent(s): 0e83215

pleasse sort the drag and drop feature , without this the game wont work - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +668 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Businessmodelreactable
3
- emoji: 📈
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: businessmodelreactable
3
+ emoji: 🐳
4
+ colorFrom: yellow
5
+ colorTo: red
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,668 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
+ <title>Business Model Canvas Game</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
11
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
12
+ <style>
13
+ :root {
14
+ --customer-segments: #ffa500;
15
+ --value-propositions: #ff5252;
16
+ --channels: #ffd700;
17
+ --customer-relationships: #4caf50;
18
+ --revenue-streams: #9c27b0;
19
+ --key-resources: #2196f3;
20
+ --key-activities: #00bcd4;
21
+ --key-partnerships: #795548;
22
+ --cost-structure: #9e9e9e;
23
+ --market-trends: #cddc39;
24
+ --team-talent: #e91e63;
25
+ --investor-relations: #3f51b5;
26
+ --technology-stack: #00bcd4;
27
+ --risk-factors: #8b0000;
28
+ --sustainability-impact: #808000;
29
+ --customer-feedback-loop: #ff00ff;
30
+ }
31
+
32
+ .canvas-grid {
33
+ display: flex;
34
+ gap: 16px;
35
+ height: 80vh;
36
+ max-height: 700px;
37
+ overflow-x: auto;
38
+ padding: 8px;
39
+ }
40
+
41
+ .canvas-block {
42
+ min-width: 300px;
43
+ width: 300px;
44
+ border-radius: 8px;
45
+ background-color: #ebecf0;
46
+ padding: 8px;
47
+ transition: all 0.3s ease;
48
+ cursor: pointer;
49
+ position: relative;
50
+ display: flex;
51
+ flex-direction: column;
52
+ max-height: 100%;
53
+ }
54
+
55
+ .canvas-block-header {
56
+ padding: 8px 10px;
57
+ font-weight: bold;
58
+ color: #172b4d;
59
+ display: flex;
60
+ justify-content: space-between;
61
+ align-items: center;
62
+ }
63
+
64
+ .canvas-block-content {
65
+ flex: 1;
66
+ overflow-y: auto;
67
+ padding: 0 4px;
68
+ margin: 8px 0;
69
+ }
70
+
71
+ .canvas-block:hover {
72
+ transform: translateY(-5px);
73
+ box-shadow: 0 8px 20px rgba(0,0,0,0.15);
74
+ }
75
+
76
+ .canvas-block.active {
77
+ box-shadow: 0 0 0 3px white, 0 0 0 6px currentColor;
78
+ }
79
+
80
+ .cube {
81
+ background: white;
82
+ border-radius: 4px;
83
+ box-shadow: 0 1px 0 rgba(9,30,66,.25);
84
+ padding: 8px 10px;
85
+ margin-bottom: 8px;
86
+ cursor: grab;
87
+ transition: all 0.2s ease;
88
+ font-size: 14px;
89
+ color: #172b4d;
90
+ position: relative;
91
+ }
92
+
93
+ .cube:hover {
94
+ background-color: #f4f5f7;
95
+ }
96
+
97
+ .cube.dragging {
98
+ transform: rotate(3deg);
99
+ box-shadow: 0 4px 8px rgba(0,0,0,0.2);
100
+ }
101
+
102
+ .cube-container {
103
+ flex: 1;
104
+ overflow-y: auto;
105
+ padding: 0 4px;
106
+ }
107
+
108
+ .applied-cube {
109
+ position: absolute;
110
+ bottom: 8px;
111
+ right: 8px;
112
+ width: 24px;
113
+ height: 24px;
114
+ border-radius: 4px;
115
+ display: flex;
116
+ align-items: center;
117
+ justify-content: center;
118
+ font-size: 12px;
119
+ box-shadow: 0 2px 4px rgba(0,0,0,0.2);
120
+ }
121
+
122
+ .stats-card {
123
+ background: white;
124
+ border-radius: 16px;
125
+ padding: 20px;
126
+ box-shadow: 0 4px 12px rgba(0,0,0,0.08);
127
+ }
128
+
129
+ .progress-bar {
130
+ height: 12px;
131
+ border-radius: 6px;
132
+ overflow: hidden;
133
+ background: #e0e0e0;
134
+ }
135
+
136
+ .progress-fill {
137
+ height: 100%;
138
+ border-radius: 6px;
139
+ transition: width 0.5s ease;
140
+ }
141
+
142
+ .firework {
143
+ position: absolute;
144
+ width: 5px;
145
+ height: 5px;
146
+ border-radius: 50%;
147
+ pointer-events: none;
148
+ }
149
+
150
+ .sidebar {
151
+ transition: transform 0.3s ease;
152
+ }
153
+
154
+ /* SortableJS ghost placeholder */
155
+ .sortable-ghost {
156
+ opacity: 0.4;
157
+ transform: rotate(3deg);
158
+ }
159
+
160
+ @media (max-width: 1024px) {
161
+ .canvas-grid {
162
+ display: grid;
163
+ grid-template-columns: repeat(3, 1fr);
164
+ grid-template-rows: repeat(5, 1fr);
165
+ height: 70vh;
166
+ }
167
+ }
168
+
169
+ @media (max-width: 768px) {
170
+ .canvas-grid {
171
+ display: grid;
172
+ grid-template-columns: repeat(2, 1fr);
173
+ grid-template-rows: repeat(8, 1fr);
174
+ height: 100vh;
175
+ }
176
+
177
+ .main-container {
178
+ flex-direction: column;
179
+ }
180
+
181
+ .sidebar {
182
+ width: 100% !important;
183
+ transform: translateX(100%);
184
+ }
185
+
186
+ .sidebar.open {
187
+ transform: translateX(0);
188
+ }
189
+ }
190
+ </style>
191
+ </head>
192
+ <body class="bg-gradient-to-br from-indigo-50 to-purple-100 min-h-screen p-4">
193
+ <div class="max-w-7xl mx-auto">
194
+ <!-- Header -->
195
+ <header class="text-center mb-8">
196
+ <h1 class="text-4xl md:text-5xl font-bold text-indigo-800 mb-2">Business Model Canvas Game</h1>
197
+ <p class="text-lg text-indigo-600 max-w-3xl mx-auto">Strategize, simulate, and succeed! Build your business model and see the financial impact in real-time.</p>
198
+ </header>
199
+
200
+ <!-- Main Game Area -->
201
+ <div class="flex flex-col lg:flex-row gap-6">
202
+ <!-- Canvas Area -->
203
+ <div class="flex-1">
204
+ <div class="bg-white rounded-2xl shadow-xl p-4 mb-6">
205
+ <div class="flex justify-between items-center mb-4">
206
+ <h2 class="text-xl font-bold text-gray-800">Business Model Canvas</h2>
207
+ <div class="flex gap-2">
208
+ <button id="resetBtn" class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg transition-all">
209
+ <i class="fas fa-sync-alt mr-2"></i>Reset
210
+ </button>
211
+ <button id="tutorialBtn" class="px-4 py-2 bg-indigo-100 hover:bg-indigo-200 text-indigo-700 rounded-lg transition-all">
212
+ <i class="fas fa-question-circle mr-2"></i>Tutorial
213
+ </button>
214
+ </div>
215
+ </div>
216
+ <div class="canvas-grid"></div>
217
+ </div>
218
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
219
+ <div class="stats-card">
220
+ <div class="flex justify-between mb-2">
221
+ <span class="font-semibold text-gray-600">Revenue</span>
222
+ <span id="revenueValue" class="font-bold text-green-600">$100,000</span>
223
+ </div>
224
+ <div class="progress-bar">
225
+ <div id="revenueBar" class="progress-fill bg-green-500" style="width: 100%"></div>
226
+ </div>
227
+ </div>
228
+ <div class="stats-card">
229
+ <div class="flex justify-between mb-2">
230
+ <span class="font-semibold text-gray-600">Cost</span>
231
+ <span id="costValue" class="font-bold text-red-600">$50,000</span>
232
+ </div>
233
+ <div class="progress-bar">
234
+ <div id="costBar" class="progress-fill bg-red-500" style="width: 50%"></div>
235
+ </div>
236
+ </div>
237
+ <div class="stats-card">
238
+ <div class="flex justify-between mb-2">
239
+ <span class="font-semibold text-gray-600">Profit</span>
240
+ <span id="profitValue" class="font-bold text-blue-600">$50,000</span>
241
+ </div>
242
+ <div class="progress-bar">
243
+ <div id="profitBar" class="progress-fill bg-blue-500" style="width: 50%"></div>
244
+ </div>
245
+ </div>
246
+ <div class="stats-card">
247
+ <div class="flex justify-between mb-2">
248
+ <span class="font-semibold text-gray-600">Margin</span>
249
+ <span id="marginValue" class="font-bold text-purple-600">50%</span>
250
+ </div>
251
+ <div class="progress-bar">
252
+ <div id="marginBar" class="progress-fill bg-purple-500" style="width: 50%"></div>
253
+ </div>
254
+ </div>
255
+ </div>
256
+ </div>
257
+
258
+ <!-- Sidebar -->
259
+ <div class="w-full lg:w-80 flex flex-col gap-6">
260
+ <div class="bg-white rounded-2xl shadow-xl p-4">
261
+ <h2 class="text-xl font-bold text-gray-800 mb-4">Mini-Cube Config</h2>
262
+ <div class="mb-4">
263
+ <label class="block text-sm font-medium text-gray-700 mb-1">Create New Segment</label>
264
+ <div class="flex gap-2">
265
+ <input id="cubeLabel" type="text" placeholder="Segment Name" class="flex-1 px-3 py-2 border border-gray-300 rounded-lg"/>
266
+ <button id="addCubeBtn" class="px-3 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
267
+ <i class="fas fa-plus"></i>
268
+ </button>
269
+ </div>
270
+ </div>
271
+ <div class="mb-4">
272
+ <label class="block text-sm font-medium text-gray-700 mb-1">Cube Impact</label>
273
+ <div class="space-y-3">
274
+ <div>
275
+ <span class="text-xs text-gray-500">Base Impact (%)</span>
276
+ <input id="cubeValue" type="range" min="-30" max="30" value="10" class="w-full"/>
277
+ <div class="flex justify-between text-xs text-gray-500">
278
+ <span>-30%</span>
279
+ <span id="cubeValueDisplay">+10%</span>
280
+ <span>+30%</span>
281
+ </div>
282
+ </div>
283
+ <div>
284
+ <span class="text-xs text-gray-500">Impact Type</span>
285
+ <select id="cubeImpactType" class="w-full px-3 py-2 border border-gray-300 rounded-lg">
286
+ <option value="direct">Direct (this block only)</option>
287
+ <option value="adjacent">Adjacent (neighbors)</option>
288
+ <option value="global">Global (all blocks)</option>
289
+ </select>
290
+ </div>
291
+ <div>
292
+ <span class="text-xs text-gray-500">Multiplier Effect</span>
293
+ <input id="cubeMultiplier" type="range" min="1" max="5" value="1" step="0.1" class="w-full"/>
294
+ <div class="flex justify-between text-xs text-gray-500">
295
+ <span>1x</span>
296
+ <span id="cubeMultiplierDisplay">1x</span>
297
+ <span>5x</span>
298
+ </div>
299
+ </div>
300
+ </div>
301
+ </div>
302
+ <div>
303
+ <h3 class="font-medium text-gray-700 mb-2">Your Cubes</h3>
304
+ <div id="cubePalette" class="cube-container"></div>
305
+ </div>
306
+ </div>
307
+ <div class="bg-white rounded-2xl shadow-xl p-4">
308
+ <h2 class="text-xl font-bold text-gray-800 mb-4">Financial Performance</h2>
309
+ <canvas id="financeChart" height="250"></canvas>
310
+ </div>
311
+ </div>
312
+ </div>
313
+
314
+ <div class="bg-white rounded-2xl shadow-xl p-4 mt-6">
315
+ <h2 class="text-xl font-bold text-gray-800 mb-4">Active Interactions</h2>
316
+ <div id="rulesContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
317
+ <!-- Dynamic rules appear here -->
318
+ </div>
319
+ </div>
320
+ </div>
321
+
322
+ <!-- Tutorial Modal -->
323
+ <div id="tutorialModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
324
+ <div class="bg-white rounded-2xl shadow-2xl p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto">
325
+ <div class="flex justify-between items-center mb-4">
326
+ <h3 class="text-2xl font-bold text-indigo-800">How to Play</h3>
327
+ <button id="closeTutorial" class="text-gray-500 hover:text-gray-700">
328
+ <i class="fas fa-times text-2xl"></i>
329
+ </button>
330
+ </div>
331
+ <div class="space-y-4">
332
+ <div><h4 class="font-bold text-lg text-gray-800 mb-2">1. Canvas Blocks</h4><p class="text-gray-600">Click any block to activate it.</p></div>
333
+ <div><h4 class="font-bold text-lg text-gray-800 mb-2">2. Mini-Cubes</h4><p class="text-gray-600">Create cubes and drag onto blocks to apply effects.</p></div>
334
+ <div><h4 class="font-bold text-lg text-gray-800 mb-2">3. Financial Impact</h4><p class="text-gray-600">Watch real-time updates to revenue, cost, profit, and margin.</p></div>
335
+ <div><h4 class="font-bold text-lg text-gray-800 mb-2">4. Special Interactions</h4><p class="text-gray-600">Combine blocks and cubes for synergies.</p></div>
336
+ <div><h4 class="font-bold text-lg text-gray-800 mb-2">5. Level Up</h4><p class="text-gray-600">Hit >25% margin or investor milestones for bonuses!</p></div>
337
+ <div class="pt-4"><button id="startPlayingBtn" class="w-full py-3 bg-indigo-600 text-white font-bold rounded-lg hover:bg-indigo-700">Start Playing</button></div>
338
+ </div>
339
+ </div>
340
+ </div>
341
+
342
+ <script>
343
+ // ---------- Data & State ----------
344
+ const canvasBlocks = [
345
+ { id: 1, title: "Customer Segments", color: "var(--customer-segments)", active:false, cubeCount: 0 },
346
+ { id: 2, title: "Value Propositions", color: "var(--value-propositions)", active:false, cubeCount: 0 },
347
+ { id: 3, title: "Channels", color: "var(--channels)", active:false, cubeCount: 0 },
348
+ { id: 4, title: "Customer Relationships", color: "var(--customer-relationships)", active:false, cubeCount: 0 },
349
+ { id: 5, title: "Revenue Streams", color: "var(--revenue-streams)", active:false, cubeCount: 0 },
350
+ { id: 6, title: "Key Resources", color: "var(--key-resources)", active:false, cubeCount: 0 },
351
+ { id: 7, title: "Key Activities", color: "var(--key-activities)", active:false, cubeCount: 0 },
352
+ { id: 8, title: "Key Partnerships", color: "var(--key-partnerships)", active:false, cubeCount: 0 },
353
+ { id: 9, title: "Cost Structure", color: "var(--cost-structure)", active:false, cubeCount: 0 }
354
+ ];
355
+ const base = { revenue:100000, cost:50000 };
356
+ const cubePresets = [
357
+ { label:"Segment 1", baseValue:0.10, impactType:"direct", multiplier:1, color:"#10B981" },
358
+ { label:"Segment 2", baseValue:0.15, impactType:"direct", multiplier:1, color:"#3B82F6" },
359
+ { label:"Segment 3", baseValue:0.08, impactType:"direct", multiplier:1, color:"#EC4899" }
360
+ ];
361
+ const rules = [
362
+ { condition:(blocks)=>false, effect:()=>({}), message:"" }
363
+ ];
364
+ let state = {
365
+ blocks: JSON.parse(JSON.stringify(canvasBlocks)),
366
+ cubes: JSON.parse(JSON.stringify(cubePresets)),
367
+ appliedCubes: [],
368
+ revenue: base.revenue,
369
+ cost: base.cost,
370
+ profit: base.revenue-base.cost,
371
+ margin: (base.revenue-base.cost)/base.revenue,
372
+ activeRules: [],
373
+ levelUp:false
374
+ };
375
+
376
+ // ---------- Rendering & Logic ----------
377
+ const canvasGrid = document.querySelector('.canvas-grid');
378
+ const cubePalette = document.getElementById('cubePalette');
379
+ const cubeValue = document.getElementById('cubeValue');
380
+ const cubeValueDisplay = document.getElementById('cubeValueDisplay');
381
+ const cubeImpactType = document.getElementById('cubeImpactType');
382
+ const cubeMultiplier = document.getElementById('cubeMultiplier');
383
+ const cubeMultiplierDisplay = document.getElementById('cubeMultiplierDisplay');
384
+ document.getElementById('addCubeBtn').addEventListener('click', createCube);
385
+ document.getElementById('resetBtn').addEventListener('click', resetGame);
386
+ document.getElementById('tutorialBtn').addEventListener('click', ()=>tutorialModal.classList.remove('hidden'));
387
+ document.getElementById('closeTutorial').addEventListener('click', ()=>tutorialModal.classList.add('hidden'));
388
+ document.getElementById('startPlayingBtn').addEventListener('click', ()=>tutorialModal.classList.add('hidden'));
389
+ cubeValue.addEventListener('input', ()=> cubeValueDisplay.textContent = `${cubeValue.value>=0?'+':''}${cubeValue.value}%`);
390
+ cubeMultiplier.addEventListener('input', ()=> cubeMultiplierDisplay.textContent = `${cubeMultiplier.value}x`);
391
+
392
+ function initGame(){
393
+ renderCanvasBlocks();
394
+ renderCubePalette();
395
+ setupDragDrop();
396
+ setupSortable();
397
+ updateFinancials();
398
+ renderFinanceChart();
399
+ if(!localStorage.getItem('bmcVisited')){
400
+ tutorialModal.classList.remove('hidden');
401
+ localStorage.setItem('bmcVisited','true');
402
+ }
403
+ }
404
+
405
+ function renderCanvasBlocks(){
406
+ canvasGrid.innerHTML='';
407
+ state.blocks.forEach(b=>{
408
+ const el=document.createElement('div');
409
+ el.className=`canvas-block ${b.active?'active':''}`;
410
+ el.style.backgroundColor=`${b.color}20`;
411
+ el.style.border=`2px solid ${b.color}`;
412
+ el.dataset.id=b.id;
413
+ el.innerHTML=`
414
+ <div class="canvas-block-header">
415
+ <span>${b.title}</span>
416
+ <span class="text-xs text-gray-500">${b.cubeCount} items</span>
417
+ </div>
418
+ <div class="canvas-block-content"></div>
419
+ `;
420
+ el.querySelector('.canvas-block-content').append(...state.appliedCubes
421
+ .filter(c=>c.blockId===b.id)
422
+ .map(cube=>{
423
+ const ce=document.createElement('div');
424
+ ce.className='cube';
425
+ ce.style.borderLeft=`4px solid ${cube.color}`;
426
+ ce.innerHTML=`${cube.label}<span class="text-xs text-gray-500 ml-2">${cube.value>0?'+':''}${Math.round(cube.value*100)}%</span>`;
427
+ return ce;
428
+ })
429
+ );
430
+ el.addEventListener('click',()=>toggleBlock(b.id));
431
+ canvasGrid.append(el);
432
+ });
433
+ }
434
+
435
+ function renderCubePalette(){
436
+ cubePalette.innerHTML='';
437
+ state.cubes.forEach((c,i)=>{
438
+ const el=document.createElement('div');
439
+ el.className='cube';
440
+ el.style.background=c.color;
441
+ el.style.color=getContrastColor(c.color);
442
+ el.textContent=c.label;
443
+ el.draggable=true;
444
+ el.dataset.index=i;
445
+ el.addEventListener('dragstart',dragStart);
446
+ el.addEventListener('dragend',dragEnd);
447
+ cubePalette.append(el);
448
+ });
449
+ }
450
+
451
+ function toggleBlock(id){
452
+ const b=state.blocks.find(x=>x.id===id);
453
+ b.active=!b.active;
454
+ updateFinancials(); checkRules(); renderCanvasBlocks();
455
+ }
456
+
457
+ function dragStart(e){
458
+ e.target.classList.add('dragging');
459
+ const i=+e.target.dataset.index, c=state.cubes[i];
460
+ e.dataTransfer.setData('application/json',JSON.stringify({i,label:c.label,color:c.color,value:c.baseValue,impactType:c.impactType,multiplier:c.multiplier}));
461
+ e.dataTransfer.effectAllowed='copy';
462
+ }
463
+ function dragEnd(e){ e.target.classList.remove('dragging'); }
464
+
465
+ function setupDragDrop(){
466
+ document.querySelectorAll('.canvas-block').forEach(block=>{
467
+ block.ondragover=e=>{e.preventDefault(); block.style.boxShadow=`0 0 10px ${block.style.borderColor}`;};
468
+ block.ondragleave=_=>block.style.boxShadow='';
469
+ block.ondrop=e=>{
470
+ e.preventDefault(); block.style.boxShadow='';
471
+ try{
472
+ const data=JSON.parse(e.dataTransfer.getData('application/json'));
473
+ applyCubeToBlock(data, +block.dataset.id);
474
+ }catch{}
475
+ };
476
+ });
477
+ }
478
+
479
+ function applyCubeToBlock(c,blockId){
480
+ const cube={...c,blockId,id:Date.now()};
481
+ cube.impacts={
482
+ direct:c.value*c.multiplier,
483
+ adjacent:c.value*c.multiplier*0.5,
484
+ global:c.value*c.multiplier*0.2
485
+ };
486
+ state.appliedCubes.push(cube);
487
+ updateFinancials(); checkRules(); renderCanvasBlocks();
488
+ animateDrop(blockId,c.color);
489
+ if(state.margin>0.25&&!state.levelUp){ state.levelUp=true; triggerLevelUp(); }
490
+ }
491
+
492
+ function animateDrop(blockId,color){
493
+ const el=document.querySelector(`.canvas-block[data-id="${blockId}"]`);
494
+ el.animate([{transform:'scale(1)',boxShadow:`0 0 0 0 ${color}`},{transform:'scale(1.05)',boxShadow:`0 0 20px 10px ${color}`},{transform:'scale(1)',boxShadow:`0 0 0 0 ${color}`}],{duration:800});
495
+ }
496
+
497
+ function updateFinancials(){
498
+ let rev=base.revenue, cost=base.cost;
499
+ state.blocks.forEach(b=>b.cubeCount=0);
500
+ state.appliedCubes.forEach(c=>{
501
+ const b=state.blocks.find(x=>x.id===c.blockId);
502
+ if(!b) return;
503
+ b.cubeCount++;
504
+ // direct
505
+ if(c.impactType==='direct') rev+=rev*c.impacts.direct;
506
+ // adjacent (example: seg→valprop)
507
+ if(c.impactType==='adjacent'&&c.blockId===1){
508
+ rev+=rev*c.impacts.adjacent;
509
+ }
510
+ // global
511
+ if(c.impactType==='global'){
512
+ rev+=rev*c.impacts.global*(state.blocks.length-1);
513
+ }
514
+ });
515
+ // rules
516
+ state.activeRules.forEach(r=>{
517
+ if(r.effect.revenueImpact) rev+=rev*r.effect.revenueImpact;
518
+ if(r.effect.costImpact) cost+=cost*r.effect.costImpact;
519
+ });
520
+ const profit=rev-cost, margin=profit/rev;
521
+ state.revenue=rev; state.cost=cost; state.profit=profit; state.margin=margin;
522
+ updateFinancialUI();
523
+ }
524
+
525
+ function updateFinancialUI(){
526
+ document.getElementById('revenueValue').textContent=`$${formatNumber(state.revenue)}`;
527
+ document.getElementById('costValue').textContent=`$${formatNumber(state.cost)}`;
528
+ document.getElementById('profitValue').textContent=`$${formatNumber(state.profit)}`;
529
+ document.getElementById('marginValue').textContent=`${Math.round(state.margin*100)}%`;
530
+ document.getElementById('costBar').style.width=`${(state.cost/state.revenue)*100}%`;
531
+ document.getElementById('profitBar').style.width=`${(state.profit/state.revenue)*100}%`;
532
+ document.getElementById('marginBar').style.width=`${state.margin*100}%`;
533
+ updateFinanceChart();
534
+ }
535
+
536
+ function checkRules(){
537
+ state.activeRules=[];
538
+ rules.forEach(r=>{ if(r.condition(state.blocks,state.appliedCubes)) state.activeRules.push(r); });
539
+ renderRules();
540
+ }
541
+
542
+ function renderRules(){
543
+ const c=document.getElementById('rulesContainer');
544
+ c.innerHTML='';
545
+ if(state.activeRules.length===0){
546
+ c.innerHTML=`<div class="text-center py-4 text-gray-500"><i class="fas fa-info-circle text-xl mb-2"></i><p>Activate blocks & apply cubes to see interactions.</p></div>`;
547
+ } else {
548
+ state.activeRules.forEach(r=>{
549
+ const el=document.createElement('div');
550
+ el.className='bg-indigo-50 border-l-4 border-indigo-500 p-3 rounded-lg';
551
+ el.innerHTML=`<div class="flex items-start"><i class="fas fa-bolt text-indigo-500 mt-1"></i><p class="ml-3 text-sm text-indigo-700">${r.message}</p></div>`;
552
+ c.append(el);
553
+ });
554
+ }
555
+ }
556
+
557
+ function createCube(){
558
+ const label=document.getElementById('cubeLabel').value.trim();
559
+ if(!label) return;
560
+ const baseValue=+document.getElementById('cubeValue').value/100;
561
+ const impactType=document.getElementById('cubeImpactType').value;
562
+ const multiplier=+document.getElementById('cubeMultiplier').value;
563
+ const newCube={label,baseValue,impactType,multiplier,color:getRandomColor()};
564
+ state.cubes.push(newCube);
565
+ renderCubePalette();
566
+ document.getElementById('cubeLabel').value='';
567
+ document.getElementById('cubeValue').value='10';
568
+ cubeValueDisplay.textContent='+10%';
569
+ document.getElementById('cubeMultiplier').value='1';
570
+ cubeMultiplierDisplay.textContent='1x';
571
+ }
572
+
573
+ function resetGame(){
574
+ state.blocks=JSON.parse(JSON.stringify(canvasBlocks));
575
+ state.cubes=JSON.parse(JSON.stringify(cubePresets));
576
+ state.appliedCubes=[];
577
+ state.activeRules=[];
578
+ state.levelUp=false;
579
+ renderCanvasBlocks(); renderCubePalette(); renderRules(); updateFinancials(); setupDragDrop(); setupSortable();
580
+ }
581
+
582
+ function triggerLevelUp(){
583
+ for(let i=0;i<30;i++) setTimeout(createFirework,i*100);
584
+ const confettiCount=150;
585
+ for(let i=0;i<confettiCount;i++){
586
+ const conf=document.createElement('div');
587
+ conf.className='confetti';
588
+ conf.style.left=`${Math.random()*100}%`;
589
+ conf.style.top='-20px';
590
+ conf.style.backgroundColor=`hsl(${Math.random()*360},100%,50%)`;
591
+ conf.style.width=`${Math.random()*10+5}px`;
592
+ conf.style.height=`${Math.random()*10+5}px`;
593
+ document.body.append(conf);
594
+ anime({targets:conf,translateY:window.innerHeight+50,rotate:Math.random()*360,duration:Math.random()*3000+2000,easing:'easeInOutQuad',complete:()=>conf.remove()});
595
+ }
596
+ const msg=document.createElement('div');
597
+ msg.className='fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-4xl font-bold text-white bg-gradient-to-r from-indigo-600 to-purple-600 px-8 py-6 rounded-2xl shadow-2xl z-50';
598
+ msg.textContent='Level Up! Margin > 25%';
599
+ document.body.append(msg);
600
+ setTimeout(()=>msg.remove(),3000);
601
+ }
602
+
603
+ function createFirework(){
604
+ const colors=['#FF5252','#FFD700','#4CAF50','#2196F3','#9C27B0','#FF9800'];
605
+ const f=document.createElement('div');
606
+ f.className='firework';
607
+ f.style.left=`${Math.random()*90+5}%`;
608
+ f.style.top=`${Math.random()*90+5}%`;
609
+ f.style.backgroundColor=colors[Math.floor(Math.random()*colors.length)];
610
+ document.body.append(f);
611
+ anime({targets:f,scale:[0,20],opacity:[1,0],duration:1000,easing:'easeOutExpo',complete:()=>f.remove()});
612
+ }
613
+
614
+ // Chart
615
+ let financeChart;
616
+ function renderFinanceChart(){
617
+ const ctx=document.getElementById('financeChart').getContext('2d');
618
+ financeChart=new Chart(ctx,{type:'line',data:{
619
+ labels:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
620
+ datasets:[
621
+ {label:'Revenue',data:Array(12).fill(base.revenue),borderColor:'#10B981',backgroundColor:'rgba(16,185,129,0.1)',tension:0.3,fill:true},
622
+ {label:'Cost',data:Array(12).fill(base.cost),borderColor:'#EF4444',backgroundColor:'rgba(239,68,68,0.1)',tension:0.3,fill:true},
623
+ {label:'Profit',data:Array(12).fill(base.revenue-base.cost),borderColor:'#3B82F6',backgroundColor:'rgba(59,130,246,0.1)',tension:0.3,fill:true}
624
+ ]
625
+ },options:{
626
+ responsive:true,maintainAspectRatio:false,plugins:{legend:{position:'top'},tooltip:{mode:'index',intersect:false}},scales:{y:{beginAtZero:true,ticks:{callback:v=>'$'+v.toLocaleString()}}}
627
+ }});
628
+ }
629
+
630
+ function updateFinanceChart(){
631
+ if(!financeChart) return;
632
+ const m=12;
633
+ financeChart.data.datasets[0].data=Array(m).fill().map((_,i)=>base.revenue+(state.revenue-base.revenue)*(i/(m-1)));
634
+ financeChart.data.datasets[1].data=Array(m).fill().map((_,i)=>base.cost+(state.cost-base.cost)*(i/(m-1)));
635
+ financeChart.data.datasets[2].data=financeChart.data.datasets[0].data.map((r,i)=>r-financeChart.data.datasets[1].data[i]);
636
+ financeChart.update();
637
+ }
638
+
639
+ // SortableJS setup
640
+ function setupSortable(){
641
+ Sortable.create(document.querySelector('.canvas-grid'),{
642
+ animation:150,
643
+ ghostClass:'sortable-ghost',
644
+ handle:'.canvas-block-header',
645
+ onEnd:()=> {
646
+ const newOrder=[...document.querySelectorAll('.canvas-block')].map(el=>+el.dataset.id);
647
+ state.blocks=newOrder.map(id=>state.blocks.find(b=>b.id===id));
648
+ }
649
+ });
650
+ Sortable.create(document.getElementById('cubePalette'),{
651
+ animation:150,
652
+ ghostClass:'sortable-ghost',
653
+ handle:'.cube',
654
+ onEnd:({oldIndex,newIndex})=>{
655
+ state.cubes.splice(newIndex,0,state.cubes.splice(oldIndex,1)[0]);
656
+ }
657
+ });
658
+ }
659
+
660
+ // Helpers
661
+ function formatNumber(n){return n.toLocaleString('en-US',{maximumFractionDigits:0});}
662
+ function getRandomColor(){const cs=['#EF4444','#F59E0B','#10B981','#3B82F6','#6366F1','#8B5CF6','#EC4899','#06B6D4'];return cs[Math.floor(Math.random()*cs.length)];}
663
+ function getContrastColor(h){const r=parseInt(h.substr(1,2),16),g=parseInt(h.substr(3,2),16),b=parseInt(h.substr(5,2),16);return((0.299*r+0.587*g+0.114*b)/255)>0.5?'#000':'#fff';}
664
+
665
+ document.addEventListener('DOMContentLoaded',initGame);
666
+ </script>
667
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=web3district/businessmodelreactable" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
668
+ </html>