euv-ui 0.51.0

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
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
use super::*;

/// Compact 2-byte theme key helpers resolving directly into `THEME_TOKENS_LUT`.
impl ThemeKey {
    /// Constructs a 2-byte `ThemeKey` from `scheme` and `mode`.
    ///
    /// # Arguments
    ///
    /// - `DesignScheme` - Target design language.
    /// - `ThemeMode` - Light or Dark appearance.
    ///
    /// # Returns
    ///
    /// - `Self` - Compact 2-byte theme key.
    #[inline(always)]
    #[must_use]
    pub const fn new(scheme: DesignScheme, mode: ThemeMode) -> Self {
        Self { scheme, mode }
    }

    /// Extracts a 2-byte `ThemeKey` from an existing `ThemeTokens` bundle.
    ///
    /// # Arguments
    ///
    /// - `&ThemeTokens` - Source theme tokens.
    ///
    /// # Returns
    ///
    /// - `Self` - Matching 2-byte theme key.
    #[inline(always)]
    #[must_use]
    pub const fn from_tokens(tokens: &ThemeTokens) -> Self {
        Self {
            scheme: tokens.scheme,
            mode: tokens.mode,
        }
    }

    /// Returns the canonical `0..34` index into `THEME_TOKENS_LUT`.
    ///
    /// # Arguments
    ///
    /// - `Self` - Compact 2-byte theme key.
    ///
    /// # Returns
    ///
    /// - `usize` - Lookup table slot index in `0..34`.
    #[inline(always)]
    #[must_use]
    pub const fn lut_index(self) -> usize {
        let Self { scheme, mode } = self;
        (ThemeTokens::scheme_index(scheme) << 1) | ThemeTokens::mode_index(mode)
    }

    /// Reconstructs a `ThemeKey` from its canonical `0..34` lookup index.
    ///
    /// # Arguments
    ///
    /// - `usize` - Lookup table slot index produced by `lut_index`.
    ///
    /// # Returns
    ///
    /// - `Option<Self>` - Matching key, or `None` when `index` is out of range.
    #[must_use]
    pub const fn from_lut_index(index: usize) -> Option<Self> {
        let schemes: [DesignScheme; 17] = DesignScheme::all();
        let scheme_idx: usize = index >> 1;
        if scheme_idx >= schemes.len() {
            return None;
        }
        let mode: ThemeMode = if (index & 1) == 0 {
            ThemeMode::Light
        } else {
            ThemeMode::Dark
        };
        Some(Self {
            scheme: schemes[scheme_idx],
            mode,
        })
    }

    /// Resolves a zero-copy `'static` reference into `THEME_TOKENS_LUT` in O(1).
    ///
    /// # Arguments
    ///
    /// - `Self` - Compact 2-byte theme key.
    ///
    /// # Returns
    ///
    /// - `&'static ThemeTokens` - Borrowed static token bundle.
    #[inline(always)]
    #[must_use]
    pub fn resolve_static(self) -> &'static ThemeTokens {
        ThemeTokens::resolve_static(self)
    }

    /// Copies the matching `ThemeTokens` bundle from `THEME_TOKENS_LUT` in O(1).
    ///
    /// # Arguments
    ///
    /// - `Self` - Compact 2-byte theme key.
    ///
    /// # Returns
    ///
    /// - `ThemeTokens` - Compiled token bundle.
    #[inline(always)]
    #[must_use]
    pub fn resolve(self) -> ThemeTokens {
        *ThemeTokens::resolve_static(self)
    }
}

/// Default theme tokens resolving from the active compile-time feature scheme in Light mode.
impl Default for ThemeTokens {
    /// Creates default `ThemeTokens`.
    ///
    /// # Returns
    ///
    /// - `Self` - Resolved design tokens.
    #[inline(always)]
    fn default() -> Self {
        Self::resolve(active_feature_scheme(), ThemeMode::Light)
    }
}

