File size: 44,147 Bytes
828bfa5
 
8a46cf9
828bfa5
 
a6fef61
8a46cf9
84de733
828bfa5
7249378
 
 
 
 
828bfa5
7249378
828bfa5
 
7249378
 
ef8890c
7249378
ef8890c
7249378
ef8890c
 
7249378
ef8890c
7249378
 
ef8890c
 
94f519c
 
7249378
 
ef8890c
 
7249378
 
 
 
 
 
ef8890c
 
7249378
 
 
 
ef8890c
 
b610e72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a38df65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d312e78
 
 
 
 
 
 
 
 
 
 
 
a38df65
d312e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a38df65
d312e78
a38df65
 
 
 
 
 
 
 
 
 
 
 
d312e78
a38df65
 
7249378
94f519c
7249378
 
 
 
 
 
 
 
 
 
ef8890c
 
7249378
 
 
 
 
 
 
ef8890c
 
7249378
 
 
 
 
 
 
 
 
ef8890c
 
84de733
94f519c
7249378
 
710ae92
7249378
 
 
b59bfeb
260bf1b
710ae92
b59bfeb
 
 
260bf1b
 
290fd6d
7e2f9e0
 
710ae92
 
7e2f9e0
 
 
 
710ae92
7e2f9e0
 
 
710ae92
 
b59bfeb
 
ef8890c
 
84de733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7249378
 
 
 
 
 
 
 
 
 
 
 
94f519c
7249378
ef8890c
 
7249378
 
 
 
 
ef8890c
 
7249378
 
 
 
 
94f519c
 
7249378
 
 
 
 
 
 
94f519c
 
7249378
 
 
94f519c
 
7249378
 
 
 
 
 
 
 
ef8890c
 
7249378
 
 
 
 
 
 
 
ef8890c
 
290fd6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7249378
 
94f519c
7249378
ef8890c
7249378
 
 
 
 
 
 
 
 
 
94f519c
 
7249378
 
 
 
 
 
 
94f519c
 
7249378
 
 
 
94f519c
7249378
 
 
 
 
 
 
 
 
94f519c
 
7249378
 
 
 
 
 
 
 
 
 
 
 
ef8890c
7249378
94f519c
 
7249378
 
 
 
 
 
 
 
 
ef8890c
 
7249378
 
 
 
 
 
 
ef8890c
 
7249378
 
 
 
 
ef8890c
 
7249378
 
 
94f519c
 
7249378
 
 
 
 
ef8890c
 
7249378
 
 
 
ef8890c
 
7249378
 
 
 
 
 
94f519c
 
7249378
 
 
 
94f519c
 
7249378
 
 
 
ef8890c
 
7249378
 
 
 
94f519c
 
7249378
 
94f519c
 
7249378
 
 
94f519c
 
7249378
 
94f519c
 
7249378
 
 
 
 
 
 
 
 
 
 
94f519c
 
7249378
 
 
 
94f519c
 
7249378
 
 
 
 
 
 
 
94f519c
 
7249378
 
 
 
ef8890c
828bfa5
 
 
84de733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d312e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a38df65
b610e72
 
 
 
 
 
 
 
 
 
7249378
828bfa5
 
b016056
943fe11
828bfa5
2579655
828bfa5
8a46cf9
 
 
828bfa5
 
b016056
8a46cf9
 
e0abbba
a7b6178
 
290fd6d
 
 
 
84de733
828bfa5
ef8890c
7249378
b016056
7249378
 
b016056
 
7249378
b016056
7249378
b016056
7249378
b610e72
 
 
 
 
 
 
 
 
 
7249378
b016056
7249378
 
 
 
 
b016056
 
 
 
 
8a46cf9
 
 
b016056
 
8a46cf9
b016056
 
 
8a46cf9
260bf1b
7249378
943fe11
 
828bfa5
b016056
 
7249378
828bfa5
 
260bf1b
828bfa5
 
8a46cf9
 
 
828bfa5
 
b016056
8a46cf9
 
a7b6178
 
290fd6d
 
 
 
828bfa5
 
 
260bf1b
8a46cf9
b016056
 
 
 
8a46cf9
943fe11
 
 
 
 
8a46cf9
b016056
8a46cf9
b016056
828bfa5
7249378
828bfa5
7249378
 
 
8a46cf9
7249378
 
fc6af73
d312e78
a38df65
d312e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a38df65
7249378
943fe11
7249378
943fe11
 
7249378
943fe11
290fd6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7249378
4c957e3
b59bfeb
8a46cf9
4c957e3
7249378
7e2f9e0
290fd6d
8a46cf9
84de733
 
 
7249378
 
 
 
 
 
 
 
 
 
4c957e3
 
7249378
 
 
 
 
 
 
 
 
290fd6d
 
 
 
 
 
 
 
 
 
7249378
 
 
 
 
 
 
 
 
 
 
 
 
a7b6178
4c957e3
7249378
 
 
 
 
 
b016056
4c957e3
 
7249378
 
4c957e3
 
 
7249378
 
 
4c957e3
 
 
7249378
 
 
 
 
 
 
8a46cf9
 
290fd6d
 
 
 
 
 
 
 
 
 
7249378
 
8a46cf9
7249378
 
 
 
 
a7b6178
7249378
 
 
 
8a46cf9
 
 
7249378
 
 
 
8a46cf9
 
 
7249378
b016056
 
 
8a46cf9
7249378
 
 
b016056
 
8a46cf9
7249378
4c957e3
 
8a46cf9
4c957e3
7249378
8a46cf9
290fd6d
a7b6178
7249378
290fd6d
7249378
 
 
 
a7b6178
290fd6d
 
 
 
a7b6178
290fd6d
7249378
 
290fd6d
7249378
 
 
 
a7b6178
290fd6d
 
 
 
7249378
 
 
4c957e3
 
b59bfeb
4c957e3
 
7249378
7e2f9e0
290fd6d
7249378
84de733
 
 
7249378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290fd6d
 
 
 
 
 
 
 
 
 
 
 
 
 
