File size: 25,172 Bytes
ecb998b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Binary MLM Tree Viewer Mockup</title>
    <style>
        :root {
            --primary: #3B82F6;
            --secondary: #8B5CF6;
            --accent: #10B981;
            --danger: #EF4444;
            --warning: #F59E0B;
            --bg-main: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --bg-card: rgba(255, 255, 255, 0.25);
            --bg-card-hover: rgba(255, 255, 255, 0.4);
            --text-primary: #1F2937;
            --text-secondary: #6B7280;
            --border-color: rgba(255, 255, 255, 0.3);
            --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
            --blur: blur(12px);
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: var(--bg-main);
            background-attachment: fixed;
            color: var(--text-primary);
            overflow: hidden;
            height: 100vh;
            padding: 20px;
        }

        .container {
            display: flex;
            flex-direction: column;
            height: calc(100vh - 40px);
            background: rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            backdrop-filter: var(--blur);
            -webkit-backdrop-filter: var(--blur);
            border: 1px solid var(--border-color);
            box-shadow: var(--shadow);
            overflow: hidden;
        }

        header {
            background: rgba(255, 255, 255, 0.15);
            padding: 20px 30px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        h1 {
            font-size: 28px;
            font-weight: 700;
            background: linear-gradient(45deg, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .controls {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }

        button {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-primary);
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 5px;
        }

        button:hover {
            background: var(--bg-card-hover);
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }

        button:active {
            transform: translateY(0);
        }

        .tree-container {
            flex: 1;
            overflow-x: auto;
            overflow-y: auto;
            padding: 30px;
            position: relative;
        }

        .tree-container::-webkit-scrollbar {
            height: 8px;
            width: 8px;
        }

        .tree-container::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
        }

        .tree-container::-webkit-scrollbar-thumb {
            background: linear-gradient(45deg, var(--primary), var(--secondary));
            border-radius: 10px;
        }

        .tree {
            display: inline-block;
            min-width: 100%;
            transform-origin: center top;
            transition: transform 0.3s ease;
        }

        .node-wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
            padding: 10px 20px;
        }

        .node {
            background: var(--bg-card);
            backdrop-filter: var(--blur);
            -webkit-backdrop-filter: var(--blur);
            border: 1px solid var(--border-color);
            border-radius: 15px;
            padding: 15px;
            box-shadow: var(--shadow);
            transition: var(--transition);
            cursor: pointer;
            position: relative;
            min-width: 180px;
            max-width: 220px;
            z-index: 2;
        }

        .node:hover {
            transform: translateY(-5px);
            background: var(--bg-card-hover);
            box-shadow: 0 12px 40px rgba(31, 38, 135, 0.5);
        }

        .node-header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 10px;
        }

        .avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            object-fit: cover;
            border: 2px solid var(--border-color);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .node-info h3 {
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
            line-height: 1.2;
        }

        .node-info .position {
            font-size: 12px;
            font-weight: 600;
            color: var(--secondary);
            background: rgba(139, 92, 246, 0.2);
            padding: 2px 8px;
            border-radius: 6px;
            display: inline-block;
            margin-top: 3px;
        }

        .scores {
            display: flex;
            justify-content: space-between;
            gap: 10px;
            margin-top: 10px;
        }

        .score-box {
            flex: 1;
            text-align: center;
            padding: 8px;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid var(--border-color);
        }

        .score-box.left {
            background: rgba(59, 130, 246, 0.15);
            border-color: rgba(59, 130, 246, 0.3);
        }

        .score-box.right {
            background: rgba(139, 92, 246, 0.15);
            border-color: rgba(139, 92, 246, 0.3);
        }

        .score-label {
            font-size: 10px;
            color: var(--text-secondary);
            text-transform: uppercase;
            font-weight: 600;
        }

        .score-value {
            font-size: 14px;
            font-weight: 700;
            color: var(--text-primary);
        }

        .toggle-btn {
            position: absolute;
            top: -8px;
            right: -8px;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background: var(--primary);
            color: white;
            border: 2px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: bold;
            cursor: pointer;
            transition: var(--transition);
            z-index: 3;
        }

        .toggle-btn:hover {
            background: var(--secondary);
            transform: scale(1.1);
        }

        .children {
            display: flex;
            justify-content: center;
            gap: 40px;
            margin-top: 40px;
            position: relative;
            transition: var(--transition);
        }

        .children.collapsed {
            display: none;
        }

        .children::before {
            content: '';
            position: absolute;
            top: -20px;
            left: 50%;
            transform: translateX(-50%);
            width: 2px;
            height: 20px;
            background: linear-gradient(to bottom, var(--primary), var(--secondary));
            opacity: 0.6;
        }

        .child-wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
        }

        .child-wrapper::before {
            content: '';
            position: absolute;
            top: -20px;
            width: 50%;
            height: 2px;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            opacity: 0.6;
        }

        .child-wrapper.left::before {
            right: 0;
        }

        .child-wrapper.right::before {
            left: 0;
        }

        .tooltip {
            position: fixed;
            background: rgba(0, 0, 0, 0.9);
            color: white;
            padding: 10px 15px;
            border-radius: 8px;
            font-size: 12px;
            z-index: 1000;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.3s;
            max-width: 250px;
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .tooltip.visible {
            opacity: 1;
        }

        @media (max-width: 768px) {
            header {
                padding: 15px 20px;
            }

            h1 {
                font-size: 22px;
            }

            button {
                padding: 8px 15px;
                font-size: 13px;
            }

            .node {
                min-width: 150px;
                padding: 12px;
            }

            .avatar {
                width: 40px;
                height: 40px;
            }

            .node-info h3 {
                font-size: 14px;
            }

            .children {
                gap: 20px;
            }
        }

        @media (max-width: 480px) {
            body {
                padding: 10px;
            }

            .container {
                height: calc(100vh - 20px);
            }

            .tree-container {
                padding: 15px;
            }

            .node {
                min-width: 130px;
                padding: 10px;
            }

            .avatar {
                width: 35px;
                height: 35px;
            }

            .node-info h3 {
                font-size: 13px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>Binary MLM Tree Viewer</h1>
            <div class="controls">
                <button id="zoomOut">βˆ’ Zoom Out</button>
                <button id="zoomIn">+ Zoom In</button>
                <button id="expandAll">πŸ“‚ Expand All</button>
                <button id="collapseAll">πŸ“ Collapse All</button>
            </div>
        </header>
        <div class="tree-container" id="treeContainer">
            <div class="tree" id="tree"></div>
        </div>
    </div>
    <div class="tooltip" id="tooltip"></div>

    <script>
        // Mock Data
        const mockData = [
            { id: 1, parentId: null, side: null, name: "Tony Stark", position: "Diamond", avatarUrl: "https://static.photos/technology/200x200/1", scoreLeft: 15500, scoreRight: 22500, isExpanded: true, details: "Joined: 2024/01/01 | Total: 38,000 PV | Team Size: 2,450" },
            { id: 2, parentId: 1, side: "L", name: "Steve Rogers", position: "Platinum", avatarUrl: "https://static.photos/people/200x200/2", scoreLeft: 8500, scoreRight: 12000, isExpanded: true, details: "Joined: 2024/02/15 | Total: 20,500 PV | Team Size: 1,200" },
            { id: 3, parentId: 1, side: "R", name: "Bruce Banner", position: "Platinum", avatarUrl: "https://static.photos/science/200x200/3", scoreLeft: 7000, scoreRight: 10500, isExpanded: true, details: "Joined: 2024/03/10 | Total: 17,500 PV | Team Size: 1,050" },
            { id: 4, parentId: 2, side: "L", name: "Natasha Romanoff", position: "Gold", avatarUrl: "https://static.photos/people/200x200/4", scoreLeft: 4500, scoreRight: 3800, isExpanded: true, details: "Joined: 2024/04/20 | Total: 8,300 PV | Team Size: 520" },
            { id: 5, parentId: 2, side: "R", name: "Clint Barton", position: "Gold", avatarUrl: "https://static.photos/outdoor/200x200/5", scoreLeft: 4000, scoreRight: 4200, isExpanded: true, details: "Joined: 2024/05/05 | Total: 8,200 PV | Team Size: 480" },
            { id: 6, parentId: 3, side: "L", name: "Thor Odinson", position: "Gold", avatarUrl: "https://static.photos/abstract/200x200/6", scoreLeft: 3200, scoreRight: 4500, isExpanded: true, details: "Joined: 2024/06/12 | Total: 7,700 PV | Team Size: 450" },
            { id: 7, parentId: 3, side: "R", name: "Loki Laufeyson", position: "Gold", avatarUrl: "https://static.photos/minimal/200x200/7", scoreLeft: 3800, scoreRight: 3000, isExpanded: true, details: "Joined: 2024/07/18 | Total: 6,800 PV | Team Size: 400" },
            { id: 8, parentId: 4, side: "L", name: "Peter Parker", position: "Silver", avatarUrl: "https://static.photos/people/200x200/8", scoreLeft: 2000, scoreRight: 1500, isExpanded: false, details: "Joined: 2024/08/25 | Total: 3,500 PV | Team Size: 180" },
            { id: 9, parentId: 4, side: "R", name: "Wanda Maximoff", position: "Silver", avatarUrl: "https://static.photos/abstract/200x200/9", scoreLeft: 1500, scoreRight: 1800, isExpanded: false, details: "Joined: 2024/09/10 | Total: 3,300 PV | Team Size: 165" },
            { id: 10, parentId: 5, side: "L", name: "Vision", position: "Silver", avatarUrl: "https://static.photos/technology/200x200/10", scoreLeft: 1800, scoreRight: 1700, isExpanded: false, details: "Joined: 2024/10/03 | Total: 3,500 PV | Team Size: 175" },
            { id: 11, parentId: 5, side: "R", name: "Sam Wilson", position: "Silver", avatarUrl: "https://static.photos/outdoor/200x200/11", scoreLeft: 1600, scoreRight: 1900, isExpanded: false, details: "Joined: 2024/11/15 | Total: 3,500 PV | Team Size: 170" },
            { id: 12, parentId: 6, side: "L", name: "Bucky Barnes", position: "Silver", avatarUrl: "https://static.photos/people/200x200/12", scoreLeft: 1400, scoreRight: 1300, isExpanded: false, details: "Joined: 2024/12/01 | Total: 2,700 PV | Team Size: 140" },
            { id: 13, parentId: 6, side: "R", name: "Carol Danvers", position: "Silver", avatarUrl: "https://static.photos/abstract/200x200/13", scoreLeft: 1100, scoreRight: 1600, isExpanded: false, details: "Joined: 2024/12/20 | Total: 2,700 PV | Team Size: 135" },
            { id: 14, parentId: 7, side: "L", name: "Scott Lang", position: "Silver", avatarUrl: "https://static.photos/minimal/200x200/14", scoreLeft: 1200, scoreRight: 1100, isExpanded: false, details: "Joined: 2025/01/05 | Total: 2,300 PV | Team Size: 125" },
            { id: 15, parentId: 7, side: "R", name: "Hope Van Dyne", position: "Silver", avatarUrl: "https://static.photos/people/200x200/15", scoreLeft: 1300, scoreRight: 1000, isExpanded: false, details: "Joined: 2025/01/18 | Total: 2,300 PV | Team Size: 120" },
            { id: 16, parentId: 8, side: "L", name: "Stephen Strange", position: "Bronze", avatarUrl: "https://static.photos/abstract/200x200/16", scoreLeft: 800, scoreRight: 600, isExpanded: false, details: "Joined: 2025/02/10 | Total: 1,400 PV | Team Size: 75" },
            { id: 17, parentId: 8, side: "R", name: "T'Challa", position: "Bronze", avatarUrl: "https://static.photos/nature/200x200/17", scoreLeft: 700, scoreRight: 700, isExpanded: false, details: "Joined: 2025/02/25 | Total: 1,400 PV | Team Size: 70" },
            { id: 18, parentId: 9, side: "L", name: "Shuri", position: "Bronze", avatarUrl: "https://static.photos/technology/200x200/18", scoreLeft: 600, scoreRight: 650, isExpanded: false, details: "Joined: 2025/03/08 | Total: 1,250 PV | Team Size: 65" },
            { id: 19, parentId: 9, side: "R", name: "Okoye", position: "Bronze", avatarUrl: "https://static.photos/people/200x200/19", scoreLeft: 550, scoreRight: 600, isExpanded: false, details: "Joined: 2025/03/20 | Total: 1,150 PV | Team Size: 60" },
            { id: 20, parentId: 10, side: "L", name: "M'Baku", position: "Bronze", avatarUrl: "https://static.photos/outdoor/200x200/20", scoreLeft: 500, scoreRight: 550, isExpanded: false, details: "Joined: 2025/04/02 | Total: 1,050 PV | Team Size: 55" }
        ];

        // State Management
        let zoomLevel = 1;
        const MIN_ZOOM = 0.5;
        const MAX_ZOOM = 2;
        const ZOOM_STEP = 0.1;

        // Utility Functions
        function formatNumber(num) {
            return num.toLocaleString();
        }

        function getPositionColor(position) {
            const colors = {
                "Diamond": "linear-gradient(45deg, #FFD700, #FFA500)",
                "Platinum": "linear-gradient(45deg, #E5E4E2, #C0C0C0)",
                "Gold": "linear-gradient(45deg, #FFD700, #FFA000)",
                "Silver": "linear-gradient(45deg, #C0C0C0, #A0A0A0)",
                "Bronze": "linear-gradient(45deg, #CD7F32, #A0522D)"
            };
            return colors[position] || "linear-gradient(45deg, #3B82F6, #8B5CF6)";
        }

        // Build Tree Structure
        function buildTree(nodeId) {
            const node = mockData.find(n => n.id === nodeId);
            if (!node) return null;

            const children = mockData.filter(n => n.parentId === nodeId);
            const leftChild = children.find(c => c.side === "L");
            const rightChild = children.find(c => c.side === "R");

            return {
                ...node,
                left: leftChild ? buildTree(leftChild.id) : null,
                right: rightChild ? buildTree(rightChild.id) : null
            };
        }

        // Create Node Element
        function createNodeElement(node) {
            const wrapper = document.createElement('div');
            wrapper.className = 'node-wrapper';

            const nodeDiv = document.createElement('div');
            nodeDiv.className = 'node';
            nodeDiv.dataset.nodeId = node.id;

            // Avatar and Info
            const hasChildren = node.left || node.right;
            nodeDiv.innerHTML = `
                ${hasChildren ? `<div class="toggle-btn">${node.isExpanded ? 'βˆ’' : '+'}</div>` : ''}
                <div class="node-header">
                    <img src="${node.avatarUrl}" alt="${node.name}" class="avatar" onerror="this.src='https://static.photos/people/200x200/1'">
                    <div class="node-info">
                        <h3>${node.name}</h3>
                        <span class="position" style="background: ${getPositionColor(node.position)}20; color: ${getPositionColor(node.position).match(/#[a-fA-F0-9]{6}/)[0]}">${node.position}</span>
                    </div>
                </div>
                <div class="scores">
                    <div class="score-box left">
                        <div class="score-label">Left</div>
                        <div class="score-value">${formatNumber(node.scoreLeft)}</div>
                    </div>
                    <div class="score-box right">
                        <div class="score-label">Right</div>
                        <div class="score-value">${formatNumber(node.scoreRight)}</div>
                    </div>
                </div>
            `;

            wrapper.appendChild(nodeDiv);

            // Children Container
            if (hasChildren) {
                const childrenDiv = document.createElement('div');
                childrenDiv.className = `children ${node.isExpanded ? '' : 'collapsed'}`;

                // Left Child
                if (node.left) {
                    const leftWrapper = document.createElement('div');
                    leftWrapper.className = 'child-wrapper left';
                    leftWrapper.appendChild(createNodeElement(node.left));
                    childrenDiv.appendChild(leftWrapper);
                }

                // Right Child
                if (node.right) {
                    const rightWrapper = document.createElement('div');
                    rightWrapper.className = 'child-wrapper right';
                    rightWrapper.appendChild(createNodeElement(node.right));
                    childrenDiv.appendChild(rightWrapper);
                }

                wrapper.appendChild(childrenDiv);
            }

            // Event Listeners
            nodeDiv.addEventListener('click', (e) => {
                if (e.target.classList.contains('toggle-btn')) {
                    e.stopPropagation();
                    toggleNode(node.id);
                }
            });

            nodeDiv.addEventListener('mouseenter', (e) => showTooltip(e, node));
            nodeDiv.addEventListener('mouseleave', hideTooltip);

            return wrapper;
        }

        // Toggle Node Expand/Collapse
        function toggleNode(nodeId) {
            const node = mockData.find(n => n.id === nodeId);
            if (node) {
                node.isExpanded = !node.isExpanded;
                renderTree();
            }
        }

        // Tooltip Functions
        function showTooltip(e, node) {
            const tooltip = document.getElementById('tooltip');
            tooltip.innerHTML = `
                <strong>${node.name}</strong><br>
                Position: ${node.position}<br>
                ${node.details}
            `;
            tooltip.classList.add('visible');
            updateTooltipPosition(e);
        }

        function hideTooltip() {
            const tooltip = document.getElementById('tooltip');
            tooltip.classList.remove('visible');
        }

        function updateTooltipPosition(e) {
            const tooltip = document.getElementById('tooltip');
            const rect = tooltip.getBoundingClientRect();
            let x = e.clientX;
            let y = e.clientY - rect.height - 10;

            if (x + rect.width > window.innerWidth) {
                x = window.innerWidth - rect.width - 10;
            }

            if (y < 10) {
                y = e.clientY + 10;
            }

            tooltip.style.left = x + 'px';
            tooltip.style.top = y + 'px';
        }

        // Zoom Functions
        function setZoom(level) {
            zoomLevel = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, level));
            const tree = document.getElementById('tree');
            tree.style.transform = `scale(${zoomLevel})`;
        }

        // Expand/Collapse All
        function expandAll(expand = true) {
            mockData.forEach(node => {
                const hasChildren = mockData.some(n => n.parentId === node.id);
                if (hasChildren) {
                    node.isExpanded = expand;
                }
            });
            renderTree();
        }

        // Render Tree
        function renderTree() {
            const treeContainer = document.getElementById('tree');
            treeContainer.innerHTML = '';
            const rootNode = mockData.find(n => n.parentId === null);
            if (rootNode) {
                const tree = buildTree(rootNode.id);
                treeContainer.appendChild(createNodeElement(tree));
            }
        }

        // Initialize
        document.addEventListener('DOMContentLoaded', () => {
            renderTree();

            // Zoom Controls
            document.getElementById('zoomIn').addEventListener('click', () => {
                setZoom(zoomLevel + ZOOM_STEP);
            });

            document.getElementById('zoomOut').addEventListener('click', () => {
                setZoom(zoomLevel - ZOOM_STEP);
            });

            // Expand/Collapse Controls
            document.getElementById('expandAll').addEventListener('click', () => expandAll(true));
            document.getElementById('collapseAll').addEventListener('click', () => expandAll(false));

            // Mouse move for tooltip
            document.addEventListener('mousemove', (e) => {
                const tooltip = document.getElementById('tooltip');
                if (tooltip.classList.contains('visible')) {
                    updateTooltipPosition(e);
                }
            });

            // Keyboard shortcuts
            document.addEventListener('keydown', (e) => {
                if (e.key === '+' || e.key === '=') {
                    setZoom(zoomLevel + ZOOM_STEP);
                } else if (e.key === '-') {
                    setZoom(zoomLevel - ZOOM_STEP);
                } else if (e.key === '0') {
                    setZoom(1);
                }
            });
        });

        // Update tree on window resize
        window.addEventListener('resize', () => {
            const treeContainer = document.getElementById('treeContainer');
            const tree = document.getElementById('tree');
            const containerWidth = treeContainer.clientWidth;
            const treeWidth = tree.scrollWidth * zoomLevel;
            
            if (treeWidth > containerWidth) {
                tree.style.transformOrigin = 'left top';
            } else {
                tree.style.transformOrigin = 'center top';
            }
        });
    </script>
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
</body>
</html>