/// Complete 17-scheme x 2-mode deterministic token resolver backed by compile-time LUTs.
impl ThemeTokens {
    /// Maps a `DesignScheme` variant to its canonical `0..17` LUT index.
    ///
    /// # Arguments
    ///
    /// - `DesignScheme` - Target design language.
    ///
    /// # Returns
    ///
    /// - `usize` - Canonical array index in `0..17`.
    #[inline(always)]
    const fn scheme_index(scheme: DesignScheme) -> usize {
        match scheme {
            DesignScheme::Shadcn => 0,
            DesignScheme::Cupertino => 1,
            DesignScheme::Material => 2,
            DesignScheme::Fluent => 3,
            DesignScheme::AntDesign => 4,
            DesignScheme::Bootstrap => 5,
            DesignScheme::DaisyUi => 6,
            DesignScheme::Geist => 7,
            DesignScheme::HeroUi => 8,
            DesignScheme::Linear => 9,
            DesignScheme::Mantine => 10,
            DesignScheme::Monochrome => 11,
            DesignScheme::Notion => 12,
            DesignScheme::Park => 13,
            DesignScheme::Radix => 14,
            DesignScheme::Stripe => 15,
            DesignScheme::Supabase => 16,
        }
    }

    /// Maps a `ThemeMode` variant to its binary LUT offset (`0` = Light, `1` = Dark).
    ///
    /// # Arguments
    ///
    /// - `ThemeMode` - Light or Dark appearance.
    ///
    /// # Returns
    ///
    /// - `usize` - Mode bit (`0` or `1`).
    #[inline(always)]
    const fn mode_index(mode: ThemeMode) -> usize {
        match mode {
            ThemeMode::Light => 0,
            ThemeMode::Dark => 1,
        }
    }