7249378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c957e3
 
290fd6d
7249378
290fd6d
7249378
 
 
 
 
 
 
 
290fd6d
 
 
 
7249378
290fd6d
8a46cf9
7249378
 
 
 
 
 
8a46cf9
290fd6d
 
 
 
7249378
 
 
8a46cf9
ef8890c
7249378
 
8a46cf9
7249378
 
8a46cf9
7249378
 
7105520
7249378
828bfa5
7249378
 
8a46cf9
7249378
 
8a46cf9
7249378
8a46cf9
 
7249378
 
 
 
7e2f9e0
e0abbba
8a46cf9
 
 
 
7249378
8a46cf9
7249378
8a46cf9
7249378
a38df65
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
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
import streamlit as st
import os
from datetime import datetime
from connect_four_game import ConnectFour
from minimax_ai import MinimaxAI
from llm_explanation import MoveExplainer
from report_generator import generate_match_report
import random

st.set_page_config(
    page_title="Connect Four AI Pro",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Modern Gaming UI Theme with Connect Four Colors
st.markdown('''
<style>
    /* Import Google Fonts */
    @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700;900&family=Rajdhani:wght@300;400;500;600;700&display=swap');
    
    /* Global Styles */
    * {
        font-family: 'Rajdhani', sans-serif !important;
    }
    
    /* Main Background with Gaming Gradient */
    .stApp {
        background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
        background-attachment: fixed;
    }
    
    /* Sidebar Styling */
    [data-testid="stSidebar"] {
        background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
        border-right: 2px solid rgba(255, 215, 0, 0.3);
    }
    
    [data-testid="stSidebar"] h1, 
    [data-testid="stSidebar"] h2, 
    [data-testid="stSidebar"] h3 {
        color: #FFD700 !important;
        font-family: 'Orbitron', sans-serif !important;
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    }
    
    [data-testid="stSidebar"] p,
    [data-testid="stSidebar"] label {
        color: #E0E0E0 !important;
        font-weight: 500;
    }
    
    /* Project Info Container */
    .project-info-container {
        background: linear-gradient(135deg, rgba(255, 107, 107, 0.15), rgba(255, 165, 0, 0.15));
        border-radius: 12px;
        padding: 1rem;
        margin: 0 0 1rem 0;
        border-left: 4px solid #FF6B6B;
    }
    
    .project-info-title {
        color: #FF6B6B !important;
        font-weight: 700 !important;
        font-size: 0.9rem !important;
    }
    
    .project-field {
        background: rgba(0, 0, 0, 0.3);
        border-left: 3px solid #FF6B6B;
        padding: 0.5rem 0.7rem;
        margin: 0.4rem 0;
        border-radius: 6px;
        color: #E0E0E0 !important;
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
    }
    
    .project-field-label {
        color: #FF6B6B !important;
        font-weight: 700 !important;
    }
    
    .project-field-value {
        color: #E0E0E0 !important;
        margin-top: 0.2rem;
        font-size: 0.75rem;
    }
    
    /* Syllabus Coverage Container */
    .syllabus-container {
        background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(102, 126, 234, 0.1));
        border-radius: 12px;
        padding: 1rem;
        margin: 1rem 0;
        border-left: 4px solid #00D4FF;
    }
    
    .syllabus-title {
        color: #00D4FF !important;
        font-weight: 700 !important;
        font-size: 0.95rem !important;
    }
    
    .syllabus-category {
        color: #FFD700 !important;
        font-weight: 700 !important;
        font-size: 0.85rem !important;
        margin-top: 0.8rem !important;
        margin-bottom: 0.4rem !important;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .syllabus-item-direct {
        background: rgba(0, 255, 136, 0.15);
        border-left: 3px solid #00FF88;
        color: #00FF88 !important;
    }
    
    .syllabus-item-partial {
        background: rgba(255, 165, 0, 0.15);
        border-left: 3px solid #FFA500;
        color: #FFD700 !important;
    }
    
    .syllabus-item-foundational {
        background: rgba(100, 150, 255, 0.15);
        border-left: 3px solid #6496FF;
        color: #A8D8FF !important;
    }
    
    .syllabus-item-extensible {
        background: rgba(200, 100, 255, 0.15);
        border-left: 3px solid #C864FF;
        color: #E0B8FF !important;
    }
    
    .syllabus-item {
        padding: 0.6rem 0.7rem;
        margin: 0.4rem 0;
        border-radius: 6px;
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
    }
    
    .syllabus-topic-name {
        font-weight: 700 !important;
    }
    
    .syllabus-topic-usage {
        font-size: 0.75rem !important;
        margin-top: 0.2rem;
        opacity: 0.9;
    }
    
    /* Main Title */
    h1 {
        font-family: 'Orbitron', sans-serif !important;
        font-weight: 900 !important;
        font-size: 3rem !important;
        background: linear-gradient(90deg, #FFD700, #FFA500, #FF6347);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        text-align: center;
        text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
        margin-bottom: 1rem !important;
        animation: glow 2s ease-in-out infinite alternate;
    }
    
    @keyframes glow {
        from {
            filter: drop-shadow(0 0 5px #FFD700);
        }
        to {
            filter: drop-shadow(0 0 20px #FFD700);
        }
    }
    
    /* Subheaders */
    h2, h3 {
        font-family: 'Orbitron', sans-serif !important;
        color: #FFD700 !important;
        font-weight: 700 !important;
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
        border-bottom: 2px solid rgba(255, 215, 0, 0.3);
        padding-bottom: 0.5rem;
        margin-top: 1.5rem !important;
    }
    
    /* Game Board Container */
    .board-container {
        background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
        border-radius: 20px;
        padding: 1rem;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
                    inset 0 0 30px rgba(255, 215, 0, 0.1);
        border: 3px solid rgba(255, 215, 0, 0.3);
        margin: 1rem auto;
        text-align: center;
        width: fit-content;
        display: block;
        position: static !important;
        height: auto !important;
    }
    
    /* Board Display */
    .board-display {
        font-family: 'Courier New', monospace !important;
        font-size: 0.85rem !important;
        line-height: 1.2 !important;
        color: #FFD700 !important;
        background: linear-gradient(135deg, rgba(15, 12, 41, 0.8), rgba(48, 43, 99, 0.8)) !important;
        border: 2px solid rgba(255, 215, 0, 0.4) !important;
        border-radius: 12px !important;
        padding: 0.8rem !important;
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.3) !important;
        overflow-x: auto !important;
        white-space: pre !important;
        width: fit-content !important;
        margin: 0 auto !important;
        height: auto !important;
        position: static !important;
    }
    
    /* Learning Insights Container */
    .learning-insights {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
        border-radius: 12px;
        padding: 1rem;
        margin-top: 1rem;
        border-left: 4px solid #00D4FF;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }
    
    .insight-title {
        color: #00D4FF !important;
        font-family: 'Orbitron', sans-serif !important;
        font-weight: 700 !important;
        font-size: 0.95rem !important;
        text-shadow: 0 0 8px rgba(0, 212, 255, 0.5) !important;
        margin-bottom: 0.8rem !important;
    }
    
    .insight-item {
        background: rgba(0, 0, 0, 0.2);
        border-left: 3px solid #00D4FF;
        padding: 0.6rem 0.8rem;
        margin: 0.5rem 0;
        border-radius: 6px;
        color: #E0E0E0 !important;
        font-size: 0.9rem !important;
        line-height: 1.4 !important;
    }
    
    /* Buttons - Gaming Style */
    .stButton button {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: white !important;
        font-family: 'Orbitron', sans-serif !important;
        font-weight: 700 !important;
        font-size: 1.1rem !important;
        border: 2px solid rgba(255, 215, 0, 0.5) !important;
        border-radius: 12px !important;
        padding: 0.75rem 1.5rem !important;
        box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4) !important;
        transition: all 0.3s ease !important;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
    
    .stButton button:hover {
        background: linear-gradient(135deg, #764ba2 0%, #667eea 100%) !important;
        transform: translateY(-3px);
        box-shadow: 0 12px 30px rgba(102, 126, 234, 0.6) !important;
        border-color: #FFD700 !important;
    }
    
    .stButton button:disabled {
        background: linear-gradient(135deg, #4a4a4a 0%, #2d2d2d 100%) !important;
        opacity: 0.5 !important;
        cursor: not-allowed !important;
        box-shadow: none !important;
    }
    
    /* Column Buttons - Special Styling */
    div[data-testid="column"] .stButton button {
        background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
        width: 100%;
        height: 60px;
        font-size: 1.3rem !important;
        margin: 0.2rem 0;
    }
    
    div[data-testid="column"] .stButton button:hover {
        background: linear-gradient(135deg, #fa709a 0%, #fee140 100%) !important;
        transform: scale(1.05);
    }
    
    /* Info Cards */
    .info-card {
        background: linear-gradient(135deg, #232526 0%, #414345 100%);
        border-radius: 15px;
        padding: 1.5rem;
        margin: 1rem 0;
        border: 2px solid rgba(255, 215, 0, 0.3);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    }
    
    /* Stats Display */
    .metric-container {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
        border-radius: 12px;
        padding: 1rem;
        margin: 0.5rem 0;
        border-left: 4px solid #FFD700;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }
    
    /* Algorithm Performance Card */
    .algo-perf-card {
        background: linear-gradient(135deg, #1a3a52 0%, #2d5a7b 100%);
        border-radius: 15px;
        padding: 1.2rem;
        margin: 1rem 0;
        border: 2px solid rgba(102, 126, 234, 0.5);
        box-shadow: 0 10px 30px rgba(102, 126, 234, 0.2);
    }
    
    .algo-perf-card h4 {
        color: #00D4FF !important;
        font-family: 'Orbitron', sans-serif !important;
        margin-bottom: 1rem !important;
        text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
    }
    
    .algo-stat-item {
        background: rgba(0, 0, 0, 0.3);
        border-left: 3px solid #00D4FF;
        padding: 0.8rem;
        margin: 0.5rem 0;
        border-radius: 8px;
        color: #E0E0E0;
        font-size: 0.95rem;
    }
    
    .algo-stat-label {
        color: #00D4FF !important;
        font-weight: 700 !important;
    }
    
    /* AI Badge */
    .ai-badge {
        display: inline-block;
        background: linear-gradient(135deg, #FF6347, #FF4500);
        color: white;
        padding: 0.5rem 1.5rem;
        border-radius: 25px;
        font-family: 'Orbitron', sans-serif;
        font-weight: 700;
        font-size: 1.2rem;
        border: 2px solid rgba(255, 215, 0, 0.5);
        box-shadow: 0 5px 15px rgba(255, 99, 71, 0.4);
        text-transform: uppercase;
        letter-spacing: 2px;
        animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
        0%, 100% {
            transform: scale(1);
        }
        50% {
            transform: scale(1.05);
        }
    }
    
    /* Two Player Badge */
    .two-player-badge {
        display: inline-block;
        background: linear-gradient(135deg, #4facfe, #00f2fe);
        color: white;
        padding: 0.5rem 1.5rem;
        border-radius: 25px;
        font-family: 'Orbitron', sans-serif;
        font-weight: 700;
        font-size: 1.2rem;
        border: 2px solid rgba(255, 215, 0, 0.5);
        box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
        text-transform: uppercase;
        letter-spacing: 2px;
    }
    
    /* Winner Popup */
    .winner-popup {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 3rem;
        border-radius: 20px;
        border: 4px solid #FFD700;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
        z-index: 9999;
        text-align: center;
        animation: popIn 0.5s ease-out;
    }
    
    @keyframes popIn {
        0% {
            transform: translate(-50%, -50%) scale(0.5);
            opacity: 0;
        }
        100% {
            transform: translate(-50%, -50%) scale(1);
            opacity: 1;
        }
    }
    
    /* Expander Styling */
    .streamlit-expanderHeader {
        background: linear-gradient(135deg, #232526 0%, #414345 100%) !important;
        border-radius: 10px !important;
        border: 1px solid rgba(255, 215, 0, 0.3) !important;
        color: #FFD700 !important;
        font-weight: 600 !important;
    }
    
    /* Radio Buttons */
    .stRadio label {
        color: #E0E0E0 !important;
        font-weight: 600 !important;
        font-size: 1.1rem !important;
    }
    
    /* Slider */
    .stSlider {
        padding: 1rem 0;
    }
    
    /* Text & Paragraphs */
    p, li, span {
        color: #E0E0E0 !important;
        font-size: 1.05rem !important;
        line-height: 1.6 !important;
    }
    
    /* Strong/Bold Text */
    strong {
        color: #FFD700 !important;
        font-weight: 700 !important;
    }
    
    /* Code blocks */
    code {
        background: rgba(255, 215, 0, 0.1) !important;
        color: #FFD700 !important;
        padding: 0.2rem 0.5rem !important;
        border-radius: 5px !important;
    }
    
    /* Horizontal Rules */
    hr {
        border-color: rgba(255, 215, 0, 0.3) !important;
        margin: 2rem 0 !important;
    }
    
    /* Success/Info/Warning/Error Messages */
    .stSuccess, .stInfo, .stWarning, .stError {
        border-radius: 10px !important;
        border-left: 5px solid #FFD700 !important;
    }
    
    /* Scrollbar */
    ::-webkit-scrollbar {
        width: 12px;
        height: 12px;
    }
    
    ::-webkit-scrollbar-track {
        background: #1a1a2e;
    }
    
    ::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #667eea, #764ba2);
        border-radius: 6px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(135deg, #764ba2, #667eea);
    }
    
    /* Download Button */
    .stDownloadButton button {
        background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%) !important;
        color: white !important;
        font-family: 'Orbitron', sans-serif !important;
        font-weight: 700 !important;
        border: 2px solid rgba(255, 215, 0, 0.5) !important;
        border-radius: 12px !important;
        padding: 0.75rem 1.5rem !important;
        box-shadow: 0 8px 20px rgba(17, 153, 142, 0.4) !important;
        transition: all 0.3s ease !important;
    }
    
    .stDownloadButton button:hover {
        background: linear-gradient(135deg, #38ef7d 0%, #11998e 100%) !important;
        transform: translateY(-3px);
        box-shadow: 0 12px 30px rgba(17, 153, 142, 0.6) !important;
    }
    
    /* Analysis Cards */
    .analysis-card {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
        border-radius: 15px;
        padding: 1.5rem;
        margin: 1rem 0;
        border-left: 5px solid #FFD700;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    }
    
    .analysis-card h4 {
        color: #FFD700 !important;
        font-family: 'Orbitron', sans-serif !important;
        margin-bottom: 1rem !important;
    }
</style>
''', unsafe_allow_html=True)

# Academic insights from the learning guides
LEARNING_INSIGHTS = [
    "๐Ÿ’ก Minimax: Plans moves ahead like a chess master, evaluating all possibilities recursively",
    "๐Ÿš€ Alpha-Beta Pruning: Eliminates 60-70% of unnecessary branches, making deep search practical",
    "๐ŸŽฎ Perfect Information: Connect Four has no hidden cardsโ€”AI can calculate optimal play",
    "๐ŸŒณ Search Depth: Each level deeper exponentially increases positions (7^d growth)",
    "โš”๏ธ Threat Detection: AI identifies winning opportunities AND blocks opponent threats",
    "โฑ๏ธ Terminal States: When AI finds winning move immediately (depth 0), no deeper search needed",
    "๐Ÿ”„ Recursion: Minimax calls itself to evaluate all game futures before deciding",
    "๐Ÿ“Š Big-O Notation: O(b^d) without pruning, O(b^d/2) with pruningโ€”theory meets practice",
    "๐ŸŽฏ Game Theory: Minimax chooses moves that maximize AI score, minimize opponent score",
    "๐Ÿ’พ State Management: Session state persists game across page refreshesโ€”no data loss",
    "๐Ÿ† Optimal Play: Depth 5 proves strong enough to block your best strategies",
    "โณ Time Trade-off: Deeper search = more thinking but slower response time",
    "๐Ÿค– Heuristics: Evaluation function rates positions without exploring every possibility",
    "๐ŸŒ DFS vs BFS: Game AI uses depth-first search (memory efficient) not breadth-first",
    "๐Ÿ“ˆ Exponential Growth: Why depth 8 takes 10x longer than depth 5",
]

# Comprehensive Syllabus Coverage with Categories
SYLLABUS_CATEGORIES = {
    "๐ŸŸข DIRECTLY IMPLEMENTED (100%)": [
        ("State Space Search", "Board states and transitions"),
        ("Uninformed Search", "DFS in minimax algorithm"),
        ("Heuristic Search", "Position evaluation function"),
        ("Informed Search", "Move ordering optimization"),
        ("Game Playing", "Perfect information, turn-based"),
        ("Minimax + Alpha-Beta", "Core AI engine"),
    ],
    "๐ŸŸก PARTIALLY IMPLEMENTED (50%)": [
        ("Constraint Satisfaction", "Constraints and validity"),
        ("AND/OR Graphs", "Game tree structure"),
        ("Knowledge Representation", "Board and rules repr."),
        ("Uncertainty Handling", "Heuristic confidence"),
        ("Sequential Decisions", "Move sequencing"),
    ],
    "๐Ÿ”ต FOUNDATIONAL CONCEPTS": [
        ("Propositional Logic", "Game rules as logic"),
        ("Planning", "Planning moves ahead"),
        ("Complex Decisions", "Balancing objectives"),
    ],
    "๐ŸŸฃ EXTENSIBLE (Could Add)": [
        ("Machine Learning", "Learn evaluation function"),
        ("Decision Trees", "Learn move selection"),
        ("Reinforcement Learning", "Learn through self-play"),
        ("Deep Learning", "Neural net evaluation"),
    ],
}

# PROJECT INFORMATION - EDIT THESE VALUES
PROJECT_INFO = {
    "Project Name": "Connect Four AI Pro",
    "Student Name": "Shubhanshu Bansod",  # EDIT THIS
    "Roll Number": "03",  # EDIT THIS
    "Project Guide": "Prof. Swati Chopade",  # EDIT THIS
    "Department": "MCA",  # EDIT THIS
    "College": "Veetmata Jijabai Technological Institute, Matunga, Mumbai",  # EDIT THIS
}

# Initialize Session State
if 'game' not in st.session_state:
    st.session_state.game = ConnectFour()
    st.session_state.game_mode = "vs AI"
    st.session_state.ai = MinimaxAI(st.session_state.game, depth=5)
    hf_token = os.getenv('HF_TOKEN')
    st.session_state.explainer = MoveExplainer(hf_token=hf_token) if hf_token else None
    st.session_state.move_history = []
    st.session_state.move_history_detailed = []
    st.session_state.player1_analyses = []
    st.session_state.player2_analyses = []
    st.session_state.game_over = False
    st.session_state.winner = None
    st.session_state.current_player = 1
    st.session_state.show_winner_popup = False
    st.session_state.move_count = 0
    st.session_state.current_depth = 5
    st.session_state.last_human_move_analysis = None
    st.session_state.last_ai_move_analysis = None
    st.session_state.last_human_algo_perf = None
    st.session_state.last_ai_algo_perf = None
    st.session_state.last_p1_algo_perf = None
    st.session_state.last_p2_algo_perf = None
    st.session_state.current_insight_index = 0

# Header
col_title1, col_title2 = st.columns([3, 1])
with col_title1:
    st.title("๐ŸŽฎ CONNECT FOUR AI PRO")
    
with col_title2:
    if st.session_state.game_mode == "vs AI":
        st.markdown(f'<div class="ai-badge">โšก ULTRA AI</div>', unsafe_allow_html=True)
    else:
        st.markdown('<div class="two-player-badge">๐Ÿ‘ฅ TWO PLAYER</div>', unsafe_allow_html=True)

# Sidebar Configuration
st.sidebar.header("๐Ÿ“‹ PROJECT INFORMATION")

# PROJECT INFORMATION EXPANDER AT TOP
with st.sidebar.expander("๐Ÿ“‘ ABOUT THIS PROJECT"):
    st.markdown('<div class="project-info-container"><div class="project-info-title">Project Details</div></div>', unsafe_allow_html=True)
    
    for field, value in PROJECT_INFO.items():
        st.markdown(f'<div class="project-field"><span class="project-field-label">{field}:</span><div class="project-field-value">{value}</div></div>', unsafe_allow_html=True)

st.sidebar.markdown("---")
st.sidebar.header("โš™๏ธ GAME SETTINGS")

game_mode = st.sidebar.radio(
    "๐ŸŽฎ Game Mode",
    ["vs AI", "Two Player"],
    index=0 if st.session_state.game_mode == "vs AI" else 1
)

if game_mode != st.session_state.game_mode:
    st.session_state.game_mode = game_mode
    st.session_state.game.reset()
    st.session_state.move_history = []
    st.session_state.move_history_detailed = []
    st.session_state.player1_analyses = []
    st.session_state.player2_analyses = []
    st.session_state.game_over = False
    st.session_state.current_player = 1
    st.session_state.move_count = 0
    st.rerun()

if st.session_state.game_mode == "vs AI":
    st.sidebar.markdown("---")
    st.sidebar.subheader("๐ŸŽš๏ธ AI SEARCH DEPTH")
    depth = st.sidebar.slider("Depth Level (3-8)", 3, 8, 5)
    st.session_state.ai.depth = depth
    st.session_state.current_depth = depth

st.sidebar.markdown("---")

# Control Buttons
col1, col2 = st.sidebar.columns(2)
with col1:
    if st.button("๐Ÿ”„ NEW GAME", use_container_width=True):
        st.session_state.game.reset()
        st.session_state.move_history = []
        st.session_state.move_history_detailed = []
        st.session_state.player1_analyses = []
        st.session_state.player2_analyses = []
        st.session_state.game_over = False
        st.session_state.winner = None
        st.session_state.current_player = 1
        st.session_state.show_winner_popup = False
        st.session_state.move_count = 0
        st.session_state.last_human_move_analysis = None
        st.session_state.last_ai_move_analysis = None
        st.session_state.last_human_algo_perf = None
        st.session_state.last_ai_algo_perf = None
        st.session_state.last_p1_algo_perf = None
        st.session_state.last_p2_algo_perf = None
        st.rerun()

with col2:
    if st.button("โ†ฉ๏ธ UNDO", use_container_width=True, disabled=len(st.session_state.move_history) == 0):
        undo_count = min(2, len(st.session_state.move_history)) if st.session_state.game_mode == "vs AI" else 1
        for _ in range(undo_count):
            if st.session_state.move_history:
                st.session_state.game.undo_move(st.session_state.move_history[-1])
                st.session_state.move_history.pop()
                st.session_state.move_history_detailed.pop()
                if st.session_state.game_mode == "Two Player" and st.session_state.player1_analyses and st.session_state.player2_analyses:
                    if st.session_state.move_count % 2 == 0:
                        st.session_state.player2_analyses.pop()
                    else:
                        st.session_state.player1_analyses.pop()
                st.session_state.move_count -= 1
        st.session_state.game_over = False
        st.session_state.show_winner_popup = False
        st.rerun()

# Game Statistics
st.sidebar.markdown("---")
st.sidebar.subheader("๐Ÿ“Š GAME STATISTICS")
st.sidebar.markdown(f'<div class="metric-container"><strong>Total Moves:</strong> {st.session_state.move_count}</div>', unsafe_allow_html=True)

if st.session_state.game_mode == "Two Player":
    st.sidebar.markdown(f'<div class="metric-container"><strong>Player 1 (๐Ÿ”ด):</strong> {len(st.session_state.player1_analyses)} moves</div>', unsafe_allow_html=True)
    st.sidebar.markdown(f'<div class="metric-container"><strong>Player 2 (๐ŸŸก):</strong> {len(st.session_state.player2_analyses)} moves</div>', unsafe_allow_html=True)

# COMPREHENSIVE Syllabus Coverage Section
st.sidebar.markdown("---")
with st.sidebar.expander("๐Ÿ“š COMPREHENSIVE COVERAGE (21 Topics)"):
    st.markdown('<div class="syllabus-container"><div class="syllabus-title">Topics Across 4 Categories</div></div>', unsafe_allow_html=True)
    
    for category, topics in SYLLABUS_CATEGORIES.items():
        st.markdown(f'<div class="syllabus-category">{category}</div>', unsafe_allow_html=True)
        
        if "DIRECTLY" in category:
            style_class = "syllabus-item-direct"
        elif "PARTIALLY" in category:
            style_class = "syllabus-item-partial"
        elif "FOUNDATIONAL" in category:
            style_class = "syllabus-item-foundational"
        else:
            style_class = "syllabus-item-extensible"
        
        for topic_name, topic_usage in topics:
            st.markdown(f'<div class="syllabus-item {style_class}"><span class="syllabus-topic-name">{topic_name}</span><div class="syllabus-topic-usage">{topic_usage}</div></div>', unsafe_allow_html=True)

# Move History
if st.session_state.move_history:
    with st.sidebar.expander("๐Ÿ“œ MOVE HISTORY"):
        for i, col in enumerate(st.session_state.move_history, 1):
            player = "๐Ÿ”ด" if i % 2 == 1 else "๐ŸŸก"
            st.write(f"**Move {i}:** {player} โ†’ Column {col}")

# Helper function to display algorithm performance
def display_algorithm_performance(title, algo_perf):
    """Display algorithm performance metrics in a styled card"""
    if algo_perf:
        st.markdown(f'<div class="algo-perf-card">', unsafe_allow_html=True)
        st.markdown(f"#### โš™๏ธ {title}")
        
        col1, col2 = st.columns(2)
        with col1:
            st.markdown(f'<div class="algo-stat-item"><span class="algo-stat-label">๐Ÿ” Nodes Explored:</span> {algo_perf["nodes_explored"]:,}</div>', unsafe_allow_html=True)
            st.markdown(f'<div class="algo-stat-item"><span class="algo-stat-label">โœ‚๏ธ Pruning Efficiency:</span> {algo_perf["pruning_efficiency"]:.1f}%</div>', unsafe_allow_html=True)
        
        with col2:
            st.markdown(f'<div class="algo-stat-item"><span class="algo-stat-label">๐Ÿšซ Nodes Pruned:</span> {algo_perf["nodes_pruned"]:,}</div>', unsafe_allow_html=True)
            st.markdown(f'<div class="algo-stat-item"><span class="algo-stat-label">โšก Response Time:</span> {algo_perf["time_ms"]:.0f}ms</div>', unsafe_allow_html=True)
        
        st.markdown(f'<div class="algo-stat-item"><span class="algo-stat-label">๐ŸŒณ Search Depth:</span> {algo_perf["depth"]}</div>', unsafe_allow_html=True)
        st.markdown('</div>', unsafe_allow_html=True)

# Main Game Layout
if st.session_state.game_mode == "vs AI":
    col1, col2 = st.columns([1, 1], gap="large")
    
    with col1:
        st.subheader("๐ŸŽฏ GAME BOARD")
        board_str = st.session_state.game.board_to_string()
        st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
        
        # Learning Insights Section
        st.markdown(f'<div class="learning-insights"><div class="insight-title">๐Ÿ“š QUICK INSIGHT</div><div class="insight-item">{random.choice(LEARNING_INSIGHTS)}</div></div>', unsafe_allow_html=True)
        
        # Column Selection
        st.markdown("### ๐ŸŽฒ SELECT YOUR MOVE")
        cols = st.columns(7)
        for i, col in enumerate(cols):
            with col:
                if st.button(f"โ†“\n{i}", key=f"col_{i}", 
                           disabled=st.session_state.game_over or not st.session_state.game.is_valid_move(i)):
                    # Human Move
                    st.session_state.game.make_move(i, 1)
                    st.session_state.move_history.append(i)
                    st.session_state.move_count += 1
                    
                    # Get AI recommendation
                    ai_move = st.session_state.ai.get_best_move()
                    is_optimal = (i == ai_move['move'])
                    recommendation = {
                        'is_optimal': is_optimal,
                        'suggested_column': ai_move['move'],
                        'score_diff': abs(ai_move['score'] - st.session_state.game.evaluate(2))
                    }
                    
                    # Store human algorithm performance
                    human_algo_perf = {
                        'nodes_explored': ai_move.get('nodes_explored', 0),
                        'nodes_pruned': ai_move.get('nodes_pruned', 0),
                        'pruning_efficiency': ai_move.get('pruning_efficiency', 0),
                        'depth': ai_move.get('depth', 0),
                        'time_ms': ai_move.get('time_ms', 0)
                    }
                    st.session_state.last_human_algo_perf = human_algo_perf
                    
                    # Generate explanation
                    explanation_data = None
                    if st.session_state.explainer:
                        move_data = {
                            'move': i,
                            'score': st.session_state.game.evaluate(2),
                            'threats': ai_move.get('threats', []),
                            'nodes_explored': ai_move.get('nodes_explored', 0)
                        }
                        explanation_result = st.session_state.explainer.explain_move(move_data)
                        if explanation_result['success']:
                            explanation_data = explanation_result['explanation']
                            st.session_state.last_human_move_analysis = explanation_result
                    
                    move_detail = {
                        'player': 1,
                        'player_name': 'Human',
                        'column': i,
                        'analysis': ai_move,
                        'explanation': explanation_data,
                        'recommendation': recommendation
                    }
                    st.session_state.move_history_detailed.append(move_detail)
                    
                    # Check win
                    if st.session_state.game.check_winner(1):
                        st.session_state.game_over = True
                        st.session_state.winner = "Human"
                        st.session_state.show_winner_popup = True
                        st.rerun()
                    
                    if st.session_state.game.is_board_full():
                        st.session_state.game_over = True
                        st.session_state.winner = "Draw"
                        st.session_state.show_winner_popup = True
                        st.rerun()
                    
                    # AI Move
                    if not st.session_state.game_over:
                        ai_move = st.session_state.ai.get_best_move()
                        st.session_state.game.make_move(ai_move['move'], 2)
                        st.session_state.move_history.append(ai_move['move'])
                        st.session_state.move_count += 1
                        
                        # Store AI algorithm performance
                        ai_algo_perf = {
                            'nodes_explored': ai_move.get('nodes_explored', 0),
                            'nodes_pruned': ai_move.get('nodes_pruned', 0),
                            'pruning_efficiency': ai_move.get('pruning_efficiency', 0),
                            'depth': ai_move.get('depth', 0),
                            'time_ms': ai_move.get('time_ms', 0)
                        }
                        st.session_state.last_ai_algo_perf = ai_algo_perf
                        
                        # AI explanation
                        ai_explanation_data = None
                        if st.session_state.explainer:
                            ai_move_data = {
                                'move': ai_move['move'],
                                'score': ai_move['score'],
                                'threats': ai_move.get('threats', []),
                                'nodes_explored': ai_move.get('nodes_explored', 0)
                            }
                            ai_explanation_result = st.session_state.explainer.explain_move(ai_move_data)
                            if ai_explanation_result['success']:
                                ai_explanation_data = ai_explanation_result['explanation']
                                st.session_state.last_ai_move_analysis = ai_explanation_result
                        
                        ai_move_detail = {
                            'player': 2,
                            'player_name': 'AI (Ultra)',
                            'column': ai_move['move'],
                            'analysis': ai_move,
                            'explanation': ai_explanation_data
                        }
                        st.session_state.move_history_detailed.append(ai_move_detail)
                        
                        # Check AI win
                        if st.session_state.game.check_winner(2):
                            st.session_state.game_over = True
                            st.session_state.winner = "AI"
                            st.session_state.show_winner_popup = True
                            st.rerun()
                        
                        if st.session_state.game.is_board_full():
                            st.session_state.game_over = True
                            st.session_state.winner = "Draw"
                            st.session_state.show_winner_popup = True
                            st.rerun()
                    
                    st.rerun()
    
    with col2:
        st.subheader("๐Ÿค– AI ANALYSIS & INSIGHTS")
        
        # Display Human Move Analysis
        if st.session_state.last_human_move_analysis:
            st.markdown('<div class="analysis-card">', unsafe_allow_html=True)
            st.markdown("#### ๐Ÿ‘ค YOUR LAST MOVE")
            analysis = st.session_state.last_human_move_analysis
            st.info(f"**Explanation:** {analysis['explanation']}")
            st.success(f"**Threat Analysis:** {analysis['threat_analysis']}")
            st.warning(f"**Key Insight:** {analysis['key_insight']}")
            st.markdown('</div>', unsafe_allow_html=True)
            
            # Display Human Algorithm Performance
            if st.session_state.last_human_algo_perf:
                display_algorithm_performance("YOUR MOVE - ALGORITHM PERFORMANCE", st.session_state.last_human_algo_perf)
        
        # Display AI Move Analysis
        if st.session_state.last_ai_move_analysis:
            st.markdown('<div class="analysis-card">', unsafe_allow_html=True)
            st.markdown("#### ๐Ÿค– AI'S LAST MOVE")
            analysis = st.session_state.last_ai_move_analysis
            st.info(f"**Explanation:** {analysis['explanation']}")
            st.success(f"**Threat Analysis:** {analysis['threat_analysis']}")
            st.warning(f"**Key Insight:** {analysis['key_insight']}")
            st.markdown('</div>', unsafe_allow_html=True)
            
            # Display AI Algorithm Performance
            if st.session_state.last_ai_algo_perf:
                display_algorithm_performance("AI MOVE - ALGORITHM PERFORMANCE", st.session_state.last_ai_algo_perf)
        
        if not st.session_state.last_human_move_analysis and not st.session_state.last_ai_move_analysis:
            st.info("๐ŸŽฒ Make your first move to see AI analysis!")

else:  # Two Player Mode
    col1, col2 = st.columns([1, 1], gap="large")
    
    with col1:
        st.subheader("๐ŸŽฏ GAME BOARD")
        board_str = st.session_state.game.board_to_string()
        st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
        
        # Learning Insights Section
        st.markdown(f'<div class="learning-insights"><div class="insight-title">๐Ÿ“š QUICK INSIGHT</div><div class="insight-item">{random.choice(LEARNING_INSIGHTS)}</div></div>', unsafe_allow_html=True)
        
        # Current Player Indicator
        current_player_symbol = "๐Ÿ”ด RED" if st.session_state.current_player == 1 else "๐ŸŸก YELLOW"
        st.markdown(f'<div class="info-card"><h3 style="text-align: center;">Current Turn: {current_player_symbol}</h3></div>', unsafe_allow_html=True)
        
        # Column Selection
        st.markdown("### ๐ŸŽฒ SELECT COLUMN")
        cols = st.columns(7)
        for i, col in enumerate(cols):
            with col:
                if st.button(f"โ†“\n{i}", key=f"col_{i}", 
                           disabled=st.session_state.game_over or not st.session_state.game.is_valid_move(i)):
                    # Make move
                    st.session_state.game.make_move(i, st.session_state.current_player)
                    st.session_state.move_history.append(i)
                    st.session_state.move_count += 1
                    
                    # Get AI analysis
                    ai_move = st.session_state.ai.get_best_move()
                    is_optimal = (i == ai_move['move'])
                    recommendation = {
                        'is_optimal': is_optimal,
                        'suggested_column': ai_move['move'],
                        'score_diff': abs(ai_move['score'] - st.session_state.game.evaluate(2))
                    }
                    
                    # Store algorithm performance
                    algo_perf = {
                        'nodes_explored': ai_move.get('nodes_explored', 0),
                        'nodes_pruned': ai_move.get('nodes_pruned', 0),
                        'pruning_efficiency': ai_move.get('pruning_efficiency', 0),
                        'depth': ai_move.get('depth', 0),
                        'time_ms': ai_move.get('time_ms', 0)
                    }
                    
                    if st.session_state.current_player == 1:
                        st.session_state.last_p1_algo_perf = algo_perf
                    else:
                        st.session_state.last_p2_algo_perf = algo_perf
                    
                    # Generate explanation
                    explanation_data = None
                    if st.session_state.explainer:
                        move_data = {
                            'move': i,
                            'score': st.session_state.game.evaluate(2),
                            'threats': ai_move.get('threats', []),
                            'nodes_explored': ai_move.get('nodes_explored', 0)
                        }
                        explanation_result = st.session_state.explainer.explain_move(move_data)
                        if explanation_result['success']:
                            explanation_data = explanation_result['explanation']
                            if st.session_state.current_player == 1:
                                st.session_state.player1_analyses.append(explanation_result)
                            else:
                                st.session_state.player2_analyses.append(explanation_result)
                    
                    player_name = f"Player {st.session_state.current_player}"
                    move_detail = {
                        'player': st.session_state.current_player,
                        'player_name': player_name,
                        'column': i,
                        'analysis': ai_move,
                        'explanation': explanation_data,
                        'recommendation': recommendation
                    }
                    st.session_state.move_history_detailed.append(move_detail)
                    
                    # Check win
                    if st.session_state.game.check_winner(st.session_state.current_player):
                        st.session_state.game_over = True
                        st.session_state.winner = f"Player {st.session_state.current_player}"
                        st.session_state.show_winner_popup = True
                        st.rerun()
                    
                    if st.session_state.game.is_board_full():
                        st.session_state.game_over = True
                        st.session_state.winner = "Draw"
                        st.session_state.show_winner_popup = True
                        st.rerun()
                    
                    # Switch player
                    st.session_state.current_player = 2 if st.session_state.current_player == 1 else 1
                    st.rerun()
    
    with col2:
        st.subheader("๐Ÿ“Š PLAYER ANALYSIS & PERFORMANCE")
        
        # Player 1 Analysis
        if st.session_state.player1_analyses:
            st.markdown('<div class="analysis-card">', unsafe_allow_html=True)
            st.markdown("#### ๐Ÿ”ด PLAYER 1 - LAST MOVE")
            analysis = st.session_state.player1_analyses[-1]
            st.info(f"**Explanation:** {analysis['explanation']}")
            st.success(f"**Threat Analysis:** {analysis['threat_analysis']}")
            st.warning(f"**Key Insight:** {analysis['key_insight']}")
            st.markdown('</div>', unsafe_allow_html=True)
            
            # Display Player 1 Algorithm Performance
            if st.session_state.last_p1_algo_perf:
                display_algorithm_performance("PLAYER 1 - ALGORITHM PERFORMANCE", st.session_state.last_p1_algo_perf)
        
        # Player 2 Analysis
        if st.session_state.player2_analyses:
            st.markdown('<div class="analysis-card">', unsafe_allow_html=True)
            st.markdown("#### ๐ŸŸก PLAYER 2 - LAST MOVE")
            analysis = st.session_state.player2_analyses[-1]
            st.info(f"**Explanation:** {analysis['explanation']}")
            st.success(f"**Threat Analysis:** {analysis['threat_analysis']}")
            st.warning(f"**Key Insight:** {analysis['key_insight']}")
            st.markdown('</div>', unsafe_allow_html=True)
            
            # Display Player 2 Algorithm Performance
            if st.session_state.last_p2_algo_perf:
                display_algorithm_performance("PLAYER 2 - ALGORITHM PERFORMANCE", st.session_state.last_p2_algo_perf)
        
        if not st.session_state.player1_analyses and not st.session_state.player2_analyses:
            st.info("๐ŸŽฒ Start playing to see move analysis!")

# Winner Display
if st.session_state.show_winner_popup:
    if st.session_state.winner == "Draw":
        st.balloons()
        st.success("๐Ÿค **GAME OVER - IT'S A DRAW!**")
    elif st.session_state.winner == "Human":
        st.balloons()
        st.success("๐Ÿ† **CONGRATULATIONS! YOU WON!**")
    elif st.session_state.winner == "AI":
        st.balloons()
        st.error("๐Ÿค– **AI WINS! Better luck next time!**")
    else:
        st.balloons()
        st.success(f"๐Ÿ† **{st.session_state.winner.upper()} WINS!**")

# Match Report Download
if st.session_state.game_over and st.session_state.move_history_detailed:
    st.markdown("---")
    st.subheader("๐Ÿ“„ MATCH REPORT")
    
    report = generate_match_report(
        game_mode=st.session_state.game_mode,
        ai_mode="Ultra AI" if st.session_state.game_mode == "vs AI" else "N/A",
        winner=st.session_state.winner,
        move_history_data=st.session_state.move_history_detailed,
        game_board=st.session_state.game.board_to_string(),
        search_depth=st.session_state.current_depth if st.session_state.game_mode == "vs AI" else None
    )
    
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    st.download_button(
        label="๐Ÿ“ฅ DOWNLOAD MATCH REPORT",
        data=report,
        file_name=f"connect_four_match_report_{timestamp}.txt",
        mime="text/plain",
        use_container_width=True
    )