dotmax 0.1.11

High-performance terminal braille rendering for images, animations, and graphics
Documentation
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
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
//! Architecture / construction progress bars.
//!
//! Thirteen structurally distinct styles, each animating a different building
//! form or construction activity:
//!
//! - `skyscraper`       — glass towers top out one by one, lit windows twinkle
//! - `suspension-bridge`— red pylons + main cable; deck launched span by span
//! - `gothic-arch`      — pointed lancet arches rise, fill with stained glass
//! - `brick-wall`       — running-bond masonry laid course by course, trowel sweeps
//! - `pyramid`          — three stepped pyramids rise course by course under a sun
//! - `scaffolding`      — standards, ledgers, boards and braces go up bay by bay
//! - `geodesic-dome`    — triangulated hemisphere assembles band by band
//! - `spiral-staircase` — looking down the well: treads laid along a spiral rail
//! - `roman-aqueduct`   — two arch tiers advance over a river; water flows on top
//! - `classical-column` — Ionic colonnade rises drum by drum under an entablature
//! - `blueprint`        — a drafting pen sweeps lines onto graph paper
//! - `tower-crane`      — lattice crane hoists beams as a frame rises beside it
//! - `colosseum`        — three arcade tiers + attic, ruined far end, built left to right

use super::super::draw;
use super::super::{BarContext, ProgressStyle};
use crate::{BrailleGrid, Color, DotmaxError};

// ─────────────────────────────────────────────────────────────────────────────
// Registry
// ─────────────────────────────────────────────────────────────────────────────

/// All styles in the `architecture` theme.
///
/// Returns thirteen `Box<dyn ProgressStyle>` values, each implementing a
/// structurally distinct architecture/construction scene in braille dot space.
pub fn styles() -> Vec<Box<dyn ProgressStyle>> {
    vec![
        Box::new(Skyscraper),
        Box::new(SuspensionBridge),
        Box::new(GothicArch),
        Box::new(BrickWall),
        Box::new(Pyramid),
        Box::new(Scaffolding),
        Box::new(GeodesicDome),
        Box::new(SpiralStaircase),
        Box::new(RomanAqueduct),
        Box::new(ClassicalColumn),
        Box::new(Blueprint),
        Box::new(TowerCrane),
        Box::new(Colosseum),
    ]
}

// ─────────────────────────────────────────────────────────────────────────────
// Shared helpers
// ─────────────────────────────────────────────────────────────────────────────

/// Set a dot from signed coordinates and tint its cell — the one primitive the
/// hand-coloured scenes build on. Out-of-bounds writes are ignored.
fn paint(grid: &mut BrailleGrid, x: i32, y: i32, c: Color) {
    let (dw, dh) = draw::dot_dims(grid);
    if x < 0 || y < 0 || x as usize >= dw || y as usize >= dh {
        return;
    }
    draw::dot(grid, x as usize, y as usize);
    let _ = grid.set_cell_color(x as usize / 2, y as usize / 4, c);
}

/// Coloured horizontal run `x0..=x1` at row `y`.
fn paint_h(grid: &mut BrailleGrid, x0: i32, x1: i32, y: i32, c: Color) {
    for x in x0.min(x1)..=x0.max(x1) {
        paint(grid, x, y, c);
    }
}

/// Coloured vertical run `y0..=y1` at column `x`.
fn paint_v(grid: &mut BrailleGrid, x: i32, y0: i32, y1: i32, c: Color) {
    for y in y0.min(y1)..=y0.max(y1) {
        paint(grid, x, y, c);
    }
}

/// Coloured Bresenham line between two dot-space points.
fn paint_line(grid: &mut BrailleGrid, x0: i32, y0: i32, x1: i32, y1: i32, c: Color) {
    let (dx, dy) = ((x1 - x0).abs(), (y1 - y0).abs());
    let (sx, sy) = (if x0 < x1 { 1 } else { -1 }, if y0 < y1 { 1 } else { -1 });
    let (mut x, mut y, mut err) = (x0, y0, dx - dy);
    loop {
        paint(grid, x, y, c);
        if x == x1 && y == y1 {
            break;
        }
        let e2 = 2 * err;
        if e2 > -dy {
            err -= dy;
            x += sx;
        }
        if e2 < dx {
            err += dx;
            y += sy;
        }
    }
}

/// Cheap deterministic hash of three integers into `0.0..=1.0` — used for
/// window lights and stained-glass colours that flicker without state.
fn hash3(a: i32, b: i32, c: i32) -> f32 {
    let mut h = (a as u32).wrapping_mul(0x9E37_79B1)
        ^ (b as u32).wrapping_mul(0x85EB_CA77)
        ^ (c as u32).wrapping_mul(0xC2B2_AE3D);
    h ^= h >> 15;
    h = h.wrapping_mul(0x2C1B_3C6D);
    h ^= h >> 12;
    (h & 0xFFFF) as f32 / 65535.0
}

// ─────────────────────────────────────────────────────────────────────────────
// 1. Skyscraper
// ─────────────────────────────────────────────────────────────────────────────