    /// Computes a `ThemePalette` at compile time for one `(DesignScheme, ThemeMode)` pair.
    ///
    /// # Arguments
    ///
    /// - `DesignScheme` - Target design language.
    /// - `ThemeMode` - Light or Dark appearance.
    ///
    /// # Returns
    ///
    /// - `ThemePalette` - Resolved semantic color palette.
    const fn build_palette(scheme: DesignScheme, mode: ThemeMode) -> ThemePalette {
        let (accent_light_hex, accent_dark_hex): (u32, u32) = match scheme {
            DesignScheme::Shadcn => (0x18181B, 0xFAFAFA),
            DesignScheme::Cupertino => (0x0066D6, 0x0A84FF),
            DesignScheme::Material => (0x6750A4, 0xD0BCFF),
            DesignScheme::Fluent => (0x0067C0, 0x60CDFF),
            DesignScheme::AntDesign => (0x1266E3, 0x3C89E8),
            DesignScheme::Bootstrap => (0x0B5ED7, 0x3D8BFD),
            DesignScheme::DaisyUi => (0x570DF8, 0xA78BFA),
            DesignScheme::Geist => (0x000000, 0xFFFFFF),
            DesignScheme::HeroUi => (0x0063D8, 0x338EF7),
            DesignScheme::Linear => (0x4F5BC4, 0x828FFF),
            DesignScheme::Mantine => (0x1971C2, 0x339AF0),
            DesignScheme::Monochrome => (0x111111, 0xF5F5F5),
            DesignScheme::Notion => (0x2F3437, 0xE8E8E8),
            DesignScheme::Park => (0x334155, 0xE2E8F0),
            DesignScheme::Radix => (0x3E63DD, 0x6E8BFF),
            DesignScheme::Stripe => (0x554CE8, 0x8A84FF),
            DesignScheme::Supabase => (0x047857, 0x3ECF8E),
        };
        let is_dark: bool = matches!(mode, ThemeMode::Dark);
        let primary_hex: u32 = if is_dark {
            accent_dark_hex
        } else {
            accent_light_hex
        };
        let primary: Color = Color::hex(primary_hex);
        let primary_foreground: Color = if contrast_ratio_hex(0xFFFFFF, primary_hex)
            >= contrast_ratio_hex(0x09090B, primary_hex)
        {
            Color::hex(0xFFFFFF)
        } else {
            Color::hex(0x09090B)
        };
        let (
            light_bg,
            light_card,
            light_muted,
            light_border,
            dark_bg,
            dark_card,
            dark_muted,
            dark_border,
        ): (Color, Color, Color, Color, Color, Color, Color, Color) = match scheme {
            DesignScheme::Shadcn => (
                Color::hex(0xFAFAFA),
                Color::hex(0xFFFFFF),
                Color::hex(0xF4F4F5),
                Color::hex(0xE4E4E7),
                Color::hex(0x09090B),
                Color::hex(0x111113),
                Color::hex(0x18181B),
                Color::hex(0x27272A),
            ),
            DesignScheme::Cupertino => (
                Color::hex(0xF2F2F7),
                Color::hex(0xFFFFFF),
                Color::hex(0xE5E5EA),
                Color::hex(0xD1D1D6),
                Color::hex(0x000000),
                Color::hex(0x1C1C1E),
                Color::hex(0x2C2C2E),
                Color::hex(0x38383A),
            ),
            DesignScheme::Material => (
                Color::hex(0xFEF7FF),
                Color::hex(0xFFFFFF),
                Color::hex(0xF3EDF7),
                Color::hex(0xCAC4D0),
                Color::hex(0x141218),
                Color::hex(0x1D1B20),
                Color::hex(0x2B2930),
                Color::hex(0x49454F),
            ),
            DesignScheme::Fluent => (
                Color::hex(0xF3F3F3),
                Color::hex(0xFFFFFF),
                Color::hex(0xEAEAEA),
                Color::hex(0xD9D9D9),
                Color::hex(0x202020),
                Color::hex(0x2B2B2B),
                Color::hex(0x323232),
                Color::hex(0x404040),
            ),
            DesignScheme::AntDesign => (
                Color::hex(0xF5F5F5),
                Color::hex(0xFFFFFF),
                Color::hex(0xF0F0F0),
                Color::hex(0xD9D9D9),
                Color::hex(0x0A0A0A),
                Color::hex(0x141414),
                Color::hex(0x1F1F1F),
                Color::hex(0x303030),
            ),
            DesignScheme::Bootstrap => (
                Color::hex(0xF8F9FA),
                Color::hex(0xFFFFFF),
                Color::hex(0xE9ECEF),
                Color::hex(0xDEE2E6),
                Color::hex(0x121417),
                Color::hex(0x1B1F23),
                Color::hex(0x252A30),
                Color::hex(0x343A40),
            ),
            DesignScheme::DaisyUi => (
                Color::hex(0xF7F7FA),
                Color::hex(0xFFFFFF),
                Color::hex(0xEEEDF5),
                Color::hex(0xDCD9E8),
                Color::hex(0x11131A),
                Color::hex(0x191D26),
                Color::hex(0x222736),
                Color::hex(0x32394D),
            ),
            DesignScheme::Geist => (
                Color::hex(0xFAFAFA),
                Color::hex(0xFFFFFF),
                Color::hex(0xF2F2F2),
                Color::hex(0xEAEAEA),
                Color::hex(0x000000),
                Color::hex(0x0A0A0A),
                Color::hex(0x171717),
                Color::hex(0x262626),
            ),
            DesignScheme::HeroUi => (
                Color::hex(0xF8FAFC),
                Color::hex(0xFFFFFF),
                Color::hex(0xF1F5F9),
                Color::hex(0xE2E8F0),
                Color::hex(0x070B14),
                Color::hex(0x0F172A),
                Color::hex(0x1E293B),
                Color::hex(0x334155),
            ),
            DesignScheme::Linear => (
                Color::hex(0xF7F8FA),
                Color::hex(0xFFFFFF),
                Color::hex(0xEEF0F4),
                Color::hex(0xDFE3EA),
                Color::hex(0x0B0C10),
                Color::hex(0x13151C),
                Color::hex(0x1C1F29),
                Color::hex(0x2A2E3D),
            ),
            DesignScheme::Mantine => (
                Color::hex(0xF8F9FA),
                Color::hex(0xFFFFFF),
                Color::hex(0xF1F3F5),
                Color::hex(0xDEE2E6),
                Color::hex(0x141517),
                Color::hex(0x1A1B1E),
                Color::hex(0x25262B),
                Color::hex(0x373A40),
            ),
            DesignScheme::Monochrome => (
                Color::hex(0xF7F7F7),
                Color::hex(0xFFFFFF),
                Color::hex(0xEDEDED),
                Color::hex(0xD4D4D4),
                Color::hex(0x0A0A0A),
                Color::hex(0x141414),
                Color::hex(0x1F1F1F),
                Color::hex(0x333333),
            ),
            DesignScheme::Notion => (
                Color::hex(0xFBFBF9),
                Color::hex(0xFFFFFF),
                Color::hex(0xF1F1EE),
                Color::hex(0xE3E2DF),
                Color::hex(0x191919),
                Color::hex(0x202020),
                Color::hex(0x2A2A2A),
                Color::hex(0x373737),
            ),
            DesignScheme::Park => (
                Color::hex(0xF8FAFC),
                Color::hex(0xFFFFFF),
                Color::hex(0xF1F5F9),
                Color::hex(0xCBD5E1),
                Color::hex(0x0B1120),
                Color::hex(0x111827),
                Color::hex(0x1E293B),
                Color::hex(0x334155),
            ),
            DesignScheme::Radix => (
                Color::hex(0xF9FAFB),
                Color::hex(0xFFFFFF),
                Color::hex(0xF0F2F7),
                Color::hex(0xDCE1EB),
                Color::hex(0x111113),
                Color::hex(0x18191B),
                Color::hex(0x212225),
                Color::hex(0x303238),
            ),
            DesignScheme::Stripe => (
                Color::hex(0xF6F9FC),
                Color::hex(0xFFFFFF),
                Color::hex(0xEBF1F6),
                Color::hex(0xD8E2EC),
                Color::hex(0x0A1628),
                Color::hex(0x10213A),
                Color::hex(0x172D4D),
                Color::hex(0x254066),
            ),
            DesignScheme::Supabase => (
                Color::hex(0xF8FAFC),
                Color::hex(0xFFFFFF),
                Color::hex(0xF1F5F4),
                Color::hex(0xDDE5E2),
                Color::hex(0x121212),
                Color::hex(0x1C1C1C),
                Color::hex(0x262626),
                Color::hex(0x333333),
            ),
        };
        if is_dark {
            ThemePalette {
                background: dark_bg,
                foreground: Color::hex(0xFAFAFA),
                card: dark_card,
                card_foreground: Color::hex(0xFAFAFA),
                primary,
                primary_foreground,
                secondary: dark_muted,
                secondary_foreground: Color::hex(0xFAFAFA),
                muted: dark_muted,
                muted_foreground: Color::hex(0xA1A1AA),
                accent: mix_rgb_const(dark_muted, dark_border, 176),
                destructive: Color::hex(0xDC2626),
                destructive_foreground: Color::hex(0xFAFAFA),
                success: Color::hex(0x22C55E),
                success_foreground: Color::hex(0x052E16),
                warning: Color::hex(0xF59E0B),
                warning_foreground: Color::hex(0x09090B),
                switch_track_off: Color::hex(0x3F3F46),
                switch_thumb: Color::hex(0xFAFAFA),
                media_surface: Color::hex(0x0B1120),
                border: dark_border,
                ring: primary,
                overlay: Color::rgba(0, 0, 0, 184),
            }
        } else {
            ThemePalette {
                background: light_bg,
                foreground: Color::hex(0x09090B),
                card: light_card,
                card_foreground: Color::hex(0x09090B),
                primary,
                primary_foreground,
                secondary: light_muted,
                secondary_foreground: Color::hex(0x18181B),
                muted: light_muted,
                muted_foreground: Color::hex(0x71717A),
                accent: mix_rgb_const(light_muted, light_border, 152),
                destructive: Color::hex(0xDC2626),
                destructive_foreground: Color::hex(0xFFFFFF),
                success: Color::hex(0x15803D),
                success_foreground: Color::hex(0xFFFFFF),
                warning: Color::hex(0xD97706),
                warning_foreground: Color::hex(0x09090B),
                switch_track_off: Color::hex(0x8E8E93),
                switch_thumb: Color::hex(0xFFFFFF),
                media_surface: Color::hex(0x0F172A),
                border: light_border,
                ring: primary,
                overlay: Color::rgba(0, 0, 0, 128),
            }
        }
    }

