File size: 53,734 Bytes
c887af6
 
 
 
 
da7c69a
c887af6
 
 
32d03a3
c887af6
da7c69a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32fcfd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c887af6
 
da7c69a
c887af6
da7c69a
c887af6
da7c69a
 
 
305204b
da7c69a
 
 
 
 
 
 
15bf25b
c887af6
 
 
da7c69a
 
 
 
c887af6
da7c69a
 
c887af6
 
 
 
 
da7c69a
 
c887af6
da7c69a
 
 
 
 
c887af6
da7c69a
 
 
 
c887af6
32fcfd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da7c69a
 
 
 
 
 
 
 
c887af6
da7c69a
 
 
 
 
 
 
 
 
 
c887af6
da7c69a
 
 
6b2c51b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f394cc
 
 
 
 
 
 
 
 
 
 
 
 
 
de20df8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da7c69a
 
 
 
 
 
 
c887af6
da7c69a
 
 
 
 
 
 
 
 
 
8f394cc
 
 
 
 
 
c887af6
da7c69a
 
c887af6
da7c69a
c887af6
 
 
 
da7c69a
 
 
c887af6
 
 
 
 
 
da7c69a
8f394cc
 
da7c69a
 
c887af6
8f394cc
da7c69a
 
8f394cc
c887af6
da7c69a
 
c887af6
 
 
 
 
da7c69a
c887af6
da7c69a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c887af6
6b2c51b
 
 
 
 
 
 
 
da7c69a
747b5b2
6b2c51b
 
 
 
747b5b2
 
 
 
 
da7c69a
 
 
 
c887af6
747b5b2
6b2c51b
c887af6
747b5b2
 
14f1f7e
8f394cc
fe6a4ea
da7c69a
747b5b2
c887af6
da7c69a
 
747b5b2
 
 
 
 
 
da7c69a
 
747b5b2
 
da7c69a
 
747b5b2
 
 
 
da7c69a
 
 
 
 
8f394cc
da7c69a
8f394cc
da7c69a
747b5b2
da7c69a
 
 
 
 
 
 
 
 
 
 
 
c887af6
8f394cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da7c69a
8f394cc
da7c69a
 
c887af6
 
da7c69a
 