/// A skyline of narrow glass towers tops out one by one, left to right. Each
/// finished tower gets a setback crown, an antenna with a blinking beacon and
/// twinkling lit windows; the tower going up is a bare steel frame with a
/// crane swinging on top.
struct Skyscraper;
impl ProgressStyle for Skyscraper {
    fn name(&self) -> &str {
        "skyscraper"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Glass towers top out one by one across a skyline; lit windows twinkle, beacons blink, a crane swings on the tower going up"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 4 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let ground = hi - 1;
        let steel = Color::rgb(120, 140, 172);
        let lit = Color::rgb(255, 214, 120);
        let frame = Color::rgb(150, 120, 90);
        let crane = Color::rgb(250, 190, 40);
        let beacon = Color::rgb(255, 60, 50);

        // Tower plan: (width in dots, height as a fraction of the sky).
        const PLAN: [(i32, f32); 6] = [
            (6, 0.72),
            (7, 1.0),
            (5, 0.6),
            (6, 0.88),
            (5, 0.68),
            (7, 0.95),
        ];
        let mut towers = Vec::new();
        let mut x = 2;
        while x < wi - 3 {
            let (tw, hf) = PLAN[towers.len() % PLAN.len()];
            let tw = tw.min(wi - 1 - x);
            if tw < 4 {
                break;
            }
            towers.push((x, tw, hf));
            x += tw + 3;
        }
        let built = ctx.eased * towers.len().max(1) as f32;
        let tick = (ctx.time * 1.5) as i32;

        for (k, &(x0, tw, hf)) in towers.iter().enumerate() {
            let frac = (built - k as f32).clamp(0.0, 1.0);
            if frac <= 0.0 {
                continue;
            }
            let full_h = (((hi - 3) as f32 * hf).round() as i32).max(3);
            let h = ((full_h as f32 * frac).ceil() as i32).max(1);
            let top = ground - h;
            let done = frac >= 1.0;
            let crown = ground - full_h + full_h / 4; // setback starts above here
            for y in top..ground {
                let inset = i32::from(tw >= 7 && y < crown);
                let (l, r) = (x0 + inset, x0 + tw - 1 - inset);
                // The top three floors of a rising tower are bare frame.
                let skeleton = !done && y < top + 3;
                let c = if skeleton { frame } else { steel };
                paint(grid, l, y, c);
                paint(grid, r, y, c);
                if skeleton {
                    if (ground - y) % 2 == 0 {
                        paint_h(grid, l, r, y, frame);
                    }
                } else if (ground - y) % 2 == 1 {
                    for wx in l + 1..r {
                        if hash3(wx, y, tick + k as i32 * 7) < 0.66 {
                            paint(grid, wx, y, lit);
                        }
                    }
                }
            }
            let inset = i32::from(tw >= 7 && top < crown);
            paint_h(grid, x0 + inset, x0 + tw - 1 - inset, top, steel);
            let mid = x0 + tw / 2;
            if done {
                // Antenna + blinking aviation beacon.
                paint_v(grid, mid, top - 2, top - 1, steel);
                if (ctx.time * 2.0 + k as f32).sin() > 0.0 {
                    paint(grid, mid, top - 3, beacon);
                }
            } else {
                // Tower crane on the rising frame: mast + swinging jib.
                let mast = x0 + 1;
                paint_v(grid, mast, top - 4, top - 1, crane);
                let reach = ((ctx.time * 1.3).cos() * (tw + 6) as f32) as i32;
                paint_h(grid, mast - 3, mast + reach, top - 4, crane);
                let hook = mast + reach * 3 / 4;
                paint_v(grid, hook, top - 3, top - 2, crane);
            }
        }
        paint_h(grid, 0, wi - 1, ground, Color::rgb(90, 90, 104));
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 2. Suspension Bridge
// ─────────────────────────────────────────────────────────────────────────────

/// Two tall pylons carry a sagging main cable; the road deck is launched left
/// to right under it, suspenders dropping onto each new span, while a car
/// shuttles along the finished deck above rippling water.
struct SuspensionBridge;
impl ProgressStyle for SuspensionBridge {
    fn name(&self) -> &str {
        "suspension-bridge"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Red pylons and a sagging main cable; the deck is launched span by span with suspenders, a car crosses, water ripples below"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let red = Color::rgb(222, 78, 44);
        let deck_c = Color::rgb(190, 190, 200);
        let water = Color::rgb(50, 120, 210);
        let car = Color::rgb(255, 220, 90);

        let deck_y = (hi * 5 / 8).max(2);
        let water_y = deck_y + 3;
        let t1 = wi * 27 / 100;
        let t2 = wi - 1 - t1;
        let mid = (t1 + t2) as f32 / 2.0;
        let half = ((t2 - t1) as f32 / 2.0).max(1.0);
        let top = 1;
        let sag = (deck_y - 1 - top) as f32;

        // Water first so the structure paints over it.
        for y in water_y..hi {
            for x in 0..wi {
                let v = (x as f32 * 0.45 + ctx.time * 3.0 + y as f32 * 2.1).sin();
                if v > 0.55 {
                    paint(grid, x, y, water);
                }
            }
        }

        // Main cable: parabola between tower tops, side spans to anchors.
        let cable_y = |x: i32| -> i32 {
            let xf = x as f32;
            if x >= t1 && x <= t2 {
                let u = (xf - mid) / half;
                (deck_y as f32 - 1.0 - sag * u * u).round() as i32
            } else {
                let (from, len) = if x < t1 {
                    (t1 as f32 - xf, t1 as f32)
                } else {
                    (xf - t2 as f32, (wi - 1 - t2) as f32)
                };
                let s = (from / len.max(1.0)).clamp(0.0, 1.0);
                (top as f32 + sag * s + 1.5 * s * (1.0 - s)).round() as i32
            }
        };
        let mut prev = cable_y(0);
        for x in 0..wi {
            let y = cable_y(x);
            paint_v(grid, x, prev, y, red);
            prev = y;
        }

        // Deck launched left to right; suspenders drop onto finished deck.
        let built = (ctx.eased * wi as f32).round() as i32;
        for x in 0..built.min(wi) {
            if x % 3 == 0 && x > 0 && x < wi - 1 {
                let cy = cable_y(x);
                if cy < deck_y - 1 {
                    paint_v(grid, x, cy + 1, deck_y - 1, red);
                }
            }
            paint(grid, x, deck_y, deck_c);
            if x % 2 == 0 {
                paint(grid, x, deck_y + 1, deck_c);
            }
        }

        // Pylons: twin legs with portal beams, standing in the water.
        for &tx in &[t1, t2] {
            paint_v(grid, tx - 1, 0, hi - 1, red);
            paint_v(grid, tx + 1, 0, hi - 1, red);
            paint_h(grid, tx - 1, tx + 1, 0, red);
            paint_h(grid, tx - 1, tx + 1, deck_y / 2, red);
        }

        // A car shuttles along whatever deck exists.
        if built > 6 {
            let span = (built - 4).max(1) as f32;
            let tri = 1.0 - ((ctx.time * 0.35).fract() * 2.0 - 1.0).abs();
            let cx = (tri * span) as i32;
            paint_h(grid, cx, cx + 3, deck_y - 1, car);
            paint_h(grid, cx + 1, cx + 2, deck_y - 2, car);
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 3. Gothic Arch / Cathedral
// ─────────────────────────────────────────────────────────────────────────────

/// An arcade of pointed lancet arches is raised bay by bay: piers rise, the
/// two arcs spring and meet at the point, then stained glass fills the window
/// and shimmers with time. Pinnacles crown every pier.
struct GothicArch;
impl ProgressStyle for GothicArch {
    fn name(&self) -> &str {
        "gothic-arch"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Pointed lancet arches rise bay by bay on pinnacled piers, then fill with shimmering stained glass"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 14 || dh < 6 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let stone = Color::rgb(214, 196, 160);
        let glass = [
            Color::rgb(60, 100, 230),
            Color::rgb(210, 40, 70),
            Color::rgb(245, 190, 60),
            Color::rgb(60, 180, 110),
            Color::rgb(150, 80, 220),
        ];
        let ground = hi - 1;
        let bay = 12;
        let span = bay - 2;
        let n = ((wi - 2) / bay).max(1);
        let off = ((wi - n * bay - 2) / 2) & !1; // keep piers cell-aligned
        let spring = hi * 9 / 16;
        let r = span as f32 * 0.85;
        let tick = (ctx.time * 2.0) as i32;
        let built = ctx.eased * n as f32;
        paint_h(grid, 0, wi - 1, ground, stone);

        // Height of the arch intrados above `spring` at dot column `dx` of a bay.
        let arc = |dx: i32| -> f32 {
            let d = dx.min(span - 1 - dx) as f32;
            let c = r - d; // distance to the opposite arc centre
            (r * r - c * c).max(0.0).sqrt()
        };

        for k in 0..n {
            let px = off + k * bay; // left pier
            let x0 = px + 2; // first window column
            let f = (built - k as f32).clamp(0.0, 1.0);
            if f <= 0.0 {
                continue;
            }
            // Stained glass once the arch is closed, in diamond leaded panes.
            if f >= 0.85 {
                for dx in 0..span {
                    let ay = spring - arc(dx).round() as i32;
                    for y in ay + 1..=ground {
                        if (dx + y) % 4 == 0 || (dx - y).rem_euclid(4) == 0 {
                            continue; // lead came
                        }
                        let cell = (x0 + dx) / 2 * 31 + y / 4;
                        let g = glass[(hash3(cell, k, tick) * 4.99) as usize];
                        paint(grid, x0 + dx, y, g);
                    }
                }
            }
            // Piers rise first (both sides of the bay).
            let pier_f = (f / 0.4).min(1.0);
            let pier_top = ground - ((ground - 1) as f32 * pier_f).round() as i32;
            for &p in &[px, px + bay] {
                paint_v(grid, p, pier_top, ground, stone);
                paint_v(grid, p + 1, pier_top.max(spring), ground, stone);
            }
            if pier_f >= 1.0 {
                // Pinnacle finials.
                paint(grid, px, 0, stone);
                paint(grid, px + bay, 0, stone);
            }
            // The two arcs spring together and meet at the point.
            let arch_f = ((f - 0.4) / 0.45).clamp(0.0, 1.0);
            let reach = (arch_f * (span / 2) as f32).round() as i32;
            let mut prev: Option<(i32, i32)> = None;
            for dx in 0..span {
                let side = dx.min(span - 1 - dx);
                if side >= reach {
                    prev = None;
                    continue;
                }
                let y = spring - arc(dx).round() as i32;
                let x = x0 + dx;
                match prev {
                    Some((pxx, py)) => paint_line(grid, pxx, py, x, y, stone),
                    None => paint(grid, x, y, stone),
                }
                prev = Some((x, y));
            }
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 4. Brick Wall
// ─────────────────────────────────────────────────────────────────────────────

/// Red bricks in running bond, one course per cell row, laid brick by brick
/// left to right and course by course bottom to top. Mortar joints are the
/// gaps; the brick being bedded is still an outline while a trowel taps it.
struct BrickWall;
impl ProgressStyle for BrickWall {
    fn name(&self) -> &str {
        "brick-wall"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Red bricks in running bond are laid one by one, course by course, while a trowel taps the newest brick into its mortar bed"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let reds = [
            Color::rgb(178, 62, 44),
            Color::rgb(198, 82, 54),
            Color::rgb(158, 54, 40),
            Color::rgb(210, 104, 66),
        ];
        let steel = Color::rgb(200, 200, 212);
        let handle = Color::rgb(150, 100, 60);

        let brick = 8; // 7 dots of brick + 1 dot head joint
        let courses = (hi / 4).max(1);
        let per = (wi + brick / 2) / brick + 1;
        let total = (courses * per) as f32;
        let laid = ctx.eased * total;
        let whole = laid as i32;
        let mut current: Option<(i32, i32)> = None;

        for c in 0..courses {
            let y0 = hi - 4 * (c + 1); // top row of this course
            let off = (c % 2) * (brick / 2);
            for b in 0..per {
                let idx = c * per + b;
                if idx > whole {
                    break;
                }
                let x0 = b * brick - off;
                let x1 = (x0 + brick - 2).min(wi - 1);
                if x1 < 0 {
                    continue;
                }
                let colour = reds[(hash3(b, c, 3) * 3.99) as usize];
                if idx == whole {
                    // Being bedded: outline only.
                    paint_h(grid, x0.max(0), x1, y0, colour);
                    paint_h(grid, x0.max(0), x1, y0 + 2, colour);
                    paint_v(grid, x0.max(0), y0, y0 + 2, colour);
                    paint_v(grid, x1, y0, y0 + 2, colour);
                    current = Some((x1, y0));
                } else {
                    for y in y0..y0 + 3 {
                        paint_h(grid, x0.max(0), x1, y, colour);
                    }
                }
            }
        }

        // Trowel taps the newest brick: blade + handle, bobbing with time.
        if let Some((x, y)) = current {
            let tap = ((ctx.time * 6.0).sin() * 0.5 + 0.5).round() as i32;
            let (tx, ty) = (x + 2, y - 3 + tap);
            paint_h(grid, tx, tx + 3, ty + 1, steel);
            paint_h(grid, tx + 1, tx + 2, ty + 2, steel);
            paint_line(grid, tx + 3, ty, tx + 5, ty - 2, handle);
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 5. Pyramid
// ─────────────────────────────────────────────────────────────────────────────

/// Three stepped pyramids rise on the desert under a low sun, built course by
/// course, each course laid left to right. Faces are lit on the left and in
/// shadow on the right; the great pyramid wears a gold capstone when done.
struct Pyramid;
impl ProgressStyle for Pyramid {
    fn name(&self) -> &str {
        "pyramid"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Three stepped sandstone pyramids rise course by course under a desert sun; sunlit and shadowed faces, gold capstone"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let lit = Color::rgb(232, 198, 132);
        let shade = Color::rgb(168, 124, 78);
        let gold = Color::rgb(255, 214, 90);
        let sun = Color::rgb(255, 160, 60);
        let sand = Color::rgb(200, 170, 110);

        let ground = hi - 1;
        let max_c = ((ground - 1) / 2).max(1);
        // (centre as a fraction of width, courses) — great, middle, small.
        let plan = [
            (0.23, max_c),
            (0.59, (max_c * 6 / 7).max(1)),
            (0.86, (max_c * 4 / 7).max(1)),
        ];
        let total: i32 = plan.iter().map(|p| p.1).sum();
        let laid = ctx.eased * total as f32;

        // Sun low in the sky, and drifting sand along the ground.
        let (sx, sy) = (wi - 22, 3);
        for dy in -2i32..=2 {
            let half = 2 - dy.abs() / 2;
            paint_h(grid, sx - half, sx + half, sy + dy, sun);
        }
        for x in 0..wi {
            if (x as f32 + ctx.time * 6.0).rem_euclid(7.0) < 5.0 {
                paint(grid, x, ground, sand);
            }
        }

        let mut before = 0;
        for (pi, &(fx, courses)) in plan.iter().enumerate() {
            let cx = (wi as f32 * fx) as i32;
            for c in 0..courses {
                let f = (laid - (before + c) as f32).clamp(0.0, 1.0);
                if f <= 0.0 {
                    break;
                }
                let hw = (courses - c) * 2;
                let (x0, x1) = (cx - hw, cx + hw);
                let reach = x0 + ((x1 - x0 + 1) as f32 * f) as i32;
                let capstone = pi == 0 && c == courses - 1 && f >= 1.0;
                for y in [ground - 1 - 2 * c, ground - 2 - 2 * c] {
                    for x in x0..reach.min(x1 + 1) {
                        let col = if capstone {
                            gold
                        } else if x < cx {
                            lit
                        } else {
                            shade
                        };
                        paint(grid, x, y, col);
                    }
                }
            }
            before += courses;
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 6. Scaffolding
// ─────────────────────────────────────────────────────────────────────────────

/// Tube-and-coupler scaffolding is erected bay by bay, lift by lift: steel
/// standards, ledgers at every lift, timber boards on top and yellow cross
/// braces. A bucket is hoisted up and down on the newest bay.
struct Scaffolding;
impl ProgressStyle for Scaffolding {
    fn name(&self) -> &str {
        "scaffolding"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Steel standards, ledgers, timber boards and cross braces go up bay by bay, lift by lift; a bucket is hoisted on the newest bay"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 12 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let steel = Color::rgb(176, 186, 202);
        let brace = Color::rgb(124, 134, 150);
        let bucket = Color::rgb(240, 180, 40);
        let board = Color::rgb(178, 116, 62);
        let rope = Color::rgb(140, 140, 150);

        let ground = hi - 1;
        let bay = 10;
        let nb = ((wi - 2) / bay).max(1);
        let lifts = ((hi - 1) / 5).max(1);
        let lift_h = (hi - 1) / lifts;
        let total = (nb * lifts) as f32;
        let placed = ctx.eased * total;

        paint_h(grid, 0, wi - 1, ground, Color::rgb(100, 96, 90));
        for b in 0..nb {
            let x0 = 1 + b * bay;
            let x1 = x0 + bay;
            for l in 0..lifts {
                let f = (placed - (b * lifts + l) as f32).clamp(0.0, 1.0);
                if f <= 0.0 {
                    continue;
                }
                let yb = ground - l * lift_h; // bottom of this lift
                let yt = yb - lift_h; // ledger level on top
                                      // Standards climb first, then the ledger, brace and boards.
                let rise = (f * 2.0).min(1.0);
                let ytop = yb - (lift_h as f32 * rise).round() as i32;
                if f >= 0.5 {
                    let (bx0, bx1) = if (b + l) % 2 == 0 { (x0, x1) } else { (x1, x0) };
                    paint_line(grid, bx0, yb, bx1, yt, brace);
                }
                paint_v(grid, x0, ytop, yb, steel);
                paint_v(grid, x1, ytop, yb, steel);
                if f >= 0.5 {
                    paint_h(grid, x0, x1, yt, steel);
                }
                if f >= 0.75 {
                    paint_h(grid, x0 + 1, x1 - 1, yt + 1, board);
                }
            }
        }

        // Hoist on the newest bay: a rope and a bucket bobbing on it.
        let cur = (placed as i32 / lifts).min(nb - 1);
        let hx = 1 + cur * bay + bay / 2;
        let bob = ((ctx.time * 1.2).sin() * 0.5 + 0.5) * (hi - 5) as f32;
        let by = 1 + bob as i32;
        if ctx.eased < 1.0 {
            paint_v(grid, hx, 0, by, rope);
            paint_h(grid, hx - 1, hx + 1, by + 1, bucket);
            paint_h(grid, hx - 1, hx + 1, by + 2, bucket);
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 7. Geodesic Dome
// ─────────────────────────────────────────────────────────────────────────────

/// A geodesic dome assembled ring by ring from the base up: each band is a
/// row of triangles struck between staggered hub points, so the finished
/// hemisphere reads as a lattice of triangles. Hubs glint as light moves
/// across the dome.
struct GeodesicDome;
impl ProgressStyle for GeodesicDome {
    fn name(&self) -> &str {
        "geodesic-dome"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "A triangulated geodesic hemisphere assembles band by band from the base up; light glints across its hubs"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 6 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let strut = Color::rgb(150, 180, 220);
        let hub = Color::rgb(240, 248, 255);
        let base = Color::rgb(214, 184, 142);

        let ground = hi - 1;
        let ry = (ground - 1) as f32;
        let rx = (ry * 1.6).min(wi as f32 / 2.0 - 1.0);
        let cx = wi as f32 / 2.0;
        let rings = 4;
        let seg = 8; // hubs across the visible front half of a ring
        let built = ctx.eased * rings as f32;
        let glint = (ctx.time * 0.5).fract() * seg as f32;

        // Hub `j` on ring `k` (k = rings is the apex), staggered every ring.
        let hub_at = |k: i32, j: f32| -> (i32, i32) {
            let phi = k as f32 / rings as f32 * std::f32::consts::FRAC_PI_2;
            let theta = (j + 0.5 * (k % 2) as f32) / seg as f32 * std::f32::consts::PI;
            (
                (cx - rx * phi.cos() * theta.cos()).round() as i32,
                (ground as f32 - ry * phi.sin()).round() as i32,
            )
        };

        paint_h(grid, 0, wi - 1, ground, base);
        for k in 0..rings {
            let f = (built - k as f32).clamp(0.0, 1.0);
            if f <= 0.0 {
                break;
            }
            let odd = k % 2 == 1;
            // Staggered rings have one hub fewer inside the silhouette.
            let upto = ((f * seg as f32).ceil() as i32).min(seg + 1 - i32::from(odd));
            for j in 0..upto {
                let a = hub_at(k, j as f32);
                // Ring strut to the next hub on the same ring.
                if j < seg {
                    let b = hub_at(k, (j + 1) as f32);
                    if !(odd && j == seg - 1) {
                        paint_line(grid, a.0, a.1, b.0, b.1, strut);
                    }
                }
                // Diagonal struts up to the staggered hubs on the next ring.
                for dj in [-1, 0] {
                    let jj = j + dj + i32::from(odd);
                    if (0..=seg).contains(&jj) {
                        let b = hub_at(k + 1, jj as f32);
                        paint_line(grid, a.0, a.1, b.0, b.1, strut);
                    }
                }
            }
            // Hubs glint as light sweeps across.
            for j in 0..upto {
                if (j as f32 - glint).abs() < 1.0 {
                    let a = hub_at(k, j as f32);
                    paint(grid, a.0, a.1, hub);
                }
            }
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 8. Spiral Staircase
// ─────────────────────────────────────────────────────────────────────────────

/// Looking down a stairwell: a brass handrail spirals from the outer wall in
/// to the newel post, and wedge-shaped stone treads are laid along it, from
/// the top landing down into the well as progress rises. The view slowly
/// turns with time, as if descending.
struct SpiralStaircase;
impl ProgressStyle for SpiralStaircase {
    fn name(&self) -> &str {
        "spiral-staircase"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Looking down a stairwell: treads are laid along a spiralling brass handrail down to the newel post; the view slowly turns"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 6 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let post = Color::rgb(196, 146, 76);
        let tread = Color::rgb(232, 222, 200);
        let rail = Color::rgb(214, 150, 70);
        let riser = Color::rgb(178, 166, 146);

        let (cx, cy) = (wi as f32 / 2.0, (hi - 1) as f32 / 2.0);
        let ry = cy;
        let rx = (ry * 3.2).min(cx - 1.0); // a perspective stretch
        let turns = 1.5;
        let sweep = turns * std::f32::consts::TAU;
        let shrink = 0.8; // radius lost from outer wall to newel
        let gap = shrink / turns; // radial spacing between spiral arms
        let spin = ctx.time * 0.4;
        let at = |u: f32, r: f32| -> (i32, i32) {
            let a = u * sweep + spin;
            (
                (cx + rx * r * a.cos()).round() as i32,
                (cy + ry * r * a.sin()).round() as i32,
            )
        };

        // The handrail spiral, drawn first so laid treads own their cells.
        let samples = 360;
        let mut prev = at(0.0, 1.0);
        for s in 1..=samples {
            let u = s as f32 / samples as f32;
            let p = at(u, 1.0 - shrink * u);
            paint_line(grid, prev.0, prev.1, p.0, p.1, rail);
            prev = p;
        }

        // Treads: solid wedges filling the band between one turn of the rail
        // and the next, split by thin risers and laid from the top landing
        // (outside) down into the well.
        let tau = std::f32::consts::TAU;
        let n = 22.0;
        let laid = ctx.eased * n;
        for y in 0..hi {
            for x in 0..wi {
                let (ex, ey) = ((x as f32 - cx) / rx, (y as f32 - cy) / ry);
                let rho = (ex * ex + ey * ey).sqrt();
                let a = (ey.atan2(ex) - spin).rem_euclid(tau);
                // Walk the arms passing this angle to find the one just outside.
                let mut m = 0.0;
                loop {
                    let u = (a + m * tau) / sweep;
                    if u > 1.0 {
                        break;
                    }
                    let r = 1.0 - shrink * u;
                    if rho < r - 0.04 && rho > r - gap + 0.04 {
                        let k = u * n;
                        if k < laid && k.fract() > 0.2 {
                            let c = if (k as i32) % 2 == 0 { tread } else { riser };
                            paint(grid, x, y, c);
                        }
                        break;
                    }
                    m += 1.0;
                }
            }
        }

        // Newel post at the bottom of the well.
        let (nx, ny) = (cx.round() as i32, cy.round() as i32);
        paint_h(grid, nx - 1, nx, ny, post);
        paint_h(grid, nx - 1, nx, ny + 1, post);
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 9. Roman Aqueduct
// ─────────────────────────────────────────────────────────────────────────────

/// A two-tier Roman aqueduct in the Pont du Gard manner: big round arches
/// over a river, a row of small arches above, and the water channel on top.
/// Masonry advances left to right — lower tier first, upper tier and channel
/// close behind — and water flows along the finished channel.
struct RomanAqueduct;
impl ProgressStyle for RomanAqueduct {
    fn name(&self) -> &str {
        "roman-aqueduct"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Two tiers of round stone arches advance across a river, with the water channel on top flowing as each span is finished"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 4 || dh < 4 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let stone = Color::rgb(214, 184, 142);
        let water = Color::rgb(70, 150, 230);

        // Rows scale with height: channel on top, small tier, big tier.
        let floor = (hi / 8).max(1); // channel floor row
        let impost = hi / 2; // between the tiers
        let ground = hi - 1;
        let lower = (ctx.eased * (wi + 24) as f32) as i32;
        let (upper, channel) = (lower - 12, lower - 24);

        // Is (x, y) inside an arch opening of span `span` on `pitch`, springing
        // at row `spring` with its crown at row `crown`?
        let opening = |x: i32, y: i32, pitch: i32, span: i32, crown: i32, spring: i32| {
            let ux = (x + pitch / 2).rem_euclid(pitch) - (pitch - span) / 2;
            if ux < 0 || ux >= span || y < crown {
                return false;
            }
            let r = (spring - crown).max(1) as f32;
            let dx = ux as f32 + 0.5 - span as f32 / 2.0;
            let dy = (spring - y).max(0) as f32;
            dx * dx * (r * r) / ((span as f32 / 2.0).powi(2)) + dy * dy <= r * r
        };

        for x in 0..wi {
            for y in 0..hi {
                let lit = if y < floor {
                    x < channel && y == 0
                } else if y == floor {
                    x < channel
                } else if y < impost {
                    x < upper && !opening(x, y, 6, 4, floor + 2, impost - 2)
                } else {
                    x < lower && (y == impost || !opening(x, y, 12, 9, impost + 2, ground - 2))
                };
                if lit {
                    paint(grid, x, y, stone);
                }
            }
            // Water runs along the finished channel...
            if x < channel && ((x as f32 - ctx.time * 10.0).rem_euclid(8.0)) < 3.0 {
                paint(grid, x, (floor - 1).max(1), water);
            }
            // ...and the river ripples under the big arches.
            let open = |x| opening(x, ground, 12, 9, impost + 2, ground - 2);
            if (x as f32 * 0.7 + ctx.time * 3.0).sin() > 0.2 && open(x & !1) && open(x | 1) {
                paint(grid, x, ground, water);
            }
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 10. Classical Column
// ─────────────────────────────────────────────────────────────────────────────

/// A colonnade of Ionic columns on a stepped stylobate. Columns go up left to
/// right: base, then fluted drums lowered one at a time on a crane rope, then
/// the scrolled capital; the entablature runs across each finished column and
/// a band of sunlight sweeps the marble.
struct ClassicalColumn;
impl ProgressStyle for ClassicalColumn {
    fn name(&self) -> &str {
        "classical-column"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Ionic columns rise drum by drum on a stepped base, gain scrolled capitals, then carry the entablature; sunlight sweeps the marble"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 12 || dh < 8 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let marble = Color::rgb(206, 200, 186);
        let glint = Color::rgb(255, 252, 240);
        let entab = Color::rgb(214, 184, 142);
        let step_c = Color::rgb(150, 140, 126);
        let rope = Color::rgb(140, 140, 150);

        let ground = hi - 1;
        let base_y = ground - 2;
        let cap_y = hi * 3 / 16; // abacus row
        let shaft_top = cap_y + 3;
        let shaft_h = (base_y - shaft_top).max(1);
        let pitch = 14;
        let n = ((wi - 4) / pitch).max(1);
        let off = (wi - n * pitch) / 2;
        let built = ctx.eased * n as f32;
        let sun = (ctx.time * 0.25).fract() * (wi + 20) as f32 - 10.0;

        // Stepped stylobate.
        paint_h(grid, 0, wi - 1, ground, step_c);
        paint_h(grid, 2, wi - 3, ground - 1, step_c);

        for k in 0..n {
            let cx = off + k * pitch + pitch / 2;
            let f = (built - k as f32).clamp(0.0, 1.0);
            if f <= 0.0 {
                continue;
            }
            let c = if (cx as f32 - sun).abs() < 5.0 {
                glint
            } else {
                marble
            };
            // Attic base.
            paint_h(grid, cx - 3, cx + 3, base_y, c);
            // Fluted shaft: three ridges, stacked drum by drum.
            let shaft_f = (f / 0.8).min(1.0);
            let rows = (shaft_h as f32 * shaft_f).round() as i32;
            let top = base_y - rows;
            for &dx in &[-2, 0, 2] {
                paint_v(grid, cx + dx, top, base_y - 1, c);
            }
            if shaft_f < 1.0 {
                // Next drum hangs on the crane rope, settling with time.
                let bob = ((ctx.time * 2.0).sin() * 0.5 + 0.5) * 3.0;
                let dy = top - 3 - bob.round() as i32;
                paint_v(grid, cx, 0, dy - 1, rope);
                paint_h(grid, cx - 2, cx + 2, dy, c);
                paint_h(grid, cx - 2, cx + 2, dy + 1, c);
            } else {
                // Ionic capital: echinus, curled volutes, flat abacus.
                paint_h(grid, cx - 4, cx + 4, cap_y, c);
                paint_h(grid, cx - 3, cx + 3, cap_y + 1, c);
                for &s in &[-1, 1] {
                    paint(grid, cx + s * 4, cap_y + 1, c);
                    paint(grid, cx + s * 4, cap_y + 2, c);
                    paint(grid, cx + s * 3, cap_y + 2, c);
                }
            }
            // Entablature across each finished column.
            if f >= 1.0 {
                let (l, r) = (cx - pitch / 2, cx + pitch / 2);
                paint_h(grid, l, r, cap_y - 1, entab);
                for x in l..=r {
                    if (x - off) % 3 == 0 {
                        paint(grid, x, cap_y - 2, entab);
                    }
                }
                paint_h(grid, l - 1, r + 1, cap_y - 3, entab);
            }
        }
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 11. Blueprint
// ─────────────────────────────────────────────────────────────────────────────

/// A drafting pen sweeps technical lines across graph paper; grid appears first.
struct Blueprint;
impl ProgressStyle for Blueprint {
    fn name(&self) -> &str {
        "blueprint"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Blueprint drafted: graph grid first, then walls, windows, and dimensions"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 4 || dh < 4 {
            return Ok(());
        }

        // Phase 1 (0–0.2): faint grid lines.
        if ctx.eased > 0.0 {
            let grid_spacing = 4usize;
            let grid_p = (ctx.eased / 0.2).min(1.0);
            let grid_cols = ((dw / grid_spacing) as f32 * grid_p) as usize;
            let grid_rows = ((dh / grid_spacing) as f32 * grid_p) as usize;
            for gx in 0..=grid_cols {
                let x = gx * grid_spacing;
                // Every other dot to keep it light.
                let mut y = 0usize;
                while y < dh {
                    draw::dot(grid, x.min(dw.saturating_sub(1)), y);
                    y += 2;
                }
            }
            for gy in 0..=grid_rows {
                let y = gy * grid_spacing;
                let mut x = 0usize;
                while x < dw {
                    draw::dot(grid, x, y.min(dh.saturating_sub(1)));
                    x += 2;
                }
            }
        }

        // Phase 2 (0.2–0.6): floor plan walls sweep in (outer rectangle).
        if ctx.eased > 0.2 {
            let wall_p = ((ctx.eased - 0.2) / 0.4).min(1.0);
            let x0 = dw / 8;
            let x1 = dw - dw / 8;
            let y0 = dh / 8;
            let y1 = dh - dh / 8;
            let perim = 2 * ((x1 - x0) + (y1 - y0));
            let drawn = (wall_p * perim as f32) as usize;
            // Walk the perimeter: top, right, bottom, left.
            let top_len = x1 - x0;
            let right_len = y1 - y0;
            let bot_len = x1 - x0;
            let left_len = y1 - y0;
            let mut rem = drawn;
            // Top.
            let seg = rem.min(top_len);
            draw::hline(grid, x0, x0 + seg, y0);
            rem = rem.saturating_sub(seg);
            // Right.
            let seg = rem.min(right_len);
            draw::vline(grid, x1, y0, y0 + seg);
            rem = rem.saturating_sub(seg);
            // Bottom (reversed).
            let seg = rem.min(bot_len);
            draw::hline(grid, x1.saturating_sub(seg), x1, y1);
            rem = rem.saturating_sub(seg);
            // Left (reversed).
            let seg = rem.min(left_len);
            draw::vline(grid, x0, y1.saturating_sub(seg), y1);
        }

        // Phase 3 (0.6–0.85): interior walls and door opening.
        if ctx.eased > 0.6 {
            let int_p = ((ctx.eased - 0.6) / 0.25).min(1.0);
            let mid_x = dw / 2;
            let y0 = dh / 8;
            let y1 = dh - dh / 8;
            let wall_len = (y1 - y0).saturating_sub(4); // door gap
            let drawn = (int_p * wall_len as f32) as usize;
            draw::vline(grid, mid_x, y0, y0 + drawn);
        }

        // Phase 4 (0.85–1.0): dimension lines + pen cursor.
        if ctx.eased > 0.85 {
            let dim_p = (ctx.eased - 0.85) / 0.15;
            // Dimension line along the top.
            let y_dim = (dh / 8).saturating_sub(2);
            let x_end = (dim_p * dw as f32) as usize;
            draw::hline(grid, 0, x_end.min(dw.saturating_sub(1)), y_dim);
            // Arrow heads.
            draw::dot(grid, 0, y_dim);
            let tail = x_end.min(dw.saturating_sub(1));
            draw::dot(grid, tail, y_dim);
        }

        // Pen cursor: a moving dot at the current draw frontier.
        let pen_x = (ctx.eased * dw as f32).round() as usize;
        let pen_y = ((ctx.time * 1.5).sin() * dh as f32 * 0.1 + dh as f32 * 0.5) as usize;
        draw::dot(
            grid,
            pen_x.min(dw.saturating_sub(1)),
            pen_y.min(dh.saturating_sub(1)),
        );

        // Tint: blueprint blue.
        let (cw, ch) = grid.dimensions();
        let blue = crate::Color::rgb(30, 80, 200);
        let light = crate::Color::rgb(100, 160, 255);
        for cx2 in 0..cw {
            for cy2 in 0..ch {
                let t = cx2 as f32 / cw.max(1) as f32;
                let color = {
                    let r = (blue.r as f32 + (light.r as f32 - blue.r as f32) * t) as u8;
                    let g = (blue.g as f32 + (light.g as f32 - blue.g as f32) * t) as u8;
                    let b = (blue.b as f32 + (light.b as f32 - blue.b as f32) * t) as u8;
                    crate::Color::rgb(r, g, b)
                };
                draw::tint_row(grid, cy2, cx2, cx2, color);
            }
        }

        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 12. Tower Crane
// ─────────────────────────────────────────────────────────────────────────────

/// A yellow tower crane — lattice mast, Warren-truss jib, counter-jib with its
/// concrete counterweight, cab and pendant ties — builds a concrete frame
/// beside it: floors go up with progress while the trolley runs out along
/// the jib and the hook lifts a steel beam.
struct TowerCrane;
impl ProgressStyle for TowerCrane {
    fn name(&self) -> &str {
        "tower-crane"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "A lattice tower crane with counterweight and trolley hoists steel beams while the building beside it rises floor by floor"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 24 || dh < 10 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let yellow = Color::rgb(250, 190, 40);
        let weight = Color::rgb(150, 150, 162);
        let cab = Color::rgb(90, 160, 230);
        let cable = Color::rgb(130, 130, 140);
        let beam = Color::rgb(214, 90, 50);
        let concrete = Color::rgb(176, 176, 186);

        let ground = hi - 1;
        let mx = (wi / 6).max(12);
        let (apex, top_chord, jib_y) = (0, 2, 4);
        let jib_end = wi - 2;
        let tail = mx - 10;

        // The building: concrete frame rising floor by floor beside the mast.
        let (bx0, bx1) = (mx + 12, wi - 4);
        let floors = ((ground - jib_y - 4) / 2).max(1);
        let level = ctx.eased * floors as f32;
        let whole = level as i32;
        for f in 0..=whole.min(floors - 1) {
            let y = ground - 2 * (f + 1);
            let len = if f < whole {
                bx1 - bx0
            } else {
                ((level - whole as f32) * (bx1 - bx0) as f32) as i32
            };
            if len <= 0 {
                continue;
            }
            paint_h(grid, bx0, bx0 + len, y, concrete);
            let mut x = bx0;
            while x <= bx0 + len {
                paint(grid, x, y + 1, concrete);
                x += 6;
            }
        }
        let roof = ground - 2 * whole;

        // Pendant ties first, so the steelwork owns the cells they cross.
        paint_line(grid, mx, apex, tail, jib_y, cable);
        paint_line(grid, mx, apex, (mx + jib_end) / 2, top_chord, cable);
        paint_line(grid, mx - 1, jib_y, mx, apex, yellow);
        paint_line(grid, mx + 1, jib_y, mx, apex, yellow);

        // Mast: two chords with alternating diagonal lacing.
        paint_v(grid, mx - 1, jib_y, ground, yellow);
        paint_v(grid, mx + 1, jib_y, ground, yellow);
        let mut y = jib_y;
        while y < ground {
            let (a, b) = if (y / 3) % 2 == 0 { (-1, 1) } else { (1, -1) };
            paint_line(grid, mx + a, y, mx + b, y + 3, yellow);
            y += 3;
        }
        // Jib (Warren truss) and counter-jib with its counterweight.
        paint_h(grid, mx, jib_end, jib_y, yellow);
        paint_h(grid, mx, jib_end - 6, top_chord, yellow);
        let mut x = mx;
        while x + 2 < jib_end - 6 {
            paint_line(grid, x, jib_y, x + 2, top_chord, yellow);
            paint_line(grid, x + 2, top_chord, x + 4, jib_y, yellow);
            x += 4;
        }
        paint_h(grid, tail, mx, jib_y, yellow);
        for wy in jib_y..jib_y + 3 {
            paint_h(grid, tail, tail + 3, wy, weight);
        }
        // Operator's cab under the jib.
        paint_h(grid, mx + 2, mx + 3, jib_y + 1, cab);
        paint_h(grid, mx + 2, mx + 3, jib_y + 2, cab);

        // Trolley shuttles out along the jib; the hook lifts and lowers a beam.
        let reach = (jib_end - 6 - (mx + 6)).max(1) as f32;
        let tri = 1.0 - ((ctx.time * 0.18).fract() * 2.0 - 1.0).abs();
        let tx = mx + 6 + (tri * reach) as i32;
        paint_h(grid, tx - 1, tx + 1, jib_y + 1, yellow);
        let floor_y = if tx >= bx0 - 3 && tx <= bx1 + 3 {
            roof - 2
        } else {
            ground - 1
        };
        let bob = (ctx.time * 1.1).sin() * 0.5 + 0.5;
        let hook = jib_y + 3 + ((floor_y - jib_y - 3).max(0) as f32 * bob) as i32;
        paint_v(grid, tx, jib_y + 2, hook - 1, cable);
        paint_h(grid, tx - 3, tx + 3, hook, beam);

        paint_h(grid, 0, wi - 1, ground, Color::rgb(140, 110, 80));
        Ok(())
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// 13. Colosseum
// ─────────────────────────────────────────────────────────────────────────────

/// The Colosseum's outer wall: three tiers of round arches under a windowed
/// attic, its far end broken down in a ruined, stepped profile. Travertine is
/// raised left to right with progress while evening light sweeps the stone.
struct Colosseum;
impl ProgressStyle for Colosseum {
    fn name(&self) -> &str {
        "colosseum"
    }
    fn theme(&self) -> &str {
        "architecture"
    }
    fn describe(&self) -> &str {
        "Three tiers of travertine arches under a windowed attic rise left to right, the far end broken in a ruined profile"
    }
    fn render(&self, grid: &mut BrailleGrid, ctx: &BarContext) -> Result<(), DotmaxError> {
        let (dw, dh) = draw::dot_dims(grid);
        if dw < 8 || dh < 8 {
            return Ok(());
        }
        grid.enable_color_support();
        let (wi, hi) = (dw as i32, dh as i32);
        let stone = Color::rgb(214, 190, 146);
        let light = Color::rgb(250, 226, 178);

        let tier = (hi / 4).max(2);
        let built = (ctx.eased * wi as f32).round() as i32;
        let sweep = (ctx.time * 0.3).fract() * (wi + 16) as f32 - 8.0;
        // Ruined profile: full height, then stepping down to two tiers.
        let ruin_from = wi * 6 / 10;
        let ruin_to = wi * 85 / 100;
        let top_at = |x: i32| -> i32 {
            if x < ruin_from {
                0
            } else if x >= ruin_to {
                2 * tier
            } else {
                let t = (x - ruin_from) * 2 * tier / (ruin_to - ruin_from).max(1);
                t - t % 2 + (x % 3 == 0) as i32
            }
        };

        for x in 0..built.min(wi) {
            let c = if (x as f32 - sweep).abs() < 6.0 {
                light
            } else {
                stone
            };
            for y in top_at(x)..hi {
                let band = y / tier; // 0 = attic, 1..=3 = arcades
                let row = y % tier;
                let ux = (x + 3).rem_euclid(6);
                let solid = if band == 0 {
                    // Attic: solid with small square windows every other bay.
                    !((1..=2).contains(&row) && (x / 6) % 2 == 0 && (2..4).contains(&ux))
                } else if row == 0 {
                    true // cornice between tiers
                } else {
                    // Round-headed arch opening, 4 dots wide on a 6-dot bay.
                    let inside = (1..5).contains(&ux);
                    let crown = row == 1 && (ux == 1 || ux == 4);
                    !inside || crown
                };
                if solid {
                    paint(grid, x, y, c);
                }
            }
        }
        Ok(())
    }
}