    /// Precomputes all 34 `(DesignScheme, ThemeMode)` semantic color palettes into a compile-time lookup table.
    ///
    /// # Returns
    ///
    /// - `[ThemePalette; 34]` - Compile-time palette LUT indexed by `(scheme_idx << 1) | dark_idx`.
    pub(crate) const fn build_palette_lut() -> [ThemePalette; 34] {
        let schemes: [DesignScheme; 17] = DesignScheme::all();
        let placeholder: ThemePalette = Self::build_palette(DesignScheme::Shadcn, ThemeMode::Light);
        let mut lut: [ThemePalette; 34] = [placeholder; 34];
        let mut idx: usize = 0;
        while idx < schemes.len() {
            let scheme: DesignScheme = schemes[idx];
            lut[idx << 1] = Self::build_palette(scheme, ThemeMode::Light);
            lut[(idx << 1) | 1] = Self::build_palette(scheme, ThemeMode::Dark);
            idx += 1;
        }
        lut
    }

    /// Builds one complete `ThemeTokens` entry from compile-time palette and geometry LUTs.
    ///
    /// # Arguments
    ///
    /// - `DesignScheme` - Target design language.
    /// - `ThemeMode` - Light or Dark appearance.
    ///
    /// # Returns
    ///
    /// - `Self` - Resolved token bundle.
    fn build_tokens(scheme: DesignScheme, mode: ThemeMode) -> Self {
        let scheme_idx: usize = Self::scheme_index(scheme);
        let dark_idx: usize = Self::mode_index(mode);
        let palette: ThemePalette = THEME_PALETTE_LUT[(scheme_idx << 1) | dark_idx];
        let [
            radius_sm,
            radius_md,
            radius_lg,
            radius_xl,
            control_sm,
            control_md,
            control_lg,
        ]: [f32; 7] = THEME_CANONICAL_GEOMETRY_METRICS;
        let (shadow_xs, shadow_sm, shadow_md, shadow_lg): (Shadow, Shadow, Shadow, Shadow) =
            if dark_idx != 0 {
                (
                    Shadow::new(0.0, 1.0, 2.0, 0.0, Color::rgba(0, 0, 0, 48)),
                    Shadow::new(0.0, 2.0, 6.0, 0.0, Color::rgba(0, 0, 0, 64)),
                    Shadow::new(0.0, 6.0, 16.0, 0.0, Color::rgba(0, 0, 0, 84)),
                    Shadow::new(0.0, 12.0, 26.0, 0.0, Color::rgba(0, 0, 0, 108)),
                )
            } else {
                (
                    Shadow::new(0.0, 1.0, 2.0, 0.0, Color::rgba(0, 0, 0, 12)),
                    Shadow::new(0.0, 1.0, 3.0, 0.0, Color::rgba(0, 0, 0, 18)),
                    Shadow::new(0.0, 4.0, 12.0, 0.0, Color::rgba(0, 0, 0, 24)),
                    Shadow::new(0.0, 10.0, 20.0, 0.0, Color::rgba(0, 0, 0, 32)),
                )
            };
        let geometry: ThemeGeometry = ThemeGeometry {
            radius_sm,
            radius_md,
            radius_lg,
            radius_xl,
            border_width: 1.0,
            ring_width: 2.0,
            control_sm,
            control_md,
            control_lg,
            font_body: 14.0,
            font_heading: 16.0,
            font_title: 24.0,
            shadow_xs,
            shadow_sm,
            shadow_md,
            shadow_lg,
        };
        Self {
            scheme,
            mode,
            palette,
            geometry,
        }
    }