8f394cc
 
 
c887af6
da7c69a
8f394cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c887af6
8f394cc
 
 
 
 
 
 
c887af6
32fcfd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe6a4ea
32fcfd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe6a4ea
32fcfd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de20df8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b2c51b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de20df8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32fcfd1
da7c69a
c887af6
 
 
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BeatFridge - Discover Music</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/lucide@latest"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="responsive.css">
    <style>
        * { font-family: 'Inter', sans-serif; }
        body { background-color: #0a0a0a; color: #ffffff; }
        ::-webkit-scrollbar { width: 8px; }
        ::-webkit-scrollbar-track { background: #0a0a0a; }
        ::-webkit-scrollbar-thumb { background: #2d2d2d; border-radius: 4px; }
        .glass { background: rgba(20,20,20,0.6); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.08); }
        .glass-panel { background: rgba(30,30,30,0.4); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,0.05); }
        .neon-text { background: linear-gradient(135deg, #00d4ff 0%, #7c3aed 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
        .track-card { transition: all 0.3s cubic-bezier(0.4,0,0.2,1); }
        .track-card:hover { transform: translateY(-4px); box-shadow: 0 20px 40px -10px rgba(0,212,255,0.15); }
        .play-btn-overlay { opacity: 0; transition: all 0.3s ease; }
        .track-card:hover .play-btn-overlay { opacity: 1; }
        .glow-cyan { box-shadow: 0 0 20px rgba(0,212,255,0.3); }
        .sticky-player { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; }
        .avatar-ring { box-shadow: 0 0 0 4px #0a0a0a, 0 0 0 6px rgba(0,212,255,0.5); }
        .artist-card { transition: all 0.3s ease; }
        .artist-card:hover { transform: translateY(-2px); }
        .scroll-row { overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
        .scroll-row::-webkit-scrollbar { display: none; }

        /* ===== Beat Feed ===== */
        .beat-feed-wrap { position: relative; }
        .beat-feed-container {
            height: 72vh; max-height: 680px; min-height: 400px;
            overflow-y: auto; scroll-snap-type: y mandatory;
            scrollbar-width: none; -ms-overflow-style: none;
            scroll-behavior: smooth; border-radius: 1rem;
            background: rgba(255,255,255,0.02);
            border: 1px solid rgba(255,255,255,0.06);
        }
        .beat-feed-container::-webkit-scrollbar { display: none; }
        .beat-feed-card {
            scroll-snap-align: start; height: 100%; min-height: 100%;
            flex-shrink: 0; position: relative; overflow: hidden;
            cursor: pointer; user-select: none;
        }
        .beat-feed-card .card-bg-img {
            position: absolute; inset: -20px;
            background-size: cover; background-position: center;
            filter: blur(30px) brightness(0.25) saturate(1.2);
            transform: scale(1.1);
            transition: filter 0.6s ease, transform 0.6s ease;
        }
        .beat-feed-card.feed-active .card-bg-img {
            filter: blur(35px) brightness(0.35) saturate(1.4);
            transform: scale(1.15);
        }
        .beat-feed-card .card-gradient {
            position: absolute; inset: 0;
            background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.25) 45%, rgba(0,0,0,0.5) 100%);
        }
        .feed-waveform { display: flex; align-items: flex-end; gap: 2px; height: 44px; }
        .feed-waveform .wbar {
            width: 3px; border-radius: 2px; flex-shrink: 0;
            background: rgba(0,212,255,0.25);
            transition: background 0.4s ease;
        }
        .beat-feed-card.feed-active .feed-waveform .wbar {
            background: rgba(0,212,255,0.6);
            animation: feedWave 0.6s ease-in-out infinite alternate;
        }
        @keyframes feedWave {
            0% { transform: scaleY(0.35); }
            100% { transform: scaleY(1); }
        }
        .feed-tab-btn {
            padding: 7px 18px; border-radius: 9999px; font-size: 13px;
            font-weight: 600; color: #9ca3af;
            background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
            cursor: pointer; transition: all 0.2s; white-space: nowrap;
        }
        .feed-tab-btn:hover { background: rgba(255,255,255,0.07); color: #d1d5db; }
        .feed-tab-btn.active {
            background: rgba(0,212,255,0.12); border-color: rgba(0,212,255,0.4); color: #00d4ff;
        }
        .feed-play-btn {
            width: 60px; height: 60px; border-radius: 50%;
            background: rgba(0,212,255,0.9); border: none;
            display: flex; align-items: center; justify-content: center;
            cursor: pointer; transition: all 0.2s;
            box-shadow: 0 0 28px rgba(0,212,255,0.35);
        }
        .feed-play-btn:hover { transform: scale(1.08); }
        .feed-play-btn:active { transform: scale(0.93); }
        .feed-action-btn {
            display: inline-flex; align-items: center; gap: 6px;
            padding: 9px 20px; border-radius: 12px; font-size: 13px; font-weight: 600;
            cursor: pointer; transition: all 0.2s; border: none;
        }
        .feed-action-unlock {
            background: linear-gradient(135deg, rgba(249,115,22,0.2), rgba(239,68,68,0.12));
            border: 1px solid rgba(249,115,22,0.35); color: #f97316;
        }
        .feed-action-unlock:hover { background: linear-gradient(135deg, rgba(249,115,22,0.3), rgba(239,68,68,0.18)); border-color: rgba(249,115,22,0.55); }
        .feed-action-free {
            background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.35); color: #22c55e;
        }
        .feed-action-free:hover { background: rgba(34,197,94,0.2); border-color: rgba(34,197,94,0.55); }
        .feed-action-dl {
            background: rgba(0,212,255,0.1); border: 1px solid rgba(0,212,255,0.3); color: #00d4ff;
        }
        .feed-action-dl:hover { background: rgba(0,212,255,0.18); border-color: rgba(0,212,255,0.5); }
        .feed-badge {
            position: absolute; top: 12px; right: 12px;
            padding: 4px 11px; border-radius: 8px;
            font-size: 11px; font-weight: 700;
            backdrop-filter: blur(8px); z-index: 5;
        }
        .feed-muted-hint {
            position: absolute; top: 12px; left: 12px;
            padding: 5px 11px; border-radius: 8px; font-size: 11px;
            background: rgba(0,0,0,0.55); backdrop-filter: blur(8px);
            color: #9ca3af; z-index: 5;
            display: flex; align-items: center; gap: 5px;
            opacity: 0; transition: opacity 0.3s; pointer-events: none;
        }
        .beat-feed-card.feed-active .feed-muted-hint { opacity: 1; }
        .beat-feed-card.feed-playing .feed-muted-hint { opacity: 1; color: #00d4ff; }
        .feed-arrow { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 5;
            animation: feedBounce 1.5s ease-in-out infinite; opacity: 0.4; }
        @keyframes feedBounce { 0%,100%{transform:translateX(-50%) translateY(0)} 50%{transform:translateX(-50%) translateY(6px)} }
        @media (max-width: 767px) {
            .beat-feed-container { height: 62vh; min-height: 340px; border-radius: 0.75rem; }
            .feed-play-btn { width: 52px; height: 52px; }
        }
    </style>
</head>
<body class="bg-black text-white overflow-x-hidden">

    <!-- Top Navigation -->
    <nav class="fixed top-0 left-0 right-0 z-40 glass border-b border-white/5">
        <div class="max-w-[1600px] mx-auto px-4 sm:px-6 h-14 flex items-center justify-between">
            <div class="flex items-center gap-6">
                <a href="index.html" class="flex items-center gap-2">
                    <div class="w-8 h-8 rounded-lg flex items-center justify-center bg-white/10 border border-white/20">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-5 h-5 text-white"><rect x="4" y="2" width="16" height="20" rx="2"/><line x1="4" y1="9" x2="20" y2="9"/><line x1="15" y1="5" x2="15" y2="7"/><line x1="15" y1="12" x2="15" y2="18"/></svg>
                    </div>
                    <span class="text-lg font-bold tracking-tight hidden sm:inline">BeatFridge</span>
                </a>
                <div class="hidden md:flex items-center gap-5 text-sm font-medium text-gray-400">
                    <a href="index.html" class="text-cyan-400">Home</a>
                    <a href="search.html" class="hover:text-cyan-400 transition">Search</a>
                    <a href="upload.html" data-nav-upload class="hover:text-cyan-400 transition flex items-center gap-1"><i data-lucide="upload-cloud" class="w-4 h-4"></i>Upload</a>
                    <a href="library.html" class="hover:text-cyan-400 transition">Library</a>
                </div>
            </div>
            <div class="flex items-center gap-3">
                <button class="w-9 h-9 rounded-full bg-white/5 border border-white/10 flex items-center justify-center hover:bg-white/10 transition relative">
                    <i data-lucide="bell" class="w-4 h-4 text-gray-300"></i>
                    <span class="absolute top-1.5 right-1.5 w-2 h-2 bg-orange-500 rounded-full"></span>
                </button>
                <div id="topNavAvatarWrap" class="w-9 h-9 rounded-full bg-gradient-to-br from-cyan-400 to-purple-600 cursor-pointer hover:scale-105 transition avatar-ring overflow-hidden" onclick="BF.isLoggedIn() ? window.location.href='profile.html' : BF.showSignInModal()">
                    <img id="topNavAvatar" src="http://static.photos/people/200x200/42" alt="Profile" class="w-full h-full rounded-full object-cover">
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="max-w-[1600px] mx-auto pt-16 px-4 sm:px-6 pb-32 md:pb-24">
        
        <!-- Hero / Greeting -->
        <div class="pt-6 pb-6">
            <h1 class="text-2xl sm:text-3xl font-bold mb-1" id="greeting">Good evening</h1>
            <p class="text-gray-400 text-sm">Discover new music and artists</p>
        </div>

        <!-- Quick Genre Pills -->
        <div class="mb-8">
            <div class="scroll-row flex gap-2 pb-2" id="genrePills"></div>
        </div>

        <!-- Beat Feed -->
        <section class="mb-10 beat-feed-wrap" id="beatFeedSection">
            <div class="flex items-center justify-between mb-4">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="flame" class="w-5 h-5 text-orange-400"></i>
                    Beat Feed
                </h2>
                <span class="text-[11px] text-gray-600 flex items-center gap-1"><i data-lucide="mouse-pointer-click" class="w-3.5 h-3.5"></i>Scroll to discover</span>
            </div>
            <div class="flex gap-2 mb-4 overflow-x-auto pb-1" id="feedTabs" style="scrollbar-width:none;-ms-overflow-style:none;">
                <button class="feed-tab-btn active" data-tab="trending" onclick="setFeedTab('trending')">🔥 Trending</button>
                <button class="feed-tab-btn" data-tab="new" onclick="setFeedTab('new')">✨ New</button>
                <button class="feed-tab-btn" data-tab="free" onclick="setFeedTab('free')">🆓 Free</button>
                <button class="feed-tab-btn" data-tab="premium" onclick="setFeedTab('premium')">💎 Premium</button>
            </div>
            <div class="beat-feed-container" id="beatFeedContainer"></div>
        </section>

        <!-- Trending Now -->
        <section class="mb-10">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="trending-up" class="w-5 h-5 text-cyan-400"></i>
                    Trending Now
                </h2>
                <a href="search.html" class="text-sm text-cyan-400 hover:text-cyan-300 transition">See all</a>
            </div>
            <div class="scroll-row flex gap-4 pb-2" id="trendingRow"></div>
        </section>

        <!-- Fresh Uploads -->
        <section class="mb-10">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="sparkles" class="w-5 h-5 text-orange-400"></i>
                    Fresh Uploads
                </h2>
            </div>
            <div class="space-y-2" id="freshList"></div>
        </section>

        <!-- Rising Beats -->
        <section class="mb-10" id="risingBeatsSection">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="flame" class="w-5 h-5 text-orange-500"></i>
                    Rising Beats
                    <span class="text-xs text-orange-400/60 font-normal ml-1">🔥 Fastest growing</span>
                </h2>
                <div class="flex items-center gap-2">
                    <button class="text-xs text-gray-500 hover:text-cyan-400 transition flex items-center gap-1" onclick="refreshRisingBeats()">
                        <i data-lucide="refresh-cw" class="w-3.5 h-3.5"></i> Refresh
                    </button>
                    <span class="text-[10px] text-gray-600 flex items-center gap-1" id="risingUpdateTime">Updated just now</span>
                </div>
            </div>
            <div class="scroll-row flex gap-3 pb-2" id="risingRow"></div>
        </section>

        <!-- You Might Like -->
        <section class="mb-10 hidden" id="recSection">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="sparkles" class="w-5 h-5 text-cyan-400"></i>
                    You Might Like
                </h2>
                <button class="text-xs text-gray-500 hover:text-cyan-400 transition flex items-center gap-1" onclick="refreshRecommendations()">
                    <i data-lucide="refresh-cw" class="w-3.5 h-3.5"></i> Refresh
                </button>
            </div>
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3" id="recGrid"></div>
        </section>

        <!-- Motivational Prompt for Producers (shown if logged in as producer with 0 uploads) -->
        <section class="mb-10 hidden" id="producerPromptSection">
            <div class="glass-panel rounded-2xl p-6 bg-gradient-to-r from-cyan-500/10 to-orange-500/10 border border-cyan-500/20">
                <div class="flex flex-col sm:flex-row items-center gap-4">
                    <div class="w-14 h-14 rounded-xl bg-gradient-to-br from-cyan-500/20 to-orange-500/20 flex items-center justify-center flex-shrink-0">
                        <i data-lucide="upload-cloud" class="w-7 h-7 text-cyan-400"></i>
                    </div>
                    <div class="flex-1 text-center sm:text-left">
                        <h3 class="text-lg font-bold text-white mb-1" id="producerPromptText">Your beat could be someone's next hit 🎵</h3>
                        <p class="text-sm text-gray-400">Upload your first track and start earning today</p>
                    </div>
                    <a href="upload.html" class="px-6 py-3 bg-cyan-500 hover:bg-cyan-400 text-black font-semibold rounded-xl transition glow-cyan flex items-center gap-2 flex-shrink-0">
                        <i data-lucide="upload-cloud" class="w-4 h-4"></i>
                        Upload Now
                    </a>
                </div>
            </div>
        </section>

        <!-- Top Creators This Week -->
        <section class="mb-10">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="trophy" class="w-5 h-5 text-orange-400"></i>
                    Top Creators This Week
                </h2>
                <span class="text-xs text-gray-600 flex items-center gap-1"><i data-lucide="trending-up" class="w-3.5 h-3.5"></i>Based on earnings & plays</span>
            </div>
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-3" id="topCreatorsGrid"></div>
        </section>

        <!-- Artists to Discover -->
        <section class="mb-10">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="users" class="w-5 h-5 text-purple-400"></i>
                    Artists to Discover
                </h2>
            </div>
            <div class="scroll-row flex gap-4 pb-2" id="artistRow"></div>
        </section>

        <!-- Recently Played (if any) -->
        <section class="mb-10 hidden" id="recentSection">
            <div class="flex items-center justify-between mb-5">
                <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
                    <i data-lucide="clock" class="w-5 h-5 text-cyan-400"></i>
                    Recently Played
                </h2>
                <div class="flex items-center gap-3">
                    <button class="text-xs text-gray-500 hover:text-cyan-400 transition flex items-center gap-1" onclick="clearRecentlyPlayed()">
                        <i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Clear
                    </button>
                    <a href="library.html" class="text-sm text-cyan-400 hover:text-cyan-300 transition">View all</a>
                </div>
            </div>
            <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3" id="recentGrid"></div>
        </section>

    </main>

    <!-- Sticky Bottom Player -->
    <div class="sticky-player glass border-t border-white/10 px-4 py-3">
        <div class="max-w-[1600px] mx-auto flex items-center gap-4">
            <div class="flex items-center gap-3 w-48 sm:w-64 flex-shrink-0">
                <div class="w-12 h-12 sm:w-14 sm:h-14 rounded-lg overflow-hidden flex-shrink-0">
                    <img id="playerArt" src="http://static.photos/technology/200x200/5" class="w-full h-full object-cover">
                </div>
                <div class="min-w-0 flex-1">
                    <p id="playerTitle" class="text-sm font-medium text-white truncate">Midnight Synthesis</p>
                    <p id="playerArtist" class="text-xs text-gray-400 truncate">Aurora Void</p>
                </div>
            </div>
            <div class="flex-1 flex items-center justify-center max-w-2xl mx-auto">
                <button class="bf-player-ctrl" onclick="BF.playPrevious()" title="Previous"><i data-lucide="skip-back" class="w-4 h-4 fill-current"></i></button>
                <button class="bf-player-ctrl" onclick="BF.replayTrack()" title="Replay"><i data-lucide="rotate-ccw" class="w-4 h-4"></i></button>
                <button class="w-10 h-10 rounded-full bg-white text-black flex items-center justify-center hover:scale-105 transition" onclick="BF.togglePlay()">
                    <i data-lucide="play" class="w-5 h-5 fill-current ml-0.5" id="playIcon"></i>
                </button>
                <button class="bf-player-ctrl" onclick="BF.playNext()" title="Next"><i data-lucide="skip-forward" class="w-4 h-4 fill-current"></i></button>
            </div>
            <div class="hidden sm:flex items-center gap-3 w-48 sm:w-64 justify-end">
                <button class="bf-player-ctrl" onclick="toggleRepeat()" title="Repeat" id="repeatBtn"><i data-lucide="repeat" class="w-4 h-4"></i></button>
                <div class="flex items-center gap-2 group">
                    <i data-lucide="volume-2" class="w-5 h-5 text-gray-400"></i>
                    <div class="w-20 h-1 bg-white/10 rounded-full overflow-hidden"><div class="h-full bg-cyan-400 w-[70%] rounded-full"></div></div>
                </div>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
    <script>
        // Init app
        BF.init('home');

        // Greeting based on time
        const hour = new Date().getHours();
        const greetEl = document.getElementById('greeting');
        const user = BF.getCurrentUser();
        const name = user ? `, ${user.displayName || user.username}` : '';
        if (hour < 12) greetEl.textContent = `Good morning${name}`;
        else if (hour < 18) greetEl.textContent = `Good afternoon${name}`;
        else greetEl.textContent = `Good evening${name}`;

        // Genre Pills
        const genreColors = { cyan: 'bg-cyan-500/20 text-cyan-400 border-cyan-500/30', purple: 'bg-purple-500/20 text-purple-400 border-purple-500/30', orange: 'bg-orange-500/20 text-orange-400 border-orange-500/30', pink: 'bg-pink-500/20 text-pink-400 border-pink-500/30', green: 'bg-green-500/20 text-green-400 border-green-500/30', red: 'bg-red-500/20 text-red-400 border-red-500/30' };
        document.getElementById('genrePills').innerHTML = BF.getGenres().map(g => `
            <a href="search.html?genre=${g.name.toLowerCase()}" class="flex-shrink-0 px-4 py-2 rounded-full border text-sm font-medium transition hover:opacity-80 ${genreColors[g.color]}">
                ${g.name}
            </a>
        `).join('');

        // Initialize recent activity simulation for trending algorithm
        if (!JSON.parse(localStorage.getItem('bf_recent_activity') || '{}')._simulated) {
            BF.simulateRecentActivity();
        }
        // Save ranking snapshot for position-change tracking
        BF.saveRankingSnapshot();

        // Trending Row with trend indicators
        const trending = BF.getTrendingTracks().slice(0, 8);
        document.getElementById('trendingRow').innerHTML = trending.map(track => {
            const trend = BF.getTrackTrendIndicator(track.id);
            const trendBadge = trend.direction !== 'stable'
                ? `<span class="absolute top-2 left-2 px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm flex items-center gap-0.5">${trend.arrow} ${trend.label}</span>`
                : '';
            const isSuperFanLocked = [2, 4, 6].includes(track.id);
            const isFanActive = BF.isSuperFanOf(track.artist);
            const locked = isSuperFanLocked && !isFanActive;
            return `
            <div class="track-card flex-shrink-0 w-36 sm:w-44 glass-panel rounded-xl p-3 group cursor-pointer relative ${locked ? 'opacity-80' : ''}" onclick="${locked ? 'BF.showSuperFanModal(\"'+track.artist+'\", \"'+track.image+'\")' : 'BF.playTrack('+JSON.stringify(track).replace(/"/g, '&quot;')+')'}">
                <div class="relative aspect-square rounded-lg overflow-hidden mb-3">
                    <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110" loading="lazy">
                    <div class="play-btn-overlay absolute inset-0 bg-black/50 flex items-center justify-center">
                        <div class="w-10 h-10 rounded-full bg-cyan-500 text-black flex items-center justify-center glow-cyan"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
                    </div>
                    ${locked ? '<div class="bf-locked-overlay"><span class="bf-superfan-badge"><i data-lucide="lock" class="w-3 h-3"></i> Super Fan Only</span><p class="text-[9px] text-gray-400 mt-1">Unlock</p></div>' : ''}
                    ${trendBadge}
                </div>
                <h3 class="text-sm font-semibold text-white truncate group-hover:text-cyan-400 transition ${locked ? 'opacity-60' : ''}">${track.title}</h3>
                <p class="text-xs text-gray-500 truncate ${locked ? 'opacity-60' : ''}">${track.artist}</p>
                ${BF.renderDL(track.id, track.title, track.artist)}
                ${BF.renderLikeBtn(track.id, track.title, track.artist)}
                ${BF.renderShare(track.id, track.title, track.artist)}
            </div>
        `}).join('');

        // Fresh Uploads List
        const fresh = BF.getAllTracks().slice(0, 6);
        document.getElementById('freshList').innerHTML = fresh.map((track, i) => {
            const isSuperFanLocked = [2, 4].includes(track.id);
            const isFanActive = BF.isSuperFanOf(track.artist);
            const locked = isSuperFanLocked && !isFanActive;
            return `
            <div class="flex items-center gap-3 p-3 rounded-xl hover:bg-white/5 transition cursor-pointer group ${locked ? 'opacity-70' : ''}" onclick="${locked ? 'BF.showSuperFanModal(\"'+track.artist+'\", \"'+track.image+'\")' : 'BF.playTrack('+JSON.stringify(track).replace(/"/g, '&quot;')+')'}">
                <span class="text-sm text-gray-600 w-5 text-right">${i + 1}</span>
                <div class="w-12 h-12 rounded-lg overflow-hidden flex-shrink-0 relative">
                    <img src="${track.image}" class="w-full h-full object-cover ${locked ? 'blur-sm' : ''}" loading="lazy">
                    ${locked ? '<div class="absolute inset-0 bg-black/50 flex items-center justify-center"><i data-lucide="lock" class="w-4 h-4 text-orange-400"></i></div>' : '<div class="absolute inset-0 bg-black/50 flex items-center justify-center opacity-0 group-hover:opacity-100 transition"><i data-lucide="play" class="w-4 h-4 text-cyan-400 fill-current"></i></div>'}
                </div>
                <div class="flex-1 min-w-0">
                    <div class="flex items-center gap-2">
                        <h4 class="text-sm font-medium text-white truncate group-hover:text-cyan-400 transition">${track.title}</h4>
                        ${locked ? '<span class="bf-superfan-badge text-[9px]"><i data-lucide="lock" class="w-2.5 h-2.5"></i>Super Fan Only</span>' : ''}
                    </div>
                    <p class="text-xs text-gray-500 truncate">${track.artist}</p>
                </div>
                <div class="hidden sm:flex items-center gap-3 text-xs text-gray-500">
                    <span>${track.plays} plays</span>
                    <span>${track.duration}</span>
                    <span class="hidden sm:inline-flex">${BF.renderDL(track.id, track.title, track.artist)} ${BF.renderLikeBtn(track.id, track.title, track.artist)}</span>
                </div>
                <span class="sm:hidden flex-shrink-0 flex items-center gap-1">${BF.renderDL(track.id, track.title, track.artist)} ${BF.renderLikeBtn(track.id, track.title, track.artist)}</span>
            </div>
        `}).join('');

        // Artist Row
        document.getElementById('artistRow').innerHTML = BF.getArtists().map(artist => `
            <a href="artist.html" class="artist-card flex-shrink-0 w-32 sm:w-40 glass-panel rounded-xl p-4 text-center group cursor-pointer">
                <div class="w-20 h-20 sm:w-24 sm:h-24 rounded-full overflow-hidden mx-auto mb-3 ${artist.verified ? 'avatar-ring' : ''}">
                    <img src="${artist.image}" class="w-full h-full object-cover" loading="lazy">
                </div>
                <h3 class="text-sm font-semibold text-white truncate group-hover:text-cyan-400 transition">${artist.name}</h3>
                <p class="text-xs text-gray-500">${artist.followers} followers</p>
                ${artist.verified ? '<span class="inline-flex items-center gap-1 text-[10px] text-cyan-400 mt-1"><i data-lucide="check-circle" class="w-3 h-3"></i>Verified</span>' : ''}
            </a>
        `).join('');

        // Recently Played with Quick Replay
        function renderRecentlyPlayed() {
            try {
                const rp = JSON.parse(localStorage.getItem('recentlyPlayed') || '[]');
                if (rp.length) {
                    document.getElementById('recentSection').classList.remove('hidden');
                    document.getElementById('recentGrid').innerHTML = rp.slice(0, 6).map(track => `
                        <div class="glass-panel rounded-xl p-3 group cursor-pointer relative" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
                            <div class="relative aspect-square rounded-lg overflow-hidden mb-2">
                                <img src="${track.image}" class="w-full h-full object-cover" loading="lazy">
                                <div class="play-btn-overlay absolute inset-0 bg-black/50 flex items-center justify-center">
                                    <div class="w-10 h-10 rounded-full bg-cyan-500 text-black flex items-center justify-center glow-cyan"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
                                </div>
                                <button class="bf-replay-btn absolute bottom-1.5 right-1.5 z-10" onclick="event.stopPropagation(); BF.replayTrack(); BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})" title="Quick replay">
                                    <i data-lucide="rotate-ccw" class="w-3 h-3"></i>
                                </button>
                            </div>
                            <h4 class="text-xs font-medium text-white truncate group-hover:text-cyan-400 transition">${track.title}</h4>
                            <p class="text-[11px] text-gray-500 truncate">${track.artist}</p>
                            <div class="mt-1.5 flex items-center gap-1.5">${BF.renderLikeBtn(track.id, track.title, track.artist)}</div>
                        </div>
                    `).join('');
                    lucide.createIcons();
                } else {
                    document.getElementById('recentSection').classList.add('hidden');
                }
            } catch {}
        }
        renderRecentlyPlayed();

        function clearRecentlyPlayed() {
            if (!confirm('Clear your recently played history?')) return;
            localStorage.removeItem('recentlyPlayed');
            renderRecentlyPlayed();
            BF.showToast('History cleared');
        }

        // You Might Like — Recommendations based on current track
        function renderRecommendations() {
            try {
                const currentTrack = JSON.parse(localStorage.getItem('currentTrack') || 'null');
                const recs = BF.getRecommendations(currentTrack, 6);
                const section = document.getElementById('recSection');
                const grid = document.getElementById('recGrid');
                if (!recs.length) { section.classList.add('hidden'); return; }
                section.classList.remove('hidden');
                grid.innerHTML = recs.map(track => `
                    <div class="bf-rec-card glass-panel rounded-xl p-3 group" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
                        <div class="relative aspect-square rounded-lg overflow-hidden mb-2">
                            <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110" loading="lazy">
                            <div class="play-btn-overlay absolute inset-0 bg-black/50 flex items-center justify-center">
                                <div class="w-10 h-10 rounded-full bg-cyan-500 text-black flex items-center justify-center glow-cyan"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
                            </div>
                        </div>
                        <h4 class="text-xs font-medium text-white truncate group-hover:text-cyan-400 transition">${track.title}</h4>
                        <p class="text-[11px] text-gray-500 truncate">${track.artist}</p>
                        <div class="mt-1.5 flex items-center gap-1.5">
                            ${BF.renderLikeBtn(track.id, track.title, track.artist)}
                        </div>
                    </div>
                `).join('');
                lucide.createIcons();
            } catch {}
        }
        renderRecommendations();

        function refreshRecommendations() {
            renderRecommendations();
            BF.showToast('Recommendations refreshed ✨');
        }

        // Set up queue for continuous playback when playing from trending
        function setupQueueFromAll() {
            const allTracks = BF.getAllTracks();
            BF.setPlayQueue(allTracks, 0);
        }
        setupQueueFromAll();

        // Continuous playback: listen for track "end" and auto-advance
        // Since we don't have real audio, we simulate with a timer that auto-advances
        let _autoAdvanceTimer = null;
        function startAutoAdvance() {
            if (_autoAdvanceTimer) clearInterval(_autoAdvanceTimer);
            _autoAdvanceTimer = setInterval(() => {
                try {
                    const playing = localStorage.getItem('isPlaying') === 'true';
                    if (playing) {
                        const progress = parseFloat(localStorage.getItem('progress') || '0');
                        if (progress >= 98) {
                            // Track "ended" — play next
                            const hasNext = BF.playNext();
                            if (hasNext) {
                                renderRecentlyPlayed();
                                renderRecommendations();
                            }
                        }
                    }
                } catch {}
            }, 3000);
        }
        startAutoAdvance();

        // Listen for track change events to update recommendations
        window.addEventListener('bf:trackChange', () => {
            renderRecommendations();
            renderRecentlyPlayed();
        });

        // Repeat toggle
        function toggleRepeat() {
            const btn = document.getElementById('repeatBtn');
            const isRepeat = localStorage.getItem('bf_repeat') === 'true';
            localStorage.setItem('bf_repeat', !isRepeat);
            if (!isRepeat) {
                btn.classList.add('text-cyan-400');
                BF.showToast('Repeat on 🔁');
            } else {
                btn.classList.remove('text-cyan-400');
                BF.showToast('Repeat off');
            }
            lucide.createIcons();
        }
        // Init repeat state
        if (localStorage.getItem('bf_repeat') === 'true') {
            const rb = document.getElementById('repeatBtn');
            if (rb) rb.classList.add('text-cyan-400');
        }

        // ===== BEAT FEED =====
        const feedState = { tab: 'trending', page: 0, pageSize: 5, playing: null, muted: true, observer: null };

        function initBeatFeed() {
            feedState.page = 0;
            feedState.playing = null;
            feedState.muted = true;
            renderFeedCards(true);
            setupFeedObserver();
        }

        function getFeedTracks() {
            let tracks = BF.getAllTracks();
            switch (feedState.tab) {
                case 'trending':
                    tracks = [...tracks].sort((a, b) => {
                        const p = s => { const n = parseFloat(s); return (s || '').includes('K') ? n * 1000 : n; };
                        return p(b.plays || '0') - p(a.plays || '0');
                    }); break;
                case 'new':
                    tracks = tracks.filter(t => t.date && (t.date.includes('day') || t.date.includes('Just') || t.date.includes('hour') || t.date.includes('minute') || t.date.includes('week'))); break;
                case 'free':
                    tracks = tracks.filter(t => !BF.isTrackLocked(t.id, t.artist)); break;
                case 'premium':
                    tracks = tracks.filter(t => BF.isTrackLocked(t.id, t.artist) || BF.getTrackMonetization(t.id)); break;
            }
            return tracks;
        }

        function renderFeedCards(reset) {
            const container = document.getElementById('beatFeedContainer');
            if (!container) return;
            if (reset) { container.innerHTML = ''; feedState.page = 0; }

            const tracks = getFeedTracks();
            const start = feedState.page * feedState.pageSize;
            const batch = tracks.slice(start, start + feedState.pageSize);

            if (!batch.length && reset) {
                container.innerHTML = '<div class="flex flex-col items-center justify-center h-full text-center p-8"><div class="w-14 h-14 rounded-full bg-white/5 flex items-center justify-center mb-4"><i data-lucide="music" class="w-7 h-7 text-gray-600"></i></div><p class="text-gray-500 text-sm">No tracks in this category</p></div>';
                lucide.createIcons(); return;
            }

            batch.forEach(track => {
                const isLocked = BF.isTrackLocked(track.id, track.artist);
                const isSF = BF.isSuperFanOf(track.artist);
                const mon = BF.getTrackMonetization(track.id);
                const price = mon ? (mon.minimumPrice || 0.50) : 0.50;
                const safeTitle = String(track.title).replace(/'/g, "\\'");
                const safeArtist = String(track.artist).replace(/'/g, "\\'");

                let waveHtml = '';
                for (let b = 0; b < 42; b++) {
                    const h = 12 + Math.random() * 88;
                    waveHtml += '<div class="wbar" style="height:' + h + '%;animation-delay:' + (b * 0.04).toFixed(2) + 's"></div>';
                }

                let actionBtn = '';
                let shareBtnHtml = '<button class="feed-action-btn" style="background:rgba(167,139,250,0.08);border:1px solid rgba(167,139,250,0.3);color:#a78bfa" onclick="event.stopPropagation();BF.showShareModal(\'' + safeTitle + '\',\'' + safeArtist + '\',' + track.id + ')"><i data-lucide="share-2" class="w-4 h-4"></i>Share</button>';
                if (isLocked && !isSF) {
                    actionBtn = '<button class="feed-action-btn feed-action-unlock" onclick="event.stopPropagation();BF.showDownloadModal(\'' + safeTitle + '\',\'' + safeArtist + '\',' + track.id + ')"><i data-lucide="lock" class="w-4 h-4"></i>Unlock · 
</body>
</html> + price.toFixed(2) + '</button>';
                } else if (isSF && isLocked) {
                    actionBtn = '<button class="feed-action-btn feed-action-free" onclick="event.stopPropagation();BF.showDownloadModal(\'' + safeTitle + '\',\'' + safeArtist + '\',' + track.id + ')"><i data-lucide="zap" class="w-4 h-4"></i>Free</button>';
                } else {
                    actionBtn = '<button class="feed-action-btn feed-action-dl" onclick="event.stopPropagation();BF.showDownloadModal(\'' + safeTitle + '\',\'' + safeArtist + '\',' + track.id + ')"><i data-lucide="download" class="w-4 h-4"></i>Download</button>';
                }

                const badge = isLocked
                    ? '<div class="feed-badge bg-orange-500/80 text-white">
</body>
</html> + price.toFixed(2) + '</div>'
                    : '<div class="feed-badge bg-green-500/80 text-white">Free</div>';

                const card = document.createElement('div');
                card.className = 'beat-feed-card';
                card.dataset.trackId = track.id;
                card.dataset.track = JSON.stringify(track).replace(/"/g, '&quot;');
                card.onclick = function () { tapFeedCard(this); };
                card.innerHTML =
                    '<div class="card-bg-img" style="background-image:url(\'' + track.image + '\')"></div>' +
                    '<div class="card-gradient"></div>' +
                    '<div class="feed-muted-hint"><i data-lucide="volume-x" class="w-3.5 h-3.5"></i><span class="hint-text">Tap to play</span></div>' +
                    badge +
                    '<div class="relative z-10 flex flex-col justify-between h-full p-5 sm:p-6">' +
                        '<div class="flex items-center justify-between">' +
                            '<div class="flex items-center gap-2 text-[11px] text-gray-500">' +
                                '<span class="flex items-center gap-1"><i data-lucide="play-circle" class="w-3.5 h-3.5"></i>' + track.plays + '</span>' +
                                '<span>' + track.duration + '</span>' +
                                (track.genre ? '<span class="capitalize bg-white/5 px-2 py-0.5 rounded">' + track.genre + '</span>' : '') +
                            '</div>' +
                        '</div>' +
                        '<div class="flex items-center justify-center">' +
                            '<button class="feed-play-btn"><i data-lucide="play" class="w-6 h-6 text-black fill-current ml-0.5"></i></button>' +
                        '</div>' +
                        '<div>' +
                            '<div class="feed-waveform mb-4">' + waveHtml + '</div>' +
                            '<div class="flex items-end justify-between gap-4">' +
                                '<div class="flex-1 min-w-0">' +
                                    '<h3 class="text-lg sm:text-xl font-bold text-white truncate mb-0.5">' + track.title + '</h3>' +
                                    '<p class="text-sm text-gray-400 truncate">' + track.artist + '</p>' +
                                '</div>' +
                                '<div class="flex-shrink-0">' + actionBtn + '</div>' +
                                '<div class="flex-shrink-0 flex items-center gap-2">' + actionBtn + shareBtnHtml + '</div>' +
                            '</div>' +
                        '</div>' +
                    '</div>';
                container.appendChild(card);
            });

            feedState.page++;
            lucide.createIcons();
            if (feedState.observer) setupFeedObserver();
        }

        function setupFeedObserver() {
            if (feedState.observer) feedState.observer.disconnect();
            feedState.observer = new IntersectionObserver(entries => {
                entries.forEach(entry => {
                    const card = entry.target;
                    const wasActive = card.classList.contains('feed-active');
                    if (entry.isIntersecting && entry.intersectionRatio >= 0.55) {
                        document.querySelectorAll('.beat-feed-card.feed-active').forEach(c => {
                            if (c !== card) { c.classList.remove('feed-active'); updateFeedCardIcon(c, false); }
                        });
                        card.classList.add('feed-active');
                        if (!wasActive) updateFeedCardIcon(card, true);
                    } else {
                        card.classList.remove('feed-active', 'feed-playing');
                        if (wasActive) updateFeedCardIcon(card, false);
                    }
                });
            }, { root: document.getElementById('beatFeedContainer'), threshold: [0.55] });
            document.querySelectorAll('.beat-feed-card').forEach(c => feedState.observer.observe(c));
        }

        function updateFeedCardIcon(card, playing) {
            const icon = card.querySelector('.feed-play-btn i');
            if (!icon) return;
            icon.setAttribute('data-lucide', playing ? 'pause' : 'play');
            icon.classList.toggle('ml-0.5', !playing);
            lucide.createIcons();
        }

        function tapFeedCard(card) {
            const track = JSON.parse(card.dataset.track);
            const wasPlaying = card.classList.contains('feed-playing');

            document.querySelectorAll('.beat-feed-card.feed-playing').forEach(c => {
                c.classList.remove('feed-playing');
                const hint = c.querySelector('.hint-text');
                const hIcon = c.querySelector('.feed-muted-hint i');
                if (hint) hint.textContent = 'Tap to play';
                if (hIcon) hIcon.setAttribute('data-lucide', 'volume-x');
            });

            if (wasPlaying) {
                BF.togglePlay();
                feedState.muted = true;
                const hint = card.querySelector('.hint-text');
                if (hint) hint.textContent = 'Tap to play';
                const hIcon = card.querySelector('.feed-muted-hint i');
                if (hIcon) hIcon.setAttribute('data-lucide', 'volume-x');
                card.classList.remove('feed-playing');
            } else {
                BF.playTrack(track);
                feedState.muted = false;
                feedState.playing = card;
                card.classList.add('feed-active', 'feed-playing');
                const hint = card.querySelector('.hint-text');
                if (hint) hint.textContent = 'Now playing';
                const hIcon = card.querySelector('.feed-muted-hint i');
                if (hIcon) hIcon.setAttribute('data-lucide', 'volume-2');
            }
            lucide.createIcons();
        }

        function setFeedTab(tab) {
            feedState.tab = tab;
            document.querySelectorAll('.feed-tab-btn').forEach(t => t.classList.toggle('active', t.dataset.tab === tab));
            renderFeedCards(true);
            setupFeedObserver();
        }

        // Infinite scroll
        const bfContainer = document.getElementById('beatFeedContainer');
        if (bfContainer) {
            bfContainer.addEventListener('scroll', function () {
                if (this.scrollTop + this.clientHeight >= this.scrollHeight - 150) {
                    const total = getFeedTracks().length;
                    if (feedState.page * feedState.pageSize < total) {
                        renderFeedCards(false);
                    }
                }
            });
        }

        // Top Creators This Week
        (function renderTopCreators() {
            const creators = BF.getTopCreatorsThisWeek();
            const grid = document.getElementById('topCreatorsGrid');
            if (!grid || !creators.length) return;
            const medals = ['🥇', '🥈', '🥉', '4', '5'];
            grid.innerHTML = creators.map((c, i) => `
                <div class="glass-panel rounded-xl p-4 text-center group cursor-pointer hover:bg-white/[0.03] transition relative">
                    <div class="absolute top-2 right-2 text-lg">${medals[i]}</div>
                    <div class="w-16 h-16 rounded-full overflow-hidden mx-auto mb-3 ${i === 0 ? 'avatar-ring' : ''}">
                        <img src="${c.image}" class="w-full h-full object-cover">
                    </div>
                    <h3 class="text-sm font-semibold text-white truncate group-hover:text-cyan-400 transition">${c.name}</h3>
                    <p class="text-xs text-gray-500">${c.genre}</p>
                    <div class="mt-2 flex items-center justify-center gap-2 text-[10px]">
                        <span class="text-green-400 font-semibold">${c.earnings}</span>
                        <span class="text-gray-600">·</span>
                        <span class="text-orange-400 font-semibold">${c.change}</span>
                    </div>
                    <div class="mt-2">
                        <span class="text-[10px] text-gray-600">${c.tracks} tracks</span>
                    </div>
                </div>
            `).join('');
            lucide.createIcons();
        })();

        // ===== RISING BEATS =====
        function renderRisingBeats() {
            const rising = BF.getRisingBeats().slice(0, 8);
            const container = document.getElementById('risingRow');
            if (!container) return;

            if (!rising.length) {
                document.getElementById('risingBeatsSection').style.display = 'none';
                return;
            }

            container.innerHTML = rising.map((track, i) => {
                const isLocked = BF.isTrackLocked(track.id, track.artist);
                const isSF = BF.isSuperFanOf(track.artist);
                const safeTitle = String(track.title).replace(/'/g, "\\'");
                const safeArtist = String(track.artist).replace(/'/g, "\\'");

                // Rising badge: velocity indicator
                const velocity = track._velocity || 0;
                const hotness = velocity > 200 ? '🔥🔥🔥' : velocity > 100 ? '🔥🔥' : velocity > 30 ? '🔥' : '📈';
                const recentPlays = track._recentPlays || 0;
                const recentUnlocks = track._recentUnlocks || 0;

                return `
                <div class="track-card flex-shrink-0 w-40 sm:w-48 glass-panel rounded-xl p-3 group cursor-pointer relative" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
                    <div class="relative aspect-square rounded-lg overflow-hidden mb-3">
                        <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110" loading="lazy">
                        <div class="play-btn-overlay absolute inset-0 bg-black/50 flex items-center justify-center">
                            <div class="w-10 h-10 rounded-full bg-orange-500 text-white flex items-center justify-center" style="box-shadow:0 0 16px rgba(249,115,22,0.3)"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
                        </div>
                        <span class="absolute top-2 left-2 px-1.5 py-0.5 rounded text-[9px] font-bold text-orange-400 bg-black/60 backdrop-blur-sm">${hotness} #${i + 1}</span>
                        ${isLocked ? '<div class="bf-locked-overlay"><span class="bf-superfan-badge"><i data-lucide="lock" class="w-3 h-3"></i> Unlock</span></div>' : ''}
                    </div>
                    <h3 class="text-sm font-semibold text-white truncate group-hover:text-orange-400 transition">${track.title}</h3>
                    <p class="text-xs text-gray-500 truncate">${track.artist}</p>
                    <div class="mt-1.5 flex items-center gap-2 text-[10px]">
                        <span class="text-green-400 font-semibold">+${recentPlays} plays</span>
                        <span class="text-gray-600">·</span>
                        <span class="text-cyan-400">${recentUnlocks} unlocks</span>
                    </div>
                    <div class="mt-1.5">${BF.renderDL(track.id, track.title, track.artist)}</div>
                </div>
                `;
            }).join('');
            lucide.createIcons();
        }

        function refreshRisingBeats() {
            BF.simulateRecentActivity();
            renderRisingBeats();
            const timeEl = document.getElementById('risingUpdateTime');
            if (timeEl) timeEl.textContent = 'Updated just now';
            BF.showToast('Rankings refreshed 🔥');
        }

        renderRisingBeats();

        // ===== DYNAMIC RANKING UPDATES =====
        // Re-render trending and rising every 30 seconds
        let _rankingUpdateCount = 0;
        setInterval(() => {
            _rankingUpdateCount++;
            BF.saveRankingSnapshot();
            // Re-render trending row with updated rankings
            const newTrending = BF.getTrendingTracks().slice(0, 8);
            const trendingRow = document.getElementById('trendingRow');
            if (trendingRow && newTrending.length) {
                // Only full re-render every 3rd cycle to avoid flickering
                if (_rankingUpdateCount % 3 === 0) {
                    // Update trend indicators on existing cards
                    newTrending.forEach((track, idx) => {
                        const card = trendingRow.children[idx];
                        if (card) {
                            const trend = BF.getTrackTrendIndicator(track.id);
                            // Find and update trend badge
                            const oldBadge = card.querySelector('[data-trend-badge]');
                            if (oldBadge) {
                                oldBadge.className = `px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm flex items-center gap-0.5`;
                                oldBadge.setAttribute('data-trend-badge', 'true');
                                oldBadge.innerHTML = `${trend.arrow} ${trend.label}`;
                            }
                        }
                    });
                }
            }
            // Update rising beats
            renderRisingBeats();
            const timeEl = document.getElementById('risingUpdateTime');
            if (timeEl) timeEl.textContent = 'Updated ' + (_rankingUpdateCount * 30) + 's ago';
        }, 30000);

        // Producer motivational prompt
        (function checkProducerPrompt() {
            try {
                const user = BF.getCurrentUser();
                if (user && (user.role === 'producer' || user.isArtist)) {
                    const userTracks = BF.getAllTracks().filter(t => t.artistId === user.id || t.artist === (user.displayName || user.username));
                    if (userTracks.length === 0) {
                        const section = document.getElementById('producerPromptSection');
                        if (section) {
                            section.classList.remove('hidden');
                            document.getElementById('producerPromptText').textContent = BF.getMotivationalPrompt();
                        }
                    }
                }
            } catch(e) {}
        })();

        initBeatFeed();
        lucide.createIcons();
    </script>
</body>
</html>