function __kitty_host_color -d "Map an ssh host/alias to a stable 'bg fg' hex pair for the kitty tab"
    set -l host $argv[1]

    # ---- Explicit table for known hosts (alias OR resolved hostname) ----
    # Keep colors meaningful: infra/routers = warm/danger, personal cloud = blue,
    # local heavy box = green, geo VPS = a varied but recognizable palette.
    set -l bg
    switch $host
        # Routers / network gear — orange = "you are touching the plumbing"
        case '192.168.1.1' '192.168.15.1' 'proxmox'
            set bg ff8c00
        # Home Unbound resolvers (see reset-zone) — amber, sibling of routers
        case '192.168.88.88' '192.168.11.11'
            set bg d79921
        # ryzen / mini — local powerhouse boxes — green
        case ryzen mini 'mini.*' 'mini-*'
            set bg 689d6a
        # Personal cloud (beslan / setia / zephyr.setia.cloud) — blue
        case 'beslan*' setia 'setia*' 'zephyr*' '*.setia.cloud'
            set bg 2e84e6
        # Riga boxes — teal
        case 'riga*'
            set bg 1abc9c
        # Finland / Helsinki — purple
        case fi 'fi-*' hel hel2
            set bg 9b59b6
        # US (NJ / NY) — red-ish, "far away prod"
        case nj 'nj-*' ny 'ny-*'
            set bg e74c3c
        # Stockholm / Tallinn / Vilnius / Krasnodar / Voronezh — slate blue
        case sth tln vln krd vrn kz blr highland riga am
            set bg 5b7bb4
        case '*'
            set bg ''
    end

    # ---- Hash fallback: stable, curated palette so every host is distinct ----
    set -l kind explicit
    if test -z "$bg"
        set kind hash
        set -l palette 458588 b16286 d65d0e 689d6a d79921 8f3f71 \
            076678 af3a03 427b58 9d0006 b57614 8ec07c \
            cc241d 98971a d5c4a1 fb4934
        set -l n (printf '%s' "$host" | cksum | string split ' ')[1]
        set -l idx (math "$n % "(count $palette)" + 1")
        set bg $palette[$idx]
    end

    # ---- Pick readable fg (black/white) from bg luminance ----
    set -l r (math "0x"(string sub -s 1 -l 2 $bg))
    set -l g (math "0x"(string sub -s 3 -l 2 $bg))
    set -l b (math "0x"(string sub -s 5 -l 2 $bg))
    set -l lum (math -s0 "0.299 * $r + 0.587 * $g + 0.114 * $b")
    set -l fg ffffff
    test $lum -gt 150; and set fg 000000

    echo "#$bg #$fg $kind"
end