    /// Populates all 34 `(DesignScheme, ThemeMode)` complete `ThemeTokens` entries into the static lookup table.
    ///
    /// # Returns
    ///
    /// - `[Self; 34]` - Static tokens LUT indexed by `(scheme_idx << 1) | dark_idx`.
    pub(crate) fn build_tokens_lut() -> [Self; 34] {
        let schemes: [DesignScheme; 17] = DesignScheme::all();
        let placeholder: Self = Self::build_tokens(DesignScheme::Shadcn, ThemeMode::Light);
        let mut lut: [Self; 34] = [placeholder; 34];
        for (idx, scheme) in schemes.into_iter().enumerate() {
            lut[idx << 1] = Self::build_tokens(scheme, ThemeMode::Light);
            lut[(idx << 1) | 1] = Self::build_tokens(scheme, ThemeMode::Dark);
        }
        lut
    }

    /// Resolves a zero-copy `'static` reference to the `ThemeTokens` entry for `key` in O(1).
    ///
    /// # Arguments
    ///
    /// - `ThemeKey` - Compact 2-byte `(DesignScheme, ThemeMode)` lookup key.
    ///
    /// # Returns
    ///
    /// - `&'static Self` - Static reference into `THEME_TOKENS_LUT`.
    #[inline(always)]
    #[must_use]
    pub fn resolve_static(key: ThemeKey) -> &'static Self {
        &THEME_TOKENS_LUT.get_or_init(Self::build_tokens_lut)[key.lut_index()]
    }

    /// Returns the compact 2-byte `ThemeKey` identifying this token bundle.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active theme tokens.
    ///
    /// # Returns
    ///
    /// - `ThemeKey` - Compact 2-byte `(scheme, mode)` key.
    #[inline(always)]
    #[must_use]
    pub const fn key(&self) -> ThemeKey {
        ThemeKey::from_tokens(self)
    }

    /// Resolves complete `ThemeTokens` for any `(DesignScheme, ThemeMode)` pair via O(1) static LUT lookup.
    ///
    /// # Arguments
    ///
    /// - `DesignScheme` - Target design language.
    /// - `ThemeMode` - Light or Dark appearance.
    ///
    /// # Returns
    ///
    /// - `Self` - Compiled zero-allocation token bundle.
    #[inline(always)]
    #[must_use]
    pub fn resolve(scheme: DesignScheme, mode: ThemeMode) -> Self {
        *Self::resolve_static(ThemeKey::new(scheme, mode))
    }

    /// Returns a standard card surface `Style` honoring the active scheme and theme.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active theme tokens.
    ///
    /// # Returns
    ///
    /// - `Style` - Compiled card box style.
    #[inline(always)]
    #[must_use]
    pub fn card_style(&self) -> Style {
        let theme_palette: ThemePalette = self.get_palette();
        let theme_geometry: ThemeGeometry = self.get_geometry();
        let mut style: Style = Style::default();
        style
            .get_mut_layout()
            .set_flex_direction(FlexDirection::Column)
            .set_padding(Edges::all(SPACE_MD))
            .set_row_gap(SPACE_MD)
            .set_column_gap(SPACE_MD)
            .set_overflow(Overflow::Hidden);
        style
            .get_mut_paint()
            .set_background(Some(theme_palette.get_card()))
            .set_border(Border::new(
                theme_geometry.get_border_width(),
                theme_palette.get_border(),
            ))
            .set_radius(CornerRadius::all(theme_geometry.get_radius_lg()))
            .set_shadow(Some(theme_geometry.get_shadow_sm()));
        style
            .get_mut_text()
            .set_color(theme_palette.get_card_foreground())
            .set_font_size(theme_geometry.get_font_body());
        style
    }
}

