{
  "id": "mod_password_forge",
  "type": "module",
  "version": "1.2",
  "context": {
    "layout": "phone",
    "title": "Password Forge",
    "icon": "🔐",
    "pool": "{{ (${upper} ? 'ABCDEFGHJKLMNPQRSTUVWXYZ' : '') + (${lower} ? 'abcdefghijkmnpqrstuvwxyz' : '') + (${digits} ? '23456789' : '') + (${symbols} ? '!@#$%&*-_+=?' : '') }}"
  },
  "state": {
    "password": "",
    "sliderVal": 0.3333,
    "length": 16,
    "upper": true,
    "lower": true,
    "digits": true,
    "symbols": false,
    "focused": "",
    "showToast": false,
    "toastText": ""
  },
  "dependencies": [
    {
      "service": {
        "audio": {
          "id": "dep_audio"
        }
      }
    },
    {
      "action": {
        "state": {
          "id": "act_generate",
          "input": {
            "password": "{{ prefix(prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1) + prefix(suffix(@{pool},count(@{pool})-random(0,count(@{pool})-1)),1), ${length}) }}"
          }
        }
      }
    }
  ],
  "children": [
    {
      "id": "pf_scroll",
      "type": "scroll",
      "style": {
        "layout": {
          "maxWidth": "infinity",
          "maxHeight": "infinity"
        },
        "scroll": {
          "dismissesKeyboard": "interactively"
        },
        "common": {
          "background": {
            "light": "#F2F2F7",
            "dark": "#0D0D12"
          }
        }
      },
      "children": [
        {
          "id": "pf_stack",
          "type": "vstack",
          "context": {
            "_spacing": 20,
            "_alignment": "center"
          },
          "style": {
            "layout": {
              "maxWidth": "infinity",
              "padding": {
                "top": 14,
                "bottom": 28,
                "leading": 18,
                "trailing": 18
              }
            }
          },
          "children": [
            {
              "id": "pf_hero_card",
              "type": "vstack",
              "context": {
                "_spacing": 10,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "gradient": {
                      "linear": {
                        "colors": [
                          "#4F46E5",
                          "#06B6D4"
                        ],
                        "startPoint": "topLeading",
                        "endPoint": "bottomTrailing"
                      }
                    }
                  },
                  "cornerRadius": 20
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.22
                  },
                  "radius": 12,
                  "y": 6
                }
              },
              "children": [
                {
                  "id": "pf_hero_label",
                  "type": "label",
                  "context": {
                    "_title": "YOUR PASSWORD",
                    "_image": "sf://key.horizontal.fill"
                  },
                  "style": {
                    "common": {
                      "font": {
                        "kind": "caption",
                        "weight": "semibold"
                      },
                      "foreground": {
                        "color": {
                          "color": "white",
                          "opacity": 0.85
                        }
                      }
                    }
                  }
                },
                {
                  "id": "pf_password_field",
                  "type": "textfield",
                  "context": {
                    "_label": "Password",
                    "_text": "${password}",
                    "_focused": "${focused}"
                  },
                  "style": {
                    "textField": {
                      "standard": "plain",
                      "autocapitalization": "none",
                      "autocorrectionDisabled": true
                    },
                    "common": {
                      "font": {
                        "kind": "system",
                        "size": 22,
                        "weight": "bold"
                      },
                      "foreground": {
                        "color": "white"
                      }
                    },
                    "layout": {
                      "maxWidth": "infinity"
                    },
                    "animation": {
                      "kind": "spring",
                      "value": "${password}",
                      "duration": 0.35,
                      "bounce": 0.3
                    }
                  },
                  "events": {
                    "onFocus": [
                      {
                        "state": {
                          "id": "pf_focus_toast",
                          "input": {
                            "toastText": "Press and hold the text, then tap Copy",
                            "showToast": true
                          },
                          "output": {
                            "success": [
                              {
                                "interval": {
                                  "id": "toast_timer",
                                  "input": {
                                    "delay": 2.5
                                  },
                                  "output": {
                                    "success": [
                                      {
                                        "state": {
                                          "id": "pf_hide_focus",
                                          "input": {
                                            "showToast": false
                                          }
                                        }
                                      },
                                      {
                                        "interval": {
                                          "id": "toast_timer",
                                          "input": {
                                            "cancel": true
                                          }
                                        }
                                      }
                                    ]
                                  }
                                }
                              }
                            ]
                          }
                        }
                      }
                    ]
                  }
                },
                {
                  "id": "pf_copy_hint",
                  "type": "text",
                  "context": {
                    "_text": "Press and hold the password to select and copy it."
                  },
                  "style": {
                    "common": {
                      "font": "caption",
                      "foreground": {
                        "color": {
                          "color": "white",
                          "opacity": 0.8
                        }
                      }
                    }
                  }
                }
              ]
            },
            {
              "id": "pf_length_card",
              "type": "vstack",
              "context": {
                "_spacing": 12,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "light": "#FFFFFF",
                    "dark": "#1C1C22"
                  },
                  "cornerRadius": 16
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.1
                  },
                  "radius": 8,
                  "y": 4
                }
              },
              "children": [
                {
                  "id": "pf_length_row",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "pf_length_title",
                      "type": "label",
                      "context": {
                        "_title": "Length",
                        "_image": "sf://ruler"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": {
                            "color": "onSurface"
                          }
                        }
                      }
                    },
                    {
                      "id": "pf_length_sp",
                      "type": "spacer"
                    },
                    {
                      "id": "pf_length_value",
                      "type": "text",
                      "context": {
                        "_text": "{{ ${length} + ' chars' }}"
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "title3",
                            "weight": "bold"
                          },
                          "foreground": {
                            "color": "accentColor"
                          }
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "pf_slider",
                  "type": "slider",
                  "context": {
                    "_value": "${sliderVal}"
                  }
                },
                {
                  "id": "pf_slider_scale",
                  "type": "hstack",
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "pf_min_lbl",
                      "type": "text",
                      "context": {
                        "_text": "8"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "secondary"
                          }
                        }
                      }
                    },
                    {
                      "id": "pf_scale_sp",
                      "type": "spacer"
                    },
                    {
                      "id": "pf_max_lbl",
                      "type": "text",
                      "context": {
                        "_text": "32"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "secondary"
                          }
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "id": "pf_types_card",
              "type": "vstack",
              "context": {
                "_spacing": 4,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": {
                    "top": 14,
                    "bottom": 8,
                    "leading": 18,
                    "trailing": 18
                  }
                },
                "common": {
                  "background": {
                    "light": "#FFFFFF",
                    "dark": "#1C1C22"
                  },
                  "cornerRadius": 16
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.1
                  },
                  "radius": 8,
                  "y": 4
                }
              },
              "children": [
                {
                  "id": "pf_types_title",
                  "type": "text",
                  "context": {
                    "_text": "Character types"
                  },
                  "style": {
                    "common": {
                      "font": "headline",
                      "foreground": {
                        "color": "onSurface"
                      }
                    },
                    "layout": {
                      "padding": {
                        "bottom": 4
                      }
                    }
                  }
                },
                {
                  "id": "pf_toggle_upper",
                  "type": "toggle",
                  "context": {
                    "_label": "Uppercase (A–Z)",
                    "_image": "textformat.size.larger",
                    "_isOn": "${upper}"
                  }
                },
                {
                  "id": "pf_div1",
                  "type": "divider"
                },
                {
                  "id": "pf_toggle_lower",
                  "type": "toggle",
                  "context": {
                    "_label": "Lowercase (a–z)",
                    "_image": "textformat.size.smaller",
                    "_isOn": "${lower}"
                  }
                },
                {
                  "id": "pf_div2",
                  "type": "divider"
                },
                {
                  "id": "pf_toggle_digits",
                  "type": "toggle",
                  "context": {
                    "_label": "Digits (2–9)",
                    "_image": "number",
                    "_isOn": "${digits}"
                  }
                },
                {
                  "id": "pf_div3",
                  "type": "divider"
                },
                {
                  "id": "pf_toggle_symbols",
                  "type": "toggle",
                  "context": {
                    "_label": "Symbols (!@#$…)",
                    "_image": "asterisk",
                    "_isOn": "${symbols}"
                  }
                }
              ]
            },
            {
              "id": "pf_regen_btn",
              "type": "button",
              "context": {
                "_label": "Regenerate",
                "_image": "sf://arrow.triangle.2.circlepath"
              },
              "style": {
                "button": {
                  "custom": {
                    "layout": {
                      "maxWidth": "infinity",
                      "minHeight": 52
                    },
                    "common": {
                      "background": {
                        "gradient": {
                          "linear": {
                            "colors": [
                              "#6366F1",
                              "#06B6D4"
                            ],
                            "startPoint": "leading",
                            "endPoint": "trailing"
                          }
                        }
                      },
                      "foreground": {
                        "color": "white"
                      },
                      "cornerRadius": 16,
                      "font": {
                        "kind": "headline"
                      }
                    }
                  }
                }
              },
              "events": {
                "onTap": [
                  {
                    "service": {
                      "id": "pf_regen_haptic",
                      "input": {
                        "serviceId": "dep_audio",
                        "params": {
                          "haptic": "success"
                        }
                      }
                    }
                  },
                  {
                    "template": {
                      "id": "pf_regen_gen",
                      "input": "act_generate"
                    }
                  },
                  {
                    "state": {
                      "id": "pf_regen_toast",
                      "input": {
                        "toastText": "New password generated",
                        "showToast": true
                      },
                      "output": {
                        "success": [
                          {
                            "interval": {
                              "id": "toast_timer",
                              "input": {
                                "delay": 2
                              },
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "pf_hide_regen",
                                      "input": {
                                        "showToast": false
                                      }
                                    }
                                  },
                                  {
                                    "interval": {
                                      "id": "toast_timer",
                                      "input": {
                                        "cancel": true
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            },
            {
              "id": "pf_toast",
              "type": "hstack",
              "context": {
                "_spacing": 8,
                "_alignment": "center"
              },
              "style": {
                "layout": {
                  "padding": {
                    "top": 10,
                    "bottom": 10,
                    "leading": 16,
                    "trailing": 16
                  }
                },
                "common": {
                  "background": {
                    "material": "regular"
                  },
                  "foreground": {
                    "color": "primary"
                  },
                  "cornerRadius": 18,
                  "opacity": "{{ ${showToast} ? 1.0 : 0.0 }}",
                  "scale": "{{ ${showToast} ? 1.0 : 0.9 }}"
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.15
                  },
                  "radius": 8,
                  "y": 4
                },
                "animation": {
                  "kind": "spring",
                  "value": "${showToast}",
                  "duration": 0.35,
                  "bounce": 0.25
                }
              },
              "children": [
                {
                  "id": "pf_toast_icon",
                  "type": "image",
                  "context": {
                    "_source": "sf://checkmark.circle.fill"
                  },
                  "style": {
                    "layout": {
                      "width": 16,
                      "height": 16
                    },
                    "common": {
                      "foreground": {
                        "color": "green"
                      }
                    }
                  }
                },
                {
                  "id": "pf_toast_text",
                  "type": "text",
                  "context": {
                    "_text": "${toastText}"
                  },
                  "style": {
                    "common": {
                      "font": "subheadline",
                      "foreground": {
                        "color": "primary"
                      }
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "events": {
    "onAppear": [
      {
        "state": {
          "id": "pf_init",
          "input": {
            "length": "{{ cast(${sliderVal} * 24 + 8, 'int') }}",
            "showToast": false
          },
          "output": {
            "success": [
              {
                "template": {
                  "id": "pf_gen_init",
                  "input": "act_generate"
                }
              }
            ]
          }
        }
      }
    ],
    "onChange": [
      {
        "observed": "sliderVal",
        "actions": [
          {
            "state": {
              "id": "pf_set_len",
              "input": {
                "length": "{{ cast(${sliderVal} * 24 + 8, 'int') }}"
              },
              "output": {
                "success": [
                  {
                    "template": {
                      "id": "pf_gen_len",
                      "input": "act_generate"
                    }
                  }
                ]
              }
            }
          }
        ]
      },
      {
        "observed": "upper",
        "actions": [
          {
            "condition": {
              "id": "pf_chk_upper",
              "input": "{{ ${upper} || ${lower} || ${digits} || ${symbols} }}",
              "output": {
                "success": [
                  {
                    "template": {
                      "id": "pf_gen_upper",
                      "input": "act_generate"
                    }
                  }
                ],
                "failure": [
                  {
                    "state": {
                      "id": "pf_rev_upper",
                      "input": {
                        "upper": true,
                        "toastText": "Keep at least one character type on",
                        "showToast": true
                      },
                      "output": {
                        "success": [
                          {
                            "service": {
                              "id": "pf_warn_upper",
                              "input": {
                                "serviceId": "dep_audio",
                                "params": {
                                  "haptic": "warning"
                                }
                              }
                            }
                          },
                          {
                            "interval": {
                              "id": "toast_timer",
                              "input": {
                                "delay": 2.2
                              },
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "pf_hide_upper",
                                      "input": {
                                        "showToast": false
                                      }
                                    }
                                  },
                                  {
                                    "interval": {
                                      "id": "toast_timer",
                                      "input": {
                                        "cancel": true
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      },
      {
        "observed": "lower",
        "actions": [
          {
            "condition": {
              "id": "pf_chk_lower",
              "input": "{{ ${upper} || ${lower} || ${digits} || ${symbols} }}",
              "output": {
                "success": [
                  {
                    "template": {
                      "id": "pf_gen_lower",
                      "input": "act_generate"
                    }
                  }
                ],
                "failure": [
                  {
                    "state": {
                      "id": "pf_rev_lower",
                      "input": {
                        "lower": true,
                        "toastText": "Keep at least one character type on",
                        "showToast": true
                      },
                      "output": {
                        "success": [
                          {
                            "service": {
                              "id": "pf_warn_lower",
                              "input": {
                                "serviceId": "dep_audio",
                                "params": {
                                  "haptic": "warning"
                                }
                              }
                            }
                          },
                          {
                            "interval": {
                              "id": "toast_timer",
                              "input": {
                                "delay": 2.2
                              },
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "pf_hide_lower",
                                      "input": {
                                        "showToast": false
                                      }
                                    }
                                  },
                                  {
                                    "interval": {
                                      "id": "toast_timer",
                                      "input": {
                                        "cancel": true
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      },
      {
        "observed": "digits",
        "actions": [
          {
            "condition": {
              "id": "pf_chk_digits",
              "input": "{{ ${upper} || ${lower} || ${digits} || ${symbols} }}",
              "output": {
                "success": [
                  {
                    "template": {
                      "id": "pf_gen_digits",
                      "input": "act_generate"
                    }
                  }
                ],
                "failure": [
                  {
                    "state": {
                      "id": "pf_rev_digits",
                      "input": {
                        "digits": true,
                        "toastText": "Keep at least one character type on",
                        "showToast": true
                      },
                      "output": {
                        "success": [
                          {
                            "service": {
                              "id": "pf_warn_digits",
                              "input": {
                                "serviceId": "dep_audio",
                                "params": {
                                  "haptic": "warning"
                                }
                              }
                            }
                          },
                          {
                            "interval": {
                              "id": "toast_timer",
                              "input": {
                                "delay": 2.2
                              },
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "pf_hide_digits",
                                      "input": {
                                        "showToast": false
                                      }
                                    }
                                  },
                                  {
                                    "interval": {
                                      "id": "toast_timer",
                                      "input": {
                                        "cancel": true
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      },
      {
        "observed": "symbols",
        "actions": [
          {
            "condition": {
              "id": "pf_chk_symbols",
              "input": "{{ ${upper} || ${lower} || ${digits} || ${symbols} }}",
              "output": {
                "success": [
                  {
                    "template": {
                      "id": "pf_gen_symbols",
                      "input": "act_generate"
                    }
                  }
                ],
                "failure": [
                  {
                    "state": {
                      "id": "pf_rev_symbols",
                      "input": {
                        "symbols": true,
                        "toastText": "Keep at least one character type on",
                        "showToast": true
                      },
                      "output": {
                        "success": [
                          {
                            "service": {
                              "id": "pf_warn_symbols",
                              "input": {
                                "serviceId": "dep_audio",
                                "params": {
                                  "haptic": "warning"
                                }
                              }
                            }
                          },
                          {
                            "interval": {
                              "id": "toast_timer",
                              "input": {
                                "delay": 2.2
                              },
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "pf_hide_symbols",
                                      "input": {
                                        "showToast": false
                                      }
                                    }
                                  },
                                  {
                                    "interval": {
                                      "id": "toast_timer",
                                      "input": {
                                        "cancel": true
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    ]
  }
}