-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2413 lines (2287 loc) · 154 KB
/
Copy pathindex.html
File metadata and controls
2413 lines (2287 loc) · 154 KB
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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">
<title>ArchViz 3D — Gerador Procedural</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400;500;600&family=Jost:wght@300;400;500;600&display=swap');
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{--gold:#b8935a;--gold2:#d4b07a;--ui-bg:rgba(14,11,8,.93);--ui-border:rgba(184,147,90,.22);--ui-text:#e8e0d0;--ui-muted:#887c6a;--r:12px;--ps:0 20px 60px rgba(0,0,0,.75),0 0 0 .5px rgba(184,147,90,.08)}
html,body{width:100%;height:100%;overflow:hidden;background:#0c0a08;font-family:'Jost',sans-serif}
#c{display:block;position:fixed;inset:0;width:100%!important;height:100%!important}
#loader{position:fixed;inset:0;z-index:100;background:#0c0a08;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:22px;transition:opacity .8s ease}
#loader.out{opacity:0;pointer-events:none}
.lt{font-family:'Cormorant Garamond',serif;font-size:30px;font-weight:300;color:var(--gold);letter-spacing:.14em}
.ls{font-size:11px;color:var(--ui-muted);letter-spacing:.14em;text-transform:uppercase}
.lb{width:220px;height:2px;background:rgba(184,147,90,.18);border-radius:2px;overflow:hidden}
.lf{height:100%;background:linear-gradient(90deg,var(--gold),var(--gold2));width:0%;transition:width .25s ease}
#hdr{position:fixed;top:0;left:0;right:0;z-index:20;display:flex;align-items:center;justify-content:space-between;padding:16px 24px;background:linear-gradient(180deg,rgba(12,10,8,.94) 0%,transparent 100%);pointer-events:none}
.ht{font-family:'Cormorant Garamond',serif;font-size:19px;font-weight:400;color:var(--gold);letter-spacing:.08em}
.hs{font-size:11px;color:var(--ui-muted);letter-spacing:.1em;text-transform:uppercase;margin-top:2px}
.hb{background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:40px;padding:6px 15px;font-size:11px;color:#c8b890;letter-spacing:.08em;backdrop-filter:blur(12px)}
#panel{position:fixed;top:68px;right:18px;z-index:20;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:var(--r);padding:12px 14px;backdrop-filter:blur(22px);min-width:152px;box-shadow:var(--ps);max-height:50vh;overflow-y:auto}
.pt{font-size:9px;font-weight:600;letter-spacing:.14em;color:var(--ui-muted);text-transform:uppercase;margin-bottom:12px;padding-bottom:8px;border-bottom:1px solid rgba(255,255,255,.06)}
.ri{display:flex;align-items:center;gap:9px;padding:5px 0}
.rd{width:8px;height:8px;border-radius:2px;flex-shrink:0}
.rn{font-size:12px;color:var(--ui-text)}
.rz{font-size:10px;color:var(--ui-muted);margin-left:auto}
.ps{height:1px;background:rgba(255,255,255,.06);margin:10px 0}
.sr{display:flex;justify-content:space-between;align-items:center;padding:3px 0}
.sl{font-size:10px;color:var(--ui-muted)}
.sv{font-size:12px;color:var(--gold);font-weight:500}
.empty-hint{text-align:center;padding:16px 4px;color:var(--ui-muted);font-size:11px;line-height:1.8}
#tb{position:fixed;bottom:26px;left:50%;transform:translateX(-50%);z-index:20;display:flex;gap:2px;align-items:center;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:50px;padding:5px 8px;backdrop-filter:blur(22px);box-shadow:0 8px 40px rgba(0,0,0,.65),inset 0 1px 0 rgba(255,255,255,.04)}
.btn{display:flex;align-items:center;gap:6px;padding:7px 13px;border:none;border-radius:40px;cursor:pointer;font-family:'Jost',sans-serif;font-size:11px;font-weight:500;letter-spacing:.04em;transition:all .18s ease;white-space:nowrap;outline:none}
.btn svg{flex-shrink:0}
.bp{background:linear-gradient(135deg,var(--gold),var(--gold2));color:#0c0a08}
.bp:hover{background:linear-gradient(135deg,var(--gold2),#e0c888)}
.bg{background:transparent;color:var(--ui-muted)}
.bg:hover{color:var(--ui-text);background:rgba(255,255,255,.07)}
.ba{background:rgba(184,147,90,.16);color:var(--gold);border:1px solid rgba(184,147,90,.32)}
.ts{width:1px;height:22px;background:rgba(255,255,255,.07);margin:0 2px}
#hint{position:fixed;bottom:78px;left:50%;transform:translateX(-50%);z-index:20;pointer-events:none;font-size:11px;color:var(--ui-muted);letter-spacing:.06em;background:rgba(12,10,8,.75);padding:5px 15px;border-radius:20px;border:1px solid rgba(255,255,255,.05);backdrop-filter:blur(8px);opacity:1;transition:opacity 1.4s ease}
#hint.f{opacity:0}
#cmp{position:fixed;bottom:26px;left:26px;z-index:20;width:48px;height:48px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:50%;backdrop-filter:blur(12px);display:flex;align-items:center;justify-content:center;box-shadow:0 4px 20px rgba(0,0,0,.5)}
.spanel{background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:16px;padding:16px;backdrop-filter:blur(24px);box-shadow:var(--ps);opacity:0;pointer-events:none;transition:opacity .3s ease,transform .35s cubic-bezier(.34,1.2,.64,1)}
.spanel.open{opacity:1;pointer-events:all}
#kpanel{position:fixed;top:50%;left:18px;transform:translateY(-50%) translateX(-20px);z-index:20;min-width:195px}
#kpanel.open{transform:translateY(-50%) translateX(0)}
.krow{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 0;border-bottom:1px solid rgba(255,255,255,.04)}
.krow:last-child{border-bottom:none}
.klabel{font-size:11px;color:var(--ui-text)}
.kbtn{background:rgba(184,147,90,.12);color:var(--gold);border:1px solid rgba(184,147,90,.26);border-radius:8px;cursor:pointer;font-family:'Jost',sans-serif;font-size:11px;padding:5px 10px;transition:all .15s;outline:none;display:flex;align-items:center;gap:5px}
.kbtn:hover{background:rgba(184,147,90,.26)}
.karr{display:flex;gap:3px}
.kval{font-size:10px;color:var(--ui-muted);text-align:right}
#epanel{display:none}
/* ═══════════════════════════════════════════════
PAINEL LATERAL EXTERNO — sempre visível, lado esquerdo
═══════════════════════════════════════════════ */
#sidepanel{
position:fixed;top:50%;left:18px;transform:translateY(-50%);
z-index:25;width:214px;
background:var(--ui-bg);border:1px solid var(--ui-border);
border-radius:16px;padding:14px 12px;
backdrop-filter:blur(24px);box-shadow:var(--ps);
display:flex;flex-direction:column;gap:0;
max-height:94vh;overflow-y:auto;
}
#sidepanel::-webkit-scrollbar{width:3px}
#sidepanel::-webkit-scrollbar-thumb{background:rgba(184,147,90,.28);border-radius:2px}
.sp-title{
font-size:9px;font-weight:700;letter-spacing:.18em;color:var(--gold);
text-transform:uppercase;padding-bottom:9px;margin-bottom:4px;
border-bottom:1px solid rgba(184,147,90,.22);
display:flex;align-items:center;gap:7px;
}
.sp-sec{
font-size:8px;font-weight:700;letter-spacing:.16em;
color:rgba(184,147,90,.7);text-transform:uppercase;
margin:10px 0 6px;display:flex;align-items:center;gap:6px;
}
.sp-sec-line{flex:1;height:1px;background:rgba(255,255,255,.06)}
.sp-grid{display:grid;grid-template-columns:1fr 1fr;gap:5px;margin-bottom:2px}
/* Botão quadrado (grade 2 cols) */
.sp-btn{
display:flex;flex-direction:column;align-items:center;justify-content:center;
gap:5px;padding:9px 4px 8px;border-radius:10px;cursor:pointer;
border:1.5px solid rgba(255,255,255,.07);
background:rgba(255,255,255,.04);
font-family:'Jost',sans-serif;font-size:10px;font-weight:500;
color:var(--ui-muted);letter-spacing:.02em;
transition:all .18s ease;outline:none;text-align:center;line-height:1.3;
user-select:none;
}
.sp-btn:hover{background:rgba(184,147,90,.1);border-color:rgba(184,147,90,.28);color:var(--ui-text);}
.sp-btn.on{background:rgba(184,147,90,.18);border-color:rgba(184,147,90,.6);color:var(--gold);box-shadow:0 0 10px rgba(184,147,90,.15);}
.sp-ico{
width:30px;height:30px;border-radius:8px;
display:flex;align-items:center;justify-content:center;
background:rgba(255,255,255,.05);transition:background .18s;
}
.sp-btn.on .sp-ico{background:rgba(184,147,90,.22);}
/* Botão largo (full width) */
.sp-btn-wide{
display:flex;align-items:center;gap:9px;
padding:9px 10px;border-radius:10px;cursor:pointer;
border:1.5px solid rgba(255,255,255,.07);
background:rgba(255,255,255,.04);
font-family:'Jost',sans-serif;font-size:11px;font-weight:500;
color:var(--ui-muted);transition:all .18s;outline:none;
width:100%;margin-bottom:5px;user-select:none;text-align:left;
}
.sp-btn-wide:hover{background:rgba(184,147,90,.1);border-color:rgba(184,147,90,.28);color:var(--ui-text);}
.sp-btn-wide.on{background:rgba(184,147,90,.18);border-color:rgba(184,147,90,.6);color:var(--gold);}
.sp-ico-sm{
width:24px;height:24px;border-radius:7px;flex-shrink:0;
display:flex;align-items:center;justify-content:center;
background:rgba(255,255,255,.05);transition:background .18s;
}
.sp-btn-wide.on .sp-ico-sm{background:rgba(184,147,90,.22);}
.sp-badge{
margin-left:auto;font-size:8px;font-weight:700;letter-spacing:.05em;
padding:2px 6px;border-radius:8px;text-transform:uppercase;flex-shrink:0;
}
.sp-badge-new{background:rgba(184,147,90,.28);color:var(--gold);border:1px solid rgba(184,147,90,.4);}
.sp-div{height:1px;background:rgba(255,255,255,.06);margin:8px 0;}
.sp-note{font-size:9.5px;color:var(--ui-muted);line-height:1.65;padding:5px 3px;opacity:.85}
}
/* ── GIZMO / SELETOR DE OBJETO EXTERNO ─────────────── */
#ext-sel-panel{
position:fixed;bottom:82px;left:50%;transform:translateX(-50%);
z-index:28;display:none;
background:var(--ui-bg);border:1px solid var(--ui-border);
border-radius:40px;padding:5px 8px;
backdrop-filter:blur(20px);box-shadow:0 6px 32px rgba(0,0,0,.6);
align-items:center;gap:3px;
}
#ext-sel-panel.show{display:flex;}
.gizmo-lbl{font-size:10px;color:var(--gold);font-weight:500;padding:0 8px;letter-spacing:.04em;white-space:nowrap;}
.gizmo-sep{width:1px;height:20px;background:rgba(255,255,255,.07);margin:0 2px;}
.gbtn{display:flex;align-items:center;gap:5px;padding:6px 10px;border:none;border-radius:30px;cursor:pointer;font-family:'Jost',sans-serif;font-size:10px;font-weight:500;color:var(--ui-muted);background:transparent;transition:all .15s;outline:none;white-space:nowrap;}
.gbtn:hover{background:rgba(255,255,255,.08);color:var(--ui-text);}
.gbtn.danger{color:#e08070;}
.gbtn.danger:hover{background:rgba(160,50,40,.22);}
/* Hint externo */
#ext-mode-hint{
position:fixed;top:68px;left:50%;transform:translateX(-50%);
z-index:26;display:none;pointer-events:none;
font-size:11px;color:var(--gold);background:rgba(184,147,90,.14);
border:1px solid rgba(184,147,90,.35);border-radius:20px;
padding:5px 16px;letter-spacing:.05em;backdrop-filter:blur(8px);
}
#ext-mode-hint.show{display:block;}
.esec{font-size:9px;font-weight:600;letter-spacing:.14em;color:var(--gold);text-transform:uppercase;margin:10px 0 6px;opacity:.75}
.esec:first-of-type{margin-top:4px}
.etog{display:flex;align-items:center;gap:10px;padding:5px 2px;cursor:pointer;font-size:12px;color:var(--ui-text);user-select:none;transition:color .15s}
.etog:hover{color:#fff}
.etog input{display:none}
.esl{width:34px;height:18px;background:rgba(255,255,255,.1);border-radius:9px;position:relative;flex-shrink:0;transition:background .22s;border:1px solid rgba(255,255,255,.08)}
.esl::after{content:'';position:absolute;width:14px;height:14px;background:#666;border-radius:50%;top:1px;left:1px;transition:transform .22s cubic-bezier(.34,1.56,.64,1),background .22s}
.etog input:checked+.esl{background:rgba(184,147,90,.45);border-color:rgba(184,147,90,.5)}
.etog input:checked+.esl::after{transform:translateX(16px);background:var(--gold)}
.edps{height:1px;background:rgba(255,255,255,.06);margin:8px 0 4px}
#editpanel{position:fixed;top:50%;left:18px;transform:translateY(-50%) translateX(-20px);z-index:22;min-width:210px}
#editpanel.open{transform:translateY(-50%) translateX(0)}
.eprow{font-size:11px;color:var(--ui-text);padding:7px 0;border-bottom:1px solid rgba(255,255,255,.04)}
.eprow:last-child{border-bottom:none;padding-bottom:0}
.selinfo{font-size:12px;color:var(--gold);font-weight:500;min-height:18px;margin-top:3px}
.add-grid{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-top:8px}
.add-btn{background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);border-radius:8px;padding:7px 8px;cursor:pointer;font-family:'Jost',sans-serif;font-size:10px;color:var(--ui-muted);text-align:center;transition:all .15s;outline:none}
.add-btn:hover{background:rgba(184,147,90,.12);border-color:rgba(184,147,90,.3);color:var(--gold)}
.del-btn{width:100%;padding:9px;background:rgba(160,50,40,.16);border:1px solid rgba(160,50,40,.28);border-radius:8px;cursor:pointer;font-family:'Jost',sans-serif;font-size:11px;font-weight:500;color:#e08070;transition:all .15s;outline:none;margin-top:6px;display:flex;align-items:center;justify-content:center;gap:6px}
.del-btn:hover{background:rgba(160,50,40,.3)}
.del-btn:disabled{opacity:.32;cursor:not-allowed}
#deco-fab{position:fixed;bottom:26px;right:26px;z-index:30;width:52px;height:52px;border-radius:50%;border:none;cursor:pointer;background:linear-gradient(135deg,var(--gold),var(--gold2));box-shadow:0 4px 20px rgba(184,147,90,.45);display:flex;align-items:center;justify-content:center;transition:transform .25s cubic-bezier(.34,1.56,.64,1),box-shadow .25s;outline:none}
#deco-fab:hover{transform:scale(1.1) rotate(12deg);box-shadow:0 6px 28px rgba(184,147,90,.65)}
#deco-fab.open{transform:rotate(45deg) scale(1.05);background:linear-gradient(135deg,#b03828,#d04838)}
@keyframes fabPulse{0%{transform:scale(1);opacity:.55}100%{transform:scale(1.9);opacity:0}}
@keyframes pulse360{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.4;transform:scale(1.4)}}
#deco-fab::before{content:'';position:absolute;inset:0;border-radius:50%;border:2px solid var(--gold2);animation:fabPulse 2.2s ease-out infinite;pointer-events:none}
#deco-fab.open::before{animation:none;opacity:0}
#deco-fab-label{position:fixed;bottom:34px;right:86px;z-index:29;font-size:11px;color:var(--gold);background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:20px;padding:4px 10px;backdrop-filter:blur(12px);opacity:1;transition:opacity .3s;pointer-events:none;white-space:nowrap}
#deco-fab-label.hidden{opacity:0}
#dpanel{position:fixed;top:50%;right:90px;transform:translateY(-50%) translateX(30px);z-index:25;min-width:205px;display:flex;flex-direction:column;gap:12px}
#dpanel.open{transform:translateY(-50%) translateX(0)}
.dpt{display:flex;align-items:center;gap:8px;font-size:11px;font-weight:600;letter-spacing:.1em;color:var(--gold);text-transform:uppercase;padding-bottom:10px;border-bottom:1px solid rgba(184,147,90,.18)}
.dgroup{display:flex;flex-direction:column;gap:6px}
.dlabel{font-size:10px;color:var(--ui-muted);letter-spacing:.06em;display:flex;align-items:center;gap:5px}
.dlabel-dot{width:6px;height:6px;border-radius:2px;background:var(--gold);opacity:.5;flex-shrink:0}
.dswatches{display:flex;gap:5px;flex-wrap:wrap}
.dsw{width:24px;height:24px;border-radius:6px;cursor:pointer;border:2px solid transparent;transition:transform .15s,border-color .15s,box-shadow .15s;position:relative}
.dsw:hover{transform:scale(1.2)}
.dsw.act{border-color:rgba(255,255,255,.9);box-shadow:0 0 0 1px rgba(255,255,255,.2);transform:scale(1.08)}
.dsw.act::after{content:'✓';position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:11px;color:rgba(255,255,255,.9)}
.dps{height:1px;background:rgba(255,255,255,.06)}
#ai-overlay{position:fixed;inset:0;z-index:38;background:rgba(0,0,0,.55);backdrop-filter:blur(2px);opacity:0;pointer-events:none;transition:opacity .3s}
#ai-overlay.open{opacity:1;pointer-events:all}
#aipanel{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.96);z-index:40;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:18px;padding:0;backdrop-filter:blur(32px);box-shadow:0 32px 96px rgba(0,0,0,.85);width:min(680px,92vw);max-height:90vh;overflow:hidden;opacity:0;pointer-events:none;transition:opacity .35s,transform .4s cubic-bezier(.34,1.2,.64,1);display:flex;flex-direction:column}
#aipanel.open{opacity:1;pointer-events:all;transform:translate(-50%,-50%) scale(1)}
.ai-header{padding:22px 24px 18px;border-bottom:1px solid rgba(184,147,90,.14);display:flex;align-items:flex-start;justify-content:space-between;flex-shrink:0}
.ai-title{font-family:'Cormorant Garamond',serif;font-size:22px;font-weight:400;color:var(--gold);letter-spacing:.06em}
.ai-sub{font-size:11px;color:var(--ui-muted);margin-top:4px;max-width:400px;line-height:1.6}
.ai-close{background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.08);border-radius:8px;padding:6px;cursor:pointer;color:var(--ui-muted);transition:all .15s;outline:none;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.ai-close:hover{background:rgba(255,255,255,.12);color:var(--ui-text)}
.ai-body{padding:20px 24px;overflow-y:auto;flex:1}
.ai-body::-webkit-scrollbar{width:4px}
.ai-body::-webkit-scrollbar-thumb{background:rgba(184,147,90,.25);border-radius:2px}
.ai-sec{margin-bottom:20px}
.ai-sec-t{font-size:9px;font-weight:600;letter-spacing:.18em;color:var(--gold);text-transform:uppercase;margin-bottom:12px;opacity:.8}
.ai-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.ai-field{display:flex;flex-direction:column;gap:5px}
.ai-label{font-size:10px;color:var(--ui-muted);letter-spacing:.06em}
.ai-input{background:rgba(255,255,255,.04);border:1px solid rgba(184,147,90,.2);border-radius:8px;padding:9px 12px;font-family:'Jost',sans-serif;font-size:13px;color:var(--ui-text);outline:none;transition:border-color .2s;width:100%}
.ai-input:focus{border-color:rgba(184,147,90,.55);background:rgba(184,147,90,.06)}
.ai-calc{font-size:10px;color:var(--gold);margin-top:2px;min-height:14px}
.ai-checks{display:flex;flex-wrap:wrap;gap:8px}
.ai-chk{display:flex;align-items:center;gap:6px;cursor:pointer;padding:5px 10px;border:1px solid rgba(184,147,90,.16);border-radius:7px;background:rgba(255,255,255,.03);transition:all .16s;user-select:none}
.ai-chk:hover{border-color:rgba(184,147,90,.35);background:rgba(184,147,90,.08)}
.ai-chk input{display:none}
.ai-chk.selected{border-color:rgba(184,147,90,.5);background:rgba(184,147,90,.12)}
.ai-chk span{font-size:11px;color:var(--ui-text)}
.ai-chk.selected span{color:var(--gold)}
.ai-selwrap{position:relative}
.ai-select{background:rgba(255,255,255,.04);border:1px solid rgba(184,147,90,.2);border-radius:8px;padding:9px 12px;font-family:'Jost',sans-serif;font-size:13px;color:var(--ui-text);outline:none;width:100%;cursor:pointer;-webkit-appearance:none}
.ai-select:focus{border-color:rgba(184,147,90,.55)}
.ai-select option{background:#1a1410}
.ai-selwrap::after{content:'';position:absolute;right:12px;top:50%;transform:translateY(-50%);border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid var(--ui-muted);pointer-events:none}
.ai-footer{padding:16px 24px 20px;border-top:1px solid rgba(255,255,255,.05);display:flex;gap:10px;flex-shrink:0}
.ai-btn{flex:1;padding:11px;border:none;border-radius:10px;cursor:pointer;font-family:'Jost',sans-serif;font-size:12px;font-weight:500;letter-spacing:.06em;transition:all .2s;outline:none}
.ai-btn-p{background:linear-gradient(135deg,var(--gold),var(--gold2));color:#0c0a08}
.ai-btn-p:hover{background:linear-gradient(135deg,var(--gold2),#e0c888);transform:translateY(-1px)}
.ai-btn-s{background:rgba(184,147,90,.1);color:var(--gold);border:1px solid rgba(184,147,90,.25)}
.ai-btn-s:hover{background:rgba(184,147,90,.2)}
.ai-btn:disabled{opacity:.4;cursor:not-allowed;transform:none}
.ai-res{background:rgba(184,147,90,.06);border:1px solid rgba(184,147,90,.22);border-radius:12px;padding:16px;animation:resIn .4s cubic-bezier(.34,1.2,.64,1)}
@keyframes resIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.ai-res-hdr{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
.ai-res-title{font-family:'Cormorant Garamond',serif;font-size:16px;color:var(--gold);font-weight:400}
.viab{font-size:10px;font-weight:600;letter-spacing:.1em;text-transform:uppercase;padding:3px 10px;border-radius:20px}
.va{background:rgba(60,140,60,.25);color:#7be07b;border:1px solid rgba(60,140,60,.35)}
.vm{background:rgba(180,130,40,.22);color:#e8c860;border:1px solid rgba(180,130,40,.32)}
.vb{background:rgba(160,50,40,.22);color:#e08070;border:1px solid rgba(160,50,40,.32)}
.ai-room-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:8px;margin-bottom:12px}
.ai-rc{background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.06);border-radius:8px;padding:8px 10px}
.ai-rc-n{font-size:10px;color:var(--ui-muted);margin-bottom:2px}
.ai-rc-a{font-size:13px;color:var(--ui-text);font-weight:500}
.ai-obs{font-size:11px;color:var(--ui-muted);line-height:1.7;padding-top:10px;border-top:1px solid rgba(255,255,255,.05)}
.ai-obs strong{color:var(--gold2)}
.ai-spin-wrap{display:flex;align-items:center;gap:10px;padding:16px;color:var(--ui-muted);font-size:12px;justify-content:center}
@keyframes spin{to{transform:rotate(360deg)}}
.ai-spinner{width:18px;height:18px;border:2px solid rgba(184,147,90,.2);border-top-color:var(--gold);border-radius:50%;animation:spin .8s linear infinite;flex-shrink:0}
#sel-highlight{position:fixed;pointer-events:none;z-index:50;display:none}
#sel-highlight.show{display:block}
.edit-hint{position:fixed;top:70px;left:50%;transform:translateX(-50%);z-index:25;font-size:11px;color:var(--gold);background:rgba(184,147,90,.14);border:1px solid rgba(184,147,90,.32);border-radius:20px;padding:5px 16px;letter-spacing:.06em;pointer-events:none;opacity:0;transition:opacity .3s}
.edit-hint.show{opacity:1}
@media(max-width:600px){#panel{display:none}.hb{display:none}.btn span{display:none}.btn{padding:8px 10px}#dpanel{right:16px;min-width:185px}#deco-fab{bottom:90px;right:16px}#deco-fab-label{display:none}#kpanel,#epanel,#editpanel{left:10px}#aipanel{width:96vw;max-height:96vh}.ai-grid{grid-template-columns:1fr}.ai-footer{flex-direction:column}}
50%{transform:scale(1.25);opacity:1;}
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="loader"><div class="lt">ArchViz 3D</div><div class="ls">Gerador Procedural · Planta 3D</div><div class="lb"><div class="lf" id="lf"></div></div></div>
<!-- ═══════════════════════════════════════════════════
NOVO PAINEL LATERAL ESQUERDO — sempre visível
═══════════════════════════════════════════════════ -->
<div id="sidepanel">
<!-- Título -->
<div class="sp-title">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="var(--gold)" stroke-width="1.8" stroke-linecap="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
Área Externa
</div>
<!-- ── PAISAGISMO ── -->
<div class="sp-sec"><span class="sp-sec-line"></span>Paisagismo<span class="sp-sec-line"></span></div>
<div class="sp-grid">
<button class="sp-btn" id="spb-trees" onclick="spToggle('trees',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><path d="M12 22v-7"/><path d="M12 15l-5-5h10l-5 5z"/><path d="M9 10l-4-4h14l-4 4z"/></svg></div>
Árvores
</button>
<button class="sp-btn" id="spb-garden" onclick="spToggle('garden',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><circle cx="12" cy="8" r="3"/><path d="M12 11v10"/><path d="M8 19h8"/></svg></div>
Jardim
</button>
<button class="sp-btn" id="spb-fence" onclick="spToggle('fence',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><line x1="3" y1="20" x2="21" y2="20"/><line x1="3" y1="13" x2="21" y2="13"/><line x1="6" y1="20" x2="6" y2="8"/><line x1="12" y1="20" x2="12" y2="8"/><line x1="18" y1="20" x2="18" y2="8"/></svg></div>
Cerca
</button>
<button class="sp-btn" id="spb-path" onclick="spToggle('path',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><rect x="3" y="3" width="7" height="5" rx="1"/><rect x="14" y="3" width="7" height="5" rx="1"/><rect x="3" y="11" width="7" height="5" rx="1"/><rect x="14" y="11" width="7" height="5" rx="1"/></svg></div>
Calçada
</button>
</div>
<!-- ── PISCINA ── -->
<div class="sp-sec"><span class="sp-sec-line"></span>Piscina<span class="sp-sec-line"></span></div>
<button class="sp-btn-wide" id="spb-pool1" onclick="spToggleDraggable('pool1',this)">
<div class="sp-ico-sm">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><rect x="2" y="6" width="20" height="12" rx="3"/><line x1="2" y1="12" x2="22" y2="12"/><line x1="7" y1="6" x2="7" y2="18"/></svg>
</div>
<span>Piscina Ret. + Deck</span>
<span class="sp-badge sp-badge-new">Mover</span>
</button>
<button class="sp-btn-wide" id="spb-pool2" onclick="spToggleDraggable('pool2',this)">
<div class="sp-ico-sm">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><ellipse cx="12" cy="12" rx="10" ry="5"/><path d="M2 12c3-3 7-3 10 0s7 3 10 0"/></svg>
</div>
<span>Prainha / Raia</span>
<span class="sp-badge sp-badge-new">Mover</span>
</button>
<!-- ── ÁREA GOURMET ── -->
<div class="sp-sec"><span class="sp-sec-line"></span>Área Gourmet<span class="sp-sec-line"></span></div>
<button class="sp-btn-wide" id="spb-bbq" onclick="spToggleDraggable('bbq',this)">
<div class="sp-ico-sm">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M4 5h16v3H4z"/><path d="M6 8v8a2 2 0 0 0 4 0V8"/><path d="M14 8v8a2 2 0 0 0 4 0V8"/><line x1="12" y1="2" x2="12" y2="5"/></svg>
</div>
<span>Churrasqueira</span>
<span class="sp-badge sp-badge-new">Novo</span>
</button>
<button class="sp-btn-wide" id="spb-espreg" onclick="spToggleDraggable('espreg',this)">
<div class="sp-ico-sm">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M4 18h16"/><path d="M4 18V9l5-4 5 4v9"/><circle cx="19" cy="8" r="2"/><path d="M17 18v-6"/></svg>
</div>
<span>Espreguiçadeiras</span>
<span class="sp-badge sp-badge-new">Novo</span>
</button>
<div class="sp-grid">
<button class="sp-btn" id="spb-pergola" onclick="spToggleDraggable('pergola',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><line x1="2" y1="6" x2="22" y2="6"/><line x1="5" y1="6" x2="5" y2="20"/><line x1="19" y1="6" x2="19" y2="20"/><line x1="12" y1="6" x2="12" y2="14" opacity=".5"/></svg></div>
Pergolado
</button>
<button class="sp-btn" id="spb-furn" onclick="spToggleDraggable('furn',this)">
<div class="sp-ico"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"><circle cx="12" cy="9" r="3"/><path d="M12 12v8"/><path d="M8 16h8"/></svg></div>
Mesa+Cad.
</button>
</div>
<!-- ── GARAGEM ── -->
<div class="sp-sec"><span class="sp-sec-line"></span>Garagem<span class="sp-sec-line"></span></div>
<button class="sp-btn-wide" id="spb-garage" onclick="spToggleDraggable('garage',this)">
<div class="sp-ico-sm">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><rect x="1" y="4" width="15" height="12" rx="1"/><path d="M16 8h5l2 4v4h-7V8z"/><circle cx="5.5" cy="17.5" r="2.5"/><circle cx="18.5" cy="17.5" r="2.5"/></svg>
</div>
<span>Garagem + Carro 3D</span>
<span class="sp-badge sp-badge-new">Novo</span>
</button>
<div class="sp-div"></div>
<div class="sp-note">💡 Gere uma planta primeiro. Objetos <strong style="color:var(--gold)">Novo</strong> são arrastáveis — clique para selecionar e mover no quintal.</div>
</div>
<div id="editpanel" class="spanel">
<div class="pt" style="margin-bottom:10px;display:flex;align-items:center;gap:7px"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="var(--gold)" stroke-width="1.8" stroke-linecap="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>Modo Edição</div>
<div class="eprow"><div style="font-size:10px;color:var(--ui-muted);margin-bottom:3px">Selecionado</div><div class="selinfo" id="sel-info">Nenhum</div></div>
<div class="eprow"><div style="font-size:10px;color:var(--ui-muted);margin-bottom:0">Adicionar Móvel</div>
<div class="add-grid"><button class="add-btn" onclick="spawnFurn('sofa')">Sofá</button><button class="add-btn" onclick="spawnFurn('cama')">Cama</button><button class="add-btn" onclick="spawnFurn('mesa')">Mesa</button><button class="add-btn" onclick="spawnFurn('cadeira')">Cadeira</button><button class="add-btn" onclick="spawnFurn('armario')">Armário</button><button class="add-btn" onclick="spawnFurn('planta')">Planta</button></div>
</div>
<button class="del-btn" id="del-btn" onclick="deleteSelected()" disabled><svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/></svg>Remover Item</button>
</div>
<div id="deco-fab-label">Decoração</div>
<button id="deco-fab" onclick="togglePanel('dpanel','deco-fab')">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="rgba(12,10,8,.85)" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="12" r="9"/><circle cx="7" cy="12" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="10" cy="8" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="14" cy="8" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="17" cy="12" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/></svg>
</button>
<div id="dpanel" class="spanel">
<div class="dpt"><svg width="14" height="14" viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="7" stroke="var(--gold)" stroke-width="1"/><circle cx="4.5" cy="9" r="1.2" fill="#c04030"/><circle cx="7" cy="6" r="1.2" fill="#4a8a50"/><circle cx="10" cy="6" r="1.2" fill="#4878b0"/><circle cx="12" cy="9" r="1.2" fill="var(--gold)"/></svg>Decoração</div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot"></div>Cor das Paredes</div><div class="dswatches" id="sw-wall"><div class="dsw act" data-hex="f0ebe0" style="background:#f0ebe0" title="Areia"></div><div class="dsw" data-hex="e8e0d8" style="background:#e8e0d8" title="Off-White"></div><div class="dsw" data-hex="d4dde0" style="background:#d4dde0" title="Azul Névoa"></div><div class="dsw" data-hex="d8e4d4" style="background:#d8e4d4" title="Verde Sage"></div><div class="dsw" data-hex="e8d8d0" style="background:#e8d8d0" title="Rosa Quartz"></div><div class="dsw" data-hex="2e2a26" style="background:#2e2a26" title="Carvão"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#7a8ab0"></div>Sofá</div><div class="dswatches" id="sw-sofa"><div class="dsw act" data-hex="575048" style="background:#575048" title="Grafite"></div><div class="dsw" data-hex="3a4a5a" style="background:#3a4a5a" title="Azul Navy"></div><div class="dsw" data-hex="5a3a2e" style="background:#5a3a2e" title="Terracota"></div><div class="dsw" data-hex="7a8a70" style="background:#7a8a70" title="Verde Musgo"></div><div class="dsw" data-hex="9a8878" style="background:#9a8878" title="Bege Camel"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#c8a870"></div>Piso</div><div class="dswatches" id="sw-floor"><div class="dsw act" data-hex="c8a870" style="background:#c8a870" title="Madeira Clara"></div><div class="dsw" data-hex="7a5a3a" style="background:#7a5a3a" title="Madeira Escura"></div><div class="dsw" data-hex="d4cfc8" style="background:#d4cfc8" title="Concreto"></div><div class="dsw" data-hex="c8b89a" style="background:#c8b89a" title="Carvalho"></div><div class="dsw" data-hex="3a3530" style="background:#3a3530" title="Wengué"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#f0f0e8"></div>Teto</div><div class="dswatches" id="sw-ceil"><div class="dsw act" data-hex="f8f3ec" style="background:#f8f3ec" title="Branco Quente"></div><div class="dsw" data-hex="ffffff" style="background:#ffffff" title="Branco Puro"></div><div class="dsw" data-hex="dde8f0" style="background:#dde8f0" title="Azul Gelo"></div><div class="dsw" data-hex="1a1a1a" style="background:#1a1a1a" title="Preto"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#8a6850"></div>Tapete</div><div class="dswatches" id="sw-rug"><div class="dsw act" data-hex="584030" style="background:#584030" title="Terracota"></div><div class="dsw" data-hex="3a4a58" style="background:#3a4a58" title="Azul"></div><div class="dsw" data-hex="485840" style="background:#485840" title="Verde"></div><div class="dsw" data-hex="585040" style="background:#585040" title="Oliva"></div><div class="dsw" data-hex="e0d8cc" style="background:#e0d8cc" title="Creme"></div></div></div>
</div>
<div id="ai-overlay" onclick="closeAI()"></div>
<div id="aipanel">
<div class="ai-header"><div><div class="ai-title">Assistente de Planta</div><div class="ai-sub">Informe as dimensões e programa — o sistema gera a planta 3D do zero, proceduralmente.</div></div><button class="ai-close" onclick="closeAI()"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button></div>
<div class="ai-body" id="ai-body">
<div id="ai-form">
<div class="ai-sec"><div class="ai-sec-t">Dimensões do Terreno</div><div class="ai-grid"><div class="ai-field"><label class="ai-label">Largura (m)</label><input class="ai-input" id="ai-w" type="number" min="4" max="50" step=".5" value="6" oninput="calcArea()"></div><div class="ai-field"><label class="ai-label">Comprimento (m)</label><input class="ai-input" id="ai-d" type="number" min="4" max="100" step=".5" value="8" oninput="calcArea()"></div></div><div class="ai-calc" id="ai-area-calc">— Área: <strong style="color:var(--gold)">48 m²</strong></div></div>
<div class="ai-sec"><div class="ai-sec-t">Programa de Necessidades</div><div class="ai-grid"><div class="ai-field"><label class="ai-label">Quartos (total)</label><input class="ai-input" id="ai-qts" type="number" min="1" max="5" value="2"></div><div class="ai-field"><label class="ai-label">Suítes</label><input class="ai-input" id="ai-suites" type="number" min="0" max="4" value="1" oninput="calcBaths()"></div><div class="ai-field"><label class="ai-label">Banh. Sociais</label><input class="ai-input" id="ai-bths-social" type="number" min="0" max="3" value="1" oninput="calcBaths()"></div><div class="ai-field" style="display:none"><input class="ai-input" id="ai-bths" type="number" value="2"></div></div><div class="ai-calc" id="bath-calc" style="font-size:9px;color:var(--ui-muted);margin-top:3px">— 1 suíte + 1 banheiro social = 2 banheiros</div></div>
<div class="ai-sec"><div class="ai-sec-t">Ambientes Desejados</div><div class="ai-checks"><label class="ai-chk selected"><input type="checkbox" id="chk-suite" checked><span>Suíte</span></label><label class="ai-chk selected"><input type="checkbox" id="chk-sala" checked><span>Sala de Estar</span></label><label class="ai-chk selected"><input type="checkbox" id="chk-coz" checked><span>Cozinha</span></label><label class="ai-chk"><input type="checkbox" id="chk-garagem"><span>Garagem</span></label><label class="ai-chk"><input type="checkbox" id="chk-servico"><span>Área de Serviço</span></label><label class="ai-chk"><input type="checkbox" id="chk-escritorio"><span>Escritório</span></label></div></div>
<div class="ai-sec"><div class="ai-sec-t">Prioridade</div><div class="ai-selwrap"><select class="ai-select" id="ai-prio"><option value="aproveitamento">Melhor aproveitamento de área</option><option value="conforto">Conforto e espaço interno</option><option value="ventilacao">Ventilação e iluminação natural</option><option value="custo">Menor custo construtivo</option><option value="fachada">Fachada valorizada</option></select></div></div>
</div>
<div id="ai-result-wrap" style="display:none"></div>
</div>
<div class="ai-footer">
<button class="ai-btn ai-btn-p" id="ai-gen-btn" onclick="runGenerate()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" style="display:inline;vertical-align:middle;margin-right:5px"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>Gerar Planta 3D</button>
<button class="ai-btn ai-btn-s" id="ai-var-btn" style="display:none" onclick="runVariation()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" style="display:inline;vertical-align:middle;margin-right:5px"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg>Nova Variação</button>
</div>
</div>
<div id="hdr"><div><div class="ht">Gerador de Plantas 3D</div><div class="hs">Sistema Procedural · ArchViz Premium</div></div><div class="hb" id="hb-badge">Configure no painel IA</div></div>
<div id="panel">
<div class="pt">Cômodos</div>
<div id="room-list"><div class="empty-hint">Nenhuma planta<br>gerada ainda.<br><br>Use o botão<br><strong style="color:var(--gold)">Planta IA</strong></div></div>
<div class="ps"></div>
<div class="sr"><span class="sl">Área Total</span><span class="sv" id="sv-area">—</span></div>
<div class="sr"><span class="sl">Quartos</span><span class="sv" id="sv-qts">—</span></div>
<div class="sr"><span class="sl">Banheiros</span><span class="sv" id="sv-bths">—</span></div>
</div>
<div id="tb">
<button class="btn bp" id="bPe" onclick="setView('p')"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg><span>Perspectiva</span></button>
<button class="btn bg" id="bTo" onclick="setView('t')"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg><span>Vista Superior</span></button>
<div class="ts"></div>
<button class="btn bg" id="bW" onclick="toggleWalls()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="1"/><line x1="2" y1="10" x2="22" y2="10"/><line x1="2" y1="16" x2="22" y2="16"/><line x1="8" y1="10" x2="8" y2="4"/><line x1="16" y1="16" x2="16" y2="10"/></svg><span>Paredes</span></button>
<button class="btn bg" id="bR" onclick="toggleRoof()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 12 12 3 21 12"/><path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7"/></svg><span>Teto</span></button>
<div class="ts"></div>
<button class="btn bg" id="bAI" onclick="toggleAI()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg><span>Planta IA</span></button>
<button class="btn bg" id="bEdit" onclick="toggleEditMode()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg><span>Editar</span></button>
<button class="btn bg" id="bK" onclick="togglePanel('kpanel','bK')"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="14" rx="1"/><path d="M16 7V5a2 2 0 0 0-4 0v2"/><circle cx="8.5" cy="12.5" r="1.5"/><circle cx="15.5" cy="12.5" r="1.5"/><circle cx="8.5" cy="17.5" r="1.5"/></svg><span>Cozinha</span></button>
<div class="ts"></div>
<button class="btn bg" onclick="resetCam()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg><span>Reset</span></button>
<button class="btn bg" id="b360" onclick="toggle360()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="12" rx="10" ry="4"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10"/><path d="M12 2a15.3 15.3 0 0 0-4 10 15.3 15.3 0 0 0 4 10"/></svg><span>Tour 360°</span></button>
</div>
<div id="hint">Arraste · Scroll zoom · Botão direito mover — Gere uma planta pelo painel <strong style="color:var(--gold)">IA</strong></div>
<div id="tour360-indicator" style="display:none;position:fixed;top:70px;left:50%;transform:translateX(-50%);z-index:30;background:rgba(184,147,90,.18);border:1px solid rgba(184,147,90,.5);border-radius:30px;padding:7px 20px;font-size:12px;color:var(--gold);letter-spacing:.08em;backdrop-filter:blur(12px);pointer-events:none">
<span style="display:inline-flex;align-items:center;gap:8px">
<span style="width:8px;height:8px;background:var(--gold);border-radius:50%;display:inline-block;animation:pulse360 1s ease-in-out infinite"></span>
Tour 360° ativo — clique em qualquer lugar ou pressione ESC para parar
</span>
</div>
<div id="ext-sel-panel">
<span class="gizmo-lbl" id="ext-sel-lbl">Objeto</span>
<span class="gizmo-sep"></span>
<button class="gbtn" onclick="extRotate(-Math.PI/8)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M2.5 2v6h6"/><path d="M2.66 15.57a10 10 0 1 0 .57-8.38"/></svg> -45°</button>
<button class="gbtn" onclick="extRotate(Math.PI/8)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M21.5 2v6h-6"/><path d="M21.34 15.57a10 10 0 1 1-.57-8.38"/></svg> +45°</button>
<button class="gbtn" onclick="extRotate(Math.PI/2)">⟳ 90°</button>
<span class="gizmo-sep"></span>
<button class="gbtn" onclick="extResetPos()"><svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg> Reposicionar</button>
<span class="gizmo-sep"></span>
<button class="gbtn danger" onclick="extDelete()"><svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/></svg> Remover</button>
<span class="gizmo-sep"></span>
<button class="gbtn" onclick="extDeselect()">×</button>
</div>
<div id="ext-mode-hint">Modo Externo — Clique para selecionar · Arraste para mover · Scroll = zoom</div>
<div class="edit-hint" id="edit-hint">Modo Edição Universal — Clique em qualquer objeto para selecionar · Arraste para mover · ESC para sair</div>
<div id="cmp"><svg id="csw" viewBox="0 0 32 32" width="30" height="30" fill="none" style="transition:transform .2s"><circle cx="16" cy="16" r="13" stroke="rgba(184,147,90,0.3)" stroke-width="1"/><polygon points="16,3 18,15 16,13 14,15" fill="#c04030"/><polygon points="16,29 18,17 16,19 14,17" fill="#555"/><text x="16" y="2.5" text-anchor="middle" fill="#c04030" font-size="3.5" font-family="Jost,sans-serif">N</text></svg></div>
<div id="kpanel" class="spanel">
<div class="pt" style="margin-bottom:12px;display:flex;align-items:center;gap:7px"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="var(--gold)" stroke-width="1.8" stroke-linecap="round"><rect x="2" y="7" width="20" height="14" rx="1"/><path d="M16 7V5a2 2 0 0 0-4 0v2"/><circle cx="8.5" cy="12.5" r="1.5"/><circle cx="15.5" cy="12.5" r="1.5"/><circle cx="8.5" cy="17.5" r="1.5"/></svg>Cozinha</div>
<div class="krow"><span class="klabel">Fogão</span><button class="kbtn" onclick="cycleStove()"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/></svg><span id="stoveLbl">Pos 1</span></button></div>
<div class="krow"><span class="klabel">Bancos ↑↓</span><div class="karr"><button class="kbtn" onclick="moveStools(0,-0.35)"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><polyline points="18 15 12 9 6 15"/></svg></button><button class="kbtn" onclick="moveStools(0,0.35)"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><polyline points="6 9 12 15 18 9"/></svg></button></div></div>
<div class="krow"><span class="klabel">Bancos ←→</span><div class="karr"><button class="kbtn" onclick="moveStools(-0.3,0)"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><polyline points="15 18 9 12 15 6"/></svg></button><button class="kbtn" onclick="moveStools(0.3,0)"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><polyline points="9 18 15 12 9 6"/></svg></button></div></div>
<div style="text-align:right;padding-top:5px"><span class="kval" id="stoolPos">—</span></div>
</div>
<div id="epanel" class="spanel" style="display:none!important"></div>
<div id="editpanel" class="spanel">
<div class="pt" style="margin-bottom:10px;display:flex;align-items:center;gap:7px"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="var(--gold)" stroke-width="1.8" stroke-linecap="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>Modo Edição</div>
<div class="eprow"><div style="font-size:10px;color:var(--ui-muted);margin-bottom:3px">Selecionado</div><div class="selinfo" id="sel-info">Nenhum</div></div>
<div class="eprow"><div style="font-size:10px;color:var(--ui-muted);margin-bottom:0">Adicionar Móvel</div>
<div class="add-grid"><button class="add-btn" onclick="spawnFurn('sofa')">Sofá</button><button class="add-btn" onclick="spawnFurn('cama')">Cama</button><button class="add-btn" onclick="spawnFurn('mesa')">Mesa</button><button class="add-btn" onclick="spawnFurn('cadeira')">Cadeira</button><button class="add-btn" onclick="spawnFurn('armario')">Armário</button><button class="add-btn" onclick="spawnFurn('planta')">Planta</button></div>
</div>
<button class="del-btn" id="del-btn" onclick="deleteSelected()" disabled><svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/></svg>Remover Item</button>
</div>
<div id="deco-fab-label">Decoração</div>
<button id="deco-fab" onclick="togglePanel('dpanel','deco-fab')">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="rgba(12,10,8,.85)" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="12" r="9"/><circle cx="7" cy="12" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="10" cy="8" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="14" cy="8" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/><circle cx="17" cy="12" r="1.5" fill="rgba(12,10,8,.85)" stroke="none"/></svg>
</button>
<div id="dpanel" class="spanel">
<div class="dpt"><svg width="14" height="14" viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="7" stroke="var(--gold)" stroke-width="1"/><circle cx="4.5" cy="9" r="1.2" fill="#c04030"/><circle cx="7" cy="6" r="1.2" fill="#4a8a50"/><circle cx="10" cy="6" r="1.2" fill="#4878b0"/><circle cx="12" cy="9" r="1.2" fill="var(--gold)"/></svg>Decoração</div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot"></div>Cor das Paredes</div><div class="dswatches" id="sw-wall"><div class="dsw act" data-hex="f0ebe0" style="background:#f0ebe0" title="Areia"></div><div class="dsw" data-hex="e8e0d8" style="background:#e8e0d8" title="Off-White"></div><div class="dsw" data-hex="d4dde0" style="background:#d4dde0" title="Azul Névoa"></div><div class="dsw" data-hex="d8e4d4" style="background:#d8e4d4" title="Verde Sage"></div><div class="dsw" data-hex="e8d8d0" style="background:#e8d8d0" title="Rosa Quartz"></div><div class="dsw" data-hex="2e2a26" style="background:#2e2a26" title="Carvão"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#7a8ab0"></div>Sofá</div><div class="dswatches" id="sw-sofa"><div class="dsw act" data-hex="575048" style="background:#575048" title="Grafite"></div><div class="dsw" data-hex="3a4a5a" style="background:#3a4a5a" title="Azul Navy"></div><div class="dsw" data-hex="5a3a2e" style="background:#5a3a2e" title="Terracota"></div><div class="dsw" data-hex="7a8a70" style="background:#7a8a70" title="Verde Musgo"></div><div class="dsw" data-hex="9a8878" style="background:#9a8878" title="Bege Camel"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#c8a870"></div>Piso</div><div class="dswatches" id="sw-floor"><div class="dsw act" data-hex="c8a870" style="background:#c8a870" title="Madeira Clara"></div><div class="dsw" data-hex="7a5a3a" style="background:#7a5a3a" title="Madeira Escura"></div><div class="dsw" data-hex="d4cfc8" style="background:#d4cfc8" title="Concreto"></div><div class="dsw" data-hex="c8b89a" style="background:#c8b89a" title="Carvalho"></div><div class="dsw" data-hex="3a3530" style="background:#3a3530" title="Wengué"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#f0f0e8"></div>Teto</div><div class="dswatches" id="sw-ceil"><div class="dsw act" data-hex="f8f3ec" style="background:#f8f3ec" title="Branco Quente"></div><div class="dsw" data-hex="ffffff" style="background:#ffffff" title="Branco Puro"></div><div class="dsw" data-hex="dde8f0" style="background:#dde8f0" title="Azul Gelo"></div><div class="dsw" data-hex="1a1a1a" style="background:#1a1a1a" title="Preto"></div></div></div>
<div class="dps"></div>
<div class="dgroup"><div class="dlabel"><div class="dlabel-dot" style="background:#8a6850"></div>Tapete</div><div class="dswatches" id="sw-rug"><div class="dsw act" data-hex="584030" style="background:#584030" title="Terracota"></div><div class="dsw" data-hex="3a4a58" style="background:#3a4a58" title="Azul"></div><div class="dsw" data-hex="485840" style="background:#485840" title="Verde"></div><div class="dsw" data-hex="585040" style="background:#585040" title="Oliva"></div><div class="dsw" data-hex="e0d8cc" style="background:#e0d8cc" title="Creme"></div></div></div>
</div>
<div id="ai-overlay" onclick="closeAI()"></div>
<div id="aipanel">
<div class="ai-header"><div><div class="ai-title">Assistente de Planta</div><div class="ai-sub">Informe as dimensões e programa — o sistema gera a planta 3D do zero, proceduralmente.</div></div><button class="ai-close" onclick="closeAI()"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button></div>
<div class="ai-body" id="ai-body">
<div id="ai-form">
<div class="ai-sec"><div class="ai-sec-t">Dimensões do Terreno</div><div class="ai-grid"><div class="ai-field"><label class="ai-label">Largura (m)</label><input class="ai-input" id="ai-w" type="number" min="4" max="50" step=".5" value="6" oninput="calcArea()"></div><div class="ai-field"><label class="ai-label">Comprimento (m)</label><input class="ai-input" id="ai-d" type="number" min="4" max="100" step=".5" value="8" oninput="calcArea()"></div></div><div class="ai-calc" id="ai-area-calc">— Área: <strong style="color:var(--gold)">48 m²</strong></div></div>
<div class="ai-sec"><div class="ai-sec-t">Programa de Necessidades</div><div class="ai-grid"><div class="ai-field"><label class="ai-label">Quartos (total)</label><input class="ai-input" id="ai-qts" type="number" min="1" max="5" value="2"></div><div class="ai-field"><label class="ai-label">Suítes</label><input class="ai-input" id="ai-suites" type="number" min="0" max="4" value="1" oninput="calcBaths()"></div><div class="ai-field"><label class="ai-label">Banh. Sociais</label><input class="ai-input" id="ai-bths-social" type="number" min="0" max="3" value="1" oninput="calcBaths()"></div><div class="ai-field" style="display:none"><input class="ai-input" id="ai-bths" type="number" value="2"></div></div><div class="ai-calc" id="bath-calc" style="font-size:9px;color:var(--ui-muted);margin-top:3px">— 1 suíte + 1 banheiro social = 2 banheiros</div></div>
<div class="ai-sec"><div class="ai-sec-t">Ambientes Desejados</div><div class="ai-checks"><label class="ai-chk selected"><input type="checkbox" id="chk-suite" checked><span>Suíte</span></label><label class="ai-chk selected"><input type="checkbox" id="chk-sala" checked><span>Sala de Estar</span></label><label class="ai-chk selected"><input type="checkbox" id="chk-coz" checked><span>Cozinha</span></label><label class="ai-chk"><input type="checkbox" id="chk-garagem"><span>Garagem</span></label><label class="ai-chk"><input type="checkbox" id="chk-servico"><span>Área de Serviço</span></label><label class="ai-chk"><input type="checkbox" id="chk-escritorio"><span>Escritório</span></label></div></div>
<div class="ai-sec"><div class="ai-sec-t">Prioridade</div><div class="ai-selwrap"><select class="ai-select" id="ai-prio"><option value="aproveitamento">Melhor aproveitamento de área</option><option value="conforto">Conforto e espaço interno</option><option value="ventilacao">Ventilação e iluminação natural</option><option value="custo">Menor custo construtivo</option><option value="fachada">Fachada valorizada</option></select></div></div>
</div>
<div id="ai-result-wrap" style="display:none"></div>
</div>
<div class="ai-footer">
<button class="ai-btn ai-btn-p" id="ai-gen-btn" onclick="runGenerate()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" style="display:inline;vertical-align:middle;margin-right:5px"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>Gerar Planta 3D</button>
<button class="ai-btn ai-btn-s" id="ai-var-btn" style="display:none" onclick="runVariation()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" style="display:inline;vertical-align:middle;margin-right:5px"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg>Nova Variação</button>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script>
'use strict';
// ═══════════════════════════════════════════════════
// RENDERER + SCENE SETUP
// ═══════════════════════════════════════════════════
const canvas = document.getElementById('c');
const R = new THREE.WebGLRenderer({canvas, antialias:true});
R.setPixelRatio(Math.min(window.devicePixelRatio,2));
R.shadowMap.enabled=true; R.shadowMap.type=THREE.PCFSoftShadowMap;
R.outputEncoding=THREE.sRGBEncoding; R.toneMapping=THREE.ACESFilmicToneMapping;
R.toneMappingExposure=1.2; R.physicallyCorrectLights=true;
const scene=new THREE.Scene(); scene.background=new THREE.Color(0x0d0b09);
scene.fog=new THREE.Fog(0x0d0b09,40,100);
const camera=new THREE.PerspectiveCamera(42,1,.1,300);
// ═══════════════════════════════════════════════════
// GLOBAL STATE
// ═══════════════════════════════════════════════════
let gStructure=null, gFurniture=null, gExternal=null, gRoof=null;
let currentRooms=[], buildingCfg=null;
let furnitureItems=[]; // {group, type, label}
let selectedItem=null;
let editMode=false;
let wVis=true, rVis=true;
let gStove=null, stoolGroups=[], stoolBX=0, stoolBZ=0;
let _stoveIdx=0;
const extGroups={}; // keyed groups from buildExternal (always-visible layer)
const extObjects=[]; // {group, key, label} — draggable external objects
let selExtObj=null; // currently selected external object
let extDragTarget=null;
let extDragOffset=new THREE.Vector3();
let extDragPlane=new THREE.Plane(new THREE.Vector3(0,1,0),0);
let extSelHL=null; // BoxHelper for selected external object
const WT=0.12, H=2.8;
// ═══════════════════════════════════════════════════
// TEXTURES
// ═══════════════════════════════════════════════════
function tex(sz,fn){const c=document.createElement('canvas');c.width=c.height=sz;fn(c.getContext('2d'),sz);return new THREE.CanvasTexture(c);}
const tWood=tex(512,(ctx,s)=>{const g=ctx.createLinearGradient(0,0,s,0);g.addColorStop(0,'#c8a870');g.addColorStop(.5,'#b89860');g.addColorStop(1,'#c4a46c');ctx.fillStyle=g;ctx.fillRect(0,0,s,s);for(let i=0;i<24;i++){ctx.strokeStyle=`rgba(80,50,18,${.05+Math.random()*.08})`;ctx.lineWidth=.5+Math.random()*1.5;ctx.beginPath();const y=i*(s/24);ctx.moveTo(0,y);for(let x=0;x<=s;x+=16)ctx.lineTo(x,y+(Math.random()-.5)*4);ctx.stroke();}for(let i=0;i<60;i++){ctx.strokeStyle=`rgba(100,60,20,${.02+Math.random()*.04})`;ctx.lineWidth=.4;ctx.beginPath();const x=Math.random()*s;ctx.moveTo(x,0);ctx.lineTo(x+(Math.random()*8-4),s);ctx.stroke();}});
tWood.wrapS=tWood.wrapT=THREE.RepeatWrapping;tWood.repeat.set(4,5);
const tWall=tex(256,(ctx,s)=>{ctx.fillStyle='#ece7de';ctx.fillRect(0,0,s,s);for(let i=0;i<4000;i++){ctx.fillStyle=`rgba(${120+Math.random()*60},${110+Math.random()*50},${90+Math.random()*40},.012)`;ctx.fillRect(Math.random()*s,Math.random()*s,2,2);}});
tWall.wrapS=tWall.wrapT=THREE.RepeatWrapping;tWall.repeat.set(2,1.2);
const tTile=tex(256,(ctx,s)=>{ctx.fillStyle='#d4e2ea';ctx.fillRect(0,0,s,s);const g=32;ctx.strokeStyle='rgba(120,160,185,.45)';ctx.lineWidth=1.5;for(let x=0;x<=s;x+=g){ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,s);ctx.stroke()}for(let y=0;y<=s;y+=g){ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(s,y);ctx.stroke()}});
tTile.wrapS=tTile.wrapT=THREE.RepeatWrapping;tTile.repeat.set(3,3);
const tMarble=tex(256,(ctx,s)=>{ctx.fillStyle='#e8dfd0';ctx.fillRect(0,0,s,s);for(let i=0;i<10;i++){ctx.beginPath();ctx.strokeStyle=`rgba(155,135,105,${.12+Math.random()*.18})`;ctx.lineWidth=.8+Math.random()*2;ctx.moveTo(Math.random()*s,Math.random()*s);for(let j=0;j<6;j++)ctx.bezierCurveTo(Math.random()*s,Math.random()*s,Math.random()*s,Math.random()*s,Math.random()*s,Math.random()*s);ctx.stroke();}});
const tFabric=tex(128,(ctx,s)=>{ctx.fillStyle='#605850';ctx.fillRect(0,0,s,s);for(let i=0;i<s;i+=3){ctx.strokeStyle=i%6===0?`rgba(80,72,64,.9)`:`rgba(68,60,54,.9)`;ctx.lineWidth=1.5;ctx.beginPath();ctx.moveTo(0,i);ctx.lineTo(s,i);ctx.stroke();}for(let i=0;i<s;i+=6){ctx.strokeStyle=`rgba(90,80,68,.3)`;ctx.lineWidth=.5;ctx.beginPath();ctx.moveTo(i,0);ctx.lineTo(i,s);ctx.stroke();}});
tFabric.wrapS=tFabric.wrapT=THREE.RepeatWrapping;tFabric.repeat.set(3,2);
// ═══════════════════════════════════════════════════
// MATERIALS
// ═══════════════════════════════════════════════════
const S=o=>new THREE.MeshStandardMaterial(o);
const M={
wall:S({map:tWall,color:0xf0ebe0,roughness:.88,metalness:0}),
wallInt:S({color:0xeae4d8,roughness:.9,metalness:0}),
floor:S({map:tWood,color:0xc8a870,roughness:.68,metalness:.02}),
floorTile:S({map:tTile,color:0xd0dde8,roughness:.25,metalness:.08}),
ceil:S({color:0xf8f3ec,roughness:.95,metalness:0,side:THREE.BackSide}),
wdDk:S({color:0x2e2016,roughness:.55,metalness:.04}),wdMd:S({color:0x5e4022,roughness:.62,metalness:.02}),wdLt:S({color:0x967040,roughness:.58,metalness:.02}),
fabric:S({map:tFabric,color:0x575048,roughness:.96,metalness:0}),fab2:S({color:0x6a6058,roughness:.96,metalness:0}),
linen:S({color:0xeae0d0,roughness:.92,metalness:0}),cushA:S({color:0xb86050,roughness:.94,metalness:0}),cushB:S({color:0x8a9878,roughness:.94,metalness:0}),
cntrtop:S({map:tMarble,color:0xddd4c0,roughness:.18,metalness:.12}),
ceramic:S({color:0xf0ede8,roughness:.12,metalness:.06}),cerW:S({color:0xe8e4e0,roughness:.08,metalness:.12}),
chrome:S({color:0xd0d0d0,roughness:.08,metalness:.96}),brass:S({color:0xb8963c,roughness:.18,metalness:.92}),darkM:S({color:0x202020,roughness:.35,metalness:.85}),
glass:S({color:0xa8c8d8,roughness:.04,metalness:.08,transparent:true,opacity:.32}),glassM:S({color:0xb0c8d4,roughness:.12,metalness:.08,transparent:true,opacity:.28}),
dWood:S({color:0x7a5838,roughness:.48,metalness:.02}),frWood:S({color:0x8a6848,roughness:.52,metalness:.02}),
rug:S({color:0x584030,roughness:.99,metalness:0}),rugB:S({color:0x8a6850,roughness:.99,metalness:0}),
plant:S({color:0x486838,roughness:.9,metalness:0}),pot:S({color:0x9a7050,roughness:.58,metalness:.04}),
lampSh:S({color:0xf0e2b0,roughness:.84,metalness:0,emissive:0xffe090,emissiveIntensity:.06}),
lampOn:S({color:0xffe8a0,roughness:.8,metalness:0,emissive:0xffcc60,emissiveIntensity:.5}),
tvScrn:S({color:0x060808,roughness:.04,metalness:.85,emissive:0x080e1c,emissiveIntensity:.6}),
tvFrm:S({color:0x181818,roughness:.28,metalness:.75}),
picFrm:S({color:0x2e1e0e,roughness:.48,metalness:.04}),picA:S({color:0xd0b888,roughness:.82,metalness:0}),
selHL:S({color:0xd4b07a,roughness:.5,metalness:.3,emissive:0xb8935a,emissiveIntensity:.15}),
};
// ═══════════════════════════════════════════════════
// GEOMETRY HELPERS
// ═══════════════════════════════════════════════════
const bx=(w,h,d)=>new THREE.BoxGeometry(w,h,d);
const cy=(rt,rb,h,s=16)=>new THREE.CylinderGeometry(rt,rb,h,s);
const sp=(r,w=12,h=9)=>new THREE.SphereGeometry(r,w,h);
const tor=(r,t,rs=8,ts=18)=>new THREE.TorusGeometry(r,t,rs,ts);
const con=(r,h,s=10)=>new THREE.ConeGeometry(r,h,s);
function mk(geo,mat,x=0,y=0,z=0,rx=0,ry=0,rz=0,cast=true,recv=true){const m=new THREE.Mesh(geo,mat);m.position.set(x,y,z);m.rotation.set(rx,ry,rz);m.castShadow=cast;m.receiveShadow=recv;return m;}
function add(g,...ms){ms.forEach(m=>g.add(m));return ms[0];}
// ═══════════════════════════════════════════════════
// STATIC SCENE (grid, ground, ambient lights)
// ═══════════════════════════════════════════════════
scene.add(new THREE.AmbientLight(0xfff8ee,.42));
const sun=new THREE.DirectionalLight(0xfff4d4,2.0);
sun.position.set(14,28,12);sun.castShadow=true;
sun.shadow.mapSize.set(4096,4096);
const sc=sun.shadow.camera;sc.near=1;sc.far=100;sc.left=sc.bottom=-24;sc.right=sc.top=24;
sun.shadow.bias=-.0005;sun.shadow.normalBias=.03;
scene.add(sun);
const fl2=new THREE.DirectionalLight(0xc8d4f0,.45);fl2.position.set(-12,8,-10);scene.add(fl2);
const gnd=mk(new THREE.PlaneGeometry(120,120),S({color:0x0a0806,roughness:1,metalness:0}),0,-.12,0,-Math.PI/2);
gnd.receiveShadow=true;scene.add(gnd);
scene.add(new THREE.GridHelper(80,80,0x1a1510,0x141210));
// ═══════════════════════════════════════════════════
// WALL BUILDER (with doors & windows cut)
// ═══════════════════════════════════════════════════
// ops: [{t:0-1, w, h, type:'door'|'window', sill?}]
function wallSegs(len,mat,ops=[]){
const g=new THREE.Group();
const sorted=[...ops].sort((a,b)=>a.t-b.t);
let cur=0;
for(const op of sorted){
const oL=op.t*len-op.w/2, oR=op.t*len+op.w/2;
const pre=oL-cur;
if(pre>.015) g.add(mk(bx(pre,H,WT),mat,cur+pre/2-len/2,H/2,0));
const topH=H-op.h;
if(topH>.01) g.add(mk(bx(op.w,topH,WT),mat,op.t*len-len/2,op.h+topH/2,0));
if(op.type==='window'){
const sill=op.sill||.8;
g.add(mk(bx(op.w,sill,WT),mat,op.t*len-len/2,sill/2,0));
const wg=new THREE.Group();
wg.add(mk(bx(op.w+.08,op.h+.08,WT+.03),M.frWood,0,0,0));
wg.add(mk(bx(op.w*.47,op.h*.86,.04),M.glass,-op.w*.24,0,0));
wg.add(mk(bx(op.w*.47,op.h*.86,.04),M.glass,op.w*.24,0,0));
wg.add(mk(bx(op.w-.03,.03,.06),M.frWood,0,0,.01));
wg.add(mk(bx(.03,op.h-.03,.06),M.frWood,0,0,.01));
wg.position.set(op.t*len-len/2,sill+op.h/2,0);
g.add(wg);
} else if(op.type==='door'){
const df=new THREE.Group();
df.add(mk(bx(.07,op.h+.1,WT+.04),M.frWood,-op.w/2-.04,(op.h+.1)/2,0));
df.add(mk(bx(.07,op.h+.1,WT+.04),M.frWood,op.w/2+.04,(op.h+.1)/2,0));
df.add(mk(bx(op.w+.14,.07,WT+.04),M.frWood,0,op.h+.04,0));
const piv=new THREE.Group(); piv.position.set(-op.w/2+.04,0,0);
piv.add(mk(bx(op.w-.07,op.h-.04,.04),M.dWood,(op.w-.07)/2,(op.h-.04)/2,.01));
piv.add(mk(sp(.028,6,4),M.brass,op.w-.1,op.h*.5,.035));
piv.rotation.y=Math.PI*.13;
df.add(piv);
df.position.set(op.t*len-len/2,0,0);
g.add(df);
}
cur=oR;
}
const post=len-cur;
if(post>.015) g.add(mk(bx(post,H,WT),mat,cur+post/2-len/2,H/2,0));
return g;
}
function wallX(group,x1,x2,z,mat,ops=[]){
const len=Math.abs(x2-x1);if(len<.05)return;
const wg=wallSegs(len,mat,ops);
wg.position.set((x1+x2)/2,0,z);group.add(wg);return wg;
}
function wallZ(group,x,z1,z2,mat,ops=[]){
const len=Math.abs(z2-z1);if(len<.05)return;
const wg=wallSegs(len,mat,ops);
wg.position.set(x,0,(z1+z2)/2);wg.rotation.y=-Math.PI/2;group.add(wg);return wg;
}
// ═══════════════════════════════════════════════════
// ROOM LAYOUT ENGINE
// ═══════════════════════════════════════════════════
// ═══════════════════════════════════════════════════
// ROOM LAYOUT ENGINE — lógica corrigida de suítes e banheiros
// Regras:
// - suitesQty: quantos quartos têm banheiro integrado (suíte)
// - bthsSocial: quantos banheiros ficam na circulação comum
// - Suítes ficam nos primeiros quartos (começando pelo 1°)
// - Banheiro social fica no corredor da zona íntima
// ═══════════════════════════════════════════════════
function computeRooms(cfg){
const {planW,planD,quartos,banheiros,sala,cozinha,garagem,servico}=cfg;
// Quantas suítes e banheiros sociais (com fallback para legado)
const suitesQty = cfg.suitesQty !== undefined ? Math.min(cfg.suitesQty, quartos) : (cfg.suite ? 1 : 0);
const bthsSocial = cfg.bthsSocial !== undefined ? cfg.bthsSocial : Math.max(0, banheiros - suitesQty);
const rooms=[];
const midX=planW/2;
const bedD=planD/quartos;
const bathW=Math.min(1.75,midX*.62);
const bathD=Math.min(1.65,bedD*.42);
// ── Zona privada: quartos + banheiros integrados (suítes) ──
for(let i=0;i<quartos;i++){
const qz=i*bedD;
const isSuite = i < suitesQty; // primeiros quartos são suítes
if(isSuite){
// Suíte: banheiro integrado no próprio quarto
const abd=Math.min(bathD,bedD*.42);
rooms.push({
type:'banheiro',id:`wc-suite${i+1}`,
label:`Banheiro Suíte ${i+1}`,
x:0,z:qz+bedD-abd,w:bathW,d:abd
});
rooms.push({
type:'suite',id:`suite${i+1}`,
label: i===0 ? 'Suíte Casal' : `Suíte ${i+1}`,
x:0,z:qz,w:midX,d:bedD-abd
});
} else {
// Quarto simples: sem banheiro próprio
rooms.push({
type:'quarto',id:`q${i+1}`,
label:`Quarto ${String(i+1).padStart(2,'0')}`,
x:0,z:qz,w:midX,d:bedD
});
}
}
// ── Banheiro(s) social(is): na zona de circulação, entre quartos ──
// Posiciona após o último quarto, dentro da zona privada
for(let bs=0;bs<bthsSocial;bs++){
const socialZ = planD * (0.45 + bs * 0.18); // distribui verticalmente
const socialD = Math.min(1.6, bedD*.38);
const socialW = Math.min(1.7, midX*.58);
rooms.push({
type:'banheiro',id:`wc-social${bs+1}`,
label: bthsSocial===1 ? 'Banheiro Social' : `Banheiro Social ${bs+1}`,
x:midX*.12, // ligeiramente recuado do eixo
z:Math.min(planD-socialD-.1,socialZ),
w:socialW,d:socialD
});
}
// ── Zona social (right x=midX..planW) ──
let sz=0;
if(garagem){const gd=Math.min(3.4,planD*.38);rooms.push({type:'garagem',id:'garagem',label:'Garagem',x:midX,z:0,w:midX,d:gd});sz=gd;}
const srvD=servico?Math.min(1.9,(planD-sz)*.17):0;
const mainD=planD-sz-srvD;
if(cozinha&&sala){const kd=mainD*.41;rooms.push({type:'cozinha',id:'cozinha',label:'Cozinha',x:midX,z:sz,w:midX,d:kd});rooms.push({type:'sala',id:'sala',label:'Sala de Estar',x:midX,z:sz+kd,w:midX,d:mainD-kd});}
else if(cozinha){rooms.push({type:'cozinha',id:'cozinha',label:'Cozinha',x:midX,z:sz,w:midX,d:mainD});}
else if(sala){rooms.push({type:'sala',id:'sala',label:'Sala de Estar',x:midX,z:sz,w:midX,d:mainD});}
if(servico){rooms.push({type:'servico',id:'servico',label:'\u00c1rea de Servi\u00e7o',x:midX,z:planD-srvD,w:midX,d:srvD});}
return rooms;
}
// ═══════════════════════════════════════════════════
// STRUCTURE BUILDERS
// ═══════════════════════════════════════════════════
function buildFloors(group,rooms,planW,planD){
group.add(mk(bx(planW+.4,.14,planD+.4),S({color:0x7a7060,roughness:.9,metalness:.02}),planW/2,-.07,planD/2,0,0,0,false,true));
for(const r of rooms){
const mat=r.type==='banheiro'?M.floorTile:M.floor;
group.add(mk(bx(r.w-.01,.015,r.d-.01),mat,r.x+r.w/2,.008,r.z+r.d/2,0,0,0,false,true));
}
}
function buildWalls(group,rooms,planW,planD){
const midX=planW/2;
const bedrooms=rooms.filter(r=>r.type==='quarto'||r.type==='suite');
const baths=rooms.filter(r=>r.type==='banheiro');
const kit=rooms.find(r=>r.type==='cozinha');
const sala=rooms.find(r=>r.type==='sala');
// Entry door — right half front
const entryT=(midX+midX/2)/planW;
// North exterior
const nOps=[{t:entryT,w:.88,h:2.1,type:'door'}];
if(bedrooms.length>0)nOps.push({t:(bedrooms[0].x+bedrooms[0].w/2)/planW,w:.94,h:.9,sill:.8,type:'window'});
wallX(group,0,planW,WT/2,M.wall,nOps);
// South exterior
const sOps=[{t:.25,w:.94,h:.9,sill:.8,type:'window'},{t:.75,w:.94,h:.9,sill:.8,type:'window'}];
wallX(group,0,planW,planD-WT/2,M.wall,sOps);
// West exterior — bedroom windows
const wOps=bedrooms.map(r=>({t:(r.z+r.d/2)/planD,w:.94,h:.9,sill:.8,type:'window'}));
baths.forEach(b=>wOps.push({t:(b.z+b.d/2)/planD,w:.48,h:.5,sill:1.5,type:'window'}));
wallZ(group,WT/2,0,planD,M.wall,wOps);
// East exterior — social windows
const eOps=[];
if(kit)eOps.push({t:(kit.z+kit.d/2)/planD,w:1.0,h:.9,sill:.8,type:'window'});
if(sala)eOps.push({t:(sala.z+sala.d/2)/planD,w:1.1,h:.9,sill:.8,type:'window'});
if(!eOps.length)eOps.push({t:.5,w:1.0,h:.9,sill:.8,type:'window'});
wallZ(group,planW-WT/2,0,planD,M.wall,eOps);
// Interior divider x=midX
const divDoors=bedrooms.map(r=>({t:(r.z+r.d/2)/planD,w:.8,h:2.1,type:'door'}));
if(!divDoors.length)divDoors.push({t:.5,w:.8,h:2.1,type:'door'});
wallZ(group,midX,WT/2,planD-WT/2,M.wallInt,divDoors);
// Bedroom horizontal dividers
for(let i=0;i<bedrooms.length-1;i++){const z=bedrooms[i].z+bedrooms[i].d;wallX(group,WT/2,midX-WT/2,z,M.wallInt,[]);}
// Bathroom walls
for(const b of baths){
wallX(group,b.x,b.x+b.w,b.z,M.wallInt,[]);
wallZ(group,b.x+b.w,b.z,b.z+b.d,M.wallInt,[{t:.5,w:.7,h:2.1,type:'door'}]);
}
// Baseboard
const bm=S({color:0xf0ece4,roughness:.78});
group.add(mk(bx(planW-.24,.08,.04),bm,planW/2,.04,WT*.9,0,0,0,false));
group.add(mk(bx(planW-.24,.08,.04),bm,planW/2,.04,planD-WT*.9,0,0,0,false));
group.add(mk(bx(.04,.08,planD),bm,WT*.9,.04,planD/2,0,0,0,false));
group.add(mk(bx(.04,.08,planD),bm,planW-WT*.9,.04,planD/2,0,0,0,false));
}
function buildRoof(group,planW,planD){
group.add(mk(bx(planW-.24,.06,planD-.24),M.ceil,planW/2,H,planD/2,0,0,0,false,true));
group.add(mk(bx(planW+.35,.14,planD+.35),S({color:0xd8cca8,roughness:.82}),planW/2,H+.07,planD/2,0,0,0,true,false));
group.add(mk(bx(planW+.5,.06,planD+.5),S({color:0xc8bc98,roughness:.8}),planW/2,H+.04,planD/2,0,0,0,false,false));
}
// ═══════════════════════════════════════════════════
// FURNITURE REGISTRY
// ═══════════════════════════════════════════════════
function regFurn(group,type,label){
group.userData.isFurniture=true;group.userData.fType=type;group.userData.fLabel=label;
gFurniture.add(group);furnitureItems.push({group,type,label});return group;
}
// ═══════════════════════════════════════════════════
// AUTO-FURNISH BY ROOM TYPE
// ═══════════════════════════════════════════════════
function autoFurnish(rooms){
for(const r of rooms){
if(r.type==='quarto'||r.type==='suite') furnBedroom(r);
else if(r.type==='sala') furnLiving(r);
else if(r.type==='cozinha') furnKitchen(r);
else if(r.type==='banheiro') furnBath(r);
}
}
function furnBedroom(r){
const {x,z,w,d}=r;
// ── BED: centered in room width, against south wall (far from door) ──
const bw=Math.min(1.4,w-.38), bd=Math.min(2.0,d*.58);
// bed headboard against the far wall (z+d - margin)
const bx0=x+w/2;
const bz0=z+d-bd/2-.14;
if(bw>.85&&bd>1.2){
const bg=new THREE.Group();
const hw=bw/2*.8, hd=bd/2*.78;
[[-hw,-hd],[hw,-hd],[-hw,hd],[hw,hd]].forEach(([lx,lz])=>{bg.add(mk(bx(.09,.3,.09),M.wdDk,lx,.15,lz));bg.add(mk(bx(.11,.04,.11),M.wdLt,lx,.31,lz));});
bg.add(mk(bx(bw,.07,bd),M.wdDk,0,.32,0));
bg.add(mk(bx(bw,.86,.1),M.wdDk,0,.74,-bd/2+.05));
bg.add(mk(bx(bw*.84,.6,.055),M.wdMd,0,.76,-bd/2+.09));
bg.add(mk(bx(bw,.22,bd*.95),M.linen,0,.54,0));
bg.add(mk(bx(bw*.9,.12,bd*.8),S({color:0xe4ddd0,roughness:.94}),0,.69,.06));
[-.24,.24].forEach(px=>{bg.add(mk(bx(.43,.1,.31),M.linen,px*bw/1.4,.69,-bd/2+.36));});
bg.position.set(bx0,0,bz0);
regFurn(bg,'cama','Cama');
}
// ── NIGHTSTAND: beside bed, inside room bounds ──
if(w>2.0){
const ns=new THREE.Group();
ns.add(mk(bx(.45,.43,.38),M.wdDk,0,.215,0));
ns.add(mk(bx(.43,.022,.36),M.cntrtop,0,.435,0));
ns.add(mk(cy(.024,.024,.24,8),M.brass,0,.55,0));
ns.add(mk(cy(.11,.09,.17,12),M.lampSh,0,.72,0));
ns.add(mk(sp(.038,6,4),M.lampOn,0,.645,0));
// clamp nightstand to room bounds
const nsX=Math.min(x+w-.26, bx0+bw/2+.28);
ns.position.set(nsX, 0, bz0);
regFurn(ns,'mesinha','Mesa de Cabeceira');
}
// ── WARDROBE: against the near wall (z=z+margin), centered ──
if(d>2.2){
const wg=new THREE.Group();
const wdW=Math.min(1.32,w-.18);
wg.add(mk(bx(wdW,2.12,.55),M.wdDk,0,1.06,0));
wg.add(mk(bx(wdW-.03,2.09,.52),S({color:0x3a2410,roughness:.52}),0,1.06,.015));
wg.add(mk(bx(.014,2.03,.53),M.wdLt,0,1.06,0));
[-.21,.21].forEach(hx=>wg.add(mk(bx(.038,.13,.03),M.brass,hx*wdW/1.32,1.06,.282)));
// against near wall but leaving door clearance on z side
wg.position.set(x+w/2, 0, z+.32);
regFurn(wg,'armario','Guarda-Roupa');
}
// ── BEDROOM RUG (optional, if enough space) ──
if(w>2.4&&d>3.0){
const rg=new THREE.Group();
rg.add(mk(bx(1.5,.016,1.1),M.rug,0,0,0,false,true));
rg.add(mk(bx(1.5,.017,.05),M.rugB,0,0,-.54,false,true));
rg.add(mk(bx(1.5,.017,.05),M.rugB,0,0,.54,false,true));
rg.position.set(bx0,.009,bz0+.4);
regFurn(rg,'tapete','Tapete Quarto');
}
}
function furnLiving(r){
const {x,z,w,d}=r;
const cx=x+w/2;
const sw=Math.min(2.08,w-.44), sd=.88;
// ── SOFA: against far wall, facing center ──
const sg=new THREE.Group();
sg.add(mk(bx(sw,.28,sd),M.wdDk,0,.14,0));
for(let i=0;i<3;i++){const sx=-sw/2+sw/6+i*(sw/3);sg.add(mk(bx(sw/3-.05,.17,sd-.05),M.fabric,sx,.36,0));sg.add(mk(bx(sw/3-.08,.37,.21),M.fabric,sx,.61,-(sd/2-.11)));}
sg.add(mk(bx(sw,.85,.09),M.wdDk,0,.7,-sd/2+.04));
[-sw/2-.055,sw/2+.055].forEach(ax=>{sg.add(mk(bx(.088,.54,sd),M.wdDk,ax,.4,0));sg.add(mk(bx(.12,.06,sd+.04),M.wdLt,ax,.67,0));});
sg.add(mk(bx(.34,.24,.08),M.cushA,-.64,.62,-(sd/2-.17),0,.13));
sg.add(mk(bx(.34,.24,.08),M.cushB,.62,.62,-(sd/2-.17),0,-.12));
// sofa against south wall of room, facing TV (north)
sg.position.set(cx, 0, z+d-sd/2-.14);
sg.rotation.y=Math.PI;
regFurn(sg,'sofa','Sofá');
// ── TV + RACK: against near wall (north) ──
const tvg=new THREE.Group();
const tvW=Math.min(1.48,w-.36);
tvg.add(mk(bx(tvW,.45,.38),M.wdDk,0,.225,0));
tvg.add(mk(bx(tvW-.02,.42,.35),S({color:0x28180a,roughness:.5}),0,.225,.014));
tvg.add(mk(bx(tvW,.024,.4),M.wdLt,0,.45,0));
tvg.add(mk(bx(tvW*.88,.6,.044),M.tvFrm,0,.93,0));
tvg.add(mk(bx(tvW*.82,.55,.034),M.tvScrn,0,.93,.018));
// TV against north wall of room
tvg.position.set(cx, 0, z+.2);
regFurn(tvg,'tv','Rack + TV');
// ── COFFEE TABLE: centered between sofa and TV ──
if(d>3.2){
const midZ=z+(d*.5);
const tg=new THREE.Group();
tg.add(mk(bx(.9,.024,.48),M.glass,0,.37,0));
tg.add(mk(bx(.86,.018,.44),S({color:0x1c1a18,roughness:.4}),0,.35,0));
[[.36,.19],[-.36,.19],[.36,-.19],[-.36,-.19]].forEach(([lx,lz])=>tg.add(mk(bx(.022,.32,.022),M.brass,lx,.16,lz)));
tg.add(mk(cy(.048,.055,.065,10),M.pot,-.28,.384,.08));
tg.add(mk(sp(.085,8,6),M.plant,-.28,.48,.08));
tg.position.set(cx, 0, midZ);
regFurn(tg,'mesa','Mesa de Centro');
// Rug centered under coffee table + sofa area
const rg=new THREE.Group();
rg.add(mk(bx(1.9,.016,1.3),M.rug,0,0,0,false,true));
rg.add(mk(bx(1.9,.017,.052),M.rugB,0,0,-.64,false,true));
rg.add(mk(bx(1.9,.017,.052),M.rugB,0,0,.64,false,true));
rg.add(mk(bx(.052,.017,1.2),M.rugB,-.94,0,0,false,true));
rg.add(mk(bx(.052,.017,1.2),M.rugB,.94,0,0,false,true));
rg.position.set(cx,.009,midZ);
regFurn(rg,'tapete','Tapete');
}
// ── FLOOR LAMP: corner of room ──
const fl=new THREE.Group();
fl.add(mk(cy(.16,.16,.02,20),M.darkM,0,.01,0));
fl.add(mk(cy(.009,.009,1.4,8),M.brass,0,.71,0));
fl.add(mk(cy(.21,.15,.27,16),M.lampSh,0,1.56,0));
fl.add(mk(sp(.038,6,4),M.lampOn,0,1.44,0));
// lamp in far corner, away from walls slightly
fl.position.set(x+w-.38, 0, z+d-.38);
regFurn(fl,'luminaria','Luminária');
// ── WALL ART ──
if(d>2.6){
const ag=new THREE.Group();
ag.add(mk(bx(.52+.06,.38+.06,.03),M.picFrm,0,0,0));
ag.add(mk(bx(.52,.38,.024),M.picA,0,0,.005));
[[0xb87050,-.1,.06],[0x7a9278,.1,-.04],[0xd4c89a,0,0]].forEach(([col,px2,py])=>ag.add(mk(bx(.52*.28,.38*.28,.007),S({color:col,roughness:.84}),px2,py,.016)));
ag.position.set(cx, H*.64, z+WT+.022);
regFurn(ag,'quadro','Quadro');
}
}
// ── KITCHEN LAYOUT VARIANTS ──────────────────────
// variant 0 = linear, 1 = L-shape, 2 = compact+table
function furnKitchen(r){
const {x,z,w,d}=r;
// choose layout based on room proportions
const variant = w>d*1.3 ? 0 : (d>3.2 ? 1 : 2);
const wallMat=M.wdDk, counterMat=M.cntrtop;
const COUNTH=0.87, COUNTD=0.58;
// ── Common: geladeira (fridge) always against east wall ──
const fg=new THREE.Group();
const fW=0.68, fH=1.72, fD=0.62;
fg.add(mk(bx(fW,fH,fD),S({color:0xd4d0cc,roughness:.2,metalness:.55}),0,fH/2,0));
fg.add(mk(bx(fW-.02,fH*.55,fD-.01),S({color:0xbcb8b4,roughness:.18,metalness:.6}),0,fH*.73,0));
fg.add(mk(bx(fW-.02,fH*.43,fD-.01),S({color:0xbcb8b4,roughness:.18,metalness:.6}),0,fH*.25,0));
fg.add(mk(bx(.032,.13,.028),M.chrome,.24,fH*.73+.12,-(fD/2)));
fg.add(mk(bx(.032,.1,.028),M.chrome,.24,fH*.25+.1,-(fD/2)));
// fridge against east/right wall
fg.position.set(x+w-fW/2-.04, 0, z+fD/2+.06);
regFurn(fg,'geladeira','Geladeira');
if(variant===0){
// ── LINEAR: bancada + pia + fogão na parede norte (z=z+offset)
const cw=Math.min(w-fW-.12, w*.68), ch=COUNTH, cd=COUNTD;
const cStartX=x+cw/2+.06;
// armário inferior + bancada
const cg=new THREE.Group();
cg.add(mk(bx(cw,ch,cd),wallMat,0,ch/2,0));
cg.add(mk(bx(cw+.02,.04,cd+.02),counterMat,0,ch+.02,0));
for(let i=0;i<Math.floor(cw/.45);i++){
const dw=cw/Math.floor(cw/.45)-.04;
const dx=-cw/2+dw/2+i*(cw/Math.floor(cw/.45))+.02;
cg.add(mk(bx(dw,ch-.06,.016),S({color:0xf4efea,roughness:.68}),dx,ch/2,-(cd/2)));
cg.add(mk(bx(.04,.1,.02),M.brass,dx,ch*.44,-(cd/2)-.01));
}
cg.position.set(cStartX, 0, z+cd/2+.06);
regFurn(cg,'bancada','Bancada');
// armário superior
const uc=new THREE.Group();
uc.add(mk(bx(cw*.7,.6,.32),wallMat,0,0,0));
for(let i=0;i<3;i++){const dw=cw*.7/3-.03,dx=-cw*.7/2+dw/2+i*(cw*.7/3)+.01;uc.add(mk(bx(dw,.56,.016),S({color:0xf4efea,roughness:.68}),dx,0,-.16));uc.add(mk(bx(.03,.08,.02),M.chrome,dx,-.05,-.17));}
uc.position.set(cStartX, H*.67, z+.22);
regFurn(uc,'armSuper','Arm. Suspenso');
// pia integrada na bancada (offset within counter)
const sinkG=new THREE.Group();
sinkG.add(mk(bx(.52,.07,.36),S({color:0xb8c0c4,roughness:.12,metalness:.7}),0,0,0));
sinkG.add(mk(bx(.44,.05,.28),S({color:0x8090a0,roughness:.08,metalness:.75}),.0,-.02,0));
sinkG.add(mk(bx(.032,.14,.028),M.chrome,-.12,.1,0));
sinkG.add(mk(cy(.03,.03,.12,8),M.chrome,-.04,.1,-.06));
sinkG.position.set(x+cw*.35, ch+.04, z+cd/2+.06);
regFurn(sinkG,'pia','Pia');
// fogão posicionado na bancada
_buildStove(r, x+cw*.72, z+COUNTD/2+.06, 0);
} else if(variant===1){
// ── L-SHAPE: bancada na parede norte + lateral oeste ──
const cwN=w*.72, chh=COUNTH, cdN=COUNTD;
const cwL=d*.46;