/// Contrast-safe foreground pairing helpers for `ThemePalette`.
impl ThemePalette {
    /// Returns a foreground guaranteed to reach `>= CONTRAST_MIN_TEXT` against `bg`, preferring palette text colors.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active palette.
    /// - `Color` - Effective (opaque) background color.
    ///
    /// # Returns
    ///
    /// - `Color` - Readable foreground color.
    #[must_use]
    pub fn readable_foreground_on(&self, bg: Color) -> Color {
        self.readable_foreground_with(self.get_foreground(), bg)
    }

    /// Returns `preferred` when it reaches `>= CONTRAST_MIN_TEXT` against `bg`, otherwise the most readable fallback.
    ///
    /// Fallback order: palette `foreground`, palette `background`, then pure black / white (one of which always
    /// exceeds `4.58:1` against any opaque color).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active palette.
    /// - `Color` - Preferred semantic foreground.
    /// - `Color` - Effective (opaque) background color.
    ///
    /// # Returns
    ///
    /// - `Color` - Readable foreground color.
    #[must_use]
    pub fn readable_foreground_with(&self, preferred: Color, bg: Color) -> Color {
        if contrast_ratio(preferred, bg) >= CONTRAST_MIN_TEXT {
            return preferred;
        }
        let candidates: [Color; 2] = [self.get_foreground(), self.get_background()];
        if let Some(found) = candidates
            .into_iter()
            .find(|&candidate: &Color| contrast_ratio(candidate, bg) >= CONTRAST_MIN_TEXT)
        {
            return found;
        }
        if contrast_ratio(COLOR_WHITE, bg) >= contrast_ratio(COLOR_BLACK, bg) {
            COLOR_WHITE
        } else {
            COLOR_BLACK
        }
    }

    /// Resolves a muted secondary foreground color meeting `CONTRAST_MIN_TEXT` against `bg` while staying visually distinct from full `foreground`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active palette.
    /// - `Color` - Effective opaque background color.
    ///
    /// # Returns
    ///
    /// - `Color` - Contrast-safe muted foreground color.
    #[must_use]
    fn readable_muted_foreground(&self, bg: Color) -> Color {
        let base_muted: Color = self.get_muted_foreground();
        let full_fg: Color = self.get_foreground();
        for step in [0_u8, 40_u8, 84_u8, 128_u8, 176_u8] {
            let candidate: Color = if step == 0 {
                base_muted
            } else {
                mix_rgb_const(base_muted, full_fg, step)
            };
            if contrast_ratio(candidate, bg) >= CONTRAST_MIN_TEXT {
                return candidate;
            }
        }
        self.readable_foreground_with(base_muted, bg)
    }

