{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "wicket",
  "type": "registry:block",
  "title": "Wicket",
  "description": "Auth card block covering every flow — sign in, sign up, magic link, OTP/2FA, forgot and reset password — morphing between steps with direction-aware slides and a spring height. SSO buttons with per-button spinners, password reveal + caps-lock warning, a 4-segment strength meter with a live rule checklist, an envelope that folds shut on 'Check your inbox' with a resend countdown, Passcode cells that auto-submit and shake on a wrong code, and async callbacks driving pending, a slide-in error banner and a drawn-check success state.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/passcode.json",
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/app/wicket/wicket.tsx",
      "type": "registry:block",
      "target": "components/crucible/wicket.tsx",
      "content": "\"use client\";\n\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useInView,\n  type Transition,\n  type Variants,\n} from \"motion/react\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { Passcode } from \"@/components/crucible/passcode\";\n\n/* ------------------------------------------------------------------ types */\n\n/** Every flow the card can show. */\nexport type WicketView = \"sign-in\" | \"sign-up\" | \"magic-link\" | \"otp\" | \"forgot\" | \"reset\";\n\n/** A single-sign-on provider button. */\nexport interface WicketProvider {\n  /** Stable id passed to `onProvider`. */\n  id: string;\n  /** Visible provider name — rendered as \"Continue with {label}\". */\n  label: string;\n  /** Optional glyph (16px). Defaults to a neutral generic mark. */\n  icon?: React.ReactNode;\n}\n\n/** Values submitted from the sign-in view. */\nexport interface WicketSignInValues {\n  email: string;\n  password: string;\n  remember: boolean;\n}\n\n/** Values submitted from the sign-up view. */\nexport interface WicketSignUpValues {\n  name: string;\n  email: string;\n  password: string;\n  acceptedTerms: boolean;\n}\n\n/** Per-view header copy override. */\nexport interface WicketCopy {\n  title?: string;\n  subtitle?: string;\n}\n\n/**\n * Async auth callbacks resolve to finish the flow, reject (throw) to show the\n * error banner with the error's message, or — for sign-in / sign-up / SSO —\n * resolve to another view (e.g. `\"otp\"`) to continue into a second step.\n */\ntype Outcome = void | WicketView;\ntype Async<T> = T | Promise<T>;\n\n/** Imperative verbs exposed through the `ref` prop. */\nexport interface WicketHandle {\n  /** Jump to a view (resets that view's pending/sent/done state). */\n  setView: (view: WicketView) => void;\n  /** Clear every field and state and return to `defaultView`. */\n  reset: () => void;\n  /** Replay the plate-in intro. */\n  replay: () => void;\n}\n\nexport interface WicketProps {\n  /** Controlled view. Omit for internal navigation (see `defaultView`). */\n  view?: WicketView;\n  /** Initial view when uncontrolled. @default \"sign-in\" */\n  defaultView?: WicketView;\n  /** Fires whenever the card asks to move to another view (links, flow steps). */\n  onViewChange?: (view: WicketView) => void;\n  /** SSO buttons shown on sign-in and sign-up. Pass `[]` to hide the row. @default Google + GitHub with generic glyphs */\n  providers?: WicketProvider[];\n  /** Logo slot above the header. @default a neutral accent mark */\n  logo?: React.ReactNode;\n  /** Product name woven into the default copy (\"Sign in to {title}\"). @default \"Halyard\" */\n  title?: string;\n  /** Override the title/subtitle of any view. */\n  copy?: Partial<Record<WicketView, WicketCopy>>;\n  /** Sign in with email + password. Resolve to `\"otp\"` to require a second factor. */\n  onSignIn?: (values: WicketSignInValues) => Async<Outcome>;\n  /** Create an account. Resolve to a view to continue (e.g. `\"otp\"` to verify). */\n  onSignUp?: (values: WicketSignUpValues) => Async<Outcome>;\n  /** Send a magic sign-in link. Resolving shows the \"Check your inbox\" state. */\n  onMagicLink?: (email: string) => Async<void>;\n  /** Verify a one-time code (auto-submits once every cell is filled). Reject to shake + clear. */\n  onVerifyOtp?: (code: string) => Async<void>;\n  /** Send a password-reset email. Resolving shows the sent state. */\n  onForgot?: (email: string) => Async<void>;\n  /** Set a new password from a reset link. */\n  onReset?: (values: { password: string }) => Async<void>;\n  /** SSO button pressed. Resolve to finish, or to a view to continue. */\n  onProvider?: (id: string) => Async<Outcome>;\n  /** A \"Resend\" button was pressed (after its countdown). */\n  onResend?: (view: \"magic-link\" | \"otp\" | \"forgot\", email: string) => Async<void>;\n  /** Fires when a flow reaches its final success state. */\n  onComplete?: (view: WicketView) => void;\n  /** Prefill the email field. */\n  defaultEmail?: string;\n  /** Seconds before \"Resend\" re-enables. @default 30 */\n  resendSeconds?: number;\n  /** Number of OTP cells. @default 6 */\n  otpLength?: number;\n  /** The single signature accent — primary button, focus rings, links. @default violet #a78bfa */\n  accentColor?: string;\n  /** Imperative handle (`setView`, `reset`, `replay`). React 19 ref-as-prop. */\n  ref?: React.Ref<WicketHandle>;\n  className?: string;\n}\n\n/* -------------------------------------------------------------- constants */\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\nconst SPRING: Transition = { type: \"spring\", stiffness: 380, damping: 36, mass: 0.8 };\nconst INSTANT: Transition = { duration: 0 };\nconst SUCCESS = \"#34d399\";\nconst DANGER = \"#fb7185\";\n\nconst DEFAULT_PROVIDERS: WicketProvider[] = [\n  { id: \"google\", label: \"Google\", icon: <GlobeGlyph /> },\n  { id: \"github\", label: \"GitHub\", icon: <BracketsGlyph /> },\n];\n\n/** Depth for direction-aware slides: deeper = slides in from the right. */\nconst DEPTH: Record<WicketView, number> = {\n  \"sign-in\": 0,\n  \"sign-up\": 1,\n  \"magic-link\": 1,\n  forgot: 1,\n  otp: 2,\n  reset: 2,\n};\nconst ORDER: WicketView[] = [\"sign-in\", \"sign-up\", \"magic-link\", \"forgot\", \"otp\", \"reset\"];\n\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\n\nconst RULES = [\n  { id: \"len\", label: \"8+ characters\", test: (p: string) => p.length >= 8 },\n  { id: \"case\", label: \"Upper & lowercase\", test: (p: string) => /[a-z]/.test(p) && /[A-Z]/.test(p) },\n  { id: \"num\", label: \"A number\", test: (p: string) => /\\d/.test(p) },\n  { id: \"sym\", label: \"A symbol\", test: (p: string) => /[^A-Za-z0-9]/.test(p) },\n] as const;\nconst STRENGTH = [\n  { label: \"\", color: \"transparent\" },\n  { label: \"Weak\", color: \"#f87171\" },\n  { label: \"Fair\", color: \"#fbbf24\" },\n  { label: \"Good\", color: \"#a3e635\" },\n  { label: \"Strong\", color: SUCCESS },\n] as const;\n\n/* ---------------------------------------------------------------- helpers */\n\n/** Black or white text, whichever reads against the accent fill. */\nfunction readableOn(hex: string): string {\n  const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());\n  if (!m) return \"#0a0a0a\";\n  let s = m[1];\n  if (s.length === 3) s = s.replace(/./g, (c) => c + c);\n  const n = parseInt(s, 16);\n  const lum = 0.2126 * ((n >> 16) & 255) + 0.7152 * ((n >> 8) & 255) + 0.0722 * (n & 255);\n  return lum > 140 ? \"#0a0a0a\" : \"#ffffff\";\n}\n\nfunction strength(p: string): number {\n  if (!p) return 0;\n  const met = RULES.filter((r) => r.test(p)).length;\n  // Short passwords can't be better than Weak no matter the mix.\n  return p.length < 8 ? Math.min(met, 1) || 1 : Math.max(1, met);\n}\n\nfunction maskEmail(email: string): string {\n  const [user, domain] = email.split(\"@\");\n  if (!user || !domain) return email;\n  return `${user[0]}${\"•\".repeat(Math.min(4, Math.max(2, user.length - 1)))}@${domain}`;\n}\n\nconst wait = (ms: number) => new Promise<void>((r) => window.setTimeout(r, ms));\n\nfunction errorMessage(e: unknown, fallback: string): string {\n  if (e instanceof Error && e.message) return e.message;\n  if (typeof e === \"string\" && e) return e;\n  return fallback;\n}\n\n/** Ticking countdown; timestamps only read in handlers/effects. */\nfunction useCountdown() {\n  const [left, setLeft] = React.useState(0);\n  const endRef = React.useRef(0);\n  const start = React.useCallback((seconds: number) => {\n    endRef.current = performance.now() + seconds * 1000;\n    setLeft(seconds);\n  }, []);\n  const clear = React.useCallback(() => {\n    endRef.current = 0;\n    setLeft(0);\n  }, []);\n  React.useEffect(() => {\n    if (left <= 0) return;\n    const t = window.setInterval(() => {\n      const next = Math.max(0, Math.ceil((endRef.current - performance.now()) / 1000));\n      setLeft(next);\n    }, 250);\n    return () => window.clearInterval(t);\n  }, [left > 0]); // eslint-disable-line react-hooks/exhaustive-deps\n  return { left, start, clear };\n}\n\nconst fmtClock = (s: number) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, \"0\")}`;\n\n/* ------------------------------------------------------------------ glyphs */\n\nfunction GlobeGlyph() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.3\" className=\"size-4\" aria-hidden>\n      <circle cx=\"8\" cy=\"8\" r=\"6.25\" />\n      <path d=\"M1.75 8h12.5M8 1.75c1.8 1.9 2.6 4 2.6 6.25S9.8 12.35 8 14.25M8 1.75C6.2 3.65 5.4 5.75 5.4 8s.8 4.35 2.6 6.25\" />\n    </svg>\n  );\n}\n\nfunction BracketsGlyph() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\" aria-hidden>\n      <path d=\"M5.25 4.5 1.75 8l3.5 3.5M10.75 4.5 14.25 8l-3.5 3.5M9.1 2.75 6.9 13.25\" />\n    </svg>\n  );\n}\n\nfunction DefaultLogo({ accent }: { accent: string }) {\n  return (\n    <span\n      className=\"relative grid size-10 place-items-center rounded-xl border border-white/[0.1] bg-neutral-950 shadow-[inset_0_1px_0_rgba(255,255,255,0.06)]\"\n      aria-hidden\n    >\n      <span\n        className=\"absolute inset-0 rounded-xl opacity-60\"\n        style={{ background: `radial-gradient(70% 70% at 50% 0%, color-mix(in srgb, ${accent} 35%, transparent), transparent 70%)` }}\n      />\n      <svg viewBox=\"0 0 20 20\" className=\"relative size-5\" fill=\"none\">\n        <path d=\"M4 15.5V8.2a6 6 0 0 1 12 0v7.3\" stroke={accent} strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n        <path d=\"M7.5 15.5V9.4a2.5 2.5 0 0 1 5 0v6.1\" stroke=\"white\" strokeOpacity=\"0.85\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n      </svg>\n    </span>\n  );\n}\n\nfunction Spinner({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" className={cn(\"size-4 animate-spin motion-reduce:animate-[spin_1.6s_linear_infinite]\", className)} fill=\"none\" aria-hidden>\n      <circle cx=\"8\" cy=\"8\" r=\"6\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"2\" />\n      <path d=\"M14 8a6 6 0 0 0-6-6\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction EyeGlyph({ off }: { off: boolean }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinecap=\"round\" className=\"size-4\" aria-hidden>\n      <path d=\"M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8 12.1 12.5 8 12.5 1.5 8 1.5 8Z\" />\n      <circle cx=\"8\" cy=\"8\" r=\"2\" />\n      {off && <path d=\"M2.5 2.5l11 11\" />}\n    </svg>\n  );\n}\n\n/* -------------------------------------------------------------- primitives */\n\ninterface Ctx {\n  accent: string;\n  ink: string;\n  reduced: boolean;\n}\nconst WicketCtx = React.createContext<Ctx>({ accent: \"#a78bfa\", ink: \"#0a0a0a\", reduced: false });\n\nconst inputBase =\n  \"h-10 w-full rounded-[10px] border bg-white/[0.03] px-3 text-sm text-white outline-none transition-[border-color,box-shadow,background-color] duration-150 placeholder:text-white/25 hover:bg-white/[0.045] focus:bg-white/[0.05] focus:border-[var(--wk-accent)] focus:shadow-[0_0_0_3px_var(--wk-ring)] disabled:opacity-60\";\n\ninterface FieldProps extends Omit<React.ComponentPropsWithoutRef<\"input\">, \"className\"> {\n  label: string;\n  error?: string | null;\n  hint?: React.ReactNode;\n  aside?: React.ReactNode;\n  trailing?: React.ReactNode;\n  inputRef?: React.Ref<HTMLInputElement>;\n}\n\nfunction Field({ label, error, hint, aside, trailing, inputRef, id, ...input }: FieldProps) {\n  const auto = React.useId();\n  const fid = id ?? auto;\n  const errId = `${fid}-err`;\n  const hintId = `${fid}-hint`;\n  const describedBy = [error ? errId : null, hint ? hintId : null].filter(Boolean).join(\" \") || undefined;\n  return (\n    <div className=\"flex flex-col gap-1.5\">\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <label htmlFor={fid} className=\"text-[13px] font-medium text-white/75\">\n          {label}\n        </label>\n        {aside}\n      </div>\n      <div className=\"relative\">\n        <input\n          ref={inputRef}\n          id={fid}\n          aria-invalid={error ? true : undefined}\n          aria-describedby={describedBy}\n          className={cn(\n            inputBase,\n            trailing && \"pr-10\",\n            error ? \"border-rose-400/55\" : \"border-white/[0.08]\"\n          )}\n          {...input}\n        />\n        {trailing && <div className=\"absolute inset-y-0 right-0 flex items-center pr-1.5\">{trailing}</div>}\n      </div>\n      <Collapse show={!!error}>\n        <p id={errId} className=\"flex items-center gap-1.5 pt-0.5 text-[12.5px] text-rose-300\">\n          <svg viewBox=\"0 0 16 16\" className=\"size-3.5 shrink-0\" fill=\"currentColor\" aria-hidden>\n            <path d=\"M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3.25h1.5v4.5h-1.5v-4.5Zm.75 7a.9.9 0 1 1 0-1.8.9.9 0 0 1 0 1.8Z\" />\n          </svg>\n          {error}\n        </p>\n      </Collapse>\n      {hint && <div id={hintId}>{hint}</div>}\n    </div>\n  );\n}\n\n/** Height + opacity reveal for inline messages. */\nfunction Collapse({ show, children }: { show: boolean; children: React.ReactNode }) {\n  const { reduced } = React.useContext(WicketCtx);\n  return (\n    <AnimatePresence initial={false}>\n      {show && (\n        <motion.div\n          initial={reduced ? { opacity: 0 } : { opacity: 0, height: 0 }}\n          animate={reduced ? { opacity: 1 } : { opacity: 1, height: \"auto\" }}\n          exit={reduced ? { opacity: 0 } : { opacity: 0, height: 0 }}\n          transition={reduced ? { duration: 0.12 } : { duration: 0.2, ease: EASE }}\n          className=\"overflow-hidden\"\n        >\n          {children}\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n\nfunction PrimaryButton({\n  pending,\n  children,\n  pendingLabel,\n  ...rest\n}: React.ComponentPropsWithoutRef<\"button\"> & { pending?: boolean; pendingLabel?: string }) {\n  const { accent, ink } = React.useContext(WicketCtx);\n  const inert = rest.disabled && !pending;\n  return (\n    <button\n      {...rest}\n      aria-disabled={pending || undefined}\n      className=\"relative inline-flex h-10 w-full items-center justify-center gap-2 rounded-[10px] text-sm font-semibold shadow-[inset_0_1px_0_rgba(255,255,255,0.25),0_1px_2px_rgba(0,0,0,0.4)] transition-[filter,transform] duration-150 hover:brightness-110 active:scale-[0.99] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--wk-accent)] disabled:cursor-not-allowed disabled:shadow-none disabled:hover:brightness-100 disabled:active:scale-100\"\n      style={inert ? { backgroundColor: \"rgba(255,255,255,0.06)\", color: \"rgba(255,255,255,0.35)\" } : { backgroundColor: accent, color: ink }}\n    >\n      {pending && <Spinner />}\n      <span>{pending ? (pendingLabel ?? children) : children}</span>\n    </button>\n  );\n}\n\nfunction TextLink({\n  className,\n  strong,\n  ...rest\n}: React.ComponentPropsWithoutRef<\"button\"> & { strong?: boolean }) {\n  return (\n    <button\n      type=\"button\"\n      {...rest}\n      className={cn(\n        \"rounded-[6px] text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[var(--wk-accent)] focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-900 disabled:cursor-not-allowed disabled:opacity-50\",\n        strong ? \"text-[var(--wk-accent)] hover:brightness-125\" : \"text-white/55 hover:text-white\",\n        className\n      )}\n    />\n  );\n}\n\nfunction Checkbox({\n  checked,\n  onChange,\n  children,\n  error,\n  id,\n}: {\n  checked: boolean;\n  onChange: (v: boolean) => void;\n  children: React.ReactNode;\n  error?: string | null;\n  id?: string;\n}) {\n  const { accent, ink, reduced } = React.useContext(WicketCtx);\n  const auto = React.useId();\n  const fid = id ?? auto;\n  return (\n    <div className=\"flex flex-col gap-1\">\n      <label htmlFor={fid} className=\"group flex cursor-pointer items-start gap-2.5 text-[13px] leading-5 text-white/60\">\n        <span className=\"relative mt-0.5 grid size-4 shrink-0 place-items-center\">\n          <input\n            id={fid}\n            type=\"checkbox\"\n            checked={checked}\n            onChange={(e) => onChange(e.target.checked)}\n            aria-invalid={error ? true : undefined}\n            aria-describedby={error ? `${fid}-err` : undefined}\n            className={cn(\n              \"peer absolute inset-0 m-0 size-4 cursor-pointer appearance-none rounded-[5px] border bg-white/[0.03] outline-none transition-colors focus-visible:shadow-[0_0_0_3px_var(--wk-ring)] group-hover:border-white/30\",\n              error ? \"border-rose-400/60\" : \"border-white/20\"\n            )}\n            style={checked ? { backgroundColor: accent, borderColor: accent } : undefined}\n          />\n          <svg viewBox=\"0 0 12 12\" className=\"pointer-events-none relative size-3\" fill=\"none\" aria-hidden>\n            <motion.path\n              d=\"M2.5 6.2 5 8.5l4.5-5\"\n              stroke={ink}\n              strokeWidth=\"1.8\"\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              initial={false}\n              animate={{ pathLength: checked ? 1 : 0, opacity: checked ? 1 : 0 }}\n              transition={reduced ? INSTANT : { duration: 0.2, ease: EASE }}\n            />\n          </svg>\n        </span>\n        <span>{children}</span>\n      </label>\n      <Collapse show={!!error}>\n        <p id={`${fid}-err`} className=\"pl-[26px] text-[12.5px] text-rose-300\">\n          {error}\n        </p>\n      </Collapse>\n    </div>\n  );\n}\n\nfunction PasswordField({\n  label,\n  value,\n  onChange,\n  onBlur,\n  error,\n  autoComplete,\n  aside,\n  meter,\n  name,\n  placeholder,\n  disabled,\n}: {\n  label: string;\n  value: string;\n  onChange: (v: string) => void;\n  onBlur?: () => void;\n  error?: string | null;\n  autoComplete: string;\n  aside?: React.ReactNode;\n  meter?: boolean;\n  name: string;\n  placeholder?: string;\n  disabled?: boolean;\n}) {\n  const [shown, setShown] = React.useState(false);\n  const [caps, setCaps] = React.useState(false);\n  const capsCheck = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (typeof e.getModifierState === \"function\") setCaps(e.getModifierState(\"CapsLock\"));\n  };\n  return (\n    <Field\n      label={label}\n      name={name}\n      type={shown ? \"text\" : \"password\"}\n      autoComplete={autoComplete}\n      placeholder={placeholder}\n      value={value}\n      disabled={disabled}\n      onChange={(e) => onChange(e.target.value)}\n      onKeyDown={capsCheck}\n      onKeyUp={capsCheck}\n      onBlur={() => {\n        setCaps(false);\n        onBlur?.();\n      }}\n      error={error}\n      aside={aside}\n      spellCheck={false}\n      trailing={\n        <button\n          type=\"button\"\n          onClick={() => setShown((s) => !s)}\n          aria-label={shown ? \"Hide password\" : \"Show password\"}\n          aria-pressed={shown}\n          className=\"grid size-7 place-items-center rounded-[7px] text-white/45 outline-none transition-colors hover:bg-white/[0.06] hover:text-white focus-visible:ring-2 focus-visible:ring-[var(--wk-accent)]\"\n        >\n          <EyeGlyph off={shown} />\n        </button>\n      }\n      hint={\n        <>\n          <Collapse show={caps}>\n            <p className=\"flex items-center gap-1.5 pt-0.5 text-[12.5px] text-amber-300/90\" role=\"status\">\n              <svg viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinejoin=\"round\" aria-hidden>\n                <path d=\"M8 2.5 2.75 8H5.5v3h5V8h2.75L8 2.5ZM5.5 13.5h5\" />\n              </svg>\n              Caps Lock is on\n            </p>\n          </Collapse>\n          {meter && <StrengthMeter password={value} />}\n        </>\n      }\n    />\n  );\n}\n\nfunction StrengthMeter({ password }: { password: string }) {\n  const { reduced } = React.useContext(WicketCtx);\n  const score = strength(password);\n  const tone = STRENGTH[score];\n  return (\n    <div className=\"pt-1.5\">\n      <div className=\"flex items-center gap-3\">\n        <div className=\"grid flex-1 grid-cols-4 gap-1.5\" aria-hidden>\n          {[1, 2, 3, 4].map((seg) => (\n            <span key={seg} className=\"relative h-1 overflow-hidden rounded-full bg-white/[0.08]\">\n              <motion.span\n                className=\"absolute inset-0 origin-left rounded-full\"\n                initial={false}\n                animate={{ scaleX: score >= seg ? 1 : 0, backgroundColor: score >= seg ? tone.color : \"rgba(255,255,255,0)\" }}\n                transition={reduced ? INSTANT : { duration: 0.32, ease: EASE, delay: score >= seg ? (seg - 1) * 0.04 : 0 }}\n              />\n            </span>\n          ))}\n        </div>\n        <span\n          className=\"w-12 text-right text-[12px] font-medium tabular-nums transition-colors\"\n          style={{ color: score ? tone.color : \"rgba(255,255,255,0.3)\" }}\n          aria-live=\"polite\"\n        >\n          {password ? (\n            <>\n              <span className=\"sr-only\">Password strength: </span>\n              {tone.label}\n            </>\n          ) : (\n            \"—\"\n          )}\n        </span>\n      </div>\n      <ul className=\"mt-2.5 grid grid-cols-2 gap-x-3 gap-y-1.5\">\n        {RULES.map((r) => {\n          const ok = !!password && r.test(password);\n          return (\n            <li key={r.id} className={cn(\"flex items-center gap-1.5 text-[12px] transition-colors\", ok ? \"text-white/75\" : \"text-white/35\")}>\n              <span\n                className=\"grid size-3.5 shrink-0 place-items-center rounded-full border transition-colors\"\n                style={{ borderColor: ok ? SUCCESS : \"rgba(255,255,255,0.18)\", backgroundColor: ok ? `color-mix(in srgb, ${SUCCESS} 18%, transparent)` : \"transparent\" }}\n              >\n                <svg viewBox=\"0 0 12 12\" className=\"size-2.5\" fill=\"none\" aria-hidden>\n                  <motion.path\n                    d=\"M2.5 6.2 5 8.5l4.5-5\"\n                    stroke={SUCCESS}\n                    strokeWidth=\"2\"\n                    strokeLinecap=\"round\"\n                    strokeLinejoin=\"round\"\n                    initial={false}\n                    animate={{ pathLength: ok ? 1 : 0, opacity: ok ? 1 : 0 }}\n                    transition={reduced ? INSTANT : { duration: 0.25, ease: EASE }}\n                  />\n                </svg>\n              </span>\n              <span>\n                {r.label}\n                <span className=\"sr-only\">{ok ? \" — met\" : \" — not met\"}</span>\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n    </div>\n  );\n}\n\nfunction ErrorBanner({ message, onDismiss }: { message: string | null; onDismiss: () => void }) {\n  const { reduced } = React.useContext(WicketCtx);\n  return (\n    <AnimatePresence initial={false}>\n      {message && (\n        <motion.div\n          key=\"banner\"\n          initial={reduced ? { opacity: 0 } : { opacity: 0, height: 0, y: -6 }}\n          animate={reduced ? { opacity: 1 } : { opacity: 1, height: \"auto\", y: 0 }}\n          exit={reduced ? { opacity: 0 } : { opacity: 0, height: 0, y: -6 }}\n          transition={reduced ? { duration: 0.12 } : { duration: 0.26, ease: EASE }}\n          className=\"overflow-hidden\"\n        >\n          <div className=\"pb-4\">\n            <div\n              role=\"alert\"\n              className=\"flex items-start gap-2.5 rounded-[10px] border px-3 py-2.5 text-[13px] leading-5\"\n              style={{ borderColor: `color-mix(in srgb, ${DANGER} 30%, transparent)`, backgroundColor: `color-mix(in srgb, ${DANGER} 9%, transparent)`, color: \"#fecdd3\" }}\n            >\n              <svg viewBox=\"0 0 16 16\" className=\"mt-0.5 size-4 shrink-0\" fill=\"currentColor\" aria-hidden>\n                <path d=\"M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3.25h1.5v4.5h-1.5v-4.5Zm.75 7a.9.9 0 1 1 0-1.8.9.9 0 0 1 0 1.8Z\" />\n              </svg>\n              <span className=\"flex-1\">{message}</span>\n              <button\n                type=\"button\"\n                onClick={onDismiss}\n                aria-label=\"Dismiss error\"\n                className=\"-m-1 grid size-6 place-items-center rounded-md text-rose-200/70 outline-none hover:bg-white/[0.06] hover:text-white focus-visible:ring-2 focus-visible:ring-rose-300\"\n              >\n                <svg viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden>\n                  <path d=\"m4 4 8 8M12 4l-8 8\" />\n                </svg>\n              </button>\n            </div>\n          </div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n\nfunction Divider({ children }: { children: React.ReactNode }) {\n  return (\n    <div className=\"flex items-center gap-3 text-[11.5px] font-medium uppercase tracking-[0.12em] text-white/30\">\n      <span className=\"h-px flex-1 bg-white/[0.08]\" />\n      {children}\n      <span className=\"h-px flex-1 bg-white/[0.08]\" />\n    </div>\n  );\n}\n\n/** Envelope whose letter drops in and flap folds shut. */\nfunction Envelope() {\n  const { accent, reduced } = React.useContext(WicketCtx);\n  const flap = \"M8 22 L48 50 L88 22\";\n  return (\n    <svg viewBox=\"0 -8 96 88\" className=\"h-[80px] w-[88px]\" fill=\"none\" aria-hidden>\n      <defs>\n        <linearGradient id=\"wk-env-back\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#262626\" />\n          <stop offset=\"1\" stopColor=\"#171717\" />\n        </linearGradient>\n      </defs>\n      {/* back panel */}\n      <rect x=\"8\" y=\"22\" width=\"80\" height=\"54\" rx=\"7\" fill=\"url(#wk-env-back)\" stroke=\"rgba(255,255,255,0.14)\" />\n      {/* open flap (behind the letter) — fades as the front flap folds */}\n      {!reduced && (\n        <motion.path\n          d=\"M8 22 L48 -6 L88 22 Z\"\n          fill=\"#1f1f1f\"\n          stroke=\"rgba(255,255,255,0.14)\"\n          strokeLinejoin=\"round\"\n          initial={{ opacity: 1 }}\n          animate={{ opacity: 0 }}\n          transition={{ delay: 0.5, duration: 0.01 }}\n        />\n      )}\n      {/* letter */}\n      <motion.g initial={reduced ? false : { y: -26 }} animate={{ y: 0 }} transition={{ duration: 0.45, ease: EASE, delay: 0.05 }}>\n        <rect x=\"18\" y=\"28\" width=\"60\" height=\"40\" rx=\"4\" fill=\"#fafafa\" />\n        <rect x=\"26\" y=\"36\" width=\"26\" height=\"4\" rx=\"2\" fill={accent} />\n        <rect x=\"26\" y=\"45\" width=\"44\" height=\"3\" rx=\"1.5\" fill=\"#d4d4d4\" />\n        <rect x=\"26\" y=\"52\" width=\"36\" height=\"3\" rx=\"1.5\" fill=\"#d4d4d4\" />\n      </motion.g>\n      {/* front pocket */}\n      <path d=\"M8 22 L48 50 L88 22 V69 a7 7 0 0 1 -7 7 H15 a7 7 0 0 1 -7 -7 Z\" fill=\"#1c1c1c\" stroke=\"rgba(255,255,255,0.14)\" strokeLinejoin=\"round\" />\n      {/* front flap folding shut */}\n      <motion.path\n        d={`${flap} Z`}\n        fill=\"#232323\"\n        stroke=\"rgba(255,255,255,0.18)\"\n        strokeLinejoin=\"round\"\n        style={{ transformBox: \"fill-box\", transformOrigin: \"50% 0%\" }}\n        initial={reduced ? false : { scaleY: -1, opacity: 0 }}\n        animate={{ scaleY: 1, opacity: 1 }}\n        transition={reduced ? INSTANT : { scaleY: { delay: 0.5, duration: 0.42, ease: EASE }, opacity: { delay: 0.5, duration: 0.01 } }}\n      />\n      {/* seal */}\n      <motion.circle\n        cx=\"48\"\n        cy=\"50\"\n        r=\"5\"\n        fill={accent}\n        initial={reduced ? false : { scale: 0, opacity: 0 }}\n        animate={{ scale: 1, opacity: 1 }}\n        transition={reduced ? INSTANT : { delay: 0.86, type: \"spring\", stiffness: 520, damping: 26 }}\n        style={{ transformBox: \"fill-box\", transformOrigin: \"50% 50%\" }}\n      />\n    </svg>\n  );\n}\n\nfunction DrawnCheck() {\n  const { reduced } = React.useContext(WicketCtx);\n  return (\n    <svg viewBox=\"0 0 56 56\" className=\"size-14\" fill=\"none\" aria-hidden>\n      <circle cx=\"28\" cy=\"28\" r=\"26\" fill={`color-mix(in srgb, ${SUCCESS} 10%, transparent)`} />\n      <motion.circle\n        cx=\"28\"\n        cy=\"28\"\n        r=\"25\"\n        stroke={SUCCESS}\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n        initial={reduced ? false : { pathLength: 0 }}\n        animate={{ pathLength: 1 }}\n        transition={reduced ? INSTANT : { duration: 0.5, ease: EASE }}\n        style={{ rotate: -90, transformOrigin: \"50% 50%\" }}\n      />\n      <motion.path\n        d=\"M18 28.5 25 35.5 38.5 21\"\n        stroke={SUCCESS}\n        strokeWidth=\"3\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={reduced ? false : { pathLength: 0 }}\n        animate={{ pathLength: 1 }}\n        transition={reduced ? INSTANT : { duration: 0.34, ease: EASE, delay: 0.38 }}\n      />\n    </svg>\n  );\n}\n\n/* --------------------------------------------------------------- component */\n\ntype Phase = \"form\" | \"sent\" | \"done\";\ntype FieldName = \"name\" | \"email\" | \"password\" | \"confirm\" | \"terms\";\n\ninterface Values {\n  name: string;\n  email: string;\n  password: string;\n  confirm: string;\n  remember: boolean;\n  terms: boolean;\n}\n\nfunction validate(view: WicketView, v: Values): Partial<Record<FieldName, string>> {\n  const e: Partial<Record<FieldName, string>> = {};\n  const needsEmail = view === \"sign-in\" || view === \"sign-up\" || view === \"magic-link\" || view === \"forgot\";\n  if (needsEmail) {\n    if (!v.email.trim()) e.email = \"Enter your email address\";\n    else if (!EMAIL_RE.test(v.email.trim())) e.email = \"That doesn't look like a valid email\";\n  }\n  if (view === \"sign-in\" && !v.password) e.password = \"Enter your password\";\n  if (view === \"sign-up\" || view === \"reset\") {\n    const s = strength(v.password);\n    if (!v.password) e.password = \"Choose a password\";\n    else if (v.password.length < 8) e.password = \"Use at least 8 characters\";\n    else if (s < 3) e.password = \"Mix in a number, symbol or capital letter\";\n  }\n  if (view === \"sign-up\") {\n    if (!v.name.trim()) e.name = \"Tell us your name\";\n    if (!v.terms) e.terms = \"Please accept the terms to continue\";\n  }\n  if (view === \"reset\") {\n    if (!v.confirm) e.confirm = \"Confirm your new password\";\n    else if (v.confirm !== v.password) e.confirm = \"Passwords don't match\";\n  }\n  return e;\n}\n\nconst FIELD_ORDER: FieldName[] = [\"name\", \"email\", \"password\", \"confirm\", \"terms\"];\n\nconst EMPTY: Values = { name: \"\", email: \"\", password: \"\", confirm: \"\", remember: true, terms: false };\n\n/**\n * Wicket — one auth card for every flow. Sign in, sign up (with a 4-segment\n * strength meter and live rule checklist), magic link (an envelope folds shut\n * on \"Check your inbox\" with a resend countdown), OTP/2FA (Passcode cells that\n * auto-submit and shake on a wrong code), and forgot/reset password. Views\n * morph with direction-aware slides inside a spring-animated height; async\n * callbacks drive pending spinners, a slide-in error banner and a drawn-check\n * success state. Real `<form>`s, autocomplete hints, labelled fields with\n * `aria-invalid`/`aria-describedby`, validation on blur and a shake on invalid\n * submit; focus lands on the first field whenever the view changes. Reduced\n * motion swaps every slide and shake for crossfades — never blank.\n */\nexport function Wicket({\n  view: viewProp,\n  defaultView = \"sign-in\",\n  onViewChange,\n  providers = DEFAULT_PROVIDERS,\n  logo,\n  title = \"Halyard\",\n  copy,\n  onSignIn,\n  onSignUp,\n  onMagicLink,\n  onVerifyOtp,\n  onForgot,\n  onReset,\n  onProvider,\n  onResend,\n  onComplete,\n  defaultEmail = \"\",\n  resendSeconds = 30,\n  otpLength = 6,\n  accentColor = \"#a78bfa\",\n  ref,\n  className,\n}: WicketProps) {\n  const reduced = useReducedMotion();\n  const accent = accentColor;\n  const ink = readableOn(accent);\n  const ctx = React.useMemo<Ctx>(() => ({ accent, ink, reduced }), [accent, ink, reduced]);\n\n  /* ----- view (controlled / uncontrolled) */\n  const [innerView, setInnerView] = React.useState<WicketView>(defaultView);\n  const view = viewProp ?? innerView;\n\n  const [values, setValues] = React.useState<Values>(() => ({ ...EMPTY, email: defaultEmail }));\n  const [touched, setTouched] = React.useState<Set<FieldName>>(() => new Set());\n  const [submitted, setSubmitted] = React.useState(false);\n  const [phase, setPhase] = React.useState<Phase>(\"form\");\n  const [pending, setPending] = React.useState(false);\n  const [providerPending, setProviderPending] = React.useState<string | null>(null);\n  const [error, setError] = React.useState<string | null>(null);\n  const [otp, setOtp] = React.useState(\"\");\n  const [doneOf, setDoneOf] = React.useState<WicketView>(\"sign-in\");\n  const [announce, setAnnounce] = React.useState(\"\");\n  const [dir, setDir] = React.useState(1);\n  const countdown = useCountdown();\n\n  // Reset per-view state whenever the visible view changes (controlled or not).\n  const [shownView, setShownView] = React.useState(view);\n  if (shownView !== view) {\n    const d = DEPTH[view] - DEPTH[shownView] || Math.sign(ORDER.indexOf(view) - ORDER.indexOf(shownView)) || 1;\n    setShownView(view);\n    setDir(d > 0 ? 1 : -1);\n    setPhase(\"form\");\n    setPending(false);\n    setProviderPending(null);\n    setError(null);\n    setSubmitted(false);\n    setTouched(new Set());\n    setOtp(\"\");\n    setValues((v) => ({ ...v, password: \"\", confirm: \"\" }));\n  }\n\n  // Focus management: after the user navigates, focus the next stage's first field.\n  const navigatedRef = React.useRef(false);\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const shakeRef = React.useRef<HTMLDivElement>(null);\n  const otpRef = React.useRef<HTMLDivElement>(null);\n\n  const go = React.useCallback(\n    (next: WicketView) => {\n      navigatedRef.current = true;\n      if (viewProp === undefined) setInnerView(next);\n      onViewChange?.(next);\n    },\n    [viewProp, onViewChange]\n  );\n\n  // OTP code was just \"sent\" on entering the view — start its resend timer.\n  React.useEffect(() => {\n    if (view === \"otp\") countdown.start(resendSeconds);\n    else countdown.clear();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [view]);\n\n  const focusStage = React.useCallback(() => {\n    const root = stageRef.current;\n    if (!root) return;\n    const target =\n      root.querySelector<HTMLElement>(\"[data-autofocus]\") ??\n      root.querySelector<HTMLElement>(\"input:not([type=hidden]):not([type=checkbox]):not(:disabled)\");\n    target?.focus({ preventScroll: true });\n  }, []);\n\n  /* ----- intro */\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const inView = useInView(rootRef, { once: true, amount: 0.2 });\n  const [introKey, setIntroKey] = React.useState(0);\n  const [fallback, setFallback] = React.useState(false);\n  React.useEffect(() => {\n    // Never stuck invisible if the in-view trigger never fires.\n    const t = window.setTimeout(() => setFallback(true), 1400);\n    return () => window.clearTimeout(t);\n  }, []);\n  const revealed = inView || fallback || reduced;\n\n  /* ----- field helpers */\n  const errors = React.useMemo(() => validate(view, values), [view, values]);\n  const errFor = (f: FieldName) => (submitted || touched.has(f) ? (errors[f] ?? null) : null);\n  const set = <K extends keyof Values>(k: K, v: Values[K]) => {\n    setValues((s) => ({ ...s, [k]: v }));\n    if (error) setError(null);\n  };\n  const touch = (f: FieldName) => setTouched((t) => (t.has(f) ? t : new Set(t).add(f)));\n\n  const shake = React.useCallback(\n    (el: HTMLElement | null) => {\n      if (!el || reduced) return;\n      animate(el, { x: [0, -9, 8, -6, 4, -2, 0] }, { duration: 0.42, ease: \"easeOut\" });\n    },\n    [reduced]\n  );\n\n  const finish = React.useCallback(\n    (of: WicketView) => {\n      setDoneOf(of);\n      setDir(1);\n      setPhase(\"done\");\n      setAnnounce(of === \"reset\" ? \"Password updated\" : of === \"sign-up\" ? \"Account created — redirecting\" : \"Signed in — redirecting\");\n      navigatedRef.current = true;\n      onComplete?.(of);\n    },\n    [onComplete]\n  );\n\n  /** Run an async callback with pending / error / outcome handling. */\n  const run = async (fn: () => Promise<Outcome | void>, fallbackError: string, onOk: (out: Outcome | void) => void) => {\n    setPending(true);\n    setError(null);\n    setAnnounce(\"Working…\");\n    try {\n      const out = await fn();\n      setPending(false);\n      onOk(out);\n    } catch (e) {\n      setPending(false);\n      const msg = errorMessage(e, fallbackError);\n      setError(msg);\n      setAnnounce(\"\");\n      // OTP failures shake just the cells (see the effect below).\n      if (view !== \"otp\") shake(shakeRef.current);\n    }\n  };\n\n  const guard = (): boolean => {\n    setSubmitted(true);\n    const first = FIELD_ORDER.find((f) => errors[f]);\n    if (!first) return true;\n    shake(shakeRef.current);\n    const el = stageRef.current?.querySelector<HTMLElement>(`[data-field=\"${first}\"] input`);\n    el?.focus({ preventScroll: true });\n    setAnnounce(errors[first] ?? \"\");\n    return false;\n  };\n\n  const onSubmit = (e: React.FormEvent) => {\n    e.preventDefault();\n    if (pending) return;\n    if (!guard()) return;\n    const email = values.email.trim();\n    switch (view) {\n      case \"sign-in\":\n        void run(\n          async () => (onSignIn ? onSignIn({ email, password: values.password, remember: values.remember }) : wait(900)),\n          \"We couldn't sign you in. Try again.\",\n          (out) => (out ? go(out) : finish(\"sign-in\"))\n        );\n        break;\n      case \"sign-up\":\n        void run(\n          async () => (onSignUp ? onSignUp({ name: values.name.trim(), email, password: values.password, acceptedTerms: values.terms }) : wait(1000)),\n          \"We couldn't create your account. Try again.\",\n          (out) => (out ? go(out) : finish(\"sign-up\"))\n        );\n        break;\n      case \"magic-link\":\n      case \"forgot\":\n        void run(\n          async () => (view === \"magic-link\" ? (onMagicLink ? onMagicLink(email) : wait(900)) : onForgot ? onForgot(email) : wait(900)),\n          \"We couldn't send that email. Try again.\",\n          () => {\n            navigatedRef.current = true;\n            setDir(1);\n            setPhase(\"sent\");\n            setAnnounce(`Email sent to ${email}`);\n            countdown.start(resendSeconds);\n          }\n        );\n        break;\n      case \"reset\":\n        void run(\n          async () => (onReset ? onReset({ password: values.password }) : wait(900)),\n          \"We couldn't update your password. Try again.\",\n          () => finish(\"reset\")\n        );\n        break;\n      case \"otp\":\n        submitOtp(otp);\n        break;\n    }\n  };\n\n  const submitOtp = (code: string) => {\n    if (pending) return;\n    if (code.length < otpLength) {\n      setError(`Enter all ${otpLength} digits`);\n      shake(otpRef.current);\n      return;\n    }\n    void run(\n      async () => (onVerifyOtp ? onVerifyOtp(code) : wait(900)),\n      \"That code didn't match. Try again.\",\n      () => finish(\"otp\")\n    );\n  };\n\n  // When a verify fails, clear the cells and refocus the first one.\n  React.useEffect(() => {\n    if (view !== \"otp\" || !error || pending) return;\n    shake(otpRef.current);\n    const t = window.setTimeout(() => {\n      setOtp(\"\");\n      otpRef.current?.querySelector<HTMLInputElement>(\"input\")?.focus({ preventScroll: true });\n    }, reduced ? 0 : 420);\n    return () => window.clearTimeout(t);\n  }, [view, error, pending, shake, reduced]);\n\n  const provider = (id: string) => {\n    if (providerPending || pending) return;\n    setProviderPending(id);\n    setError(null);\n    const p = providers.find((x) => x.id === id);\n    setAnnounce(`Connecting to ${p?.label ?? id}…`);\n    Promise.resolve(onProvider ? onProvider(id) : wait(1100))\n      .then((out) => {\n        setProviderPending(null);\n        if (out) go(out);\n        else finish(view);\n      })\n      .catch((e) => {\n        setProviderPending(null);\n        setError(errorMessage(e, `We couldn't connect to ${p?.label ?? id}.`));\n        setAnnounce(\"\");\n      });\n  };\n\n  const resend = () => {\n    if (countdown.left > 0) return;\n    const v = view === \"otp\" ? \"otp\" : view === \"forgot\" ? \"forgot\" : \"magic-link\";\n    countdown.start(resendSeconds);\n    setAnnounce(v === \"otp\" ? \"A new code is on its way\" : `Sent again to ${values.email.trim()}`);\n    void Promise.resolve(onResend?.(v, values.email.trim())).catch((e) => setError(errorMessage(e, \"We couldn't resend. Try again.\")));\n  };\n\n  const reset = React.useCallback(() => {\n    navigatedRef.current = false;\n    setValues({ ...EMPTY, email: defaultEmail });\n    setTouched(new Set());\n    setSubmitted(false);\n    setPhase(\"form\");\n    setPending(false);\n    setProviderPending(null);\n    setError(null);\n    setOtp(\"\");\n    setAnnounce(\"\");\n    countdown.clear();\n    if (viewProp === undefined) setInnerView(defaultView);\n    else onViewChange?.(defaultView);\n  }, [defaultEmail, defaultView, viewProp, onViewChange, countdown]);\n\n  React.useImperativeHandle(\n    ref,\n    () => ({\n      setView: (v: WicketView) => {\n        if (v === view) {\n          navigatedRef.current = true;\n          setDir(-1);\n          setPhase(\"form\");\n          setError(null);\n          setPending(false);\n          setSubmitted(false);\n          setTouched(new Set());\n          setOtp(\"\");\n          return;\n        }\n        go(v);\n      },\n      reset,\n      replay: () => setIntroKey((k) => k + 1),\n    }),\n    [view, go, reset]\n  );\n\n  /* ----- height animation */\n  const measureRef = React.useRef<HTMLDivElement>(null);\n  const [height, setHeight] = React.useState<number | \"auto\">(\"auto\");\n  React.useLayoutEffect(() => {\n    const el = measureRef.current;\n    if (!el || typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(() => setHeight(el.offsetHeight));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const stageKey = phase === \"done\" ? `done-${doneOf}` : `${view}-${phase}`;\n  // A freshly mounted stage takes focus if the user navigated to it.\n  const attachStage = React.useCallback(\n    (el: HTMLDivElement | null) => {\n      stageRef.current = el;\n      if (el && navigatedRef.current) {\n        navigatedRef.current = false;\n        requestAnimationFrame(focusStage);\n      }\n    },\n    [focusStage]\n  );\n\n  /* ----- copy */\n  const email = values.email.trim();\n  const defaults: Record<WicketView, Required<WicketCopy>> = {\n    \"sign-in\": { title: \"Welcome back\", subtitle: `Sign in to your ${title} account` },\n    \"sign-up\": { title: \"Create your account\", subtitle: `Start your 14-day ${title} trial — no card needed` },\n    \"magic-link\": { title: \"Sign in with email\", subtitle: \"We'll email you a one-tap sign-in link\" },\n    otp: { title: \"Two-step verification\", subtitle: `Enter the ${otpLength}-digit code from your authenticator or texts` },\n    forgot: { title: \"Reset your password\", subtitle: \"Enter your email and we'll send a reset link\" },\n    reset: { title: \"Choose a new password\", subtitle: \"Make it at least 8 characters with a good mix\" },\n  };\n  const head = { ...defaults[view], ...copy?.[view] };\n\n  const variants: Variants = reduced\n    ? { enter: { opacity: 0 }, center: { opacity: 1 }, exit: { opacity: 0 } }\n    : {\n        enter: (d: number) => ({ opacity: 0, x: d * 32 }),\n        center: { opacity: 1, x: 0 },\n        exit: (d: number) => ({ opacity: 0, x: d * -32 }),\n      };\n  const stageTransition: Transition = reduced\n    ? { duration: 0.16 }\n    : { x: { type: \"spring\", stiffness: 420, damping: 38 }, opacity: { duration: 0.18 } };\n\n  const showProviders = (view === \"sign-in\" || view === \"sign-up\") && providers.length > 0;\n  const busy = pending || !!providerPending;\n\n  /* ----- stage bodies */\n  const header = (t: string, s: React.ReactNode, center = true) => (\n    <div className={cn(\"mb-6 flex flex-col gap-1.5\", center && \"items-center text-center\")}>\n      <h2 className=\"text-[19px] font-semibold tracking-[-0.01em] text-white outline-none\" tabIndex={-1}>\n        {t}\n      </h2>\n      <p className=\"max-w-[36ch] text-[13.5px] leading-5 text-white/50 text-balance\">{s}</p>\n    </div>\n  );\n\n  let body: React.ReactNode;\n  if (phase === \"done\") {\n    const msg: Record<WicketView, [string, string]> = {\n      \"sign-in\": [\"Signed in\", \"Signed in — redirecting…\"],\n      \"sign-up\": [\"Account created\", \"Welcome aboard — redirecting…\"],\n      \"magic-link\": [\"Signed in\", \"Signed in — redirecting…\"],\n      forgot: [\"Signed in\", \"Signed in — redirecting…\"],\n      otp: [\"Verified\", \"Signed in — redirecting…\"],\n      reset: [\"Password updated\", \"You can now sign in with your new password.\"],\n    };\n    const [t, s] = msg[doneOf];\n    body = (\n      <div className=\"flex flex-col items-center py-4 text-center\" role=\"status\">\n        <DrawnCheck />\n        <h2 className=\"mt-5 text-[19px] font-semibold tracking-[-0.01em] text-white outline-none\" tabIndex={-1} data-autofocus>\n          {t}\n        </h2>\n        <p className=\"mt-1.5 text-[13.5px] text-white/50\">{s}</p>\n        {doneOf === \"reset\" ? (\n          <div className=\"mt-6 w-full\">\n            <PrimaryButton type=\"button\" onClick={() => go(\"sign-in\")}>\n              Continue to sign in\n            </PrimaryButton>\n          </div>\n        ) : (\n          <div className=\"mt-6 h-1 w-40 overflow-hidden rounded-full bg-white/[0.06]\" aria-hidden>\n            <motion.div\n              className=\"h-full rounded-full\"\n              style={{ backgroundColor: accent, originX: 0 }}\n              initial={reduced ? { scaleX: 1 } : { scaleX: 0 }}\n              animate={{ scaleX: 1 }}\n              transition={reduced ? INSTANT : { duration: 2.4, ease: [0.4, 0, 0.2, 1], delay: 0.4 }}\n            />\n          </div>\n        )}\n      </div>\n    );\n  } else if (phase === \"sent\") {\n    body = (\n      <div className=\"flex flex-col items-center text-center\">\n        <Envelope />\n        <h2 className=\"mt-5 text-[19px] font-semibold tracking-[-0.01em] text-white outline-none\" tabIndex={-1}>\n          Check your inbox\n        </h2>\n        <p className=\"mt-1.5 max-w-[32ch] text-[13.5px] leading-5 text-white/50\">\n          {view === \"forgot\" ? \"We sent a password reset link to\" : \"We sent a sign-in link to\"}\n          <br />\n          <span className=\"font-medium text-white/85\">{email}</span>\n        </p>\n        <p className=\"mt-1 text-[12.5px] text-white/35\">The link expires in 15 minutes.</p>\n        <div className=\"mt-6 flex w-full flex-col gap-2.5\">\n          <button\n            type=\"button\"\n            data-autofocus\n            onClick={resend}\n            aria-disabled={countdown.left > 0}\n            className={cn(\n              \"inline-flex h-10 w-full items-center justify-center gap-2 rounded-[10px] border border-white/[0.1] bg-white/[0.04] text-sm font-medium text-white/85 outline-none transition-colors focus-visible:border-[var(--wk-accent)] focus-visible:shadow-[0_0_0_3px_var(--wk-ring)]\",\n              countdown.left > 0 ? \"cursor-default text-white/45\" : \"hover:bg-white/[0.07]\"\n            )}\n          >\n            {countdown.left > 0 ? (\n              <>\n                Resend in <span className=\"tabular-nums\">{fmtClock(countdown.left)}</span>\n              </>\n            ) : (\n              \"Resend email\"\n            )}\n          </button>\n          <TextLink className=\"self-center\" onClick={() => { navigatedRef.current = true; setDir(-1); setPhase(\"form\"); countdown.clear(); }}>\n            Use a different email\n          </TextLink>\n        </div>\n      </div>\n    );\n  } else {\n    const emailField = (\n      <div data-field=\"email\">\n        <Field\n          label=\"Email\"\n          name=\"email\"\n          type=\"email\"\n          inputMode=\"email\"\n          autoComplete=\"email\"\n          placeholder=\"you@company.com\"\n          value={values.email}\n          onChange={(e) => set(\"email\", e.target.value)}\n          onBlur={() => values.email && touch(\"email\")}\n          error={errFor(\"email\")}\n          disabled={busy}\n          spellCheck={false}\n          autoCapitalize=\"none\"\n        />\n      </div>\n    );\n    body = (\n      <>\n        {header(head.title, view === \"otp\" && email ? <>Enter the {otpLength}-digit code we sent to <span className=\"text-white/80\">{maskEmail(email)}</span></> : head.subtitle)}\n        <ErrorBanner message={error} onDismiss={() => setError(null)} />\n        {showProviders && (\n          <>\n            <div className={cn(\"grid gap-2\", providers.length === 1 ? \"grid-cols-1\" : providers.length === 2 ? \"grid-cols-2\" : \"grid-cols-3\")}>\n              {providers.map((p) => {\n                const isPending = providerPending === p.id;\n                return (\n                  <button\n                    key={p.id}\n                    type=\"button\"\n                    onClick={() => provider(p.id)}\n                    disabled={busy && !isPending}\n                    aria-busy={isPending || undefined}\n                    aria-label={`Continue with ${p.label}`}\n                    title={`Continue with ${p.label}`}\n                    className=\"inline-flex h-10 min-w-0 items-center justify-center gap-2 rounded-[10px] border border-white/[0.1] bg-white/[0.03] px-3 text-[13px] font-medium text-white/85 outline-none transition-colors hover:border-white/[0.16] hover:bg-white/[0.06] focus-visible:border-[var(--wk-accent)] focus-visible:shadow-[0_0_0_3px_var(--wk-ring)] disabled:opacity-45\"\n                  >\n                    <span className=\"grid size-4 shrink-0 place-items-center text-white/70\">{isPending ? <Spinner /> : (p.icon ?? <GlobeGlyph />)}</span>\n                    <span className=\"truncate\">\n                      {providers.length === 1 && \"Continue with \"}\n                      {p.label}\n                    </span>\n                  </button>\n                );\n              })}\n            </div>\n            <div className=\"my-5\">\n              <Divider>or</Divider>\n            </div>\n          </>\n        )}\n        <form noValidate onSubmit={onSubmit} className=\"flex flex-col gap-4\" aria-busy={pending || undefined}>\n          {view === \"sign-in\" && (\n            <>\n              {emailField}\n              <div data-field=\"password\">\n                <PasswordField\n                  label=\"Password\"\n                  name=\"password\"\n                  autoComplete=\"current-password\"\n                  placeholder=\"••••••••\"\n                  value={values.password}\n                  onChange={(v) => set(\"password\", v)}\n                  onBlur={() => values.password && touch(\"password\")}\n                  error={errFor(\"password\")}\n                  disabled={busy}\n                  aside={<TextLink onClick={() => go(\"forgot\")}>Forgot password?</TextLink>}\n                />\n              </div>\n              <Checkbox checked={values.remember} onChange={(v) => set(\"remember\", v)}>\n                Keep me signed in for 30 days\n              </Checkbox>\n              <div className=\"flex flex-col gap-3 pt-1\">\n                <PrimaryButton type=\"submit\" pending={pending} pendingLabel=\"Signing in…\">\n                  Sign in\n                </PrimaryButton>\n                <TextLink className=\"self-center\" onClick={() => go(\"magic-link\")}>\n                  Email me a link instead\n                </TextLink>\n              </div>\n            </>\n          )}\n          {view === \"sign-up\" && (\n            <>\n              <div data-field=\"name\">\n                <Field\n                  label=\"Full name\"\n                  name=\"name\"\n                  autoComplete=\"name\"\n                  placeholder=\"Ada Lindqvist\"\n                  value={values.name}\n                  onChange={(e) => set(\"name\", e.target.value)}\n                  onBlur={() => values.name && touch(\"name\")}\n                  error={errFor(\"name\")}\n                  disabled={busy}\n                />\n              </div>\n              {emailField}\n              <div data-field=\"password\">\n                <PasswordField\n                  label=\"Password\"\n                  name=\"new-password\"\n                  autoComplete=\"new-password\"\n                  placeholder=\"At least 8 characters\"\n                  value={values.password}\n                  onChange={(v) => set(\"password\", v)}\n                  onBlur={() => values.password && touch(\"password\")}\n                  error={errFor(\"password\")}\n                  disabled={busy}\n                  meter\n                />\n              </div>\n              <div data-field=\"terms\">\n                <Checkbox checked={values.terms} onChange={(v) => set(\"terms\", v)} error={submitted ? (errors.terms ?? null) : null}>\n                  I agree to the <span className=\"text-white/80 underline decoration-white/25 underline-offset-2\">Terms</span> and{\" \"}\n                  <span className=\"text-white/80 underline decoration-white/25 underline-offset-2\">Privacy Policy</span>\n                </Checkbox>\n              </div>\n              <div className=\"pt-1\">\n                <PrimaryButton type=\"submit\" pending={pending} pendingLabel=\"Creating account…\">\n                  Create account\n                </PrimaryButton>\n              </div>\n            </>\n          )}\n          {(view === \"magic-link\" || view === \"forgot\") && (\n            <>\n              {emailField}\n              <div className=\"pt-1\">\n                <PrimaryButton type=\"submit\" pending={pending} pendingLabel=\"Sending…\">\n                  {view === \"forgot\" ? \"Send reset link\" : \"Send magic link\"}\n                </PrimaryButton>\n              </div>\n            </>\n          )}\n          {view === \"otp\" && (\n            <>\n              <div ref={otpRef} className=\"flex justify-center\">\n                <Passcode\n                  length={otpLength}\n                  value={otp}\n                  onChange={(v) => {\n                    setOtp(v);\n                    if (error) setError(null);\n                  }}\n                  onComplete={submitOtp}\n                  disabled={pending}\n                  colors={[accent, SUCCESS]}\n                  aria-label={`${otpLength}-digit verification code`}\n                  size=\"sm\"\n                  name=\"code\"\n                />\n              </div>\n              <PrimaryButton type=\"submit\" pending={pending} pendingLabel=\"Verifying…\" disabled={!pending && otp.length < otpLength}>\n                Verify\n              </PrimaryButton>\n              <p className=\"text-center text-[13px] text-white/45\">\n                Didn&apos;t get it?{\" \"}\n                {countdown.left > 0 ? (\n                  <span className=\"text-white/40\">\n                    Resend in <span className=\"tabular-nums text-white/60\">{fmtClock(countdown.left)}</span>\n                  </span>\n                ) : (\n                  <TextLink strong onClick={resend}>\n                    Resend code\n                  </TextLink>\n                )}\n              </p>\n            </>\n          )}\n          {view === \"reset\" && (\n            <>\n              <input type=\"email\" name=\"email\" autoComplete=\"username\" value={email} readOnly hidden />\n              <div data-field=\"password\">\n                <PasswordField\n                  label=\"New password\"\n                  name=\"new-password\"\n                  autoComplete=\"new-password\"\n                  placeholder=\"At least 8 characters\"\n                  value={values.password}\n                  onChange={(v) => set(\"password\", v)}\n                  onBlur={() => values.password && touch(\"password\")}\n                  error={errFor(\"password\")}\n                  disabled={busy}\n                  meter\n                />\n              </div>\n              <div data-field=\"confirm\">\n                <PasswordField\n                  label=\"Confirm password\"\n                  name=\"confirm-password\"\n                  autoComplete=\"new-password\"\n                  placeholder=\"Repeat it\"\n                  value={values.confirm}\n                  onChange={(v) => set(\"confirm\", v)}\n                  onBlur={() => values.confirm && touch(\"confirm\")}\n                  error={errFor(\"confirm\")}\n                  disabled={busy}\n                />\n                <Collapse show={!!values.confirm && !errFor(\"confirm\")}>\n                  <p\n                    className=\"flex items-center gap-1.5 pt-1.5 text-[12.5px]\"\n                    style={{ color: values.confirm === values.password ? SUCCESS : \"rgba(255,255,255,0.4)\" }}\n                    aria-live=\"polite\"\n                  >\n                    {values.confirm === values.password ? \"✓ Passwords match\" : \"Keep typing — doesn't match yet\"}\n                  </p>\n                </Collapse>\n              </div>\n              <div className=\"pt-1\">\n                <PrimaryButton type=\"submit\" pending={pending} pendingLabel=\"Updating…\">\n                  Update password\n                </PrimaryButton>\n              </div>\n            </>\n          )}\n        </form>\n      </>\n    );\n  }\n\n  /* ----- footer */\n  let footer: React.ReactNode = null;\n  if (phase !== \"done\") {\n    if (view === \"sign-in\")\n      footer = (\n        <>\n          New to {title}? <TextLink strong onClick={() => go(\"sign-up\")}>Create an account</TextLink>\n        </>\n      );\n    else if (view === \"sign-up\")\n      footer = (\n        <>\n          Already have an account? <TextLink strong onClick={() => go(\"sign-in\")}>Sign in</TextLink>\n        </>\n      );\n    else\n      footer = (\n        <TextLink onClick={() => go(\"sign-in\")} className=\"inline-flex items-center gap-1.5\">\n          <svg viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n            <path d=\"M10 3.5 5.5 8l4.5 4.5\" />\n          </svg>\n          Back to sign in\n        </TextLink>\n      );\n  }\n  const footerKey = phase === \"done\" ? \"none\" : view === \"sign-in\" || view === \"sign-up\" ? view : \"back\";\n\n  return (\n    <WicketCtx.Provider value={ctx}>\n      <div\n        ref={rootRef}\n        data-crucible=\"wicket\"\n        className={cn(\"@container relative w-full max-w-[400px]\", className)}\n        style={\n          {\n            \"--wk-accent\": accent,\n            \"--wk-ring\": `color-mix(in srgb, ${accent} 26%, transparent)`,\n          } as React.CSSProperties\n        }\n      >\n        <motion.div\n          key={introKey}\n          initial={{ opacity: 0, y: 14, scale: 0.985 }}\n          animate={revealed ? { opacity: 1, y: 0, scale: 1 } : { opacity: 0, y: 14, scale: 0.985 }}\n          transition={reduced ? INSTANT : { duration: 0.6, ease: EASE }}\n          className=\"relative overflow-hidden rounded-2xl border border-white/[0.08] bg-neutral-900/85 shadow-[0_1px_0_rgba(255,255,255,0.04)_inset,0_24px_60px_-20px_rgba(0,0,0,0.7)] backdrop-blur-xl\"\n        >\n          {/* accent hairline + top glow */}\n          <span aria-hidden className=\"pointer-events-none absolute inset-x-10 top-0 h-px\" style={{ background: `linear-gradient(90deg, transparent, ${accent}, transparent)`, opacity: 0.55 }} />\n          <span aria-hidden className=\"pointer-events-none absolute inset-x-0 top-0 h-32\" style={{ background: `radial-gradient(60% 100% at 50% 0%, color-mix(in srgb, ${accent} 9%, transparent), transparent 70%)` }} />\n\n          <div className=\"relative px-5 pb-6 pt-7 @min-[380px]:px-8 @min-[380px]:pb-7\">\n            <motion.div\n              className=\"mb-5 flex justify-center\"\n              initial={{ opacity: 0, y: 6 }}\n              animate={revealed ? { opacity: 1, y: 0 } : { opacity: 0, y: 6 }}\n              transition={reduced ? INSTANT : { duration: 0.5, ease: EASE, delay: 0.12 }}\n            >\n              {logo ?? <DefaultLogo accent={accent} />}\n            </motion.div>\n\n            <motion.div\n              initial={false}\n              animate={{ height: reduced ? \"auto\" : height }}\n              transition={reduced ? INSTANT : SPRING}\n              className=\"-mx-2 -my-1 overflow-hidden\"\n            >\n              <div ref={measureRef} className=\"px-2 py-1\">\n                <motion.div\n                  ref={shakeRef}\n                  initial={{ opacity: 0, y: 8 }}\n                  animate={revealed ? { opacity: 1, y: 0 } : { opacity: 0, y: 8 }}\n                  transition={reduced ? INSTANT : { duration: 0.55, ease: EASE, delay: 0.2 }}\n                >\n                  <AnimatePresence mode=\"wait\" initial={false} custom={dir}>\n                    <motion.div\n                      key={stageKey}\n                      ref={attachStage}\n                      custom={dir}\n                      variants={variants}\n                      initial=\"enter\"\n                      animate=\"center\"\n                      exit=\"exit\"\n                      transition={stageTransition}\n                    >\n                      {body}\n                    </motion.div>\n                  </AnimatePresence>\n                </motion.div>\n              </div>\n            </motion.div>\n          </div>\n\n          <AnimatePresence initial={false}>\n            {footer && (\n              <motion.div\n                initial={reduced ? { opacity: 0 } : { opacity: 0, height: 0 }}\n                animate={reduced ? { opacity: 1 } : { opacity: 1, height: \"auto\" }}\n                exit={reduced ? { opacity: 0 } : { opacity: 0, height: 0 }}\n                transition={reduced ? { duration: 0.15 } : { duration: 0.28, ease: EASE }}\n                className=\"overflow-hidden\"\n              >\n                <div className=\"border-t border-white/[0.06] bg-white/[0.015] px-5 py-4 text-center text-[13px] text-white/45\">\n                  <AnimatePresence mode=\"wait\" initial={false}>\n                    <motion.div\n                      key={footerKey}\n                      initial={{ opacity: 0 }}\n                      animate={{ opacity: 1 }}\n                      exit={{ opacity: 0 }}\n                      transition={{ duration: reduced ? 0.12 : 0.16 }}\n                    >\n                      {footer}\n                    </motion.div>\n                  </AnimatePresence>\n                </div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </motion.div>\n        <p className=\"sr-only\" aria-live=\"polite\" role=\"status\">\n          {announce}\n        </p>\n      </div>\n    </WicketCtx.Provider>\n  );\n}\n\nexport default Wicket;\n"
    }
  ]
}