    /// Resolves paired `(bg, fg, border)` colors for `role` with a guaranteed-readable foreground.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active palette.
    /// - `SurfaceRole` - Semantic surface role.
    ///
    /// # Returns
    ///
    /// - `SurfaceColors` - Contrast-safe surface color triple.
    #[must_use]
    pub fn surface(&self, role: SurfaceRole) -> SurfaceColors {
        let (bg, preferred, border): (Color, Color, Color) = match role {
            SurfaceRole::Background => (
                self.get_background(),
                self.get_foreground(),
                self.get_border(),
            ),
            SurfaceRole::Card => (
                self.get_card(),
                self.get_card_foreground(),
                self.get_border(),
            ),
            SurfaceRole::Primary => (
                self.get_primary(),
                self.get_primary_foreground(),
                self.get_primary(),
            ),
            SurfaceRole::Secondary => (
                self.get_secondary(),
                self.get_secondary_foreground(),
                self.get_border(),
            ),
            SurfaceRole::Muted => (self.get_muted(), self.get_foreground(), self.get_border()),
            SurfaceRole::Accent => (self.get_accent(), self.get_foreground(), self.get_border()),
            SurfaceRole::Destructive => (
                self.get_destructive(),
                self.get_destructive_foreground(),
                self.get_destructive(),
            ),
            SurfaceRole::Success => (
                self.get_success(),
                self.get_success_foreground(),
                self.get_success(),
            ),
            SurfaceRole::Warning => (
                self.get_warning(),
                self.get_warning_foreground(),
                self.get_warning(),
            ),
        };
        let opaque_bg: Color = blend_over(bg, self.get_background());
        SurfaceColors::new(
            bg,
            self.readable_foreground_with(preferred, opaque_bg),
            border,
        )
    }

    /// Resolves unified contrast-safe `(bg, fg, border)` colors for any interactive component state across all 34 themes.
    ///
    /// Guarantees identical state-transition semantics in Light and Dark modes:
    /// - Hovering never mutates structural border colors.
    /// - Every role transitions background and foreground together deterministically.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Active theme palette.
    /// - `InteractionRole` - Semantic control interaction family.
    /// - `bool` - Whether the item is currently active / selected / toggled on.
    /// - `bool` - Whether the pointer is hovering the control.
    /// - `bool` - Whether the pointer is actively pressing the control.
    ///
    /// # Returns
    ///
    /// - `SurfaceColors` - Paired `(bg, fg, border)` colors with `>= 4.5:1` contrast.
    #[must_use]
    pub fn interaction_colors(
        &self,
        role: InteractionRole,
        active: bool,
        hovered: bool,
        pressed: bool,
    ) -> SurfaceColors {
        match role {
            InteractionRole::SolidPrimary => {
                let base_surface: SurfaceColors = self.surface(SurfaceRole::Primary);
                let bg_color: Color = if pressed {
                    blend_over(base_surface.get_fg().with_alpha(52), base_surface.get_bg())
                } else if hovered {
                    blend_over(base_surface.get_fg().with_alpha(26), base_surface.get_bg())
                } else {
                    base_surface.get_bg()
                };
                let fg_color: Color =
                    self.readable_foreground_with(base_surface.get_fg(), bg_color);
                SurfaceColors::new(bg_color, fg_color, bg_color)
            }
            InteractionRole::SolidDestructive => {
                let base_surface: SurfaceColors = self.surface(SurfaceRole::Destructive);
                let bg_color: Color = if pressed {
                    blend_over(base_surface.get_fg().with_alpha(52), base_surface.get_bg())
                } else if hovered {
                    blend_over(base_surface.get_fg().with_alpha(26), base_surface.get_bg())
                } else {
                    base_surface.get_bg()
                };
                let fg_color: Color =
                    self.readable_foreground_with(base_surface.get_fg(), bg_color);
                SurfaceColors::new(bg_color, fg_color, bg_color)
            }
            InteractionRole::SecondarySurface => {
                let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                if pressed {
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, self.get_border())
                } else if hovered || active {
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        self.get_border(),
                    )
                } else {
                    self.surface(SurfaceRole::Secondary)
                }
            }
            InteractionRole::OutlineSurface => {
                let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                let card_surface: SurfaceColors = self.surface(SurfaceRole::Card);
                if pressed {
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, card_surface.get_border())
                } else if hovered || active {
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        card_surface.get_border(),
                    )
                } else {
                    card_surface
                }
            }
            InteractionRole::GhostSurface => {
                let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                if pressed {
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, COLOR_TRANSPARENT)
                } else if hovered || active {
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        COLOR_TRANSPARENT,
                    )
                } else {
                    let base_surface: SurfaceColors = self.surface(SurfaceRole::Background);
                    SurfaceColors::new(COLOR_TRANSPARENT, base_surface.get_fg(), COLOR_TRANSPARENT)
                }
            }
            InteractionRole::LinkSurface => {
                let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                if pressed {
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(self.get_primary(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, COLOR_TRANSPARENT)
                } else if hovered || active {
                    let fg_color: Color =
                        self.readable_foreground_with(self.get_primary(), accent_surface.get_bg());
                    SurfaceColors::new(accent_surface.get_bg(), fg_color, COLOR_TRANSPARENT)
                } else {
                    let fg_color: Color =
                        self.readable_foreground_with(self.get_primary(), self.get_background());
                    SurfaceColors::new(COLOR_TRANSPARENT, fg_color, COLOR_TRANSPARENT)
                }
            }
            InteractionRole::SegmentedPill => {
                if active {
                    let card_surface: SurfaceColors = self.surface(SurfaceRole::Card);
                    let bg_color: Color = if pressed {
                        blend_over(card_surface.get_fg().with_alpha(18), card_surface.get_bg())
                    } else {
                        card_surface.get_bg()
                    };
                    let fg_color: Color =
                        self.readable_foreground_with(card_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, card_surface.get_border())
                } else if pressed {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(24),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, COLOR_TRANSPARENT)
                } else if hovered {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        COLOR_TRANSPARENT,
                    )
                } else {
                    let muted_bg: Color = self.surface(SurfaceRole::Muted).get_bg();
                    let idle_fg: Color = self.readable_muted_foreground(muted_bg);
                    SurfaceColors::new(COLOR_TRANSPARENT, idle_fg, COLOR_TRANSPARENT)
                }
            }
            InteractionRole::NavItem => {
                if active {
                    let tint_alpha: u8 = if pressed {
                        44
                    } else if hovered {
                        34
                    } else {
                        24
                    };
                    let row_bg: Color = self.get_primary().with_alpha(tint_alpha);
                    let opaque_bg: Color = blend_over(row_bg, self.get_card());
                    let fg_color: Color =
                        self.readable_foreground_with(self.get_foreground(), opaque_bg);
                    SurfaceColors::new(row_bg, fg_color, self.get_primary())
                } else if pressed {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, COLOR_TRANSPARENT)
                } else if hovered {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        COLOR_TRANSPARENT,
                    )
                } else {
                    let card_bg: Color = self.surface(SurfaceRole::Card).get_bg();
                    let idle_fg: Color = self.readable_muted_foreground(card_bg);
                    SurfaceColors::new(COLOR_TRANSPARENT, idle_fg, COLOR_TRANSPARENT)
                }
            }
            InteractionRole::OptionItem => {
                if active {
                    let primary_surface: SurfaceColors = self.surface(SurfaceRole::Primary);
                    let bg_color: Color = if pressed {
                        blend_over(
                            primary_surface.get_fg().with_alpha(44),
                            primary_surface.get_bg(),
                        )
                    } else if hovered {
                        blend_over(
                            primary_surface.get_fg().with_alpha(22),
                            primary_surface.get_bg(),
                        )
                    } else {
                        primary_surface.get_bg()
                    };
                    let fg_color: Color =
                        self.readable_foreground_with(primary_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, primary_surface.get_border())
                } else if pressed {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    let bg_color: Color = blend_over(
                        accent_surface.get_fg().with_alpha(28),
                        accent_surface.get_bg(),
                    );
                    let fg_color: Color =
                        self.readable_foreground_with(accent_surface.get_fg(), bg_color);
                    SurfaceColors::new(bg_color, fg_color, COLOR_TRANSPARENT)
                } else if hovered {
                    let accent_surface: SurfaceColors = self.surface(SurfaceRole::Accent);
                    SurfaceColors::new(
                        accent_surface.get_bg(),
                        accent_surface.get_fg(),
                        COLOR_TRANSPARENT,
                    )
                } else {
                    let card_surface: SurfaceColors = self.surface(SurfaceRole::Card);
                    SurfaceColors::new(COLOR_TRANSPARENT, card_surface.get_fg(), COLOR_TRANSPARENT)
                }
            }
        }
    }
}